@@ -443,6 +443,45 @@ int emit_wat(const std::string &infile,
443
443
return 0 ;
444
444
}
445
445
446
+ int dump_all_passes (const std::string &infile,
447
+ const std::string &runtime_library_dir,
448
+ CompilerOptions &compiler_options) {
449
+ std::string input = LCompilers::read_file (infile);
450
+
451
+ Allocator al (4 *1024 );
452
+ LCompilers::LocationManager lm;
453
+ LCompilers::diag::Diagnostics diagnostics;
454
+ {
455
+ LCompilers::LocationManager::FileLocations fl;
456
+ fl.in_filename = infile;
457
+ lm.files .push_back (fl);
458
+ lm.file_ends .push_back (input.size ());
459
+ }
460
+
461
+ LCompilers::Result<LCompilers::LPython::AST::ast_t *> r = parse_python_file (
462
+ al, runtime_library_dir, infile, diagnostics, 0 , compiler_options.new_parser );
463
+ std::cerr << diagnostics.render (lm, compiler_options);
464
+ if (!r.ok ) {
465
+ return 1 ;
466
+ }
467
+ LCompilers::LPython::AST::ast_t * ast = r.result ;
468
+ diagnostics.diagnostics .clear ();
469
+ LCompilers::Result<LCompilers::ASR::TranslationUnit_t*>
470
+ r1 = LCompilers::LPython::python_ast_to_asr (al, lm, nullptr , *ast, diagnostics, compiler_options, true , " __main__" , infile);
471
+ std::cerr << diagnostics.render (lm, compiler_options);
472
+ if (r1.ok ) {
473
+ LCompilers::PassManager pass_manager;
474
+ compiler_options.po .always_run = true ;
475
+ compiler_options.po .run_fun = " f" ;
476
+ pass_manager.dump_all_passes (al, r1.result , compiler_options.po , diagnostics, lm);
477
+ std::cerr << diagnostics.render (lm, compiler_options);
478
+ } else {
479
+ LCOMPILERS_ASSERT (diagnostics.has_error ())
480
+ return 1 ;
481
+ }
482
+ return 0 ;
483
+ }
484
+
446
485
#ifdef HAVE_LFORTRAN_RAPIDJSON
447
486
448
487
int get_symbols (const std::string &infile,
@@ -1549,6 +1588,8 @@ int main(int argc, char *argv[])
1549
1588
app.add_flag (" --get-rtl-header-dir" , print_rtl_header_dir, " Print the path to the runtime library header file" );
1550
1589
app.add_flag (" --get-rtl-dir" , print_rtl_dir, " Print the path to the runtime library file" );
1551
1590
app.add_flag (" --verbose" , compiler_options.po .verbose , " Print debugging statements" );
1591
+ app.add_flag (" --dump-all-passes" , compiler_options.po .dump_all_passes , " Apply all the passes and dump the ASR into a file" );
1592
+ app.add_flag (" --dump-all-passes-fortran" , compiler_options.po .dump_fortran , " Apply all passes and dump the ASR after each pass into fortran file" );
1552
1593
app.add_flag (" --cumulative" , compiler_options.po .pass_cumulative , " Apply all the passes cumulatively till the given pass" );
1553
1594
app.add_flag (" --enable-cpython" , compiler_options.enable_cpython , " Enable CPython runtime" );
1554
1595
app.add_flag (" --enable-symengine" , compiler_options.enable_symengine , " Enable Symengine runtime" );
@@ -1726,6 +1767,10 @@ int main(int argc, char *argv[])
1726
1767
outfile = basename + " .out" ;
1727
1768
}
1728
1769
1770
+ if (compiler_options.po .dump_fortran || compiler_options.po .dump_all_passes ) {
1771
+ dump_all_passes (arg_file, compiler_options);
1772
+ }
1773
+
1729
1774
// if (arg_E) {
1730
1775
// return emit_c_preprocessor(arg_file, compiler_options);
1731
1776
// }
0 commit comments