* @instruction The instruction to encode
* @dispatchFrom The dock from which the instruction being written is to be dispatched (required for encoding)
*/
- public abstract Instruction readInstruction(DataInputStream is, Dock dispatchFrom) throws IOException;
+ public abstract BitVector encodeInstruction(Instruction instruction, Dock dispatchFrom);
/**
* Decodes an instruction from a BitVector
* @instruction The instruction to decode
* @dispatchFrom The dock from which the instructions being read are to be dispatched (required for decoding)
*/
- public abstract void writeInstruction(DataOutputStream os, Dock dispatchFrom, Instruction instr) throws IOException;
+ public abstract Instruction decodeInstruction(BitVector instruction, Dock dispatchFrom);
/** If supported, run the given code and create a FleetProcess to interact with it. */
public FleetProcess run(Instruction[] program) {
return null;
}
- /** read a machine-formatted instruction from a file (into a Java object) */
- public Instruction readInstruction(DataInputStream is, Dock dispatchFrom) throws IOException {
- long inst = 0;
- try {
- inst = (inst << 8) | (is.readByte() & 0xff);
- inst = (inst << 8) | (is.readByte() & 0xff);
- inst = (inst << 8) | (is.readByte() & 0xff);
- inst = (inst << 8) | (is.readByte() & 0xff);
- inst = (inst << 8) | (is.readByte() & 0xff);
- inst = (inst << 8) | (is.readByte() & 0xff);
- return readInstruction(inst, dispatchFrom);
- } catch (EOFException eof) {
- return null;
- }
+ public Instruction decodeInstruction(BitVector instruction, Dock dispatchFrom) {
+ return readInstruction(instruction.toLong(), dispatchFrom);
+ }
+
+ public BitVector encodeInstruction(Instruction instr, Dock dispatchFrom) {
+ return new BitVector(getWordWidth()).set(writeInstruction(instr, dispatchFrom));
}
public int getShiftWidth() { return SHIFT.valmaskwidth; }
return instr;
}
- public void writeInstruction(DataOutputStream os, Dock dispatchFrom, Instruction d) throws IOException {
- long instr = writeInstruction(d, dispatchFrom);
- for(int i=5; i>=0; i--)
- os.write(BitManipulations.getIntField(i*8+7, i*8, instr));
- }
-
- private static long flagFunctionToLong(FlagFunction ff) {
+ private long flagFunctionToLong(FlagFunction ff) {
long ret = 0;
for(Predicate p : ff)
switch(p) {