Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Sync libasr with LFortran #2827

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions integration_tests/array_expr_05.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from lpython import u8, u16, u32, u64
from lpython import u8, u16, u32, u64, i8
from numpy import uint8, uint16, uint32, uint64, array

def g():
Expand All @@ -7,11 +7,6 @@ def g():
a32: u32[3] = array([127, 3, 111], dtype=uint32)
a64: u64[3] = array([127, 3, 111], dtype=uint64)

print(a8)
print(a16)
print(a32)
print(a64)

assert (a8[0] == u8(127))
assert (a8[1] == u8(3))
assert (a8[2] == u8(111))
Expand All @@ -28,4 +23,9 @@ def g():
assert (a64[1] == u64(3))
assert (a64[2] == u64(111))

print(a8)
print(a16)
print(a32)
print(a64)

g()
10 changes: 5 additions & 5 deletions integration_tests/bindc_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def f():
y[1] = i16(2)
yptr1 = pointer(y)
print(pointer(y), yptr1)
print(yptr1[0], yptr1[1])
assert yptr1[0] == i16(1)
assert yptr1[1] == i16(2)
# print(yptr1[0], yptr1[1])
# assert yptr1[0] == i16(1)
# assert yptr1[1] == i16(2)

yptr1 = c_p_pointer(yq, i16[:], array([2]))
# yptr1 = c_p_pointer(yq, i16[:], array([2]))

print(yq, yptr1)
# print(yq, yptr1)

f()
16 changes: 8 additions & 8 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,9 @@ int interactive_python_repl(
std::cout << " - History (Keys: Up, Down)" << std::endl;

std::vector<std::string> history;

std::function<bool(std::string)> iscomplete = determine_completeness;

std::string code_string;
size_t cell_count = 0;
while (true) {
Expand Down Expand Up @@ -1013,8 +1013,8 @@ int interactive_python_repl(
}
case (LCompilers::PythonCompiler::EvalResult::struct_type) : {
if (verbose) {
std::cout << "Return type: "
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
std::cout << "Return type: "
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
<< std::endl;
}
if (verbose) section("Result:");
Expand Down Expand Up @@ -1094,7 +1094,7 @@ int compile_python_using_llvm(
}
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
if( compiler_options.po.disable_main ) {
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
if( err ) {
return err;
}
Expand Down Expand Up @@ -1237,7 +1237,7 @@ int compile_to_binary_wasm(
}
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
if( compiler_options.po.disable_main ) {
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
if( err ) {
return err;
}
Expand Down Expand Up @@ -1310,7 +1310,7 @@ int compile_to_binary_x86(
}
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
if( compiler_options.po.disable_main ) {
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
if( err ) {
return err;
}
Expand Down Expand Up @@ -1384,7 +1384,7 @@ int compile_to_binary_wasm_to_x86(
}
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
if( compiler_options.po.disable_main ) {
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
if( err ) {
return err;
}
Expand Down
55 changes: 30 additions & 25 deletions src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ unit
= TranslationUnit(symbol_table symtab, node* items)

symbol
= Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body)
| Module(symbol_table symtab, identifier name, identifier* dependencies, bool loaded_from_mod, bool intrinsic)
| Function(symbol_table symtab, identifier name, ttype function_signature, identifier* dependencies, expr* args, stmt* body, expr? return_var, access access, bool deterministic, bool side_effect_free, string? module_file)
= Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body, location start_name, location end_name)
| Module(symbol_table symtab, identifier name, identifier* dependencies, bool loaded_from_mod, bool intrinsic, location start_name, location end_name)
| Function(symbol_table symtab, identifier name, ttype function_signature, identifier* dependencies, expr* args, stmt* body, expr? return_var, access access, bool deterministic, bool side_effect_free, string? module_file, location start_name, location end_name)
| GenericProcedure(symbol_table parent_symtab, identifier name, symbol* procs, access access)
| CustomOperator(symbol_table parent_symtab, identifier name, symbol* procs, access access)
| ExternalSymbol(symbol_table parent_symtab, identifier name, symbol external, identifier module_name, identifier* scope_names, identifier original_name, access access)
| Struct(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, identifier* member_functions, abi abi, access access, bool is_packed, bool is_abstract, call_arg* initializers, expr? alignment, symbol? parent)
| EnumType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
| UnionType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
| Variable(symbol_table parent_symtab, identifier name, identifier* dependencies, intent intent, expr? symbolic_value, expr? value, storage_type storage, ttype type, symbol? type_declaration, abi abi, access access, presence presence, bool value_attr)
| ClassType(symbol_table symtab, identifier name, abi abi, access access)
| Enum(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
| Union(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
| Variable(symbol_table parent_symtab, identifier name, identifier* dependencies, intent intent, expr? symbolic_value, expr? value, storage_type storage, ttype type, symbol? type_declaration, abi abi, access access, presence presence, bool value_attr, bool target_attr)
| Class(symbol_table symtab, identifier name, abi abi, access access)
| ClassProcedure(symbol_table parent_symtab, identifier name, identifier? self_argument, identifier proc_name, symbol proc, abi abi, bool is_deferred, bool is_nopass)
| AssociateBlock(symbol_table symtab, identifier name, stmt* body)
| Block(symbol_table symtab, identifier name, stmt* body)
Expand All @@ -35,7 +35,7 @@ stmt
| Cycle(identifier? stmt_name)
| ExplicitDeallocate(expr* vars)
| ImplicitDeallocate(expr* vars)
| DoConcurrentLoop(do_loop_head head, stmt* body)
| DoConcurrentLoop(do_loop_head* head, expr* shared, expr* local, reduction_expr* reduction, stmt* body)
| DoLoop(identifier? name, do_loop_head head, stmt* body, stmt* orelse)
| ErrorStop(expr? code)
| Exit(identifier? stmt_name)
Expand All @@ -45,23 +45,23 @@ stmt
| GoToTarget(int id, identifier name)
| If(expr test, stmt* body, stmt* orelse)
| IfArithmetic(expr test, int lt_label, int eq_label, int gt_label)
| Print(expr* values, expr? separator, expr? end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think end and separator are used in python syntax.

| Print(expr text)
| FileOpen(int label, expr? newunit, expr? filename, expr? status, expr? form)
| FileClose(int label, expr? unit, expr? iostat, expr? iomsg, expr? err, expr? status)
| FileRead(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? size, expr? id, expr* values, stmt? overloaded)
| FileBackspace(int label, expr? unit, expr? iostat, expr? err)
| FileRewind(int label, expr? unit, expr? iostat, expr? err)
| FileInquire(int label, expr? unit, expr? file, expr? iostat, expr? err, expr? exist, expr? opened, expr? number, expr? named, expr? name, expr? access, expr? sequential, expr? direct, expr? form, expr? formatted, expr? unformatted, expr? recl, expr? nextrec, expr? blank, expr? position, expr? action, expr? read, expr? write, expr? readwrite, expr? delim, expr? pad, expr? flen, expr? blocksize, expr? convert, expr? carriagecontrol, expr? iolength)
| FileInquire(int label, expr? unit, expr? file, expr? iostat, expr? err, expr? exist, expr? opened, expr? number, expr? named, expr? name, expr? access, expr? sequential, expr? direct, expr? form, expr? formatted, expr? unformatted, expr? recl, expr? nextrec, expr? blank, expr? position, expr? action, expr? read, expr? write, expr? readwrite, expr? delim, expr? pad, expr? flen, expr? blocksize, expr? convert, expr? carriagecontrol, expr? size, expr? iolength)
| FileWrite(int label, expr? unit, expr? iomsg, expr? iostat, expr? id, expr* values, expr? separator, expr? end, stmt? overloaded)
| Return()
| Select(expr test, case_stmt* body, stmt* default, bool enable_fall_through)
| Stop(expr? code)
| Assert(expr test, expr? msg)
| SubroutineCall(symbol name, symbol? original_name, call_arg* args, expr? dt)
| IntrinsicImpureSubroutine(int intrinsic_id, expr* args, int overload_id)
| IntrinsicImpureSubroutine(int sub_intrinsic_id, expr* args, int overload_id)
| Where(expr test, stmt* body, stmt* orelse)
| WhileLoop(identifier? name, expr test, stmt* body, stmt* orelse)
| Nullify(symbol* vars)
| Nullify(expr* vars)
| Flush(int label, expr unit, expr? err, expr? iomsg, expr? iostat)
| ListAppend(expr a, expr ele)
| AssociateBlockCall(symbol m)
Expand Down Expand Up @@ -89,11 +89,11 @@ expr
| IntrinsicImpureFunction(int impure_intrinsic_id, expr* args, int overload_id, ttype? type, expr? value)
| TypeInquiry(int inquiry_id, ttype arg_type, expr? arg, ttype type, expr value)
| StructConstructor(symbol dt_sym, call_arg* args, ttype type, expr? value)
| EnumTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| UnionTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| StructConstant(symbol dt_sym, call_arg* args, ttype type)
| EnumConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| UnionConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| ImpliedDoLoop(expr* values, expr var, expr start, expr end, expr? increment, ttype type, expr? value)
| IntegerConstant(int n, ttype type)
| IntegerBOZ(int v, integerboz intboz_type, ttype? type)
| IntegerConstant(int n, ttype type, integerboz intboz_type)
| IntegerBitNot(expr arg, ttype type, expr? value)
| IntegerUnaryMinus(expr arg, ttype type, expr? value)
| IntegerCompare(expr left, cmpop op, expr right, ttype type, expr? value)
Expand Down Expand Up @@ -139,15 +139,16 @@ expr
| StringContains(expr substr, expr str, ttype type, expr? value)
| StringOrd(expr arg, ttype type, expr? value)
| StringChr(expr arg, ttype type, expr? value)
| StringFormat(expr fmt, expr* args, string_format_kind kind, ttype type, expr? value)
| StringFormat(expr? fmt, expr* args, string_format_kind kind, ttype type, expr? value)
| StringPhysicalCast(expr arg, string_physical_type old, string_physical_type new, ttype type, expr? value)
| CPtrCompare(expr left, cmpop op, expr right, ttype type, expr? value)
| SymbolicCompare(expr left, cmpop op, expr right, ttype type, expr? value)
| DictConstant(expr* keys, expr* values, ttype type)
| DictLen(expr arg, ttype type, expr? value)
| Var(symbol v)
| FunctionParam(int param_number, ttype type, expr? value)
| ArrayConstructor(expr* args, ttype type, expr? value, arraystorage storage_format)
| ArrayConstant(expr* args, ttype type, arraystorage storage_format)
| ArrayConstant(int n_data, void data, ttype type, arraystorage storage_format)
| ArrayItem(expr v, array_index* args, ttype type, arraystorage storage_format, expr? value)
| ArraySection(expr v, array_index* args, ttype type, expr? value)
| ArraySize(expr v, expr? dim, ttype type, expr? value)
Expand Down Expand Up @@ -191,21 +192,22 @@ expr
| PointerNullConstant(ttype type)
| PointerAssociated(expr ptr, expr? tgt, ttype type, expr? value)
| RealSqrt(expr arg, ttype type, expr? value)
| ArrayIsContiguous(expr array, ttype type, expr? value)

ttype
= Integer(int kind)
| UnsignedInteger(int kind)
| Real(int kind)
| Complex(int kind)
| Character(int kind, int len, expr? len_expr)
| String(int kind, int len, expr? len_expr, string_physical_type physical_type)
| Logical(int kind)
| Set(ttype type)
| List(ttype type)
| Tuple(ttype* type)
| StructType(ttype* data_member_types, ttype* member_function_types, bool is_cstruct, symbol derived_type)
| Enum(symbol enum_type)
| Union(symbol union_type)
| Class(symbol class_type)
| EnumType(symbol enum_type)
| UnionType(symbol union_type)
| ClassType(symbol class_type)
| Dict(ttype key_type, ttype value_type)
| Pointer(ttype type)
| Allocatable(ttype type)
Expand All @@ -215,7 +217,7 @@ ttype
| Array(ttype type, dimension* dims, array_physical_type physical_type)
| FunctionType(ttype* arg_types, ttype? return_var_type, abi abi, deftype deftype, string? bindc_name, bool elemental, bool pure, bool module, bool inline, bool static, symbol* restrictions, bool is_restriction)

cast_kind = RealToInteger | IntegerToReal | LogicalToReal | RealToReal | IntegerToInteger | RealToComplex | IntegerToComplex | IntegerToLogical | RealToLogical | CharacterToLogical | CharacterToInteger | CharacterToList | ComplexToLogical | ComplexToComplex | ComplexToReal | ComplexToInteger | LogicalToInteger | RealToCharacter | IntegerToCharacter | LogicalToCharacter | UnsignedIntegerToInteger | UnsignedIntegerToUnsignedInteger | UnsignedIntegerToReal | UnsignedIntegerToLogical | IntegerToUnsignedInteger | RealToUnsignedInteger | CPtrToUnsignedInteger | UnsignedIntegerToCPtr | IntegerToSymbolicExpression | ListToArray | DerivedToBase
cast_kind = RealToInteger | IntegerToReal | LogicalToReal | RealToReal | IntegerToInteger | RealToComplex | IntegerToComplex | IntegerToLogical | RealToLogical | StringToLogical | StringToInteger | StringToList | ComplexToLogical | ComplexToComplex | ComplexToReal | ComplexToInteger | LogicalToInteger | RealToString | IntegerToString | LogicalToString | UnsignedIntegerToInteger | UnsignedIntegerToUnsignedInteger | UnsignedIntegerToReal | UnsignedIntegerToLogical | IntegerToUnsignedInteger | RealToUnsignedInteger | CPtrToUnsignedInteger | UnsignedIntegerToCPtr | IntegerToSymbolicExpression | ListToArray
storage_type = Default | Save | Parameter
access = Public | Private
intent = Local | In | Out | InOut | ReturnVar | Unspecified
Expand All @@ -227,18 +229,21 @@ alloc_arg = (expr a, dimension* dims, expr? len_expr, ttype? type)
attribute = Attribute(identifier name, attribute_arg *args)
attribute_arg = (identifier arg)
call_arg = (expr? value)
reduction_expr = (reduction_op op, expr arg)
tbind = Bind(string lang, string name)
array_index = (expr? left, expr? right, expr? step)
do_loop_head = (expr? v, expr? start, expr? end, expr? increment)
case_stmt = CaseStmt(expr* test, stmt* body, bool fall_through) | CaseStmt_Range(expr? start, expr? end, stmt* body)
type_stmt = TypeStmtName(symbol sym, stmt* body) | ClassStmt(symbol sym, stmt* body) | TypeStmtType(ttype type, stmt* body)
enumtype = IntegerConsecutiveFromZero | IntegerUnique | IntegerNotUnique | NonInteger
require_instantiation = Require(identifier name, identifier* args)
array_physical_type = DescriptorArray | PointerToDataArray | UnboundedPointerToDataArray | FixedSizeArray | CharacterArraySinglePointer | NumPyArray | ISODescriptorArray | SIMDArray
array_physical_type = DescriptorArray | PointerToDataArray | UnboundedPointerToDataArray | FixedSizeArray | StringArraySinglePointer | NumPyArray | ISODescriptorArray | SIMDArray
string_physical_type = PointerString | DescriptorString
binop = Add | Sub | Mul | Div | Pow | BitAnd | BitOr | BitXor | BitLShift | BitRShift
reduction_op = ReduceAdd | ReduceSub | ReduceMul | ReduceMIN | ReduceMAX
logicalbinop = And | Or | Xor | NEqv | Eqv
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE
integerboz = Binary | Hex | Octal
integerboz = Binary | Hex | Octal | Decimal
arraybound = LBound | UBound
arraystorage = RowMajor | ColMajor
string_format_kind = FormatFortran | FormatC | FormatPythonPercent | FormatPythonFString | FormatPythonFormat
Expand Down
15 changes: 14 additions & 1 deletion src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (NOT LFORTRAN_VERSION)
CACHE STRING "LFortran version" FORCE)
endif ()

configure_file(config.h.in config.h)
configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)

set(SRC
codegen/asr_to_cpp.cpp
Expand All @@ -30,8 +30,11 @@ set(SRC
codegen/wasm_utils.cpp

pass/nested_vars.cpp
pass/array_struct_temporary.cpp
pass/where.cpp
pass/function_call_in_declaration.cpp
pass/array_passed_in_function_call.cpp
pass/openmp.cpp
pass/param_to_const.cpp
pass/do_loops.cpp
pass/for_all.cpp
Expand Down Expand Up @@ -70,6 +73,7 @@ set(SRC
pass/unique_symbols.cpp
pass/insert_deallocate.cpp
pass/promote_allocatable_to_nonallocatable.cpp
pass/replace_with_compile_time_values.cpp

asr_verify.cpp
asr_utils.cpp
Expand All @@ -81,6 +85,7 @@ set(SRC
modfile.cpp
pickle.cpp
serialization.cpp
stacktrace.cpp
utils2.cpp
)
if (WITH_LLVM)
Expand All @@ -90,6 +95,9 @@ if (WITH_LLVM)
codegen/llvm_array_utils.cpp
codegen/llvm_utils.cpp
)
if (WITH_MLIR)
set(SRC ${SRC} codegen/asr_to_mlir.cpp)
endif()
# We use deprecated API in LLVM, so we disable the warning until we upgrade
if (NOT MSVC)
set_source_files_properties(codegen/evaluator.cpp PROPERTIES
Expand All @@ -100,11 +108,16 @@ if (WITH_LLVM)
COMPILE_FLAGS -Wno-deprecated-declarations)
set_source_files_properties(codegen/llvm_utils.cpp PROPERTIES
COMPILE_FLAGS -Wno-deprecated-declarations)
set_source_files_properties(stacktrace.cpp PROPERTIES
COMPILE_FLAGS -Wno-deprecated-declarations)
endif()
endif()
add_library(asr STATIC ${SRC})
target_include_directories(asr BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
target_include_directories(asr BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
if (WITH_LIBUNWIND)
target_link_libraries(asr p::libunwind)
endif()
if (WITH_BFD)
target_link_libraries(asr p::bfd)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/asdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# See the EBNF at the top of the file to understand the logical connection
# between the various node types.

builtin_types = {'identifier', 'string', 'int', 'bool', 'float', 'node', 'symbol_table'}
builtin_types = {'identifier', 'string', 'int', 'bool', 'float', 'node', 'symbol_table', 'void', 'location'}

class AST:
def __repr__(self):
Expand Down
Loading
Loading