@@ -262,6 +262,7 @@ int emit_cpp(const std::string &infile,
262
262
263
263
int emit_c (const std::string &infile,
264
264
const std::string &runtime_library_dir,
265
+ LCompilers::PassManager& pass_manager,
265
266
CompilerOptions &compiler_options)
266
267
{
267
268
Allocator al (4 *1024 );
@@ -293,6 +294,13 @@ int emit_c(const std::string &infile,
293
294
}
294
295
LCompilers::ASR::TranslationUnit_t* asr = r1.result ;
295
296
297
+ // Apply ASR passes
298
+ LCompilers::PassOptions pass_options;
299
+ pass_manager.use_default_passes ();
300
+ pass_options.run_fun = " f" ;
301
+ pass_options.always_run = true ;
302
+ pass_manager.apply_passes (al, asr, pass_options, diagnostics);
303
+
296
304
diagnostics.diagnostics .clear ();
297
305
auto res = LCompilers::asr_to_c (al, *asr, diagnostics, compiler_options, 0 );
298
306
std::cerr << diagnostics.render (lm, compiler_options);
@@ -305,7 +313,7 @@ int emit_c(const std::string &infile,
305
313
}
306
314
307
315
int emit_c_to_file (const std::string &infile, const std::string &outfile,
308
- const std::string &runtime_library_dir,
316
+ const std::string &runtime_library_dir, LCompilers::PassManager& pass_manager,
309
317
CompilerOptions &compiler_options)
310
318
{
311
319
Allocator al (4 *1024 );
@@ -337,6 +345,13 @@ int emit_c_to_file(const std::string &infile, const std::string &outfile,
337
345
}
338
346
LCompilers::ASR::TranslationUnit_t* asr = r1.result ;
339
347
348
+ // Apply ASR passes
349
+ LCompilers::PassOptions pass_options;
350
+ pass_manager.use_default_passes ();
351
+ pass_options.run_fun = " f" ;
352
+ pass_options.always_run = true ;
353
+ pass_manager.apply_passes (al, asr, pass_options, diagnostics);
354
+
340
355
diagnostics.diagnostics .clear ();
341
356
auto res = LCompilers::asr_to_c (al, *asr, diagnostics, compiler_options, 0 );
342
357
std::cerr << diagnostics.render (lm, compiler_options);
@@ -1666,7 +1681,8 @@ int main(int argc, char *argv[])
1666
1681
return emit_cpp (arg_file, runtime_library_dir, compiler_options);
1667
1682
}
1668
1683
if (show_c) {
1669
- return emit_c (arg_file, runtime_library_dir, compiler_options);
1684
+ return emit_c (arg_file, runtime_library_dir, lpython_pass_manager,
1685
+ compiler_options);
1670
1686
}
1671
1687
if (show_wat) {
1672
1688
return emit_wat (arg_file, runtime_library_dir, compiler_options);
@@ -1741,7 +1757,8 @@ int main(int argc, char *argv[])
1741
1757
runtime_library_dir, compiler_options, time_report, backend);
1742
1758
} else if (backend == Backend::c) {
1743
1759
std::string emit_file_name = basename + " __tmp__generated__.c" ;
1744
- err = emit_c_to_file (arg_file, emit_file_name, runtime_library_dir, compiler_options);
1760
+ err = emit_c_to_file (arg_file, emit_file_name, runtime_library_dir,
1761
+ lpython_pass_manager, compiler_options);
1745
1762
err = link_executable ({emit_file_name}, outfile, runtime_library_dir,
1746
1763
backend, static_link, true , compiler_options, rtlib_header_dir);
1747
1764
} else if (backend == Backend::llvm) {
0 commit comments