Commit Graph

2556 Commits

Author SHA1 Message Date
Bill Currie d1e83b9d48 [qfcc] Create a compound initializer expression type
This fixes the problem of using the return value of a function as an
element in a compound initializer. The cause of the problem is that
compound initializers were represented by block expressions, but
function calls are contained within block expressions, so def
initialization saw the block expression and thought it was a nested
compound initializer.

Technically, it was a bug in the nested element parsing code in that it
wasn't checking the result value of the block expression, but using a
whole new expression type makes things much cleaner and the work done
paves the way for labeled initializers and compound assignments.
2020-03-11 15:46:57 +09:00
Bill Currie f10f9e157d [qfcc] Warn about unused labels 2020-03-11 13:33:06 +09:00
Bill Currie 393e540ffa [qfcc] Print the source name of an undefined label
Undefined labels generated by the compiler indicate severe trouble.
2020-03-11 13:31:12 +09:00
Bill Currie 813319efc2 [qfcc] Implement goto
It's just too useful when used correctly.
2020-03-11 12:53:40 +09:00
Bill Currie 4a8854d9ed [qfcc] Add expression tracking to operands
Not much uses it yet, but it will make for better diagnostics.
2020-03-11 12:51:34 +09:00
Bill Currie 1cd5ea5732 [qfcc] Add support for named labels in statements
Yeah, I've finally decided to implement goto. Limited to function scope
of course.
2020-03-11 12:49:10 +09:00
Bill Currie d5560434c0 [qfcc] Rename label to bool_label for clarity
And also so I can use `label' for source labels.
2020-03-11 11:06:09 +09:00
Bill Currie 3061f7e30e [qfcc] Update sendv test for corrected implementation 2020-03-11 11:04:49 +09:00
Bill Currie 826f066e00 [qfcc] Be more consistent with string saving
Not that it really makes any difference for labels since they're
guaranteed unique, but it does remove the question of "why nva instead
of save_string?". Looking at history, save_string came after I changed
it from strdup (va()) to nva(), and then either didn't think to look for
nva or thought it wasn't worth changing.
2020-03-11 10:50:15 +09:00
Bill Currie 5535a6a509 [qfcc] Fix missing words in a comment 2020-03-11 10:49:49 +09:00
Bill Currie 9acfdea8b5 [qfcc] Improve line number binding for function calls
Multi-line calls (especially messages) got rather confusing to read as
the lines jumped back and forth. Now the binding is better but the dags
code is reordering the parameters sometimes.
2020-03-11 01:52:45 +09:00
Bill Currie a013714bd0 [qfcc] Add missing header file changes
Oops
2020-03-08 20:11:21 +09:00
Bill Currie 89ec86f77f [qfcc] Add option to promote of float through ...
The server code is not yet ready for doubles, especially in its varargs
builtins: they expect only floats. When float promotion is enabled
(default for advanced code, disabled for traditional or v6only),
"@float_promoted@" is written to the prog's strings.
2020-03-08 19:13:57 +09:00
Bill Currie bcf75b541a [qfcc] Build movep dest pointer correctly
This fixes the mangled pointer in struct-init-param.r.
2020-03-08 17:40:38 +09:00
Bill Currie 5020966be3 [qfcc] Fix ud-chain alias handling
That was a fair bit trickier than I thought, but now .return and .paramN
are handled correctly, too, especially taking call instructions into
account (they can "kill" all 9 defs).
2020-03-08 16:57:12 +09:00
Bill Currie 3d9410c66d [qfcc] Force overlap to 0 for non-alias def/temops
Make the code behave as intended: visiting all aliases when starting
with the real def/tempop regardless of the overlap setting.
2020-03-08 16:53:28 +09:00
Bill Currie 035da472ec [qfcc] Offset alias tempop offsets
Alias tempop offsets are relative to the real tempop. This fixes alias
tempops never overlapping the real tempop.
2020-03-08 16:51:01 +09:00
Bill Currie 695b3ba0d0 [qfcc] Rearrange vecexpr.r for easier debugging
Putting the most likely function to have problems at the top reduces
break-point shenanigans.
2020-03-08 16:50:39 +09:00
Bill Currie d9d321f65b [qfcc] Check for previous errors in vector exprs
Fixes a segfault when one of the expressions used to construct the
vector was the result of an error.
2020-03-08 15:40:07 +09:00
Bill Currie b81d58c795 Revert "[qfcc] Correct a comment"
This reverts commit a2f203c840.

There is indeed a world of difference between "any" and "only", and it
helps if I read the rest of the docs AND the code :P.
2020-03-08 14:58:57 +09:00
Bill Currie 8696e76a25 [qfcc] Handle aliases when setting use and def
As expected, this does not fix the mangled pointer problem in
struct-init-param.r, but it does improve the ud-chains. There's still a
problem with .return, but it's handling in flow_analyze_statement is a
bit "special" :P.
2020-03-08 12:17:56 +09:00
Bill Currie a2f203c840 [qfcc] Correct a comment
There's a world of difference between "any" and "only".
2020-03-08 12:10:12 +09:00
Bill Currie b2faca16a7 [qfcc] Rename the kill alias functions
Having "visit" in the name felt redundant in the end.
2020-03-08 12:08:56 +09:00
Bill Currie c2ed6d41bd [qfcc] Finish struct-init-param test
When the bug is fixed, it will pass now (does without optimization).
2020-03-08 03:55:08 +09:00
Bill Currie e4c87091a3 [qfcc] Lots of flow analysis docs
And some function shuffling for grouping. I'm not satisfied with the
docs, but they're a lot more helpful than they were.
2020-03-08 03:53:53 +09:00
Bill Currie 809c103fd1 [qfcc] Shuffle some code around to be clearer
Doing the same thing at the end of two branches of an if/else seems off.

And doing an associative(?) set operation every time through a loop is
wasteful.
2020-03-08 03:46:52 +09:00
Bill Currie 7338689146 [qfcc] Treat offset real tempops as an error
tempops always have an offset field, but only those that are aliases
should ever have a non-zero offset.
2020-03-08 03:42:18 +09:00
Bill Currie d44d956038 [qfcc] Remove a long dead function 2020-03-08 03:39:24 +09:00
Bill Currie f56de00c21 [qfcc] Rename a field
depth_first is much clearer than dfo. I had to check what dfo meant too
many times in one night.
2020-03-08 03:38:45 +09:00
Bill Currie 2b15e61b28 [qfcc] Remove obsolete structure fields
init_vars hasn't been used for a long time.
2020-03-08 03:33:01 +09:00
Bill Currie e524db1fc1 [qfcc] Set op type when aliasing a value
This fixes the ICE when attempting to compile address-cast without
optimization (just realized why, too: the assignment was optimized out
of existence).
2020-03-08 03:11:46 +09:00
Bill Currie 6ada20f685 [qfcc] Show offset for op_x_def_ofs relocs 2020-03-07 02:06:33 +09:00
Bill Currie 48514ba2f3 [qfcc] Create alias def for defs accessed via pointer
This the fixes the incorrect flow analysis caused by the def being seen
to have the wrong size (structure field of structure def seen through a
constant pointer). Fixes the ICE, but the pointer constant is broken
somewhere in dags, presumably.
2020-03-07 01:30:36 +09:00
Bill Currie faa6eabfbe [qfcc] Add a failing test for struct init to param
This actually took a bit to reproduce.
2020-03-06 22:28:04 +09:00
Bill Currie f7757cf894 [qfcc] Add filename to dot output
It makes things so much easier when viewing the graphs
2020-03-06 21:05:53 +09:00
Bill Currie de06efa604 [qfcc] Fix handling of nil for static initializers
nil is most definitely constant.
2020-03-06 20:38:40 +09:00
Bill Currie 9dbc81432a [qfcc] Use full type for differentiating values
This fixes the problem of using nil for two different compound types
within the one expression. The problem is all compound types have the
same low-level type (ev_invalid) and this caused the two different nils
to have the same type when taken back up to expression level.
2020-03-06 20:33:47 +09:00
Bill Currie 07e6baf32f [qfcc] Support { } as nil in nested initializers
Did top-level earlier, but forgot to add support for deeper nestings.
2020-03-06 20:32:37 +09:00
Bill Currie 9b269c2f8e [qfcc] Fix mangled method parameters
Method parameters (ie, extra parameters without selector names) were
getting reversed during function type construction.
2020-03-06 17:37:58 +09:00
Bill Currie a2cebe3cac [qfcc] Add failing test for method parameters 2020-03-06 17:36:23 +09:00
Bill Currie 94e35b5f57 [qfcc] Clean up error messages around superclass 2020-03-05 21:10:15 +09:00
Bill Currie 66b8ab6890 [qfcc] Rework method ivar access
While expression symbols worked for what they are, they weren't so good
for ivar access because every ivar of a class (and its super classes)
would be accessed at method scope creation, generating spurious access
errors if any were private. That is, when the access checks worked at
all.
2020-03-05 18:45:47 +09:00
Bill Currie 5200c3f518 [qfcc] Update chewed-alias test for new warnings 2020-03-05 18:26:11 +09:00
Bill Currie 1bf56b28ac [qfcc] Warn when messaging a forward-declared class
But only once.
2020-03-05 15:39:34 +09:00
Bill Currie 59db90d177 [qfcc] Fix method not found warnings
It turns out they should not be optional, but do need to be smarter
about when and which. So another two FIXMEs gone :)
2020-03-05 14:48:53 +09:00
Bill Currie 669c8f43d8 whitespace 2020-03-05 14:48:49 +09:00
Bill Currie ccaa4ad3d2 [qfcc] Catch assignment of void* to class pointers
id and other class pointers imply that the object can receive messages,
but void * has no such implication, so treat it as a mismatch.
2020-03-05 14:14:20 +09:00
Bill Currie 65a5e4f2a4 [qfcc] Allow inherited methods to satisfy protocols
I suspect that the current state of things will produce problems later
on, but this works for now.
2020-03-05 12:52:37 +09:00
Bill Currie 1459361cbd [qfcc] Set builtin function def flags
This fixes the missing redefinition error when a builtin is defined
twice (and thus corrupting the function chain).
2020-03-05 11:48:15 +09:00
Bill Currie 9ccfe8aefc [qfcc] Rewrite init_elements
The end goal was to fix erroneous non-constant initializer errors for
the following (ie, nested initializer blocks):

    typedef struct { int x; int y; } Point;
    typedef struct { int width; int height; } Extent;
    typedef struct Rect_s { Point offset; Extent extent; } Rect;
    Rect makeRect (int xpos, int ypos, int xlen, int ylen)
    {
	Rect rect = {{xpos, ypos}, {xlen, ylen}};
	return rect;
    }

However, it turned out that nested initializer blocks for local
variables did not work at all in that the relocations were lost because
fake defs were being created for the generated instructions.

Thus, instead of creating fake defs, simply record the offset relative
to the base def, the type, and the basic type initializer expression,
then generate instructions that all refer to the correct def but with a
relative offset.

Other than using the new element system, static initializers are largely
unaffected.
2020-03-05 11:05:13 +09:00