def do(self, src, imports=None): mod = python_to_ir(io.StringIO(src), imports=imports) f = io.StringIO() irutils.print_module(mod, file=f) # Round trip test: irutils.read_module(io.StringIO(f.getvalue()))
def test_return_from_loop(self): """ Check the behavior when we return from within a loop """ mod = """module foo; global procedure x() { block1: { jmp block2; } block2: { i32 a = 2; i32 b = 5; cjmp a < b ? block3 : block4; } block3: { exit; } block4: { i32 c = 2; i32 d = 5; cjmp c < d ? block5 : block6; } block5: { jmp block2; } block6: { exit; } } """ ir_module = irutils.read_module(io.StringIO(mod)) ir_function = ir_module['x'] # print(ir_function) # irutils.print_module(ir_module) shape, _ = relooper.find_structure(ir_function)
def serialization_roundtrip(ir_module): f = io.StringIO() print_module(ir_module, file=f) txt1 = f.getvalue() print(txt1) # Round trip via json: d = to_json(ir_module) ir_module2 = from_json(d) f = io.StringIO() print_module(ir_module2, file=f) txt2 = f.getvalue() assert txt1 == txt2 # Round trip via textual representation: f = io.StringIO(txt1) ir_module3 = read_module(f) f = io.StringIO() print_module(ir_module3, file=f) txt3 = f.getvalue() assert txt1 == txt3
def test_add_example(self): with open(relpath("data", "add.pi")) as f: m = irutils.read_module(f) self.assertTrue(m)