Skip to content

Commit e3c27fb

Browse files
committed
DEV: Sync libasr with LFortran branch
1 parent 7eb2bea commit e3c27fb

File tree

126 files changed

+27848
-12070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+27848
-12070
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ CPackSourceConfig.cmake
4141
_CPack_Packages
4242
/CMakeSettings.json
4343
src/libasr/libasr.a.*
44+
src/libasr/asr.h
45+
src/libasr/ast.h
46+
src/libasr/asr_base_visitor.h
47+
src/libasr/asr_deserialization_visitor.h
48+
src/libasr/asr_expr_base_replacer_visitor.h
49+
src/libasr/asr_expr_call_replacer_visitor.h
50+
src/libasr/asr_expr_stmt_duplicator_visitor.h
51+
src/libasr/asr_expr_type_visitor.h
52+
src/libasr/asr_expr_value_visitor.h
53+
src/libasr/asr_json_visitor.h
54+
src/libasr/asr_lookup_name_visitor.h
55+
src/libasr/asr_pass_walk_visitor.h
56+
src/libasr/asr_pickle_visitor.h
57+
src/libasr/asr_serialization_visitor.h
58+
src/libasr/asr_stmt_base_replacer_visitor.h
59+
src/libasr/asr_tree_visitor.h
60+
src/libasr/asr_walk_visitor.h
61+
src/libasr/wasm_visitor.h
62+
src/libasr/pass/intrinsic_function_registry_util.h
63+
src/lfortran/config.h
64+
src/libasr/config.h
4465

4566
## libraries
4667
*.a

src/bin/lpython.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,9 @@ int interactive_python_repl(
856856
std::cout << " - History (Keys: Up, Down)" << std::endl;
857857

858858
std::vector<std::string> history;
859-
859+
860860
std::function<bool(std::string)> iscomplete = determine_completeness;
861-
861+
862862
std::string code_string;
863863
size_t cell_count = 0;
864864
while (true) {
@@ -1013,8 +1013,8 @@ int interactive_python_repl(
10131013
}
10141014
case (LCompilers::PythonCompiler::EvalResult::struct_type) : {
10151015
if (verbose) {
1016-
std::cout << "Return type: "
1017-
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
1016+
std::cout << "Return type: "
1017+
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
10181018
<< std::endl;
10191019
}
10201020
if (verbose) section("Result:");
@@ -1094,7 +1094,7 @@ int compile_python_using_llvm(
10941094
}
10951095
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
10961096
if( compiler_options.po.disable_main ) {
1097-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1097+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
10981098
if( err ) {
10991099
return err;
11001100
}
@@ -1237,7 +1237,7 @@ int compile_to_binary_wasm(
12371237
}
12381238
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
12391239
if( compiler_options.po.disable_main ) {
1240-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1240+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
12411241
if( err ) {
12421242
return err;
12431243
}
@@ -1310,7 +1310,7 @@ int compile_to_binary_x86(
13101310
}
13111311
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
13121312
if( compiler_options.po.disable_main ) {
1313-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1313+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
13141314
if( err ) {
13151315
return err;
13161316
}
@@ -1384,7 +1384,7 @@ int compile_to_binary_wasm_to_x86(
13841384
}
13851385
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
13861386
if( compiler_options.po.disable_main ) {
1387-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1387+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
13881388
if( err ) {
13891389
return err;
13901390
}

src/libasr/ASR.asdl

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ unit
99
= TranslationUnit(symbol_table symtab, node* items)
1010

1111
symbol
12-
= Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body)
13-
| Module(symbol_table symtab, identifier name, identifier* dependencies, bool loaded_from_mod, bool intrinsic)
14-
| 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)
12+
= Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body, location start_name, location end_name)
13+
| Module(symbol_table symtab, identifier name, identifier* dependencies, bool loaded_from_mod, bool intrinsic, location start_name, location end_name)
14+
| 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)
1515
| GenericProcedure(symbol_table parent_symtab, identifier name, symbol* procs, access access)
1616
| CustomOperator(symbol_table parent_symtab, identifier name, symbol* procs, access access)
1717
| ExternalSymbol(symbol_table parent_symtab, identifier name, symbol external, identifier module_name, identifier* scope_names, identifier original_name, access access)
1818
| 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)
19-
| EnumType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
20-
| UnionType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
21-
| 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)
22-
| ClassType(symbol_table symtab, identifier name, abi abi, access access)
19+
| Enum(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
20+
| Union(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
21+
| 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)
22+
| Class(symbol_table symtab, identifier name, abi abi, access access)
2323
| ClassProcedure(symbol_table parent_symtab, identifier name, identifier? self_argument, identifier proc_name, symbol proc, abi abi, bool is_deferred, bool is_nopass)
2424
| AssociateBlock(symbol_table symtab, identifier name, stmt* body)
2525
| Block(symbol_table symtab, identifier name, stmt* body)
@@ -35,7 +35,7 @@ stmt
3535
| Cycle(identifier? stmt_name)
3636
| ExplicitDeallocate(expr* vars)
3737
| ImplicitDeallocate(expr* vars)
38-
| DoConcurrentLoop(do_loop_head head, stmt* body)
38+
| DoConcurrentLoop(do_loop_head* head, expr* shared, expr* local, reduction_expr* reduction, stmt* body)
3939
| DoLoop(identifier? name, do_loop_head head, stmt* body, stmt* orelse)
4040
| ErrorStop(expr? code)
4141
| Exit(identifier? stmt_name)
@@ -45,23 +45,23 @@ stmt
4545
| GoToTarget(int id, identifier name)
4646
| If(expr test, stmt* body, stmt* orelse)
4747
| IfArithmetic(expr test, int lt_label, int eq_label, int gt_label)
48-
| Print(expr* values, expr? separator, expr? end)
48+
| Print(expr text)
4949
| FileOpen(int label, expr? newunit, expr? filename, expr? status, expr? form)
5050
| FileClose(int label, expr? unit, expr? iostat, expr? iomsg, expr? err, expr? status)
5151
| FileRead(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? size, expr? id, expr* values, stmt? overloaded)
5252
| FileBackspace(int label, expr? unit, expr? iostat, expr? err)
5353
| FileRewind(int label, expr? unit, expr? iostat, expr? err)
54-
| 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)
54+
| 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)
5555
| FileWrite(int label, expr? unit, expr? iomsg, expr? iostat, expr? id, expr* values, expr? separator, expr? end, stmt? overloaded)
5656
| Return()
5757
| Select(expr test, case_stmt* body, stmt* default, bool enable_fall_through)
5858
| Stop(expr? code)
5959
| Assert(expr test, expr? msg)
6060
| SubroutineCall(symbol name, symbol? original_name, call_arg* args, expr? dt)
61-
| IntrinsicImpureSubroutine(int intrinsic_id, expr* args, int overload_id)
61+
| IntrinsicImpureSubroutine(int sub_intrinsic_id, expr* args, int overload_id)
6262
| Where(expr test, stmt* body, stmt* orelse)
6363
| WhileLoop(identifier? name, expr test, stmt* body, stmt* orelse)
64-
| Nullify(symbol* vars)
64+
| Nullify(expr* vars)
6565
| Flush(int label, expr unit, expr? err, expr? iomsg, expr? iostat)
6666
| ListAppend(expr a, expr ele)
6767
| AssociateBlockCall(symbol m)
@@ -89,11 +89,11 @@ expr
8989
| IntrinsicImpureFunction(int impure_intrinsic_id, expr* args, int overload_id, ttype? type, expr? value)
9090
| TypeInquiry(int inquiry_id, ttype arg_type, expr? arg, ttype type, expr value)
9191
| StructConstructor(symbol dt_sym, call_arg* args, ttype type, expr? value)
92-
| EnumTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
93-
| UnionTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
92+
| StructConstant(symbol dt_sym, call_arg* args, ttype type)
93+
| EnumConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
94+
| UnionConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
9495
| ImpliedDoLoop(expr* values, expr var, expr start, expr end, expr? increment, ttype type, expr? value)
95-
| IntegerConstant(int n, ttype type)
96-
| IntegerBOZ(int v, integerboz intboz_type, ttype? type)
96+
| IntegerConstant(int n, ttype type, integerboz intboz_type)
9797
| IntegerBitNot(expr arg, ttype type, expr? value)
9898
| IntegerUnaryMinus(expr arg, ttype type, expr? value)
9999
| IntegerCompare(expr left, cmpop op, expr right, ttype type, expr? value)
@@ -139,23 +139,23 @@ expr
139139
| StringContains(expr substr, expr str, ttype type, expr? value)
140140
| StringOrd(expr arg, ttype type, expr? value)
141141
| StringChr(expr arg, ttype type, expr? value)
142-
| StringFormat(expr fmt, expr* args, string_format_kind kind, ttype type, expr? value)
142+
| StringFormat(expr? fmt, expr* args, string_format_kind kind, ttype type, expr? value)
143+
| StringPhysicalCast(expr arg, string_physical_type old, string_physical_type new, ttype type, expr? value)
143144
| CPtrCompare(expr left, cmpop op, expr right, ttype type, expr? value)
144145
| SymbolicCompare(expr left, cmpop op, expr right, ttype type, expr? value)
145146
| DictConstant(expr* keys, expr* values, ttype type)
146147
| DictLen(expr arg, ttype type, expr? value)
147148
| Var(symbol v)
148149
| FunctionParam(int param_number, ttype type, expr? value)
149150
| ArrayConstructor(expr* args, ttype type, expr? value, arraystorage storage_format)
150-
| ArrayConstant(expr* args, ttype type, arraystorage storage_format)
151+
| ArrayConstant(int n_data, void data, ttype type, arraystorage storage_format)
151152
| ArrayItem(expr v, array_index* args, ttype type, arraystorage storage_format, expr? value)
152153
| ArraySection(expr v, array_index* args, ttype type, expr? value)
153154
| ArraySize(expr v, expr? dim, ttype type, expr? value)
154155
| ArrayBound(expr v, expr? dim, ttype type, arraybound bound, expr? value)
155156
| ArrayTranspose(expr matrix, ttype type, expr? value)
156157
| ArrayPack(expr array, expr mask, expr? vector, ttype type, expr? value)
157158
| ArrayReshape(expr array, expr shape, ttype type, expr? value)
158-
| ArrayAll(expr mask, expr? dim, ttype type, expr? value)
159159
| ArrayBroadcast(expr array, expr shape, ttype type, expr? value)
160160
| BitCast(expr source, expr mold, expr? size, ttype type, expr? value)
161161
| StructInstanceMember(expr v, symbol m, ttype type, expr? value)
@@ -191,21 +191,22 @@ expr
191191
| PointerNullConstant(ttype type)
192192
| PointerAssociated(expr ptr, expr? tgt, ttype type, expr? value)
193193
| RealSqrt(expr arg, ttype type, expr? value)
194+
| ArrayIsContiguous(expr array, ttype type, expr? value)
194195

195196
ttype
196197
= Integer(int kind)
197198
| UnsignedInteger(int kind)
198199
| Real(int kind)
199200
| Complex(int kind)
200-
| Character(int kind, int len, expr? len_expr)
201+
| String(int kind, int len, expr? len_expr, string_physical_type physical_type)
201202
| Logical(int kind)
202203
| Set(ttype type)
203204
| List(ttype type)
204205
| Tuple(ttype* type)
205206
| StructType(ttype* data_member_types, ttype* member_function_types, bool is_cstruct, symbol derived_type)
206-
| Enum(symbol enum_type)
207-
| Union(symbol union_type)
208-
| Class(symbol class_type)
207+
| EnumType(symbol enum_type)
208+
| UnionType(symbol union_type)
209+
| ClassType(symbol class_type)
209210
| Dict(ttype key_type, ttype value_type)
210211
| Pointer(ttype type)
211212
| Allocatable(ttype type)
@@ -215,7 +216,7 @@ ttype
215216
| Array(ttype type, dimension* dims, array_physical_type physical_type)
216217
| 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)
217218

218-
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
219+
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
219220
storage_type = Default | Save | Parameter
220221
access = Public | Private
221222
intent = Local | In | Out | InOut | ReturnVar | Unspecified
@@ -227,18 +228,21 @@ alloc_arg = (expr a, dimension* dims, expr? len_expr, ttype? type)
227228
attribute = Attribute(identifier name, attribute_arg *args)
228229
attribute_arg = (identifier arg)
229230
call_arg = (expr? value)
231+
reduction_expr = (reduction_op op, expr arg)
230232
tbind = Bind(string lang, string name)
231233
array_index = (expr? left, expr? right, expr? step)
232234
do_loop_head = (expr? v, expr? start, expr? end, expr? increment)
233235
case_stmt = CaseStmt(expr* test, stmt* body, bool fall_through) | CaseStmt_Range(expr? start, expr? end, stmt* body)
234236
type_stmt = TypeStmtName(symbol sym, stmt* body) | ClassStmt(symbol sym, stmt* body) | TypeStmtType(ttype type, stmt* body)
235237
enumtype = IntegerConsecutiveFromZero | IntegerUnique | IntegerNotUnique | NonInteger
236238
require_instantiation = Require(identifier name, identifier* args)
237-
array_physical_type = DescriptorArray | PointerToDataArray | UnboundedPointerToDataArray | FixedSizeArray | CharacterArraySinglePointer | NumPyArray | ISODescriptorArray | SIMDArray
239+
array_physical_type = DescriptorArray | PointerToDataArray | UnboundedPointerToDataArray | FixedSizeArray | StringArraySinglePointer | NumPyArray | ISODescriptorArray | SIMDArray
240+
string_physical_type = PointerString | DescriptorString
238241
binop = Add | Sub | Mul | Div | Pow | BitAnd | BitOr | BitXor | BitLShift | BitRShift
242+
reduction_op = ReduceAdd | ReduceSub | ReduceMul | ReduceMIN | ReduceMAX
239243
logicalbinop = And | Or | Xor | NEqv | Eqv
240244
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE
241-
integerboz = Binary | Hex | Octal
245+
integerboz = Binary | Hex | Octal | Decimal
242246
arraybound = LBound | UBound
243247
arraystorage = RowMajor | ColMajor
244248
string_format_kind = FormatFortran | FormatC | FormatPythonPercent | FormatPythonFString | FormatPythonFormat

src/libasr/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (NOT LFORTRAN_VERSION)
1212
CACHE STRING "LFortran version" FORCE)
1313
endif ()
1414

15-
configure_file(config.h.in config.h)
15+
configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
1616

1717
set(SRC
1818
codegen/asr_to_cpp.cpp
@@ -30,14 +30,16 @@ set(SRC
3030
codegen/wasm_utils.cpp
3131

3232
pass/nested_vars.cpp
33+
pass/array_struct_temporary.cpp
3334
pass/where.cpp
3435
pass/function_call_in_declaration.cpp
36+
pass/array_passed_in_function_call.cpp
37+
pass/openmp.cpp
3538
pass/param_to_const.cpp
3639
pass/do_loops.cpp
3740
pass/for_all.cpp
3841
pass/while_else.cpp
3942
pass/global_stmts.cpp
40-
pass/python_bind.cpp
4143
pass/select_case.cpp
4244
pass/init_expr.cpp
4345
pass/implied_do_loops.cpp
@@ -70,17 +72,18 @@ set(SRC
7072
pass/unique_symbols.cpp
7173
pass/insert_deallocate.cpp
7274
pass/promote_allocatable_to_nonallocatable.cpp
75+
pass/replace_with_compile_time_values.cpp
7376

7477
asr_verify.cpp
7578
asr_utils.cpp
7679
casting_utils.cpp
7780
diagnostics.cpp
78-
stacktrace.cpp
7981
string_utils.cpp
8082
asr_scopes.cpp
8183
modfile.cpp
8284
pickle.cpp
8385
serialization.cpp
86+
stacktrace.cpp
8487
utils2.cpp
8588
)
8689
if (WITH_LLVM)
@@ -90,6 +93,9 @@ if (WITH_LLVM)
9093
codegen/llvm_array_utils.cpp
9194
codegen/llvm_utils.cpp
9295
)
96+
if (WITH_MLIR)
97+
set(SRC ${SRC} codegen/asr_to_mlir.cpp)
98+
endif()
9399
# We use deprecated API in LLVM, so we disable the warning until we upgrade
94100
if (NOT MSVC)
95101
set_source_files_properties(codegen/evaluator.cpp PROPERTIES
@@ -100,11 +106,16 @@ if (WITH_LLVM)
100106
COMPILE_FLAGS -Wno-deprecated-declarations)
101107
set_source_files_properties(codegen/llvm_utils.cpp PROPERTIES
102108
COMPILE_FLAGS -Wno-deprecated-declarations)
109+
set_source_files_properties(stacktrace.cpp PROPERTIES
110+
COMPILE_FLAGS -Wno-deprecated-declarations)
103111
endif()
104112
endif()
105113
add_library(asr STATIC ${SRC})
106114
target_include_directories(asr BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
107115
target_include_directories(asr BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
116+
if (WITH_LIBUNWIND)
117+
target_link_libraries(asr p::libunwind)
118+
endif()
108119
if (WITH_BFD)
109120
target_link_libraries(asr p::bfd)
110121
endif()

src/libasr/asdl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# See the EBNF at the top of the file to understand the logical connection
3434
# between the various node types.
3535

36-
builtin_types = {'identifier', 'string', 'int', 'bool', 'float', 'node', 'symbol_table'}
36+
builtin_types = {'identifier', 'string', 'int', 'bool', 'float', 'node', 'symbol_table', 'void', 'location'}
3737

3838
class AST:
3939
def __repr__(self):

0 commit comments

Comments
 (0)