Skip to content

Conversation

HPCguy
Copy link
Contributor

@HPCguy HPCguy commented Nov 24, 2022

Without the fix on this branch,
the following code currently
adds 2 to the je ptr, instead of 8.

int *je = 0;
int n = 2;
je += n;

Without the fix on this branch,
the following code currently
adds 2 to the je ptr, instead of 8.

int *je = 0;
int n = 2;
je += n;
*--n=';'; *--n = t; *--n = Load;
if (tk < ShlAssign) tk = Or + (tk - OrAssign);
else tk = Shl + (tk - ShlAssign);
tk |= REENTRANT; compound = 1; expr(Assign);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if compound-op bypasses literal const optimizations still make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old way was taking shortcuts while this technique is a "full parse" using the full standard AST rules. It is "complete" while the old way skipped steps. scripts/disasm can be used to look at the assembly code, so that you can verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int main()
{
int *je = 0;
je += 4 - 2;
return 0;
}
% amacc -si test.c
ENT 1
// int *je = 0
LEA je (-1)
PSH
IMM 0
SI
// je += 4 - 2
LEA je (-1)
PSH
LI
PSH
IMM 8 // 2 * sizeof (int)
ADD
SI

Copy link
Contributor Author

@HPCguy HPCguy Nov 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int main()
{
int n = 5;
n *= 4 - 2; // should be n = n * (4 - 2), not n = (n * 4) -2
return 0;
}
% amacc -si test.c
ENT 1
LEA n (-1)
PSH
IMM 5
SI
// n *= 4 - 2;
LEA n (-1)
PSH
LI
PSH
IMM 2 // correct!
MUL // correct!
SI

@jserv jserv merged commit 049302a into jserv:master Nov 25, 2022
@jserv
Copy link
Owner

jserv commented Nov 25, 2022

Thank @HPCguy for the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants