data in: in1
data in: in2
data in: inOp
+ constant ADD: 0
+ constant SUB: 1
+ constant MAX: 2
+ constant MIN: 3
data out: out
-== Constants ========================================================
-ADD: add the two arguments; treat link as carry
-SUB: subtract the two arguments; treat link as carry
-MAX:
-MIN:
== TeX ==============================================================
This ship is a two-input arithmetic unit. It features several
8: sendto alu.in2;
8: sendto alu.in2;
-Alu2.ADD: sendto alu.inOp;
-Alu2.SUB: sendto alu.inOp;
-Alu2.MIN: sendto alu.inOp;
-Alu2.MAX: sendto alu.inOp;
+Alu2.inOp[ADD]: sendto alu.inOp;
+Alu2.inOp[SUB]: sendto alu.inOp;
+Alu2.inOp[MIN]: sendto alu.inOp;
+Alu2.inOp[MAX]: sendto alu.inOp;
alu.in1: [*] take, deliver;
alu.in2: [*] take, deliver;
/** return the BenkoBox which is the destination of this Box's shortcut (if any) */
public BenkoBox getShortcut() { return null; }
+ public abstract long resolveLiteral(String literal);
}
break;
}
}
- long literal = chosenship.resolveLiteral(portName);
+ BenkoBox chosenport = chosenship.getBenkoBox(portName);
+ Tree specs = t.child(0).child(2);
+ long literal = 0;
+ for(int i=0; i<specs.size(); i++) {
+ Tree tt = specs.child(i);
+ literal |= chosenport.resolveLiteral(string(tt));
+ }
cb.add(new Instruction.Literal.Absolute(portReference(t.child(1)), literal));
} else if (t.head().equals("Literal")) {
Source = Port
| ShipSpecific
-SSL = ShipSpecificLiteral:: shiptype "." ShipSpecificLiteral
+SSL = ShipSpecificLiteral:: shiptype "." portname "[" SSLSpec "]"
Port = Port:: shipname "." portname
| SubPort:: shipname "." portname "." portname
| ^"()"
+SSLSpec:: = SSLElement +/ ","
+SSLElement = "":: [a-zA-Z0-9=_]++
+
CodeBagBody:: = Statement +/ ws
CodeBag = CodeBagRef:: CodeBagName
| AnonymousCodeBag:: "{" CodeBagBody "}" /ws
CodeBagName = name
shipname = name
-shiptype = Name:: [A-Z] ("":: [A-Za-z0-9\[\]_]**)
-ShipSpecificLiteral = Name:: [A-Z] ("":: [A-Z0-9\[\]_]**)
-portname = Name:: [a-z] ("":: [A-Za-z0-9\[\]_]**)
-name = Name:: [A-Za-z] ("":: [A-Za-z0-9\[\]_]**)
+shiptype = Name:: [A-Z] ("":: [A-Za-z0-9_]**)
+ShipSpecificLiteral = Name:: [A-Z] ("":: [A-Z0-9_]**)
+portname = Name:: [a-z] ("":: [A-Za-z0-9_]**)
+name = Name:: [A-Za-z] ("":: [A-Za-z0-9_]**)
index = "[" ("":: [0-9]+) "]" | ("":: [0-9]+)
int = "":: [\-0-9]++
ShipSpecific = ShipSpecific:: "\"" (~[\"])++ "\""
void addDest(String dest) { destinations.add(dest); }
-
public Constant getConstant(String name) {
Constant ret = constants.get(name);
if (ret == null) ret = ship.getConstant(name);
return ret;
}
+
+ public long resolveLiteral(String s) {
+ long val = 0;
+ long ret = 0;
+ if (s.indexOf('=') != -1) {
+ val = Long.parseLong(s.substring(s.indexOf('=')+1));
+ s = s.substring(0, s.indexOf('='));
+ }
+ Constant c = getConstant(s);
+ if (c==null) throw new RuntimeException("no constant " + s + " on benkobox " + this);
+ ret |= c.setbits;
+ ret &= ~c.clearbits;
+ // FIXME: val
+ return ret;
+ }
}
}
}
- public static long resolveConstant(String exp, BenkoBoxDescription bbd) {
- long ret = 0;
- for(StringTokenizer st = new StringTokenizer(exp, ",");
- st.hasMoreTokens();) {
- String s = st.nextToken();
- long val = 0;
- if (s.indexOf('=') != -1) {
- val = Long.parseLong(s.substring(s.indexOf('=')+1));
- s = s.substring(0, s.indexOf('='));
- }
- Constant c = bbd.getConstant(s);
- if (c==null) {
- if (s.startsWith("0x")) ret |= Long.parseLong(s, 16);
- else ret |= Long.parseLong(s);
- } else {
- ret |= c.setbits;
- ret &= ~c.clearbits;
- // FIXME: val
- }
- }
- return ret;
- }
}
\ No newline at end of file
String constname = key.substring("constant".length()+1).trim();
String val = s.substring(s.indexOf(':')+1).trim();
p.constants.put(constname, new Constant(val));
+ continue;
} else if (key.startsWith("shortcut to")) {
continue;
}
package edu.berkeley.fleet.fpga;
+import edu.berkeley.fleet.doc.*;
+import edu.berkeley.fleet.api.*;
import edu.berkeley.fleet.api.*;
import edu.berkeley.fleet.api.BenkoBox;
import java.util.*;
public int addr = (default_addr++);
public int instr_bits;
public int instr_addr = (default_instr_addr++);
+ private final BenkoBoxDescription bbd;
protected boolean special = false;
protected boolean ihorn = false;
protected boolean dhorn = false;
public boolean inbox;
public boolean isInbox() { return inbox; }
public boolean isOutbox() { return !inbox; }
- public FpgaBenkoBox(boolean inbox, FpgaShip ship, String name) {
- this(inbox, ship, name, false, false, false);
+ public long resolveLiteral(String literal) {
+ return bbd.resolveLiteral(literal);
+ }
+ public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name) {
+ this(bbd, inbox, ship, name, false, false, false);
}
- public FpgaBenkoBox(boolean inbox, FpgaShip ship, String name, boolean special) {
- this(inbox, ship, name, special, false, false);
+ public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name, boolean special) {
+ this(bbd, inbox, ship, name, special, false, false);
}
- public FpgaBenkoBox(boolean inbox, FpgaShip ship, String name, boolean special, boolean ihorn, boolean dhorn) {
+ public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name, boolean special, boolean ihorn, boolean dhorn) {
+ this.bbd = bbd;
this.inbox = inbox;
this.special = special;
this.dhorn = dhorn;
public FpgaShip(Fpga fleet, String name, String type, ShipDescription sd) {
this.fleet = fleet; this.type = type;
for(BenkoBoxDescription sdbb : sd) {
- FpgaBenkoBox sbb = new FpgaBenkoBox(sdbb.isInbox(), this, sdbb.getName());
+ FpgaBenkoBox sbb = new FpgaBenkoBox(sdbb, sdbb.isInbox(), this, sdbb.getName());
for(String port : sdbb) {
if (port.equals("")) continue;
sbb.addDestination(port);
}
}
if (type.equals("Debug")) {
- new FpgaBenkoBox(false, this, "out", true);
+ new FpgaBenkoBox(null, false, this, "out", true);
} else if (type.equals("Execute")) {
- new FpgaBenkoBox(false, this, "ihorn", true, true, false);
- new FpgaBenkoBox(false, this, "dhorn", true, false, true);
+ new FpgaBenkoBox(null, false, this, "ihorn", true, true, false);
+ new FpgaBenkoBox(null, false, this, "dhorn", true, false, true);
} else if (type.equals("Memory")) {
- new FpgaBenkoBox(true, this, "command", true);
- new FpgaBenkoBox(false, this, "ihorn", true, true, false);
- new FpgaBenkoBox(false, this, "dhorn", true, false, true);
+ new FpgaBenkoBox(null, true, this, "command", true);
+ new FpgaBenkoBox(null, false, this, "ihorn", true, true, false);
+ new FpgaBenkoBox(null, false, this, "dhorn", true, false, true);
}
}
package edu.berkeley.fleet.interpreter;
import edu.berkeley.sbp.util.ANSI;
import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.doc.*;
import edu.berkeley.fleet.api.Instruction;
import java.util.*;
Class c = Class.forName("edu.berkeley.fleet.interpreter."+shipType);
Constructor con = c.getConstructor(new Class[] { Interpreter.class, String.class });
InterpreterShip ret = (InterpreterShip)con.newInstance(new Object[] { this, shipname });
+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ships/"+shipType+".ship")));
+ ShipDescription sd = new ShipDescription(shipname, br);
+ ret.setShipDescription(sd);
ships.put(shipname, ret);
return ret;
} catch (Exception e) {
package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.doc.*;
import edu.berkeley.fleet.api.*;
import edu.berkeley.fleet.api.BenkoBox;
import java.util.*;
private final InterpreterShip ship;
private final Destination[] ports;
private final int addr = max_addr++;
-
+ private BenkoBoxDescription bbd;
+
+ public void setDescription(BenkoBoxDescription bbd) {
+ this.bbd = bbd;
+ }
+ public long resolveLiteral(String literal) {
+ return bbd.resolveLiteral(literal);
+ }
+
public InterpreterBenkoBox(InterpreterShip ship, String name, String[] ports) {
this.ship = ship;
this.name = name;
package edu.berkeley.fleet.interpreter;
import edu.berkeley.fleet.api.*;
-
-import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.doc.*;
import java.util.*;
import java.io.*;
abstract class InterpreterShip extends Ship {
/** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
- public InterpreterShip(Interpreter fleet, String name, String type) { this.fleet = fleet; this.type = type; }
+ public InterpreterShip(Interpreter fleet, String name, String type) {
+ this.fleet = fleet;
+ this.type = type;
+ }
private Interpreter fleet;
private String type;
public Fleet getFleet() { return fleet; }
public Interpreter getInterpreter() { return fleet; }
+ public void setShipDescription(ShipDescription sd) {
+ for(InterpreterBenkoBox ibb : ports.values()) {
+ for(BenkoBoxDescription bbd : sd) {
+ if (bbd.getName().equals(ibb.getName()))
+ ibb.setDescription(bbd);
+ }
+ }
+ }
+
/**
* Override this method, check inboxes for the data you need, and
* if you find it, deposit results in an outbox; we'll take care
2: sendto alu.in1;
4: sendto alu.in2;
-Alu2.ADD: sendto alu.inOp;
+Alu2.inOp[ADD]: sendto alu.inOp;
alu.in1: [*] nop;
(*) take, deliver;
(*) deliver;