get instructions immediately from assembly code
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 18 Jun 2020 10:26:10 +0000 (11:26 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 18 Jun 2020 10:26:10 +0000 (11:26 +0100)
src/soc/simulator/program.py

index cd515a8d0ebd175094913ad2ce1c47a3c481a399..fdcea64201580ab7432f767f6a16c1c6d9580e7a 100644 (file)
@@ -24,6 +24,7 @@ class Program:
             instructions = '\n'.join(instructions)
         self.assembly = instructions + '\n' # plus final newline
         self._assemble()
+        self._instructions = list(self._get_instructions())
 
     def __enter__(self):
         return self
@@ -64,13 +65,16 @@ class Program:
                 sys.exit(1)
             self._link(outfile)
 
-    def generate_instructions(self):
+    def _get_instructions(self):
         while True:
             data = self.binfile.read(4)
             if not data:
                 break
             yield struct.unpack('<i', data)[0]
 
+    def generate_instructions(self):
+        yield from self._instructions
+
     def reset(self):
         self.binfile.seek(0)