-
Notifications
You must be signed in to change notification settings - Fork 219
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
[WIP][Discussion] Standalone preprocessor tool design #1358
Comments
These parameters look good to me. @hzeller @fangism please comment if you have some additional ideas. One thing that we should consider early on is how to handle conditionals in the code, here are some notes from my discussion with @mglb Consider following code:
To parse this into a tree, Verible could preprocess the code and generate two sources: one for condition being true, one for condition being false. Both sources would be parsed into alternate trees. The trees would be then merged to share common branches. Alternate branches would be wrapped in a dedicated node. What is needed
Note that the integration with linter and formatter can be done at a later step, but we have to keep in mind that this is the ultimate goal so we have to think about how to make that as easy as possible with the implementation we're doing |
And in general, the standalone tool should take raw systemverilog sources as input and ouput preprocessed code (only one branch of the conditional code based on the defines, macros should be resolved etc). I suggest we start working on this one by one, e.g: pick the first feature you want to work on - I think conditionals are a great candidate - scan the tree for all conditional statements, create the trees as suggested above (or suggest an alternative solution), as the last step, look up all the defines (you can start with defines provided from the commandline and store info from |
Hello All, I am currently working on conditionals feature in the standalone tool PR #1360, I am facing a problem, and would like to know what you think about my solution before implementing it. Problem: Using this method allows the tool to correctly choose the matching branch if a conditional is encountered, however it makes it hard to preserve the original white-space characters to output the SV source code as it was before preprocessing. This problem will be even harder when Solution:
Do you have any suggestions? Thanks |
Hello! |
I added a new command for the tool Example: `define BAZ 1
`define MAZ 1
`ifdef BAZ
module foo(); endmodule
`ifdef MAZ
module moo(); endmodule
`else
module not_moo(); endmodule
`endif
module foo2(); endmodule
`else
module not_foo(); endmodule
`endif
module m(); endmodule Output:
These variants are ready to be passed to the parser without any needed modification. Thanks, |
Sorry, I didn't understand your idea, can you elaborate more? Thanks |
Between any two tokens A, B that belong to the same memory buffer (which is true in Verible), you can construct a https://en.cppreference.com/w/cpp/string/basic_string_view/basic_string_view It appears the two-iterator range constructor isn't available until C++20, so something like this will work: // assuming A is before B in the same memory buffer
absl::string_view text_between_A_and_B(A.end(), std::distance(A.end(), B.begin())); |
The range between tokens can contain preprocessor directives and inactive code, so it can't be used in all cases. ····module foo(); endmodule/*1*/
`ifdef MAZ
····module moo(); endmodule
`endif
····/*2*/module foo2(); endmodule For a variant where
Do you mean you want to add a new token type (
I'm not sure I understand how would it work. Could you elaborate? |
Hello @mglb, Thanks for your feedback!
I meant the latter, and yes It's a lot of work.
I meant to have a loop with 2 pointers (initially pointing to the beginning of both streams), let's assume: The idea was to:
This is okay just when the non white-space tokens remain unchanged in both streams, but in case of an expanded macros, It might be a challenge. |
BTW, for finding some interesting examples and 'good to evil' uses of the verilog preprocessor, always good to have a look at Wilson's paper https://veripool.org/papers/Preproc_Good_Evil_SNUGBos10_paper.pdf |
I read it when I was getting to know the project, didn't benefit from it a lot then. |
Standalone Preprocessor Tool Design
Introduction
The goal of this thread is to discuss and put the outlines of the standalone preprocessor tool.
The preprocessor tool should fully support the directives described in 2018 SV-LRM, and provide APIs that can be easily used by other Verible tools.
This proposal is a continuation on the already built pseudo-preprocessing tool.
Flags description
Using the Abseil flags library allows an easy access to flags and their arguments.
Positional arguments
Those mainly are the SV files to preprocess, defines and search-directory paths for includes.
Any of the following positional argument can be passed one or more times.
`define foo text
`include "file_name"
(IN-PROGRESS)
The text was updated successfully, but these errors were encountered: