Skip to content

Commit ed807bb

Browse files
authored
Merge pull request #1069 from redbopo/skip_asr_pass_option
Add an option to skip pass in default pipeline
2 parents d2a5640 + 6525a76 commit ed807bb

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

src/bin/lpython.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ int main(int argc, char *argv[])
12971297
bool show_errors = false;
12981298
bool with_intrinsic_modules = false;
12991299
std::string arg_pass;
1300+
std::string skip_pass;
13001301
bool arg_no_color = false;
13011302
bool show_llvm = false;
13021303
bool show_asm = false;
@@ -1363,6 +1364,7 @@ int main(int argc, char *argv[])
13631364
app.add_flag("--indent", compiler_options.indent, "Indented print ASR/AST");
13641365
app.add_flag("--tree", compiler_options.tree, "Tree structure print ASR/AST");
13651366
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");
13661368
app.add_flag("--disable-main", compiler_options.disable_main, "Do not generate any code for the `main` function");
13671369
app.add_flag("--symtab-only", compiler_options.symtab_only, "Only create symbol tables in ASR (skip executable stmt)");
13681370
app.add_flag("--time-report", time_report, "Show compilation time report");
@@ -1539,7 +1541,7 @@ int main(int argc, char *argv[])
15391541
// return emit_c_preprocessor(arg_file, compiler_options);
15401542
// }
15411543

1542-
lpython_pass_manager.parse_pass_arg(arg_pass);
1544+
lpython_pass_manager.parse_pass_arg(arg_pass, skip_pass);
15431545
if (show_tokens) {
15441546
return emit_tokens(arg_file, true, compiler_options);
15451547
}

src/libasr/pass/pass_manager.h

Lines changed: 34 additions & 24 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},
@@ -97,6 +99,8 @@ namespace LCompilers {
9799
// Note: this is not enough for rtlib, we also need to include
98100
// it
99101
if (rtlib && passes[i] == "unused_functions") continue;
102+
if( std::find(_skip_passes.begin(), _skip_passes.end(), passes[i]) != _skip_passes.end())
103+
continue;
100104
_passes_db[passes[i]](al, *asr, pass_options);
101105
#if defined(WITH_LFORTRAN_ASSERT)
102106
if (!LFortran::asr_verify(*asr, true, diagnostics)) {
@@ -107,6 +111,31 @@ namespace LCompilers {
107111
}
108112
}
109113

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+
110139
public:
111140

112141
bool rtlib=false;
@@ -157,34 +186,15 @@ namespace LCompilers {
157186
};
158187

159188
_user_defined_passes.clear();
189+
_skip_passes.clear();
160190
}
161191

162-
void parse_pass_arg(std::string& arg_pass) {
192+
void parse_pass_arg(std::string& arg_pass, std::string& skip_pass) {
163193
_user_defined_passes.clear();
164-
if (arg_pass == "") {
165-
return ;
166-
}
194+
_skip_passes.clear();
167195

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

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

0 commit comments

Comments
 (0)