read into a BytesIO to avoid "too many open files"
[soc.git] / src / soc / simulator / program.py
index fda0c9594eebc1e1f436bb80157827d6a70bf1a3..d77f9d7839777c3bd607d04cdfc4c617c3dc4268 100644 (file)
@@ -27,7 +27,10 @@ class Program:
             self.obj_fmt = "-le"
 
         if isinstance(instructions, str):  # filename
-            self.binfile = open(instructions, "rb")
+            # 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.assembly = ''  # noo disassemble number fiiive
             print("program", self.binfile)
         else: