-
Notifications
You must be signed in to change notification settings - Fork 171
Run the executable if no error #1302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Thirumalai-Shaktivel
merged 1 commit into
lcompilers:main
from
Thirumalai-Shaktivel:auto_run
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -927,16 +927,6 @@ int link_executable(const std::vector<std::string> &infiles, | |||||||||||||||||||||||||||||||||
std::cout << "The command '" + cmd + "' failed." << std::endl; | ||||||||||||||||||||||||||||||||||
return 10; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (compiler_options.arg_o == "") { | ||||||||||||||||||||||||||||||||||
err = system(outfile.c_str()); | ||||||||||||||||||||||||||||||||||
if (err != 0) { | ||||||||||||||||||||||||||||||||||
if (0 < err && err < 256) { | ||||||||||||||||||||||||||||||||||
return err; | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
return 1; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
std::string CC = "cc"; | ||||||||||||||||||||||||||||||||||
char *env_CC = std::getenv("LFORTRAN_CC"); | ||||||||||||||||||||||||||||||||||
|
@@ -962,16 +952,6 @@ int link_executable(const std::vector<std::string> &infiles, | |||||||||||||||||||||||||||||||||
std::cout << "The command '" + cmd + "' failed." << std::endl; | ||||||||||||||||||||||||||||||||||
return 10; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (compiler_options.arg_o == "") { | ||||||||||||||||||||||||||||||||||
err = system(("./" + outfile).c_str()); | ||||||||||||||||||||||||||||||||||
if (err != 0) { | ||||||||||||||||||||||||||||||||||
if (0 < err && err < 256) { | ||||||||||||||||||||||||||||||||||
return err; | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
return 1; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return 0; | ||||||||||||||||||||||||||||||||||
} else if (backend == Backend::cpp) { | ||||||||||||||||||||||||||||||||||
|
@@ -1527,32 +1507,48 @@ int main(int argc, char *argv[]) | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (endswith(arg_file, ".py")) | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
int err = 0; | ||||||||||||||||||||||||||||||||||
if (backend == Backend::x86) { | ||||||||||||||||||||||||||||||||||
return compile_to_binary_x86(arg_file, outfile, | ||||||||||||||||||||||||||||||||||
err = compile_to_binary_x86(arg_file, outfile, | ||||||||||||||||||||||||||||||||||
runtime_library_dir, compiler_options, time_report); | ||||||||||||||||||||||||||||||||||
} else if (backend == Backend::wasm) { | ||||||||||||||||||||||||||||||||||
return compile_to_binary_wasm(arg_file, outfile, | ||||||||||||||||||||||||||||||||||
err = compile_to_binary_wasm(arg_file, outfile, | ||||||||||||||||||||||||||||||||||
runtime_library_dir, compiler_options, time_report); | ||||||||||||||||||||||||||||||||||
} else if (backend == Backend::wasm_x86) { | ||||||||||||||||||||||||||||||||||
return compile_to_binary_wasm_to_x86(arg_file, outfile, | ||||||||||||||||||||||||||||||||||
err = compile_to_binary_wasm_to_x86(arg_file, outfile, | ||||||||||||||||||||||||||||||||||
runtime_library_dir, compiler_options, time_report); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
std::string tmp_o = outfile + ".tmp.o"; | ||||||||||||||||||||||||||||||||||
int err; | ||||||||||||||||||||||||||||||||||
if (backend == Backend::llvm) { | ||||||||||||||||||||||||||||||||||
} else if (backend == Backend::llvm) { | ||||||||||||||||||||||||||||||||||
#ifdef HAVE_LFORTRAN_LLVM | ||||||||||||||||||||||||||||||||||
err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, lpython_pass_manager, compiler_options, time_report); | ||||||||||||||||||||||||||||||||||
std::string tmp_o = outfile + ".tmp.o"; | ||||||||||||||||||||||||||||||||||
err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, | ||||||||||||||||||||||||||||||||||
lpython_pass_manager, compiler_options, time_report); | ||||||||||||||||||||||||||||||||||
if (err != 0) return err; | ||||||||||||||||||||||||||||||||||
err = link_executable({tmp_o}, outfile, runtime_library_dir, | ||||||||||||||||||||||||||||||||||
backend, static_link, true, compiler_options); | ||||||||||||||||||||||||||||||||||
if (err != 0) return err; | ||||||||||||||||||||||||||||||||||
#else | ||||||||||||||||||||||||||||||||||
std::cerr << "Compiling Python files to object files requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl; | ||||||||||||||||||||||||||||||||||
return 1; | ||||||||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
throw LFortran::LCompilersException("Unsupported backend."); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (err) return err; | ||||||||||||||||||||||||||||||||||
return link_executable({tmp_o}, outfile, runtime_library_dir, | ||||||||||||||||||||||||||||||||||
backend, static_link, true, compiler_options); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (compiler_options.arg_o == "") { | ||||||||||||||||||||||||||||||||||
if (backend == Backend::wasm) { | ||||||||||||||||||||||||||||||||||
err = system(("js " + outfile +".js").c_str()); | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
err = system(("./" + outfile).c_str()); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (err != 0) { | ||||||||||||||||||||||||||||||||||
if (0 < err && err < 256) { | ||||||||||||||||||||||||||||||||||
return err; | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
return 1; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
+1543
to
+1549
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a separate topic: def test():
quit(10)
test() $ lpython a.py
err = 2560
STOP
$ echo $?
1 So, I thought to replace this with the following change:
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return 0; | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
return link_executable(arg_files, outfile, runtime_library_dir, | ||||||||||||||||||||||||||||||||||
backend, static_link, true, compiler_options); | ||||||||||||||||||||||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shaikh-Ubaid, the Wasm Backend executable can be executed using
js filename.out.js
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be executed using
node a.out.js
(wherea.out
anda.out.js
are the output files generated).I am unsure if we need auto-execution for
wasm
backend (or other backends excludingllvm
). It seems that when a user specifies a particular backend (apart fromllvm
, for example, let's say--backend=wasm
), the (primary) intention of the user is to generate target backend code from the source code. Thus, if a user executeslpython examples/expr2.py --backend wasm
, he's trying to generatewasm
code from the source code. He could later choose to use the generatedwasm
code for his own purposes or choose to execute it.I think it would be better if we leave the choice of what should be done with the output code (
wasm
code in our example) onto the user. One added advantage of leaving the choice with the user is that the user would get to know what all files are generated using a particular backend (wasm
backend generates two filesa.out
anda.out.js
). The user also gets the opportunity to explore how the generated target (wasm
) code could be executed.I am just sharing my thoughts here. Anything is-fine/works for me.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czgdp1807 @certik Can you please share your thoughts as well?
I made these changes because I felt like the behaviour should be consistent on all the backends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. I guess
--show-wasm
should generate the code?Overall I guess at least the executable shouldn't be deleted after automatic execution. For now for LLVM backend it gets deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this PR changes got merged. LPython doesn't generate
a.out
anymore. Instead, it generatesfilename.out
. These changes were made because of some problems in testing the runtime outputs, see here for more details. Also, to stop the automatic execution one can use the-o
option to specify the executable to be written into.I apologize for not sharing this updated information.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion either way on this. I feel calling "node" from LPython seems fragile.
I think for now, why don't we do the following:
lpython a.py
compilesa.py
with the default backend (currently LLVM, perhaps in the future it will be WASM + x86/arm) and runs itlpython
, then it will not run it by default.Although I can see how this is not super consistent. But it gets us started. I think the most common use case is
python a.py
, so we now already havelpython a.py
. Everything else seems lower priority.We could also consider
lpython run a.py
orlpython --run a.py
, and then you can supply other options as needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean
lpython --run a.py --backend x86
to run by default?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
lpython a.py --backend x86 && ./a.out
is much familiar than using--run
. So, Let's only supportlpython a.py
to run by default.Also, I have a doubt: Currently, we write the executable to
filename.out
. Is this fine for other backend as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me.