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},
@@ -97,6 +99,8 @@ namespace LCompilers {
97
99
// Note: this is not enough for rtlib, we also need to include
98
100
// it
99
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 ;
100
104
_passes_db[passes[i]](al, *asr, pass_options);
101
105
#if defined(WITH_LFORTRAN_ASSERT)
102
106
if (!LFortran::asr_verify (*asr, true , diagnostics)) {
@@ -107,6 +111,31 @@ namespace LCompilers {
107
111
}
108
112
}
109
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
+
110
139
public:
111
140
112
141
bool rtlib=false ;
@@ -157,34 +186,15 @@ namespace LCompilers {
157
186
};
158
187
159
188
_user_defined_passes.clear ();
189
+ _skip_passes.clear ();
160
190
}
161
191
162
- void parse_pass_arg (std::string& arg_pass) {
192
+ void parse_pass_arg (std::string& arg_pass, std::string& skip_pass ) {
163
193
_user_defined_passes.clear ();
164
- if (arg_pass == " " ) {
165
- return ;
166
- }
194
+ _skip_passes.clear ();
167
195
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);
188
198
}
189
199
190
200
void apply_passes (Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
0 commit comments