1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-03 22:29:31 +00:00
Commit Graph

3575 Commits

Author SHA1 Message Date
acqn
71bd6415d6 No more unnecessary jump-over labels generated for logical OR false cases. 2021-04-24 23:53:26 +02:00
Oliver Schmidt
5d84a4ba13 Removed non-ASCII chars. 2021-04-19 16:06:10 +02:00
Oliver Schmidt
f272bc8f42 Removed non-ASCII chars. 2021-04-19 15:50:52 +02:00
Marco Aurelio da Costa
fd3d5d35fb mc: Implemented .LITERAL 2021-04-19 15:42:29 +02:00
acqn
f901adba22 Predefined type strings for inlined std function parameters. 2021-04-19 15:36:55 +02:00
acqn
9cea9ce5e2 Made the code more constness-correct with 'Type' usage. 2021-04-19 15:36:55 +02:00
acqn
cb64aaf20c Made the code more constness-correct with 'Type' usage for inlined std functions. 2021-04-19 15:36:55 +02:00
acqn
328345b9c3 Removed a helper function that is no longer used. 2021-04-19 15:36:55 +02:00
acqn
24d36854d2 Minor cleanups with array element qualifiers. 2021-04-19 15:36:55 +02:00
acqn
896f463a23 Used more specific pointers instead of the "arbitary attribute pointer" used in type strings. 2021-04-19 15:36:55 +02:00
acqn
bfb7c936aa Preparation for constness-correction. 2021-04-19 15:36:55 +02:00
Evgeny Vrublevsky
ac08482fa3 Allow editing cc65.props from Property Manager. 2021-04-18 21:12:51 +02:00
Evgeny Vrublevsky
ee8c7b47bc Add new lines at the end of the project files. 2021-04-18 21:12:51 +02:00
Evgeny Vrublevsky
7be3b53f72 cc65.props uses spaces instead of tabs. 2021-04-18 21:12:51 +02:00
Evgeny Vrublevsky
2120dd662c Move all common project settings into cc65.props. 2021-04-18 21:12:51 +02:00
Marco Aurelio da Costa
83ee928fb1 mc: Formatting, remove stray lines 2021-04-18 20:39:05 +02:00
Marco Aurelio da Costa
c915b5d7f3 Implemented charmap stack
New commands:
 .PUSHCHARMAP: will push the current charmap state into an internal stack
 .POPCHARMAP: will restore the current charmap to the last pushed charmap

Details:
  The push and pop facilities are implemented directly inside the tgttrans.h,
  to facilitate its reuse on the C compiler.
2021-04-18 20:39:05 +02:00
acqn
6e61093e79 Fixed pointer subtraction in certain very rare cases. 2021-04-17 11:14:37 +02:00
acqn
e9545d68ee Minor clean-ups and typo fixes. 2021-04-17 11:43:03 +08:00
Dirk Lehmann
eb1cf750f2 -W-unreachable-code option added, alphabetic order of --list-warnings 2021-04-13 09:37:55 +02:00
acqn
e435da6234 Interim fix for Issue #897. 2021-04-06 22:20:39 +02:00
acqn
bd8eae67f1 Fixed local struct field access via the address of the struct. 2021-04-05 15:49:54 +02:00
acqn
1a3628df1a Fixed the term 'argument' vs 'parameter' in function parser. 2021-04-03 17:50:46 +02:00
acqn
2864b3ef8a Fixed composition of prototypes and old-style function definitions with default promotions.
Fixed function parameter list comparison with empty ones.
2021-04-03 17:50:46 +02:00
acqn
91fd30611a Fixed ICE on error cases such as '&func + int a'. 2021-04-03 17:45:52 +02:00
acqn
4a38965384 Warnings on discarding pointer qualifiers always.
Added new -W options to turn on/off warnings on certain pointer conversion cases:
- pointer-sign: to a pointer type differing in pointee signedness. Default on.
- pointer-types: to a pointer type incompatible. Default on.
2021-03-30 19:41:20 +02:00
acqn
b802efde54 Fixed ternary result type detection with pointer types.
Fixed pointer type comparison and conversion, especially regarding qualifiers.
Improved diagnostics about type comparison and conversion.
Reorganized some type-comparison/conversion functions.
2021-03-30 19:41:20 +02:00
acqn
f9812930c1 More detailed diagnostic info about conflicted function types. 2021-03-30 16:47:57 +08:00
acqn
cb8fbf4772 Removed the non-existing-in-C "struct/union scope" for structs/unions.
Fixed handling of struct/union field declarations without identifiers, which do nothing.
2021-03-29 19:28:22 +02:00
acqn
f273b1ebcb Fixed crash with non-inlined __fastcall__ function invocation with no arguments. 2021-03-26 11:02:46 +08:00
acqn
3755e4a863 Replaced checking for __fastcall__ aginst AutoCDecl etc. with IsFastcallFunc(). 2021-03-24 14:35:44 +08:00
acqn
3c2e7ce41c More reliable test for true/false with addresses for AND, OR and ternary operators.
Minor comment typo fix.
2021-03-20 01:39:32 +01:00
acqn
f8835d2867 Fixed codegen with addresses as boolean test conditions.
Fixed warning on unreachable code of if body.
2021-03-20 01:39:32 +01:00
acqn
325b7b4ab3 Enabled 'a ? b, c : d'. 2021-03-20 00:09:47 +01:00
acqn
a51d6d40de Ternary fix for some obscure cases. 2021-03-20 00:09:47 +01:00
acqn
6974c1ff12 Fixed and cleaned up codegen logic with arithmetic conversion in addition and subtraction. 2021-03-19 16:35:03 +01:00
Christian Groessler
cd116e5ba0 src/ar65/library.c: style fix 2021-03-18 22:27:42 +01:00
Christian Groessler
9b05fe9982 src/ar65/library.c: fix compilation on Windows 2021-03-18 22:27:42 +01:00
Christian Groessler
358d750b3e ar65: fix parallel builds by using a per-process temp file 2021-03-18 22:27:42 +01:00
Christian Groessler
64449f0f54 ar65: better version of last change 2021-03-18 22:27:42 +01:00
Christian Groessler
d3c495e8b9 ar65: fix parallel builds by using a per-process temp file 2021-03-18 22:27:42 +01:00
acqn
b02838439c Changed g_addaddr_local() codegen to reduce code size. 2021-03-16 22:29:20 +01:00
acqn
8eeaaa3f36 Made certain types of comparison between addresses in constant expressions work. 2021-03-16 22:29:20 +01:00
acqn
99c7fe0ada Reusing code from parseadd() for ArrayRef().
Now index[ptr] works in constant expressions.
Fixed codegen for cast type in constant expressions.
Calls on swapstk in 'i[ptr]' is avoided when possible.
2021-03-16 22:29:20 +01:00
acqn
f5972dfd08 Made int+pointer work in constant expressions.
Fixed codegen for cast type addition in constant expressions.
Calls on swapstk in 'i+ptr' is avoided when possible.
2021-03-16 22:29:20 +01:00
acqn
aa6fdf58b8 Addresses in constant subtraction expressions now work.
Fixed codegen for cast type subtraction in constant expressions.
2021-03-16 22:29:20 +01:00
acqn
c4a2620e29 Added an utility function to check for quasi-constant addresses (of stack variables). 2021-03-16 22:29:20 +01:00
acqn
0a8ca3041a Changd all Find*Last*InOpenRange() to return the beginning of the open range.
Fixed FindArgLastUsageInOpenRange().
2021-03-16 22:24:19 +01:00
acqn
4376b83390 Fixed LoadAAt(). 2021-03-16 22:24:19 +01:00
acqn
bd5d5b7385 Removed the prototype of evalexpr() that no longer exists. 2021-03-16 22:24:19 +01:00
acqn
047d0f479b Comments format fix. 2021-03-03 10:07:24 +01:00
acqn
2aad72af90 Removed trailing whitespaces. 2021-03-03 10:07:24 +01:00
acqn
3caceb8174 Fixed result type in certain contant expression addition cases. 2021-02-26 19:45:46 +01:00
acqn
f2eed38fc8 Fixed expression type of the result of numeric constant comparison. 2021-02-26 19:45:46 +01:00
acqn
ea0c634e12 Improved codegen for unsigned char type comparison with numeric constants. 2021-02-23 22:06:21 +01:00
acqn
d628772cd1 Fixed signed char type comparison with unsigned numeric constants. 2021-02-23 22:06:21 +01:00
acqn
f1c715c455 Fixed a bug that pointer subtraction results from two absolute addresses are calculated as unsigned long. 2021-02-22 14:14:59 -05:00
acqn
81d6321cd7 Fixed internal representation of calculated constant results.
Minor clean-up.
2021-02-22 14:14:59 -05:00
acqn
eadaf2fef8 Fixed deferred post-inc and post-dec in unevaluated context such as 'sizeof(i++)'. 2021-02-22 11:02:47 +01:00
acqn
40b26f4060 Now the compiler removes code that has no observable effect. 2021-02-22 13:47:32 +08:00
acqn
7f05bd797f Now the compiler tracks code that has no observable effect. 2021-02-21 16:36:29 +08:00
acqn
55ae350fed Fixed 'Opt_staxspidx' for the invariant of 'staxspidx'. 2021-02-17 07:03:11 -05:00
acqn
bfc7a51a44 Fixed Issue #1265 according to C89/C99 standards. 2021-01-30 14:31:51 +01:00
acqn
c9ac515286 Functions with no prototypes might use EAX registers. 2021-01-30 14:31:51 +01:00
acqn
a1992702f8 Declarations of 'extern' object and function should be visible in the file scope. 2021-01-30 14:31:51 +01:00
acqn
b99455cc47 Fixed Issue #1374. 2021-01-19 14:33:27 +01:00
Rocky
a9b71b6207 return-type - new warning suppression type added 2021-01-06 16:05:04 +01:00
Jesse Rosenstock
e0c12c90cd g_asr, g_asl: Use ROL/ROR for char shifts by >= 6
Instead of `val` right (left) shifts, we can also do `9 - val` left (right)
rotates and a mask.  This saves 3 bytes and 8 cycles for `val == 7` and
1 byte and 4 cycles for `val == 6`.
2020-12-27 14:22:40 -05:00
Christian Groessler
ef258bdc19 remove TABs which again slipped in.... 2020-12-25 07:16:26 +01:00
Jesse Rosenstock
dfd047ce6a g_typeadjust: Use CF_CHAR for char args
If lhs and rhs are either both signed char or both unsigned char,
return flags for that type instead of (unsigned) int.  The flags
are used only for codegen.  Currently, this does nothing, since
codegen treats chars as ints unless CF_FORCECHAR is set, but it
allows more efficient char x char -> int codegen to be added in
the future.
2020-12-24 14:40:39 -05:00
Greg King
b2c1a77bb3 Fixed the cc65 code that optimizes 16-bit compares when the high bytes are known to be equal.
Only the low bytes are compared.  Originally, signed 16-bit compares were optimized into signed 8-bit compares.  But, the sign bits are in the high bytes; and, they're equal.  Therefore, the low bytes always must be compared as unsigned numbers.
Fixes #1348.
2020-12-24 12:27:09 -05:00
Tim Gates
2646c06f61 docs: fix simple typo, paramater -> parameter
There is a small typo in src/cc65/pragma.c.

Should read `parameter` rather than `paramater`.
2020-11-29 10:26:08 +01:00
Greg King
8b42f570e9 Fixed code that caused a seg-fault after parsing a (deferred) post-count argument followed by a (nested) function-call argument.
The old broken code defers the count until the end of the (parent function's) argument list.  But, a nested function call clears the pointer to the deferred type.  That leads to an access violation.
The new code defers only until the end of each argument.  Fixes #1320.
2020-11-20 17:45:14 -05:00
Oliver Schmidt
cffcbce60f Bumped version.
I placed the Git tag V2.19 in hindsight at 555282497c. But I certainly don't want to rewrite the Git history just for the reported version, so I simply set the reported version at today's HEAD to 2.19.
2020-11-20 19:11:20 +01:00
Zsolt Branyiczky
63543dee07 Revert transient modification of EATab Table 0 comment 2020-11-19 22:02:07 +01:00
Zsolt Branyiczky
527500cedc instruction table contained wrong parameters at SIR opcode 2020-11-19 22:02:07 +01:00
Zsolt Branyiczky
0e98818db5 assembled SAC and SIR opcodes of 6502DTV cpu were wrong 2020-11-19 22:02:07 +01:00
Zsolt Branyiczky
130d3b52a2 new macros supporting 6502DTV cpu 2020-11-19 22:02:07 +01:00
Zsolt Branyiczky
4205a04a34 6502DTV is not a superset of 6502X more 2020-11-19 22:02:07 +01:00
Polluks
bd6e5927c4 Fixed #1341 2020-11-18 10:28:19 +01:00
Oliver Schmidt
116682c190 Avoid C99 idioms. 2020-11-16 18:08:00 +01:00
Jesse Rosenstock
060417b0dc Adjust type of int constants that fit in char
When there is an integral constant like `3` in an expression, it has
type `int` according to the C spec, even though it can be represented
as an `unsigned char`.  Change codegen (`hie_internal` and `typeadjust`)
to treat it as `unsigned char` instead of `int` so that faster,
unsigned operations can be used.

For the test case in #1298, reduces the cycles per iteration from
4311 to 1884.  This is a great improvement, but still much worse than
the 1053 cycles/iter from `c4698df~`, so more work remains to be done.

Further partial fix for #1298 and #1308.
2020-11-16 00:56:19 +01:00
Greg King
2915464667 Fixed cc65's generation of char-type bit-shift code.
Fixed CHAR-to-INT type conversions in the right-shift code generator.  Also fixed some printf-style format specifiers.
2020-11-15 15:22:23 -05:00
Zsolt Branyiczky
2d7777b604 Instruction table is synchronized with the c65's one 2020-11-15 16:35:55 +01:00
Zsolt Branyiczky
0f7cf87bfa Synchronizin InsTab6502DTV instructions table for DTV with the illegal opcodes verified by VICE-emu tests 2020-11-15 16:35:55 +01:00
Zsolt Branyiczky
92c013944e Mistyped comment, missing comma 2020-11-15 16:35:55 +01:00
Zsolt Branyiczky
b33b053307 add c64dtv support 2020-11-15 16:35:55 +01:00
Jesse Rosenstock
5db74b4b19 Use u16 codegen for u8 x u8 ops
In g_typeadjust, before we apply the integral promotions, we check if
both types are unsigned char.  If so, we promote to unsigned int, rather
than int, which would be chosen by the standard rules.  This is only a
performance optimization and does not affect correctness, as the flags
returned by g_typeadjust are only used for code generation, and not to
determine types of other expressions containing this one.  All unsigned
char bit-patterns are valid as both int and unsigned int and represent
the same value, so either signed or unsigned int operations can be used.
This special case part is not duplicated by ArithmeticConvert.

Partial fix for #1308.
2020-11-09 21:19:22 +01:00
Jesse Rosenstock
b5f0c0468d Add stdint.h types for C89 compilers
Add `intN_t` and `uintN_t` for N = 8, 16, 32.
2020-11-03 21:24:52 +01:00
Jesse Rosenstock
65193c6aaf Add stdint.h constants INT32_MIN and UINT32_MAX
These were missing before
2020-11-03 09:26:26 +01:00
acqn
07cc6a3d20 Made optimization steps aware of long branches better. 2020-10-24 21:25:24 +02:00
acqn
5c43d1e04f Changed codegen for postfix inc/dec operations by deferring them till sequence points.
This usually allows faster & smaller code.
Note that deferred operations must still be called at sequence points even if the whole expressions containing them had constant values.
2020-10-20 22:01:55 +02:00
acqn
bb7b69f513 Added OptShiftBack for shifting the C flag into register A and back. 2020-10-20 21:55:39 +02:00
acqn
0354322413 Added OptSignExtened for testing signness right after sign extention. 2020-10-20 21:55:39 +02:00
acqn
9c776a24e5 Use bcc instead of bne in OptNegAX2 to ease optimizations. 2020-10-20 21:55:39 +02:00
acqn
4f3a96a535 Added new opt OptPushPop2.
Also renamed OptPushPop to OptPushPop1.
2020-10-20 21:55:39 +02:00
acqn
262c4235df Symbols in ZP segments will use '.exportzp' instead of '.export' if exported. 2020-10-11 23:05:20 +02:00
acqn
e58c84acf7 Support for optionally specifying address size for segments with:
#pragma ***-name([push,] "name"[, "addrsize"])
where "addrsize" is any addressing size supported in ca65.
2020-10-11 23:05:20 +02:00
acqn
f8c9dde989 The instruction parser can now recognize ZP locations and set the addressing mode for them. 2020-10-11 23:05:20 +02:00
Jesse Rosenstock
81550ca1ee CS_MergeLabels: Keep labels referenced by data
Partial fix for ICE in #1211.  This may fix enough to allow #1049 to be
fixed.

When merging labels, keep the first label with a ref that has no JumpTo;
this is a data segment label, used by computed gotos.

The real fix is to track and rewrite labels in data, but this is more
involved.
2020-10-08 12:11:03 +02:00
acqn
dbba5f3fc9 Fixed handling of %v in inline asm parser. 2020-10-04 12:25:24 +02:00
acqn
a85d5330fa Fixed StrBuf initialization in PreparseArg(). 2020-10-04 12:17:14 +02:00
Jesse Rosenstock
b931e65811 Fix ICE for bit-fields with typedef
Fixes #1267

Avoid ICE, but treat plain int bit-fields declared via typedef as
signed rather than unsigned.  It is more efficient to treat them
as unsigned, but this requires distinguishing int from signed int,
and this is curently not done.
2020-10-03 15:04:31 +02:00
Greg King
c05a750f47 Fixed some copy-&-paste typo mistakes about HuC6280's TMA mnemonic. 2020-10-01 07:25:08 -04:00
acqn
b525554bfe Added support for parsing asm byte size expressions with a pair of parentheses. 2020-09-27 12:22:05 +02:00
acqn
688342e194 Now every code entry has its argument parsed to tell some info.
It fixes the compiling performance regression as well.
Built-in ZPs are recognized.
2020-09-27 12:22:05 +02:00
acqn
cc0f8422f2 More fixes and new utils to check if opcode arguments can be used elsewhere.
Fixed tracking with LI_RELOAD_Y and LI_DIRECT.
Fixed tracking with LI_CHECK_Y and LI_RELOAD_Y.
2020-09-27 12:22:05 +02:00
acqn
f3771a465d Fixed various issues in the usage-tracking code.
Added some utility functions.
2020-09-27 12:22:05 +02:00
acqn
d379affc4b Moved some reusable code from cc65/coptstop.c into new files. 2020-09-27 12:22:05 +02:00
acqn
28c7aa2bc8 Replaced direct CEF_NUMARG flag checks on code entries with CE_HasNumArg(). 2020-09-27 12:22:05 +02:00
acqn
c45a6b3685 Utility function ParseOpcArgStr(). 2020-09-27 12:22:05 +02:00
Jesse Rosenstock
d0089aef95 Fix bit-field truncation warning message
Fix copy & paste bug with warning message.

struct X {
      signed int a : 3;
};
struct X g = { 5 };

Before:
s.c(4): Warning: Implicit truncation from 'int' to 'int : 3' in bit-field
initializer changes value from 5 to 5

After:
s.c(4): Warning: Implicit truncation from 'int' to 'int : 3' in bit-field
initializer changes value from 5 to -3

Fixes #1268
2020-09-26 17:41:45 -04:00
Greg King
81ac28ff71 Used TAY/TYA instead of PHA/PLA when extracting a bit-field.
Without optimization, it saves a few CPU cycles.  With optimization, it saves more cycles and a few bytes.
2020-09-22 12:47:09 -04:00
Greg King
ea95728330 Avoided an avalanche of messages from bad bit-field declarations.
Made cc65 replace a bad bit-field type with a good one, and always parse the field width.

Shortenned a parameter name to a spelling that's consistent with other function headers.
2020-09-22 12:47:09 -04:00
Greg King
07ea5259ac Changed a cc65 error message to say that the sizes of bit-field types (not bit-fields) are limited. 2020-09-22 12:47:08 -04:00
Greg King
bf4b195016 Added some comments that explain where the g_branch() code generator can and can't be used. 2020-09-18 15:50:26 -04:00
acqn
de630a1245 Fixed quick hack for known registers after calling certain runtime functions,
and new quick hack for tosshrax.
2020-09-18 09:04:15 +02:00
acqn
079f4a99dd Added processor state info to the OPCDesc table. However, since some opcodes are affected by the addressing mode, this info is unused in codegen/optimizer but just as quick in-code documentation/hints. 2020-09-18 09:04:15 +02:00
acqn
a7d6eb9190 Added processor flag usage/change-tracking for non-JSR/RTS code entries.
Some existing optimizations are impacted and need fixes in order to work correctly again.
Fixed and improved OptPrecalc. Now it respects the C/V/Z/N flags.
Fixed optimizations impacted by added support of tracking processor flags.
2020-09-18 09:04:15 +02:00
acqn
d02b12fa6c Made local code/data labels really local to the functions where they live in. 2020-09-18 09:02:16 +02:00
acqn
86ced2bd4c Avoided unnecessarily boosting the code label numbers with boolean AND. 2020-09-18 08:59:56 +02:00
acqn
b8ae5c28fe Added debug output support for processor flags. 2020-09-13 13:50:35 +02:00
acqn
810e17edfe Fixed processor states tracking for the BIT/TRB/TSB opcode.
Added new opcode descriptions about whether and how the opcode accesses memory.
2020-09-13 13:50:35 +02:00
acqn
66c5faeb9a Added processor flags usage tracking.
Added ZNRegs for tracking what register(s) Z/N flags currently reflect.
Added utility functions to check if the specified processor state is known to be a certain value.
2020-09-13 13:50:35 +02:00
acqn
fe3f267233 Added new runtime sub bcasta/bcastax/bcasteax opposing to bnega/bnegax/bnegeax. 2020-09-11 13:33:54 +02:00
acqn
142b0bf9b3 Added utility functions to get names of comparison function/transformer subroutines. 2020-09-11 13:33:54 +02:00
acqn
ab7e9f8424 Hotfix for Issue #1250. 2020-09-08 16:28:21 +02:00
Jesse Rosenstock
4e4e4c2d21 Allow char bit-fields
These are not required to be supported (only int, signed int, and
unsigned int are required), but most compilers support it.

https://port70.net/~nsz/c/c89/c89-draft.html#3.5.2.1
https://port70.net/~nsz/c/c89/c89-draft.html#A.6.5.8

For consistency with other integral types, plain `char` bit-fields
are unsigned, regardless of the `--signed-chars` option.

Fixes #1047
2020-09-08 14:24:04 +02:00
acqn
41cee0eb44 Extended support for more addressing modes in tos* optimizations. 2020-09-08 14:19:48 +02:00
acqn
7553b60ef0 Improved OptStackOps for optimizating further when operands have equal hi-bytes. 2020-09-08 14:19:48 +02:00
acqn
57117fa687 Utility functions about compare conditions. 2020-09-08 14:19:48 +02:00
acqn
64ef562fa7 Moved all optimization steps from codeopt.c and some optimization steps from coptind.c into new separate files. 2020-09-08 14:18:22 +02:00
Jesse Rosenstock
9a0e4a35e1 Fix enum bit-field ICE #1244
This previously resulted in an ICE:
cc65: Check failed: (Entry->Type->C & T_MASK_SIGN) == T_SIGN_SIGNED,
file 'cc65/symtab.c', line 874

This CHECK is in the code that deals with changing `int` bitfields to
`unsigned int`.

Work around this by treating enum bit-fields as having their signedness
specified, so this type change code does not get called.

Fixes #1244.
2020-09-07 11:21:23 +02:00
Tevo
1e7a9e44af Update comment to reflect addition of integer boundary constants 2020-09-06 23:32:00 +02:00
Tevo
23a8b2c303 Define integer size macros for lacking systems
Define integer size macros for lacking systems
2020-09-06 23:32:00 +02:00
acqn
6bb2d1d5d1 Fixed a comment on struct/union types in DoCompare(). 2020-09-06 22:47:11 +02:00
acqn
1cde952cf5 Fixed comparing an enum type with a non-enum type in DoCompare(). 2020-09-06 22:47:11 +02:00
acqn
6e0fb630d7 Fixed check for processor flags usage in case of PHP. 2020-09-06 13:32:38 +02:00
acqn
e2f950b15e Avoided referencing string literals with sizeof so that they are not output if unused elsewhere. 2020-09-05 13:21:21 +02:00
acqn
903e84c24c Std-functions are no longer inlined if they are unevaluated. 2020-09-05 13:21:21 +02:00
acqn
df07e23f2c Fixed bnegeax funcinfo on register usage. 2020-09-05 02:25:56 -04:00
acqn
f849de6769 Object addresses as non-NULL for comparison with NULL. 2020-09-04 19:50:32 +02:00
acqn
8e0b2f0833 Object addresses as non-NULL in boolean context. 2020-09-04 19:50:32 +02:00
acqn
bc5570b708 Fixed logical-NOT in constant context. 2020-09-04 19:50:32 +02:00
acqn
676b14429d Better opt chance for certain optimization steps e.g. OptPtrStore1 etc. 2020-09-04 12:00:10 +02:00
acqn
29d1999947 Rearranged the OptFunc's in alphabetic order. 2020-09-04 12:00:10 +02:00
acqn
761d00b7dc Ignore running removed old optimization steps. Neither list them in help info. 2020-09-04 12:00:10 +02:00
acqn
ae340703f2 OptDupLoads shouldn't silently do optimizations. 2020-09-04 11:58:25 +02:00
acqn
f45d2515eb Fixed OptPush1 in case later code would rely on that pushax zeroes register Y. 2020-09-04 11:58:25 +02:00
acqn
fb6bc275bc Fixed evaluation flags propagation to subexpressions in assignments and function calls. 2020-09-02 21:36:59 +02:00
acqn
2379504449 Fixed AND/OR in certain cases where the 'E_NEED_TEST' flag set for usage only in subexpressions should be cleared. 2020-09-02 21:36:59 +02:00
acqn
28de3423eb Merged some switch cases in code generation subroutines. 2020-08-31 09:12:03 +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
Oliver Schmidt
bee559d5f4
Merge pull request #1220 from acqn/StaticConst
[cc65] Fixed constant boolean expressions
2020-08-31 08:59:25 +02:00
acqn
74def4608a The 'E_NEED_TEST' flag shouldn't be overwritten when loading the expression result. 2020-08-31 02:30:12 +08:00
acqn
c0a873e0c8 Reduced exess errors on wrong initializations with curly braces. 2020-08-30 17:35:48 +02:00
acqn
8b580e1191 Disabled struct/union fields of 'void' type. 2020-08-30 17:33:36 +02:00
acqn
f1161daee9 Recursively checking for incomplete/unknown-sized types. 2020-08-30 17:33:36 +02:00
acqn
8541f18340 Improved diagnostic info on assignment to void types. 2020-08-30 17:33:36 +02:00
acqn
abcc2a8f1a Disallowed void arrays of elements of variant sizes. 2020-08-30 17:33:36 +02:00
acqn
d87846e1e1 Improved comments according to PR reviews. 2020-08-30 22:12:30 +08:00
acqn
60c59f59a3 Renamed StaticConstExpr() and StaticConstAbsIntExpr() with clearer comments. 2020-08-30 00:26:52 +08:00
acqn
df755df44d Warning about ESU types declared inside parameter list as they are invisble outside. 2020-08-29 16:37:16 +02:00
acqn
33a75e0a73 Optimized parameter list checking.
Fixed function type comparison between ANSI and K&R styles.
2020-08-29 16:37:16 +02:00
acqn
0a96ffc878 Fixed function parameter checking.
Fixed function return type checking.
2020-08-29 16:37:16 +02:00
acqn
4e61ae5b36 Fixed function parameter type conversion. 2020-08-29 16:37:16 +02:00
acqn
632da3f4ee Fixed tracking and checking flexible array members. 2020-08-29 16:35:42 +02:00
acqn
504aee3835
Merge branch 'master' into StaticConst 2020-08-27 06:27:23 +08:00
acqn
bb9c203222 Fixed integer promotion of unary operations. 2020-08-26 22:17:16 +02:00
acqn
8d225c32b1 Fixed checks on assignment to incomplete types. 2020-08-26 22:14:51 +02:00
acqn
43cb092a68 Fixed CHECK failures on certain usage of incomplete enums. 2020-08-26 22:14:51 +02:00
acqn
1957dc7a5c Disallowed arrays of incomplete types.
Fixed diagnostics on incomplete local arrays.
2020-08-26 22:14:51 +02:00
acqn
f5b1b69376 Forbid struct/union fields of incomplete types. 2020-08-26 22:14:51 +02:00
Jesse Rosenstock
d38e5858f0 Add tests for #1211
CL_MoveRefs: Add CHECK (E->JumpTo != NULL) to make failure clearer.
2020-08-24 18:10:22 +02:00
acqn
c3a6b39945 Made struct assignment less hackish. 2020-08-24 18:02:29 +02:00
acqn
d1995fc81a Fixed rvalue-ness of cast results. 2020-08-24 17:16:37 +02:00
acqn
911a79796d Fixed checks and diagnostics on type-casting. 2020-08-24 17:16:37 +02:00
acqn
0486d28abc Fixed Issue #327. 2020-08-22 13:44:18 +02:00
acqn
f289ea6c14 Avoided generating unnecessary true-case labels in logic AND/OR. 2020-08-22 11:10:17 +08:00
acqn
0536f4f9bd Minor fixes on constant expression checking and comments. 2020-08-21 23:27:41 +02:00
acqn
63256fd15d Changed negation of signed long stored in unsigned long to unsigned subtraction. 2020-08-21 23:16:17 +02:00
acqn
f59c2a08d9 Added support for changing multiplications with certain negative multipliers into bit-shifts. Only enable certain kinds of signed mul replacements with shift according to the code size factor settings. 2020-08-21 23:16:17 +02:00
acqn
ea7336591c Removed special-casing code for scaling up. Now it uses the normal multiplying code. 2020-08-21 23:16:17 +02:00
acqn
85ea06687b Fixed logical AND and logical OR. 2020-08-20 07:52:15 +08:00
acqn
725511131a Fixed constant expression checks with no-code requirement.
Used return-by-value initialization for ExprDesc.
2020-08-20 07:52:11 +08: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
acqn
17bbba7327 Added integer boolean type string.
No longer set the "expression tested" flag with constant results in comparison.
2020-08-20 07:52:03 +08:00
acqn
9fcde120aa Made function signatures in asm output use the parameter lists from original definitions instead of the composites. 2020-08-19 08:40:19 +02:00
Greg King
36dd82f0e6 Added g_branch() to cc65's code generator.
It uses BRA if the platform's CPU has BRA.  Else, it generates a JMP.

(Used it in the bitfield sign-extending code.)
2020-08-18 19:11:18 -04: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
acqn
56b659c0be Made char type a distinct type. 2020-08-18 10:48:38 +02:00
acqn
87889df9e9 Fixed type checking in relation operations. 2020-08-18 09:39:43 +02:00
acqn
f206833a20 Alternative fix for Issue #1167. 2020-08-17 20:31:02 +02:00
acqn
0afa1a9a95 Fixed function signatures in asm output.
Improved full type name production.
2020-08-17 20:30:32 +02:00
acqn
ebae994dc9 Fixed CHECK failure when calling functions defined with repeated parameter names.
Clarified the terms "parameter" vs "argument" in FunctionParamList().
2020-08-17 20:27:57 +02:00
acqn
15f28c3a8c Fixed getting the basic raw type names. 2020-08-17 00:00:03 +02:00
acqn
11cd3e5cbd Utility for checking general datatype categories, incomplete ESU types and arrays of unknown sizes. 2020-08-17 00:00:03 +02:00
Jesse Rosenstock
1cf9404c19 Support C2X _Static_assert(expr) syntax
This makes the message in _Static_assert(expr, message) optional.

Fixes #1188.
2020-08-16 11:38:20 +02:00
Jesse Rosenstock
c4698dfd07 Use C89 semantics for integer conversions
Previously, the following rules were used for binary operators:
* If one of the values is a long, the result is long.
* If one of the values is unsigned, the result is also unsigned.
* Otherwise the result is an int.

C89 specifies the "usual arithmetic conversions" as:
* The integral promotions are performed on both operands.
* Then the following rules are applied:
  * If either operand has type unsigned long int, the other operand is
    converted to unsigned long int.
  * Otherwise, if one operand has type long int and the other has type
    unsigned int, if a long int can represent all values of an unsigned int,
    the operand of type unsigned int is converted to long int; if a long int
    cannot represent all the values of an unsigned int, both operands are
    converted to unsigned long int.
  * Otherwise, if either operand has type long int, the other operand is
    converted to long int.
  * Otherwise, if either operand has type unsigned int, the other operand is
    converted to unsigned int.
  * Otherwise, both operands have type int.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.5

As one example, these rules give a different result for an operator
with one long operand and one unsigned int operand.  Previously,
the result type was unsigned long.  With C89 semantics, it is just long,
since long can represent all unsigned ints.

Integral promotions convert types shorter than int to int (or unsigned int).
Both char and unsigned char are promoted to int since int can represent
all unsigned chars.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.1

Rename promoteint to ArithmeticConvert, since this is more accurate.

Fixes #170
2020-08-15 19:14:31 +02:00
acqn
fdded33097 Made it easier to support 0-size structs in the future. 2020-08-15 06:27:11 +08:00
acqn
b19bb14348 Fixed checking conflitcing declarations with external vs other linkage. 2020-08-14 18:33:54 +02:00
acqn
13ed557b92 Fixed compatibility checking of function declarations by using the composite types of them. 2020-08-14 18:33:54 +02:00
acqn
44d52935da Utility for getting the composite types of functions. 2020-08-14 18:33:54 +02:00
acqn
8a417ff039 Improved ESU declaration failure handling. 2020-08-14 18:15:31 +02:00
acqn
0dfe9ff5fe Fixed testing 'struct->field'. 2020-08-14 08:32:22 +08:00
acqn
0fa18886c0 Fixed copying structs/unions > 4 bytes. 2020-08-13 08:59:05 +02:00
acqn
03b37cf712 Fixed type comparisons of typedefs and arrays. 2020-08-12 15:04:26 +02:00
acqn
eb4464e828 Fixed type comparisons of ESU types with stricter rules. 2020-08-12 15:04:26 +02:00
acqn
fe44fe963f Disallowed empty enums. 2020-08-12 15:02:43 +02:00
acqn
97065faf1a Disallowed struct/union types of 0 size as cc65 is not ready to support them. 2020-08-12 15:02:43 +02:00
acqn
4dfc1a5ded Using a dedicated SC_FICTITIOUS flag in case of parsing errors. 2020-08-12 15:01:31 +02:00
acqn
bde5be6793 Improved error message on initializing extern variables inside functions. 2020-08-12 15:01:31 +02:00
acqn
b62b1650f5 Improved error messages on struct/union type multiple definitions. 2020-08-12 15:01:31 +02:00
acqn
fe3f726fd6 Improved incomplete enum typed diagnostics. 2020-08-12 15:01:31 +02:00
acqn
0d53806490 Avoided excess errors in incomplete struct assignment. 2020-08-12 15:01:31 +02:00
acqn
9317db6642 Slightly improved type error messages of 'op='. 2020-08-12 15:01:31 +02:00
acqn
9fcfa3fc49 Fixed full type names of functions with "empty" parameter list. 2020-08-12 15:01:31 +02:00
acqn
68d63b089d Reduced error flood raised by misplaced variable declarations. 2020-08-12 15:01:31 +02:00
acqn
0f1a5e0520 Set enum tag definition flags. 2020-08-09 22:12:36 +02:00
acqn
1dd899c7c9 Fixed non-file-scope multiple definition checking. 2020-08-09 22:12:36 +02:00
acqn
d68cd90e47 Function declaration in functions cannot have storage classes other than 'extern'. 2020-08-07 10:16:33 +02:00
acqn
43efc256f1 Changed error/warning messages not using the term 'tentative' according to PR reviews. 2020-08-07 10:16:33 +02:00
acqn
b2d3b8379c Warning about forward declaration of enum types in non-cc65 modes. 2020-08-07 10:16:33 +02:00
acqn
8cdffc1944 No storage for unsuccessfully parsed variables. 2020-08-07 10:16:33 +02:00
acqn
fdef067629 Fixed tentative definition of variables of incomplete types that may be completed later.
Tenative arrays that never get completed are now assumed each to have one element.
2020-08-07 10:16:33 +02:00
acqn
fdd120db49 Enabled to output errors and warnings about tentative definitions. 2020-08-07 10:16:33 +02:00
acqn
f59d6b8f6a Redefining enums/structs/unions of 0 size is no longer treated as declarations and thus forbidden. 2020-08-07 10:16:33 +02:00
Jesse Rosenstock
cdfc1afd89 Fix vacuous comparison warning from 0df45fe
cc65/symentry.c:306:60: warning: address of array 'Sym->Name' will always evaluate to 'true' [-Wpointer-bool-conversion]
    sprintf (TypeName, "%s %s", GetBasicTypeName (T), Sym->Name ? Sym->Name : "<unknown>");
                                                      ~~~~~^~~~ ~
2020-08-05 17:48:13 +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
acqn
bae431eab0 Fixed error message of CheckedPSizeOf(). 2020-08-03 06:18:28 +02:00
acqn
d6aa446b54 Error info for loading expressions of incomplete enum types.
No more "Illegal type 0016".
2020-08-02 23:51:11 +02:00
acqn
6df4f1996b Improved diagnostics with more detailed type names. 2020-08-02 23:51:11 +02:00
acqn
11a5f0edf1 No "Statement has no effect" warnings on statements with errors. 2020-08-02 23:51:11 +02:00
acqn
7e68a24625 Clearer warning messages on unused symbols. 2020-08-02 23:51:11 +02:00
acqn
e8c2886455 Improved error messages on redefinitions of constants and bit-fields. 2020-08-02 23:51:11 +02:00
acqn
ef5a4db12e Improved warning messages on UB shifts. 2020-08-02 23:51:11 +02:00
acqn
2ab7272673 Improved warning on comparison of unsigned type < 0. 2020-08-02 23:51:11 +02:00
acqn
99ac1c46da Made errors/warnings statistic message visible when there are errors. 2020-08-02 23:51:11 +02:00
acqn
44e3080ea9 Increased upper limit of allowed errors before aborting. 2020-08-02 23:51:11 +02:00
acqn
00c16d34a4 Minor fixes for HandleSymRedefinition(). 2020-08-02 23:51:11 +02:00
acqn
80b0e57543 Changed parameter constness of TypeConversion(). 2020-08-02 18:55:46 +02:00
acqn
003d47cc8b Improved type conversion diagnostic messages.
Allowed incompatible pointer assignments with warnings.
Fixed Issue #1089.
2020-08-02 18:55:46 +02:00
acqn
d841bbe498 Utility to check for castability. 2020-08-02 18:55:46 +02:00
acqn
52051f444e Using tracked individual string buffers instead of a shared static string buffer for full type names. 2020-08-02 18:55:46 +02:00
acqn
4ccf10f3fa Utility to get full type names. 2020-08-02 18:55:46 +02:00
acqn
0df45fe2f2 Utility for getting ESU tag type symbols. 2020-08-02 18:55:46 +02:00
Oliver Schmidt
c831f40e9b Unfortunately there's no other way than using the absolute path to init the correct MSVC 2017 environment. 2020-08-02 18:44:13 +02:00
Oliver Schmidt
992596c981 Initialize MSVC 2017 environment before build. 2020-08-02 17:32:36 +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
acqn
2a555d198c Changed 'switch' to 'if' according PR review comments. 2020-08-02 12:28:11 +02:00
acqn
30fd8592ae Avoid internal errors when using function-type objects in expressions. 2020-08-02 12:28:11 +02:00
acqn
e526cbbff6 Fixed handling multiple storage specifiers in one declaration. 2020-08-02 02:20:25 +02:00
Oliver Schmidt
e1043fac12 Adjusted to https://github.com/cc65/cc65/pull/1124. 2020-08-01 10:56:05 +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
d0c7108dcf Change copyright notice to "The cc65 Authors" 2020-07-30 19:17:11 +02:00
Jesse Rosenstock
3df6c383c0 Add support for static_assert
Add C11's _Static_assert and static_assert macro.

This is like #error, but is handled at a later stage
of translation, so it is possible to check sizes of
types, values of enums, etc.

https://en.cppreference.com/w/c/language/_Static_assert
https://port70.net/~nsz/c/c11/n1570.html#6.7.10
2020-07-30 19:17:11 +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
e38f601fcc Fixed padding at the ends of structs with bit-fields. 2020-07-30 08:38:24 +02:00
acqn
8a511bb63d Fixed nested array initializers. 2020-07-30 08:38:24 +02:00
acqn
9075a853dc Allows one trailing comma before the closing curly of a struct/union initializer. 2020-07-30 08:38:24 +02:00
acqn
25d10d9d9a Fixed nested struct/union initialization.
Fixed bit-fields offsets in anonymous structs.
2020-07-30 08:38:24 +02:00
acqn
d6d667a688 Improved error handling with symbol redefinitions. 2020-07-30 08:22:29 +02:00
acqn
92de4fa0d0 Enabled to recognize labels when parsing local variable declarations. 2020-07-30 08:22:29 +02:00
acqn
19c81ed866 Fixed type mask usage. 2020-07-30 08:13:23 +02:00
Jesse Rosenstock
fb9b50ff9c Move type checks before bit-field width parsing 2020-07-30 08:10:38 +02:00
Jesse Rosenstock
a2561d07f3 Remove special-case bit-field width code
cbb33f8 restricted allowed bit-field types to int,
so this is equivalent for now, but forward-compatible.

Fixes FIXME

Also move the int type check before parsing the colon.
2020-07-30 08:10:38 +02:00
Oliver Schmidt
8eab28012a
Adjusted project name. 2020-07-28 23:29:16 +02:00
acqn
cbb33f86e8 Disabled using non-int-size types to declare bit-fields. 2020-07-28 23:26:25 +02:00
acqn
c37f9f1a41 Check if the integer size is known in GetIntegerTypeMin/Max() to prevent potential misuse. 2020-07-28 23:26:25 +02:00
acqn
0f412b6beb Small fixes according to PR review. 2020-07-28 23:26:25 +02:00
acqn
7e243e0f2c Allowed using all integer types including enum and char types to define bit-fields,
but kept the currently behavior that all of them are treated as unsigned int.
2020-07-28 23:26:25 +02:00
acqn
d8184fbe54 No longer insert all enums in the global symbol table. 2020-07-28 23:26:25 +02:00
acqn
daa65199b3 Fixed underlying types of enums.
Made enumerator diagnostics more sensible.
Fixed Issue #1048 as a natural result.
2020-07-28 23:26:25 +02:00
Greg King
44c82eb1c3 Made da65 disassemble branch instructions with relative address expression operands if there's no label. 2020-07-21 18:43:32 -04:00
acqn
07e18774f7 Added spaces around '|' with regex replacement. 2020-07-21 18:23:52 +02:00
acqn
c66d0881b9 Made the enum/enumerator types clearer and improved DumpSymEntry() output. 2020-07-21 18:23:52 +02:00
acqn
18bd76bb90 Minor fixes and improvements. 2020-07-21 18:23:52 +02:00
acqn
65081aebed Made able to recognize global declarations of static arrays. Fixed Issue #975. 2020-07-21 18:23:52 +02:00
acqn
0250c87ac6 Fixed SC_* type masks by making them all bitwise-exclusive. 2020-07-21 18:23:52 +02:00
acqn
78342fa82c Fix for "auto" variables made "static" with the "-Cl" options. 2020-07-20 15:01:47 +02:00
acqn
71c2d27705 Removed an ED_IsBitField() test according to PR review. 2020-07-20 14:54:32 +02:00
acqn
2245783345 Fixed ability to do actual type conversion from bit-fields to integers. Note this doesn't try to fix the signedness issues. 2020-07-20 14:54:32 +02:00
acqn
b67b8ddd38 Disabled applying 'sizeof' to bit-fields. 2020-07-20 14:54:32 +02:00
acqn
62a6e37487 Made the code handling '&expression' slightly tidier. 2020-07-20 14:54:32 +02:00
acqn
3c52ad1d9e New utility ED_DisBitField() to make an expression no longer a bit-field. 2020-07-20 14:54:32 +02:00
Greg King
fd0a6955da Changed "IsTypeStruct() || IsTypeUnion()" expressions into shorter "IsClassStruct()" expressions.
Type-classes are groups of types that can be handled in the same way (similar syntax).
2020-07-19 14:30:22 -04:00
acqn
29c50ab25f Corrected the error message about struct/union members not found. 2020-07-19 12:57:59 +02:00
acqn
768e03a474 Small fixes and tidy-up based on PR review.
Renamed GetReplacementType() to GetStructReplacementType().
Clarified in comments that most *Struct* facilities work for unions as well.
Made it clear in some error messages with regards to structs/unions.
2020-07-19 10:58:33 +02:00
acqn
0c3e1b491f Disabled -Wstruct-param by default. 2020-07-19 10:58:33 +02:00
acqn
b45d373fd6 Fixed passing by value structs/unions <= 4 bytes in size to functions. Larger ones are forbidden for now. 2020-07-19 10:58:33 +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
66ecc0e52c New utility to get the proper replacement type for passing structs/unions by value.
New utility to get basic type names such as 'struct', 'union' and so on.
2020-07-19 10:58:33 +02:00
acqn
333fa97326 Whitespaces/newlines fixes. 2020-07-18 12:54:29 +02:00
acqn
9198b3be00 Fixed '&function' and '&array'. 2020-07-18 12:54:29 +02:00
acqn
d23b577331 More compiler flags on address types to match the location types of expressions. 2020-07-18 12:54:29 +02:00
acqn
2108489523 Fix for Issue #1075 and #1077. 2020-07-18 12:54:29 +02:00