Skip to content

Commit

Permalink
Sync libasr with LFortran/LPython
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Oct 10, 2022
1 parent 890b609 commit 0560d5c
Show file tree
Hide file tree
Showing 98 changed files with 12,596 additions and 2,895 deletions.
49 changes: 35 additions & 14 deletions src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,22 @@ symbol
stmt* body)
| Module(symbol_table symtab, identifier name, identifier* dependencies,
bool loaded_from_mod, bool intrinsic)
| Subroutine(symbol_table symtab, identifier name, expr* args, stmt* body,
abi abi, access access, deftype deftype, string? bindc_name, bool pure,
bool module)
| Function(symbol_table symtab, identifier name, expr* args, stmt* body,
expr return_var, abi abi, access access, deftype deftype, bool elemental,
string? bindc_name)
expr? return_var, abi abi, access access, deftype deftype,
string? bindc_name, bool elemental, bool pure, bool module, bool inline,
bool static, ttype* type_params, symbol* restrictions, bool is_restriction)
| 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)
| DerivedType(symbol_table symtab, identifier name, identifier* members,
| StructType(symbol_table symtab, identifier name, identifier* members,
abi abi, access access, symbol? parent)
| EnumType(symbol_table symtab, identifier name, identifier* members,
abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
| UnionType(symbol_table symtab, identifier name, identifier* members,
abi abi, access access, symbol? parent)
| Variable(symbol_table parent_symtab, identifier name, intent intent,
expr? symbolic_value, expr? value, storage_type storage, ttype type,
Expand Down Expand Up @@ -171,10 +173,10 @@ stmt
-- GoTo points to a GoToTarget with the corresponding target_id within
-- the same procedure. We currently use `int` IDs to link GoTo with
-- GoToTarget to avoid issues with serialization.
| GoTo(int target_id)
| GoTo(int target_id, identifier name)
-- An empty statement, a target of zero or more GoTo statements
-- the `id` is only unique within a procedure
| GoToTarget(int id)
| 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? fmt, expr* values, expr? separator, expr? end)
Expand Down Expand Up @@ -208,6 +210,7 @@ stmt
| SetRemove(expr a, expr ele)
| ListInsert(expr a, expr pos, expr ele)
| ListRemove(expr a, expr ele)
| ListClear(expr a)
| DictInsert(expr a, expr key, expr value)


Expand All @@ -216,9 +219,11 @@ expr
-- Such as: (x, y+z), (3.0, 2.0) generally not known at compile time
| ComplexConstructor(expr re, expr im, ttype type, expr? value)
| NamedExpr(expr target, expr value, ttype type)
| FunctionCall(symbol name, symbol? original_name,
call_arg* args, ttype type, expr? value, expr? dt)
| DerivedTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| FunctionCall(symbol name, symbol? original_name, call_arg* args,
ttype type, expr? value, expr? dt)
| StructTypeConstructor(symbol dt_sym, expr* 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)
| ImpliedDoLoop(expr* values, expr var, expr start, expr end,
expr? increment, ttype type, expr? value)
| IntegerConstant(int n, ttype type)
Expand All @@ -239,6 +244,7 @@ expr
| LogicalNot(expr arg, ttype type, expr? value)
| LogicalCompare(expr left, cmpop op, expr right, ttype type, expr? value)
| LogicalBinOp(expr left, logicalbinop op, expr right, ttype type, expr? value)
| TemplateBinOp(expr left, binop op, expr right, ttype type, expr? value)

| ListConstant(expr* args, ttype type)
| ListLen(expr arg, ttype type, expr? value)
Expand All @@ -248,7 +254,7 @@ expr
| SetLen(expr arg, ttype type, expr? value)

| TupleConstant(expr* elements, ttype type)
| TupleLen(expr arg, ttype type, expr? value)
| TupleLen(expr arg, ttype type, expr value)

| StringConstant(string s, ttype type)
| StringConcat(expr left, expr right, ttype type, expr? value)
Expand Down Expand Up @@ -277,7 +283,11 @@ expr
| ArrayReshape(expr array, expr shape, ttype type, expr? value)

| BitCast(expr source, expr mold, expr? size, ttype type, expr? value)
| DerivedRef(expr v, symbol m, ttype type, expr? value)
| StructInstanceMember(expr v, symbol m, ttype type, expr? value)
| EnumMember(expr v, symbol m, ttype type, expr? value)
| UnionRef(expr v, symbol m, ttype type, expr? value)
| EnumName(expr v, ttype enum_type, ttype type, expr? value)
| EnumValue(expr v, ttype enum_type, ttype type, expr? value)
| OverloadedCompare(expr left, cmpop op, expr right, ttype type, expr? value, expr overloaded)
| OverloadedBinOp(expr left, binop op, expr right, ttype type, expr? value, expr overloaded)
| Cast(expr arg, cast_kind kind, ttype type, expr? value)
Expand All @@ -293,6 +303,8 @@ expr
| ListPop(expr a, expr? index, ttype type, expr? value)
| DictPop(expr a, expr key, ttype type, expr? value)
| SetPop(expr a, ttype type, expr? value)
| IntegerBitLen(expr a, ttype type, expr? value)
| Ichar(expr arg, ttype type, expr? value)


-- `len` in Character:
Expand Down Expand Up @@ -323,11 +335,16 @@ ttype
| Set(ttype type)
| List(ttype type)
| Tuple(ttype* type)
| Derived(symbol derived_type, dimension* dims)
| Struct(symbol derived_type, dimension* dims)
| Enum(symbol enum_type, dimension *dims)
| Union(symbol union_type, dimension *dims)
| Class(symbol class_type, dimension* dims)
| Dict(ttype key_type, ttype value_type)
| Pointer(ttype type)
| CPtr()
| TypeParameter(identifier param, dimension* dims)

restriction_arg = RestrictionArg(identifier restriction_name, symbol restriction_func)

binop = Add | Sub | Mul | Div | Pow | BitAnd | BitOr | BitXor | BitLShift | BitRShift

Expand All @@ -351,9 +368,11 @@ cast_kind
| RealToLogical
| CharacterToLogical
| CharacterToInteger
| CharacterToList
| ComplexToLogical
| ComplexToComplex
| ComplexToReal
| ComplexToInteger
| LogicalToInteger
| RealToCharacter
| IntegerToCharacter
Expand All @@ -377,4 +396,6 @@ do_loop_head = (expr? v, expr? start, expr? end, expr? increment)

case_stmt = CaseStmt(expr* test, stmt* body) | CaseStmt_Range(expr? start, expr? end, stmt* body)

enumtype = IntegerConsecutiveFromZero | IntegerUnique | IntegerNotUnique | NonInteger

}
6 changes: 5 additions & 1 deletion src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ configure_file(config.h.in config.h)
set(SRC
codegen/asr_to_cpp.cpp
codegen/asr_to_c.cpp
codegen/asr_to_julia.cpp
codegen/asr_to_py.cpp
codegen/x86_assembler.cpp
codegen/asr_to_x86.cpp
Expand All @@ -33,9 +34,9 @@ set(SRC
pass/implied_do_loops.cpp
pass/array_op.cpp
pass/class_constructor.cpp
pass/arr_dims_propagate.cpp
pass/arr_slice.cpp
pass/print_arr.cpp
pass/print_list.cpp
pass/pass_utils.cpp
pass/unused_functions.cpp
pass/flip_sign.cpp
Expand All @@ -46,7 +47,10 @@ set(SRC
pass/inline_function_calls.cpp
pass/loop_unroll.cpp
pass/dead_code_removal.cpp
pass/instantiate_template.cpp
pass/update_array_dim_intrinsic_calls.cpp
pass/pass_array_by_data.cpp
pass/pass_list_concat.cpp

asr_verify.cpp
asr_utils.cpp
Expand Down
Loading

0 comments on commit 0560d5c

Please sign in to comment.