Skip to content

ASR Pass: Fix variables names to be used in C backend #1592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ RUN(NAME array_02_decl LABELS cpython llvm c)
RUN(NAME array_03_decl LABELS cpython llvm c)
RUN(NAME variable_decl_01 LABELS cpython llvm c)
RUN(NAME variable_decl_02 LABELS cpython llvm c)
RUN(NAME array_expr_01 LABELS cpython llvm)
RUN(NAME array_expr_02 LABELS cpython llvm)
RUN(NAME array_01 LABELS cpython llvm wasm)
RUN(NAME array_02 LABELS cpython wasm)
RUN(NAME array_expr_01 LABELS cpython llvm c)
RUN(NAME array_expr_02 LABELS cpython llvm c)
RUN(NAME array_01 LABELS cpython llvm wasm c)
RUN(NAME array_02 LABELS cpython wasm c)
RUN(NAME bindc_01 LABELS cpython llvm c)
RUN(NAME bindc_02 LABELS cpython llvm c)
RUN(NAME bindc_04 LABELS llvm c)
Expand All @@ -229,8 +229,8 @@ RUN(NAME print_01 LABELS cpython llvm c wasm) # wasm not yet supports
RUN(NAME print_03 LABELS x86 c wasm wasm_x86 wasm_x64) # simple test case specifically for x86, wasm_x86 and wasm_x64
RUN(NAME print_04 LABELS cpython llvm c)
RUN(NAME print_06 LABELS cpython llvm c)
RUN(NAME print_05 LABELS cpython llvm wasm wasm_x64)
RUN(NAME print_float LABELS cpython llvm wasm wasm_x64)
RUN(NAME print_05 LABELS cpython llvm c wasm wasm_x64)
RUN(NAME print_float LABELS cpython llvm c wasm wasm_x64)
RUN(NAME print_list_tuple_01 LABELS cpython llvm c)
RUN(NAME print_list_tuple_02 LABELS cpython llvm c)

Expand Down Expand Up @@ -259,7 +259,7 @@ RUN(NAME expr_15 LABELS cpython llvm c)
RUN(NAME loop_01 LABELS cpython llvm c)
RUN(NAME loop_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
RUN(NAME loop_03 LABELS cpython llvm c wasm wasm_x64)
RUN(NAME loop_04 LABELS cpython llvm)
RUN(NAME loop_04 LABELS cpython llvm c)
RUN(NAME loop_05 LABELS cpython llvm c)
RUN(NAME if_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
RUN(NAME if_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
Expand Down
4 changes: 3 additions & 1 deletion integration_tests/loop_04.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ltypes import i32

j: i32
i: i32

for i in range(5):
j = i
print("j: ", j)
print("j: ", j)
6 changes: 4 additions & 2 deletions integration_tests/loop_05.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from ltypes import i32

def f():
j :i32 = 0
j: i32 = 0
while True:
j = j + 1
print(j)
Expand All @@ -8,4 +10,4 @@ def f():
print("out of outer loop")
assert j == 5

f()
f()
2 changes: 1 addition & 1 deletion src/libasr/pass/arr_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ReplaceArraySection: public ASR::BaseExprReplacer<ReplaceArraySection> {
void replace_ArraySection(ASR::ArraySection_t* x) {
LCOMPILERS_ASSERT(current_scope != nullptr);
ASR::expr_t* x_arr_var = x->m_v;
std::string new_name = "~" + std::to_string(slice_counter) + "_slice";
std::string new_name = "__libasr__created__section__" + std::to_string(slice_counter) + "_slice";
slice_counter += 1;
char* new_var_name = s2c(al, new_name);
ASR::ttype_t* slice_asr_type = get_array_from_slice(x, x_arr_var);
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/pass/pass_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace LCompilers {
ASR::expr_t* create_var(int counter, std::string suffix, const Location& loc,
ASR::ttype_t* var_type, Allocator& al, SymbolTable*& current_scope) {
ASR::expr_t* idx_var = nullptr;
std::string str_name = "~" + std::to_string(counter) + suffix;
std::string str_name = "__libasr__created__var__" + std::to_string(counter) + suffix;
char* idx_var_name = s2c(al, str_name);

if( current_scope->get_symbol(std::string(idx_var_name)) == nullptr ) {
Expand Down