def run_case(self, testcase: DataDrivenTestCase) -> None: # Kind of hacky. Not sure if we need more structure here. options = CompilerOptions(strip_asserts='StripAssert' in testcase.name) """Perform a runtime checking transformation test case.""" with use_custom_builtins( os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase): expected_output = remove_comment_lines(testcase.output) # replace native_int with platform specific ints int_format_str = 'int32' if IS_32_BIT_PLATFORM else 'int64' expected_output = [ s.replace('native_int', int_format_str) for s in expected_output ] try: ir = build_ir_for_single_file(testcase.input, options) except CompileError as e: actual = e.messages else: actual = [] for fn in ir: if (fn.name == TOP_LEVEL_NAME and not testcase.name.endswith('_toplevel')): continue actual.extend(format_func(fn)) assert_test_output(testcase, actual, 'Invalid source code output', expected_output)
def format_modules(modules: ModuleIRs) -> List[str]: ops = [] for module in modules.values(): for fn in module.functions: ops.extend(format_func(fn)) ops.append('') return ops
def run_case(self, testcase: DataDrivenTestCase) -> None: # Kind of hacky. Not sure if we need more structure here. options = CompilerOptions(strip_asserts='StripAssert' in testcase.name) """Perform a runtime checking transformation test case.""" with use_custom_builtins( os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase): expected_output = remove_comment_lines(testcase.output) expected_output = replace_native_int(expected_output) expected_output = replace_word_size(expected_output) name = testcase.name # If this is specific to some bit width, always pass if platform doesn't match. if name.endswith('_64bit') and IS_32_BIT_PLATFORM: return if name.endswith('_32bit') and not IS_32_BIT_PLATFORM: return try: ir = build_ir_for_single_file(testcase.input, options) except CompileError as e: actual = e.messages else: actual = [] for fn in ir: if (fn.name == TOP_LEVEL_NAME and not name.endswith('_toplevel')): continue actual.extend(format_func(fn)) assert_test_output(testcase, actual, 'Invalid source code output', expected_output)
def run_case(self, testcase: DataDrivenTestCase) -> None: """Perform a data-flow analysis test case.""" with use_custom_builtins( os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase): # replace native_int with platform specific ints int_format_str = 'int32' if IS_32_BIT_PLATFORM else 'int64' testcase.output = [ s.replace('native_int', int_format_str) for s in testcase.output ] try: ir = build_ir_for_single_file(testcase.input) except CompileError as e: actual = e.messages else: actual = [] for fn in ir: if (fn.name == TOP_LEVEL_NAME and not testcase.name.endswith('_toplevel')): continue exceptions.insert_exception_handling(fn) actual.extend(format_func(fn)) cfg = analysis.get_cfg(fn.blocks) args = set(reg for reg, i in fn.env.indexes.items() if i < len(fn.args)) name = testcase.name if name.endswith('_MaybeDefined'): # Forward, maybe analysis_result = analysis.analyze_maybe_defined_regs( fn.blocks, cfg, args) elif name.endswith('_Liveness'): # Backward, maybe analysis_result = analysis.analyze_live_regs( fn.blocks, cfg) elif name.endswith('_MustDefined'): # Forward, must analysis_result = analysis.analyze_must_defined_regs( fn.blocks, cfg, args, regs=fn.env.regs()) elif name.endswith('_BorrowedArgument'): # Forward, must analysis_result = analysis.analyze_borrowed_arguments( fn.blocks, cfg, args) else: assert False, 'No recognized _AnalysisName suffix in test case' for key in sorted(analysis_result.before.keys(), key=lambda x: (x[0].label, x[1])): pre = ', '.join( sorted(reg.name for reg in analysis_result.before[key])) post = ', '.join( sorted(reg.name for reg in analysis_result.after[key])) actual.append('%-8s %-23s %s' % ((key[0].label, key[1]), '{%s}' % pre, '{%s}' % post)) assert_test_output(testcase, actual, 'Invalid source code output')
def run_case(self, testcase: DataDrivenTestCase) -> None: """Perform a runtime checking transformation test case.""" with use_custom_builtins( os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase): expected_output = remove_comment_lines(testcase.output) try: ir = build_ir_for_single_file(testcase.input) except CompileError as e: actual = e.messages else: actual = [] for fn in ir: if (fn.name == TOP_LEVEL_NAME and not testcase.name.endswith('_toplevel')): continue insert_ref_count_opcodes(fn) actual.extend(format_func(fn)) assert_test_output(testcase, actual, 'Invalid source code output', expected_output)