remove superfluous computeOffset() and computeTarget()
authoradam <adam@megacz.com>
Mon, 12 Feb 2007 15:40:30 +0000 (16:40 +0100)
committeradam <adam@megacz.com>
Mon, 12 Feb 2007 15:40:30 +0000 (16:40 +0100)
src/edu/berkeley/fleet/api/Fleet.java
src/edu/berkeley/fleet/assembler/Parser.java

index 991bd01..6391bf5 100644 (file)
@@ -14,20 +14,6 @@ public abstract class Fleet implements Iterable<Ship> {
     /** ships must be returned in the same order every time -- ordering may be significant */
     public abstract Iterator<Ship> iterator();
 
-    /**
-     *  Compute the value that should go in the MACHINE-addressed
-     *  "offset" field of a literal given BYTE-addressed origin and
-     *  target
-     */ 
-    public abstract int computeOffset(int origin, int target);
-
-    /**
-     *  Compute the value that should go in the "offset" field of a
-     *  literal given BYTE-addressed origin and MACHINE-addressed
-     *  target
-     */ 
-    public abstract int computeTarget(int origin, int offset);
-
     /** if possible, run the given code and create a FleetProcess */
     public FleetProcess run(byte[] code) {
         throw new RuntimeException("class " + this.getClass().getName() + " does not implement method run()");
index f39f869..60550e2 100644 (file)
@@ -64,17 +64,21 @@ public class Parser {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         CountingOutputStream cos   = new CountingOutputStream(baos);
         DataOutputStream dos       = new DataOutputStream(cos);
+        int count = 0;
         for(int i=0; i<codeBags.size(); i++) {
             CodeBag c = codeBags.get(i);
             dos.flush();
-            codeBagMap[i] = cos.getCount();
-            for(Instruction inst : c)
+            codeBagMap[i] = count;//cos.getCount();
+            for(Instruction inst : c) {
                 fleet.writeInstruction(dos, inst);
+                count++;
+            }
         }
 
         // now write for real
         cos = new CountingOutputStream(out);
         dos = new DataOutputStream(cos);
+        count = 0;
         for(int i=0; i<codeBags.size(); i++) {
             CodeBag c = codeBags.get(i);
             dos.flush();
@@ -83,12 +87,13 @@ public class Parser {
                     dos.flush();
                     cos.getCount();
                     Instruction.Literal.CodeBagDescriptor old = (Instruction.Literal.CodeBagDescriptor)inst;
-                    int offset = fleet.computeOffset(cos.getCount(), codeBagMap[(int)old.offset]);
+                    int offset = codeBagMap[(int)old.offset] - count;
                     inst = new Instruction.Literal.CodeBagDescriptor(old.dest,
                                                                      offset,
                                                                      codeBags.get((int)old.offset).size());
                 }
                 fleet.writeInstruction(dos, inst);
+                count++;
             }
         }
         dos.flush();