Skip to content

Commit fe2fbf0

Browse files
authored
Merge pull request #2156 from Smit-create/pass_op1
Add `cumulative` flag for pass
2 parents f669bce + b63e46e commit fe2fbf0

7 files changed

+728
-2
lines changed

run_tests.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ def is_included(backend):
2626
llvm_dbg = is_included("llvm_dbg")
2727
cpp = is_included("cpp")
2828
c = is_included("c")
29+
is_cumulative = is_included("cumulative")
2930
wat = is_included("wat")
3031
run = is_included("run")
3132
run_with_dbg = is_included("run_with_dbg")
3233
disable_main = is_included("disable_main")
3334
pass_ = test.get("pass", None)
3435
optimization_passes = ["flip_sign", "div_to_mul", "fma", "sign_from_value",
3536
"inline_function_calls", "loop_unroll",
36-
"dead_code_removal", "loop_vectorise", "print_list_tuple"]
37+
"dead_code_removal", "loop_vectorise", "print_list_tuple",
38+
"class_constructor"]
3739

3840
if pass_ and (pass_ not in ["do_loops", "global_stmts"] and
3941
pass_ not in optimization_passes):
@@ -91,7 +93,10 @@ def is_included(backend):
9193
extra_args)
9294

9395
if pass_ is not None:
94-
cmd = "lpython --pass=" + pass_ + \
96+
cmd = "lpython "
97+
if is_cumulative:
98+
cmd += "--cumulative "
99+
cmd += "--pass=" + pass_ + \
95100
" --show-asr --no-color {infile} -o {outfile}"
96101
run_test(filename, "pass_{}".format(pass_), cmd,
97102
filename, update_reference, extra_args)

src/bin/lpython.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ int emit_asr(const std::string &infile,
242242
pass_options.run_fun = "f";
243243
pass_options.always_run = true;
244244
pass_options.verbose = compiler_options.verbose;
245+
pass_options.pass_cumulative = compiler_options.pass_cumulative;
245246

246247
pass_manager.apply_passes(al, asr, pass_options, diagnostics);
247248

@@ -1574,6 +1575,7 @@ int main(int argc, char *argv[])
15741575
app.add_flag("--get-rtl-header-dir", print_rtl_header_dir, "Print the path to the runtime library header file");
15751576
app.add_flag("--get-rtl-dir", print_rtl_dir, "Print the path to the runtime library file");
15761577
app.add_flag("--verbose", compiler_options.verbose, "Print debugging statements");
1578+
app.add_flag("--cumulative", compiler_options.pass_cumulative, "Apply all the passes cumulatively till the given pass");
15771579
app.add_flag("--enable-cpython", compiler_options.enable_cpython, "Enable CPython runtime");
15781580
app.add_flag("--enable-symengine", compiler_options.enable_symengine, "Enable Symengine runtime");
15791581
app.add_flag("--link-numpy", compiler_options.link_numpy, "Enable NumPy runtime (implies --enable-cpython)");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-structs_16-44de89a",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/../integration_tests/structs_16.py",
5+
"infile_hash": "e87ea0ba10cb7fcd6ce2eb6d2e953a26dcd6a843f6cf4e891287dcb1",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": "asr-structs_16-44de89a.stdout",
9+
"stdout_hash": "003d4550abb6fca33a8741e4d586a32ab5ce3355a40da5f911d61112",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
13+
}
Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
(TranslationUnit
2+
(SymbolTable
3+
1
4+
{
5+
_global_symbols:
6+
(Module
7+
(SymbolTable
8+
9
9+
{
10+
A:
11+
(StructType
12+
(SymbolTable
13+
2
14+
{
15+
B:
16+
(UnionType
17+
(SymbolTable
18+
3
19+
{
20+
x:
21+
(Variable
22+
3
23+
x
24+
[]
25+
Local
26+
()
27+
()
28+
Default
29+
(Integer 4)
30+
()
31+
Source
32+
Public
33+
Required
34+
.false.
35+
),
36+
y:
37+
(Variable
38+
3
39+
y
40+
[]
41+
Local
42+
()
43+
()
44+
Default
45+
(Integer 8)
46+
()
47+
Source
48+
Public
49+
Required
50+
.false.
51+
)
52+
})
53+
B
54+
[]
55+
[x
56+
y]
57+
Source
58+
Public
59+
[(())
60+
(())]
61+
()
62+
),
63+
b:
64+
(Variable
65+
2
66+
b
67+
[]
68+
Local
69+
()
70+
()
71+
Default
72+
(Union
73+
2 B
74+
)
75+
()
76+
Source
77+
Public
78+
Required
79+
.false.
80+
),
81+
c:
82+
(Variable
83+
2
84+
c
85+
[]
86+
Local
87+
()
88+
()
89+
Default
90+
(Integer 4)
91+
()
92+
Source
93+
Public
94+
Required
95+
.false.
96+
)
97+
})
98+
A
99+
[]
100+
[b
101+
c]
102+
Source
103+
Public
104+
.false.
105+
.false.
106+
[(())
107+
(())]
108+
()
109+
()
110+
),
111+
_lpython_main_program:
112+
(Function
113+
(SymbolTable
114+
8
115+
{
116+
117+
})
118+
_lpython_main_program
119+
(FunctionType
120+
[]
121+
()
122+
Source
123+
Implementation
124+
()
125+
.false.
126+
.false.
127+
.false.
128+
.false.
129+
.false.
130+
[]
131+
[]
132+
.false.
133+
)
134+
[test_ordering]
135+
[]
136+
[(SubroutineCall
137+
9 test_ordering
138+
()
139+
[]
140+
()
141+
)]
142+
()
143+
Public
144+
.false.
145+
.false.
146+
()
147+
),
148+
test_ordering:
149+
(Function
150+
(SymbolTable
151+
4
152+
{
153+
A_B:
154+
(ExternalSymbol
155+
4
156+
A_B
157+
2 B
158+
A
159+
[]
160+
B
161+
Public
162+
),
163+
ad:
164+
(Variable
165+
4
166+
ad
167+
[]
168+
Local
169+
()
170+
()
171+
Default
172+
(Struct
173+
9 A
174+
)
175+
()
176+
Source
177+
Public
178+
Required
179+
.false.
180+
),
181+
bd:
182+
(Variable
183+
4
184+
bd
185+
[]
186+
Local
187+
()
188+
()
189+
Default
190+
(Union
191+
4 A_B
192+
)
193+
()
194+
Source
195+
Public
196+
Required
197+
.false.
198+
)
199+
})
200+
test_ordering
201+
(FunctionType
202+
[]
203+
()
204+
Source
205+
Implementation
206+
()
207+
.false.
208+
.false.
209+
.false.
210+
.false.
211+
.false.
212+
[]
213+
[]
214+
.false.
215+
)
216+
[]
217+
[]
218+
[(=
219+
(Var 4 bd)
220+
(UnionTypeConstructor
221+
4 A_B
222+
[]
223+
(Union
224+
4 A_B
225+
)
226+
()
227+
)
228+
()
229+
)
230+
(=
231+
(UnionInstanceMember
232+
(Var 4 bd)
233+
3 x
234+
(Integer 4)
235+
()
236+
)
237+
(IntegerConstant 1 (Integer 4))
238+
()
239+
)
240+
(=
241+
(Var 4 ad)
242+
(StructTypeConstructor
243+
9 A
244+
[((Var 4 bd))
245+
((IntegerConstant 2 (Integer 4)))]
246+
(Struct
247+
9 A
248+
)
249+
()
250+
)
251+
()
252+
)
253+
(Assert
254+
(IntegerCompare
255+
(UnionInstanceMember
256+
(StructInstanceMember
257+
(Var 4 ad)
258+
2 b
259+
(Union
260+
2 B
261+
)
262+
()
263+
)
264+
3 x
265+
(Integer 4)
266+
()
267+
)
268+
Eq
269+
(IntegerConstant 1 (Integer 4))
270+
(Logical 4)
271+
()
272+
)
273+
()
274+
)
275+
(Assert
276+
(IntegerCompare
277+
(StructInstanceMember
278+
(Var 4 ad)
279+
2 c
280+
(Integer 4)
281+
()
282+
)
283+
Eq
284+
(IntegerConstant 2 (Integer 4))
285+
(Logical 4)
286+
()
287+
)
288+
()
289+
)]
290+
()
291+
Public
292+
.false.
293+
.false.
294+
()
295+
)
296+
})
297+
_global_symbols
298+
[]
299+
.false.
300+
.false.
301+
),
302+
main_program:
303+
(Program
304+
(SymbolTable
305+
7
306+
{
307+
_lpython_main_program:
308+
(ExternalSymbol
309+
7
310+
_lpython_main_program
311+
9 _lpython_main_program
312+
_global_symbols
313+
[]
314+
_lpython_main_program
315+
Public
316+
)
317+
})
318+
main_program
319+
[_global_symbols]
320+
[(SubroutineCall
321+
7 _lpython_main_program
322+
()
323+
[]
324+
()
325+
)]
326+
)
327+
})
328+
[]
329+
)

0 commit comments

Comments
 (0)