Skip to content

Commit d9525b6

Browse files
Merge pull request #1302 from Thirumalai-Shaktivel/auto_run
2 parents 5a8b50f + ef95afc commit d9525b6

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

src/bin/lpython.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -927,16 +927,6 @@ int link_executable(const std::vector<std::string> &infiles,
927927
std::cout << "The command '" + cmd + "' failed." << std::endl;
928928
return 10;
929929
}
930-
if (compiler_options.arg_o == "") {
931-
err = system(outfile.c_str());
932-
if (err != 0) {
933-
if (0 < err && err < 256) {
934-
return err;
935-
} else {
936-
return 1;
937-
}
938-
}
939-
}
940930
} else {
941931
std::string CC = "cc";
942932
char *env_CC = std::getenv("LFORTRAN_CC");
@@ -962,16 +952,6 @@ int link_executable(const std::vector<std::string> &infiles,
962952
std::cout << "The command '" + cmd + "' failed." << std::endl;
963953
return 10;
964954
}
965-
if (compiler_options.arg_o == "") {
966-
err = system(("./" + outfile).c_str());
967-
if (err != 0) {
968-
if (0 < err && err < 256) {
969-
return err;
970-
} else {
971-
return 1;
972-
}
973-
}
974-
}
975955
}
976956
return 0;
977957
} else if (backend == Backend::cpp) {
@@ -1527,32 +1507,48 @@ int main(int argc, char *argv[])
15271507

15281508
if (endswith(arg_file, ".py"))
15291509
{
1510+
int err = 0;
15301511
if (backend == Backend::x86) {
1531-
return compile_to_binary_x86(arg_file, outfile,
1512+
err = compile_to_binary_x86(arg_file, outfile,
15321513
runtime_library_dir, compiler_options, time_report);
15331514
} else if (backend == Backend::wasm) {
1534-
return compile_to_binary_wasm(arg_file, outfile,
1515+
err = compile_to_binary_wasm(arg_file, outfile,
15351516
runtime_library_dir, compiler_options, time_report);
15361517
} else if (backend == Backend::wasm_x86) {
1537-
return compile_to_binary_wasm_to_x86(arg_file, outfile,
1518+
err = compile_to_binary_wasm_to_x86(arg_file, outfile,
15381519
runtime_library_dir, compiler_options, time_report);
1539-
}
1540-
1541-
std::string tmp_o = outfile + ".tmp.o";
1542-
int err;
1543-
if (backend == Backend::llvm) {
1520+
} else if (backend == Backend::llvm) {
15441521
#ifdef HAVE_LFORTRAN_LLVM
1545-
err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, lpython_pass_manager, compiler_options, time_report);
1522+
std::string tmp_o = outfile + ".tmp.o";
1523+
err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
1524+
lpython_pass_manager, compiler_options, time_report);
1525+
if (err != 0) return err;
1526+
err = link_executable({tmp_o}, outfile, runtime_library_dir,
1527+
backend, static_link, true, compiler_options);
1528+
if (err != 0) return err;
15461529
#else
15471530
std::cerr << "Compiling Python files to object files requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl;
15481531
return 1;
15491532
#endif
15501533
} else {
15511534
throw LFortran::LCompilersException("Unsupported backend.");
15521535
}
1553-
if (err) return err;
1554-
return link_executable({tmp_o}, outfile, runtime_library_dir,
1555-
backend, static_link, true, compiler_options);
1536+
1537+
if (compiler_options.arg_o == "") {
1538+
if (backend == Backend::wasm) {
1539+
err = system(("js " + outfile +".js").c_str());
1540+
} else {
1541+
err = system(("./" + outfile).c_str());
1542+
}
1543+
if (err != 0) {
1544+
if (0 < err && err < 256) {
1545+
return err;
1546+
} else {
1547+
return 1;
1548+
}
1549+
}
1550+
}
1551+
return 0;
15561552
} else {
15571553
return link_executable(arg_files, outfile, runtime_library_dir,
15581554
backend, static_link, true, compiler_options);

0 commit comments

Comments
 (0)