Bug 866 - Pywriter Bug with Dropped Brackets when Converting Pseudo-Code
Summary: Pywriter Bug with Dropped Brackets when Converting Pseudo-Code
Status: CONFIRMED
Alias: None
Product: Libre-SOC's first SoC
Classification: Unclassified
Component: Source Code (show other bugs)
Version: unspecified
Hardware: PC Linux
: High enhancement
Assignee: Luke Kenneth Casson Leighton
URL:
Depends on:
Blocks:
 
Reported: 2022-06-22 15:13 BST by Andrey Miroshnikov
Modified: 2022-06-22 19:04 BST (History)
2 users (show)

See Also:
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:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ^