Skip to content

Commit da38f59

Browse files
authored
Merge pull request #87 from czgdp1807/array_02
Ported ``integration_tests/pass_array_by_data_08.f90`` from LFortran and improve LC to compile it
2 parents 5babb21 + 887f4c6 commit da38f59

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ RUN(NAME array_21.cpp LABELS gcc llvm NOFAST)
207207
RUN(NAME array_22.cpp LABELS gcc llvm NOFAST)
208208
RUN(NAME array_23.cpp LABELS gcc llvm NOFAST)
209209
RUN(NAME array_24.cpp LABELS gcc llvm NOFAST)
210+
RUN(NAME array_25.cpp LABELS gcc llvm NOFAST)
210211

211212
RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST)
212213
RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST)

integration_tests/array_25.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <cmath>
3+
#include <xtensor/xtensor.hpp>
4+
#include <xtensor/xfixed.hpp>
5+
#include "xtensor/xio.hpp"
6+
7+
void fill_array(xt::xtensor<int, 1>& aa);
8+
9+
int main() {
10+
xt::xtensor<int, 1> a = xt::empty<int>({10});
11+
xt::xtensor_fixed<int, xt::xshape<10>> ae = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
12+
13+
fill_array(a);
14+
std::cout << a << std::endl;
15+
if( xt::any(xt::not_equal(a, ae)) ) {
16+
exit(2);
17+
}
18+
}
19+
20+
void fill_array(xt::xtensor<int, 1>& a) {
21+
int i;
22+
for( i = 0; i < 10; i++ ) {
23+
a[i] = i;
24+
}
25+
}

src/lc/clang_ast_to_asr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,10 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
692692
print_args = nullptr;
693693
is_stmt_created = true;
694694
}
695-
} else if( cxx_operator_name == "operator()" ) {
695+
} else if( cxx_operator_name == "operator()" || cxx_operator_name == "operator[]" ) {
696696
clang::Expr** args = x->getArgs();
697697
if( x->getNumArgs() == 0 ) {
698-
throw std::runtime_error("operator() needs at least the callee to be present.");
698+
throw std::runtime_error(cxx_operator_name + " needs at least the callee to be present.");
699699
}
700700

701701
TraverseStmt(args[0]);
@@ -1672,7 +1672,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
16721672
name == "range" || name == "pow" || name == "equal" ||
16731673
name == "operator<" || name == "operator<=" || name == "operator>=" ||
16741674
name == "operator!=" || name == "operator\"\"i" || name == "sin" ||
1675-
name == "cos" || name == "amin" ) {
1675+
name == "cos" || name == "amin" || name == "operator[]" ) {
16761676
if( sym != nullptr && ASR::is_a<ASR::Function_t>(
16771677
*ASRUtils::symbol_get_past_external(sym)) ) {
16781678
throw std::runtime_error("Special function " + name + " cannot be overshadowed yet.");

src/libasr/pass/pass_array_by_data.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ class PassArrayByDataProcedureVisitor : public PassUtils::PassVisitor<PassArrayB
126126
} else {
127127
break ;
128128
}
129-
if( std::find(indices.begin(), indices.end(), i) !=
130-
indices.end() ) {
129+
if( std::find(indices.begin(), indices.end(), i) != indices.end() ) {
131130
if( arg_func ) {
132-
suffix += "_" + std::string(arg_func->m_name);
131+
suffix += "_" + ASRUtils::type_to_str(arg_func->m_function_signature);
133132
} else {
134-
suffix += "_" + std::string(arg->m_name);
133+
suffix += "_" + ASRUtils::type_to_str(arg->m_type);
135134
}
135+
suffix += "_" + std::to_string(i);
136136
}
137137
ASR::expr_t* new_arg;
138138
if (arg_func) {
@@ -151,6 +151,13 @@ class PassArrayByDataProcedureVisitor : public PassUtils::PassVisitor<PassArrayB
151151
}
152152
}
153153
ASR::symbol_t* new_symbol = nullptr;
154+
suffix = to_lower(suffix);
155+
for( size_t suffixi = 0; suffixi < suffix.size(); suffixi++ ) {
156+
if( !((suffix[suffixi] >= 'a' && suffix[suffixi] <= 'z') ||
157+
(suffix[suffixi] >= '0' && suffix[suffixi] <= '9')) ) {
158+
suffix[suffixi] = '_';
159+
}
160+
}
154161
std::string new_name = std::string(x->m_name) + suffix;
155162
if( ASR::is_a<ASR::Function_t>( *((ASR::symbol_t*) x) ) ) {
156163
ASR::FunctionType_t* x_func_type = ASRUtils::get_FunctionType(x);

0 commit comments

Comments
 (0)