Commit Graph

32 Commits

Author SHA1 Message Date
acqn dc001cb4be Reverted E_ADDRESS_OF logic fix.
Added testcase.
2022-09-01 12:56:46 +08:00
Bob Andrews 6b0afe0834
Merge pull request #1785 from acqn/Effectless
[cc65] Avoid generating asm from C code that has no observable effects
2022-07-19 17:38:03 +02:00
acqn 6a3b9a9880 E_ADDRESS_OF logic fix. 2021-05-16 19:08:42 +08:00
acqn 7f05bd797f Now the compiler tracks code that has no observable effect. 2021-02-21 16:36:29 +08:00
acqn 2d96f79bc7 Added and used new utility type functions for bit-fields.
Fixed GetUnderlyingTypeCode() for bit-fields with widths > 16.
2021-12-01 09:45:17 +08:00
acqn 5adb29ce31 Made "bit-field-ness" a type property instead of a SymbolEntry or ExprDesc property.
Fixed integer promotion and result type in certain operations.
Fixed bit-fields 'op=' and postfix inc/dec operators.
2021-06-09 08:03:12 +02:00
acqn 6b64b43395 Made local static data use a separated label pool from the code label pool. 2020-08-31 09:12:03 +02:00
acqn 9398e1cd33 Use a dedicated label pool for literals. 2020-08-31 09:12:03 +02:00
acqn 504aee3835
Merge branch 'master' into StaticConst 2020-08-27 06:27:23 +08:00
acqn 43cb092a68 Fixed CHECK failures on certain usage of incomplete enums. 2020-08-26 22:14:51 +02:00
acqn 3ea3887c77 Fixed warnings on const comparison.
Warnings on expressions with no effects.
Fixed const ternary.
Fixed ternary with struct/union types as the true/false-branch expressions.
2020-08-20 07:52:06 +08:00
Jesse Rosenstock ff535b8e1a Treat signed int bit-fields as signed
Prior to this PR, `int`, `signed int`, and `unsigned int`
bitfields are all treated as `unsigned int`.

With this PR, `signed int` will be treated as `signed int`,
and the others remain unsigned.

Since `Type` does not distinguish between `int` and `signed int`,
add an extra `int* SignenessSpecified` param to `ParseTypeSpec`
so we can tell these apart for bit-fields and treat plain `int : N`
as `unsigned int : N` since it is more efficient to zero-extend
than sign-extend.

Fixes #1095
2020-08-18 12:23:20 +02:00
Jesse Rosenstock 55cebc7b9e Move bit-field adjustment to codegen.c
Extract functions g_testbitfield and g_extractbitfield from LoadExpr.

This helps prepare for #1192, since g_extractbitfield will get much
longer and call AddCodeLine.
2020-08-18 10:55:31 +02:00
Jesse Rosenstock d8f9201ecd LoadExpr: Optimize <= 8-bit bit-field loads
Set CF_FORCECHAR to do as many operations as char ops as possible.
Clear high byte at the end.
2020-08-05 12:49:46 +02:00
Jesse Rosenstock 0c72647edd Remove extra ED_TestDone call
Accidentally added in #1141.
2020-08-03 12:40:58 +02:00
Jesse Rosenstock adda28f5c5 LoadExpr: Set CF_FORCECHAR if test is required
If we are testing, we do not need to load the high byte(s).
2020-08-02 12:31:57 +02:00
Jesse Rosenstock 9c70bd44a6 Clarify comment about large shift
This is to avoid overflow on host platform.
2020-07-31 19:33:28 +02:00
Jesse Rosenstock 847982c6bf Handle bit-field test after shift/mask
Previously, bit-field tests were incorrectly combined with load in
`if (x.bitfield)`.  Delay the test until after the shift/mask
is done.  Still combine tests with load if no shift/mask is required.

Fixes #1139
2020-07-31 19:33:28 +02:00
Jesse Rosenstock 2d5fd0fc63 Use char ops if possible for bit-field loads
Set CF_FORCECHAR and change type to char once we have
shifted into a char.

This saves some unnecessary ldx #0 instructions.
2020-07-30 14:59:23 +02:00
acqn 9f67b45ea0 Fixed returning by value structs/unions <= 4 bytes in size from functions. Larger ones are forbidden for now. 2020-07-19 10:58:33 +02:00
acqn 2108489523 Fix for Issue #1075 and #1077. 2020-07-18 12:54:29 +02:00
Greg King 0390c34e88 Changed multi-line C comments into another style.
The left side doesn't look unbalanced.
2014-06-30 16:51:07 -04:00
Oliver Schmidt 4185caf855 Normalized code. 2014-03-04 01:11:19 +01:00
Oliver Schmidt 85885001b1 Removed (pretty inconsistently used) tab chars from source code base. 2013-05-09 13:57:12 +02:00
uz 66f1f82943 Masking a bit field is unnecessary if there was no shift operation or if the
shift operation shifted just zeroes into the value.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5412 b7a2c559-68d2-44c3-8de9-860c34a00d81
2012-01-20 15:54:43 +00:00
uz 96b46beee0 Fixed a problem with bit-fields: Values spanning more than a byte must always
be loaded as an int. This was not the case if the expression rhs was a char.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4382 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-10-20 08:21:12 +00:00
uz 7983009e06 Improved code for bit fields.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4097 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-08-31 15:11:32 +00:00
uz 6b4fe90928 First implementation of bit fields.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4079 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-08-29 21:20:13 +00:00
uz 37157a31a8 Fixed problems with R3977: While the solution was correct, the generated code
is bad, since information is lost when converting functions and arrays to
pointers and cannot be regained easily. So I've reverted the change and fixed
the problem in a less general manner.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3984 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-07-30 14:45:50 +00:00
uz 32348f5778 Fixed an error: If an expression is loaded into the primary, a function must
be converted to pointer-to-function and an array to pointer-to-member resp.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3977 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-07-28 18:56:16 +00:00
cuz d184d938fd Fixed a bug
git-svn-id: svn://svn.cc65.org/cc65/trunk@3117 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-06-10 08:48:02 +00:00
cuz 975323ece2 Renamed ExprLoad to LoadExpr.
Moved LoadExpr + support functions into a separate module.
Removed obsolete files.
Some cleanup and makefile adjustments.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3114 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-06-09 19:25:28 +00:00