From f99dc1f939c24670be62e6473783a51f74fee6a3 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 17 Feb 2007 09:40:21 +0100 Subject: [PATCH] add initial support for virtual destinations --- src/edu/berkeley/fleet/api/BenkoBox.java | 9 +++++- src/edu/berkeley/fleet/api/Destination.java | 10 ++++++ src/edu/berkeley/fleet/api/Instruction.java | 34 ++++++++++---------- .../berkeley/fleet/ies44/InstructionEncoder.java | 4 +-- .../berkeley/fleet/interpreter/Interpreter.java | 2 +- tests/alu2/simple-alu2-test.fleet | 9 +++--- 6 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 src/edu/berkeley/fleet/api/Destination.java diff --git a/src/edu/berkeley/fleet/api/BenkoBox.java b/src/edu/berkeley/fleet/api/BenkoBox.java index 1e93825..5a3d9dd 100644 --- a/src/edu/berkeley/fleet/api/BenkoBox.java +++ b/src/edu/berkeley/fleet/api/BenkoBox.java @@ -1,6 +1,7 @@ package edu.berkeley.fleet.api; +import java.util.*; -public abstract class BenkoBox { +public abstract class BenkoBox extends Destination { /** you should extend subclasses, not this class directly */ //FIXME @@ -24,4 +25,10 @@ public abstract class BenkoBox { public Outbox() { } } + /** get all destinations associated with this BenkoBox */ + public Iterable getDestinations() { + HashSet self = new HashSet(); + self.add(this); + return self; + } } diff --git a/src/edu/berkeley/fleet/api/Destination.java b/src/edu/berkeley/fleet/api/Destination.java new file mode 100644 index 0000000..8bf7270 --- /dev/null +++ b/src/edu/berkeley/fleet/api/Destination.java @@ -0,0 +1,10 @@ +package edu.berkeley.fleet.api; + +public abstract class Destination { + + Destination() { } + + /** return the Ship to which this BenkoBox belongs */ + public abstract Ship getShip(); + +} diff --git a/src/edu/berkeley/fleet/api/Instruction.java b/src/edu/berkeley/fleet/api/Instruction.java index 5e3c106..5b89965 100644 --- a/src/edu/berkeley/fleet/api/Instruction.java +++ b/src/edu/berkeley/fleet/api/Instruction.java @@ -18,9 +18,9 @@ public abstract class Instruction { public static class Executable extends Instruction { - public final BenkoBox benkoBox; - public final BenkoBox dest; - public final int count; + public final BenkoBox benkoBox; + public final Destination dest; + public final int count; public final boolean tokenIn; public final boolean dataIn; @@ -30,15 +30,15 @@ public abstract class Instruction { public final boolean recycle; /** count=0 denotes a standing move */ - public Executable(BenkoBox benkoBox, - BenkoBox dest, - int count, - boolean tokenIn, - boolean dataIn, - boolean latch, - boolean dataOut, - boolean tokenOut, - boolean recycle) { + public Executable(BenkoBox benkoBox, + Destination dest, + int count, + boolean tokenIn, + boolean dataIn, + boolean latch, + boolean dataOut, + boolean tokenOut, + boolean recycle) { this.benkoBox = benkoBox; this.dest = dest; this.count = count; @@ -94,12 +94,12 @@ public abstract class Instruction { } public static class Literal extends Instruction { - public final BenkoBox dest; - protected Literal(BenkoBox dest) { this.dest = dest; } + public final Destination dest; + protected Literal(Destination dest) { this.dest = dest; } public static class Absolute extends Literal { public final long value; - public Absolute(BenkoBox dest, long value) { super(dest); this.value = value; } + public Absolute(Destination dest, long value) { super(dest); this.value = value; } public String toString() { return value + ": sendto " + dest; } @@ -108,7 +108,7 @@ public abstract class Instruction { public static class Relative extends Literal { /** value transmitted will be offset plus the address from which this instruction was loaded */ public final long offset; - public Relative(BenkoBox dest, long offset) { super(dest); this.offset = offset; } + public Relative(Destination dest, long offset) { super(dest); this.offset = offset; } public String toString() { String off = ""+offset; if (offset > 0) off = "+"+off; @@ -120,7 +120,7 @@ public abstract class Instruction { /** address of CBD, relative to address that this instruction was loaded from */ public final long offset; public final long size; - public CodeBagDescriptor(BenkoBox dest, long offset, long size) { + public CodeBagDescriptor(Destination dest, long offset, long size) { super(dest); this.offset = offset; this.size = size; } public String toString() { String off = ""+offset; diff --git a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java index e8f38a3..0e9174d 100644 --- a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java +++ b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java @@ -6,7 +6,7 @@ import java.io.*; public abstract class InstructionEncoder { /** get the bits describing this box's location on the DESTINATION HORN */ - public abstract long getBoxAddr(BenkoBox box); + public abstract long getBoxAddr(Destination box); /** get the bits describing this box's location on the INSTRUCTION HORN */ public abstract long getBoxInstAddr(BenkoBox box); @@ -91,7 +91,7 @@ public abstract class InstructionEncoder { if (d instanceof Instruction.Executable) { Instruction.Executable inst = (Instruction.Executable)d; - BenkoBox dest = inst.dest; + Destination dest = inst.dest; instr = dest==null ? 0 : (getBoxAddr(dest) << 1); if (inst.count >= (1<<8)) throw new RuntimeException("count field must be less than 128"); diff --git a/src/edu/berkeley/fleet/interpreter/Interpreter.java b/src/edu/berkeley/fleet/interpreter/Interpreter.java index 16f36b8..d78be10 100644 --- a/src/edu/berkeley/fleet/interpreter/Interpreter.java +++ b/src/edu/berkeley/fleet/interpreter/Interpreter.java @@ -206,7 +206,7 @@ public class Interpreter extends Fleet { public void writeInstruction(DataOutputStream os, Instruction d) throws IOException { iie.writeInstruction(os, d); } private class InterpreterInstructionEncoder extends InstructionEncoder { - public long getBoxAddr(BenkoBox box) { return ((InterpreterBenkoBox)box).addr; } + public long getBoxAddr(Destination 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) diff --git a/tests/alu2/simple-alu2-test.fleet b/tests/alu2/simple-alu2-test.fleet index 965d80a..9ca5d4d 100644 --- a/tests/alu2/simple-alu2-test.fleet +++ b/tests/alu2/simple-alu2-test.fleet @@ -22,8 +22,7 @@ Alu2.SUB: sendto alu.inOp; Alu2.MIN: sendto alu.inOp; Alu2.MAX: sendto alu.inOp; -alu.in1: [*] take, deliver; -alu.in2: [*] take, deliver; -alu.inOp: [*] take, deliver; -alu.out: - [*] take, sendto debug.in; +alu.in1: [*] take, deliver; +alu.in2: [*] take, deliver; +alu.inOp: [*] take, deliver; +alu.out: [*] take, sendto debug.in; -- 1.7.10.4