Merge branch 'master' of git.libre-soc.org:soc
[soc.git] / src / soc / simulator / program.py
index d77f9d7839777c3bd607d04cdfc4c617c3dc4268..aeb33a23a170a893a0bcc4426a6bc2a774632790 100644 (file)
@@ -1,3 +1,7 @@
+# License: LGPLv3
+# Copyright (C) 2020 Michael Nolan <mtnolan2640@gmail.com>
+# Copyright (C) 2020 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
+
 """POWER Program
 
 takes powerpc assembly instructions and turns them into LE/BE binary
@@ -9,6 +13,8 @@ import subprocess
 import struct
 import os
 import sys
+from io import BytesIO
+
 
 filedir = os.path.dirname(os.path.realpath(__file__))
 memmap = os.path.join(filedir, "memmap")
@@ -26,11 +32,15 @@ class Program:
             self.endian_fmt = "elf64-little"
             self.obj_fmt = "-le"
 
-        if isinstance(instructions, str):  # filename
+        if isinstance(instructions, bytes):  # actual bytes
+            self.binfile = BytesIO(instructions)
+            self.binfile.name = "assembly"
+            self.assembly = ''  # noo disassemble number fiiive
+        elif isinstance(instructions, str):  # filename
             # read instructions into a BytesIO to avoid "too many open files"
             with open(instructions, "rb") as f:
                 b = f.read()
-            self.binfile = BytesIO(b, 'rb')
+            self.binfile = BytesIO(b)
             self.assembly = ''  # noo disassemble number fiiive
             print("program", self.binfile)
         else: