add wat to write out raw binary assembled programs
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 29 Aug 2020 13:18:41 +0000 (14:18 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 29 Aug 2020 13:18:41 +0000 (14:18 +0100)
src/soc/simulator/program.py

index aeb33a23a170a893a0bcc4426a6bc2a774632790..17950cdaf8aab0258b5a12639dc3d3958ae99e0a 100644 (file)
@@ -110,5 +110,20 @@ class Program:
         self.binfile.seek(curpos, 0)
         return size
 
+    def write_bin(self, fname):
+        self.reset()
+        data = self.binfile.read()
+        with open(fname, "wb") as f:
+            f.write(data)
+
     def close(self):
         self.binfile.close()
+
+if __name__ == '__main__':
+    lst = ['addi 5, 0, 4660',
+           'mtcrf 255, 5',
+           'mfocrf 2, 1',
+           'attn',
+          ]
+    with Program(lst, False) as p:
+        p.write_bin("/tmp/test.bin")