From: adam Date: Mon, 3 Nov 2008 09:51:00 +0000 (+0100) Subject: change readInstruction/writeInstruction to encodeInstruction/decodeInstruction X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=42514a734f7539d178763f53d487a79f75428886;p=fleet.git change readInstruction/writeInstruction to encodeInstruction/decodeInstruction --- diff --git a/src/edu/berkeley/fleet/api/Fleet.java b/src/edu/berkeley/fleet/api/Fleet.java index ca06e08..ce0cfb2 100644 --- a/src/edu/berkeley/fleet/api/Fleet.java +++ b/src/edu/berkeley/fleet/api/Fleet.java @@ -41,14 +41,14 @@ public abstract class Fleet implements Iterable { * @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) { diff --git a/src/edu/berkeley/fleet/two/FleetTwoFleet.java b/src/edu/berkeley/fleet/two/FleetTwoFleet.java index 921c0b6..da3e2f1 100644 --- a/src/edu/berkeley/fleet/two/FleetTwoFleet.java +++ b/src/edu/berkeley/fleet/two/FleetTwoFleet.java @@ -106,20 +106,12 @@ public abstract class FleetTwoFleet extends Fleet { 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; } @@ -306,13 +298,7 @@ public abstract class FleetTwoFleet extends Fleet { 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) {