GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added option to pass custom C postprocessor by czgdp1807 · Pull Request #1331 · lcompilers/lpython

Added option to pass custom C postprocessor #1331

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.

Sign up for GitHub

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

Closed
czgdp1807 wants to merge 2 commits into lcompilers:main from czgdp1807:post_process

Uh oh!

There was an error while loading. Please reload this page.

Closed

Added option to pass custom C postprocessor #1331

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
3c47c14
done
czgdp1807 Nov 29, 2022
004a1af
Write to a file if -o provided --show-c option
czgdp1807 Dec 5, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Write to a file if -o provided --show-c option
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@czgdp1807
czgdp1807 committed Dec 5, 2022
commit 004a1af901078e7ebe324ca9bd0db441afba074a

There are no files selected for viewing

6 changes: 6 additions & 0 deletions 6 .gitignore
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,9 @@ integration_tests/array_02_decl.c
integration_tests/expr_12
integration_tests/expr_12.c
integration_tests/expr_07_generated.c
integration_tests/expr_07.c
expr_07.c
tests/c_interop1.c
tests/expr7.c
tests/loop1.c
tests/loop2.c
4 changes: 2 additions & 2 deletions 4 integration_tests/CMakeLists.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ macro(RUN)
add_custom_command(
OUTPUT ${name}.c
COMMAND lpython --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
--custom-c-postprocessor ${CMAKE_CURRENT_SOURCE_DIR}/${custom_c_postprocessor} > ${name}.c
--custom-c-postprocessor ${CMAKE_CURRENT_SOURCE_DIR}/${custom_c_postprocessor} -o ${name}.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
VERBATIM)
else ()
add_custom_command(
OUTPUT ${name}.c
COMMAND lpython --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py > ${name}.c
COMMAND lpython --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py -o ${name}.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
VERBATIM)
endif()
Expand Down
8 changes: 6 additions & 2 deletions 8 integration_tests/test_c_custom_postprocessor.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

filename = sys.argv[1]

f = open(filename).read()
file = open(filename, "r")
f = file.read()
file.close()

open(filename, "w").write(f)
file = open(filename, "w")
file.write(f)
file.close()
33 changes: 23 additions & 10 deletions 33 src/bin/lpython.cpp
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,34 @@ int emit_c(const std::string &infile,
LFORTRAN_ASSERT(diagnostics.has_error())
return 3;
}

std::string output_file;
bool print_to_std = true;
if( !compiler_options.arg_o.empty() ) {
output_file = compiler_options.arg_o;
print_to_std = false;
} else {
output_file = remove_extension(infile) + ".c";
}
std::string ccode_file = output_file;
std::ofstream ccode_out(ccode_file);
ccode_out << res.result;
ccode_out.close();
if( !compiler_options.c_postprocessor_script.empty() ) {
std::string ccode_file = remove_extension(infile) + "_generated.c";
std::ofstream ccode_out(ccode_file);
ccode_out << res.result;
std::string command = "python " + compiler_options.c_postprocessor_script + " " + ccode_file;
system(command.c_str());
ccode_out.close();
std::ifstream ccode_in(ccode_file);
std::string modified_result = "";
while( std::getline(ccode_in, modified_result) ) {
std::cout << modified_result << "\n";
if( print_to_std ) {
std::ifstream ccode_in(ccode_file);
std::string modified_result = "";
while( std::getline(ccode_in, modified_result) ) {
std::cout << modified_result << "\n";
}
ccode_in.close();
}
ccode_in.close();
} else {
std::cout << res.result;
if( print_to_std ) {
std::cout << res.result;
}
}
return 0;
}
Expand Down
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.