45
45
46
46
#include < map>
47
47
#include < vector>
48
+ #include < algorithm>
48
49
49
50
namespace LCompilers {
50
51
@@ -57,6 +58,7 @@ namespace LCompilers {
57
58
std::vector<std::string> _passes;
58
59
std::vector<std::string> _with_optimization_passes;
59
60
std::vector<std::string> _user_defined_passes;
61
+ std::vector<std::string> _skip_passes;
60
62
std::map<std::string, pass_function> _passes_db = {
61
63
{" do_loops" , &LFortran::pass_replace_do_loops},
62
64
{" global_stmts" , &LFortran::pass_wrap_global_stmts_into_function},
@@ -86,7 +88,6 @@ namespace LCompilers {
86
88
87
89
bool is_fast;
88
90
bool apply_default_passes;
89
- std::string skip_pass;
90
91
91
92
void _apply_passes (Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
92
93
std::vector<std::string>& passes, PassOptions &pass_options,
@@ -98,6 +99,8 @@ namespace LCompilers {
98
99
// Note: this is not enough for rtlib, we also need to include
99
100
// it
100
101
if (rtlib && passes[i] == " unused_functions" ) continue ;
102
+ if ( std::find (_skip_passes.begin (), _skip_passes.end (), passes[i]) != _skip_passes.end ())
103
+ continue ;
101
104
_passes_db[passes[i]](al, *asr, pass_options);
102
105
#if defined(WITH_LFORTRAN_ASSERT)
103
106
if (!LFortran::asr_verify (*asr, true , diagnostics)) {
@@ -108,6 +111,31 @@ namespace LCompilers {
108
111
}
109
112
}
110
113
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
+
111
139
public:
112
140
113
141
bool rtlib=false ;
@@ -158,35 +186,15 @@ namespace LCompilers {
158
186
};
159
187
160
188
_user_defined_passes.clear ();
189
+ _skip_passes.clear ();
161
190
}
162
191
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 ) {
164
193
_user_defined_passes.clear ();
165
- skip_pass = s_pass;
166
- if (arg_pass == " " ) {
167
- return ;
168
- }
194
+ _skip_passes.clear ();
169
195
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);
190
198
}
191
199
192
200
void apply_passes (Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
0 commit comments