Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Nov 8, 2023
1 parent da8d25b commit 3031306
Show file tree
Hide file tree
Showing 57 changed files with 5,578 additions and 2,312 deletions.
44 changes: 22 additions & 22 deletions integration_tests/array_01_decl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ class ArraySizes(Enum):
SIZE_3: i32 = 3
SIZE_10: i32 = 10

def accept_i16_array(xi16: i16[:]) -> i16:
xi16[2] = i16(32)
return xi16[2]
# def accept_i16_array(xi16: i16[:]) -> i16:
# xi16[2] = i16(32)
# return xi16[2]

def accept_i32_array(xi32: i32[:]) -> i32:
xi32[1] = 32
return xi32[1]

def accept_i64_array(xi64: i64[:]) -> i64:
xi64[1] = i64(64)
return xi64[1]
# def accept_i64_array(xi64: i64[:]) -> i64:
# xi64[1] = i64(64)
# return xi64[1]

def accept_f32_array(xf32: f32[:]) -> f32:
xf32[1] = f32(32.0)
return xf32[1]
# def accept_f32_array(xf32: f32[:]) -> f32:
# xf32[1] = f32(32.0)
# return xf32[1]

def accept_f64_array(xf64: f64[:]) -> f64:
xf64[0] = 64.0
return xf64[0]
# def accept_f64_array(xf64: f64[:]) -> f64:
# xf64[0] = 64.0
# return xf64[0]

def declare_arrays():
ai16: i16[ArraySizes.SIZE_3.value] = empty(ArraySizes.SIZE_3.value, dtype=int16)
# ai16: i16[ArraySizes.SIZE_3.value] = empty(ArraySizes.SIZE_3.value, dtype=int16)
ai32: i32[ArraySizes.SIZE_3] = empty(ArraySizes.SIZE_3.value, dtype=int32)
ai64: i64[10] = empty(10, dtype=int64)
af32: f32[3] = empty(3, dtype=float32)
af64: f64[ArraySizes.SIZE_10] = empty(10, dtype=float64)
ac32: c32[ArraySizes.SIZE_3] = empty(3, dtype=complex64)
ac64: c64[10] = empty(10, dtype=complex128)
print(accept_i16_array(ai16))
# ai64: i64[10] = empty(10, dtype=int64)
# af32: f32[3] = empty(3, dtype=float32)
# af64: f64[ArraySizes.SIZE_10] = empty(10, dtype=float64)
# ac32: c32[ArraySizes.SIZE_3] = empty(3, dtype=complex64)
# ac64: c64[10] = empty(10, dtype=complex128)
# print(accept_i16_array(ai16))
print(accept_i32_array(ai32))
print(accept_i64_array(ai64))
print(accept_f32_array(af32))
print(accept_f64_array(af64))
# print(accept_i64_array(ai64))
# print(accept_f32_array(af32))
# print(accept_f64_array(af64))

declare_arrays()
6 changes: 6 additions & 0 deletions integration_tests/symbolics_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ def main0():
assert(z == pi + y)
assert(z != S(2)*pi + y)

# testing PR 2404
p: S = Symbol('pi')
print(p)
print(p != pi)
assert(p != pi)

main0()
73 changes: 25 additions & 48 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,6 @@ std::string get_kokkos_dir()
throw LCompilers::LCompilersException("LFORTRAN_KOKKOS_DIR is not defined");
}

int visualize_json(std::string &astr_data_json, LCompilers::Platform os) {
using namespace LCompilers;
std::string file_loc = LCompilers::LPython::generate_visualize_html(astr_data_json);
std::string open_cmd = "";
switch (os) {
case Linux: open_cmd = "xdg-open"; break;
case Windows: open_cmd = "start"; break;
case macOS_Intel:
case macOS_ARM: open_cmd = "open"; break;
default:
std::cerr << "Unsupported Platform " << pf2s(os) <<std::endl;
std::cerr << "Please open file " << file_loc << " manually" <<std::endl;
return 11;
}
std::string cmd = open_cmd + " " + file_loc;
int err = system(cmd.data());
if (err) {
std::cout << "The command '" + cmd + "' failed." << std::endl;
return 11;
}
return 0;
}

#ifdef HAVE_LFORTRAN_LLVM

#endif
Expand Down Expand Up @@ -171,10 +148,10 @@ int emit_ast(const std::string &infile,
}
LCompilers::LPython::AST::ast_t* ast = r.result;

if (compiler_options.tree) {
if (compiler_options.po.tree) {
std::cout << LCompilers::LPython::pickle_tree_python(*ast,
compiler_options.use_colors) << std::endl;
} else if (compiler_options.json) {
} else if (compiler_options.po.json) {
LCompilers::LocationManager lm;
{
LCompilers::LocationManager::FileLocations fl;
Expand All @@ -185,7 +162,7 @@ int emit_ast(const std::string &infile,
lm.file_ends.push_back(input.size());
}
std::cout << LCompilers::LPython::pickle_json(*ast, lm) << std::endl;
} else if (compiler_options.visualize) {
} else if (compiler_options.po.visualize) {
LCompilers::LocationManager lm;
{
LCompilers::LocationManager::FileLocations fl;
Expand Down Expand Up @@ -241,12 +218,12 @@ int emit_asr(const std::string &infile,
LCompilers::PassOptions pass_options;
pass_options.run_fun = "f";
pass_options.always_run = true;
pass_options.verbose = compiler_options.verbose;
pass_options.pass_cumulative = compiler_options.pass_cumulative;
pass_options.all_symbols_mangling = compiler_options.all_symbols_mangling;
pass_options.module_name_mangling = compiler_options.module_name_mangling;
pass_options.global_symbols_mangling = compiler_options.global_symbols_mangling;
pass_options.intrinsic_symbols_mangling = compiler_options.intrinsic_symbols_mangling;
pass_options.verbose = compiler_options.po.verbose;
pass_options.pass_cumulative = compiler_options.po.pass_cumulative;
pass_options.all_symbols_mangling = compiler_options.po.all_symbols_mangling;
pass_options.module_name_mangling = compiler_options.po.module_name_mangling;
pass_options.global_symbols_mangling = compiler_options.po.global_symbols_mangling;
pass_options.intrinsic_symbols_mangling = compiler_options.po.intrinsic_symbols_mangling;


pass_manager.apply_passes(al, asr, pass_options, diagnostics);
Expand Down Expand Up @@ -349,11 +326,11 @@ int emit_c(const std::string &infile,
pass_manager.use_default_passes(true);
pass_options.run_fun = "f";
pass_options.always_run = true;
pass_options.verbose = compiler_options.verbose;
pass_options.all_symbols_mangling = compiler_options.all_symbols_mangling;
pass_options.module_name_mangling = compiler_options.module_name_mangling;
pass_options.global_symbols_mangling = compiler_options.global_symbols_mangling;
pass_options.intrinsic_symbols_mangling = compiler_options.intrinsic_symbols_mangling;
pass_options.verbose = compiler_options.po.verbose;
pass_options.all_symbols_mangling = compiler_options.po.all_symbols_mangling;
pass_options.module_name_mangling = compiler_options.po.module_name_mangling;
pass_options.global_symbols_mangling = compiler_options.po.global_symbols_mangling;
pass_options.intrinsic_symbols_mangling = compiler_options.po.intrinsic_symbols_mangling;

pass_manager.apply_passes(al, asr, pass_options, diagnostics);

Expand Down Expand Up @@ -406,11 +383,11 @@ int emit_c_to_file(const std::string &infile, const std::string &outfile,
pass_manager.use_default_passes(true);
pass_options.run_fun = "f";
pass_options.always_run = true;
pass_options.verbose = compiler_options.verbose;
pass_options.all_symbols_mangling = compiler_options.all_symbols_mangling;
pass_options.module_name_mangling = compiler_options.module_name_mangling;
pass_options.global_symbols_mangling = compiler_options.global_symbols_mangling;
pass_options.intrinsic_symbols_mangling = compiler_options.intrinsic_symbols_mangling;
pass_options.verbose = compiler_options.po.verbose;
pass_options.all_symbols_mangling = compiler_options.po.all_symbols_mangling;
pass_options.module_name_mangling = compiler_options.po.module_name_mangling;
pass_options.global_symbols_mangling = compiler_options.po.global_symbols_mangling;
pass_options.intrinsic_symbols_mangling = compiler_options.po.intrinsic_symbols_mangling;

pass_manager.apply_passes(al, asr, pass_options, diagnostics);

Expand Down Expand Up @@ -1585,16 +1562,16 @@ int main(int argc, char *argv[])
app.add_flag("--print-targets", print_targets, "Print the registered targets");
app.add_flag("--get-rtl-header-dir", print_rtl_header_dir, "Print the path to the runtime library header file");
app.add_flag("--get-rtl-dir", print_rtl_dir, "Print the path to the runtime library file");
app.add_flag("--verbose", compiler_options.verbose, "Print debugging statements");
app.add_flag("--cumulative", compiler_options.pass_cumulative, "Apply all the passes cumulatively till the given pass");
app.add_flag("--verbose", compiler_options.po.verbose, "Print debugging statements");
app.add_flag("--cumulative", compiler_options.po.pass_cumulative, "Apply all the passes cumulatively till the given pass");
app.add_flag("--enable-cpython", compiler_options.enable_cpython, "Enable CPython runtime");
app.add_flag("--enable-symengine", compiler_options.enable_symengine, "Enable Symengine runtime");
app.add_flag("--link-numpy", compiler_options.link_numpy, "Enable NumPy runtime (implies --enable-cpython)");
app.add_flag("--separate-compilation", separate_compilation, "Generates unique names for all the symbols");
app.add_flag("--module-mangling", compiler_options.module_name_mangling, "Mangles the module name");
app.add_flag("--global-mangling", compiler_options.global_symbols_mangling, "Mangles all the global symbols");
app.add_flag("--intrinsic-mangling", compiler_options.intrinsic_symbols_mangling, "Mangles all the intrinsic symbols");
app.add_flag("--all-mangling", compiler_options.all_symbols_mangling, "Mangles all possible symbols");
app.add_flag("--module-mangling", compiler_options.po.module_name_mangling, "Mangles the module name");
app.add_flag("--global-mangling", compiler_options.po.global_symbols_mangling, "Mangles all the global symbols");
app.add_flag("--intrinsic-mangling", compiler_options.po.intrinsic_symbols_mangling, "Mangles all the intrinsic symbols");
app.add_flag("--all-mangling", compiler_options.po.all_symbols_mangling, "Mangles all possible symbols");

// LSP specific options
app.add_flag("--show-errors", show_errors, "Show errors when LSP is running in the background");
Expand Down
4 changes: 3 additions & 1 deletion src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ symbol
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)
access access, bool deterministic, bool side_effect_free, string? module_file)
| GenericProcedure(symbol_table parent_symtab, identifier name,
symbol* procs, access access)
| CustomOperator(symbol_table parent_symtab, identifier name,
Expand Down Expand Up @@ -323,6 +323,7 @@ expr
| ArrayPack(expr array, expr mask, expr? vector, ttype type, expr? value)
| ArrayReshape(expr array, expr shape, ttype type, expr? value)
| ArrayAll(expr mask, expr? dim, ttype type, expr? value)
| ArrayBroadcast(expr array, expr shape, ttype type, expr? value)

| BitCast(expr source, expr mold, expr? size, ttype type, expr? value)
| StructInstanceMember(expr v, symbol m, ttype type, expr? value)
Expand Down Expand Up @@ -428,6 +429,7 @@ array_physical_type
| FixedSizeArray
| NumPyArray
| ISODescriptorArray
| SIMDArray

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

Expand Down
2 changes: 2 additions & 0 deletions src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SRC
codegen/asr_to_cpp.cpp
codegen/asr_to_c.cpp
codegen/asr_to_julia.cpp
codegen/asr_to_fortran.cpp
codegen/asr_to_py.cpp
codegen/x86_assembler.cpp
codegen/asr_to_x86.cpp
Expand Down Expand Up @@ -62,6 +63,7 @@ set(SRC
pass/pass_list_expr.cpp
pass/pass_compare.cpp
pass/unique_symbols.cpp
pass/insert_deallocate.cpp

asr_verify.cpp
asr_utils.cpp
Expand Down
5 changes: 4 additions & 1 deletion src/libasr/asdl_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ def visitModule(self, mod):
self.emit( "Struct& self() { return static_cast<Struct&>(*this); }", 1)
self.emit("public:")
self.emit( "std::string s, indtd = \"\";", 1)
self.emit( "bool no_loc = false;", 1)
self.emit( "int indent_level = 0, indent_spaces = 4;", 1)
# Storing a reference to LocationManager like this isn't ideal.
# One must make sure JsonBaseVisitor isn't reused in a case where AST/ASR has changed
Expand All @@ -1739,7 +1740,9 @@ def visitModule(self, mod):
self.emit( "indtd = std::string(indent_level*indent_spaces, ' ');",2)
self.emit( "}",1)
self.emit( "void append_location(std::string &s, uint32_t first, uint32_t last) {", 1)
self.emit( 's.append("\\"loc\\": {");', 2);
self.emit( 'if (no_loc) return;', 2)
self.emit( 's.append(",\\n" + indtd);', 2)
self.emit( 's.append("\\"loc\\": {");', 2)
self.emit( 'inc_indent();', 2)
self.emit( 's.append("\\n" + indtd);', 2)
self.emit( 's.append("\\"first\\": " + std::to_string(first));', 2)
Expand Down
Loading

0 comments on commit 3031306

Please sign in to comment.