Skip to content

Commit a9807b0

Browse files
committed
Enable skip multi passes.
Also change option to --skip-pass, format like other options.
1 parent 654a7fe commit a9807b0

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

src/bin/lpython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ int main(int argc, char *argv[])
903903
app.add_flag("--indent", compiler_options.indent, "Indented print ASR/AST");
904904
app.add_flag("--tree", compiler_options.tree, "Tree structure print ASR/AST");
905905
app.add_option("--pass", arg_pass, "Apply the ASR pass and show ASR (implies --show-asr)");
906-
app.add_option("--skip_pass", skip_pass, "Skip an ASR pass in default pipeline");
906+
app.add_option("--skip-pass", skip_pass, "Skip an ASR pass in default pipeline");
907907
app.add_flag("--disable-main", compiler_options.disable_main, "Do not generate any code for the `main` function");
908908
app.add_flag("--symtab-only", compiler_options.symtab_only, "Only create symbol tables in ASR (skip executable stmt)");
909909
app.add_flag("--time-report", time_report, "Show compilation time report");

src/libasr/pass/pass_manager.h

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include <map>
4242
#include <vector>
43+
#include <algorithm>
4344

4445
namespace LCompilers {
4546

@@ -52,6 +53,7 @@ namespace LCompilers {
5253
std::vector<std::string> _passes;
5354
std::vector<std::string> _with_optimization_passes;
5455
std::vector<std::string> _user_defined_passes;
56+
std::vector<std::string> _skip_passes;
5557
std::map<std::string, pass_function> _passes_db = {
5658
{"do_loops", &LFortran::pass_replace_do_loops},
5759
{"global_stmts", &LFortran::pass_wrap_global_stmts_into_function},
@@ -77,20 +79,45 @@ namespace LCompilers {
7779

7880
bool is_fast;
7981
bool apply_default_passes;
80-
std::string skip_pass;
8182

8283
void _apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
8384
std::vector<std::string>& passes, PassOptions pass_options) {
8485
pass_options.runtime_library_dir = LFortran::get_runtime_library_dir();
8586
for (size_t i = 0; i < passes.size(); i++) {
86-
if (passes[i] == skip_pass) continue;
87+
if( std::find(_skip_passes.begin(), _skip_passes.end(), passes[i]) != _skip_passes.end())
88+
continue;
8789
_passes_db[passes[i]](al, *asr, pass_options);
8890
}
8991
}
9092

93+
void _parse_pass_arg(std::string& arg, std::vector<std::string>& passes) {
94+
if (arg == "") return;
95+
96+
std::string current_pass = "";
97+
for( size_t i = 0; i < arg.size(); i++ ) {
98+
char ch = arg[i];
99+
if (ch != ' ' && ch != ',') {
100+
current_pass.push_back(ch);
101+
}
102+
if (ch == ',' || i == arg.size() - 1) {
103+
current_pass = LFortran::to_lower(current_pass);
104+
if( _passes_db.find(current_pass) == _passes_db.end() ) {
105+
std::cerr << current_pass << " isn't supported yet.";
106+
std::cerr << " Only the following passes are supported:- "<<std::endl;
107+
for( auto it: _passes_db ) {
108+
std::cerr << it.first << std::endl;
109+
}
110+
exit(1);
111+
}
112+
passes.push_back(current_pass);
113+
current_pass.clear();
114+
}
115+
}
116+
}
117+
91118
public:
92119

93-
PassManager(): is_fast{false}, apply_default_passes{false}, skip_pass("") {
120+
PassManager(): is_fast{false}, apply_default_passes{false} {
94121
_passes = {
95122
"global_stmts",
96123
"class_constructor",
@@ -131,35 +158,15 @@ namespace LCompilers {
131158
};
132159

133160
_user_defined_passes.clear();
161+
_skip_passes.clear();
134162
}
135163

136-
void parse_pass_arg(std::string& arg_pass, std::string& s_pass) {
164+
void parse_pass_arg(std::string& arg_pass, std::string& skip_pass) {
137165
_user_defined_passes.clear();
138-
skip_pass = s_pass;
139-
if (arg_pass == "") {
140-
return ;
141-
}
166+
_skip_passes.clear();
142167

143-
std::string current_pass = "";
144-
for( size_t i = 0; i < arg_pass.size(); i++ ) {
145-
char ch = arg_pass[i];
146-
if (ch != ' ' && ch != ',') {
147-
current_pass.push_back(ch);
148-
}
149-
if (ch == ',' || i == arg_pass.size() - 1) {
150-
current_pass = LFortran::to_lower(current_pass);
151-
if( _passes_db.find(current_pass) == _passes_db.end() ) {
152-
std::cerr << current_pass << " isn't supported yet.";
153-
std::cerr << " Only the following passes are supported:- "<<std::endl;
154-
for( auto it: _passes_db ) {
155-
std::cerr << it.first << std::endl;
156-
}
157-
exit(1);
158-
}
159-
_user_defined_passes.push_back(current_pass);
160-
current_pass.clear();
161-
}
162-
}
168+
_parse_pass_arg(arg_pass, _user_defined_passes);
169+
_parse_pass_arg(skip_pass, _skip_passes);
163170
}
164171

165172
void apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr,

0 commit comments

Comments
 (0)