eliminate ShipDescription.Constant class, use BitVector instead
[fleet.git] / src / edu / berkeley / fleet / assembler / Parser.java
index e43b035..78049db 100644 (file)
@@ -291,7 +291,7 @@ public class Parser {
         }
     }
 
-    private long parseSSL(Tree t) {
+    private BitVector parseSSL(Tree t) {
         String shipType = name(t.child(0));
         String portName = name(t.child(1));
         Ship chosenship = null;
@@ -305,14 +305,12 @@ public class Parser {
         Dock chosenport = chosenship.getDock(portName);
         Tree specs = t.child(2);
         long literal = 0;
-        for(int i=0; i<specs.size(); i++) {
-            Tree tt = specs.child(i);
-            literal |= resolveLiteral(chosenport, stringBody(tt));
-        }
-        return literal;
+        if (specs.size() != 1) throw new RuntimeException("multiple constants not supported");
+        Tree tt = specs.child(0);
+        return resolveLiteral(chosenport, stringBody(tt));
     }
 
-    private static long resolveLiteral(Dock dd, String s) {
+    private static BitVector resolveLiteral(Dock dd, String s) {
         long val = 0;
         long ret = 0;
         boolean hasval = false;
@@ -321,13 +319,7 @@ public class Parser {
             s = s.substring(0, s.indexOf('='));
             hasval = true;
         }
-        ShipDescription.Constant c = ((FleetTwoDock)dd).getDockConstant(s);
-        if (c==null) throw new RuntimeException("no constant " + s + " on dock " + dd);
-        ret |= c.setbits;
-        ret &= ~c.clearbits;
-        if (hasval)
-            ret |= ((~(0xffffffffffffffffL << c.numberWidth)) & val) << c.numberOffset;
-        return ret;
+        return ((FleetTwoDock)dd).getDockConstant(s);
     }
 
     private static FlagFunction parseFlags(Tree<String> t) {
@@ -417,7 +409,7 @@ public class Parser {
                     cb.add(new Abort(dock, predicate));
                     continue;
                 } else if ("word".equals(tt.head())) {
-                    long literal = 0;
+                    BitVector literal = null;
                     if (tt.child(0).head().equals("CodeBagBody")) {
                         Tree<String> tq = tt;
                         CodeBag cb2 = getCodeBag("anon"+(anoncount++));
@@ -433,28 +425,22 @@ public class Parser {
                     } else if (tt.child(0).head().equals("[")) {
                         literal = parseSSL(tt.child(0));
                     } else {
-                        literal = number(tt.child(0));
+                        literal = new BitVector(dock.getShip().getFleet().getWordWidth()).set(number(tt.child(0)));
                     }
                     count = 1;
-                    /*
-                    if ("int".equals(tt.child(1).head())) {
-                        count = (int)number(tt.child(1));
-                    } else if ("forever".equals(tt.child(1).head())) {
-                        count = 0;
-                    }
-                    */
-
 
                     if (((FleetTwoFleet)fleet).isSmallEnoughToFit(literal)) {
-                        cb.add(new Set(dock, predicate, SetDest.DataLatch, (literal)));
+                        cb.add(new Set(dock, predicate, SetDest.DataLatch, literal.toLong()));
                     } else {
                         int counter = 0;
                         while(counter < dock.getShip().getFleet().getWordWidth()) counter += fleet.getShiftWidth();
-                        while(counter > 0) {
-                            cb.add(new Shift(dock, predicate,
-                                             new BitVector(dock.getShip().getFleet().getShiftWidth())
-                                             .set(getField(counter-1, counter-fleet.getShiftWidth(), literal))));
+                        while(true) {
                             counter -= fleet.getShiftWidth();
+                            if (counter < 0) break;
+                            BitVector bv = new BitVector(dock.getShip().getFleet().getShiftWidth());
+                            for(int i=0; i<fleet.getShiftWidth(); i++)
+                                bv.set(i, literal.get(counter+i));
+                            cb.add(new Shift(dock, predicate, bv));
                         }
                     }