-
Notifications
You must be signed in to change notification settings - Fork 151
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
-dparsed
output produces invalid register updates with BSV
#662
Comments
As noted on issue 663, there are likely to be many bugs in the pretty-printing, but thank you again for reporting. This a problem caused by the fact that
But it would be preferable to print without the unnecessary double wrappers. This might suggest that the pretty-printing routines need to keep track of the context: the printing of In any case, it seems like an error for the pretty-printing of
If I remove the semicolon, it parses, oddly!
So maybe instead of Eliminating the extra level of wrapper might still be good to do, and removing the
One thing to do is to check whether it makes a difference to the testsuite. Specifically the One way to check would be to run a script on all .bsv files in the testsuite, to check whether the I do have access to the commit logs for BSC before going open source, so I'm able to see when those two lines for It also suggests another fix: In the same way that Although, actually, why is Anyway, that's a lot of rambling. Does any of that help? I guess I'm saying that I don't currently recall how all this works, without spending time reading the code, and I don't have time for that. But feel free to spend time on that and submit PRs if you'd like. And tests are important, and we lack them, so feel free to run a script over all the source files in the testsuite as a manual test; and feel free to add any particularly interesting or broken ones as a automatic test in the testsuite. And in particular, the Pong example in BSV may have been the guiding example for some of what you're seeing. The Pong example is in |
Thanks for the detailed explanation! For what it's worth, I found a workaround for this issue as a client who is generating code using the In short, it would be nice to fix this issue, but it's not as urgent for my needs as I originally thought it to be. |
Given this BSV code:
Compiling it with
bsc -dparsed=FooParsed.bsv Foo.bsv
yields:This is almost the same code, but there is one key difference: the
(v[idx] <= 0);
statement has surrounding parentheses. This change is significant enough to causebsc
to reject it:Removing the parentheses causes
bsc
to accept the code.The culprit is likely the
CSExpr _ e
case in this code:bsc/src/comp/CVPrint.hs
Lines 698 to 699 in f00d205
This causes the precedence to be
p+2
when pretty-printing the expressionv[idx] <= 0
, which is printed using this code:bsc/src/comp/CVPrint.hs
Line 572 in f00d205
Because the precedence is greater than
0
, this causes the overall expression to be parenthesized bypparen
.What is interesting is that there is a separate
CSExpr _ e@(Ccase _ _ _)
that callspvPrint
at precedencep
instead ofp+2
. It's unclear to me why this difference exists, but it is likely that if theCSExpr _ e
case changed its precedence top
, then this issue would be resolved. It's unclear to me if this would have ramifications when pretty-printing other forms ofCSExpr
s, however.The text was updated successfully, but these errors were encountered: