Commit graph

2971 commits

Author SHA1 Message Date
Bill Currie
54d776f243 [qfcc] Take operand width into account
Operand width is encoded in the instruction opcode, so the width needs
to be accounted for in order to select the correct instruction. With
this, my little test generates correct code for the ruamoko ISA (except
for return, still fails).
2022-01-20 16:49:07 +09:00
Bill Currie
b2ddae46b2 [qfcc] Show raw opcode when dumping instructions
Allows checking the correct instruction has been selected (it's not:
getting 4-component instructions instead of 1)
2022-01-20 15:34:43 +09:00
Bill Currie
74d00d0a3c [qfcc] Update store statements for change in B mode
Ruamoko store instructions are now always indexed and thus need a 0 for
unindexed references, but v6 stores still have no-index addressing.
2022-01-20 15:34:16 +09:00
Bill Currie
a5a8017220 [qfcc] Switch internal statement format to ruamoko
For the most part, it wasn't too bad as it's just a rotation of the
operands for some instructions (store, assign, branch), but dealing with
all the direct accesses to specific operands was a small pain. I am very
glad I made all those automated tests :)
2022-01-20 13:08:05 +09:00
Bill Currie
19baae6969 [qfcc] Dump emitted statements when verbosity >= 2
I wish I had done this years (decades, even!) ago. It makes checking the
output so much easier.
2022-01-20 13:08:05 +09:00
Bill Currie
a4ebd6aa58 [gamecode] Fix a few missed opcode renames
if and ifnot became ifnz and ifz, and return_v lost its tail (it was
always redundant, except in dags, and that's fixed with a pointer check).
2022-01-20 13:07:57 +09:00
Bill Currie
143030fec4 [gamecode] Use text for all v6p opcode names
This makes the v6p instruction table consistent with the ruamoko
instruction table, and clears up some of the ugliness with the load,
store, and assign instructions (. .= and = are now spelled out). I think
I'd still prefer an enum code (faster) but at least this is more
readable.
2022-01-20 09:26:01 +09:00
Bill Currie
30008aeb13 [qfcc] Fix a missed address expression conversion
Found while testing operator renaming.
2022-01-20 00:42:29 +09:00
Bill Currie
105d57f5e7 [qfcc] Improve handling of type names as variables
This is allowed in C so long as the scopes are different.
2022-01-19 23:17:49 +09:00
Bill Currie
07c4d28638 [qfcc] Handle bare "short"
Missed this case in duplicate_type. Allows "short foo" and
"sizeof(short)" (even though qfcc and the engine have two ideas of the
size: I expect trouble later).
2022-01-19 21:23:11 +09:00
Bill Currie
9f42cf726b [qfcc] Clean up duplicate specifier check code
I don't like the name, but having two identical copies of code is never
a good thing, especially something that big.
2022-01-19 21:20:31 +09:00
Bill Currie
df890432b7 [qfcc] Add support for unsigned, long, etc
long is ignored for double, and v6p progs are stuck with 32 bits for
longs (don't feel like extending v6p any further), but the basics are
there for Ruamoko.

short is ignored for ints because the minimum size is 32, and signed is
just noise for ints anyway (and no chars, so...).

unsigned, however, is finally implemented properly (or at least seems to
be working correctly: tests pass after getting things compiling again,
and lt.u is used where it should be :)
2022-01-19 18:08:58 +09:00
Bill Currie
e11fa77a34 [qfcc] Use pr_type_names to generate is_TYPE
This means basic types will always have a check function automatically.
2022-01-19 18:07:54 +09:00
Bill Currie
380cb3ba7f [qfcc] Clean up the type tables for binary expressions
More index labels and remove the null entries since they're not needed
with the labels.
2022-01-19 10:52:07 +09:00
Bill Currie
17add5e00f [qfcc] Use pr_type_names to create basic type defs
This takes care of the type structs and the ev_* to type map.
2022-01-18 22:59:53 +09:00
Bill Currie
57fe669099 [qfcc] Shorten type_function and type_pointer names
To type_func and type_ptr to match the ev type names.
2022-01-18 22:34:52 +09:00
Bill Currie
068c04ece6 [gamecode] Add ev_ushort and partial support
Really, only just enough to get everything compiling (which does include
vkgen running correctly).
2022-01-18 22:08:37 +09:00
Bill Currie
6df79b2b06 [qfcc] Correct xdef structures and usage in test
Attempting to add ev_ushort caused ptraliasenc to break, but that was
because it was already broken: I had implemented the scan of the xdef
table incorrectly, thus adding only 1 ev type resulted in the walked
pointer being out of phase with its data due to it first passing over
the type encodings (which is why adding long and ulong didn't cause any
obvious trouble).
2022-01-18 21:42:53 +09:00
Bill Currie
5b97aa3897 [qfcc] Use index labels for the type arrays
The one place that needed it most... constfold.c
2022-01-18 21:22:18 +09:00
Bill Currie
cd30408675 [gamecode] Rename ev_quat to ev_quaternion
I much prefer the full name, though the short version is easier to type.
2022-01-18 17:05:12 +09:00
Bill Currie
e9e54d08c0 [gamecode] Rename func_t to pr_func_t
Even more consistency.
2022-01-18 15:36:58 +09:00
Bill Currie
afd1eb775b [gamecode] Rename ev_pointer to ev_ptr
Rather short (no worse than ev_int, though) but more consistency is
usually a good thing.
2022-01-18 14:36:06 +09:00
Bill Currie
cfe7c44df0 [gamecode] Rename ev_integer to ev_int
And other related fields so integer is now int (and uinteger is uint). I
really don't know why I went with integer in the first place, but this
will make using macros easier for dealing with types.
2022-01-18 13:27:19 +09:00
Bill Currie
2df64384c1 [gamecode] Clean up string_t and pointer_t
They are both gone, and pr_pointer_t is now pr_ptr_t (pointer may be a
little clearer than ptr, but ptr is consistent with things like intptr,
and keeps the type name short).
2022-01-18 12:11:14 +09:00
Bill Currie
0bd05c71ac [gamecode] Use unsigned for entity values
I don't know why they were ever signed (oversight at id and just
propagated?). Anyway, this resulted in "unsigned" spreading a bit, but
all to reasonable places.
2022-01-16 22:15:18 +09:00
Bill Currie
66528e34fc [qfcc] Give return expressions their own type
Very simple for now (just the return value if not a void return), but
that's the last of the statements masquerading as expressions.
2022-01-09 16:28:08 +09:00
Bill Currie
563de20208 [qfcc] Give branch expressions their own type
This includes calls and unconditional jumps, relative and through a
table. The parameters are all lumped into the one object, with some
being unused by the different types (eg, args and ret_type used only by
call expressions). Just having nice names for the parameters (instead of
e1 and e2) makes it nice, even with all the sub-types lumped together.

No mysterious type aliasing bugs this time ;)
2022-01-09 14:02:16 +09:00
Bill Currie
4111d44dcc [gamecode] Move progs auxiliary headers into a subdirectory
Just another step along the road of tidying up the QF include directory
(and desirable for generated data).
2022-01-09 00:26:52 +09:00
Bill Currie
63795e790b [qfcc] Clean out some old code
The move operator names are definitely obsolete (due to dropping the
expressions a year or two ago) and the precedence checks seem to be
handled elsewhere. Memset and state expressions went away a while back
too.
2022-01-08 21:21:31 +09:00
Bill Currie
14352ea65a [qfcc] Really fix those type aliasing bugs
Found the cause: revered to wrong case for template code :/
2022-01-08 18:49:35 +09:00
Bill Currie
62d58a2255 Revert "[qfcc] Fix another type aliasing bug"
This reverts commit d14f695c68.

Found the cause: revered to wrong case for template code
2022-01-08 18:48:54 +09:00
Bill Currie
134f5ca6a4 Revert "[qfcc] Fix some type aliasing bugs"
This reverts commit da210db720.

Found the cause: revered to wrong case for template code
2022-01-08 18:48:23 +09:00
Bill Currie
65b6c366c3 [qfcc] Give assignment expressions their own type
This is getting easier (know where to look, I guess). Nicely, I found
the source of those weird type aliasing bugs :)
2022-01-08 18:44:29 +09:00
Bill Currie
d14f695c68 [qfcc] Fix another type aliasing bug
This one exposed by the address expression cleanup.
2022-01-08 16:54:08 +09:00
Bill Currie
fa482e8ee5 [qfcc] Give address expressions their own type
Definitely a pain to get working after the switch, but definitely worth
the effort. Still exposing type aliasing bugs.
2022-01-08 16:52:24 +09:00
Bill Currie
cf8061c4d3 [qfcc] Mark opcode_get as pure
Because gcc told me to :P
2022-01-08 12:14:27 +09:00
Bill Currie
da210db720 [qfcc] Fix some type aliasing bugs
I have no idea why sorting out expression aliasing exposed these type
aliasing bugs, but it did. All tests *build* again (and pass).
2022-01-08 12:10:30 +09:00
Bill Currie
23c9a317f8 [qfcc] Give alias expressions their own type
While this was a pain to get working, that pain only went to prove the
value of using proper "types" (even if only an enum) for different
expression types: just finding all the places to edit was a chore, and
easy to make mistakes (forgetting bits here and there).

Strangely enough, this exposed a pile of *type* aliasing bugs (next
commit).
2022-01-08 12:06:52 +09:00
Bill Currie
420d55406f [qfcc] Add a rule to build the qfcc tests
This makes it easier to build and run (by hand) the tests when things
aren't working.
2022-01-08 03:09:15 +09:00
Bill Currie
f5be54b6d2 [qfcc] Sanitize expr type enum
Got tired of dealing with out of date string tables.
2022-01-07 23:12:20 +09:00
Bill Currie
479d82f380 [qfcc] Create separate instruction init and lookup
v6 vs v6p are more or less as before, with ruamoko added in. qfcc will
now try (and fail, due to the opcode table opnames being wrong) to
create ruamoko progs when given the ruamoko target option.
2022-01-07 19:56:15 +09:00
Bill Currie
14d95f81d1 [gamecode] Remove PR_Opcode_Init
It was idempotent, then it became impotent. Now it's just not needed.
2022-01-07 19:25:34 +09:00
Bill Currie
7e303a1151 [qfcc] Hide details about instruction type
At this stage, I doubt emit.c will need to know the details of the
target (v6, v6p, ruamoko) since the instruction formats are identical,
just different meanings for the opcode itself.
2022-01-07 19:05:26 +09:00
Bill Currie
d9ccf3a394 [qfcc] Remove a pile of stale externs
Those opcode pointers haven't been used for years.
2022-01-07 18:54:59 +09:00
Bill Currie
2d245b8cdc [qfcc] Replace [no-]v6only with target=
This allows v6, v6p (older QF VM) or ruamoko (new QF VM) to be targeted.
Currently defaults to v6p to allow QF to continue building without too
much hassle.
2022-01-07 18:34:05 +09:00
Bill Currie
fe153b5b22 [qfcc] Add progs version to qfo and check in linker
While qfcc dealing sensibly with mixed target VMs in the object files
has always been an outstanding issue, with the new instruction set it
has become a priority. Most importantly, this should allow QF to
continue building while I work on qfcc targeting the new IS.
2022-01-07 17:56:05 +09:00
Bill Currie
c96cb1f302 [qfcc] Fix some stale documentation comments
It does little good for documentation to refer to fields that don't
exist (because a certain someone forgot to change the docs when changing
the field names, I wonder who :P).
2022-01-07 15:59:06 +09:00
Bill Currie
c9b2a740a0 [gamecode] Add etypes for long and ulong
And partial implementations in qfcc (most places will generate an
internal error (not implemented) or segfault, but some low-hanging fruit
has already been implemented).
2022-01-05 22:32:07 +09:00
Bill Currie
8a2788c267 [gamecode] Add PROG_V6P_VERSION and bump PROG_VERSION
This allows the VM to select the right execution loop and qfcc currently
still produces only the old IS (it doesn't know how to deal with the new
IS yet)
2022-01-03 13:56:43 +09:00
Bill Currie
0c17c6dc24 [gamecode] Rename the old opcodes
To reflect their basis on v6 progs instructions, they sport the v6p tag
where the p is for "plus" due to the QuakeForge extensions.
2022-01-02 21:30:02 +09:00
Bill Currie
f56fd6ffb6 [qfcc] Preserve requested alignment if larger
build_struct was unconditionally setting the type's alignment. This was
not a problem before because no types were requesting alignments larger
than those requested by their members (for structs). However, with the
upcoming new instruction set, quaternions need to be 4-word aligned.
2022-01-02 11:44:48 +09:00
Bill Currie
365762b8a6 [gamecode] Switch to using indexed initializers
The opcode table is a nightmare to maintain, but this does clean it up
and speed up opcode lookups since they can now be indexed. Of course, it
turns out I had missed adding several instructions, so had to fix that,
and qfcc needed a bit of a re-jigger to get the opcode out of the table.
2021-12-31 19:16:02 +09:00
Bill Currie
be474d9937 [gamecode] Remove the wart from def and function names
I never liked the leading s_ (though I guess it means one is supposed to
interpret the int as a string pointer, but meh).
2021-12-31 15:02:31 +09:00
Bill Currie
44c48feb56 [qfcc] Add attached node's parents to source edges
The assignment to the node's variable must come after any uses of that
node, which the node's parent set indicates. In the swap test, this was
not a problem as the node had no parents, and in the link order test, it
just happened(?) to work.
2021-12-28 09:23:14 +09:00
Bill Currie
8433905015 [qfcc] Extend reachable to the label node's parents
While using just the label node's reachable set was sufficient for a
simple swap (t = a; a = b; b = t;), it is not sufficient for
read-before-write dependencies such as found in linked-list building:

    { o = array[ind]; o.next = obj; obj = o; }

The assignment to o.next uses obj, but that use is hidden because obj's
reachable nodes does not include o thus assigning o to obj causes the
array dereference to be assigned directly to obj and thus o.next winds
up pointing to o instead of whatever obj was. The parent nodes of obj's
node are its users, so any new assigned to obj must come after those
parents as well as any node reachable by obj's node.

Fixes a runaway loop error when adding a frikbot to the server.
2021-12-27 14:25:55 +09:00
Bill Currie
4ad84b3786 [qfcc] Add a test for use/write dependencies
I ran into this with frikbot causing an infinite loop due to incorrectly
linked objects.
2021-12-27 14:17:12 +09:00
Bill Currie
44dd183d55 [qfcc] Make it a little easier to see extra info
instead of having to find an #if 0, just uncomment the define.
2021-12-27 14:15:51 +09:00
Bill Currie
95991e0d77 [qfcc] Check switch test expression early
Avoids a segfault when the test expression has errors.
2021-12-27 00:47:35 +09:00
Bill Currie
3059aa7979 [qfcc] Preserve input qfo data in qfo_to_progs
qfo_to_progs was modifying the space data pointers in the input qfo,
making it impossible to reuse the qfo. However, qfo_relocate_refs needs
the updated pointers, thus do a shallow copy of the qfo and its spaces
(but not any of the data)
2021-12-27 00:27:15 +09:00
Bill Currie
dcf8beeccc [qfcc] Remove a union wart from qfo_mspace_t 2021-12-26 20:37:01 +09:00
Bill Currie
1d3970bc38 [qfcc] Allow extern builtin function declarations
build_builtin_function does the right thing, and it was only legacy
syntax functions that were affected anyway. Certainly, external
variables should not be initialized, but klik uses @extern { } wrapped
around several builtin functions and I had added the feature to allow
just this as it is rather convenient.
2021-12-26 15:01:38 +09:00
Bill Currie
22c67fc268 [qfcc] Use flow analysis for dealloc check
I decided that the check for whether control reaches the end of the
function without performing some necessary action (eg, invoking
[super dealoc] in a derived -dealoc) is conceptually the return
statement using a pseudo operand and the necessary action defining that
pseudo operand and thus is the same as checking for uninitialised
variables. Thus, add a pseudo operand type and use one to represent the
invocation of [super alloc], with a special function to call when the
"used" pseudo operand is "uninitialised".

While I currently don't know what else pseudo operands could be used
for, the system should be flexible enough to add any check.

Fixes #24
2021-12-25 17:04:26 +09:00
Bill Currie
f903211362 [qfcc] Make operand union anonymous
This one was easy enough and gets rid of that little o. wart.
2021-12-25 12:40:24 +09:00
Bill Currie
7c24f116b4 [qfcc] Rename tmpaddr to pseudo_addr
I want to use the function's pseudo address that was used for managing
aliased temporary variables for other pseudo operands as well. The new
name seems to better reflect the variable's purpose even without the
other pseudo operands as temporary variables are, effectively, pseudo
operands until they are properly allocated.
2021-12-25 12:21:59 +09:00
Bill Currie
79b760b1d0 [qfcc] Add failing test for multi-path dealloc
This test checks for control reaching the end of the function without
invoking [super dealloc] in all paths.
2021-12-24 22:45:43 +09:00
Bill Currie
8385046486 [qfcc] Warn when super dealloc invocation is missing
Forgetting to invoke [super dealloc] in a derived class's -dealloc
method has caused me to waste far too much time chasing down the
resulting memory leaks and crashes. This is actually the main focus of
issue #24, but I want to take care of multiple paths before I consider
the issue to be done.

However, as a bonus, four cases were found :)
2021-12-24 22:45:43 +09:00
Bill Currie
ff1cdb6f89 [qfcc] Give select expressions their own type
While get_selector does the job of getting a selector from a selector
reference expression, I have long considered lumping various expression
types under ex_expr to be a mistake. Not only is this a step towards
sorting that out, it will make working on #24 easier.
2021-12-24 22:45:43 +09:00
Bill Currie
bdd3870d2f [qfcc] Add failing test for dealloc warning
I have gotten tired of chasing memory leaks caused by me forgetting to
add [super dealloc] to my dealloc methods, so getting qfcc to chew me
out when I do seems to be a good idea (having such a warning would have
saved me many hours, just as missing return warnings have).
2021-12-24 22:45:43 +09:00
Bill Currie
bdc9e9c39f [qfcc] Unalias types before checking for equality
Fixes a bogus redefinition when going from struct declaration to
typedef.
2021-12-24 06:45:13 +09:00
Bill Currie
3b1acf8a7b [qfcc] Correct some errors in the man page 2021-11-29 11:38:54 +09:00
Bill Currie
7ed12e2f37 [qfcc] Fix static function declarations
I'm surprised it took this long for static not working to cause a
problem.
2021-09-24 19:49:55 +09:00
Bill Currie
6144100d9b [qfcc] Check init exists before checking compound
Fixes a segfault that occurred during a parse error in a def
initializer.
2021-09-24 19:44:14 +09:00
Bill Currie
49c3dacbbc [util] Rename set_size to set_count
After seeing set_size and thinking it redundant (thought it returned the
capacity of the set until I checked), I realized set_count would be a
much better name (set_count (node->successors) in qfcc does make much
more sense).
2021-07-27 11:52:21 +09:00
Bill Currie
342ba65f57 [qfcc] Handle aliased field types
Fixes use of structs as entity fields. The test is currently
compile-only.
2021-07-24 18:09:54 +09:00
Bill Currie
6b38a17cf1 [gamecode] Clean up state imlementations
This makes the code easier to read. Also, yay for automated tests:
caught a mistyped time :)
2021-07-15 16:55:02 +09:00
Bill Currie
ef6dd422e5 [qfcc] Add source line number to statement blocks
For statement dot blocks.
2021-07-06 18:06:47 +09:00
Bill Currie
ddc6f6bcb0 [qfcc] Un-dereference src expression early for movep
The VM has no pointer to direct reference move instruction.

Fixes #9
2021-06-30 20:05:27 +09:00
Bill Currie
9d140d1d15 [qfcc] Use {>...} for unnamed alias types
The ... is the encoding of the aliased type. Avoids (null) in the
encoding. Fixes #10.
2021-06-30 11:00:05 +09:00
Bill Currie
a3aebc983b [qfcc] Add dependency edges for moved labels
When moving an identifier label from one node to another, the first node
must be evaluated before the second node, which the edge guarantees.
However, code for swapping two variables

    t = a; a = b; b = t;

creates a dependency cycle. The solution is to create a new leaf node
for the source operand of the assignment. This fixes the swap.r test
without pessimizing postop code.

This takes care of the core problem in #3, but there is still room for
improvement in that the load/store can be combined into a move.
2021-06-29 14:42:16 +09:00
Bill Currie
76b3bedb72 [qfcc] Revert "Kill dag leaf nodes on assignment."
This reverts commit 2fcda44ab0.

Killing the node is not the correcgt answer as it blocks many
optimization opportunities. The correct answer is adding edges to
describe the temporal dependencies. Of course, this breaks the swap.r
test.
2021-06-29 12:09:35 +09:00
Bill Currie
5291cfb03d [qfcc] Keep track of reachable dag nodes
In order to correctly handle swap-style code

    { t = a; a = b; b = t; }

edges need to be created for each of the assignments moving an
identifier lable, but the dag must remain acyclic (the above example
wants to create a cycle). Having the reachable nodes recorded makes
checking for potential loops a quick operation.
2021-06-29 09:41:03 +09:00
Bill Currie
0d1fad12f0 [qfcc] Add some comments 2021-06-29 09:12:57 +09:00
Bill Currie
d50f2c3145 [qfcc] Correctly check for constant op
Identifiers can be constants. I don't remember quite what it fixed other
than some bogus kill relations in the dags (which might have caused
issues later).
2021-06-28 20:25:26 +09:00
Bill Currie
38a6ccdc85 [qfcc] Use indexed initializers for expr functions
This will make adding new expression types easier (though the current
reason for doing so has been abandoned for now).
2021-06-28 18:12:15 +09:00
Bill Currie
365e298908 [qfcc] Make internal_error const correct
This way it can be used with const expr objects.
2021-06-28 18:12:15 +09:00
Bill Currie
13b4b44e35 [qfcc] Handle l and ll integer suffixes
They're ignored, but allow recent vulkan headers to compile.
Fixes #13
2021-06-13 13:25:18 +09:00
Bill Currie
927a446bd3 [qfcc] Ensure type src type is a class
If the src type is not a class, there is no inheritance chain to walk.
Fixes a segfault when returning self after a syntax error in the
following:

    +(EditStatus *)withRect:(Rect)rect
    {
	return [[[self alloc] initWithRect:rect]:
    }

    -setCursorMode:(CursorMode)mode
    {
	cursorMode = mode;
	return self;
    }
2021-06-09 12:08:13 +09:00
Bill Currie
88c9517629 [qfprogs] Dump class ivars when dumping modules 2021-06-04 14:59:15 +09:00
Bill Currie
88ff254f42 Get QF cross-compiling using MXE/mingw32
This includes -win clients (no clue if anything actually works yet).
2021-03-27 20:09:37 +09:00
Bill Currie
a9bd436837 [build] Autoconfiscate printf format attribute
I don't know if gnu_printf is appropriate for all cases, but it is
needed for mingw32.
2021-03-27 19:52:59 +09:00
Bill Currie
238e80c89b [build] Fix selective build of tools
A couple of things get built when they shouldn't (eg, vkgen) but this
gets the build system back to its pre-non-recursive-make
configurability.
2021-03-26 16:11:29 +09:00
Bill Currie
c9f1d770e0 Merge master into csqc-improvements
That was a mess
2021-03-25 22:01:31 +09:00
Bill Currie
66fda1fddb Rewrite edict access.
The server edict arrays are now stored outside of progs memory, only the
entity data itself (ie data accessible to progs via ent.fld) is stored in
progs memory. Many of the changes were due to code accessing edicts and
entity fields directly rather than through the provided macros.
2021-03-25 18:13:48 +09:00
Bill Currie
bc763da9f6 [qfcc] Fix a typo in the man page 2021-02-09 15:02:22 +09:00
Bill Currie
84dc73da2c [test] Get the tests building again
They happen to all pass, which is nice :)
2021-02-05 21:43:12 +09:00
Bill Currie
0bfb60775e [util] Ensure hunk allocs are cache alligned
This doesn't seem to make much difference in the vulkan renderer, but it
certainly doesn't hurt.
2021-02-03 13:19:19 +09:00
Bill Currie
7970525ef4 [util] Make va thread-safe
It now takes a context pointer (opaque data) that holds the buffers it
uses for the temporary strings. If the context pointer is null, a static
context is used (making those uses of va NOT thread-safe). Most calls to
va use the static context, but all such calls have been formatted
consistently so they are easy to find when it comes time to do a full
audit.
2021-01-31 16:05:48 +09:00
Bill Currie
c7da999b6a [qfcc] Use local_expr only for local variables
ie, not function-scope static variables.
2021-01-13 18:08:30 +09:00
Bill Currie
1205c935d0 [qfcc] Add failing test for static init
The function local static init is being treated as a non-static init
(ie, initialized each call).
2021-01-13 16:47:49 +09:00
Bill Currie
0c1699fdbb Fix a pile of double semicolons 2021-01-09 20:42:23 +09:00
Bill Currie
0426879bf6 [qfcc] Check returned type instead of expr type
Block expressions hide ex_error, but get_type() always returns null when
it finds one (which it does by recursing into block expression), so just
check the type itself.
2021-01-04 14:54:04 +09:00
Bill Currie
ab04a1915e [build] Fix a pile of gcc 10 issues
gcc got stricter about array accesses, complicating progs macros, and
much better at detecting buffer overflows.
2020-12-21 14:14:29 +09:00
Bill Currie
4a8818f0b6 [qfcc] Clean up some excess includes 2020-08-17 14:36:08 +09:00
Bill Currie
550b9c3bb2 [qfcc] Fix silent make rules flex and bison 2020-08-17 14:35:20 +09:00
Bill Currie
f544a6f0b0 [qfcc] Treat null method return type as id
This prevents a segfault when the method's return type is undefined.
2020-07-05 16:53:35 +09:00
Bill Currie
aa8aaaaca9 [build] Support silent rules for qfcc 2020-06-26 10:52:06 +09:00
Bill Currie
ed42557dd1 [qfcc] Reset flowvars for aliased global variables
When a global variable is accessed via only an alias in a function the
actual def's flowvar would remain in the state it was from the last
function that accessed the global normally. This would result in invalid
flowvar accesses which can be difficult to reproduce (thus no test
case).
2020-06-25 22:45:12 +09:00
Bill Currie
6d5ffa9f8e [build] Move to non-recursive make
There's still some cleanup to do, but everything seems to be working
nicely: `make -j` works, `make distcheck` passes. There is probably
plenty of bitrot in the package directories (RPM, debian), though.

The vc project files have been removed since those versions are way out
of date and quakeforge is pretty much dependent on gcc now anyway.

Most of the old Makefile.am files  are now Makemodule.am.  This should
allow for new Makefile.am files that allow local building (to be added
on an as-needed bases).  The current remaining Makefile.am files are for
standalone sub-projects.a

The installable bins are currently built in the top-level build
directory. This may change if the clutter gets to be too much.

While this does make a noticeable difference in build times, the main
reason for the switch was to take care of the growing dependency issues:
now it's possible to build tools for code generation (eg, using qfcc and
ruamoko programs for code-gen).
2020-06-25 11:35:37 +09:00
Bill Currie
31abf6f955 [qfcc] Fix some wrong fall-through cases
This fixes the unary minus issue for now. unary_expr needs a rewrite,
though: it's just horrible.
2020-04-08 21:23:57 +09:00
Bill Currie
d5604aef73 [qfcc] Add failing test for unary minus
Producing a void type... very odd.
2020-04-08 21:12:56 +09:00
Bill Currie
2bec2527b4 [gamecode] Re-expose PR_LoadStrings
It's required for qfprogs now that PR_LoadDebug reads strings early.
2020-04-04 14:33:49 +09:00
Bill Currie
7c5c462587 [qfcc] Write debug data space to sym file
This should keep things nicely extensible, since additional data can be
done in the data space and found using defs. This gets the compilation
units into the sym file.
2020-04-03 21:25:47 +09:00
Bill Currie
9400b9b115 [qfcc] Add a leading . to the compile_unit def 2020-04-03 19:56:07 +09:00
Bill Currie
453c646d85 [qfcc] Improve dependency checks for tests
They worked well if there was only one source file in the test, but
failed if there were two or more. While only typelinker needed the
enhanced macros, I got them all because I generally copy the nearest
block when adding a new test thus it's best if they're all "correct".
2020-04-03 19:54:25 +09:00
Bill Currie
718f243f69 [qfcc] Relocate loose string relocs when linking
This helps make partially linked object files make more sense when
looking at strings in data spaces.
2020-04-03 15:58:22 +09:00
Bill Currie
049b8f392c [qfcc] create a compilation unit for debug data
The compilation unit stores the directory from which qfcc was run and
any source files mentioned. This is similar to dwarf's compilation unit.
Right now, this is the only data in the new debug space, but more might
come in the future so it seems best to treat the debug space separately
in the object files.
2020-04-03 15:07:13 +09:00
Bill Currie
65e7df44d3 [qfcc] Add function to see if a string is in a pool
Makes for a nice string set.
2020-04-03 14:22:44 +09:00
Bill Currie
9089744290 [qfcc] Add a function to safely get cwd
getcwd is assumed to use malloc if its buff param is null. This may need
fixing in the future, but it's in one spot. The result in "saved" in the
non-progs pool.
2020-04-03 14:22:31 +09:00
Bill Currie
4b34bf3d95 [qfcc] Take optional space param for emit_structure
If the space param is null, the far data space is used.
2020-04-03 14:16:16 +09:00
Bill Currie
f8d9b720de [qfcc] Free data spaces between compiliations 2020-04-03 14:14:34 +09:00
Bill Currie
d69db50cf9 [qfcc] Remove path stripping
It never really helped sort out the path issues when using build
directories. It worked well enough for single directory projects, but
things got messy very quickly, especially when mixing ruamoko libs with
external progs. A better method based on dwarf is coming.
2020-04-03 00:50:06 +09:00
Bill Currie
5d06596814 [qfcc] Fix test harness after .ctor change 2020-04-03 00:20:39 +09:00
Bill Currie
a09eabeb4d [qfcc] Fix some const attribute warnings
Try to anticipate gcc's warnings and it one-ups you :P
2020-04-01 21:17:13 +09:00
Bill Currie
17bb408b57 [qfcc] Clean up stray dags edges
Killed nodes can leave stray (dangling) edges that cause some confusion
in the dot graphs and may cause problems later on down the track, so
ensure there are no dangling edges.
2020-04-01 16:06:45 +09:00
Bill Currie
199b3e82d9 [qfcc] Add killer node to replacement node's edges
When an operand refers to a killed node, it needs to be evaluated AFTER
the killing node is evaluated. This fixes the double-alias bug.
2020-04-01 16:05:26 +09:00
Bill Currie
4c79c9ffaf [qfcc] Do a dags pre-pass to give operands leafs
The reason double-alias fails is when the double assignment occurs, the
int operands don't yet have leaf nodes and thus the nodes cannot be
killed. This doesn't fix the bug.
2020-04-01 16:03:12 +09:00
Bill Currie
842125faf8 [qfcc] Add a failing test for aliased live vars
I'm not sure if it's due more to doubles or unions, but the bug was
found via double. It seems the dags code generator doesn't see that the
assignment to the union's double field kills the two int fields.

The test passes when NOT optimizing.
2020-04-01 13:49:58 +09:00
Bill Currie
dff0fd983c [qfcc] Fix missed t enum cleanup 2020-03-30 19:02:54 +09:00
Bill Currie
0de9b02726 [qfcc] Catch declarations of arrays of class
They're still static instances.
2020-03-30 19:02:41 +09:00
Bill Currie
ddec80edc1 [qfcc] Make type encoding union anonymous
I'd do more, but things get messy with direct access to unions that I
want to be anonymous.
2020-03-30 11:10:05 +09:00
Bill Currie
d4de1d7418 [qfcc] Do full type encoding relocation early
Because type aliases need to be unaliased, the type pointers in the type
encodings need to be correct when it comes to linking defs and
functions. This fixes the linking errors in ruamoko/game.
2020-03-29 18:19:36 +09:00
Bill Currie
188a1ea105 [qfcc] Add more comments to the linker
It's a horribly hairy beast to understand, especially anything to do
with relocs and type encodings.
2020-03-29 18:18:27 +09:00
Bill Currie
c6d5ceab0e [qfcc] Make things clearer about relocated types
I was very uncertain about the validity of messing with the old type
encoding that way, but adding the check to ensure the type has been
processed never fired, so it seems ok. And the comments help me a lot :)
2020-03-29 16:47:45 +09:00
Bill Currie
62b6e95746 [qfcc] Show a marker at first unbound reloc 2020-03-29 14:54:28 +09:00
Bill Currie
361b3ff422 [qfcc] Treat alias nodes in alias-free branch as ICE 2020-03-29 11:49:07 +09:00
Bill Currie
218cca71b8 [qfcc] Take special care when aliasing aliased types
When aliasing a type that already has aliases, the top node needs to be
replaced if it is unnamed, or the alias-free branch of the new node
needs to reach around to the alias-free branch of the existing node.
This fixes the bogus param counts in qwaq.
2020-03-29 11:29:15 +09:00
Bill Currie
78962cb205 [qwaq] Use append_type in field/pointer/array_type
This fixes the missing alias chain splitter, allowing scheme to compile
again.
2020-03-29 10:27:16 +09:00
Bill Currie
6f871a8af9 [qfcc] Unalias def types before checking
This fixes the typelinker test, but not the linking error in
ruamoko/game that it was supposed to represent. I guess there's
something more going on (maybe type encoding relocation issues).
2020-03-29 00:58:02 +09:00
Bill Currie
8ba3ab89d5 [qfcc] Add failing aliased type linking test 2020-03-28 23:30:05 +09:00
Bill Currie
c13162e41e [qfcc] Rearrange type initialization
Fixes #6
It turned out that the problem with @zero was caused by initial type
chaining occurring before the structures had been initialized and thus
the linker's @zero type encoding string was incorrect: {?=} instead of
{tag @zero-}, thus when the actual type encoding supplied by an object
file came along (with the correct encoding string), it wasn't found.
2020-03-28 22:53:35 +09:00
Bill Currie
31ea3814bb [qfcc] Decouple type encoding from the pr struct
This will allow encoding types correctly in the linker.
2020-03-28 22:15:06 +09:00
Bill Currie
54a9305dbf [qfcc] Use right object for sizeof
Since the bitfield has been abandoned, can use sizeof on the field
again.
2020-03-28 22:02:42 +09:00
Bill Currie
ac9f3404ef [qfcc] Improve string quoting when dumping strings
Not knowing if a blank line is an empty string or spaces...
2020-03-28 21:46:46 +09:00
Bill Currie
1cd7bd2bf0 [qfcc] Use correct meta for zerolinker test
Still fails, of course :)
2020-03-28 21:31:04 +09:00
Bill Currie
7218af6be4 [qfcc] Print qfo def type address 2020-03-28 21:19:20 +09:00
Bill Currie
262c6a61f5 [qfcc] Add failing test for linker zero/param issue
This tests issue #6
2020-03-28 21:11:42 +09:00
Bill Currie
f224eadbb8 [qfcc] Rework QuakeC function type manging
It is now "consistent" with the rest of the type building in that it
uses find_type(append_type(return, params)) like the C version, thus
allowing append_type to do its thing with type aliases. This fixes the
overload test.
2020-03-28 19:01:49 +09:00
Bill Currie
b6ea47dca6 [qfcc] Add failing function overload test
This is a bit of a weird one because it's a combination of the aliasing
code and mixing C prototypes with QuakeC function definitions, and the
function type rebuilding in qc-parse.y not being very "consistent" in
its abuse of the type system.
2020-03-28 18:58:08 +09:00
Bill Currie
eacdd0d3de [qfcc] Make file_basename accessible and more usable 2020-03-28 18:55:51 +09:00
Bill Currie
69037fe5eb [qfcc] Strip alias info off function params
For now. This fixes many problems but does lose type aliasing info from
function parameters.
2020-03-28 18:55:51 +09:00
Bill Currie
da39e675b8 [qfcc] Copy type chain for type aliases
The full_type branch of an alias splitter (alias with null name) needs
to mirror the clean side up to the type alias. It is causing problems
with functions, but that's expected because parameters complicate
things.
2020-03-28 18:55:51 +09:00
Bill Currie
ec3c2426ff [qfcc] Add type dot dumping
It's not connected up yet because I'm unsure of just where to put things
(it gets messy fast), but just being able to see the structure of
complex types is nice.
2020-03-28 16:22:44 +09:00
Bill Currie
8479cad8a8 [qfcc] Record alias-free type in function_t
This eases type unaliasing on functions a little.

Still more to to go, but this fixes a really hair-pulling bug: linux's
heap randomiser was making the typedef test fail randomly whenever
typedef.qfo was compiled.
2020-03-28 15:10:14 +09:00
Bill Currie
1eef2a8b5e [qfcc] Implement type aliasing again
When a type is aliased, the alias has two type chains: the simple type
chain with all other aliases stripped, and the full type chain. There
are still plenty of bugs in it, but having the clean type chain takes
care of the major issue that was in the previous attempt as only the
head of the type-chain needs to be skipped for type comparison.

Most of the bugs are in finding the locations where the head needs to be
skipped.
2020-03-28 12:10:23 +09:00
Bill Currie
734f10d43e [qfcc] Dump local defs for qfo functions 2020-03-28 12:06:34 +09:00
Bill Currie
e31f03fd36 [qfcc] Add type aliasing test again 2020-03-28 09:59:01 +09:00
Bill Currie
c6746fa391 [qfcc] Fix out-by-one in type meta check 2020-03-27 22:48:38 +09:00
Bill Currie
1da6eb5f51 [qfcc] Fix a typo in a comment 2020-03-27 22:17:36 +09:00
Bill Currie
653eabfdbf [qfcc] Clean up inconsistent type building idioms 2020-03-27 22:11:18 +09:00
Bill Currie
c6483b617c [qfcc] Remove obsolete notes
nil seems to have sorted himself out with the recent reworking of how
qfcc handles nil.
2020-03-27 20:52:37 +09:00
Bill Currie
4d616fab4a [qfcc] Use the correct statement type for memset 2020-03-27 20:47:42 +09:00
Bill Currie
fdf6fac077 [qfcc] Rewrite expr_nil to use memset if necessary
This fixes the problem with returning nil through @param (and probably
structs in general).
2020-03-27 20:32:52 +09:00
Bill Currie
9c556c07bb [qfcc] Add failing nil return through @param bug
I suspect it's general for struts, but nil really is a troubling
character sometimes.
2020-03-27 20:32:52 +09:00
Bill Currie
9e529d1508 [qfcc] Fix some incorrect test runs
Checking for float return when should be checking for int return.
Fortunately, the tests still passed.
2020-03-27 20:32:52 +09:00
Bill Currie
01cf28e436 [qfcc] Treat C-style function decls as prototypes
This removes the need for extern from the declaration.
2020-03-27 18:08:26 +09:00
Bill Currie
643711ef40 [qfcc] Pre-initialize type_object's strct pointer
This ensures that pointers to incomplete struct types are not
misidentified as id before the class system has been initialized.
2020-03-27 17:29:42 +09:00
Bill Currie
498dfdbfef [qfcc] Clean up Obj-QC type struct names
I decided that the obj_ tag was unnecessary.
2020-03-27 15:33:53 +09:00
Bill Currie
ab3d91f0c3 [qfcc] Clean up simple type checking
All simple type checks are now done using is_* helper functions. This
will help hide the implementation details of the type system from the
rest of the compiler (especially the changes needed for type aliasing).
2020-03-27 15:16:41 +09:00
Bill Currie
8b1e4eea58 [qfcc] Bring back the core of type aliasing
No aliasing is done yet, but most of the infrastructure is there again.
2020-03-27 12:27:46 +09:00
Bill Currie
53fd55143e [qfcc] Fix missed none->basic rename 2020-03-27 12:26:44 +09:00
Bill Currie
75394cc4f8 [gamecode,qfcc] Use enums for type encoding types
The enums are forced to 32 bits via bitfield spec, so can't use sizeof
on them, but this makes switch enum checks work in gcc.
2020-03-27 12:24:14 +09:00
Bill Currie
4de2c6b30e [qfcc] Move alias expr inside call block expression
This fixes the trampled return value when the first expression aliases
the return result.
2020-03-26 20:16:52 +09:00
Bill Currie
98eac2afbc [qfcc] Hide dependency generation commands 2020-03-26 20:16:32 +09:00
Bill Currie
15d4186fff [qfcc] Show line numbers in block sub expressions
Seems more useful than expression index.
2020-03-26 20:15:50 +09:00
Bill Currie
5fd63b95db [qfcc] Add a new failing test
The struct alias is somehow blocking the detection of the call so the
return value gets corrupted.
2020-03-26 19:22:41 +09:00
Bill Currie
1f8cc7186c [qfcc] Hide "function" type behind an @
I'm not sure it's all that useful and thus it clutters the namespace.
2020-03-25 21:04:22 +09:00
Bill Currie
4cef9792f4 [util] Make hash-tables semi-thread-safe
They take a pointer to a free-list used for hashlinks so the hashlink
pools can be per-thread. However, hash tables that are not updated are
always thread-safe, so this affects only updates. progs_t has been set
up such that it is easy for multiple progs within one thread can share
hashlinks.
2020-03-25 15:43:16 +09:00
Bill Currie
9bfd14b687 [qwaq] Bring in qc gcd to use for debugger testing
It was even recent enough to compile first try.
2020-03-24 23:02:19 +09:00
Bill Currie
298fcbbf70 [qfcc] Add ExitCode support to quake-pascal
gcd now passes :)
2020-03-20 12:59:25 +09:00
Bill Currie
ed03eeb8d2 [qfcc] Resync qc and qp common symbols
Forgot I needed to remove PAS from pascal as well.
2020-03-20 12:59:25 +09:00
Bill Currie
f64038b872 [qfcc] Add gcd.pas to the tests 2020-03-20 12:59:25 +09:00
Bill Currie
7447854d7c [qfcc] Recover from syntax errors in abstract_decl 2020-03-19 11:01:26 +09:00
Bill Currie
4c6e1b7fc4 [qfcc] Fix some uninitialized variable warnings
I really wish gcc would catch more issues when not optimizing.
2020-03-18 01:51:52 +09:00
Bill Currie
0293d335d0 [qfcc] Mark known source def live for movep
This fixes ivar-struct-return (and qwaq).
2020-03-18 00:02:36 +09:00
Bill Currie
43ea34535e [qfcc] Make ivar-struct-return fail
It turns out that assignments to struct fields are not counted as live
when the whole struct is later used via a pointer move.
2020-03-17 23:39:17 +09:00
Bill Currie
22cd39c853 [qfcc] Mark ptr assignment offset as an operand
This fixes structptr. All current tests pass.
2020-03-17 23:05:57 +09:00
Bill Currie
578bf9a16f [qfcc] Set dag node value for movep
This fixes compilation of all tests. However, structptr still fails.
2020-03-17 22:54:27 +09:00
Bill Currie
34c9ec51bb [qfcc] Make opcode and statement type names available 2020-03-17 22:46:23 +09:00
Bill Currie
77806f4b1b [qfcc] Get dag code generation mostly working
There's an ICE in return-ivar, but assignchain passes let alone builds.
2020-03-17 22:35:36 +09:00
Bill Currie
16bda66785 [qfcc] Add more statement types for move/memset
They ease the statement checks between assign/move/memset and the
pointer versions (don't need all those strcmps)
2020-03-17 21:39:49 +09:00
Bill Currie
3c2f6c8447 [qfcc] Simplify flow_analyize_pointer_operand
and its usage. The parts of flow_analyze_statement that use it know
where the returned operand needs to go. Unfortunately, this breaks dags
pretty hard, but that's because dags needs to learn about the fancy
assignment-type statements.
2020-03-17 21:30:16 +09:00
Bill Currie
dec2e6249e [qfcc] Increase flow operand count to 5
MOVEP instructions have up to 5 operands: 2 pointers, the count, and 0-2
referenced variables (when known).
2020-03-17 21:24:12 +09:00
Bill Currie
fa2cbc72d8 [qfcc] Analyze tempop pointers in move/memset statements 2020-03-17 15:48:06 +09:00
Bill Currie
6ec92fb83b [qfcc] Point pointer tempop to the operand
It turns out I need the operand itself, not just the tempop.
2020-03-17 15:47:42 +09:00
Bill Currie
0de011d0bf [qfcc] Add some disabled additional statement info
It's a bit cluttered for normal debugging, but I haven't decided how to
make it optional just yet.
2020-03-17 15:23:24 +09:00
Bill Currie
c5cbe83f71 [qfcc] Initialize statement numbers to -1
This is to indicate the statement has not yet been flow analyzed.
2020-03-17 15:05:58 +09:00
Bill Currie
d02a01c282 [qfcc] Make tempop pointer strings more informative
Now that the address of a tempop can be taken, their op strings need to
be visible.
2020-03-17 15:05:58 +09:00
Bill Currie
441e7b99bc [qfcc] Correctly implement pointer arithmetic 2020-03-17 13:39:22 +09:00
Bill Currie
c5400c4581 [qfcc] Make anonstruct test robust against pointer math
I noticed that pointer math is currently incorrect in qfcc, but it would
be nice for fixing it to not break anonstruct since it is testing
something else.
2020-03-17 12:16:24 +09:00
Bill Currie
0d784d9ef4 [qfcc] Rework address expr calculation
This removes a bogus lea from the instruction stream (and there can be
many such).
2020-03-17 12:13:09 +09:00