Skip to content

Commit 6525a76

Browse files
committed
Enable skip multi passes.
Also change option to --skip-pass, format like other options.
1 parent 5744828 commit 6525a76

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

src/bin/lpython.cpp

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

src/libasr/pass/pass_manager.h

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include <map>
4747
#include <vector>
48+
#include <algorithm>
4849

4950
namespace LCompilers {
5051

@@ -57,6 +58,7 @@ namespace LCompilers {
5758
std::vector<std::string> _passes;
5859
std::vector<std::string> _with_optimization_passes;
5960
std::vector<std::string> _user_defined_passes;
61+
std::vector<std::string> _skip_passes;
6062
std::map<std::string, pass_function> _passes_db = {
6163
{"do_loops", &LFortran::pass_replace_do_loops},
6264
{"global_stmts", &LFortran::pass_wrap_global_stmts_into_function},
@@ -86,7 +88,6 @@ namespace LCompilers {
8688

8789
bool is_fast;
8890
bool apply_default_passes;
89-
std::string skip_pass;
9091

9192
void _apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
9293
std::vector<std::string>& passes, PassOptions &pass_options,
@@ -98,6 +99,8 @@ namespace LCompilers {
9899
// Note: this is not enough for rtlib, we also need to include
99100
// it
100101
if (rtlib && passes[i] == "unused_functions") continue;
102+
if( std::find(_skip_passes.begin(), _skip_passes.end(), passes[i]) != _skip_passes.end())
103+
continue;
101104
_passes_db[passes[i]](al, *asr, pass_options);
102105
#if defined(WITH_LFORTRAN_ASSERT)
103106
if (!LFortran::asr_verify(*asr, true, diagnostics)) {
@@ -108,6 +111,31 @@ namespace LCompilers {
108111
}
109112
}
110113

114+
void _parse_pass_arg(std::string& arg, std::vector<std::string>& passes) {
115+
if (arg == "") return;
116+
117+
std::string current_pass = "";
118+
for( size_t i = 0; i < arg.size(); i++ ) {
119+
char ch = arg[i];
120+
if (ch != ' ' && ch != ',') {
121+
current_pass.push_back(ch);
122+
}
123+
if (ch == ',' || i == arg.size() - 1) {
124+
current_pass = LFortran::to_lower(current_pass);
125+
if( _passes_db.find(current_pass) == _passes_db.end() ) {
126+
std::cerr << current_pass << " isn't supported yet.";
127+
std::cerr << " Only the following passes are supported:- "<<std::endl;
128+
for( auto it: _passes_db ) {
129+
std::cerr << it.first << std::endl;
130+
}
131+
exit(1);
132+
}
133+
passes.push_back(current_pass);
134+
current_pass.clear();
135+
}
136+
}
137+
}
138+
111139
public:
112140

113141
bool rtlib=false;
@@ -158,35 +186,15 @@ namespace LCompilers {
158186
};
159187

160188
_user_defined_passes.clear();
189+
_skip_passes.clear();
161190
}
162191

163-
void parse_pass_arg(std::string& arg_pass, std::string& s_pass) {
192+
void parse_pass_arg(std::string& arg_pass, std::string& skip_pass) {
164193
_user_defined_passes.clear();
165-
skip_pass = s_pass;
166-
if (arg_pass == "") {
167-
return ;
168-
}
194+
_skip_passes.clear();
169195

170-
std::string current_pass = "";
171-
for( size_t i = 0; i < arg_pass.size(); i++ ) {
172-
char ch = arg_pass[i];
173-
if (ch != ' ' && ch != ',') {
174-
current_pass.push_back(ch);
175-
}
176-
if (ch == ',' || i == arg_pass.size() - 1) {
177-
current_pass = LFortran::to_lower(current_pass);
178-
if( _passes_db.find(current_pass) == _passes_db.end() ) {
179-
std::cerr << current_pass << " isn't supported yet.";
180-
std::cerr << " Only the following passes are supported:- "<<std::endl;
181-
for( auto it: _passes_db ) {
182-
std::cerr << it.first << std::endl;
183-
}
184-
exit(1);
185-
}
186-
_user_defined_passes.push_back(current_pass);
187-
current_pass.clear();
188-
}
189-
}
196+
_parse_pass_arg(arg_pass, _user_defined_passes);
197+
_parse_pass_arg(skip_pass, _skip_passes);
190198
}
191199

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

0 commit comments

Comments
 (0)