-
Notifications
You must be signed in to change notification settings - Fork 226
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
Proposal: enhance handling of conditional preprocessor directives #241
Comments
Actually, I realize now your parser is smart enough to handle conditionals in the header, just not right before a comma, so that's a separate issue. I think the proposal would still be useful, though, for cases like the always block. Thanks, |
Yes, I've considered the pseudo-preprocessing approaches you described of presenting various preprocessing filtered views, and forwarding those to subsequent parsing and processing. Some early thoughts here: Possible strategies include:
It's currently a low priority and a help-wanted area. But I agree it would multiply the potential outreach of the Verible toolset., |
Currently, the formatter doesn't handle many scenarios involving preprocessor `ifdef`s/`endif`s interleaved with `begin`s, module headers, etc. (chipsalliance#228, chipsalliance#241, chipsalliance#267) This patch attempts to solve this problem by performing multiple passes of the formatting on preprocessed variants of the source. Each of these variants has a different set of preprocessor branches enabled. Together, they should cover the entire source (though that doesn't work in all cases yet). After several formatting passes for different variants of the AST, a correct and properly formatted file is produced. This is still work in progress. Hoping to get some early feedback on this. Signed-off-by: Krzysztof Bieganski <[email protected]>
Currently, the formatter doesn't handle many scenarios involving preprocessor `ifdef`s/`endif`s interleaved with `begin`s, module headers, etc. (chipsalliance#228, chipsalliance#241, chipsalliance#267) This patch attempts to solve this problem by performing multiple passes of the formatting on preprocessed variants of the source. Each of these variants has a different set of preprocessor branches enabled. Together, they should cover the entire source (though that doesn't work in all cases yet). After several formatting passes for different variants of the AST, a correct and properly formatted file is produced. This is still work in progress, so not everything works, and the code isn't very clean. I'd love to get some early feedback on this. Signed-off-by: Krzysztof Bieganski <[email protected]>
Currently, the formatter doesn't handle many scenarios involving preprocessor `ifdef`s/`endif`s interleaved with `begin`s, module headers, etc. (chipsalliance#228, chipsalliance#241, chipsalliance#267) This patch attempts to solve this problem by performing multiple passes of the formatting on preprocessed variants of the source. Each of these variants has a different set of preprocessor branches enabled. Together, they should cover the entire source (though that doesn't work in all cases yet). After several formatting passes for different variants of the AST, a correct and properly formatted file is produced. This is still work in progress, so not everything works, and the code isn't very clean. I'd love to get some early feedback on this. Signed-off-by: Krzysztof Bieganski <[email protected]>
Currently, the formatter doesn't handle many scenarios involving preprocessor `ifdef`s/`endif`s interleaved with `begin`s, module headers, etc. (chipsalliance#228, chipsalliance#241, chipsalliance#267) This patch attempts to solve this problem by performing multiple passes of the formatting on preprocessed variants of the source. Each of these variants has a different set of preprocessor branches enabled. Together, they should cover the entire source (though that doesn't work in all cases yet). After several formatting passes for different variants of the AST, a correct and properly formatted file is produced. This is still work in progress, so not everything works, and the code isn't very clean. I'd love to get some early feedback on this. Signed-off-by: Krzysztof Bieganski <[email protected]>
Currently, the formatter doesn't handle many scenarios involving preprocessor `ifdef`s/`endif`s interleaved with `begin`s, module headers, etc. (chipsalliance#228, chipsalliance#241, chipsalliance#267) This patch attempts to solve this problem by performing multiple passes of the formatting on preprocessed variants of the source. Each of these variants has a different set of preprocessor branches enabled. Together, they should cover the entire source (though that doesn't work in all cases yet). After several formatting passes for different variants of the AST, a correct and properly formatted file is produced. This is still work in progress, so not everything works, and the code isn't very clean. I'd love to get some early feedback on this. Signed-off-by: Krzysztof Bieganski <[email protected]>
Currently, the formatter doesn't handle many scenarios involving preprocessor `ifdef`s/`endif`s interleaved with `begin`s, module headers, etc. (chipsalliance#228, chipsalliance#241, chipsalliance#267) This patch attempts to solve this problem by performing multiple passes of the formatting on preprocessed variants of the source. Each of these variants has a different set of preprocessor branches enabled. Together, they should cover the entire source (though that doesn't work in all cases yet). After several formatting passes for different variants of the AST, a correct and properly formatted file is produced. This is still work in progress, so not everything works, and the code isn't very clean. I'd love to get some early feedback on this. Signed-off-by: Krzysztof Bieganski <[email protected]>
Thanks for making this available! It looks immensely useful.
I am faced with a lot of verilog that verible cannot process due to syntax errors, similar to issue #228.
For example:
I think you'll find a lot of this sort of thing in real-world codebases.
I haven't read through the codebase or anything (and my C++ is quite rusty anyway), but taking into account the description that the lexer and parser are decoupled, and after reading through the discussion on #228 and thinking about it a bit, I have a proposal that should be much easier to implement than a full preprocessor.
This would probably have to be implemented as a user-configurable option; for reasons that will become clear, badly-constructed modules could result in an exponential blow-up of processing time and the output.
Whenever an
`ifxxx
or`else
is encountered in a context where the parser cannot process it, rewrite the token stream to push the preprocessor directive up and outside the context where it is invalid, add an`else
if necessary, and duplicate the non-conditional tokens. For example, the above module could be represented by something like this:and, of course, the code in issue #128 would simply be represented as two always blocks on different branches of the
`ifdef/`else/`endif
The text was updated successfully, but these errors were encountered: