1 package edu.berkeley.fleet.slipway;
2 import edu.berkeley.fleet.interpreter.*;
3 import edu.berkeley.fleet.api.*;
4 import edu.berkeley.fleet.ies44.*;
5 import edu.berkeley.fleet.*;
6 import java.lang.reflect.*;
7 import edu.berkeley.sbp.chr.*;
8 import edu.berkeley.sbp.misc.*;
9 import edu.berkeley.sbp.meta.*;
10 import edu.berkeley.sbp.bind.*;
11 import edu.berkeley.sbp.util.*;
14 import edu.berkeley.fleet.ships.*;
16 public class Slipway extends Interpreter {
19 createShip("Alu2", "alu2a");
20 createShip("Alu2", "alu2b");
21 createShip("Alu2", "alu2c");
22 createShip("Alu2", "alu2d");
23 createShip("Debug", "debug");
24 createShip("Execute", "execute");
25 createShip("Fifo", "fifo1");
26 createShip("Fifo", "fifo2");
27 createShip("Fifo", "fifo3");
28 createShip("Fifo", "fifo4");
29 createShip("Icache", "icache1");
30 createShip("Icache", "icache2");
31 createShip("Dcache", "dcache1");
32 createShip("Dcache", "dcache2");
35 public void dumpFabric(boolean quiet) {
36 // FIXME: this is really ugly: the order of port declarations in
37 // the XXXShip.java file must match the order in the .balsa file!
39 ArrayList instructionports = new ArrayList<InterpreterBenkoBox>();
40 for(InterpreterShip ship : shiplist)
41 for(BenkoBox port : ship.getBenkoBoxes())
42 if (!((InterpreterBenkoBox)port).special())
43 instructionports.add(port);
44 FabricTree instructions =
45 new FabricTree((InterpreterBenkoBox[])instructionports.toArray(new InterpreterBenkoBox[0]),
49 ArrayList inputports = new ArrayList<InterpreterBenkoBox>();
50 for(InterpreterShip ship : shiplist)
51 for(BenkoBox port : ship.getBenkoBoxes())
52 if (!((InterpreterBenkoBox)port).special())
55 new FabricTree((InterpreterBenkoBox[])inputports.toArray(new InterpreterBenkoBox[0]),
59 ArrayList outputports = new ArrayList<InterpreterBenkoBox>();
60 for(InterpreterShip ship : shiplist)
61 for(BenkoBox port : ship.getBenkoBoxes())
62 if (!((InterpreterBenkoBox)port).special() || ((InterpreterBenkoBox)port).dhorn())
63 outputports.add(port);
65 new FabricTree((InterpreterBenkoBox[])outputports.toArray(new InterpreterBenkoBox[0]),
69 ArrayList ihornports = new ArrayList<InterpreterBenkoBox>();
70 for(InterpreterShip ship : shiplist)
71 for(BenkoBox port : ship.getBenkoBoxes())
72 if (((InterpreterBenkoBox)port).ihorn())
75 new FabricTree((InterpreterBenkoBox[])ihornports.toArray(new InterpreterBenkoBox[0]),
80 System.out.println("`include \"macros.v\"");
81 System.out.println("module fabric(clk, data_Icache0_command_r, data_Icache0_command_a, data_Icache0_command,");
82 System.out.println(" data_Debug0_out_r, data_Debug0_out_a, data_Debug0_out);");
83 System.out.println(" input clk;");
84 System.out.println(" input data_Icache0_command_r;");
85 System.out.println(" output data_Icache0_command_a;");
86 System.out.println(" output data_Debug0_out_r;");
87 System.out.println(" input data_Debug0_out_a;");
88 System.out.println(" output [(`PACKET_WIDTH-1):0] data_Debug0_out;");
89 System.out.println(" input [(`PACKET_WIDTH-1):0] data_Icache0_command;");
90 //System.out.println(" wire [(`INSTRUCTION_WIDTH-1):0] data_Icache0_ihorn;");
91 //System.out.println(" wire [(`PACKET_WIDTH-1):0] data_Icache0_dhorn;");
96 instructions.dumpChannels(true);
97 outputs.dumpChannels(true);
98 inputs.dumpChannels(true);
99 ihorns.dumpChannels(true);
100 for(InterpreterShip ship : shiplist)
101 for(BenkoBox port : ship.getBenkoBoxes())
102 if (!((InterpreterBenkoBox)port).special() || ((InterpreterBenkoBox)port).dhorn())
103 System.out.println(" wire [(`PACKET_WIDTH-1):0] data_"
104 +getUniqueName(ship)+"_"+port.getName()+";");
106 System.out.println("");
107 instructions.dumpChannels(false);
108 System.out.println("");
109 outputs.dumpChannels(false);
110 System.out.println("");
111 inputs.dumpChannels(false);
112 System.out.println("");
113 ihorns.dumpChannels(false);
114 System.out.println("");
115 for(InterpreterShip ship : shiplist) {
116 System.out.print(ship.getClass().getSimpleName().toLowerCase());
117 System.out.print(" ");
118 System.out.print("krunk"+(krunk++));
119 System.out.print("(clk, ");
120 boolean first = true;
121 for(BenkoBox port : ship.getBenkoBoxes()) {
122 if (!first) System.out.print(", ");
124 String prefix = "data_";
125 if (((InterpreterBenkoBox)port).ihorn()) prefix = "ihorn_";
126 if (((InterpreterBenkoBox)port).dhorn()) prefix = "source_";
127 System.out.print(prefix+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
128 System.out.print(prefix+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
129 System.out.print(prefix+getUniqueName(port.getShip())+"_"+port.getName());
130 System.out.print(" ");
132 System.out.println(");");
134 for(BenkoBox port : ship.getBenkoBoxes()) {
135 if (((InterpreterBenkoBox)port).special()) continue;
136 if (port instanceof Inbox) {
137 System.out.print("inbox");
139 System.out.print("outbox");
141 System.out.print(" krunk"+(krunk++)+"(clk, ");
142 System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
143 System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
144 System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
145 System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
146 System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
147 System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
148 System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
149 System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
150 System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
151 System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
152 System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
153 System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName());
154 System.out.print(");");
155 System.out.println();
160 System.out.println("funnel topfun(clk,"+
161 " dest_r, dest_a, dest,"+
162 " source_r, source_a, source,"+
163 " data_Icache0_dhorn_r, data_Icache0_dhorn_a, data_Icache0_dhorn);");
165 System.out.println("assign instruction_r = ihorn_r;");
166 System.out.println("assign ihorn_a = instruction_a;");
167 System.out.println("assign instruction = ihorn;");
168 System.out.println("assign dest_r = source_r;");
169 System.out.println("assign source_a = dest_a;");
170 System.out.println("assign dest = source;");
171 System.out.println("endmodule");
174 private static class FabricTree {
178 public void dumpChannels(boolean decl) { root.dumpChannels(0, decl); }
179 public FabricTree(InterpreterBenkoBox[] ports, String component, String prefix) {
180 this.prefix = prefix;
181 root = (Node)mkNode("", component, ports, 0, ports.length, 0, 0);
183 private Object mkNode(String name, String component, InterpreterBenkoBox[] ports,
184 int start, int end, int addr, int bits) {
185 if (end-start == 0) return null;
186 if (end-start == 1) {
187 InterpreterBenkoBox p = ports[start];
188 if (prefix.equals("instruction")) {
191 } else if (prefix.equals("dest")) {
198 return new Node(name,
200 mkNode(name+"_0", component, ports, start, start+len/2, addr, bits+1),
201 mkNode(name+"_1", component, ports, start+len/2, end, addr | (1 << bits), bits+1),
205 private String describe(String prefix, Object o) {
206 if (o==null) return null;
207 if (o instanceof InterpreterBenkoBox) {
208 InterpreterBenkoBox p = (InterpreterBenkoBox)o;
209 return prefix+"_"+getUniqueName(p.getShip())+"_"+p.getName();
211 if (o instanceof Node) {
212 return ((Node)o).describe(prefix);
223 public Node(String name, String component, Object left, Object right, int addr, int bits) {
227 this.component = component;
231 public void dumpChannels(int indentamount, boolean decl) {
233 for(int i=0; i<indentamount; i++) indent += " ";
235 String n = describe(prefix).startsWith("instruction")
236 ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
237 System.out.println(" wire "+n+" "+indent+describe(prefix)+";");
239 System.out.println(" "+indent+
241 "krunk"+(krunk++)+"(clk, "+
242 describe(prefix)+"_r, "+
243 describe(prefix)+"_a, "+
244 describe(prefix)+", "+
245 FabricTree.this.describe(prefix, left)+"_r, "+
246 FabricTree.this.describe(prefix, left)+"_a, "+
247 FabricTree.this.describe(prefix, left)+", "+
248 FabricTree.this.describe(prefix, right)+"_r, "+
249 FabricTree.this.describe(prefix, right)+"_a, "+
250 FabricTree.this.describe(prefix, right)+
253 dumpChannels(left, indentamount+1, decl);
254 dumpChannels(right, indentamount+1, decl);
256 public void dumpChannels(Object o, int indentamount, boolean decl) {
258 if (o instanceof Node) {
259 ((Node)o).dumpChannels(indentamount, decl);
262 for(int i=0; i<indentamount; i++) indent += " ";
264 String n = FabricTree.this.describe(prefix,o).startsWith("instruction")
265 ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
266 System.out.println(" wire "+n+" "+indent+FabricTree.this.describe(prefix,o)+";");
270 public String describe(String prefix) {
275 public static int krunk=0;
277 private static String getUniqueName(Ship ship) {
278 return ship.getType() + ship.getOrdinal();