de-staticize references in Context.java
authoradam <adam@megacz.com>
Mon, 3 Nov 2008 10:03:27 +0000 (11:03 +0100)
committeradam <adam@megacz.com>
Mon, 3 Nov 2008 10:03:27 +0000 (11:03 +0100)
src/edu/berkeley/fleet/ir/Context.java
src/edu/berkeley/fleet/ir/New.java

index e4b0fe6..ac43956 100644 (file)
@@ -7,7 +7,13 @@ import edu.berkeley.fleet.api.Instruction.*;
 import edu.berkeley.fleet.api.Instruction.Set;
 import edu.berkeley.fleet.api.Instruction.Set.*;
 import static edu.berkeley.fleet.util.BitManipulations.*;
-import static edu.berkeley.fleet.two.FleetTwoFleet.SHIFT;
+
+// QUESTION: does each dock mentioned by a context have a linear chain
+// of loops, or can it branch?
+
+//    - or should we use "sub-contexts" for that
+//        - advantage: it lets us convey the fact that a bunch of loops are dispatched together
+//    - should loops have an "invoke context" opcode?
 
 /**
  *  A Context is a collection of Loops which obey these rules:
@@ -21,7 +27,8 @@ public class Context {
 
     private HashSet<LoopFactory> loopFactories = new HashSet<LoopFactory>();
 
-    public Context() { }
+    public final Fleet fleet;
+    public Context(Fleet fleet) { this.fleet = fleet; }
 
     /**
      *
@@ -184,17 +191,18 @@ public class Context {
         /** sets the data latch to a literal value */
         public void literal(long literal) {
             flush_pending();
-            if (FleetTwoFleet.isSmallEnoughToFit(literal)) {
+            if (((FleetTwoFleet)fleet).isSmallEnoughToFit(literal)) {
                 instructions.add(new Instruction.Set(dock, count!=1, predicate, SetDest.DataLatch, literal));
             } else {
                 int counter = 0;
-                while(counter < dock.getShip().getFleet().getWordWidth()) counter += SHIFT.valmaskwidth;
-                warn("literal " + literal + " requires " + counter + " instructions");
+                int extra = 0;
+                while(counter < dock.getShip().getFleet().getWordWidth()) { extra++; counter += fleet.getShiftWidth(); }
+                warn("literal " + literal + " requires " + extra + " instructions");
                 while(counter > 0) {
                     instructions.add(new Shift(dock, count!=1, predicate,
                                                new BitVector(dock.getShip().getFleet().getWordWidth())
-                                               .set(getField(counter-1, counter-SHIFT.valmaskwidth, literal))));
-                    counter -= SHIFT.valmaskwidth;
+                                               .set(getField(counter-1, counter-fleet.getShiftWidth(), literal))));
+                    counter -= fleet.getShiftWidth();
                 }
             }
         }
index db520ab..2478c46 100644 (file)
@@ -16,9 +16,11 @@ import java.net.*;
 public class New {
 
     public final Fleet fleet;
-    public New(Fleet fleet) { this.fleet = fleet; }
-
-    private Context context = new Context();
+    private Context context;
+    public New(Fleet fleet) {
+        this.fleet = fleet;
+        this.context = new Context(fleet);
+    }
 
     private HashSet<Segment> segments = new HashSet<Segment>();
     private HashSet<Ship> allocated = new HashSet<Ship>();