// codebags in numerical order
private ArrayList<CodeBag> codeBags = new ArrayList<CodeBag>();
private HashMap<String,CodeBag> codeBagsByName = new HashMap<String,CodeBag>();
+
+ private CodeBag getCodeBag(String name) {
+ CodeBag cb = codeBagsByName.get(name);
+ if (cb!=null) return cb;
+ return new CodeBag(name);
+ }
Tree<String> parse(Reader r) throws Exception {
InputStream grammarStream =
CodeBag rootCodeBag = new CodeBag();
baseCodeBag.add(new Instruction.Literal.CodeBagDescriptor(null, rootCodeBag.getFakeAddress(), 1));
walk((Tree<String>)parse(r), rootCodeBag);
-
+ if (fleet instanceof edu.berkeley.fleet.interpreter.Interpreter)
+ ((edu.berkeley.fleet.slipway.Slipway)fleet).dumpFabric(true);
+
// map from arbitrary identifiers to actual addresses
int[] codeBagMap = new int[codeBags.size()];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
}
// now write for real
- dos = new DataOutputStream(out);
- cos = new CountingOutputStream(dos);
+ cos = new CountingOutputStream(out);
+ dos = new DataOutputStream(cos);
for(int i=0; i<codeBags.size(); i++) {
CodeBag c = codeBags.get(i);
dos.flush();
}
}
dos.flush();
- }
-
- public void parse(Reader r, ArrayList<Instruction> out) throws Exception {
- // this needs to be "code bag zero"
- CodeBag baseCodeBag = new CodeBag();
- CodeBag rootCodeBag = new CodeBag();
- Instruction inst0 = new Instruction.Literal.CodeBagDescriptor(null, rootCodeBag.getFakeAddress(), 1);
- baseCodeBag.add(inst0);
- walk((Tree<String>)parse(r), rootCodeBag);
-
- // map from arbitrary identifiers to actual addresses
- int[] codeBagMap = new int[codeBags.size()];
- ArrayList<Instruction> temp = new ArrayList<Instruction>();
- for(int i=0; i<codeBags.size(); i++) {
- codeBagMap[i] = temp.size();
- for(Instruction inst : codeBags.get(i))
- temp.add(inst);
- }
-
- // now write for real
- for(int i=0; i<codeBags.size(); i++) {
- CodeBag c = codeBags.get(i);
- for(Instruction inst : c) {
- if (inst instanceof Instruction.Literal.CodeBagDescriptor) {
- Instruction.Literal.CodeBagDescriptor old = (Instruction.Literal.CodeBagDescriptor)inst;
- int offset = fleet.computeOffset(out.size(), codeBagMap[(int)old.offset]);
- inst = new Instruction.Literal.CodeBagDescriptor(old.dest,
- offset,
- codeBags.get((int)old.offset).size());
- }
- out.add(inst);
- }
- }
+ cos.flush();
+ out.flush();
+ out.close();
}
/** in the first pass, codebags are assigned "addresses" in arbitrary order */
fillCodeBag(statement, cb);
} else if (head.equals("Import")) {
- imports.add(string(t.child(0)));
+ // ignored
} else if (head.equals("Ship")) {
String name = name(t.child(0));
String type = string(t.child(1));
Ship ship = null;
- if (fleet instanceof edu.berkeley.fleet.interpreter.Interpreter) {
- edu.berkeley.fleet.interpreter.Interpreter interpreter =
- ((edu.berkeley.fleet.interpreter.Interpreter)fleet);
- String classname = type;
- boolean good = false;
- for(String s : imports)
- if ((ship = interpreter.tryCreate(s+"."+classname, name)) != null)
- break;
+
+ if (fleet instanceof Fleet.WithDynamicShips) {
+ Fleet.WithDynamicShips dyn = ((Fleet.WithDynamicShips)fleet);
+ ship = dyn.createShip(type, name);
if (ship==null)
- throw new RuntimeException("couldn't find a ship called \""+classname+"\"");
+ throw new RuntimeException("couldn't find a ship called \""+type+"\"");
} else {
ship = allocateShip(type);
}
}
private HashMap<String,Integer> numAllocated = new HashMap<String,Integer>();
+
Ship allocateShip(String shipType) {
int allocated = 0;
if (numAllocated.get(shipType) != null)
void fillCodeBag(Tree<String> t, CodeBag cb) {
if (t.head()==null) return;
else if (t.head().equals("NamedCodeBag")) {
- CodeBag cb2 = new CodeBag(name(t.child(0)));
+ CodeBag cb2 = getCodeBag(name(t.child(0)));
for(Tree<String> statement : t.child(1))
fillCodeBag(statement, cb2);
BenkoBox benkobox = portReference(t.child(1));
cb.add(new Instruction.Literal.Absolute(benkobox, literal));
+ } else if (t.head().equals("CodeBagDescriptor")) {
+ String refname = name(t.child(0).child(0));
+ CodeBag cb2 = getCodeBag(refname);
+ BenkoBox benkobox = portReference(t.child(1));
+ cb.add(new Instruction.Literal.CodeBagDescriptor(benkobox, cb2.getFakeAddress(), 0));
+
} else if (t.head().equals("Fiber")) {
BenkoBox benkobox = portReference(t.child(0));
package edu.berkeley.fleet.interpreter;
-import edu.berkeley.fleet.api.*;
-
-import edu.berkeley.fleet.api.*;
-import edu.berkeley.fleet.*;
-import java.lang.reflect.*;
-import edu.berkeley.sbp.chr.*;
-import edu.berkeley.sbp.misc.*;
-import edu.berkeley.sbp.meta.*;
-import edu.berkeley.sbp.bind.*;
-import edu.berkeley.sbp.util.*;
-import java.util.*;
import java.io.*;
+import java.util.*;
+import java.lang.reflect.*;
+import edu.berkeley.fleet.*;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.ies44.*;
import edu.berkeley.fleet.ships.*;
-public class Interpreter extends Fleet implements Iterable<Ship> {
+public class Interpreter extends Fleet /*, Fleet.WithDynamicShips*/ {
+
+ /** some "halt ship" can turn this on to stop the interpreter */
+ public boolean halt = false;
+
+ public ArrayList<InterpreterShip> shiplist = new ArrayList<InterpreterShip>();
+ public HashMap<String,InterpreterShip> ships = new HashMap<String,InterpreterShip>();
+
+ public void go(byte[] instructions) {
- public InterpreterBenkoBox resolve(edu.berkeley.fleet.api.BenkoBox bb) { return (InterpreterBenkoBox)bb; }
+ // find the first icache
+ Icache icache = null;
+ for(Ship ship : this)
+ if (ship instanceof Icache) {
+ icache = (Icache)ship;
+ break;
+ }
- public void dumpCode(Instruction[] instructions) throws IOException {
- DataOutputStream dos = new DataOutputStream(new FileOutputStream("build/fleet.bin"));
- for(int i=1; i<instructions.length; i++) {
- Instruction inst = instructions[i];
- writeInstruction(dos, inst);
+ // load the icache and take note of the 0-address CBD
+ long launch = 0;
+ for(int i=0; i<instructions.length; i+=6) {
+ long word = 0;
+ for(int j=0; j<6; j++)
+ word = (word << 8) | (instructions[i+j] & 0xff);
+ icache.writeMem(i/6, word);
+ if (i==0) launch = word;
}
- dos.flush();
- dos.close();
+
+ // dispatch the 0-address CBD
+ int base = (int)(launch >> 6);
+ base = base & ~(0xffffffff << 18);
+ int size = (int)launch;
+ size = size & ~(0xffffffff << 6);
+ icache.dispatch(base, size);
+
+ while(!halt)
+ for(InterpreterShip ship : ships.values())
+ for(int j=0; j<10; j++)
+ ship._service();
+
+ // run the ships a bit longer for good measure
+ for(int i=0; i<100; i++)
+ for(InterpreterShip ship : ships.values())
+ for(int j=0; j<10; j++)
+ ship._service();
+
+ // check the state of the ships
+ for(InterpreterShip ship : ships.values())
+ ship.shutdown();
+
+ Log.println(Log.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======"));
}
public void dispatch(Instruction i, long address) {
-
+ Log.dispatch(i);
if (i instanceof Instruction.Executable) {
- InterpreterBenkoBox sourceBenkoBox = resolve(((Instruction.Executable)i).benkoBox);
- if (!(sourceBenkoBox instanceof InstructionPort))
- throw new RuntimeException(sourceBenkoBox + " is not an InstructionPort!");
+ InterpreterBenkoBox sourceBenkoBox = (InterpreterBenkoBox)(((Instruction.Executable)i).benkoBox);
((InstructionPort)sourceBenkoBox).addInstruction(((Instruction.Executable)i));
} else if (i instanceof Instruction.Literal.CodeBagDescriptor) {
- Log.dispatch(i);
Instruction.Literal.CodeBagDescriptor cbd = (Instruction.Literal.CodeBagDescriptor)i;
- dispatchCodeBag(cbd.offset+address, cbd.size);
+ InterpreterBenkoBox destBenkoBox = (InterpreterBenkoBox)(cbd.dest);
+ long absolute_cbd = ((cbd.offset+address) << 6) | cbd.size;
+ destBenkoBox.addDataFromFabric((int)absolute_cbd);
} else if (i instanceof Instruction.Literal.Absolute) {
- InterpreterBenkoBox destBenkoBox = resolve(((Instruction.Literal.Absolute)i).dest);
+ InterpreterBenkoBox destBenkoBox = (InterpreterBenkoBox)(((Instruction.Literal.Absolute)i).dest);
Log.data(((Instruction.Literal.Absolute)i).value+"", null, destBenkoBox);
destBenkoBox.addDataFromFabric((int)((Instruction.Literal.Absolute)i).value);
} else if (i instanceof Instruction.Kill) {
- InterpreterBenkoBox benkoBox = resolve(((Instruction.Kill)i).benkoBox);
- if (!(benkoBox instanceof InstructionPort))
- throw new RuntimeException(benkoBox + " is not an InstructionPort!");
+ InterpreterBenkoBox benkoBox = (InterpreterBenkoBox)(((Instruction.Kill)i).benkoBox);
((InstructionPort)benkoBox).kill(((Instruction.Kill)i).count);
} else {
}
}
- /** some "halt ship" can turn this on to stop the interpreter */
- public boolean halt = false;
+ public void sendToken(InterpreterBenkoBox source, InterpreterBenkoBox dest) {
+ Log.token(source, dest);
+ dest.addTokenFromFabric();
+ }
- public int[] mem = new int[0];
+ public void sendData(InterpreterBenkoBox source, int data, InterpreterBenkoBox dest) {
+ Log.data(data+"", source, dest);
+ dest.addDataFromFabric(data);
+ }
- public Instruction[] instructions = null;
- public ArrayList<String> imports = new ArrayList<String>();
- private static String getUniqueName(Ship ship) {
- return ship.getType() + ship.getOrdinal();
- }
+ // Implementation of the Fleet class abstract methods /////////////////////////////////////////////////////////
- public ArrayList<InterpreterShip> shiplist = new ArrayList<InterpreterShip>();
- public HashMap<String,InterpreterShip> ships = new HashMap<String,InterpreterShip>();
+ public Iterator<Ship> iterator() { return (Iterator<Ship>)(Object)shiplist.iterator(); }
- /** read a machine-formatted instruction from a file (into a Java object) */
- public Instruction readInstruction(DataInputStream is) throws IOException {
- // FIXME
- return null;
- }
+ public int computeOffset(int origin, int target) { return (target - origin)/6; }
+ public int computeTarget(int origin, int offset) { return origin + (offset*6); }
- public void writeInstruction(DataOutputStream os, Instruction d) throws IOException {
- long instr = 0;
+ private InterpreterInstructionEncoder iie = new InterpreterInstructionEncoder();
+ public Instruction readInstruction(DataInputStream is) throws IOException { return iie.readInstruction(is); }
+ public Instruction readInstruction(long instr) { return iie.readInstruction(instr); }
+ public long writeInstruction(Instruction d) { return writeInstruction(d); }
+ public void writeInstruction(DataOutputStream os, Instruction d) throws IOException { iie.writeInstruction(os, d); }
- // 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);
+ private class InterpreterInstructionEncoder extends InstructionEncoder {
+ public long getBoxAddr(BenkoBox box) { return ((InterpreterBenkoBox)box).addr; }
+ public long getBoxInstAddr(BenkoBox box) { return ((InterpreterBenkoBox)box).instr_addr; }
+ public BenkoBox getBoxByAddr(long dest) {
+ for(Ship ship : Interpreter.this)
+ for(BenkoBox bb : ship.getBenkoBoxes())
+ if (((InterpreterBenkoBox)bb).addr == dest)
+ return bb;
+ return null;
}
-
- if (d instanceof Instruction.Executable) {
- Instruction.Executable inst = (Instruction.Executable)d;
- InterpreterBenkoBox dest = resolve(inst.dest);
- instr = dest==null ? 0 : (dest.addr << 1);
- if (inst.count >= (1<<8))
- throw new RuntimeException("count field must be less than 128");
- instr |= (((long)inst.count) << (11+1));
- if (inst.tokenIn) instr |= (1L << (11+1+7+0));
- if (inst.dataIn) instr |= (1L << (11+1+7+1));
- if (inst.latch) instr |= (1L << (11+1+7+2));
- if (inst.dataOut) instr |= (1L << (11+1+7+3));
- if (inst.tokenOut) instr |= (1L << (11+1+7+4));
- if (inst.recycle) instr |= (1L);
- instr |= ((long)resolve(inst.benkoBox).instr_addr) << (11+5+7+1);
-
- } else if (d instanceof Instruction.Literal.Absolute) {
- Instruction.Literal.Absolute ld = (Instruction.Literal.Absolute)d;
- instr = (2L << (11+24));
- instr |= (resolve(ld.dest).addr) << 24;
- if (ld.value >= (1<<25))
- throw new RuntimeException("literals must be less than 2^24");
- instr |= ((long)ld.value);
+ public BenkoBox getBoxByInstAddr(long dest) {
+ for(Ship ship : Interpreter.this)
+ for(BenkoBox bb : ship.getBenkoBoxes())
+ if (((InterpreterBenkoBox)bb).instr_addr == dest)
+ return bb;
+ return null;
}
-
- 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_;
- os.write((byte)data);
- //System.out.println(data);
- }
-
- public Iterator<Ship> iterator() {
- return (Iterator<Ship>)(Object)shiplist.iterator();
}
- public void dispatchCodeBag(long base, long size) {
- for(long i=base; i<base+size; i++)
- dispatch(instructions[(int)i], i);
+ public Ship createShip(String shipType, String shipname) {
+ try {
+ Class c = Class.forName("edu.berkeley.fleet.ships."+shipType);
+ Constructor con = c.getConstructor(new Class[] { Interpreter.class, String.class });
+ InterpreterShip ret = (InterpreterShip)con.newInstance(new Object[] { this, shipname });
+ ships.put(shipname, ret);
+ shiplist.add(ret);
+ return ret;
+ } catch (Exception e) {
+ return null;
+ }
}
- public void go() {
- Instruction.Literal.CodeBagDescriptor cbl =
- (Instruction.Literal.CodeBagDescriptor)instructions[0];
- dispatchCodeBag(cbl.offset+0, cbl.size);
-
- while(!halt)
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();
-
- // run the ships a bit longer for good measure
- for(int i=0; i<100; i++)
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();
- // check the state of the ships
- for(InterpreterShip ship : ships.values())
- ship.shutdown();
+ // Memory //////////////////////////////////////////////////////////////////////////////
- Log.println(Log.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======"));
- }
+ public int[] mem = new int[0];
public void dumpMem() {
Log.print(Log.cyan(" MEMORY: "));
mem[addr] = data;
}
- public InterpreterShip getShip(String name) {
- InterpreterShip s = ships.get(name);
- if (s == null) throw new RuntimeException("unknown ship \""+name+"\"");
- return s;
- }
-
- public InterpreterShip tryCreate(String classname, String shipname) {
- try {
- Class c = Class.forName(classname);
- Constructor con = c.getConstructor(new Class[] { Interpreter.class, String.class });
- InterpreterShip ret = (InterpreterShip)con.newInstance(new Object[] { this, shipname });
- ships.put(shipname, ret);
- shiplist.add(ret);
- return ret;
- } catch (Exception e) {
- return null;
- }
- }
- public void sendToken(InterpreterBenkoBox source, InterpreterBenkoBox dest) {
- Log.token(source, dest);
- dest.addTokenFromFabric();
- }
-
- public void sendData(InterpreterBenkoBox source, int data, InterpreterBenkoBox dest) {
- Log.data(data+"", source, dest);
- dest.addDataFromFabric(data);
- }
-
- public void dumpFabric(boolean quiet) {
- // FIXME: this is really ugly: the order of port declarations in
- // the XXXShip.java file must match the order in the .balsa file!
-
- ArrayList instructionports = new ArrayList<InterpreterBenkoBox>();
- for(InterpreterShip ship : shiplist)
- for(BenkoBox port : ship.getBenkoBoxes())
- if (!((InterpreterBenkoBox)port).special())
- instructionports.add(port);
- FabricTree instructions =
- new FabricTree((InterpreterBenkoBox[])instructionports.toArray(new InterpreterBenkoBox[0]),
- "ihorn",
- "instruction");
-
- ArrayList inputports = new ArrayList<InterpreterBenkoBox>();
- for(InterpreterShip ship : shiplist)
- for(BenkoBox port : ship.getBenkoBoxes())
- if (!((InterpreterBenkoBox)port).special())
- inputports.add(port);
- FabricTree inputs =
- new FabricTree((InterpreterBenkoBox[])inputports.toArray(new InterpreterBenkoBox[0]),
- "horn",
- "dest");
-
- ArrayList outputports = new ArrayList<InterpreterBenkoBox>();
- for(InterpreterShip ship : shiplist)
- for(BenkoBox port : ship.getBenkoBoxes())
- if (!((InterpreterBenkoBox)port).special())
- outputports.add(port);
- FabricTree outputs =
- new FabricTree((InterpreterBenkoBox[])outputports.toArray(new InterpreterBenkoBox[0]),
- "funnel",
- "source");
-
- if (quiet) return;
- System.out.println("`include \"macros.v\"");
- /*
- HashSet<Class> added = new HashSet<Class>();
- for(Ship ship : shiplist)
- if (!added.contains(ship.getClass())) {
- added.add(ship.getClass());
- System.out.println("import ["+ship.getBalsaName()+"]");
- }
- */
- 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 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_Execute0_ihorn;");
- System.out.println(" wire [(`PACKET_WIDTH-1):0] data_Execute0_dhorn;");
- System.out.println();
-
- System.out.println();
-
- instructions.dumpChannels(true);
- outputs.dumpChannels(true);
- inputs.dumpChannels(true);
- for(InterpreterShip ship : shiplist)
- for(BenkoBox port : ship.getBenkoBoxes()) {
- if (ship instanceof Execute && port instanceof Outbox) continue;
- System.out.println(" wire [(`PACKET_WIDTH-1):0] data_"+getUniqueName(ship)+"_"+port.getName()+";");
- }
-
- System.out.println("");
- instructions.dumpChannels(false);
- System.out.println("");
- outputs.dumpChannels(false);
- System.out.println("");
- inputs.dumpChannels(false);
- System.out.println("");
- for(InterpreterShip ship : shiplist) {
- System.out.print(ship.getClass().getSimpleName().toLowerCase());
- System.out.print(" ");
- System.out.print("krunk"+(krunk++));
- System.out.print("(clk, ");
- boolean first = true;
- for(BenkoBox port : ship.getBenkoBoxes()) {
- if (!first) System.out.print(", ");
- first = false;
- System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
- System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
- System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName());
- System.out.print(" ");
- }
- System.out.println(");");
-
- for(BenkoBox port : ship.getBenkoBoxes()) {
- if (((InterpreterBenkoBox)port).special()) continue;
- if (port instanceof Inbox) {
- /*
- if (((InterpreterBenkoBox)port).noInbox())
- System.out.print("stupidinbox");
- else
- */
- System.out.print("inbox");
- } else {
- System.out.print("outbox");
- }
- System.out.print(" krunk"+(krunk++)+"(clk, ");
- System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
- System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
- System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
- System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
- System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
- System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
- System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
- System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
- System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
- System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
- System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
- System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName());
- System.out.print(");");
- System.out.println();
- }
-
- }
- 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");
- }
-
- private static class FabricTree {
- int master_idx = 1;
- String prefix;
- Node root;
- public void dumpChannels(boolean decl) { root.dumpChannels(0, decl); }
- public FabricTree(InterpreterBenkoBox[] ports, String component, String prefix) {
- this.prefix = prefix;
- root = (Node)mkNode("", component, ports, 0, ports.length, 0, 0);
- }
- private Object mkNode(String name, String component, InterpreterBenkoBox[] ports,
- int start, int end, int addr, int bits) {
- if (end-start == 0) return null;
- if (end-start == 1) {
- InterpreterBenkoBox p = ports[start];
- if (prefix.equals("instruction")) {
- p.instr_addr = addr;
- p.instr_bits = bits;
- } else {
- p.addr = addr;
- p.bits = bits;
- }
- return p;
- }
- int len = end-start;
- return new Node(name,
- component,
- mkNode(name+"_0", component, ports, start, start+len/2, addr, bits+1),
- mkNode(name+"_1", component, ports, start+len/2, end, addr | (1 << bits), bits+1),
- addr,
- bits);
- }
- private String describe(String prefix, Object o) {
- if (o==null) return null;
- if (o instanceof InterpreterBenkoBox) {
- InterpreterBenkoBox p = (InterpreterBenkoBox)o;
- return prefix+"_"+getUniqueName(p.getShip())+"_"+p.getName();
- }
- if (o instanceof Node) {
- return ((Node)o).describe(prefix);
- }
- return null;
- }
- private class Node {
- Object left;
- Object right;
- String name;
- String component;
- int addr;
- int bits;
- public Node(String name, String component, Object left, Object right, int addr, int bits) {
- this.left = left;
- this.right = right;
- this.name = name;
- this.component = component;
- this.addr = addr;
- this.bits = bits;
- }
- public void dumpChannels(int indentamount, boolean decl) {
- String indent = "";
- for(int i=0; i<indentamount; i++) indent += " ";
- if (decl) {
- String n = describe(prefix).startsWith("instruction")
- ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
- System.out.println(" wire "+n+" "+indent+describe(prefix)+";");
- } else {
- System.out.println(" "+indent+
- component+" "+
- "krunk"+(krunk++)+"(clk, "+
- describe(prefix)+"_r, "+
- describe(prefix)+"_a, "+
- describe(prefix)+", "+
- FabricTree.this.describe(prefix, left)+"_r, "+
- FabricTree.this.describe(prefix, left)+"_a, "+
- FabricTree.this.describe(prefix, left)+", "+
- FabricTree.this.describe(prefix, right)+"_r, "+
- FabricTree.this.describe(prefix, right)+"_a, "+
- FabricTree.this.describe(prefix, right)+
- ");");
- }
- dumpChannels(left, indentamount+1, decl);
- dumpChannels(right, indentamount+1, decl);
- }
- public void dumpChannels(Object o, int indentamount, boolean decl) {
- if (o==null) return;
- if (o instanceof Node) {
- ((Node)o).dumpChannels(indentamount, decl);
- } else {
- String indent = "";
- for(int i=0; i<indentamount; i++) indent += " ";
- if (decl) {
- String n = FabricTree.this.describe(prefix,o).startsWith("instruction")
- ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
- System.out.println(" wire "+n+" "+indent+FabricTree.this.describe(prefix,o)+";");
- }
- }
- }
- public String describe(String prefix) {
- return prefix+name;
- }
- }
- }
- public static int krunk=0;
-
- public int computeOffset(int origin, int target) { return target - origin; }
- public int computeTarget(int origin, int offset) { return origin + offset; }
}
+