From 2feed64ea0ffb39bbb78a96674de6c8d24bcf516 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Thu, 13 Jul 2023 12:01:33 +0530 Subject: [PATCH 1/3] Add option for cumulative pass results --- src/bin/lpython.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 013c89e04f..715b29eadd 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -242,6 +242,7 @@ int emit_asr(const std::string &infile, pass_options.run_fun = "f"; pass_options.always_run = true; pass_options.verbose = compiler_options.verbose; + pass_options.pass_cumulative = compiler_options.pass_cumulative; pass_manager.apply_passes(al, asr, pass_options, diagnostics); @@ -1574,6 +1575,7 @@ int main(int argc, char *argv[]) app.add_flag("--get-rtl-header-dir", print_rtl_header_dir, "Print the path to the runtime library header file"); app.add_flag("--get-rtl-dir", print_rtl_dir, "Print the path to the runtime library file"); app.add_flag("--verbose", compiler_options.verbose, "Print debugging statements"); + app.add_flag("--cumulative", compiler_options.pass_cumulative, "Apply all the passes cumulatively till the given pass"); app.add_flag("--enable-cpython", compiler_options.enable_cpython, "Enable CPython runtime"); app.add_flag("--enable-symengine", compiler_options.enable_symengine, "Enable Symengine runtime"); app.add_flag("--link-numpy", compiler_options.link_numpy, "Enable NumPy runtime (implies --enable-cpython)"); From 9edbf81c6274fcd93790aa4a9a94a2762947b111 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Thu, 13 Jul 2023 12:03:36 +0530 Subject: [PATCH 2/3] Add option to test cumulative flag --- run_tests.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/run_tests.py b/run_tests.py index f8eee2600f..01946a9c29 100755 --- a/run_tests.py +++ b/run_tests.py @@ -26,6 +26,7 @@ def is_included(backend): llvm_dbg = is_included("llvm_dbg") cpp = is_included("cpp") c = is_included("c") + is_cumulative = is_included("cumulative") wat = is_included("wat") run = is_included("run") run_with_dbg = is_included("run_with_dbg") @@ -91,7 +92,10 @@ def is_included(backend): extra_args) if pass_ is not None: - cmd = "lpython --pass=" + pass_ + \ + cmd = "lpython " + if is_cumulative: + cmd += "--cumulative " + cmd += "--pass=" + pass_ + \ " --show-asr --no-color {infile} -o {outfile}" run_test(filename, "pass_{}".format(pass_), cmd, filename, update_reference, extra_args) From b63e46ee26e5088b2c8e68593298a7936e4f0c57 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Thu, 13 Jul 2023 12:17:34 +0530 Subject: [PATCH 3/3] Add and update references --- run_tests.py | 3 +- tests/reference/asr-structs_16-44de89a.json | 13 + tests/reference/asr-structs_16-44de89a.stdout | 329 ++++++++++++++++ ..._class_constructor-structs_16-5e3508f.json | 13 + ...lass_constructor-structs_16-5e3508f.stdout | 358 ++++++++++++++++++ tests/tests.toml | 6 + 6 files changed, 721 insertions(+), 1 deletion(-) create mode 100644 tests/reference/asr-structs_16-44de89a.json create mode 100644 tests/reference/asr-structs_16-44de89a.stdout create mode 100644 tests/reference/pass_class_constructor-structs_16-5e3508f.json create mode 100644 tests/reference/pass_class_constructor-structs_16-5e3508f.stdout diff --git a/run_tests.py b/run_tests.py index 01946a9c29..b55d6af851 100755 --- a/run_tests.py +++ b/run_tests.py @@ -34,7 +34,8 @@ def is_included(backend): pass_ = test.get("pass", None) optimization_passes = ["flip_sign", "div_to_mul", "fma", "sign_from_value", "inline_function_calls", "loop_unroll", - "dead_code_removal", "loop_vectorise", "print_list_tuple"] + "dead_code_removal", "loop_vectorise", "print_list_tuple", + "class_constructor"] if pass_ and (pass_ not in ["do_loops", "global_stmts"] and pass_ not in optimization_passes): diff --git a/tests/reference/asr-structs_16-44de89a.json b/tests/reference/asr-structs_16-44de89a.json new file mode 100644 index 0000000000..66ebe5853d --- /dev/null +++ b/tests/reference/asr-structs_16-44de89a.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-structs_16-44de89a", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_16.py", + "infile_hash": "e87ea0ba10cb7fcd6ce2eb6d2e953a26dcd6a843f6cf4e891287dcb1", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-structs_16-44de89a.stdout", + "stdout_hash": "003d4550abb6fca33a8741e4d586a32ab5ce3355a40da5f911d61112", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-structs_16-44de89a.stdout b/tests/reference/asr-structs_16-44de89a.stdout new file mode 100644 index 0000000000..073b030b81 --- /dev/null +++ b/tests/reference/asr-structs_16-44de89a.stdout @@ -0,0 +1,329 @@ +(TranslationUnit + (SymbolTable + 1 + { + _global_symbols: + (Module + (SymbolTable + 9 + { + A: + (StructType + (SymbolTable + 2 + { + B: + (UnionType + (SymbolTable + 3 + { + x: + (Variable + 3 + x + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ), + y: + (Variable + 3 + y + [] + Local + () + () + Default + (Integer 8) + () + Source + Public + Required + .false. + ) + }) + B + [] + [x + y] + Source + Public + [(()) + (())] + () + ), + b: + (Variable + 2 + b + [] + Local + () + () + Default + (Union + 2 B + ) + () + Source + Public + Required + .false. + ), + c: + (Variable + 2 + c + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ) + }) + A + [] + [b + c] + Source + Public + .false. + .false. + [(()) + (())] + () + () + ), + _lpython_main_program: + (Function + (SymbolTable + 8 + { + + }) + _lpython_main_program + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + [] + .false. + ) + [test_ordering] + [] + [(SubroutineCall + 9 test_ordering + () + [] + () + )] + () + Public + .false. + .false. + () + ), + test_ordering: + (Function + (SymbolTable + 4 + { + A_B: + (ExternalSymbol + 4 + A_B + 2 B + A + [] + B + Public + ), + ad: + (Variable + 4 + ad + [] + Local + () + () + Default + (Struct + 9 A + ) + () + Source + Public + Required + .false. + ), + bd: + (Variable + 4 + bd + [] + Local + () + () + Default + (Union + 4 A_B + ) + () + Source + Public + Required + .false. + ) + }) + test_ordering + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + [] + .false. + ) + [] + [] + [(= + (Var 4 bd) + (UnionTypeConstructor + 4 A_B + [] + (Union + 4 A_B + ) + () + ) + () + ) + (= + (UnionInstanceMember + (Var 4 bd) + 3 x + (Integer 4) + () + ) + (IntegerConstant 1 (Integer 4)) + () + ) + (= + (Var 4 ad) + (StructTypeConstructor + 9 A + [((Var 4 bd)) + ((IntegerConstant 2 (Integer 4)))] + (Struct + 9 A + ) + () + ) + () + ) + (Assert + (IntegerCompare + (UnionInstanceMember + (StructInstanceMember + (Var 4 ad) + 2 b + (Union + 2 B + ) + () + ) + 3 x + (Integer 4) + () + ) + Eq + (IntegerConstant 1 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (IntegerCompare + (StructInstanceMember + (Var 4 ad) + 2 c + (Integer 4) + () + ) + Eq + (IntegerConstant 2 (Integer 4)) + (Logical 4) + () + ) + () + )] + () + Public + .false. + .false. + () + ) + }) + _global_symbols + [] + .false. + .false. + ), + main_program: + (Program + (SymbolTable + 7 + { + _lpython_main_program: + (ExternalSymbol + 7 + _lpython_main_program + 9 _lpython_main_program + _global_symbols + [] + _lpython_main_program + Public + ) + }) + main_program + [_global_symbols] + [(SubroutineCall + 7 _lpython_main_program + () + [] + () + )] + ) + }) + [] +) diff --git a/tests/reference/pass_class_constructor-structs_16-5e3508f.json b/tests/reference/pass_class_constructor-structs_16-5e3508f.json new file mode 100644 index 0000000000..e59fedc758 --- /dev/null +++ b/tests/reference/pass_class_constructor-structs_16-5e3508f.json @@ -0,0 +1,13 @@ +{ + "basename": "pass_class_constructor-structs_16-5e3508f", + "cmd": "lpython --cumulative --pass=class_constructor --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_16.py", + "infile_hash": "e87ea0ba10cb7fcd6ce2eb6d2e953a26dcd6a843f6cf4e891287dcb1", + "outfile": null, + "outfile_hash": null, + "stdout": "pass_class_constructor-structs_16-5e3508f.stdout", + "stdout_hash": "0be8b4bbd12e9c29e6f62c71aa7f13afd1e179bcf880fefb58ce4122", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout b/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout new file mode 100644 index 0000000000..8eb7570ccf --- /dev/null +++ b/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout @@ -0,0 +1,358 @@ +(TranslationUnit + (SymbolTable + 1 + { + _global_symbols: + (Module + (SymbolTable + 9 + { + A: + (StructType + (SymbolTable + 2 + { + B: + (UnionType + (SymbolTable + 3 + { + x: + (Variable + 3 + x + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ), + y: + (Variable + 3 + y + [] + Local + () + () + Default + (Integer 8) + () + Source + Public + Required + .false. + ) + }) + B + [] + [x + y] + Source + Public + [(()) + (())] + () + ), + b: + (Variable + 2 + b + [] + Local + () + () + Default + (Union + 2 B + ) + () + Source + Public + Required + .false. + ), + c: + (Variable + 2 + c + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ) + }) + A + [] + [b + c] + Source + Public + .false. + .false. + [(()) + (())] + () + () + ), + _lpython_main_program: + (Function + (SymbolTable + 8 + { + + }) + _lpython_main_program + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + [] + .false. + ) + [test_ordering] + [] + [(SubroutineCall + 9 test_ordering + () + [] + () + )] + () + Public + .false. + .false. + () + ), + test_ordering: + (Function + (SymbolTable + 4 + { + 1_A_b: + (ExternalSymbol + 4 + 1_A_b + 2 b + A + [] + b + Public + ), + 1_A_c: + (ExternalSymbol + 4 + 1_A_c + 2 c + A + [] + c + Public + ), + A_B: + (ExternalSymbol + 4 + A_B + 2 B + A + [] + B + Public + ), + ad: + (Variable + 4 + ad + [] + Local + () + () + Default + (Struct + 9 A + ) + () + Source + Public + Required + .false. + ), + bd: + (Variable + 4 + bd + [] + Local + () + () + Default + (Union + 4 A_B + ) + () + Source + Public + Required + .false. + ) + }) + test_ordering + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + [] + .false. + ) + [] + [] + [(= + (Var 4 bd) + (UnionTypeConstructor + 4 A_B + [] + (Union + 4 A_B + ) + () + ) + () + ) + (= + (UnionInstanceMember + (Var 4 bd) + 3 x + (Integer 4) + () + ) + (IntegerConstant 1 (Integer 4)) + () + ) + (= + (StructInstanceMember + (Var 4 ad) + 4 1_A_b + (Union + 2 B + ) + () + ) + (Var 4 bd) + () + ) + (= + (StructInstanceMember + (Var 4 ad) + 4 1_A_c + (Integer 4) + () + ) + (IntegerConstant 2 (Integer 4)) + () + ) + (Assert + (IntegerCompare + (UnionInstanceMember + (StructInstanceMember + (Var 4 ad) + 2 b + (Union + 2 B + ) + () + ) + 3 x + (Integer 4) + () + ) + Eq + (IntegerConstant 1 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (IntegerCompare + (StructInstanceMember + (Var 4 ad) + 2 c + (Integer 4) + () + ) + Eq + (IntegerConstant 2 (Integer 4)) + (Logical 4) + () + ) + () + )] + () + Public + .false. + .false. + () + ) + }) + _global_symbols + [] + .false. + .false. + ), + main_program: + (Program + (SymbolTable + 7 + { + _lpython_main_program: + (ExternalSymbol + 7 + _lpython_main_program + 9 _lpython_main_program + _global_symbols + [] + _lpython_main_program + Public + ) + }) + main_program + [_global_symbols] + [(SubroutineCall + 7 _lpython_main_program + () + [] + () + )] + ) + }) + [] +) diff --git a/tests/tests.toml b/tests/tests.toml index f41ed36889..d29c5972c4 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -330,6 +330,12 @@ asr = true filename = "../integration_tests/structs_05.py" asr = true +[[test]] +filename = "../integration_tests/structs_16.py" +asr = true +pass = "class_constructor" +cumulative = true + [[test]] filename = "../integration_tests/callback_01.py" asr = true