From: adam Date: Mon, 5 Feb 2007 19:09:02 +0000 (+0100) Subject: major software code reorg X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=86b6d13d49e86dd0b44f08d6330a5ffe0fd74b0e;p=fleet.git major software code reorg --- diff --git a/src/edu/berkeley/fleet/api/Fleet.java b/src/edu/berkeley/fleet/api/Fleet.java index 6546d17..c40b2db 100644 --- a/src/edu/berkeley/fleet/api/Fleet.java +++ b/src/edu/berkeley/fleet/api/Fleet.java @@ -27,4 +27,12 @@ public abstract class Fleet implements Iterable { */ public abstract int computeTarget(int origin, int offset); + /** + * This interface marks Fleets which can create ships on the fly, like the fleeterpreter; + * if available, the parser will use this interface to create ships out of #ship definitions. + */ + public static interface WithDynamicShips { + public Ship createShip(String shiptype, String shipname); + } + } \ No newline at end of file diff --git a/src/edu/berkeley/fleet/assembler/Main.java b/src/edu/berkeley/fleet/assembler/Main.java index 6b81c8b..0b98b42 100644 --- a/src/edu/berkeley/fleet/assembler/Main.java +++ b/src/edu/berkeley/fleet/assembler/Main.java @@ -12,10 +12,4 @@ public class Main { new Parser(fleet).parse(r, out); } - /** parse the assembly code on r, encode it for fleet, and insert - * Instructions into out */ - public static void assemble(Fleet fleet, Reader r, ArrayList out) throws Exception { - new Parser(fleet).parse(r, out); - } - } \ No newline at end of file diff --git a/src/edu/berkeley/fleet/assembler/Parser.java b/src/edu/berkeley/fleet/assembler/Parser.java index 2b2dc45..e8b7f37 100644 --- a/src/edu/berkeley/fleet/assembler/Parser.java +++ b/src/edu/berkeley/fleet/assembler/Parser.java @@ -30,6 +30,12 @@ class Parser { // codebags in numerical order private ArrayList codeBags = new ArrayList(); private HashMap codeBagsByName = new HashMap(); + + private CodeBag getCodeBag(String name) { + CodeBag cb = codeBagsByName.get(name); + if (cb!=null) return cb; + return new CodeBag(name); + } Tree parse(Reader r) throws Exception { InputStream grammarStream = @@ -49,7 +55,9 @@ class Parser { CodeBag rootCodeBag = new CodeBag(); baseCodeBag.add(new Instruction.Literal.CodeBagDescriptor(null, rootCodeBag.getFakeAddress(), 1)); walk((Tree)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(); @@ -64,8 +72,8 @@ class Parser { } // 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 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)parse(r), rootCodeBag); - - // map from arbitrary identifiers to actual addresses - int[] codeBagMap = new int[codeBags.size()]; - ArrayList temp = new ArrayList(); - for(int i=0; i numAllocated = new HashMap(); + Ship allocateShip(String shipType) { int allocated = 0; if (numAllocated.get(shipType) != null) @@ -215,7 +190,7 @@ class Parser { void fillCodeBag(Tree 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 statement : t.child(1)) fillCodeBag(statement, cb2); @@ -224,6 +199,12 @@ class Parser { 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)); diff --git a/src/edu/berkeley/fleet/interpreter/DataInbox.java b/src/edu/berkeley/fleet/interpreter/DataInbox.java index ed1f6c2..869a734 100644 --- a/src/edu/berkeley/fleet/interpreter/DataInbox.java +++ b/src/edu/berkeley/fleet/interpreter/DataInbox.java @@ -8,15 +8,8 @@ public class DataInbox extends Inbox { public DataInbox(InterpreterShip ship, String name) { super(ship, name); } - public DataInbox(InterpreterShip ship, String name, boolean noInbox, boolean noChannelDef) { + public DataInbox(InterpreterShip ship, String name, boolean special) { super(ship, name); - this.noInbox = noInbox; - this.noChannelDef = noChannelDef; - } - public DataInbox(InterpreterShip ship, String name, boolean noInbox, boolean noChannelDef, boolean special) { - super(ship, name); - this.noInbox = noInbox; - this.noChannelDef = noChannelDef; this.special = special; } diff --git a/src/edu/berkeley/fleet/interpreter/DataOutbox.java b/src/edu/berkeley/fleet/interpreter/DataOutbox.java index e524417..0292499 100644 --- a/src/edu/berkeley/fleet/interpreter/DataOutbox.java +++ b/src/edu/berkeley/fleet/interpreter/DataOutbox.java @@ -6,6 +6,10 @@ public class DataOutbox extends Outbox { public DataOutbox(InterpreterShip ship, String name) { super(ship, name); } public DataOutbox(InterpreterShip ship, String name, boolean special) { super(ship, name); this.special = special; } + public DataOutbox(InterpreterShip ship, String name, boolean special, boolean ihorn) { + super(ship, name); this.special = special; this.ihorn = ihorn; } + public DataOutbox(InterpreterShip ship, String name, boolean special, boolean ihorn, boolean dhorn) { + super(ship, name); this.special = special; this.ihorn = ihorn; this.dhorn = dhorn; } private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); } public void addDataFromShip(int data) { diff --git a/src/edu/berkeley/fleet/interpreter/Interpreter.java b/src/edu/berkeley/fleet/interpreter/Interpreter.java index 789a314..2e934a3 100644 --- a/src/edu/berkeley/fleet/interpreter/Interpreter.java +++ b/src/edu/berkeley/fleet/interpreter/Interpreter.java @@ -1,54 +1,84 @@ 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 { +public class Interpreter extends Fleet /*, Fleet.WithDynamicShips*/ { + + /** some "halt ship" can turn this on to stop the interpreter */ + public boolean halt = false; + + public ArrayList shiplist = new ArrayList(); + public HashMap ships = new HashMap(); + + 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> 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 { @@ -56,104 +86,66 @@ public class Interpreter extends Fleet implements Iterable { } } - /** 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 imports = new ArrayList(); - private static String getUniqueName(Ship ship) { - return ship.getType() + ship.getOrdinal(); - } + // Implementation of the Fleet class abstract methods ///////////////////////////////////////////////////////// - public ArrayList shiplist = new ArrayList(); - public HashMap ships = new HashMap(); + public Iterator iterator() { return (Iterator)(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 iterator() { - return (Iterator)(Object)shiplist.iterator(); } - public void dispatchCodeBag(long base, long size) { - for(long i=base; i { 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(); - 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(); - 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(); - 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 added = new HashSet(); - 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 arr = new ArrayList(); - edu.berkeley.fleet.assembler.Main.assemble(fleet, r, arr); - fleet.instructions = (Instruction[])arr.toArray(new Instruction[0]); - + public void go() throws Exception { + Slipway fleet = new Slipway(); + if (dump_fabric) { fleet.dumpFabric(false); - - } else if (dump_code) { - fleet.dumpFabric(true); - fleet.dumpCode(fleet.instructions); - } else { - if (debugMemory) { fleet.dumpMem(); } - fleet.go(); - if (debugMemory) { fleet.dumpMem(); } + fleet.dumpFabric(true); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + edu.berkeley.fleet.assembler.Main.assemble(fleet, new InputStreamReader(System.in), baos); + if (dump_code) { + DataOutputStream dos = new DataOutputStream(new FileOutputStream("build/fleet.bin")); + dos.write(baos.toByteArray()); + dos.close(); + } else { + if (debugMemory) { fleet.dumpMem(); } + fleet.go(baos.toByteArray()); + if (debugMemory) { fleet.dumpMem(); } + } } } diff --git a/src/edu/berkeley/fleet/ships/Mem.java b/src/edu/berkeley/fleet/ships/Dcache.java similarity index 52% rename from src/edu/berkeley/fleet/ships/Mem.java rename to src/edu/berkeley/fleet/ships/Dcache.java index caa6ac3..c570f87 100644 --- a/src/edu/berkeley/fleet/ships/Mem.java +++ b/src/edu/berkeley/fleet/ships/Dcache.java @@ -5,7 +5,7 @@ import edu.berkeley.fleet.*; import java.util.*; import java.io.*; -public class Mem extends InterpreterShip { +public class Dcache extends InterpreterShip { DataInbox read_addr = new DataInbox(this, "read_addr"); DataOutbox read_data = new DataOutbox(this, "read_data"); @@ -13,26 +13,33 @@ public class Mem extends InterpreterShip { DataInbox write_data = new DataInbox(this, "write_data"); TokenOutbox write_done = new TokenOutbox(this, "write_done"); - public Mem(Interpreter fleet, String name) { super(fleet, name); } + public Dcache(Interpreter fleet, String name) { super(fleet, name); } - public String getBalsaName() { return "mem"; } + public String getBalsaName() { return "dcache"; } + + private long[] mem = new long[0]; + public long readMem(int addr) { return mem[addr]; } + public void writeMem(int addr, long val) { + if (addr >= mem.length) { + long[] newmem = new long[addr * 2 + 1]; + System.arraycopy(mem, 0, newmem, 0, mem.length); + mem = newmem; + } + mem[addr] = val; + } public void service() { if (read_addr.dataReadyForShip() && read_data.readyForItemFromShip()) { - Interpreter f = (Interpreter)getFleet(); - read_data.addDataFromShip(f.readMem(read_addr.removeDataForShip())); + read_data.addDataFromShip((int)readMem(read_addr.removeDataForShip())); } if (write_addr.dataReadyForShip() && write_data.dataReadyForShip() && write_done.readyForItemFromShip()) { - Interpreter f = (Interpreter)getFleet(); - f.writeMem(write_addr.removeDataForShip(), - write_data.removeDataForShip()); + writeMem(write_addr.removeDataForShip(), + write_data.removeDataForShip()); write_done.addTokenFromShip(); } - } - } diff --git a/src/edu/berkeley/fleet/ships/Debug.java b/src/edu/berkeley/fleet/ships/Debug.java index 43862e5..c6273f0 100644 --- a/src/edu/berkeley/fleet/ships/Debug.java +++ b/src/edu/berkeley/fleet/ships/Debug.java @@ -7,9 +7,8 @@ import java.io.*; public class Debug extends InterpreterShip { - //TokenInbox token = new TokenInbox(this, "token"); - DataInbox data = new DataInbox(this, "data", true, false); - DataOutbox out = new DataOutbox(this, "out", true); + DataInbox data = new DataInbox(this, "data"); + DataOutbox out = new DataOutbox(this, "out", true); public String getBalsaName() { return "debug"; } @@ -18,12 +17,6 @@ public class Debug extends InterpreterShip { } public void service() { - /* - if (token.tokenReadyForShip()) { - Log.println(Log.invert(" DEBUG: got a token"+Log.clreol())); - token.removeTokenForShip(); - } - */ if (data.dataReadyForShip()) Log.println(Log.invert(" DEBUG: got a datum: " + data.removeDataForShip()+Log.clreol())); } diff --git a/src/edu/berkeley/fleet/ships/Execute.java b/src/edu/berkeley/fleet/ships/Execute.java index 3db4f64..7880738 100644 --- a/src/edu/berkeley/fleet/ships/Execute.java +++ b/src/edu/berkeley/fleet/ships/Execute.java @@ -7,9 +7,9 @@ import java.io.*; public class Execute extends InterpreterShip { - DataInbox in = new DataInbox(this, "in", true, false, true); - DataOutbox ihorn = new DataOutbox(this, "ihorn", true); - DataOutbox dhorn = new DataOutbox(this, "dhorn", true); + DataInbox in = new DataInbox(this, "in", true); + DataOutbox ihorn = new DataOutbox(this, "ihorn", true, true, false); + DataOutbox dhorn = new DataOutbox(this, "dhorn", true, false, true); public String getBalsaName() { return "execute"; } diff --git a/src/edu/berkeley/fleet/ships/Icache.java b/src/edu/berkeley/fleet/ships/Icache.java new file mode 100644 index 0000000..11b8bbf --- /dev/null +++ b/src/edu/berkeley/fleet/ships/Icache.java @@ -0,0 +1,62 @@ +package edu.berkeley.fleet.ships; +import edu.berkeley.fleet.interpreter.*; +import edu.berkeley.fleet.*; +import edu.berkeley.fleet.api.*; + +import java.util.*; +import java.io.*; + +public class Icache extends InterpreterShip { + + DataInbox write_addr = new DataInbox(this, "write_addr"); + DataInbox write_data = new DataInbox(this, "write_data"); + TokenOutbox write_done = new TokenOutbox(this, "write_done"); + + DataInbox cbd = new DataInbox(this, "cbd"); + + // only for hardware fleet + DataInbox command = new DataInbox(this, "command", true); + DataOutbox ihorn = new DataOutbox(this, "ihorn", true, true, false); + DataOutbox dhorn = new DataOutbox(this, "dhorn", true, false, true); + + public Icache(Interpreter fleet, String name) { super(fleet, name); } + + public String getBalsaName() { return "icache"; } + + private long[] mem = new long[0]; + public long readMem(int addr) { return mem[addr]; } + public void writeMem(int addr, long val) { + if (addr >= mem.length) { + long[] newmem = new long[addr * 2 + 1]; + System.arraycopy(mem, 0, newmem, 0, mem.length); + mem = newmem; + } + mem[addr] = val; + } + + public void dispatch(int addr, int size) { + for(int i=addr; i> 6; + int size = val & 0x3f; + dispatch(addr, size); + } + + if (write_addr.dataReadyForShip() && + write_data.dataReadyForShip() && + write_done.readyForItemFromShip()) { + Interpreter f = (Interpreter)getFleet(); + f.writeMem(write_addr.removeDataForShip(), + write_data.removeDataForShip()); + write_done.addTokenFromShip(); + } + } + +}