From fc313ed6ac3cd42d018cb9c010c2857e941e2bae Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 11:29:52 +0530 Subject: [PATCH 1/8] ASR: Support for in looping over strings --- src/lpython/semantics/python_ast_to_asr.cpp | 55 ++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index b6c8d7b441..a908911969 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2685,6 +2685,7 @@ class BodyVisitor : public CommonVisitor { Vec body; body.reserve(al, x.n_body); transform_stmts(body, x.n_body, x.m_body); + bool is_explicit_iterator_required = false; ASR::expr_t *loop_end = nullptr, *loop_start = nullptr, *inc = nullptr; if (AST::is_a(*x.m_iter)) { AST::Call_t *c = AST::down_cast(x.m_iter); @@ -2722,6 +2723,40 @@ class BodyVisitor : public CommonVisitor { x.base.base.loc); } + } else if (AST::is_a(*x.m_iter)) { + std::string loop_src_var_name = AST::down_cast(x.m_iter)->m_id; + auto loop_src_var_symbol = current_scope->get_symbol(loop_src_var_name); + auto loop_src_var_ttype = ASRUtils::symbol_type(loop_src_var_symbol); + if( loop_src_var_ttype->type == ASR::ttypeType::Character) { + auto int_type = ASR::make_Integer_t(al, x.base.base.loc, 4, nullptr, 0); + + { + // create a new variable called/named __explicit_iterator of type i32 and add it to symbol table + std::string explicit_iter_name = current_scope->get_unique_name("__explicit_iterator"); + auto explicit_iter_variable = ASR::make_Variable_t(al, x.base.base.loc, current_scope, + s2c(al, explicit_iter_name), ASR::intentType::Local, nullptr, nullptr, ASR::storage_typeType::Default, + ASRUtils::TYPE(int_type), ASR::abiType::Source, ASR::accessType::Public, ASR::presenceType::Required, false + ); + + current_scope->add_symbol(explicit_iter_name, ASR::down_cast(explicit_iter_variable)); + } + + { + // make loop_end = len(loop_src_var), where loop_src_var is the variable over which + // we are iterating the for in loop + auto loop_src_var = ASR::make_Var_t(al, x.base.base.loc, loop_src_var_symbol); + auto call_str_len = ASR::make_StringLen_t(al, x.base.base.loc, ASRUtils::EXPR(loop_src_var), ASRUtils::TYPE(int_type), nullptr); + loop_end = ASRUtils::EXPR(call_str_len); + } + + is_explicit_iterator_required = true; + } else if (loop_src_var_ttype->type == ASR::ttypeType::List) { + throw SemanticError("Iterating on Lists using for in loop not yet supported as " + "visit_Len() is not yet supported on the LLVM Backend", x.base.base.loc); + } else { + throw SemanticError("Only Strings and Lists can be used with for in loop, not " + + ASRUtils::type_to_str(loop_src_var_ttype), x.base.base.loc); + } } else { throw SemanticError("Only function call `range(..)` supported as for loop iteration for now", x.base.base.loc); @@ -2735,7 +2770,25 @@ class BodyVisitor : public CommonVisitor { x.base.base.loc, false); loop_end = ASRUtils::EXPR(tmp); ASR::do_loop_head_t head; - head.m_v = target; + + if(is_explicit_iterator_required) { + // add an assignment instruction to body to assign value of loop_src_var at an index to the loop_target_var + auto explicit_iter_var = ASR::make_Var_t(al, x.base.base.loc, current_scope->get_symbol("__explicit_iterator")); + auto index_plus_one = ASR::make_IntegerBinOp_t(al, x.base.base.loc, ASRUtils::EXPR(explicit_iter_var), + ASR::binopType::Add, constant_one, a_type, nullptr); + std::string loop_src_var_name = AST::down_cast(x.m_iter)->m_id; + auto loop_src_var = ASR::make_Var_t(al, x.base.base.loc, current_scope->get_symbol(loop_src_var_name)); + auto loop_src_var_element = ASR::make_StringItem_t(al, x.base.base.loc, ASRUtils::EXPR(loop_src_var), + ASRUtils::EXPR(index_plus_one), a_type, nullptr); + auto loop_target_assignment = ASR::make_Assignment_t(al, x.base.base.loc, target, ASRUtils::EXPR(loop_src_var_element), nullptr); + body.push_back(al, ASRUtils::STMT(loop_target_assignment)); + + head.m_v = ASRUtils::EXPR(explicit_iter_var); + } else { + head.m_v = target; + } + + if (loop_start) { head.m_start = loop_start; } else { From 4d0b68faf2acacdcd4587edbda3aacdb5d616f28 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 11:33:51 +0530 Subject: [PATCH 2/8] ASR: 1. body.reserve() appropriately depending on is_explicit_iter_req_ 2. use transform_stmts() late after pushing stmt loop_target_var = list[i] --- src/lpython/semantics/python_ast_to_asr.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index a908911969..ba3f9059a1 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2683,8 +2683,6 @@ class BodyVisitor : public CommonVisitor { this->visit_expr(*x.m_target); ASR::expr_t *target=ASRUtils::EXPR(tmp); Vec body; - body.reserve(al, x.n_body); - transform_stmts(body, x.n_body, x.m_body); bool is_explicit_iterator_required = false; ASR::expr_t *loop_end = nullptr, *loop_start = nullptr, *inc = nullptr; if (AST::is_a(*x.m_iter)) { @@ -2772,6 +2770,7 @@ class BodyVisitor : public CommonVisitor { ASR::do_loop_head_t head; if(is_explicit_iterator_required) { + body.reserve(al, x.n_body + 1); // add an assignment instruction to body to assign value of loop_src_var at an index to the loop_target_var auto explicit_iter_var = ASR::make_Var_t(al, x.base.base.loc, current_scope->get_symbol("__explicit_iterator")); auto index_plus_one = ASR::make_IntegerBinOp_t(al, x.base.base.loc, ASRUtils::EXPR(explicit_iter_var), @@ -2785,9 +2784,11 @@ class BodyVisitor : public CommonVisitor { head.m_v = ASRUtils::EXPR(explicit_iter_var); } else { + body.reserve(al, x.n_body); head.m_v = target; } + transform_stmts(body, x.n_body, x.m_body); if (loop_start) { head.m_start = loop_start; From 9697c9eb1c13b4beadfa5d2fefaebaf11834cfbc Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 11:43:51 +0530 Subject: [PATCH 3/8] TEST: ASR: Add test for 'for in looping' over strings --- integration_tests/CMakeLists.txt | 1 + integration_tests/loop_01.py | 8 ++++++++ tests/tests.toml | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 integration_tests/loop_01.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index eaeacce79f..92b2abc494 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -140,6 +140,7 @@ RUN(NAME expr_09 LABELS cpython llvm) RUN(NAME expr_10 LABELS cpython llvm) RUN(NAME expr_11 LABELS cpython llvm c) RUN(NAME expr_12 LABELS llvm c) +RUN(NAME loop_01 LABELS cpython llvm) RUN(NAME test_types_01 LABELS cpython llvm) RUN(NAME test_str_01 LABELS cpython llvm) RUN(NAME test_str_02 LABELS cpython llvm) diff --git a/integration_tests/loop_01.py b/integration_tests/loop_01.py new file mode 100644 index 0000000000..a057562c5c --- /dev/null +++ b/integration_tests/loop_01.py @@ -0,0 +1,8 @@ +def main0(): + s: str + s = 'aabbcc' + c: str + for c in s: + print(c) + +main0() diff --git a/tests/tests.toml b/tests/tests.toml index b548cca84b..4258d332c9 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -140,6 +140,12 @@ ast = true asr = true llvm = true +[[test]] +filename = "../integration_tests/loop_01.py" +ast = true +asr = true +llvm = true + [[test]] filename = "../integration_tests/array_01_decl.py" asr = true From d71b8f9941bc1d742f7d456f63b7a3575fc5df90 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 11:58:09 +0530 Subject: [PATCH 4/8] TEST: Update reference tests for integration_tests/loop_01.py --- tests/reference/asr-loop_01-ff0998d.json | 13 ++++ tests/reference/asr-loop_01-ff0998d.stdout | 1 + tests/reference/ast-loop_01-8e9cffe.json | 13 ++++ tests/reference/ast-loop_01-8e9cffe.stdout | 1 + tests/reference/llvm-loop_01-ac29dce.json | 13 ++++ tests/reference/llvm-loop_01-ac29dce.stdout | 70 +++++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 tests/reference/asr-loop_01-ff0998d.json create mode 100644 tests/reference/asr-loop_01-ff0998d.stdout create mode 100644 tests/reference/ast-loop_01-8e9cffe.json create mode 100644 tests/reference/ast-loop_01-8e9cffe.stdout create mode 100644 tests/reference/llvm-loop_01-ac29dce.json create mode 100644 tests/reference/llvm-loop_01-ac29dce.stdout diff --git a/tests/reference/asr-loop_01-ff0998d.json b/tests/reference/asr-loop_01-ff0998d.json new file mode 100644 index 0000000000..bd4ef87113 --- /dev/null +++ b/tests/reference/asr-loop_01-ff0998d.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-loop_01-ff0998d", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/loop_01.py", + "infile_hash": "4a7a536aea7a5740a0e00d436fc9cae9aeb3c489af03858fabf68fd1", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-loop_01-ff0998d.stdout", + "stdout_hash": "1ebf7a3a1af7d0c81c0ce3ec718373eedf4aced075f77b3fc75a81ae", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-loop_01-ff0998d.stdout b/tests/reference/asr-loop_01-ff0998d.stdout new file mode 100644 index 0000000000..906a2521f1 --- /dev/null +++ b/tests/reference/asr-loop_01-ff0998d.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 2 {__explicit_iterator: (Variable 2 __explicit_iterator Local () () Default (Integer 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Character 1 -2 () []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) main0 [] [(= (Var 2 s) (StringConstant "aabbcc" (Character 1 6 () [])) ()) (DoLoop ((Var 2 __explicit_iterator) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (StringLen (Var 2 s) (Integer 4 []) ()) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 []))) [(= (Var 2 c) (StringItem (Var 2 s) (IntegerBinOp (Var 2 __explicit_iterator) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Integer 4 []) ()) ()) (Print () [(Var 2 c)] () ())])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/ast-loop_01-8e9cffe.json b/tests/reference/ast-loop_01-8e9cffe.json new file mode 100644 index 0000000000..ddf8990f9c --- /dev/null +++ b/tests/reference/ast-loop_01-8e9cffe.json @@ -0,0 +1,13 @@ +{ + "basename": "ast-loop_01-8e9cffe", + "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/loop_01.py", + "infile_hash": "4a7a536aea7a5740a0e00d436fc9cae9aeb3c489af03858fabf68fd1", + "outfile": null, + "outfile_hash": null, + "stdout": "ast-loop_01-8e9cffe.stdout", + "stdout_hash": "ddcda1ca979f67f69113d283d849cf4195b4c262fa0d23b46f93e30b", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast-loop_01-8e9cffe.stdout b/tests/reference/ast-loop_01-8e9cffe.stdout new file mode 100644 index 0000000000..d1eace774d --- /dev/null +++ b/tests/reference/ast-loop_01-8e9cffe.stdout @@ -0,0 +1 @@ +(Module [(FunctionDef main0 ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (Assign [(Name s Store)] (ConstantStr "aabbcc" ()) ()) (AnnAssign (Name c Store) (Name str Load) () 1) (For (Name c Store) (Name s Load) [(Expr (Call (Name print Load) [(Name c Load)] []))] [] ())] [] () ()) (Expr (Call (Name main0 Load) [] []))] []) diff --git a/tests/reference/llvm-loop_01-ac29dce.json b/tests/reference/llvm-loop_01-ac29dce.json new file mode 100644 index 0000000000..ab2bafbde5 --- /dev/null +++ b/tests/reference/llvm-loop_01-ac29dce.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-loop_01-ac29dce", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/loop_01.py", + "infile_hash": "4a7a536aea7a5740a0e00d436fc9cae9aeb3c489af03858fabf68fd1", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-loop_01-ac29dce.stdout", + "stdout_hash": "4aa64d7837978998454f3fd72b711188171038f0e79bb2030ad60481", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-loop_01-ac29dce.stdout b/tests/reference/llvm-loop_01-ac29dce.stdout new file mode 100644 index 0000000000..95daa10f75 --- /dev/null +++ b/tests/reference/llvm-loop_01-ac29dce.stdout @@ -0,0 +1,70 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@0 = private unnamed_addr constant [7 x i8] c"aabbcc\00", align 1 +@1 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 + +define void @_lpython_main_program() { +.entry: + call void @main0() + br label %return + +return: ; preds = %.entry + ret void +} + +define void @main0() { +.entry: + %__explicit_iterator = alloca i32, align 4 + %c = alloca i8*, align 8 + store i8* null, i8** %c, align 8 + %s = alloca i8*, align 8 + store i8* null, i8** %s, align 8 + store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @0, i32 0, i32 0), i8** %s, align 8 + store i32 -1, i32* %__explicit_iterator, align 4 + br label %loop.head + +loop.head: ; preds = %loop.body, %.entry + %0 = load i32, i32* %__explicit_iterator, align 4 + %1 = add i32 %0, 1 + %2 = load i8*, i8** %s, align 8 + %3 = alloca i8*, align 8 + store i8* %2, i8** %3, align 8 + %4 = call i32 @_lfortran_str_len(i8** %3) + %5 = sub i32 %4, 1 + %6 = icmp sle i32 %1, %5 + br i1 %6, label %loop.body, label %loop.end + +loop.body: ; preds = %loop.head + %7 = load i32, i32* %__explicit_iterator, align 4 + %8 = add i32 %7, 1 + store i32 %8, i32* %__explicit_iterator, align 4 + %9 = load i32, i32* %__explicit_iterator, align 4 + %10 = add i32 %9, 1 + %11 = load i8*, i8** %s, align 8 + %12 = call i8* @_lfortran_str_copy(i8* %11, i32 %10, i32 %10) + store i8* %12, i8** %c, align 8 + %13 = load i8*, i8** %c, align 8 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0)) + br label %loop.head + +loop.end: ; preds = %loop.head + br label %return + +return: ; preds = %loop.end + ret void +} + +declare i32 @_lfortran_str_len(i8**) + +declare i8* @_lfortran_str_copy(i8*, i32, i32) + +declare void @_lfortran_printf(i8*, ...) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} From d98efb6a708a3e7626d86b3adbafe57397f18fc7 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 12:27:29 +0530 Subject: [PATCH 5/8] ASR: Support throwing appropriate SemanticError() for Set and Tuple --- src/lpython/semantics/python_ast_to_asr.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index ba3f9059a1..ceaa91fb40 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2751,8 +2751,12 @@ class BodyVisitor : public CommonVisitor { } else if (loop_src_var_ttype->type == ASR::ttypeType::List) { throw SemanticError("Iterating on Lists using for in loop not yet supported as " "visit_Len() is not yet supported on the LLVM Backend", x.base.base.loc); + } else if (loop_src_var_ttype->type == ASR::ttypeType::Set) { + throw SemanticError("Iterating on Set using for in loop not yet supported", x.base.base.loc); + } else if (loop_src_var_ttype->type == ASR::ttypeType::Tuple) { + throw SemanticError("Iterating on Tuple using for in loop not yet supported", x.base.base.loc); } else { - throw SemanticError("Only Strings and Lists can be used with for in loop, not " + + throw SemanticError("Only Strings, Lists, Sets and Tuples can be used with for in loop, not " + ASRUtils::type_to_str(loop_src_var_ttype), x.base.base.loc); } } else { From a6e72fd941d6e3ce40ebfea4d7f1b6586e480d28 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 18:05:51 +0530 Subject: [PATCH 6/8] Refactor: Suggestion: Improve error message --- src/lpython/semantics/python_ast_to_asr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index ceaa91fb40..3de6fa1ffc 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2750,7 +2750,7 @@ class BodyVisitor : public CommonVisitor { is_explicit_iterator_required = true; } else if (loop_src_var_ttype->type == ASR::ttypeType::List) { throw SemanticError("Iterating on Lists using for in loop not yet supported as " - "visit_Len() is not yet supported on the LLVM Backend", x.base.base.loc); + "visit_Len() is not yet supported in the LLVM Backend", x.base.base.loc); } else if (loop_src_var_ttype->type == ASR::ttypeType::Set) { throw SemanticError("Iterating on Set using for in loop not yet supported", x.base.base.loc); } else if (loop_src_var_ttype->type == ASR::ttypeType::Tuple) { From 0decfa9eb997d1abcd7a9b831d639234e02b6fd6 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 18:12:55 +0530 Subject: [PATCH 7/8] Refactor: Suggestion: Use better approach ASR::is_a<>() for type checking --- src/lpython/semantics/python_ast_to_asr.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 3de6fa1ffc..f2baaa1dd9 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2725,7 +2725,7 @@ class BodyVisitor : public CommonVisitor { std::string loop_src_var_name = AST::down_cast(x.m_iter)->m_id; auto loop_src_var_symbol = current_scope->get_symbol(loop_src_var_name); auto loop_src_var_ttype = ASRUtils::symbol_type(loop_src_var_symbol); - if( loop_src_var_ttype->type == ASR::ttypeType::Character) { + if (ASR::is_a(*loop_src_var_ttype)) { auto int_type = ASR::make_Integer_t(al, x.base.base.loc, 4, nullptr, 0); { @@ -2748,12 +2748,12 @@ class BodyVisitor : public CommonVisitor { } is_explicit_iterator_required = true; - } else if (loop_src_var_ttype->type == ASR::ttypeType::List) { + } else if (ASR::is_a(*loop_src_var_ttype)) { throw SemanticError("Iterating on Lists using for in loop not yet supported as " "visit_Len() is not yet supported in the LLVM Backend", x.base.base.loc); - } else if (loop_src_var_ttype->type == ASR::ttypeType::Set) { + } else if (ASR::is_a(*loop_src_var_ttype)) { throw SemanticError("Iterating on Set using for in loop not yet supported", x.base.base.loc); - } else if (loop_src_var_ttype->type == ASR::ttypeType::Tuple) { + } else if (ASR::is_a(*loop_src_var_ttype)) { throw SemanticError("Iterating on Tuple using for in loop not yet supported", x.base.base.loc); } else { throw SemanticError("Only Strings, Lists, Sets and Tuples can be used with for in loop, not " + From d8aab5ea44901e3710ab81570d882317f1609ec2 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Mon, 18 Jul 2022 22:17:27 +0530 Subject: [PATCH 8/8] TEST: Remove AST, ASR, LLVM output checking for integration_tests/loop_01.py --- tests/reference/asr-loop_01-ff0998d.json | 13 ---- tests/reference/asr-loop_01-ff0998d.stdout | 1 - tests/reference/ast-loop_01-8e9cffe.json | 13 ---- tests/reference/ast-loop_01-8e9cffe.stdout | 1 - tests/reference/llvm-loop_01-ac29dce.json | 13 ---- tests/reference/llvm-loop_01-ac29dce.stdout | 70 --------------------- tests/tests.toml | 6 -- 7 files changed, 117 deletions(-) delete mode 100644 tests/reference/asr-loop_01-ff0998d.json delete mode 100644 tests/reference/asr-loop_01-ff0998d.stdout delete mode 100644 tests/reference/ast-loop_01-8e9cffe.json delete mode 100644 tests/reference/ast-loop_01-8e9cffe.stdout delete mode 100644 tests/reference/llvm-loop_01-ac29dce.json delete mode 100644 tests/reference/llvm-loop_01-ac29dce.stdout diff --git a/tests/reference/asr-loop_01-ff0998d.json b/tests/reference/asr-loop_01-ff0998d.json deleted file mode 100644 index bd4ef87113..0000000000 --- a/tests/reference/asr-loop_01-ff0998d.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "asr-loop_01-ff0998d", - "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", - "infile": "tests/../integration_tests/loop_01.py", - "infile_hash": "4a7a536aea7a5740a0e00d436fc9cae9aeb3c489af03858fabf68fd1", - "outfile": null, - "outfile_hash": null, - "stdout": "asr-loop_01-ff0998d.stdout", - "stdout_hash": "1ebf7a3a1af7d0c81c0ce3ec718373eedf4aced075f77b3fc75a81ae", - "stderr": null, - "stderr_hash": null, - "returncode": 0 -} \ No newline at end of file diff --git a/tests/reference/asr-loop_01-ff0998d.stdout b/tests/reference/asr-loop_01-ff0998d.stdout deleted file mode 100644 index 906a2521f1..0000000000 --- a/tests/reference/asr-loop_01-ff0998d.stdout +++ /dev/null @@ -1 +0,0 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 2 {__explicit_iterator: (Variable 2 __explicit_iterator Local () () Default (Integer 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Character 1 -2 () []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) main0 [] [(= (Var 2 s) (StringConstant "aabbcc" (Character 1 6 () [])) ()) (DoLoop ((Var 2 __explicit_iterator) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (StringLen (Var 2 s) (Integer 4 []) ()) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 []))) [(= (Var 2 c) (StringItem (Var 2 s) (IntegerBinOp (Var 2 __explicit_iterator) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Integer 4 []) ()) ()) (Print () [(Var 2 c)] () ())])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/ast-loop_01-8e9cffe.json b/tests/reference/ast-loop_01-8e9cffe.json deleted file mode 100644 index ddf8990f9c..0000000000 --- a/tests/reference/ast-loop_01-8e9cffe.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "ast-loop_01-8e9cffe", - "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", - "infile": "tests/../integration_tests/loop_01.py", - "infile_hash": "4a7a536aea7a5740a0e00d436fc9cae9aeb3c489af03858fabf68fd1", - "outfile": null, - "outfile_hash": null, - "stdout": "ast-loop_01-8e9cffe.stdout", - "stdout_hash": "ddcda1ca979f67f69113d283d849cf4195b4c262fa0d23b46f93e30b", - "stderr": null, - "stderr_hash": null, - "returncode": 0 -} \ No newline at end of file diff --git a/tests/reference/ast-loop_01-8e9cffe.stdout b/tests/reference/ast-loop_01-8e9cffe.stdout deleted file mode 100644 index d1eace774d..0000000000 --- a/tests/reference/ast-loop_01-8e9cffe.stdout +++ /dev/null @@ -1 +0,0 @@ -(Module [(FunctionDef main0 ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (Assign [(Name s Store)] (ConstantStr "aabbcc" ()) ()) (AnnAssign (Name c Store) (Name str Load) () 1) (For (Name c Store) (Name s Load) [(Expr (Call (Name print Load) [(Name c Load)] []))] [] ())] [] () ()) (Expr (Call (Name main0 Load) [] []))] []) diff --git a/tests/reference/llvm-loop_01-ac29dce.json b/tests/reference/llvm-loop_01-ac29dce.json deleted file mode 100644 index ab2bafbde5..0000000000 --- a/tests/reference/llvm-loop_01-ac29dce.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "llvm-loop_01-ac29dce", - "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", - "infile": "tests/../integration_tests/loop_01.py", - "infile_hash": "4a7a536aea7a5740a0e00d436fc9cae9aeb3c489af03858fabf68fd1", - "outfile": null, - "outfile_hash": null, - "stdout": "llvm-loop_01-ac29dce.stdout", - "stdout_hash": "4aa64d7837978998454f3fd72b711188171038f0e79bb2030ad60481", - "stderr": null, - "stderr_hash": null, - "returncode": 0 -} \ No newline at end of file diff --git a/tests/reference/llvm-loop_01-ac29dce.stdout b/tests/reference/llvm-loop_01-ac29dce.stdout deleted file mode 100644 index 95daa10f75..0000000000 --- a/tests/reference/llvm-loop_01-ac29dce.stdout +++ /dev/null @@ -1,70 +0,0 @@ -; ModuleID = 'LFortran' -source_filename = "LFortran" - -@0 = private unnamed_addr constant [7 x i8] c"aabbcc\00", align 1 -@1 = private unnamed_addr constant [2 x i8] c" \00", align 1 -@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 - -define void @_lpython_main_program() { -.entry: - call void @main0() - br label %return - -return: ; preds = %.entry - ret void -} - -define void @main0() { -.entry: - %__explicit_iterator = alloca i32, align 4 - %c = alloca i8*, align 8 - store i8* null, i8** %c, align 8 - %s = alloca i8*, align 8 - store i8* null, i8** %s, align 8 - store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @0, i32 0, i32 0), i8** %s, align 8 - store i32 -1, i32* %__explicit_iterator, align 4 - br label %loop.head - -loop.head: ; preds = %loop.body, %.entry - %0 = load i32, i32* %__explicit_iterator, align 4 - %1 = add i32 %0, 1 - %2 = load i8*, i8** %s, align 8 - %3 = alloca i8*, align 8 - store i8* %2, i8** %3, align 8 - %4 = call i32 @_lfortran_str_len(i8** %3) - %5 = sub i32 %4, 1 - %6 = icmp sle i32 %1, %5 - br i1 %6, label %loop.body, label %loop.end - -loop.body: ; preds = %loop.head - %7 = load i32, i32* %__explicit_iterator, align 4 - %8 = add i32 %7, 1 - store i32 %8, i32* %__explicit_iterator, align 4 - %9 = load i32, i32* %__explicit_iterator, align 4 - %10 = add i32 %9, 1 - %11 = load i8*, i8** %s, align 8 - %12 = call i8* @_lfortran_str_copy(i8* %11, i32 %10, i32 %10) - store i8* %12, i8** %c, align 8 - %13 = load i8*, i8** %c, align 8 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0)) - br label %loop.head - -loop.end: ; preds = %loop.head - br label %return - -return: ; preds = %loop.end - ret void -} - -declare i32 @_lfortran_str_len(i8**) - -declare i8* @_lfortran_str_copy(i8*, i32, i32) - -declare void @_lfortran_printf(i8*, ...) - -define i32 @main() { -.entry: - call void @_lpython_main_program() - ret i32 0 -} diff --git a/tests/tests.toml b/tests/tests.toml index 4258d332c9..b548cca84b 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -140,12 +140,6 @@ ast = true asr = true llvm = true -[[test]] -filename = "../integration_tests/loop_01.py" -ast = true -asr = true -llvm = true - [[test]] filename = "../integration_tests/array_01_decl.py" asr = true