Skip to content

Commit

Permalink
Merge pull request #117 from czgdp1807/sync_libasr
Browse files Browse the repository at this point in the history
Sync ``libasr`` with LFortran/LPython
  • Loading branch information
czgdp1807 authored Mar 27, 2024
2 parents 8b52363 + 556d22f commit 522277d
Show file tree
Hide file tree
Showing 97 changed files with 22,213 additions and 7,372 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ src/libasr/wasm_visitor.h
src/libasr/config.h
fa
fa2
c_o
llvm_o
*/bin/lc
*vscode*
integration_tests/test-*
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -ex
python src/libasr/asdl_cpp.py src/lc/LC.asdl src/lc/ast.h
python src/libasr/asdl_cpp.py src/libasr/ASR.asdl src/libasr/asr.h
python src/libasr/wasm_instructions_visitor.py
python src/libasr/intrinsic_func_registry_util_gen.py

(cd src/lc/parser && re2c -W -b tokenizer.re -o tokenizer.cpp)
(cd src/lc/parser && bison -Wall -d -r all parser.yy)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ RUN(NAME array_10.cpp LABELS gcc llvm)
RUN(NAME array_11.cpp LABELS gcc llvm)
RUN(NAME array_12.cpp LABELS gcc llvm)
RUN(NAME array_13.cpp LABELS gcc llvm)
RUN(NAME array_14.cpp LABELS gcc llvm)
RUN(NAME array_14.cpp LABELS gcc llvm NOFAST) # promote_allocatable_to_nonallocatable pass cannot be applied
RUN(NAME array_15.cpp LABELS gcc llvm)
RUN(NAME array_16.cpp LABELS gcc llvm)
RUN(NAME array_17.cpp LABELS gcc llvm)
Expand Down
12 changes: 6 additions & 6 deletions integration_tests/array_14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ int main() {

xt::xtensor<int, 2> array_const_1 = {{-14, 3, 0, -2}, {19, 1, 20, 21}};
xt::xtensor_fixed<int, xt::xshape<2>> i23_shape = {4, 2};
std::cout<< array_const_1 << std::endl;
std::cout<< array_const_1 << "\n";
array_const_1.reshape(i23_shape);
std::cout << array_const_1 << std::endl;
std::cout << array_const_1(0, 0) << " " << array_const_1(0, 1) << std::endl;
std::cout << array_const_1(1, 0) << " " << array_const_1(1, 1) << std::endl;
std::cout << array_const_1(2, 0) << " " << array_const_1(2, 1) << std::endl;
std::cout << array_const_1(3, 0) << " " << array_const_1(3, 1) << std::endl;
std::cout << array_const_1 << "\n";
std::cout << array_const_1(0, 0) << " " << array_const_1(0, 1) << "\n";
std::cout << array_const_1(1, 0) << " " << array_const_1(1, 1) << "\n";
std::cout << array_const_1(2, 0) << " " << array_const_1(2, 1) << "\n";
std::cout << array_const_1(3, 0) << " " << array_const_1(3, 1) << "\n";
if( array_const_1(0, 0) != -14 ) {
exit(2);
}
Expand Down
2 changes: 1 addition & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def single_test(test, verbose, no_llvm, skip_run_with_dbg, skip_cpptranslate, update_reference,
no_color, specific_backends=None, excluded_backends=None):
verify_hash, no_color, specific_backends=None, excluded_backends=None):
filename = test["filename"]
def is_included(backend):
return test.get(backend, False) \
Expand Down
183 changes: 106 additions & 77 deletions src/lc/clang_ast_to_asr.cpp

Large diffs are not rendered by default.

376 changes: 50 additions & 326 deletions src/libasr/ASR.asdl

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SRC
codegen/asr_to_cpp.cpp
codegen/asr_to_c.cpp
codegen/asr_to_julia.cpp
codegen/asr_to_python.cpp
codegen/asr_to_fortran.cpp
codegen/asr_to_py.cpp
codegen/x86_assembler.cpp
Expand All @@ -30,9 +31,11 @@ set(SRC

pass/nested_vars.cpp
pass/where.cpp
pass/function_call_in_declaration.cpp
pass/param_to_const.cpp
pass/do_loops.cpp
pass/for_all.cpp
pass/while_else.cpp
pass/global_stmts.cpp
pass/select_case.cpp
pass/init_expr.cpp
Expand All @@ -51,6 +54,7 @@ set(SRC
pass/div_to_mul.cpp
pass/replace_symbolic.cpp
pass/intrinsic_function.cpp
pass/intrinsic_subroutine.cpp
pass/fma.cpp
pass/loop_vectorise.cpp
pass/sign_from_value.cpp
Expand All @@ -64,6 +68,7 @@ set(SRC
pass/pass_compare.cpp
pass/unique_symbols.cpp
pass/insert_deallocate.cpp
pass/promote_allocatable_to_nonallocatable.cpp

asr_verify.cpp
asr_utils.cpp
Expand Down Expand Up @@ -111,3 +116,10 @@ endif()
if (WITH_LLVM)
target_link_libraries(asr p::llvm)
endif()

# Install the dwarf_convert.py and dat_convert.py
install(
FILES dwarf_convert.py dat_convert.py
PERMISSIONS OWNER_EXECUTE OWNER_READ
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/lfortran
)
27 changes: 8 additions & 19 deletions src/libasr/asdl_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def make_visitor(self, name, fields):
symtab_field_name = field.name
if is_stmt_present and is_symtab_present:
break
if is_stmt_present and name not in ("Assignment", "ForAllSingle"):
if is_stmt_present and name not in ("Assignment", "ForAllSingle", "FileRead", "FileWrite"):
self.emit(" %s_t& xx = const_cast<%s_t&>(x);" % (name, name), 1)
self.used = False

Expand Down Expand Up @@ -562,7 +562,7 @@ def make_visitor(self, name, fields):
symtab_field_name = field.name
if is_stmt_present and is_symtab_present:
break
if is_stmt_present and name not in ("Assignment", "ForAllSingle"):
if is_stmt_present and name not in ("Assignment", "ForAllSingle", "FileRead", "FileWrite"):
self.emit(" %s_t& xx = const_cast<%s_t&>(x);" % (name, name), 1)
self.used = False

Expand Down Expand Up @@ -1029,17 +1029,13 @@ def visitConstructor(self, cons, _):
def make_visitor(self, name, fields):
self.emit("")
self.emit("ASR::asr_t* duplicate_%s(%s_t* x) {" % (name, name), 1)
self.used = False
arguments = []
arguments = ["al", "x->base.base.loc"]
for field in fields:
ret_value = self.visitField(field)
for node_arg in ret_value:
arguments.append(node_arg)
if not self.used:
self.emit("return (asr_t*)x;", 2)
else:
node_arg_str = ', '.join(arguments)
self.emit("return make_%s_t(al, x->base.base.loc, %s);" %(name, node_arg_str), 2)
node_arg_str = ', '.join(arguments)
self.emit("return make_%s_t(%s);" %(name, node_arg_str), 2)
if self.is_stmt:
self.duplicate_stmt.append((" case ASR::stmtType::%s: {" % name, 2))
if name == "SubroutineCall":
Expand Down Expand Up @@ -1088,7 +1084,6 @@ def visitField(self, field):
field.type == "dimension"):
level = 2
if field.seq:
self.used = True
pointer_char = ''
if (field.type != "call_arg" and
field.type != "array_index" and
Expand Down Expand Up @@ -1141,7 +1136,6 @@ def visitField(self, field):
self.emit("}", level)
arguments = ("m_" + field.name + ".p", "x->n_" + field.name)
else:
self.used = True
if field.type == "symbol":
self.emit("%s_t* m_%s = x->m_%s;" % (field.type, field.name, field.name), level)
elif field.type == "do_loop_head":
Expand Down Expand Up @@ -1461,12 +1455,6 @@ def visitConstructor(self, cons, _):
def make_visitor(self, name, fields, cons):
self.emit("void visit_%s(const %s_t &x) {" % (name, name), 1)
self.emit( 's.append("(");', 2)
subs = {
"Assignment": "=",
"Associate": "=>",
}
if name in subs:
name = subs[name]

# For ASR
symbol = [
Expand Down Expand Up @@ -1680,7 +1668,7 @@ def visitField(self, field, cons):
self.emit( 's.append("()");', 3)
self.emit("}", 2)
else:
if field.name == "intrinsic_id":
if field.name == "intrinsic_id" or field.name == "inquiry_id":
self.emit('s.append(self().convert_intrinsic_id(x.m_%s));' % field.name, 2)
elif field.name == "impure_intrinsic_id":
self.emit('s.append(self().convert_impure_intrinsic_id(x.m_%s));' % field.name, 2)
Expand Down Expand Up @@ -2593,7 +2581,8 @@ def make_visitor(self, name, fields):
LCOMPILERS_ASSERT(!ASR::is_a<ASR::ExternalSymbol_t>(*e->m_external));
s = e->m_external;
}
if( ASR::down_cast<ASR::Variable_t>(s)->m_storage !=
if( ASR::is_a<ASR::Function_t>(*s) ||
ASR::down_cast<ASR::Variable_t>(s)->m_storage !=
ASR::storage_typeType::Parameter ) {
return nullptr;
}
Expand Down
Loading

0 comments on commit 522277d

Please sign in to comment.