Skip to content

Commit d1d5ee9

Browse files
committed
Save pyc files to store LPython generated ASR when c and disable-main options are enabled
1 parent 8a609bf commit d1d5ee9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/bin/lpython.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ int compile_python_to_object_file(
512512
const std::string &runtime_library_dir,
513513
LCompilers::PassManager& pass_manager,
514514
CompilerOptions &compiler_options,
515-
bool time_report)
515+
bool time_report, bool arg_c=false)
516516
{
517517
Allocator al(4*1024);
518518
LFortran::diag::Diagnostics diagnostics;
@@ -540,7 +540,8 @@ int compile_python_to_object_file(
540540
diagnostics.diagnostics.clear();
541541
auto ast_to_asr_start = std::chrono::high_resolution_clock::now();
542542
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
543-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true,
543+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics,
544+
!(arg_c && compiler_options.disable_main),
544545
compiler_options.disable_main, compiler_options.symtab_only, infile);
545546
auto ast_to_asr_end = std::chrono::high_resolution_clock::now();
546547
times.push_back(std::make_pair("AST to ASR", std::chrono::duration<double, std::milli>(ast_to_asr_end - ast_to_asr_start).count()));
@@ -551,6 +552,12 @@ int compile_python_to_object_file(
551552
return 2;
552553
}
553554
LFortran::ASR::TranslationUnit_t* asr = r1.result;
555+
if( compiler_options.disable_main ) {
556+
int err = LFortran::LPython::save_pyc_files(*asr, infile);
557+
if( err ) {
558+
return err;
559+
}
560+
}
554561
diagnostics.diagnostics.clear();
555562

556563
// ASR -> LLVM
@@ -1065,7 +1072,8 @@ int main(int argc, char *argv[])
10651072
if (arg_c) {
10661073
if (backend == Backend::llvm) {
10671074
#ifdef HAVE_LFORTRAN_LLVM
1068-
return compile_python_to_object_file(arg_file, outfile, runtime_library_dir, lpython_pass_manager, compiler_options, time_report);
1075+
return compile_python_to_object_file(arg_file, outfile, runtime_library_dir, lpython_pass_manager, compiler_options, time_report,
1076+
arg_c);
10691077
#else
10701078
std::cerr << "The -c option requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl;
10711079
return 1;

0 commit comments

Comments
 (0)