com.thesett.aima.logic.fol.wam.debugger.monitor.ByteCodeMonitor Maven / Gradle / Ivy
The newest version!
/*
* Copyright The Sett Ltd, 2005 to 2014.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.thesett.aima.logic.fol.wam.debugger.monitor;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import com.thesett.aima.logic.fol.FunctorName;
import com.thesett.aima.logic.fol.VariableAndFunctorInterner;
import com.thesett.aima.logic.fol.wam.compiler.WAMInstruction;
import com.thesett.aima.logic.fol.wam.compiler.WAMLabel;
import com.thesett.aima.logic.fol.wam.machine.WAMCodeView;
import com.thesett.common.util.SizeableList;
import com.thesett.common.util.doublemaps.DoubleKeyedMap;
import com.thesett.text.api.model.TextTableModel;
/**
* ByteCodeMonitor responds to changes in the byte code loaded into the target machine. Byte-code is disassembled and
* inserted into a {@link TextTableModel}.
*
* The instructions vary in size, so mapping between addresses in the code, and rows in the table model is not
* straightforward. This monitor maintains this mapping, and provides the methods {@link #getAddressForRow(int)} and
* {@link #getRowForAddress(int)} to access it. This can be used to work out which instruction has been selected in the
* table, or which row in the table to highlight when a particular address is being stepped, and so on.
*
*
CRC Card
* Responsibilities Collaborations
* Maintain a table model containing disassembled byte-code.
* Maintain a mapping between code addresses and table rows.
*
*
* @author Rupert Smith
*/
public class ByteCodeMonitor
{
/** Used for debugging. */
private static final java.util.logging.Logger log =
java.util.logging.Logger.getLogger(ByteCodeMonitor.class.getName());
/** Defines the label for the code address column. */
public static final String ADDRESS = "address";
/** Defines the label for the code label column. */
public static final String LABEL = "label";
/** Defines the label for the instruction mnemonic column. */
public static final String MNEMONIC = "mnemonic";
/** Defines the label for the first instruction arguments column. */
public static final String ARG_1 = "arg_1";
/** Defines the label for the second instruction arguments column. */
public static final String ARG_2 = "arg_2";
/** Column labels for the code table. */
private static final String[] BYTE_CODE_COL_LABELS = new String[] { ADDRESS, LABEL, MNEMONIC, ARG_1 };
/** The table to output the byte code to. */
private final TextTableModel table;
/** A column labeled view onto the code table. */
private final DoubleKeyedMap