def test_builtin_loadwest(): compiler = Compiler() src = ''' @kernel def main(): b = loadWest() ''' kernel_objects= compiler.compile(src) main_object = kernel_objects[0] main_object = compiler.replace_phi_nodes(main_object) code = [InstrAdapter(x) for x in main_object.code] pattern = ''' mov b@0, west '''.strip() assert match_code(code, pattern)
def test_builtin_sendout(): compiler = Compiler() src = ''' @kernel def main(): a = 3 sendOut(a) ''' kernel_objects= compiler.compile(src) main_object = kernel_objects[0] main_object = compiler.replace_phi_nodes(main_object) code = [InstrAdapter(x) for x in main_object.code] pattern = ''' imm a@0, 3 mov out, a@0 '''.strip() assert match_code(code, pattern)
def test_replace_phi_nodes(): compiler = Compiler() src = ''' @kernel def main(a): b = 3 if a > 0 else 1 ''' kernel_objects= compiler.compile(src) main_object = kernel_objects[0] main_object = compiler.replace_phi_nodes(main_object) code = [InstrAdapter(x) for x in main_object.code] pattern = ''' imm tmp_0@0,0 imm tmp_2@0,3 imm tmp_3@0,1 cmp a@0,tmp_0@0 mov b@0,tmp_3@0 mov {GT} b@0,tmp_2@0 '''.strip() assert match_code(code, pattern)