massive overhaul of slipway (fpga-fleet)
[fleet.git] / src / edu / berkeley / fleet / interpreter / Interpreter.java
index 8ed504d..87c96d8 100644 (file)
@@ -78,40 +78,39 @@ public class Interpreter extends Fleet implements Iterable<Ship> {
     }
 
     public void writeInstruction(DataOutputStream os, Instruction d) throws IOException {
+        long instr = 0;
+
+        // Kill is encoded as Execute with the illegal combination (Latch & ~DataIn)
+        if (d instanceof Instruction.Kill) {
+            Instruction.Kill k = (Instruction.Kill)d;
+            d = new Instruction.Executable(k.benkoBox, null, k.count, false, false, true, false, false, false);
+        }
+
         if (d instanceof Instruction.Executable) {
             Instruction.Executable inst = (Instruction.Executable)d;
-            
             InterpreterBenkoBox dest = resolve(inst.dest);
-            long instr = dest==null ? 0 : (dest.addr << 1);
-            
+            instr = dest==null ? 0 : (dest.addr << 1);
             instr |= (((long)inst.count) << (11+1));
             if (inst.tokenIn)  instr |= (1L << (11+1+7+0));
-            if (inst.dataOut)  instr |= (1L << (11+1+7+1));
+            if (inst.dataIn)   instr |= (1L << (11+1+7+1));
             if (inst.latch)    instr |= (1L << (11+1+7+2));
-            if (inst.dataIn)   instr |= (1L << (11+1+7+3));
+            if (inst.dataOut)  instr |= (1L << (11+1+7+3));
             if (inst.tokenOut) instr |= (1L << (11+1+7+4));
             instr |= ((long)resolve(inst.benkoBox).instr_addr) << (11+5+7+1);
-            long out = 0;
-            out |= ((InterpreterBenkoBox)ships.get("command").getBenkoBox("data")).addr;
-            out |= instr << 11;
-            dump(os, (out >> (5*8)) & 0xff);
-            dump(os, (out >> (4*8)) & 0xff);
-            dump(os, (out >> (3*8)) & 0xff);
-            dump(os, (out >> (2*8)) & 0xff);
-            dump(os, (out >> (1*8)) & 0xff);
-            dump(os, (out >> (0*8)) & 0xff);
+
         } else if (d instanceof Instruction.Literal.Absolute) {
             Instruction.Literal.Absolute ld = (Instruction.Literal.Absolute)d;
-            long out = 0;
-            out |= resolve(ld.dest).addr;
-            out |= ((long)ld.value) << 11;
-            dump(os, (out >> (5*8)) & 0xff);
-            dump(os, (out >> (4*8)) & 0xff);
-            dump(os, (out >> (3*8)) & 0xff);
-            dump(os, (out >> (2*8)) & 0xff);
-            dump(os, (out >> (1*8)) & 0xff);
-            dump(os, (out >> (0*8)) & 0xff);
+            instr = (2L << (11+24));
+            instr |= (resolve(ld.dest).addr) << 24;
+            instr |= ((long)ld.value);
         }
+
+        dump(os, (instr >> (5*8)) & 0xff);
+        dump(os, (instr >> (4*8)) & 0xff);
+        dump(os, (instr >> (3*8)) & 0xff);
+        dump(os, (instr >> (2*8)) & 0xff);
+        dump(os, (instr >> (1*8)) & 0xff);
+        dump(os, (instr >> (0*8)) & 0xff);
     }
     public void dump(OutputStream os, long data_) throws IOException {
         int data = (int)data_;
@@ -243,16 +242,17 @@ public class Interpreter extends Fleet implements Iterable<Ship> {
           System.out.println("import ["+ship.getBalsaName()+"]");
           }
         */
-        System.out.println("module fabric(clk, top_r, top_a, top,");
+        System.out.println("module fabric(clk, data_Execute0_in_r, data_Execute0_in_a, data_Execute0_in,");
         System.out.println("                   data_Debug0_out_r, data_Debug0_out_a, data_Debug0_out);");
         System.out.println("  input  clk;");
-        System.out.println("  input  top_r;");
-        System.out.println("  output top_a;");
-        System.out.println("  input  [(`PACKET_WIDTH-1):0] top;");
+        System.out.println("  input  data_Execute0_in_r;");
+        System.out.println("  output data_Execute0_in_a;");
+        System.out.println("  input  [(`PACKET_WIDTH-1):0] data_Execute0_in;");
         System.out.println("  output data_Debug0_out_r;");
         System.out.println("  input  data_Debug0_out_a;");
         System.out.println("  output [(`PACKET_WIDTH-1):0] data_Debug0_out;");
-        System.out.println("  wire   [(`INSTRUCTION_WIDTH-1):0] data_Command0_out;");
+        System.out.println("  wire   [(`INSTRUCTION_WIDTH-1):0] data_Execute0_ihorn;");
+        System.out.println("  wire   [(`PACKET_WIDTH-1):0] data_Execute0_dhorn;");
         System.out.println();
         
         System.out.println();
@@ -262,7 +262,7 @@ public class Interpreter extends Fleet implements Iterable<Ship> {
         inputs.dumpChannels(true);
         for(InterpreterShip ship : shiplist)
             for(BenkoBox port : ship.getBenkoBoxes()) {
-                if (ship instanceof Command && port instanceof Outbox) continue;
+                if (ship instanceof Execute && port instanceof Outbox) continue;
                 System.out.println("  wire [(`PACKET_WIDTH-1):0] data_"+getUniqueName(ship)+"_"+port.getName()+";");
             }
 
@@ -317,11 +317,13 @@ public class Interpreter extends Fleet implements Iterable<Ship> {
             }
 
         }
-        System.out.println("funnel topfun(clk, dest_r, dest_a, dest, source_r, source_a, source, top_r, top_a, top);");
-        System.out.println("");
-        System.out.println("  assign instruction_r      = data_Command0_out_r;");
-        System.out.println("  assign data_Command0_out_a = instruction_a;");
-        System.out.println("  assign instruction        = data_Command0_out;");
+        System.out.println("funnel topfun(clk,"+
+                           "              dest_r, dest_a, dest,"+
+                           "              source_r, source_a, source,"+
+                           "              data_Execute0_dhorn_r, data_Execute0_dhorn_a, data_Execute0_dhorn);");
+        System.out.println("assign instruction_r = data_Execute0_ihorn_r;");
+        System.out.println("assign data_Execute0_ihorn_a = instruction_a;");
+        System.out.println("assign instruction = data_Execute0_ihorn;");
         System.out.println("endmodule");
     }