40
40
41
41
#include < map>
42
42
#include < vector>
43
+ #include < algorithm>
43
44
44
45
namespace LCompilers {
45
46
@@ -52,6 +53,7 @@ namespace LCompilers {
52
53
std::vector<std::string> _passes;
53
54
std::vector<std::string> _with_optimization_passes;
54
55
std::vector<std::string> _user_defined_passes;
56
+ std::vector<std::string> _skip_passes;
55
57
std::map<std::string, pass_function> _passes_db = {
56
58
{" do_loops" , &LFortran::pass_replace_do_loops},
57
59
{" global_stmts" , &LFortran::pass_wrap_global_stmts_into_function},
@@ -77,20 +79,45 @@ namespace LCompilers {
77
79
78
80
bool is_fast;
79
81
bool apply_default_passes;
80
- std::string skip_pass;
81
82
82
83
void _apply_passes (Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
83
84
std::vector<std::string>& passes, PassOptions pass_options) {
84
85
pass_options.runtime_library_dir = LFortran::get_runtime_library_dir ();
85
86
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 ;
87
89
_passes_db[passes[i]](al, *asr, pass_options);
88
90
}
89
91
}
90
92
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
+
91
118
public:
92
119
93
- PassManager (): is_fast{false }, apply_default_passes{false }, skip_pass( " " ) {
120
+ PassManager (): is_fast{false }, apply_default_passes{false } {
94
121
_passes = {
95
122
" global_stmts" ,
96
123
" class_constructor" ,
@@ -131,35 +158,15 @@ namespace LCompilers {
131
158
};
132
159
133
160
_user_defined_passes.clear ();
161
+ _skip_passes.clear ();
134
162
}
135
163
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 ) {
137
165
_user_defined_passes.clear ();
138
- skip_pass = s_pass;
139
- if (arg_pass == " " ) {
140
- return ;
141
- }
166
+ _skip_passes.clear ();
142
167
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);
163
170
}
164
171
165
172
void apply_passes (Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
0 commit comments