Skip to content

Commit

Permalink
Merge pull request #87 from czgdp1807/array_02
Browse files Browse the repository at this point in the history
Ported ``integration_tests/pass_array_by_data_08.f90`` from LFortran and improve LC to compile it
  • Loading branch information
czgdp1807 authored Feb 7, 2024
2 parents 5babb21 + 887f4c6 commit da38f59
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ RUN(NAME array_21.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_22.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_23.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_24.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_25.cpp LABELS gcc llvm NOFAST)

RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST)
RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST)
Expand Down
25 changes: 25 additions & 0 deletions integration_tests/array_25.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <cmath>
#include <xtensor/xtensor.hpp>
#include <xtensor/xfixed.hpp>
#include "xtensor/xio.hpp"

void fill_array(xt::xtensor<int, 1>& aa);

int main() {
xt::xtensor<int, 1> a = xt::empty<int>({10});
xt::xtensor_fixed<int, xt::xshape<10>> ae = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

fill_array(a);
std::cout << a << std::endl;
if( xt::any(xt::not_equal(a, ae)) ) {
exit(2);
}
}

void fill_array(xt::xtensor<int, 1>& a) {
int i;
for( i = 0; i < 10; i++ ) {
a[i] = i;
}
}
6 changes: 3 additions & 3 deletions src/lc/clang_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,10 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
print_args = nullptr;
is_stmt_created = true;
}
} else if( cxx_operator_name == "operator()" ) {
} else if( cxx_operator_name == "operator()" || cxx_operator_name == "operator[]" ) {
clang::Expr** args = x->getArgs();
if( x->getNumArgs() == 0 ) {
throw std::runtime_error("operator() needs at least the callee to be present.");
throw std::runtime_error(cxx_operator_name + " needs at least the callee to be present.");
}

TraverseStmt(args[0]);
Expand Down Expand Up @@ -1672,7 +1672,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
name == "range" || name == "pow" || name == "equal" ||
name == "operator<" || name == "operator<=" || name == "operator>=" ||
name == "operator!=" || name == "operator\"\"i" || name == "sin" ||
name == "cos" || name == "amin" ) {
name == "cos" || name == "amin" || name == "operator[]" ) {
if( sym != nullptr && ASR::is_a<ASR::Function_t>(
*ASRUtils::symbol_get_past_external(sym)) ) {
throw std::runtime_error("Special function " + name + " cannot be overshadowed yet.");
Expand Down
15 changes: 11 additions & 4 deletions src/libasr/pass/pass_array_by_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ class PassArrayByDataProcedureVisitor : public PassUtils::PassVisitor<PassArrayB
} else {
break ;
}
if( std::find(indices.begin(), indices.end(), i) !=
indices.end() ) {
if( std::find(indices.begin(), indices.end(), i) != indices.end() ) {
if( arg_func ) {
suffix += "_" + std::string(arg_func->m_name);
suffix += "_" + ASRUtils::type_to_str(arg_func->m_function_signature);
} else {
suffix += "_" + std::string(arg->m_name);
suffix += "_" + ASRUtils::type_to_str(arg->m_type);
}
suffix += "_" + std::to_string(i);
}
ASR::expr_t* new_arg;
if (arg_func) {
Expand All @@ -151,6 +151,13 @@ class PassArrayByDataProcedureVisitor : public PassUtils::PassVisitor<PassArrayB
}
}
ASR::symbol_t* new_symbol = nullptr;
suffix = to_lower(suffix);
for( size_t suffixi = 0; suffixi < suffix.size(); suffixi++ ) {
if( !((suffix[suffixi] >= 'a' && suffix[suffixi] <= 'z') ||
(suffix[suffixi] >= '0' && suffix[suffixi] <= '9')) ) {
suffix[suffixi] = '_';
}
}
std::string new_name = std::string(x->m_name) + suffix;
if( ASR::is_a<ASR::Function_t>( *((ASR::symbol_t*) x) ) ) {
ASR::FunctionType_t* x_func_type = ASRUtils::get_FunctionType(x);
Expand Down

0 comments on commit da38f59

Please sign in to comment.