Skip to content

Commit

Permalink
PASS: Handle bounds for arr mem in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Sep 22, 2023
1 parent c396abc commit 58da39c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,7 @@ static inline ASR::symbol_t *get_asr_owner(const ASR::expr_t *expr) {
return ASRUtils::get_asr_owner(ASR::down_cast<ASR::FunctionCall_t>(expr)->m_name);
}
default: {
throw LCompilersException("Cannot find the ASR owner of underlying symbol of expression "
+ std::to_string(expr->type));
return nullptr;
}
}
return nullptr;
Expand Down
18 changes: 18 additions & 0 deletions src/libasr/pass/pass_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,25 @@ namespace LCompilers {

ASR::expr_t* get_bound(ASR::expr_t* arr_expr, int dim, std::string bound,
Allocator& al) {
ASR::ttype_t* x_mv_type = ASRUtils::expr_type(arr_expr);
ASR::dimension_t* m_dims;
int n_dims = ASRUtils::extract_dimensions_from_ttype(x_mv_type, m_dims);
bool is_data_only_array = ASRUtils::is_fixed_size_array(m_dims, n_dims) && ASRUtils::get_asr_owner(arr_expr) &&
ASR::is_a<ASR::StructType_t>(*ASRUtils::get_asr_owner(arr_expr));
ASR::ttype_t* int32_type = ASRUtils::TYPE(ASR::make_Integer_t(al, arr_expr->base.loc, 4));
if (is_data_only_array) {
const Location& loc = arr_expr->base.loc;
ASR::expr_t* zero = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 0, int32_type));
ASR::expr_t* one = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 1, int32_type));
if( bound == "ubound" ) {
return ASRUtils::EXPR(ASR::make_IntegerBinOp_t(
al, arr_expr->base.loc, m_dims[dim - 1].m_length, ASR::binopType::Sub, one, int32_type, nullptr));
}
if ( m_dims[dim - 1].m_start != nullptr ) {
return m_dims[dim - 1].m_start;
}
return zero;
}
ASR::expr_t* dim_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_expr->base.loc, dim, int32_type));
ASR::arrayboundType bound_type = ASR::arrayboundType::LBound;
if( bound == "ubound" ) {
Expand Down

0 comments on commit 58da39c

Please sign in to comment.