package sds.assemble;

import sds.classfile.attributes.LineNumberTable;
import sds.classfile.bytecode.OpcodeInfo;
import sds.classfile.bytecode.Opcodes;

/**
 *
 * @author inagaki
 */
public class LineInstructions {
	private LineNumberTable.LNTable table;
	private Opcodes opcodes;

	public LineInstructions(LineNumberTable.LNTable table) {
		this.table = table;
		this.opcodes = new Opcodes();
	}

	public void addOpcode(OpcodeInfo opcode) {
		opcodes.add(opcode.getPc(), opcode);
	}

	public LineNumberTable.LNTable getTable() {
		return table;
	}

	public Opcodes getOpcodes() {
		return opcodes;
	}

	public boolean isInPcRange(int pc) {
		return table.getStartPc() <= pc && pc <= table.getEndPc();
	}
}
package sds.assemble;

import sds.classfile.attributes.LineNumberTable;
import sds.classfile.bytecode.OpcodeInfo;
import sds.classfile.bytecode.Opcodes;

/**
 * This class is for instructions of a line of method.
 * @author inagaki
 */
public class LineInstructions {
	private LineNumberTable.LNTable table;
	private Opcodes opcodes;

	/**
	 * constructor.
	 * @param table line number table 
	 */
	public LineInstructions(LineNumberTable.LNTable table) {
		this.table = table;
		this.opcodes = new Opcodes();
	}

	/**
	 * adds opcode.
	 * @param opcode opcode 
	 */
	public void addOpcode(OpcodeInfo opcode) {
		opcodes.add(opcode.getPc(), opcode);
	}

	/**
	 * returns line number table.
	 * @return line number table
	 */
	public LineNumberTable.LNTable getTable() {
		return table;
	}

	/**
	 * returns opcodes of this line.
	 * @return opcodes
	 */
	public Opcodes getOpcodes() {
		return opcodes;
	}

	/**
	 * returns opcode from specified pc.
	 * @param pc index into the code array.
	 * @return opcode
	 */
	public OpcodeInfo get(int pc) {
		return opcodes.get(pc);
	}
}
add comment for javadoc and method to be able to get from index into the code array.