Skip to content

Commit

Permalink
Support --dump-all-passes, --dump-all-passes-fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Nov 10, 2023
1 parent f0b2a49 commit 0b3de50
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,45 @@ int emit_wat(const std::string &infile,
return 0;
}

int dump_all_passes(const std::string &infile,
const std::string &runtime_library_dir,
CompilerOptions &compiler_options) {
std::string input = LCompilers::read_file(infile);

Allocator al(4*1024);
LCompilers::LocationManager lm;
LCompilers::diag::Diagnostics diagnostics;
{
LCompilers::LocationManager::FileLocations fl;
fl.in_filename = infile;
lm.files.push_back(fl);
lm.file_ends.push_back(input.size());
}

LCompilers::Result<LCompilers::LPython::AST::ast_t*> r = parse_python_file(
al, runtime_library_dir, infile, diagnostics, 0, compiler_options.new_parser);
std::cerr << diagnostics.render(lm, compiler_options);
if (!r.ok) {
return 1;
}
LCompilers::LPython::AST::ast_t* ast = r.result;
diagnostics.diagnostics.clear();
LCompilers::Result<LCompilers::ASR::TranslationUnit_t*>
r1 = LCompilers::LPython::python_ast_to_asr(al, lm, nullptr, *ast, diagnostics, compiler_options, true, "__main__", infile);
std::cerr << diagnostics.render(lm, compiler_options);
if (r1.ok) {
LCompilers::PassManager pass_manager;
compiler_options.po.always_run = true;
compiler_options.po.run_fun = "f";
pass_manager.dump_all_passes(al, r1.result, compiler_options.po, diagnostics, lm);
std::cerr << diagnostics.render(lm, compiler_options);
} else {
LCOMPILERS_ASSERT(diagnostics.has_error())
return 1;
}
return 0;
}

#ifdef HAVE_LFORTRAN_RAPIDJSON

int get_symbols (const std::string &infile,
Expand Down Expand Up @@ -1586,6 +1625,8 @@ int main(int argc, char *argv[])
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("--dump-all-passes", compiler_options.po.dump_all_passes, "Apply all the passes and dump the ASR into a file");
app.add_flag("--dump-all-passes-fortran", compiler_options.po.dump_fortran, "Apply all passes and dump the ASR after each pass into fortran file");
app.add_flag("--cumulative", compiler_options.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");
Expand Down Expand Up @@ -1763,6 +1804,10 @@ int main(int argc, char *argv[])
outfile = basename + ".out";
}

if (compiler_options.po.dump_fortran || compiler_options.po.dump_all_passes) {
dump_all_passes(arg_file, compiler_options);
}

// if (arg_E) {
// return emit_c_preprocessor(arg_file, compiler_options);
// }
Expand Down

0 comments on commit 0b3de50

Please sign in to comment.