diff --git a/.gitignore b/.gitignore index 0e0c4e6d87..82eef6dd53 100644 --- a/.gitignore +++ b/.gitignore @@ -192,5 +192,7 @@ integration_tests/structs_05 integration_tests/structs_05.c integration_tests/expr_08 integration_tests/expr_08.c +integration_tests/array_01_decl +integration_tests/array_01_decl.c integration_tests/expr_12 integration_tests/expr_12.c diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 19459b94e8..d0ce1ce315 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -113,6 +113,7 @@ endmacro(RUN) # Test zero and non-zero exit code and assert statements +RUN(NAME array_01_decl LABELS cpython llvm c) RUN(NAME bindc_01 LABELS llvm c) RUN(NAME bindc_02 LABELS llvm c) RUN(NAME bindc_04 LABELS llvm) diff --git a/integration_tests/array_01_decl.py b/integration_tests/array_01_decl.py new file mode 100644 index 0000000000..66838dd311 --- /dev/null +++ b/integration_tests/array_01_decl.py @@ -0,0 +1,32 @@ +from ltypes import i32, i64, f32, f64, c32, c64 +from numpy import empty + +def accept_i32_array(xi32: i32[:]) -> i32: + xi32[0] = 32 + return xi32[0] + +def accept_i64_array(xi64: i64[:]) -> i64: + xi64[0] = 64 + return xi64[0] + +def accept_f32_array(xf32: f32[:]) -> f32: + xf32[0] = 32.0 + return xf32[0] + +def accept_f64_array(xf64: f64[:]) -> f64: + xf64[0] = 64.0 + return xf64[0] + +def declare_arrays(): + ai32: i32[3] = empty(3) + ai64: i64[10] = empty(10) + af32: f32[3] = empty(3) + af64: f64[10] = empty(10) + ac32: c32[3] = empty(3) + ac64: c64[10] = empty(10) + print(accept_i32_array(ai32)) + print(accept_i64_array(ai64)) + print(accept_f32_array(af32)) + print(accept_f64_array(af64)) + +declare_arrays() diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index a207ac1008..78700c1184 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -11,45 +11,16 @@ #include #include +#include +#include -namespace LFortran { -std::string convert_dims_c(size_t n_dims, ASR::dimension_t *m_dims) -{ - std::string dims; - for (size_t i=0; i(*start) && ASR::is_a(*end)) { - ASR::IntegerConstant_t *s = ASR::down_cast(start); - ASR::IntegerConstant_t *e = ASR::down_cast(end); - if (s->m_n == 1) { - dims += "[" + std::to_string(e->m_n) + "]"; - } else { - throw CodeGenError("Lower dimension must be 1 for now"); - } - } else { - dims += "[ /* FIXME symbolic dimensions */ ]"; - } - } else { - throw CodeGenError("Dimension type not supported"); - } - } - return dims; -} +namespace LFortran { std::string format_type_c(const std::string &dims, const std::string &type, const std::string &name, bool use_ref, bool /*dummy*/) { std::string fmt; - // Sync: Not sure of the following code - // std::string ref = "", ptr = ""; - // if (dims.size() > 0) ptr = "*"; - // if (use_ref) ref = "&"; - // fmt = type + " " + ptr + ref + name; std::string ref = ""; if (use_ref) ref = "*"; if( dims == "*" ) { @@ -64,9 +35,15 @@ class ASRToCVisitor : public BaseCCPPVisitor { public: + std::string array_types_decls; + std::map> eltypedims2arraytype; + ASRToCVisitor(diag::Diagnostics &diag, Platform &platform, int64_t default_lower_bound) - : BaseCCPPVisitor(diag, platform, false, false, true, default_lower_bound) {} + : BaseCCPPVisitor(diag, platform, false, false, true, default_lower_bound), + array_types_decls(std::string("\nstruct dimension_descriptor\n" + "{\n int32_t lower_bound, upper_bound;\n};\n")) { + } std::string convert_dims_c(size_t n_dims, ASR::dimension_t *m_dims) { @@ -94,11 +71,84 @@ class ASRToCVisitor : public BaseCCPPVisitor return dims; } + std::string get_array_type(std::string type_name, std::string encoded_type_name, + size_t n_dims, bool make_ptr=true) { + if( eltypedims2arraytype.find(encoded_type_name) != eltypedims2arraytype.end() && + eltypedims2arraytype[encoded_type_name].find(n_dims) != + eltypedims2arraytype[encoded_type_name].end()) { + if( make_ptr ) { + return eltypedims2arraytype[encoded_type_name][n_dims] + "*"; + } else { + return eltypedims2arraytype[encoded_type_name][n_dims]; + } + } + + std::string struct_name; + std::string new_array_type; + struct_name = "struct " + encoded_type_name + "_" + std::to_string(n_dims); + std::string array_data = format_type_c("*", type_name, "data", false, false); + new_array_type = struct_name + "\n{\n " + array_data + + ";\n struct dimension_descriptor dims[" + + std::to_string(n_dims) + "];\n bool is_allocated;\n};\n"; + type_name = struct_name + "*"; + eltypedims2arraytype[encoded_type_name][n_dims] = struct_name; + array_types_decls += "\n" + new_array_type + "\n"; + return type_name; + } + + void generate_array_decl(std::string& sub, std::string v_m_name, + std::string& type_name, std::string& dims, + std::string& encoded_type_name, + ASR::dimension_t* m_dims, int n_dims, + bool use_ref, bool dummy, + bool declare_value, bool is_pointer=false) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string type_name_copy = type_name; + type_name = get_array_type(type_name, encoded_type_name, n_dims); + std::string type_name_without_ptr = get_array_type(type_name, encoded_type_name, n_dims, false); + if( declare_value ) { + std::string variable_name = std::string(v_m_name) + "_value"; + sub = format_type_c("", type_name_without_ptr, variable_name, use_ref, dummy) + ";\n"; + sub += indent + format_type_c("", type_name, v_m_name, use_ref, dummy); + sub += " = &" + variable_name + ";\n"; + if( !is_pointer ) { + sub += indent + format_type_c(dims, type_name_copy, std::string(v_m_name) + "_data", + use_ref, dummy) + ";\n"; + sub += indent + std::string(v_m_name) + "->data = " + std::string(v_m_name) + "_data;\n"; + for (int i = 0; i < n_dims; i++) { + if( m_dims[i].m_start ) { + this->visit_expr(*m_dims[i].m_start); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = 0" + ";\n"; + } + if( m_dims[i].m_end ) { + this->visit_expr(*m_dims[i].m_end); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = -1" + ";\n"; + } + } + sub.pop_back(); + sub.pop_back(); + } + } else { + sub = format_type_c("", type_name, v_m_name, use_ref, dummy); + } + } + std::string convert_variable_decl(const ASR::Variable_t &v, - bool pre_initialise_derived_type=true, bool use_static=true) + bool pre_initialise_derived_type=true, + bool use_static=true) { std::string sub; - bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || v.m_intent == LFortran::ASRUtils::intent_inout); + bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || + v.m_intent == LFortran::ASRUtils::intent_inout); + bool is_array = ASRUtils::is_array(v.m_type); bool dummy = LFortran::ASRUtils::is_arg_dummy(v.m_intent); if (ASRUtils::is_pointer(v.m_type)) { ASR::ttype_t *t2 = ASR::down_cast(v.m_type)->m_type; @@ -109,7 +159,16 @@ class ASRToCVisitor : public BaseCCPPVisitor if( !ASRUtils::is_array(v.m_type) ) { type_name.append(" *"); } - sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout, true); + } else { + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } } else if(ASR::is_a(*t2)) { ASR::Derived_t *t = ASR::down_cast(t2); std::string der_type_name = ASRUtils::symbol_name(t->m_derived_type); @@ -124,26 +183,53 @@ class ASRToCVisitor : public BaseCCPPVisitor } } else { std::string dims; - use_ref = use_ref && !ASRUtils::is_array(v.m_type); + use_ref = use_ref && !is_array; if (ASRUtils::is_integer(*v.m_type)) { headers.insert("inttypes"); ASR::Integer_t *t = ASR::down_cast(v.m_type); dims = convert_dims_c(t->n_dims, t->m_dims); std::string type_name = "int" + std::to_string(t->m_kind * 8) + "_t"; - sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else { + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_real(*v.m_type)) { ASR::Real_t *t = ASR::down_cast(v.m_type); dims = convert_dims_c(t->n_dims, t->m_dims); std::string type_name = "float"; if (t->m_kind == 8) type_name = "double"; - sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + std::string encoded_type_name = "f" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else { + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_complex(*v.m_type)) { headers.insert("complex"); ASR::Complex_t *t = ASR::down_cast(v.m_type); dims = convert_dims_c(t->n_dims, t->m_dims); std::string type_name = "float complex"; if (t->m_kind == 8) type_name = "double complex"; - sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + std::string encoded_type_name = "c" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else { + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_logical(*v.m_type)) { ASR::Logical_t *t = ASR::down_cast(v.m_type); dims = convert_dims_c(t->n_dims, t->m_dims); @@ -157,7 +243,15 @@ class ASRToCVisitor : public BaseCCPPVisitor ASR::Derived_t *t = ASR::down_cast(v.m_type); std::string der_type_name = ASRUtils::symbol_name(t->m_derived_type); std::string dims = convert_dims_c(t->n_dims, t->m_dims); - if( v.m_intent == ASRUtils::intent_local && pre_initialise_derived_type) { + if( is_array ) { + std::string encoded_type_name = "x" + der_type_name; + std::string type_name = std::string("struct ") + der_type_name; + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else if( v.m_intent == ASRUtils::intent_local && pre_initialise_derived_type) { std::string value_var_name = v.m_parent_symtab->get_unique_name(std::string(v.m_name) + "_value"); sub = format_type_c(dims, "struct " + der_type_name, value_var_name, use_ref, dummy); @@ -244,11 +338,10 @@ R"( } )"; - unit_src += head; for (auto &item : x.m_global_scope->get_scope()) { if (ASR::is_a(*item.second)) { - unit_src += "struct " + item.first + ";\n\n"; + array_types_decls += "struct " + item.first + ";\n\n"; } } @@ -262,7 +355,7 @@ R"( for (auto &item : x.m_global_scope->get_scope()) { if (ASR::is_a(*item.second)) { visit_symbol(*item.second); - unit_src += src; + array_types_decls += src; } } @@ -335,7 +428,7 @@ R"( for (auto s: headers) { to_include += "#include <" + s + ".h>\n"; } - src = to_include + unit_src; + src = to_include + head + array_types_decls + unit_src; } void visit_Program(const ASR::Program_t &x) { @@ -391,7 +484,7 @@ R"( } indentation_level -= 1; std::string end_struct = "};\n\n"; - src = open_struct + body + end_struct; + array_types_decls += open_struct + body + end_struct; } void visit_LogicalConstant(const ASR::LogicalConstant_t &x) { @@ -480,6 +573,9 @@ R"( } for (size_t i=0; ivisit_expr(*x.m_values[i]); + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_values[i])) ) { + src += "->data"; + } ASR::ttype_t* value_type = ASRUtils::expr_type(x.m_values[i]); out += get_print_type(value_type, ASR::is_a(*x.m_values[i])); v.push_back(src); diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index 246696cd48..c6f6a39c12 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -91,12 +91,17 @@ class BaseCCPPVisitor : public ASR::BaseVisitor SymbolTable* global_scope; int64_t lower_bound; + std::string template_for_Kokkos; + size_t template_number; + std::string from_std_vector_helper; + BaseCCPPVisitor(diag::Diagnostics &diag, Platform &platform, bool gen_stdstring, bool gen_stdcomplex, bool is_c, int64_t default_lower_bound) : diag{diag}, platform{platform}, gen_stdstring{gen_stdstring}, gen_stdcomplex{gen_stdcomplex}, - is_c{is_c}, global_scope{nullptr}, lower_bound{default_lower_bound} {} + is_c{is_c}, global_scope{nullptr}, lower_bound{default_lower_bound}, + template_number{0} {} void visit_TranslationUnit(const ASR::TranslationUnit_t &x) { global_scope = x.m_global_scope; @@ -233,6 +238,8 @@ R"(#include // Returns the declaration, no semi colon at the end std::string get_subroutine_declaration(const ASR::Subroutine_t &x) { + template_for_Kokkos.clear(); + template_number = 0; std::string sym_name = x.m_name; if (sym_name == "main") { sym_name = "_xx_lcompilers_changed_main_xx"; @@ -240,19 +247,31 @@ R"(#include if (sym_name == "exit") { sym_name = "_xx_lcompilers_changed_exit_xx"; } - std::string sub = "void " + sym_name + "("; + std::string func = "void " + sym_name + "("; for (size_t i=0; im_intent)); - sub += self().convert_variable_decl(*arg, false); - if (i < x.n_args-1) sub += ", "; + if( is_c ) { + func += self().convert_variable_decl(*arg, false); + } else { + func += self().convert_variable_decl(*arg, false, true); + } + if (i < x.n_args-1) func += ", "; } - sub += ")"; - return sub; + func += ")"; + if( is_c || template_for_Kokkos.empty() ) { + return func; + } + + template_for_Kokkos.pop_back(); + template_for_Kokkos.pop_back(); + return "\ntemplate <" + template_for_Kokkos + ">\n" + func; } // Returns the declaration, no semi colon at the end std::string get_function_declaration(const ASR::Function_t &x) { + template_for_Kokkos.clear(); + template_number = 0; std::string sub; ASR::Variable_t *return_var = LFortran::ASRUtils::EXPR2VAR(x.m_return_var); if (ASRUtils::is_integer(*return_var->m_type)) { @@ -304,15 +323,25 @@ R"(#include if (sym_name == "main") { sym_name = "_xx_lcompilers_changed_main_xx"; } - sub = sub + sym_name + "("; + std::string func = sub + sym_name + "("; for (size_t i=0; im_intent)); - sub += self().convert_variable_decl(*arg, false); - if (i < x.n_args-1) sub += ", "; + if( is_c ) { + func += self().convert_variable_decl(*arg, false); + } else { + func += self().convert_variable_decl(*arg, false, true); + } + if (i < x.n_args-1) func += ", "; + } + func += ")"; + if( is_c || template_for_Kokkos.empty() ) { + return func; } - sub += ")"; - return sub; + + template_for_Kokkos.pop_back(); + template_for_Kokkos.pop_back(); + return "\ntemplate <" + template_for_Kokkos + ">\n" + func; } std::string declare_all_functions(const SymbolTable &scope) { @@ -512,7 +541,7 @@ R"(#include } args += std::to_string(ASRUtils::extract_kind_from_ttype_t(x.m_type)) + "-1"; } - src = var_name + ".extent(" + args + ")"; + src = var_name + "->data->extent(" + args + ")"; } void visit_Assignment(const ASR::Assignment_t &x) { @@ -520,6 +549,9 @@ R"(#include if (ASR::is_a(*x.m_target)) { visit_Var(*ASR::down_cast(x.m_target)); target = src; + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_target)) && !is_c ) { + target += "->data"; + } } else if (ASR::is_a(*x.m_target)) { visit_ArrayItem(*ASR::down_cast(x.m_target)); target = src; @@ -529,10 +561,17 @@ R"(#include } else { LFORTRAN_ASSERT(false) } + from_std_vector_helper.clear(); self().visit_expr(*x.m_value); std::string value = src; std::string indent(indentation_level*indentation_spaces, ' '); - src = indent + target + " = " + value + ";\n"; + if( !from_std_vector_helper.empty() ) { + src = from_std_vector_helper; + } else { + src.clear(); + } + src += indent + target + " = " + value + ";\n"; + from_std_vector_helper.clear(); } void visit_IntegerConstant(const ASR::IntegerConstant_t &x) { @@ -601,10 +640,15 @@ R"(#include void visit_ArrayItem(const ASR::ArrayItem_t &x) { this->visit_expr(*x.m_v); - std::string out = src; + std::string array = src; + std::string out = array; ASR::dimension_t* m_dims; ASRUtils::extract_dimensions_from_ttype(ASRUtils::expr_type(x.m_v), m_dims); - out += "["; + if( is_c ) { + out += "->data["; + } else { + out += "->data->operator[]("; + } for (size_t i=0; i src = "/* FIXME right index */"; } out += src; - out += " - " + std::to_string(lower_bound); - if (i < x.n_args-1) out += "]["; + out += " - " + array + "->dims[" + std::to_string(i) + "].lower_bound"; + if (i < x.n_args-1) { + if( is_c ) { + out += "]["; + } else { + out += ", "; + } + } + } + if( is_c ) { + out += "]"; + } else { + out += ")"; } - out += "]"; last_expr_precedence = 2; - // if( !prefix.empty() ) { - // src = prefix + "(" + out + ")"; - // } else { - // src = out; - // } src = out; } @@ -825,6 +874,9 @@ R"(#include void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) { self().visit_expr(*x.m_arg); std::string arg_src = std::move(src); + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) ) { + arg_src += "->data"; + } std::string type_src = get_c_type_from_ttype_t(x.m_type); src = "(" + type_src + ") " + arg_src; } @@ -834,6 +886,9 @@ R"(#include std::string source_src = std::move(src); self().visit_expr(*x.m_ptr); std::string dest_src = std::move(src); + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_ptr)) ) { + dest_src += "->data"; + } std::string type_src = get_c_type_from_ttype_t(ASRUtils::expr_type(x.m_ptr)); std::string indent(indentation_level*indentation_spaces, ' '); src = indent + dest_src + " = (" + type_src + ") " + source_src + ";\n"; diff --git a/src/libasr/codegen/asr_to_cpp.cpp b/src/libasr/codegen/asr_to_cpp.cpp index cdf4668ea3..9adffd93a5 100644 --- a/src/libasr/codegen/asr_to_cpp.cpp +++ b/src/libasr/codegen/asr_to_cpp.cpp @@ -14,7 +14,8 @@ namespace LFortran { std::string format_type(const std::string &dims, const std::string &type, - const std::string &name, bool use_ref, bool dummy) + const std::string &name, bool use_ref, bool dummy, bool use_kokko=true, + std::string kokko_ref="&", bool use_name=false, size_t size=0) { std::string fmt; if (dims.size() == 0) { @@ -25,26 +26,54 @@ std::string format_type(const std::string &dims, const std::string &type, if (dummy) { std::string c; if (!use_ref) c = "const "; - fmt = "const Kokkos::View<" + c + type + dims + "> &" + name; + if( use_kokko ) { + fmt = "const Kokkos::View<" + c + type + dims + "> &" + name; + } else { + fmt = c + type + dims + " " + name; + } } else { - fmt = "Kokkos::View<" + type + dims + "> " + name - + "(\"" + name + "\")"; + if( use_kokko ) { + fmt = "Kokkos::View<" + type + dims + ">" + kokko_ref + " " + name; + if( use_name ) { + fmt += "(\"" + name + "\""; + if( size > 0 ) { + fmt += ", " + std::to_string(size); + } + fmt += ")"; + } + } else { + fmt = type + dims + " " + name; + } } } return fmt; } +std::string remove_characters(std::string s, char c) +{ + s.erase(remove(s.begin(), s.end(), c), s.end()); + return s; +} + class ASRToCPPVisitor : public BaseCCPPVisitor { public: + + std::string array_types_decls; + std::map>> eltypedims2arraytype; + ASRToCPPVisitor(diag::Diagnostics &diag, Platform &platform, int64_t default_lower_bound) : BaseCCPPVisitor(diag, platform, true, true, false, - default_lower_bound) {} + default_lower_bound), + array_types_decls(std::string("\nstruct dimension_descriptor\n" + "{\n int32_t lower_bound, upper_bound;\n};\n")) {} - std::string convert_dims(size_t n_dims, ASR::dimension_t *m_dims) + std::string convert_dims(size_t n_dims, ASR::dimension_t *m_dims, size_t& size) { std::string dims; + size = 1; for (size_t i=0; i int64_t start_int = -1, end_int = -1; ASRUtils::extract_value(start_value, start_int); ASRUtils::extract_value(end_value, end_int); + size *= (end_int - start_int + 1); dims += "[" + std::to_string(end_int - start_int + 1) + "]"; } else { + size = 0; dims += "[ /* FIXME symbolic dimensions */ ]"; } } else { @@ -68,17 +99,137 @@ class ASRToCPPVisitor : public BaseCCPPVisitor return dims; } - std::string convert_variable_decl(const ASR::Variable_t &v, bool use_static=true) + bool is_array_type_available(std::string& encoded_type_name, std::string& dims, + size_t n_dims) { + return eltypedims2arraytype.find(encoded_type_name) != eltypedims2arraytype.end() && + eltypedims2arraytype[encoded_type_name].find(dims) != + eltypedims2arraytype[encoded_type_name].end() && + eltypedims2arraytype[encoded_type_name][dims].find(n_dims) != + eltypedims2arraytype[encoded_type_name][dims].end(); + } + + std::string get_array_type(std::string type_name, std::string encoded_type_name, + std::string& dims, + size_t n_dims, bool make_ptr=true) { + if( is_array_type_available(encoded_type_name, dims, n_dims) ) { + if( make_ptr ) { + return eltypedims2arraytype[encoded_type_name][dims][n_dims] + "*"; + } else { + return eltypedims2arraytype[encoded_type_name][dims][n_dims]; + } + } + + std::string struct_name; + std::string new_array_type; + std::string dims_copy = remove_characters(dims, '['); + dims_copy = remove_characters(dims_copy, ']'); + dims_copy = remove_characters(dims_copy, '*'); + std::string name = encoded_type_name + "_" + dims_copy + "_" + std::to_string(n_dims); + struct_name = "struct " + name; + std::string array_data = format_type("*", type_name, "data", false, false, true, "*"); + new_array_type = struct_name + "\n{\n " + array_data + + ";\n dimension_descriptor dims[" + + std::to_string(n_dims) + "];\n bool is_allocated;\n\n"; + std::string constructor = " " + name + "(" + array_data + "_): data{data_} {};\n};\n"; + new_array_type += constructor; + type_name = name + "*"; + eltypedims2arraytype[encoded_type_name][dims][n_dims] = name; + array_types_decls += "\n" + new_array_type + "\n"; + return type_name; + } + + void generate_array_decl(std::string& sub, std::string v_m_name, + std::string& type_name, std::string& dims, + std::string& encoded_type_name, + ASR::dimension_t* m_dims, int n_dims, size_t size, + bool use_ref, bool dummy, + bool declare_value, bool is_pointer=false) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string type_name_copy = type_name; + type_name = get_array_type(type_name, encoded_type_name, dims, n_dims); + std::string type_name_without_ptr = get_array_type(type_name, encoded_type_name, dims, + n_dims, false); + if( declare_value ) { + std::string variable_name = std::string(v_m_name) + "_value"; + if( !is_pointer ) { + sub = format_type("*", type_name_copy, std::string(v_m_name) + "_data", + use_ref, dummy, true, "", true, size) + ";\n" + indent; + } else { + sub = indent; + } + sub += format_type("", type_name_without_ptr, variable_name, use_ref, dummy, false); + if( !is_pointer ) { + sub += "(&" + std::string(v_m_name) + "_data);\n"; + } else { + sub += ";\n"; + } + sub += indent + format_type("", type_name, v_m_name, use_ref, dummy, false); + sub += " = &" + variable_name + ";\n"; + if( !is_pointer ) { + for (int i = 0; i < n_dims; i++) { + if( m_dims[i].m_start ) { + this->visit_expr(*m_dims[i].m_start); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = 0" + ";\n"; + } + if( m_dims[i].m_end ) { + this->visit_expr(*m_dims[i].m_end); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = -1" + ";\n"; + } + } + sub.pop_back(); + sub.pop_back(); + } + } else { + sub = format_type("", type_name, v_m_name, use_ref, dummy, false); + } + } + + std::string generate_templates_for_arrays(std::string v_name) { + std::string typename_T = "T" + std::to_string(template_number); + template_for_Kokkos += "typename " + typename_T + ", "; + template_number += 1; + return typename_T + "* " + v_name; + } + + std::string convert_variable_decl(const ASR::Variable_t &v, bool use_static=true, + bool use_templates_for_arrays=false) { std::string sub; - bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || v.m_intent == LFortran::ASRUtils::intent_inout); + bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || + + v.m_intent == LFortran::ASRUtils::intent_inout); + bool is_array = ASRUtils::is_array(v.m_type); bool dummy = LFortran::ASRUtils::is_arg_dummy(v.m_intent); if (ASRUtils::is_pointer(v.m_type)) { ASR::ttype_t *t2 = ASR::down_cast(v.m_type)->m_type; if (ASRUtils::is_integer(*t2)) { ASR::Integer_t *t = ASR::down_cast(t2); - std::string dims = convert_dims(t->n_dims, t->m_dims); - sub = format_type(dims, "int *", v.m_name, use_ref, dummy); + size_t size; + std::string dims = convert_dims(t->n_dims, t->m_dims, size); + std::string type_name = "int" + std::to_string(t->m_kind * 8) + "_t"; + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out, true); + } + } else { + sub = format_type(dims, "int *", v.m_name, use_ref, dummy); + } } else { diag.codegen_error_label("Type number '" + std::to_string(v.m_type->type) @@ -87,36 +238,101 @@ class ASRToCPPVisitor : public BaseCCPPVisitor } } else { std::string dims; + use_ref = use_ref && !is_array; if (ASRUtils::is_integer(*v.m_type)) { ASR::Integer_t *t = ASR::down_cast(v.m_type); - dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); std::string type_name = "int"; if (t->m_kind == 8) type_name = "long long"; - sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_real(*v.m_type)) { ASR::Real_t *t = ASR::down_cast(v.m_type); - dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); std::string type_name = "float"; if (t->m_kind == 8) type_name = "double"; - sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "f" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_complex(*v.m_type)) { ASR::Complex_t *t = ASR::down_cast(v.m_type); - dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); std::string type_name = "std::complex"; if (t->m_kind == 8) type_name = "std::complex"; - sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "c" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_logical(*v.m_type)) { ASR::Logical_t *t = ASR::down_cast(v.m_type); - dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); sub = format_type(dims, "bool", v.m_name, use_ref, dummy); } else if (ASRUtils::is_character(*v.m_type)) { ASR::Character_t *t = ASR::down_cast(v.m_type); - dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); sub = format_type(dims, "std::string", v.m_name, use_ref, dummy); } else if (ASR::is_a(*v.m_type)) { ASR::Derived_t *t = ASR::down_cast(v.m_type); - dims = convert_dims(t->n_dims, t->m_dims); - sub = format_type(dims, "struct", v.m_name, use_ref, dummy); + std::string der_type_name = ASRUtils::symbol_name(t->m_derived_type); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "x" + der_type_name; + std::string type_name = std::string("struct ") + der_type_name; + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, "struct", v.m_name, use_ref, dummy); + } } else { diag.codegen_error_label("Type number '" + std::to_string(v.m_type->type) @@ -166,7 +382,6 @@ Kokkos::View from_std_vector(const std::vector &v) } )"; - unit_src += headers; // Pre-declare all functions first, then generate code @@ -233,7 +448,7 @@ Kokkos::View from_std_vector(const std::vector &v) } } - src = unit_src; + src = headers + array_types_decls + unit_src; } void visit_Program(const ASR::Program_t &x) { @@ -366,6 +581,8 @@ Kokkos::View from_std_vector(const std::vector &v) } void visit_ArrayConstant(const ASR::ArrayConstant_t &x) { + std::string indent(indentation_level * indentation_spaces, ' '); + from_std_vector_helper = indent + "Kokkos::View r;\n"; std::string out = "from_std_vector({"; for (size_t i=0; ivisit_expr(*x.m_args[i]); @@ -373,7 +590,8 @@ Kokkos::View from_std_vector(const std::vector &v) if (i < x.n_args-1) out += ", "; } out += "})"; - src = out; + from_std_vector_helper += indent + "r = " + out + ";\n"; + src = "&r"; last_expr_precedence = 2; } diff --git a/tests/reference/asr-array_01_decl-39cf894.json b/tests/reference/asr-array_01_decl-39cf894.json new file mode 100644 index 0000000000..9de6947131 --- /dev/null +++ b/tests/reference/asr-array_01_decl-39cf894.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-array_01_decl-39cf894", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/array_01_decl.py", + "infile_hash": "e5f2b6082b67a8a7847e7051d7b4d3c954d1ea88d865326810543dca", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-array_01_decl-39cf894.stdout", + "stdout_hash": "3c22d34aae7280247cbdbb3e306279fa395498b5ec5b4cb0730c7d1c", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-array_01_decl-39cf894.stdout b/tests/reference/asr-array_01_decl-39cf894.stdout new file mode 100644 index 0000000000..1839d1dfb2 --- /dev/null +++ b/tests/reference/asr-array_01_decl-39cf894.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 8 {}) _lpython_main_program [] [(SubroutineCall 1 declare_arrays () [] ())] Source Public Implementation () .false. .false.), accept_f32_array: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Real 4 []) Source Public Required .false.), xf32: (Variable 4 xf32 InOut () () Default (Real 4 [(() ())]) Source Public Required .false.)}) accept_f32_array [(Var 4 xf32)] [(= (ArrayItem (Var 4 xf32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 4 []) ()) (Cast (RealConstant 3.20000000000000000e+01 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.20000000000000000e+01 (Real 4 []))) ()) (= (Var 4 _lpython_return_variable) (ArrayItem (Var 4 xf32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 4 []) ()) ()) (Return)] (Var 4 _lpython_return_variable) Source Public Implementation ()), accept_f64_array: (Function (SymbolTable 5 {_lpython_return_variable: (Variable 5 _lpython_return_variable ReturnVar () () Default (Real 8 []) Source Public Required .false.), xf64: (Variable 5 xf64 InOut () () Default (Real 8 [(() ())]) Source Public Required .false.)}) accept_f64_array [(Var 5 xf64)] [(= (ArrayItem (Var 5 xf64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 8 []) ()) (RealConstant 6.40000000000000000e+01 (Real 8 [])) ()) (= (Var 5 _lpython_return_variable) (ArrayItem (Var 5 xf64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 8 []) ()) ()) (Return)] (Var 5 _lpython_return_variable) Source Public Implementation ()), accept_i32_array: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), xi32: (Variable 2 xi32 InOut () () Default (Integer 4 [(() ())]) Source Public Required .false.)}) accept_i32_array [(Var 2 xi32)] [(= (ArrayItem (Var 2 xi32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 4 []) ()) (IntegerConstant 32 (Integer 4 [])) ()) (= (Var 2 _lpython_return_variable) (ArrayItem (Var 2 xi32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 4 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), accept_i64_array: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), xi64: (Variable 3 xi64 InOut () () Default (Integer 8 [(() ())]) Source Public Required .false.)}) accept_i64_array [(Var 3 xi64)] [(= (ArrayItem (Var 3 xi64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 8 []) ()) (Cast (IntegerConstant 64 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 3 _lpython_return_variable) (ArrayItem (Var 3 xi64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 8 []) ()) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), declare_arrays: (Subroutine (SymbolTable 6 {ac32: (Variable 6 ac32 Local () () Default (Complex 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), ac64: (Variable 6 ac64 Local () () Default (Complex 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.), af32: (Variable 6 af32 Local () () Default (Real 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), af64: (Variable 6 af64 Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.), ai32: (Variable 6 ai32 Local () () Default (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), ai64: (Variable 6 ai64 Local () () Default (Integer 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.)}) declare_arrays [] [(Print () [(FunctionCall 1 accept_i32_array () [((Var 6 ai32))] (Integer 4 []) () ())] () ()) (Print () [(FunctionCall 1 accept_i64_array () [((Var 6 ai64))] (Integer 8 []) () ())] () ()) (Print () [(FunctionCall 1 accept_f32_array () [((Var 6 af32))] (Real 4 []) () ())] () ()) (Print () [(FunctionCall 1 accept_f64_array () [((Var 6 af64))] (Real 8 []) () ())] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 7 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/c-c_interop1-e215531.json b/tests/reference/c-c_interop1-e215531.json index 02760a4761..c7b64eac0e 100644 --- a/tests/reference/c-c_interop1-e215531.json +++ b/tests/reference/c-c_interop1-e215531.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-c_interop1-e215531.stdout", - "stdout_hash": "c00467c1d9fa09bcf6f68553e99b4f18155e3f5548d94e64d36154f6", + "stdout_hash": "11cf8db8c889d3cecf22754b1cbefd486dacf602f0c3be8955b783b6", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-c_interop1-e215531.stdout b/tests/reference/c-c_interop1-e215531.stdout index c428b3b8c9..5828379972 100644 --- a/tests/reference/c-c_interop1-e215531.stdout +++ b/tests/reference/c-c_interop1-e215531.stdout @@ -28,6 +28,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations double f(double x); void g(double a, float b, int64_t c, int32_t d); diff --git a/tests/reference/c-expr7-bb2692a.json b/tests/reference/c-expr7-bb2692a.json index 0f9107c910..6dfe42d440 100644 --- a/tests/reference/c-expr7-bb2692a.json +++ b/tests/reference/c-expr7-bb2692a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-expr7-bb2692a.stdout", - "stdout_hash": "70172bc56a956c878dc8482015f5c2c043d0d0ceb38c73503e718320", + "stdout_hash": "d92016ec76d96205acde2d16bccf0e4ae23c3ad2c3c7f24117fd9a10", "stderr": "c-expr7-bb2692a.stderr", "stderr_hash": "28509dd59a386eebd632340a550d14299cd2a921ef6dc3ac7dbe7fe9", "returncode": 0 diff --git a/tests/reference/c-expr7-bb2692a.stdout b/tests/reference/c-expr7-bb2692a.stdout index 4e850e83ea..92951d046b 100644 --- a/tests/reference/c-expr7-bb2692a.stdout +++ b/tests/reference/c-expr7-bb2692a.stdout @@ -30,6 +30,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void main0(); diff --git a/tests/reference/c-expr_11-c452314.json b/tests/reference/c-expr_11-c452314.json index 6b95f7ff3d..178a814c7a 100644 --- a/tests/reference/c-expr_11-c452314.json +++ b/tests/reference/c-expr_11-c452314.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-expr_11-c452314.stdout", - "stdout_hash": "d813a0159ad56648560c2f020f991cd86d0d1a028a009f944a2af69c", + "stdout_hash": "739494cc9be85e9355203dafb1230c7ef9a43852641592e8b8319e5e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-expr_11-c452314.stdout b/tests/reference/c-expr_11-c452314.stdout index 8e02880b61..211d50eb35 100644 --- a/tests/reference/c-expr_11-c452314.stdout +++ b/tests/reference/c-expr_11-c452314.stdout @@ -28,6 +28,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void f(); diff --git a/tests/reference/c-expr_12-93c7780.json b/tests/reference/c-expr_12-93c7780.json index 2b013dc55e..3038d1f4a4 100644 --- a/tests/reference/c-expr_12-93c7780.json +++ b/tests/reference/c-expr_12-93c7780.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-expr_12-93c7780.stdout", - "stdout_hash": "df9dd4c8b17d5a8a32ca79e0820e7e2cc9156ab720dcf5e07bd644ee", + "stdout_hash": "c7677148e29aaf35b4dbf9839a76e00bc846fc978ec9fab4f03df9ef", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-expr_12-93c7780.stdout b/tests/reference/c-expr_12-93c7780.stdout index 47924378fb..1058553a0e 100644 --- a/tests/reference/c-expr_12-93c7780.stdout +++ b/tests/reference/c-expr_12-93c7780.stdout @@ -28,11 +28,24 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; + +struct i16_1 +{ + int16_t *data; + struct dimension_descriptor dims[1]; + bool is_allocated; +}; + // Forward declarations void _lpython_main_program(); -void check(int16_t **ptr); +void check(struct i16_1* *ptr); void f(); -void g(int16_t **x, int16_t *y); +void g(struct i16_1* *x, struct i16_1* y); // Implementations void _lpython_main_program() @@ -40,26 +53,33 @@ void _lpython_main_program() f(); } -void check(int16_t **ptr) +void check(struct i16_1* *ptr) { - ASSERT((*ptr)[0 - 0] == 1); - ASSERT((*ptr)[1 - 0] == 2); + ASSERT((*ptr)->data[0 - (*ptr)->dims[0].lower_bound] == 1); + ASSERT((*ptr)->data[1 - (*ptr)->dims[0].lower_bound] == 2); } void f() { - int16_t y[2]; - int16_t *yptr1; + struct i16_1 y_value; + struct i16_1* y = &y_value; + int16_t y_data[2]; + y->data = y_data; + y->dims[0].lower_bound = 0; + y->dims[0].upper_bound = 2 - 1; + struct i16_1 yptr1_value; + struct i16_1* yptr1 = &yptr1_value; +; g(&yptr1, y); check(&yptr1); } -void g(int16_t **x, int16_t *y) +void g(struct i16_1* *x, struct i16_1* y) { - y[0 - 0] = 1; - y[1 - 0] = 2; + y->data[0 - y->dims[0].lower_bound] = 1; + y->data[1 - y->dims[0].lower_bound] = 2; (*x) = y; - printf("%d%s%d\n", (*x)[0 - 0], " ", (*x)[1 - 0]); + printf("%d%s%d\n", (*x)->data[0 - (*x)->dims[0].lower_bound], " ", (*x)->data[1 - (*x)->dims[0].lower_bound]); } int main(int argc, char* argv[]) diff --git a/tests/reference/c-loop1-3e341c7.json b/tests/reference/c-loop1-3e341c7.json index 9b3e772589..314c7b5290 100644 --- a/tests/reference/c-loop1-3e341c7.json +++ b/tests/reference/c-loop1-3e341c7.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-loop1-3e341c7.stdout", - "stdout_hash": "b6f5d4094e8c39da6dbb52a047d31f332b54d989165854cceb047443", + "stdout_hash": "e08e4a1f49bac2a5b1d2f6d3d0aa26b1d18c86c2d2e92e956c91e3f3", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-loop1-3e341c7.stdout b/tests/reference/c-loop1-3e341c7.stdout index 902eefd4ea..e4fd17672c 100644 --- a/tests/reference/c-loop1-3e341c7.stdout +++ b/tests/reference/c-loop1-3e341c7.stdout @@ -28,6 +28,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void main0(); diff --git a/tests/reference/c-loop2-ce7de51.json b/tests/reference/c-loop2-ce7de51.json index 35c7f90c6b..abe3222a9a 100644 --- a/tests/reference/c-loop2-ce7de51.json +++ b/tests/reference/c-loop2-ce7de51.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-loop2-ce7de51.stdout", - "stdout_hash": "9c058de2e40792a0d3cb2d7003a3dc46271fedf9e5dfb3f87bee469e", + "stdout_hash": "21de5e08fb5e9bddada23a0e08ec66c952ffcf30d3b157c2aeeff98d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-loop2-ce7de51.stdout b/tests/reference/c-loop2-ce7de51.stdout index bfefbbdfc6..afcf3fe12c 100644 --- a/tests/reference/c-loop2-ce7de51.stdout +++ b/tests/reference/c-loop2-ce7de51.stdout @@ -28,6 +28,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void test_for(); diff --git a/tests/reference/c-print_01-4d44628.json b/tests/reference/c-print_01-4d44628.json index 4cf3b64363..020147f687 100644 --- a/tests/reference/c-print_01-4d44628.json +++ b/tests/reference/c-print_01-4d44628.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-print_01-4d44628.stdout", - "stdout_hash": "e95d95c8e25982139cb44babfc18494b55348f6e48d6c433ad578ce8", + "stdout_hash": "4ab24d8f04f3ff2b361bf69dab7ab2d6c5f40ee79d064dc58aced844", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-print_01-4d44628.stdout b/tests/reference/c-print_01-4d44628.stdout index 78b9d194d4..c7d9995922 100644 --- a/tests/reference/c-print_01-4d44628.stdout +++ b/tests/reference/c-print_01-4d44628.stdout @@ -27,6 +27,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void f(); diff --git a/tests/reference/c-test_issue_518-fbbd299.json b/tests/reference/c-test_issue_518-fbbd299.json index 0139b3fac4..a9617be2a0 100644 --- a/tests/reference/c-test_issue_518-fbbd299.json +++ b/tests/reference/c-test_issue_518-fbbd299.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c-test_issue_518-fbbd299.stdout", - "stdout_hash": "99b0491059f24fd028822e679351de3f901425299134d7ca6d1cbd05", + "stdout_hash": "89ab7f8ea0768b679a36909acc7689f55cac48896b3e062920e1a304", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c-test_issue_518-fbbd299.stdout b/tests/reference/c-test_issue_518-fbbd299.stdout index 1ca49d0887..672c2277c9 100644 --- a/tests/reference/c-test_issue_518-fbbd299.stdout +++ b/tests/reference/c-test_issue_518-fbbd299.stdout @@ -28,6 +28,11 @@ } \ } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); int64_t fib(int64_t n); diff --git a/tests/reference/cpp-assert1-ba60925.json b/tests/reference/cpp-assert1-ba60925.json index 5485707485..bc85af6497 100644 --- a/tests/reference/cpp-assert1-ba60925.json +++ b/tests/reference/cpp-assert1-ba60925.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-assert1-ba60925.stdout", - "stdout_hash": "8b282cfeb74b4f1210b23a62fa9387d3e9ccf972db1f50e3d85bc06b", + "stdout_hash": "53b55e831edf78c24f014e840ff1d2994764b4811cd20920121bbaae", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-assert1-ba60925.stdout b/tests/reference/cpp-assert1-ba60925.stdout index c5bb74f047..5428ace0b9 100644 --- a/tests/reference/cpp-assert1-ba60925.stdout +++ b/tests/reference/cpp-assert1-ba60925.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_assert(); namespace { diff --git a/tests/reference/cpp-doconcurrentloop_01-4e9f274.json b/tests/reference/cpp-doconcurrentloop_01-4e9f274.json index 4f28eb74c0..6d2e1d56ca 100644 --- a/tests/reference/cpp-doconcurrentloop_01-4e9f274.json +++ b/tests/reference/cpp-doconcurrentloop_01-4e9f274.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-doconcurrentloop_01-4e9f274.stdout", - "stdout_hash": "1fd2ff609df3374483feb7926035378b8f6162f0817e5c9fd8cb66f6", + "stdout_hash": "9bb561c231e3818ca09e0360728ea61edce90358ff38b821509db884", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout b/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout index 2fbcac0075..28fc327efa 100644 --- a/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout +++ b/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout @@ -17,10 +17,27 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; + +struct f32_10000_1 +{ + Kokkos::View* data; + dimension_descriptor dims[1]; + bool is_allocated; + + f32_10000_1(Kokkos::View* data_): data{data_} {}; +}; + // Forward declarations void _lpython_main_program(); void main0(); -void triad(const Kokkos::View &a, const Kokkos::View &b, float scalar, const Kokkos::View &c); + +template +void triad(T0* a, T1* b, float scalar, T2* c); namespace { } @@ -32,27 +49,41 @@ void _lpython_main_program() void main0() { - Kokkos::View a("a"); - Kokkos::View b("b"); - Kokkos::View c("c"); + Kokkos::View a_data("a_data", 10000); + f32_10000_1 a_value(&a_data); + f32_10000_1* a = &a_value; + a->dims[0].lower_bound = 0; + a->dims[0].upper_bound = 10000 - 1; + Kokkos::View b_data("b_data", 10000); + f32_10000_1 b_value(&b_data); + f32_10000_1* b = &b_value; + b->dims[0].lower_bound = 0; + b->dims[0].upper_bound = 10000 - 1; + Kokkos::View c_data("c_data", 10000); + f32_10000_1 c_value(&c_data); + f32_10000_1* c = &c_value; + c->dims[0].lower_bound = 0; + c->dims[0].upper_bound = 10000 - 1; int nsize; float scalar; scalar = 1.00000000000000000e+01; nsize = 1234; Kokkos::parallel_for(Kokkos::RangePolicy(0, nsize - 1+1), KOKKOS_LAMBDA(const long i) { - a[i - 0] = 5.00000000000000000e+00; - b[i - 0] = 5.00000000000000000e+00; + a->data->operator[](i - a->dims[0].lower_bound) = 5.00000000000000000e+00; + b->data->operator[](i - b->dims[0].lower_bound) = 5.00000000000000000e+00; }); triad(a, b, scalar, c); std::cout << "End Stream Triad" << std::endl; } -void triad(const Kokkos::View &a, const Kokkos::View &b, float scalar, const Kokkos::View &c) + +template +void triad(T0* a, T1* b, float scalar, T2* c) { int N; N = 1234; Kokkos::parallel_for(Kokkos::RangePolicy(0, N - 1+1), KOKKOS_LAMBDA(const long i) { - c[i - 0] = a[i - 0] + scalar*b[i - 0]; + c->data->operator[](i - c->dims[0].lower_bound) = a->data->operator[](i - a->dims[0].lower_bound) + scalar*b->data->operator[](i - b->dims[0].lower_bound); }); } diff --git a/tests/reference/cpp-expr12-fd2ea87.json b/tests/reference/cpp-expr12-fd2ea87.json index 1a058d4a07..3209a9cb90 100644 --- a/tests/reference/cpp-expr12-fd2ea87.json +++ b/tests/reference/cpp-expr12-fd2ea87.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr12-fd2ea87.stdout", - "stdout_hash": "35c946cfdef6a2bd02ef28b0605f2c1d821af3326b9e529b0220b0ec", + "stdout_hash": "16e2493ec2f3c2ffe6f5f4fc70b1724628d80b847d773694e2b34f76", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr12-fd2ea87.stdout b/tests/reference/cpp-expr12-fd2ea87.stdout index 11232918ad..2fd104ce20 100644 --- a/tests/reference/cpp-expr12-fd2ea87.stdout +++ b/tests/reference/cpp-expr12-fd2ea87.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); int32_t check(); diff --git a/tests/reference/cpp-expr15-1661c0d.json b/tests/reference/cpp-expr15-1661c0d.json index 84cc96c2f6..80d07ca85f 100644 --- a/tests/reference/cpp-expr15-1661c0d.json +++ b/tests/reference/cpp-expr15-1661c0d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr15-1661c0d.stdout", - "stdout_hash": "70cc2c6b194a476a7b67af334e96c4570e70ea404b65cf667a16aec7", + "stdout_hash": "e3305bf4072f36329f274c61b5350069eb061c33db0dfad2309bbe0f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr15-1661c0d.stdout b/tests/reference/cpp-expr15-1661c0d.stdout index 80e928fe99..74313bd15a 100644 --- a/tests/reference/cpp-expr15-1661c0d.stdout +++ b/tests/reference/cpp-expr15-1661c0d.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); double test1(); diff --git a/tests/reference/cpp-expr2-09c05ad.json b/tests/reference/cpp-expr2-09c05ad.json index f5e3af0491..f27d421c2f 100644 --- a/tests/reference/cpp-expr2-09c05ad.json +++ b/tests/reference/cpp-expr2-09c05ad.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr2-09c05ad.stdout", - "stdout_hash": "8479eec5f8c040c388befa390463632b86dbb03913a4b3a3d1212b42", + "stdout_hash": "5401db0a1f1a2373b4af5a0b900948971a0db09c0fb61731248e7748", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr2-09c05ad.stdout b/tests/reference/cpp-expr2-09c05ad.stdout index 4b194fc75e..92c6ca0ef4 100644 --- a/tests/reference/cpp-expr2-09c05ad.stdout +++ b/tests/reference/cpp-expr2-09c05ad.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_boolOp(); namespace { diff --git a/tests/reference/cpp-expr3-9c516d4.json b/tests/reference/cpp-expr3-9c516d4.json index ff5eef9ce1..4a2dec1a81 100644 --- a/tests/reference/cpp-expr3-9c516d4.json +++ b/tests/reference/cpp-expr3-9c516d4.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr3-9c516d4.stdout", - "stdout_hash": "5b2d0f5178378312fe2c1bcc8d023d5c3250248f4d414d98e645f7e6", + "stdout_hash": "da9607eab5ea52af03b2ba3b55eaff7486e7bf6fdb2971516324c392", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr3-9c516d4.stdout b/tests/reference/cpp-expr3-9c516d4.stdout index 0753269fe4..a2d0d7158e 100644 --- a/tests/reference/cpp-expr3-9c516d4.stdout +++ b/tests/reference/cpp-expr3-9c516d4.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_cast(); namespace { diff --git a/tests/reference/cpp-expr5-1de0e30.json b/tests/reference/cpp-expr5-1de0e30.json index 11dafac883..de1e9b9607 100644 --- a/tests/reference/cpp-expr5-1de0e30.json +++ b/tests/reference/cpp-expr5-1de0e30.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr5-1de0e30.stdout", - "stdout_hash": "49e7a502b06e9092a40717c402ffb22c8e9041f2afe4a5d0210cfa4c", + "stdout_hash": "3c42d21ec57653b0b2f007761f5f203436d2b96cbd13a616a9c8e14e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr5-1de0e30.stdout b/tests/reference/cpp-expr5-1de0e30.stdout index a782c11532..987e458078 100644 --- a/tests/reference/cpp-expr5-1de0e30.stdout +++ b/tests/reference/cpp-expr5-1de0e30.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_StrOp_concat(); namespace { diff --git a/tests/reference/cpp-expr6-f337f4f.json b/tests/reference/cpp-expr6-f337f4f.json index 18d57b23bf..498e1d5d8a 100644 --- a/tests/reference/cpp-expr6-f337f4f.json +++ b/tests/reference/cpp-expr6-f337f4f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr6-f337f4f.stdout", - "stdout_hash": "89cf078cdb62250496f64ac5bbcd5fa308760e51af457624515ddd89", + "stdout_hash": "478dab3faafde1d5d8e5176571bf928597b23ac4ad84c9a8c781b5bf", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr6-f337f4f.stdout b/tests/reference/cpp-expr6-f337f4f.stdout index 4cb0d7b78d..0077d43832 100644 --- a/tests/reference/cpp-expr6-f337f4f.stdout +++ b/tests/reference/cpp-expr6-f337f4f.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_ifexp(); namespace { diff --git a/tests/reference/cpp-expr7-529bd53.json b/tests/reference/cpp-expr7-529bd53.json index 2886061416..2735fe7307 100644 --- a/tests/reference/cpp-expr7-529bd53.json +++ b/tests/reference/cpp-expr7-529bd53.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr7-529bd53.stdout", - "stdout_hash": "cbb3219cd63cea6bdd16b996b99616ae41b2b57dd71b05caeaf427de", + "stdout_hash": "4bef0a6c627ce074197b3bf54162f8c2e24e2b66a7b324a0e5ca7b8b", "stderr": "cpp-expr7-529bd53.stderr", "stderr_hash": "28509dd59a386eebd632340a550d14299cd2a921ef6dc3ac7dbe7fe9", "returncode": 0 diff --git a/tests/reference/cpp-expr7-529bd53.stdout b/tests/reference/cpp-expr7-529bd53.stdout index 3aa579baa6..f93f363285 100644 --- a/tests/reference/cpp-expr7-529bd53.stdout +++ b/tests/reference/cpp-expr7-529bd53.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void main0(); diff --git a/tests/reference/cpp-expr8-704cece.json b/tests/reference/cpp-expr8-704cece.json index 778c842363..77d2470ce8 100644 --- a/tests/reference/cpp-expr8-704cece.json +++ b/tests/reference/cpp-expr8-704cece.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr8-704cece.stdout", - "stdout_hash": "c92b25d717ad1695250b3f3e685f13f94b655fb4e5928d04994acc98", + "stdout_hash": "2505bf4cefef153ad87a401a9173b8beedc1b6e995ecd800535e26ad", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr8-704cece.stdout b/tests/reference/cpp-expr8-704cece.stdout index 21aaa9d7ca..1055c46ec5 100644 --- a/tests/reference/cpp-expr8-704cece.stdout +++ b/tests/reference/cpp-expr8-704cece.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_binop(); int32_t __lpython_overloaded_2___lpython_floordiv(int a, int b); diff --git a/tests/reference/cpp-expr9-48868e9.json b/tests/reference/cpp-expr9-48868e9.json index f1fd2f0d9f..5690ec43ac 100644 --- a/tests/reference/cpp-expr9-48868e9.json +++ b/tests/reference/cpp-expr9-48868e9.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr9-48868e9.stdout", - "stdout_hash": "e6178dd2619299b23b5bbb49bdf1667785f00037b0dcd85c6df7383b", + "stdout_hash": "2ec5400d453f21957358100a557a924a6adf39bcec446b8d6ba5167d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr9-48868e9.stdout b/tests/reference/cpp-expr9-48868e9.stdout index c2c0b1fbaa..475c4f861c 100644 --- a/tests/reference/cpp-expr9-48868e9.stdout +++ b/tests/reference/cpp-expr9-48868e9.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void main0(); diff --git a/tests/reference/cpp-expr_11-422c839.json b/tests/reference/cpp-expr_11-422c839.json index 24ca5101b7..d93de22007 100644 --- a/tests/reference/cpp-expr_11-422c839.json +++ b/tests/reference/cpp-expr_11-422c839.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr_11-422c839.stdout", - "stdout_hash": "ed5b929f3c9ee51fff1d8cc1043b3f0b47734110cd431b5039abd429", + "stdout_hash": "0b56a8baf53c511c57ea1c5d33b0149b3284e71246a3e444fcbe6b4a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr_11-422c839.stdout b/tests/reference/cpp-expr_11-422c839.stdout index dc2825d338..c12948960b 100644 --- a/tests/reference/cpp-expr_11-422c839.stdout +++ b/tests/reference/cpp-expr_11-422c839.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void f(); diff --git a/tests/reference/cpp-loop1-0a8cf3b.json b/tests/reference/cpp-loop1-0a8cf3b.json index cf94dbd24f..f3aa4f55cc 100644 --- a/tests/reference/cpp-loop1-0a8cf3b.json +++ b/tests/reference/cpp-loop1-0a8cf3b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-loop1-0a8cf3b.stdout", - "stdout_hash": "8ed38a8b917c268099a66f7a3ba0d4de4495d034dd0d311ca6e8e609", + "stdout_hash": "c7c48ac70b150b4f6e4eef61d0cd32072512ee8fde7c6b4838152e08", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-loop1-0a8cf3b.stdout b/tests/reference/cpp-loop1-0a8cf3b.stdout index 63f458abbc..90788b95f4 100644 --- a/tests/reference/cpp-loop1-0a8cf3b.stdout +++ b/tests/reference/cpp-loop1-0a8cf3b.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void main0(); diff --git a/tests/reference/cpp-loop2-0686fc4.json b/tests/reference/cpp-loop2-0686fc4.json index 9eb3a68430..221d9b69b6 100644 --- a/tests/reference/cpp-loop2-0686fc4.json +++ b/tests/reference/cpp-loop2-0686fc4.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-loop2-0686fc4.stdout", - "stdout_hash": "a86d4381f0752ce2e9daab0f8622bd0bb1fd8943df1e1783bdefca72", + "stdout_hash": "42ea1370886d7b6af7c21ea91db667e76d6993662930d2e2925a53a4", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-loop2-0686fc4.stdout b/tests/reference/cpp-loop2-0686fc4.stdout index 1b452ba3f2..b773451b7c 100644 --- a/tests/reference/cpp-loop2-0686fc4.stdout +++ b/tests/reference/cpp-loop2-0686fc4.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void test_for(); diff --git a/tests/reference/cpp-loop3-6020091.json b/tests/reference/cpp-loop3-6020091.json index b8a3b6c95c..d9e94a99d1 100644 --- a/tests/reference/cpp-loop3-6020091.json +++ b/tests/reference/cpp-loop3-6020091.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-loop3-6020091.stdout", - "stdout_hash": "139189b09e9c982b73eebc2e166bb1c2880a1baa3a927cc549b04f3f", + "stdout_hash": "1ccf4ac5ceb7333112803f2a4033ca0ccdea763dc454df6f72ef1490", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-loop3-6020091.stdout b/tests/reference/cpp-loop3-6020091.stdout index 44430bb32e..56674312b7 100644 --- a/tests/reference/cpp-loop3-6020091.stdout +++ b/tests/reference/cpp-loop3-6020091.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void test_pass(); namespace { diff --git a/tests/reference/cpp-print_01-026ef17.json b/tests/reference/cpp-print_01-026ef17.json index f13d94b94f..0044665d0c 100644 --- a/tests/reference/cpp-print_01-026ef17.json +++ b/tests/reference/cpp-print_01-026ef17.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-print_01-026ef17.stdout", - "stdout_hash": "dd676c204e4cdac681c5643a3cc25491fdfd826f1f29cea9fe5330a6", + "stdout_hash": "589c4df44d69c511799fc8d4c89c9c5063b5c058295584754304fc8d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-print_01-026ef17.stdout b/tests/reference/cpp-print_01-026ef17.stdout index a64067f702..85f4cde0c5 100644 --- a/tests/reference/cpp-print_01-026ef17.stdout +++ b/tests/reference/cpp-print_01-026ef17.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void f(); diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.json b/tests/reference/cpp-test_builtin_pow-56b3f92.json index a65823e416..5cc929b970 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.json +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-test_builtin_pow-56b3f92.stdout", - "stdout_hash": "21976202ba73f579d9ab991478fa99927d914ada3a6c0e2b2012ff00", + "stdout_hash": "4b002051ba89d5289cb48a840d358270bff81a17b3dbac58a58737c9", "stderr": "cpp-test_builtin_pow-56b3f92.stderr", "stderr_hash": "180e1adfbb0d9c63a2fffa31951bbd629b3f1950cf0d97ca1389efe5", "returncode": 0 diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout index 95b0ae1be3..7bb11c8b1a 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void test_pow(); diff --git a/tests/reference/cpp-test_integer_bitnot-20195fd.json b/tests/reference/cpp-test_integer_bitnot-20195fd.json index 82c19db876..20011fdc99 100644 --- a/tests/reference/cpp-test_integer_bitnot-20195fd.json +++ b/tests/reference/cpp-test_integer_bitnot-20195fd.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-test_integer_bitnot-20195fd.stdout", - "stdout_hash": "7f136f0afed5f480a1e56ab8c7f5300ad60557f3514f2a43d6c98027", + "stdout_hash": "82e212651792094aff69d44ff8c5ad7431b77b684fa312e6ece3fb83", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-test_integer_bitnot-20195fd.stdout b/tests/reference/cpp-test_integer_bitnot-20195fd.stdout index 96b95acee7..6abbcaf54e 100644 --- a/tests/reference/cpp-test_integer_bitnot-20195fd.stdout +++ b/tests/reference/cpp-test_integer_bitnot-20195fd.stdout @@ -17,6 +17,11 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; // Forward declarations void _lpython_main_program(); void f(); diff --git a/tests/tests.toml b/tests/tests.toml index 7cd956c00b..bd41387d34 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -140,6 +140,10 @@ ast = true asr = true llvm = true +[[test]] +filename = "../integration_tests/array_01_decl.py" +asr = true + [[test]] filename = "../integration_tests/expr_07.py" asr = true