+"""POWER Program
+
+takes powerpc assembly instructions and turns them into LE/BE binary
+data. calls powerpc64-linux-gnu-as, ld and objcopy to do so.
+"""
+
import tempfile
import subprocess
import struct
import os
+import sys
filedir = os.path.dirname(os.path.realpath(__file__))
memmap = os.path.join(filedir, "memmap")
instructions = '\n'.join(instructions)
self.assembly = instructions + '\n' # plus final newline
self._assemble()
+ self._instructions = list(self._get_instructions())
def __enter__(self):
return self
outfile.name]
p = subprocess.Popen(args, stdin=subprocess.PIPE)
p.communicate(self.assembly.encode('utf-8'))
- assert(p.wait() == 0)
+ if p.wait() != 0:
+ print("Error in program:")
+ print(self.assembly)
+ 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)