checkpoint
[fleet.git] / src / edu / berkeley / fleet / CodeBag.java
index 64edd4b..fb7325a 100644 (file)
@@ -1,6 +1,7 @@
 package edu.berkeley.fleet;
 
 import java.util.*;
+import java.io.*;
 
 /** a codebag */
 public class CodeBag {
@@ -53,6 +54,39 @@ public class CodeBag {
         return parent.getCodeBag(name);
     }
 
+    public void dump(OutputStream os, int data) throws Exception {
+        os.write((byte)data);
+        System.out.print(data+" ");
+    }
+    public void dump(Fleet fleet) throws Exception {
+        OutputStream os = new FileOutputStream("fleet.bin");
+        for(Dispatchable d : dispatchables) {
+            if (d instanceof Instruction) {
+                Instruction inst = (Instruction)d;
+                dump(os, inst.source.resolve(fleet).instr_bits);
+                dump(os, inst.source.resolve(fleet).instr_addr);
+                dump(os, 5);
+                dump(os, 10); // input+output
+                dump(os, inst.destination.resolve(fleet).bits);
+                dump(os, inst.destination.resolve(fleet).addr);
+                dump(os, 0);
+                System.out.println();
+            } else if (d instanceof Literal.LiteralDatum) {
+                Literal.LiteralDatum ld = (Literal.LiteralDatum)d;
+                dump(os, ld.destination.resolve(fleet).instr_bits);
+                dump(os, ld.destination.resolve(fleet).instr_addr);
+                dump(os, 5);
+                dump(os, 2);
+                dump(os, 32);
+                dump(os, ld.data);
+                dump(os, 0);
+                System.out.println();
+            }
+        }
+        os.flush();
+        os.close();
+    }
+
     public String toString() {
         if (name != null) return name;
         StringBuffer ret = new StringBuffer();