@@ -480,6 +480,45 @@ int emit_wat(const std::string &infile,
480
480
return 0 ;
481
481
}
482
482
483
+ int dump_all_passes (const std::string &infile,
484
+ const std::string &runtime_library_dir,
485
+ CompilerOptions &compiler_options) {
486
+ std::string input = LCompilers::read_file (infile);
487
+
488
+ Allocator al (4 *1024 );
489
+ LCompilers::LocationManager lm;
490
+ LCompilers::diag::Diagnostics diagnostics;
491
+ {
492
+ LCompilers::LocationManager::FileLocations fl;
493
+ fl.in_filename = infile;
494
+ lm.files .push_back (fl);
495
+ lm.file_ends .push_back (input.size ());
496
+ }
497
+
498
+ LCompilers::Result<LCompilers::LPython::AST::ast_t *> r = parse_python_file (
499
+ al, runtime_library_dir, infile, diagnostics, 0 , compiler_options.new_parser );
500
+ std::cerr << diagnostics.render (lm, compiler_options);
501
+ if (!r.ok ) {
502
+ return 1 ;
503
+ }
504
+ LCompilers::LPython::AST::ast_t * ast = r.result ;
505
+ diagnostics.diagnostics .clear ();
506
+ LCompilers::Result<LCompilers::ASR::TranslationUnit_t*>
507
+ r1 = LCompilers::LPython::python_ast_to_asr (al, lm, nullptr , *ast, diagnostics, compiler_options, true , " __main__" , infile);
508
+ std::cerr << diagnostics.render (lm, compiler_options);
509
+ if (r1.ok ) {
510
+ LCompilers::PassManager pass_manager;
511
+ compiler_options.po .always_run = true ;
512
+ compiler_options.po .run_fun = " f" ;
513
+ pass_manager.dump_all_passes (al, r1.result , compiler_options.po , diagnostics, lm);
514
+ std::cerr << diagnostics.render (lm, compiler_options);
515
+ } else {
516
+ LCOMPILERS_ASSERT (diagnostics.has_error ())
517
+ return 1 ;
518
+ }
519
+ return 0 ;
520
+ }
521
+
483
522
#ifdef HAVE_LFORTRAN_RAPIDJSON
484
523
485
524
int get_symbols (const std::string &infile,
@@ -1586,6 +1625,8 @@ int main(int argc, char *argv[])
1586
1625
app.add_flag (" --get-rtl-header-dir" , print_rtl_header_dir, " Print the path to the runtime library header file" );
1587
1626
app.add_flag (" --get-rtl-dir" , print_rtl_dir, " Print the path to the runtime library file" );
1588
1627
app.add_flag (" --verbose" , compiler_options.verbose , " Print debugging statements" );
1628
+ app.add_flag (" --dump-all-passes" , compiler_options.po .dump_all_passes , " Apply all the passes and dump the ASR into a file" );
1629
+ 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" );
1589
1630
app.add_flag (" --cumulative" , compiler_options.pass_cumulative , " Apply all the passes cumulatively till the given pass" );
1590
1631
app.add_flag (" --enable-cpython" , compiler_options.enable_cpython , " Enable CPython runtime" );
1591
1632
app.add_flag (" --enable-symengine" , compiler_options.enable_symengine , " Enable Symengine runtime" );
@@ -1763,6 +1804,10 @@ int main(int argc, char *argv[])
1763
1804
outfile = basename + " .out" ;
1764
1805
}
1765
1806
1807
+ if (compiler_options.po .dump_fortran || compiler_options.po .dump_all_passes ) {
1808
+ dump_all_passes (arg_file, compiler_options);
1809
+ }
1810
+
1766
1811
// if (arg_E) {
1767
1812
// return emit_c_preprocessor(arg_file, compiler_options);
1768
1813
// }
0 commit comments