def prep_namespace(self):
si = yield self.decoder.SI
- self.namespace.SI = SelectableInt(si, bits=16)
+ self.namespace['SI'] = SelectableInt(si, bits=16)
def call(self, name):
+ yield from self.prep_namespace()
+
function, read_regs, uninit_regs, write_regs = self.instrs[name]
input_names = create_args(read_regs | uninit_regs)
print(input_names)
for name, output in zip(output_names, results):
regnum = yield getattr(self.decoder, name)
print('writing reg %d' % regnum)
- self.gpr[regnum] = output
+ self.gpr[regnum] = output.narrow(64)
def inject():
sim = self.run_test_program(program, initial_regs)
self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))
- def run_test_program(self, prog, initial_regs):
+ def test_addi(self):
+ lst = ["addi 3, 0, 0x1234",
+ "addi 2, 0, 0x4321",
+ "add 1, 3, 2"]
+ with Program(lst) as program:
+ sim = self.run_test_program(program)
+ print(sim.gpr(1))
+ self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))
+
+ def run_test_program(self, prog, initial_regs=[0] * 32):
simulator = self.run_tst(prog, initial_regs)
simulator.gpr.dump()
return simulator
+
if __name__ == "__main__":
unittest.main()
return onebit(other == self.value)
assert False
+ def narrow(self, bits):
+ assert bits <= self.bits
+ return SelectableInt(self.value, bits)
+
def __bool__(self):
return self.value != 0