@@ -927,16 +927,6 @@ int link_executable(const std::vector<std::string> &infiles,
927
927
std::cout << " The command '" + cmd + " ' failed." << std::endl;
928
928
return 10 ;
929
929
}
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
- }
940
930
} else {
941
931
std::string CC = " cc" ;
942
932
char *env_CC = std::getenv (" LFORTRAN_CC" );
@@ -962,16 +952,6 @@ int link_executable(const std::vector<std::string> &infiles,
962
952
std::cout << " The command '" + cmd + " ' failed." << std::endl;
963
953
return 10 ;
964
954
}
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
- }
975
955
}
976
956
return 0 ;
977
957
} else if (backend == Backend::cpp) {
@@ -1527,32 +1507,48 @@ int main(int argc, char *argv[])
1527
1507
1528
1508
if (endswith (arg_file, " .py" ))
1529
1509
{
1510
+ int err = 0 ;
1530
1511
if (backend == Backend::x86) {
1531
- return compile_to_binary_x86 (arg_file, outfile,
1512
+ err = compile_to_binary_x86 (arg_file, outfile,
1532
1513
runtime_library_dir, compiler_options, time_report);
1533
1514
} else if (backend == Backend::wasm) {
1534
- return compile_to_binary_wasm (arg_file, outfile,
1515
+ err = compile_to_binary_wasm (arg_file, outfile,
1535
1516
runtime_library_dir, compiler_options, time_report);
1536
1517
} 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,
1538
1519
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) {
1544
1521
#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;
1546
1529
#else
1547
1530
std::cerr << " Compiling Python files to object files requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl;
1548
1531
return 1 ;
1549
1532
#endif
1550
1533
} else {
1551
1534
throw LFortran::LCompilersException (" Unsupported backend." );
1552
1535
}
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 ;
1556
1552
} else {
1557
1553
return link_executable (arg_files, outfile, runtime_library_dir,
1558
1554
backend, static_link, true , compiler_options);
0 commit comments