@@ -744,6 +744,11 @@ void print_time_report(std::vector<std::pair<std::string, double>> ×, bool
744
744
745
745
#ifdef HAVE_LFORTRAN_LLVM
746
746
747
+ void section (const std::string &s)
748
+ {
749
+ std::cout << color (LCompilers::style::bold) << color (LCompilers::fg::blue) << s << color (LCompilers::style::reset) << color (LCompilers::fg::reset) << std::endl;
750
+ }
751
+
747
752
int emit_llvm (const std::string &infile,
748
753
const std::string &runtime_library_dir,
749
754
LCompilers::PassManager& pass_manager,
@@ -794,9 +799,9 @@ int emit_llvm(const std::string &infile,
794
799
}
795
800
796
801
int interactive_python_repl (
797
- // LCompilers::PassManager& pass_manager,
802
+ LCompilers::PassManager& pass_manager,
798
803
CompilerOptions &compiler_options,
799
- bool /* time_report */ )
804
+ bool verbose )
800
805
{
801
806
Allocator al (4 *1024 );
802
807
compiler_options.interactive = true ;
@@ -805,8 +810,6 @@ int interactive_python_repl(
805
810
LCompilers::LocationManager lm;
806
811
std::vector<std::pair<std::string, double >> times;
807
812
LCompilers::PythonCompiler::EvalResult r;
808
- LCompilers::PassManager pass_manager;
809
- pass_manager.use_default_passes ();
810
813
811
814
std::string code_string;
812
815
std::cout << " >>> " ;
@@ -831,8 +834,6 @@ int interactive_python_repl(
831
834
}
832
835
code_string += input + " \n " ;
833
836
834
- // std::cout << "code block: \n" << code_string;
835
-
836
837
{
837
838
cell_count++;
838
839
LCompilers::LocationManager::FileLocations fl;
@@ -847,7 +848,7 @@ int interactive_python_repl(
847
848
try {
848
849
auto evaluation_start_time = std::chrono::high_resolution_clock::now ();
849
850
LCompilers::Result<LCompilers::PythonCompiler::EvalResult>
850
- res = fe.evaluate (code_string, false , lm, pass_manager, diagnostics);
851
+ res = fe.evaluate (code_string, verbose , lm, pass_manager, diagnostics);
851
852
if (res.ok ) {
852
853
r = res.result ;
853
854
} else {
@@ -876,57 +877,66 @@ int interactive_python_repl(
876
877
continue ;
877
878
}
878
879
880
+ if (verbose) {
881
+ section (" AST:" );
882
+ std::cout << r.ast << std::endl;
883
+ section (" ASR:" );
884
+ std::cout << r.asr << std::endl;
885
+ section (" LLVM IR:" );
886
+ std::cout << r.llvm_ir << std::endl;
887
+ }
888
+
879
889
switch (r.type ) {
880
890
case (LCompilers::PythonCompiler::EvalResult::integer4) : {
881
- // if (verbose) std::cout << "Return type: integer" << std::endl;
882
- // if (verbose) section("Result:");
891
+ if (verbose) std::cout << " Return type: integer" << std::endl;
892
+ if (verbose) section (" Result:" );
883
893
std::cout << r.i32 << std::endl;
884
894
break ;
885
895
}
886
896
case (LCompilers::PythonCompiler::EvalResult::integer8) : {
887
- // if (verbose) std::cout << "Return type: integer(8)" << std::endl;
888
- // if (verbose) section("Result:");
897
+ if (verbose) std::cout << " Return type: integer(8)" << std::endl;
898
+ if (verbose) section (" Result:" );
889
899
std::cout << r.i64 << std::endl;
890
900
break ;
891
901
}
892
902
case (LCompilers::PythonCompiler::EvalResult::real4) : {
893
- // if (verbose) std::cout << "Return type: real" << std::endl;
894
- // if (verbose) section("Result:");
903
+ if (verbose) std::cout << " Return type: real" << std::endl;
904
+ if (verbose) section (" Result:" );
895
905
std::cout << std::setprecision (8 ) << r.f32 << std::endl;
896
906
break ;
897
907
}
898
908
case (LCompilers::PythonCompiler::EvalResult::real8) : {
899
- // if (verbose) std::cout << "Return type: real(8)" << std::endl;
900
- // if (verbose) section("Result:");
909
+ if (verbose) std::cout << " Return type: real(8)" << std::endl;
910
+ if (verbose) section (" Result:" );
901
911
std::cout << std::setprecision (17 ) << r.f64 << std::endl;
902
912
break ;
903
913
}
904
914
case (LCompilers::PythonCompiler::EvalResult::complex4) : {
905
- // if (verbose) std::cout << "Return type: complex" << std::endl;
906
- // if (verbose) section("Result:");
915
+ if (verbose) std::cout << " Return type: complex" << std::endl;
916
+ if (verbose) section (" Result:" );
907
917
std::cout << std::setprecision (8 ) << " (" << r.c32 .re << " , " << r.c32 .im << " )" << std::endl;
908
918
break ;
909
919
}
910
920
case (LCompilers::PythonCompiler::EvalResult::complex8) : {
911
- // if (verbose) std::cout << "Return type: complex(8)" << std::endl;
912
- // if (verbose) section("Result:");
921
+ if (verbose) std::cout << " Return type: complex(8)" << std::endl;
922
+ if (verbose) section (" Result:" );
913
923
std::cout << std::setprecision (17 ) << " (" << r.c64 .re << " , " << r.c64 .im << " )" << std::endl;
914
924
break ;
915
925
}
916
926
case (LCompilers::PythonCompiler::EvalResult::statement) : {
917
- // if (verbose) {
918
- // std::cout << "Return type: none" << std::endl;
919
- // section("Result:");
920
- // std::cout << "(statement)" << std::endl;
921
- // }
927
+ if (verbose) {
928
+ std::cout << " Return type: none" << std::endl;
929
+ section (" Result:" );
930
+ std::cout << " (statement)" << std::endl;
931
+ }
922
932
break ;
923
933
}
924
934
case (LCompilers::PythonCompiler::EvalResult::none) : {
925
- // if (verbose) {
926
- // std::cout << "Return type: none" << std::endl;
927
- // section("Result:");
928
- // std::cout << "(nothing to execute)" << std::endl;
929
- // }
935
+ if (verbose) {
936
+ std::cout << " Return type: none" << std::endl;
937
+ section (" Result:" );
938
+ std::cout << " (nothing to execute)" << std::endl;
939
+ }
930
940
break ;
931
941
}
932
942
default : throw LCompilers::LCompilersException (" Return type not supported" );
@@ -1983,7 +1993,7 @@ int main(int argc, char *argv[])
1983
1993
compiler_options.po .disable_main = true ;
1984
1994
compiler_options.emit_debug_line_column = false ;
1985
1995
compiler_options.generate_object_code = false ;
1986
- return interactive_python_repl (compiler_options, time_report );
1996
+ return interactive_python_repl (lpython_pass_manager, compiler_options, arg_v );
1987
1997
}
1988
1998
1989
1999
// TODO: for now we ignore the other filenames, only handle
0 commit comments