-
Notifications
You must be signed in to change notification settings - Fork 17
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
Verilog preprocessor: implement multi-line defines #77
Merged
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 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CORE | ||
multi-line-define1.v | ||
--preprocess | ||
// Enable multi-line checking | ||
activate-multi-line-match | ||
`line 1 "multi-line-define1.v" 0 | ||
|
||
A | ||
B | ||
C | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^PREPROCESSING FAILED$ |
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`define foo A \ | ||
B \ | ||
C | ||
`foo |
This file contains 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 |
---|---|---|
|
@@ -362,13 +362,23 @@ void verilog_preprocessort::directive() | |
// skip whitespace | ||
tokenizer().skip_ws(); | ||
|
||
// Read any tokens until end of line. | ||
// Read any tokens until end of line, | ||
// but note that \n can be escaped with a backslash. | ||
// Note that any defines in this sequence | ||
// are not expanded at this point. | ||
while(!tokenizer().eof() && tokenizer().peek() != '\n') | ||
{ | ||
auto token = tokenizer().next_token(); | ||
define.tokens.push_back(std::move(token)); | ||
if(token == '\\' && tokenizer().peek() == '\n') | ||
{ | ||
// Eat the newline, which is escaped. | ||
// Not clear whether the newline is meant to show | ||
// in the expansion. | ||
auto nl = tokenizer().next_token(); | ||
define.tokens.push_back(std::move(nl)); | ||
} | ||
else | ||
define.tokens.push_back(std::move(token)); | ||
Comment on lines
+377
to
+381
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. Probably a matter of taste:
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. Indeed a matter of taste; I do feel that the longer version is quicker to understand. |
||
} | ||
|
||
#ifdef DEBUG | ||
|
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.
Shouldn't
verilog_preprocessor_token_sourcet::skip_until_eol
also learn about this?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.
Unfortunately the standard is very unclear under which circumstances this is supposed to happen. I'll need to experiment with some standard tools.
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.
If this is global, it might be preferable to move the escaping into the flex tokenizer.
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.
Yes, it might need to move into the tokenizer.
https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/VL____LEX-STRINGS