Skip to content

Commit

Permalink
Merge pull request #52 from czgdp1807/lc_32
Browse files Browse the repository at this point in the history
Ported ``integration_tests/arrays_intrin_01.f90`` from LFortran and improve LC to compile it
  • Loading branch information
czgdp1807 authored Jan 5, 2024
2 parents 8395ad4 + 7141712 commit 5d4abf6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,5 @@ RUN(NAME array_19.cpp LABELS gcc llvm NOFAST
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
RUN(NAME array_20.cpp LABELS gcc llvm NOFAST
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
RUN(NAME array_21.cpp LABELS gcc llvm NOFAST
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
30 changes: 30 additions & 0 deletions integration_tests/array_21.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <cmath>
#include <xtensor/xtensor.hpp>
#include <xtensor/xfixed.hpp>
#include "xtensor/xio.hpp"

int main() {

xt::xtensor_fixed<int, xt::xshape<11>> nums_int = {5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5};
xt::xtensor_fixed<double, xt::xshape<5>> nums_real = {1.5, -3.2, 4.5, 0.9, 7.2};

if (xt::amin(nums_int)() != -5) {
exit(2);
}
if (xt::amax(nums_int)() != 5) {
exit(2);
}
if (xt::amin(nums_real)() != -3.2) {
exit(2);
}
if (xt::amax(nums_real)() != 7.2) {
exit(2);
}

std::cout << xt::amin(nums_int)() << " " << xt::amax(nums_int)() << std::endl;
std::cout << xt::amin(nums_real)() << " " << xt::amax(nums_real)() << std::endl;

return 0;

}
16 changes: 14 additions & 2 deletions src/lc/clang_ast_to_asr.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum SpecialFunc {
Sin,
Cos,
AMax,
AMin,
Sum,
Range,
Size,
Expand All @@ -70,6 +71,7 @@ std::map<std::string, SpecialFunc> special_function_map = {
{"sin", SpecialFunc::Sin},
{"cos", SpecialFunc::Cos},
{"amax", SpecialFunc::AMax},
{"amin", SpecialFunc::AMin},
{"sum", SpecialFunc::Sum},
{"range", SpecialFunc::Range},
{"size", SpecialFunc::Size},
Expand Down Expand Up @@ -626,6 +628,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
array_indices.p, array_indices.size(),
ASRUtils::extract_type(ASRUtils::expr_type(obj)),
ASR::arraystorageType::RowMajor, nullptr);
} else if( ASR::is_a<ASR::IntrinsicArrayFunction_t>(*obj) ) {
tmp = (ASR::asr_t*) obj;
} else {
throw std::runtime_error("Only indexing arrays is supported for now with operator().");
}
Expand Down Expand Up @@ -943,7 +947,15 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
static_cast<int64_t>(ASRUtils::IntrinsicArrayFunctions::MaxVal),
args.p, 1, 0, ASRUtils::extract_type(ASRUtils::expr_type(args.p[0])),
nullptr);
} else if( sf == SpecialFunc::Sum ) {
} else if( sf == SpecialFunc::AMin ) {
if( args.size() > 1 && args.p[1] != nullptr ) {
throw std::runtime_error("dim argument not yet supported with " + func_name);
}
tmp = ASRUtils::make_IntrinsicArrayFunction_t_util(al, Lloc(x),
static_cast<int64_t>(ASRUtils::IntrinsicArrayFunctions::MinVal),
args.p, 1, 0, ASRUtils::extract_type(ASRUtils::expr_type(args.p[0])),
nullptr);
} else if( sf == SpecialFunc::Sum ) {
if( args.size() > 1 && args.p[1] != nullptr ) {
throw std::runtime_error("dim argument not yet supported with " + func_name);
}
Expand Down Expand Up @@ -1531,7 +1543,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 == "cos" || name == "amin" ) {
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

0 comments on commit 5d4abf6

Please sign in to comment.