diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 74df0cd..adb29b0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -52,6 +52,7 @@ jobs: shell: bash -l -e {0} if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos') run: | + export CPATH=$CONDA_PREFIX/include:$CPATH lc --ast-dump tests/test.cpp lc --extra-arg=-Isrc/runtime/include examples/expr2.c --asr-dump ./run_tests.py @@ -77,5 +78,6 @@ jobs: shell: bash -l -e {0} if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos') run: | + export CPATH=$CONDA_PREFIX/include:$CPATH ./integration_tests/run_tests.py -b gcc llvm wasm c ./integration_tests/run_tests.py -b gcc llvm wasm c -f diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 38023a3..e8687ea 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -87,7 +87,7 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_EXTRAFILES RUN_EXT OR (LC_BACKEND STREQUAL "c") OR (LC_BACKEND STREQUAL "fortran")) add_custom_command( OUTPUT ${name}.o - COMMAND ${LC} -c ${extra_args} ${CMAKE_CURRENT_SOURCE_DIR}/${file_name} -o ${name}.o --extra-arg -I${CMAKE_CURRENT_SOURCE_DIR}/../src/runtime/include -- + COMMAND ${LC} -c ${CMAKE_CURRENT_SOURCE_DIR}/${file_name} -o ${name}.o ${extra_args} -- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_name} VERBATIM) add_executable(${name} ${name}.o ${extra_files}) @@ -176,10 +176,17 @@ endmacro(RUN) # x86 --- compile to x86 binary directly # wasm --- compile to WASM binary directly -RUN(NAME expr1.c LABELS gcc c wasm llvm NOFAST) -RUN(NAME expr2.c LABELS gcc c wasm llvm NOFAST) -RUN(NAME expr3.c FAIL LABELS gcc c wasm llvm NOFAST) +RUN(NAME expr1.c LABELS gcc c wasm llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CMAKE_CURRENT_SOURCE_DIR}/../src/runtime/include) +RUN(NAME expr2.c LABELS gcc c wasm llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CMAKE_CURRENT_SOURCE_DIR}/../src/runtime/include) +RUN(NAME expr3.c FAIL LABELS gcc c wasm llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CMAKE_CURRENT_SOURCE_DIR}/../src/runtime/include) # arrays -RUN(NAME array_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_02.cpp LABELS gcc llvm NOFAST) +RUN(NAME array_01.cpp LABELS gcc llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CMAKE_CURRENT_SOURCE_DIR}/../src/runtime/include) +RUN(NAME array_02.cpp LABELS gcc llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CMAKE_CURRENT_SOURCE_DIR}/../src/runtime/include) +RUN(NAME array_03.cpp LABELS gcc llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include) diff --git a/integration_tests/array_03.cpp b/integration_tests/array_03.cpp new file mode 100644 index 0000000..6620feb --- /dev/null +++ b/integration_tests/array_03.cpp @@ -0,0 +1,19 @@ +#include +#include "xtensor/xtensor.hpp" +#include "xtensor/xio.hpp" +#include "xtensor/xview.hpp" + +int main() { + + xt::xtensor arr1; /* { // TODO: Uncomment this initializer + {1.0, 2.0, 3.0}, + {2.0, 5.0, 7.0}, + {2.0, 5.0, 7.0}}; */ + + xt::xtensor arr2 {5.0, 6.0, 7.0}; + + // xt::xarray res = xt::view(arr1, 1) + arr2; // TODO: Uncomment this statement + std::cout << arr2; + + return 0; +} diff --git a/integration_tests/array_04.cpp b/integration_tests/array_04.cpp new file mode 100644 index 0000000..7f324bd --- /dev/null +++ b/integration_tests/array_04.cpp @@ -0,0 +1,19 @@ +#include +#include "xtensor/xtensor.hpp" +#include "xtensor/xio.hpp" +#include "xtensor/xview.hpp" + +int main() { + + xt::xtensor arr1 = { + {1.0, 2.0, 3.0}, + {2.0, 5.0, 7.0}, + {2.0, 5.0, 7.0}}; + + xt::xtensor arr2 {5.0, 6.0, 7.0}; + + // xt::xarray res = xt::view(arr1, 1) + arr2; // TODO: Uncomment this statement + std::cout << arr2; + + return 0; +} diff --git a/integration_tests/run_tests.py b/integration_tests/run_tests.py index 0e355cb..9fbeac8 100755 --- a/integration_tests/run_tests.py +++ b/integration_tests/run_tests.py @@ -85,7 +85,7 @@ def main(): # Setup global NO_OF_THREADS, fast_tests - os.environ["PATH"] += os.pathsep + LC_PATH + # os.environ["PATH"] += os.pathsep + LC_PATH # delete previously created directories (if any) for backend in SUPPORTED_BACKENDS: run_cmd(f"rm -rf {BASE_DIR}/test-{backend}") diff --git a/run_tests.py b/run_tests.py index e5886a4..f00e34b 100755 --- a/run_tests.py +++ b/run_tests.py @@ -115,4 +115,4 @@ def is_included(backend): filename, update_reference, extra_args) if __name__ == "__main__": - tester_main("LC", single_test) + tester_main("LC", single_test, True) diff --git a/src/lc/clang_ast_to_asr.h b/src/lc/clang_ast_to_asr.h index 8aed95a..c3f6158 100644 --- a/src/lc/clang_ast_to_asr.h +++ b/src/lc/clang_ast_to_asr.h @@ -521,6 +521,41 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitorbase.loc; + Vec new_shape_; new_shape_.reserve(al, target_expr_rank); + for( size_t i = 0; i < target_expr_rank; i++ ) { + new_shape_.push_back(al, ASRUtils::get_size(target_expr, i + 1, al)); + } + + Vec new_shape_dims; new_shape_dims.reserve(al, 1); + ASR::dimension_t new_shape_dim; new_shape_dim.loc = loc; + new_shape_dim.m_length = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, + target_expr_rank, ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)))); + new_shape_dim.m_start = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, + 0, ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)))); + new_shape_dims.push_back(al, new_shape_dim); + ASR::ttype_t* new_shape_type = ASRUtils::TYPE(ASR::make_Array_t(al, loc, + ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)), new_shape_dims.p, + new_shape_dims.size(), ASR::array_physical_typeType::FixedSizeArray)); + ASR::expr_t* new_shape = ASRUtils::EXPR(ASR::make_ArrayConstant_t(al, loc, + new_shape_.p, new_shape_.size(), new_shape_type, ASR::arraystorageType::RowMajor)); + ASR::expr_t* reshaped_expr = ASRUtils::EXPR(ASR::make_ArrayReshape_t(al, loc, expr, + new_shape, target_expr_type, nullptr)); + expr = reshaped_expr; + } + bool TraverseVarDecl(clang::VarDecl *x) { std::string name = x->getName().str(); if( scopes.size() > 0 ) { @@ -551,6 +586,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor init_exprs; init_exprs.reserve(al, x->getNumInits()); clang::Expr** clang_inits = x->getInits(); + ASR::expr_t* assignment_target_copy = assignment_target; + assignment_target = nullptr; for( size_t i = 0; i < x->getNumInits(); i++ ) { TraverseStmt(clang_inits[i]); init_exprs.push_back(al, ASRUtils::EXPR(tmp)); } + assignment_target = assignment_target_copy; ASR::ttype_t* type = ASRUtils::expr_type(init_exprs[init_exprs.size() - 1]); Vec dims; dims.reserve(al, 1); ASR::dimension_t dim; dim.loc = Lloc(x); diff --git a/src/libasr/compiler_tester/tester.py b/src/libasr/compiler_tester/tester.py index e6c4926..35da61c 100644 --- a/src/libasr/compiler_tester/tester.py +++ b/src/libasr/compiler_tester/tester.py @@ -336,7 +336,7 @@ def run_test(testname, basename, cmd, infile, update_reference=False, log.debug(s + " " + check()) -def tester_main(compiler, single_test): +def tester_main(compiler, single_test, is_lcompilers_executable_installed=False): parser = argparse.ArgumentParser(description=f"{compiler} Test Suite") parser.add_argument("-u", "--update", action="store_true", help="update all reference results") @@ -387,8 +387,9 @@ def tester_main(compiler, single_test): no_color = args.no_color # So that the tests find the `lcompiler` executable - os.environ["PATH"] = os.path.join(SRC_DIR, "bin") \ - + os.pathsep + os.environ["PATH"] + if not is_lcompilers_executable_installed: + os.environ["PATH"] = os.path.join(SRC_DIR, "bin") \ + + os.pathsep + os.environ["PATH"] test_data = toml.load(open(os.path.join(ROOT_DIR, "tests", "tests.toml"))) filtered_tests = test_data["test"] if specific_tests: diff --git a/tests/reference/asr-array_04-be6ac8a.json b/tests/reference/asr-array_04-be6ac8a.json new file mode 100644 index 0000000..270de19 --- /dev/null +++ b/tests/reference/asr-array_04-be6ac8a.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-array_04-be6ac8a", + "cmd": "lc --asr-dump --no-color {infile} -o {outfile} -extra-arg=\"\"", + "infile": "tests/../integration_tests/array_04.cpp", + "infile_hash": "a3e79a9500684211e6e080dc262e6f1e5005e257df6d05381f9dc9c6", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-array_04-be6ac8a.stdout", + "stdout_hash": "8ccda65df8bedf43f3a0c20870b16ce84c05bc2dad0df3e41ddd122e", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-array_04-be6ac8a.stdout b/tests/reference/asr-array_04-be6ac8a.stdout new file mode 100644 index 0000000..ba8845e --- /dev/null +++ b/tests/reference/asr-array_04-be6ac8a.stdout @@ -0,0 +1,278 @@ +(TranslationUnit + (SymbolTable + 1 + { + main: + (Function + (SymbolTable + 2 + { + __return_var: + (Variable + 2 + __return_var + [] + ReturnVar + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ), + arr1: + (Variable + 2 + arr1 + [] + Local + () + () + Default + (Allocatable + (Array + (Real 8) + [(() + ()) + (() + ())] + DescriptorArray + ) + ) + () + Source + Public + Required + .false. + ), + arr2: + (Variable + 2 + arr2 + [] + Local + () + () + Default + (Allocatable + (Array + (Real 8) + [(() + ())] + DescriptorArray + ) + ) + () + Source + Public + Required + .false. + ) + }) + main + (FunctionType + [] + (Integer 4) + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + .false. + ) + [] + [] + [(Allocate + [((Var 2 arr1) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + () + ())] + () + () + () + ) + (= + (Var 2 arr1) + (ArrayReshape + (ArrayConstant + [(RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 3.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 5.000000 + (Real 8) + ) + (RealConstant + 7.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 5.000000 + (Real 8) + ) + (RealConstant + 7.000000 + (Real 8) + )] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 9 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + (ArrayConstant + [(ArraySize + (Var 2 arr1) + (IntegerConstant 1 (Integer 4)) + (Integer 4) + () + ) + (ArraySize + (Var 2 arr1) + (IntegerConstant 2 (Integer 4)) + (Integer 4) + () + )] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 2 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + (Allocatable + (Array + (Real 8) + [(() + ()) + (() + ())] + DescriptorArray + ) + ) + () + ) + () + ) + (Allocate + [((Var 2 arr2) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + () + ())] + () + () + () + ) + (= + (Var 2 arr2) + (ArrayConstant + [(RealConstant + 5.000000 + (Real 8) + ) + (RealConstant + 6.000000 + (Real 8) + ) + (RealConstant + 7.000000 + (Real 8) + )] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (Print + [(Var 2 arr2)] + () + () + ) + (= + (Var 2 __return_var) + (IntegerConstant 0 (Integer 4)) + () + ) + (Return)] + (Var 2 __return_var) + Public + .false. + .false. + () + ), + main_program: + (Program + (SymbolTable + 3 + { + exit_code: + (Variable + 3 + exit_code + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ) + }) + main_program + [main] + [(= + (Var 3 exit_code) + (FunctionCall + 1 main + 1 main + [] + (Integer 4) + () + () + ) + () + )] + ) + }) + [] +) diff --git a/tests/tests.toml b/tests/tests.toml index fa78ca0..c273c2c 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -32,3 +32,7 @@ asr = true filename = "../integration_tests/array_02.cpp" extra_arg = "-Isrc/runtime/include" asr = true + +[[test]] +filename = "../integration_tests/array_04.cpp" +asr = true