add flush instruction to parser, grammar, and api
authoradam <adam@megacz.com>
Mon, 27 Oct 2008 06:34:38 +0000 (07:34 +0100)
committeradam <adam@megacz.com>
Mon, 27 Oct 2008 06:34:38 +0000 (07:34 +0100)
src/edu/berkeley/fleet/api/Instruction.java
src/edu/berkeley/fleet/assembler/Parser.java
src/edu/berkeley/fleet/assembler/fleet.g
src/edu/berkeley/fleet/two/FleetTwoFleet.java

index 014f4d8..eb7a83e 100644 (file)
@@ -222,6 +222,15 @@ public abstract class Instruction {
         public String toString() { return super.toString()+"shift "+immediate; }
     }
 
+    public static class Flush extends Instruction {
+        public Flush(Dock dock) { this(dock, false, Predicate.Default); }
+        public Flush(Dock dock, boolean looping, Predicate predicate) {
+            super(dock, looping, predicate);
+            if (!dock.isInputDock()) throw new RuntimeException("Flush is only allowed at input docks");
+        }
+        public String toString() { return super.toString()+"flush"; }
+    }
+
     /** all communication is performed with this instruction */
     public static class Move extends Instruction {
 
index 5cd4781..2203220 100644 (file)
@@ -412,6 +412,10 @@ public class Parser {
                 } else if ("shift".equals(tt.head())) {
                     cb.add(new Shift(dock, looping, predicate,
                                      new BitVector(dock.getShip().getFleet().getWordWidth()).set(number(tt.child(0)))));
+                    continue;
+                } else if ("flush".equals(tt.head())) {
+                    cb.add(new Flush(dock, looping, predicate));
+                    continue;
                 } else if ("word".equals(tt.head())) {
                     long literal = 0;
                     if (tt.child(0).head().equals("CodeBagBody")) {
index 0ad2b11..1a7a87a 100644 (file)
@@ -30,6 +30,7 @@ InstructionX    = (() | ^"[T]" ws) ^"nop"
                 |                   "set" ^"flags" "a" "=" Flags "," "b" "=" Flags   ";" /ws
                 |                   "set" ^"word"      "=" Literal                   ";" /ws
                 |              ^"shift" Literal                                      ";" /ws
+                |              ^"flush"                                              ";" /ws
 
 Flags:: = (^"0") |  (^"1") | (^"a" |  ^"b" |  ^"c" | ^"!a" | ^"!b" | ^"!c") +/ (ws "|" ws)
 
index 24dd7c9..e6af7f8 100644 (file)
@@ -143,6 +143,8 @@ public abstract class FleetTwoFleet extends Fleet {
         if (P_NOT_B.get(inst))  predicate = NotFlagB;
 
         boolean looping = !OS.get(inst);
+        if (FLUSH.get(inst))
+            return new Flush(dock, looping, predicate);
         if (SHIFT.get(inst))                return new Shift(dock, looping, predicate, new BitVector(dock.getShip().getFleet().getWordWidth()).set(SHIFT.getval(inst)));
         if (SET_IMMEDIATE.get(inst)) {
             boolean extend = SET_IMMEDIATE_EXTEND.getval(inst) != 0;
@@ -226,6 +228,9 @@ public abstract class FleetTwoFleet extends Fleet {
             instr = SHIFT.set(instr);
             instr = SHIFT.setval(instr, shift.immediate);
 
+        } else if (d instanceof Flush) {
+            instr = FLUSH.set(instr);
+
         } else if (d instanceof Set) {
             Set s = (Set)d;
             switch(s.dest) {