diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index d7a04f2229..7545ef5a16 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1297,6 +1297,7 @@ int main(int argc, char *argv[]) bool show_errors = false; bool with_intrinsic_modules = false; std::string arg_pass; + std::string skip_pass; bool arg_no_color = false; bool show_llvm = false; bool show_asm = false; @@ -1363,6 +1364,7 @@ int main(int argc, char *argv[]) app.add_flag("--indent", compiler_options.indent, "Indented print ASR/AST"); app.add_flag("--tree", compiler_options.tree, "Tree structure print ASR/AST"); app.add_option("--pass", arg_pass, "Apply the ASR pass and show ASR (implies --show-asr)"); + app.add_option("--skip-pass", skip_pass, "Skip an ASR pass in default pipeline"); app.add_flag("--disable-main", compiler_options.disable_main, "Do not generate any code for the `main` function"); app.add_flag("--symtab-only", compiler_options.symtab_only, "Only create symbol tables in ASR (skip executable stmt)"); app.add_flag("--time-report", time_report, "Show compilation time report"); @@ -1539,7 +1541,7 @@ int main(int argc, char *argv[]) // return emit_c_preprocessor(arg_file, compiler_options); // } - lpython_pass_manager.parse_pass_arg(arg_pass); + lpython_pass_manager.parse_pass_arg(arg_pass, skip_pass); if (show_tokens) { return emit_tokens(arg_file, true, compiler_options); } diff --git a/src/libasr/pass/pass_manager.h b/src/libasr/pass/pass_manager.h index c342e8ca81..acb57084d8 100644 --- a/src/libasr/pass/pass_manager.h +++ b/src/libasr/pass/pass_manager.h @@ -45,6 +45,7 @@ #include #include +#include namespace LCompilers { @@ -57,6 +58,7 @@ namespace LCompilers { std::vector _passes; std::vector _with_optimization_passes; std::vector _user_defined_passes; + std::vector _skip_passes; std::map _passes_db = { {"do_loops", &LFortran::pass_replace_do_loops}, {"global_stmts", &LFortran::pass_wrap_global_stmts_into_function}, @@ -97,6 +99,8 @@ namespace LCompilers { // Note: this is not enough for rtlib, we also need to include // it if (rtlib && passes[i] == "unused_functions") continue; + if( std::find(_skip_passes.begin(), _skip_passes.end(), passes[i]) != _skip_passes.end()) + continue; _passes_db[passes[i]](al, *asr, pass_options); #if defined(WITH_LFORTRAN_ASSERT) if (!LFortran::asr_verify(*asr, true, diagnostics)) { @@ -107,6 +111,31 @@ namespace LCompilers { } } + void _parse_pass_arg(std::string& arg, std::vector& passes) { + if (arg == "") return; + + std::string current_pass = ""; + for( size_t i = 0; i < arg.size(); i++ ) { + char ch = arg[i]; + if (ch != ' ' && ch != ',') { + current_pass.push_back(ch); + } + if (ch == ',' || i == arg.size() - 1) { + current_pass = LFortran::to_lower(current_pass); + if( _passes_db.find(current_pass) == _passes_db.end() ) { + std::cerr << current_pass << " isn't supported yet."; + std::cerr << " Only the following passes are supported:- "<