Bug 866

Summary: Pywriter Bug with Dropped Brackets when Converting Pseudo-Code
Product: Libre-SOC's first SoC Reporter: Andrey Miroshnikov <andy.miroshnikov>
Component: Source CodeAssignee: Luke Kenneth Casson Leighton <lkcl>
Status: CONFIRMED ---    
Severity: enhancement CC: libre-soc-bugs, programmerjake
Priority: High    
Version: unspecified   
Hardware: PC   
OS: Linux   
See Also: https://bugs.libre-soc.org/show_bug.cgi?id=865
NLnet milestone: NLNet.2019.10.031.Video total budget (EUR) for completion of task and all subtasks: 0
budget (EUR) for this task, excluding subtasks' budget: 0 parent task for budget allocation:
child tasks for budget allocation: The table of payments (in EUR) for this task; TOML format:

Description Andrey Miroshnikov 2022-06-22 15:13:29 BST
Currently there's a bug with the pseudo-code to Python function generator, where extra brackets are dropped. 
https://git.libre-soc.org/?p=openpower-isa.git;a=commitdiff;h=ef967c61da13d8c80ff5424fe43c35756928b145

This was noticed when adding the pseudo-code for the "cprop" instruction, and a temp variable was added to circumvent this issue:
https://git.libre-soc.org/?p=openpower-isa.git;a=commitdiff;h=a87e45f65c3e2e93fb6234c1ae7b65bd9dab60b3
Comment 1 Andrey Miroshnikov 2022-06-22 15:18:51 BST
Adding IRC log conversation:
https://libre-soc.org/irclog/%23libre-soc.2022-06-22.log.html#t2022-06-22T14:45:32
Comment 2 Luke Kenneth Casson Leighton 2022-06-22 15:29:23 BST
binary operator precedence error.
unfortunately the fix of adding explicit brackets interferes
with the detection of patterns "[0]*4" which is Power ISA
pseudocode for "0b0000"
Comment 3 Jacob Lifshay 2022-06-22 19:04:26 BST
note that python operator precedence causes `(P | G) + G ^ P` to be correctly parsed as `((P | G) + G) ^ P`, so imho if that order of operations matches what pywriter wanted to generate, missing parenthesis is not a problem for the python interpreter (though imho it is a problem for readability -- but it's generated code so doesn't necessarily need to be read very often)
https://docs.python.org/3/reference/expressions.html#operator-precedence
+ is higher precedence than ^