Commit graph

4117 commits

Author SHA1 Message Date
Bill Currie
0fa9d0d256 [qfcc] Tweak the printf to make more sense
Though I'm sure I had a good reason at the time, seeing 6.98487e-315
when expecting pi is a bit disconcerting.
2022-02-02 19:04:43 +09:00
Bill Currie
a64f91129f [qfcc] Give lea its own statement type
This makes it much easier to check (and more robust to name changes),
allowing for effectively killing the node to which the variable being
addressed is attached. This fixes the incorrect address being used for
va_list, which is what caused double-alias to fail.
2022-02-02 18:55:01 +09:00
Bill Currie
38550922cc [qfcc] Map 64-bit load/store/assign instructions
In order to not waste instructions, the Ruamoko ISA does not provide 1
and 2 component 64-bit load/store instructions since they can be
implemented using 2 and 4 component 32-bit instructions (load and store
are independent of the interpretation of the data). This fixes the
double test, and technically the double-alias test, but it fails due to
a problem with the optimizer causing lea to use the wrong reference for
the address. It also breaks the quaternion test due to what seems to be
a type error that may have been lurking for a while, further
investigation is needed there.
2022-02-02 16:06:15 +09:00
Bill Currie
93840d9892 [qfcc] Handle Ruamoko's call return destination
Since the call instruction in the Ruamoko ISA specifies the destination
of the return value of the called function, it is much like any
expression type instruction in that the def referenced by its c operand
is both defined and killed by the instruction. However, unlike other
instructions, it really has many pseudo-operands: the arguments placed
on the stack. The problem is that when one of the arguments is also the
destination of the return value, the dags code wants to use the stack
argument as it was the last use of the real argument. Thus, instead of
using the value of the child node for the result, use the value label
attached to the call node (there should be only one such label).

This fixes iterfunc, typedef, zerolinker and vkgen when optimizing. Now
all but the double tests and return postop tests pass (and the retun
postop test is not related to the Ruamoko ISA, so fails either way).
2022-02-01 21:46:28 +09:00
Bill Currie
9b81d27f1a [qfcc] Add test for var = func(var)
That is, updating a variable using a function that takes the same
variable, probably very common in iterators, thus the name. It happens
to be the first qfcc test specific to Ruamoko. It's really just the
typedef, zerolinker, and vkgen type encoding loop stripped down for ease
of debugging.

Of course, it fails :)
2022-02-01 21:40:59 +09:00
Bill Currie
4ec3486a4b [qfcc] Make lea generate a pointer operand
I really need to come up with a better way to get the result type into
the flow analyser. However, this fixes the aliasing ICE when optimizing
Ruamoko code that uses struct assignment.
2022-02-01 20:01:13 +09:00
Bill Currie
c84fb3e6d3 [qfcc] Use a hidden local variable for pascal functions
This gets gcd.pas working nicely with the Ruamoko ISA, and keeps things
reasonably nice vor v6p (it will likely do better with global CSE).
2022-02-01 16:08:58 +09:00
Bill Currie
fc56d1c6e2 [qfcc] Use dynamic addressing for Ruamoko move source
This fixes the incorrect pointer being used in movep instructions in
Ruamoko progs, as well as 3 of the test cases.
2022-02-01 14:57:16 +09:00
Bill Currie
e0c5c475ea [qfcc] Modify the modulo tests to be compatible with Ruamoko ISA
Surprisingly, it passes (I didn't expect it to due to the doubles). I'll
look into to it further later on.
2022-02-01 14:57:16 +09:00
Bill Currie
64c8c02eac [qfcc] Add pragma to control optimization
And force a couple of tests to be built with optimization. I'll probably
add it to most, if not all, but for now I'm clearing up tests as I go.
2022-02-01 14:57:16 +09:00
Bill Currie
b8c2b7f856 [ruamoko] Make a common sprintf wrapper function
This takes care of converting from progs varargs to what PR_Sprintf
expects. I got tired of modifying the wrappers when I found a third one.
2022-02-01 09:27:03 +09:00
Bill Currie
edf7a781fd [qfcc] Map uint to int for some intructions
Many math instructions don't care about the difference between signed
and unsigned operands and are thus specified using int, but need to be
usable with uint. div is NOT mapped because there is a difference:
0x8000 / 2 (16-bit) is 0x4000 unsigned but 0xc000 signed, and 0x8000 /
0xfffe is 0 unsigned and 0x4000 signed. This means I'll need to add some
more instructions. Not sure what to do about % and %% though as that's a
lot of instructions (12).
2022-01-30 22:47:57 +09:00
Bill Currie
8dc4a0ea80 [qfcc] Change v6p's jumpb opname to jump
More ease of searching, since the operand types help greatly.
2022-01-30 22:39:21 +09:00
Bill Currie
b8df11b2cb [qfcc] Really get vecaddr.r working on both ISAs
Deliberately defeating an optimiser is not so easy (but I really needed
that variable to be set).
2022-01-30 20:01:32 +09:00
Bill Currie
e1a0c31e3f [qfcc] Encode the new vector types
Thanks to the size of the type encoding being explicit in the encoding,
anything that tries to read the encodings without expecting the width
will simply skip over the width, as it is placed after the ev type in
the encoding.

Any code that needs to read both the old encodings and the new can check
the size of the basic encodings to see if the width field is present.
2022-01-30 16:00:49 +09:00
Bill Currie
4b8fdf3696 [qfcc] Implement vector scaling for Ruamoko
With this, qfcc-tests builds (can't run yet due to unsigned not having
any tests and thus the rest the Ruamoko code in QF not building yet).
2022-01-30 14:48:49 +09:00
Bill Currie
d18ee8dd86 [qfcc] Make vecaddr work in both v6p and Ruamoko
It's full of evil hacks, but has always been an evil hack relying on
undefined behavior. The weird shenanigans with local variables are
because Ruamoko doesn't copy the parameters like v6p does and thus v and
z are NOT adjacent as parameters. Worse, the padding is uninitialized
and thus should not be relied upon to be any particular value. Still
does a nice job of testing dot products, though.
2022-01-30 14:22:05 +09:00
Bill Currie
09eef8a07b [qfcc] Define __RUAMOKO__ as 2 for Ruamoko ISA
and __RAUMOKO__ as well.
2022-01-30 14:22:05 +09:00
Bill Currie
d8f6a9445e [qfcc] Implement dot and cross product for Ruamoko
With explicit operators, even. While they're a tad verbose, they're at
least unambiguous and most importantly have the right precedence (or at
least adjustable precedence if I got it wrong, but vector ops having
high precedence than scalar or component seems reasonable to me).
2022-01-30 14:14:15 +09:00
Bill Currie
e195dba626 [qfcc] Do not unalias temporary operands
I don't remember why I did this originally, but it causes the dags code
to lose the offset temp alias when accessing fields on structural temps
(known to be the case for vectors (temp-component.r), and I seem to
remember having problems with structs).
2022-01-30 14:02:13 +09:00
Bill Currie
218481764b [qfcc] Add failing test for temp.component
While it specifically checks vectors, I'm pretty sure it applies to
structs, too. Also, it's a little redundant with vecaddr.r, but is much
more specific and far less evil in what it does (no horrible pointer
shenanigans): just something that is fairly common practice.
2022-01-30 13:57:41 +09:00
Bill Currie
3f389b602a [qfcc] Add support for horizontal vector ops
And reimplement vector comparison for Ruamoko.
2022-01-30 10:56:15 +09:00
Bill Currie
feb3be4e6b [qfcc] Add types for ivec3/4 and vec3/4
Needed to get quaternions and vectors going. I'll add more later.
2022-01-30 10:54:07 +09:00
Bill Currie
5ba6bf02e8 [qfcc] Cast functions to ints for comparison
Yet more (non-)wasted instructions.
2022-01-29 18:59:38 +09:00
Bill Currie
61727941fd [qfcc] Prepend state epxression instead of just linking
This fixes an expression loop ICE when building for Ruamoko (not that
there actually was a loop, but the test is rather simplistic).
2022-01-29 18:57:48 +09:00
Bill Currie
fbaf1456fe [qfcc] Use auxiliary operands for move instructions
Since Ruamoko progs must use lea to get the address of a local variable,
add use/def/kill references to the move instruction in order to inform
flow analysis of the variable since it is otherwise lost via the
resulting pointer (not an issue when direct var reference move can be
used).

The test and digging for the def can probably do with being more
aggressive, but this did nicely as a proof of concept.
2022-01-29 18:26:54 +09:00
Bill Currie
f853a449b8 [qfcc] Cast pointers to ints for comparison
Ruamoko doesn't wast instructions on otherwise compatible low-level
types.
2022-01-29 18:23:07 +09:00
Bill Currie
501dd7db76 [qfcc] Use != nil for unary ! for Ruamoko progs
Ruamoko has no explicit ! instruction.
2022-01-29 18:22:41 +09:00
Bill Currie
7e9cf76cfe [qfcc] Change ne to cmp for v6 string inequality check
Since it's really strcmp in disguise (makes the instruction consistent
across all targets).
2022-01-29 18:18:33 +09:00
Bill Currie
baca7cbb4c [qfcc] Do not reverse function args in ruamoko call
It messed up the later check for calls to i[super dealloc].
2022-01-29 17:07:19 +09:00
Bill Currie
d61e906cb9 [qfcc] Don't use v6p store for assinging to entity.field
Ruamoko has a native addressing mode just for entities.
2022-01-29 17:05:50 +09:00
Bill Currie
54e079ab75 [qfcc] Fold int constants more aggressively
This code now reaches into one level of the expression tree and
rearranges the nodes to allow the constant folder to do its things, but
only for ints, and only when the folding is trivially correct (* and *,
+/- and +/-). There may be more opportunities, but these cover what I
needed for now and anything more will need code generation or smarter
tree manipulation as things are getting out of hand.
2022-01-29 15:38:39 +09:00
Bill Currie
284fcd312d [qfcc] Rewrite assignment destination addressing
It now addressing_mode cleaning up store instructions to use ptr+offset
instead of lea;store ptr...

Entity.field addressing has been impelmented as well.

Move instructions still generate sub-optimal code in that they use an
add instruction instead of lea.
2022-01-28 15:50:46 +09:00
Bill Currie
d3764c108a [qfcc] Rewrite expr_deref to use addressing_mode
This cleans up the generation of load instructions such that they use
ptr+offset addressing instead of lea;load ptr.
2022-01-28 15:42:06 +09:00
Bill Currie
e298f0d993 [qfcc] Break out pointer addressing
This allows the code handling simple pointer dereferences to recurse
along an alias chain that resulted from casting between different
pointer types (such chains could probably be eliminated by replacing the
type in the original pointer expression, but it wasn't worth it at this
stage).
2022-01-28 15:37:08 +09:00
Bill Currie
d28507eacf [qfcc] Reduce some alias chaining
Aliasing an alias expression to the same type as the original aliased
expression is a no-op, so drop the alias entirely in order to simplify
code generation.
2022-01-28 15:29:40 +09:00
Bill Currie
ec9fa3fee8 [qfcc] Clean up an unnecessary use of array_expr
Simply dereferencing a pointer does not need to go through array_expr
and thus collect a 0 offset that will only be constant-folded out again.
Really just a minor optimization in qfcc, but at one stage in today's
modification, it resulted in some unwanted aliasing chains.
2022-01-28 15:26:47 +09:00
Bill Currie
8d873a891f [qfcc] Make struct ptr access consistent with class ivar access
While this does make the generated code a little worse, load is behaving
nicely), the two are at least consistent with each other and when I fix
one, I'll fix both. I missed this change the other day when I did the
address_expr cleanup. Yay near-duplicate code :P
2022-01-28 09:25:53 +09:00
Bill Currie
7877168e93 [qfcc] Make a field name more clear
Just "type" isn't very informative, but "result_type" is at least a fair
bit better.
2022-01-27 23:29:32 +09:00
Bill Currie
f57aa82c4b [qfcc] Use an alias op for return_operand
This is what using new_ret_expr would result in, but new_ret_expr is no
longer used for referencing .return (except in pascal, but I haven't
gotten around to sorting that out) due to the recent changes for Ruamoko
progs. Fixes an ICE when compiling (with optimization) something like
the following (dir is a vector):

    dir /= sqrt (dir * dir);
    return dir * speed;
2022-01-27 23:24:43 +09:00
Bill Currie
82166406df [qfcc] Remove the def sorting (reverts 9a08a51ebd)
It turns out the sorting wasn't working properly and I've decided that
anything that actually needs the defs to be sorted by address (such as a
debugger searching for defs by address) can do the sorting itself. Fixes
a weird swapping of def names.
2022-01-27 16:43:43 +09:00
Bill Currie
4b4cb60c65 [qfcc] Check qfo target matches compile target
Linking mixed target VMs is unlikely to end well.
2022-01-27 13:24:21 +09:00
Bill Currie
0123e12304 [qfcc] Use locals and params_start to describe stack frame
This is necessary to get statement disassembly working, and likely
debugging in general. locals is the total size of the stack frame and
thus reaches above the function-entry stack pointer, and params_start is
the local space relative start of the parameters. Thus, knowing the
function-entry stack pointer, the bottom of the locals space can be
found by subtracting params_start, and the top of the locals space by
adding (locals - params_start).
2022-01-27 11:37:37 +09:00
Bill Currie
59ee723201 [gamecode] Rename parm to param
That misspelling bothered me from the very beginning, I'd always have
trouble getting the name right when trying to access one of those fields.
2022-01-27 10:55:06 +09:00
Bill Currie
169b8cc398 [qfcc] Rewrite qfo_to_progs offset/size calculation
This gets all the sections of the progs file nicely aligned and the code
easier to read with the offset and size calculations not being spread
through the function. ivar-struct-return now works when compiled for
Ruamoko.
2022-01-26 23:18:15 +09:00
Bill Currie
faa98d8198 [gamecode] Use a struct for offset/count pairs
This cleans up dprograms_t, making it easier to read and see what chunks
are in it (I was surprised to see only 6, the explicit pairs made it
seem to have more).
2022-01-26 19:30:25 +09:00
Bill Currie
a2fd42f174 [qfcc] Align progs memory to 32 bytes in the test harness
This ensures the engine can align everything to 32 bytes.
2022-01-26 16:57:34 +09:00
Bill Currie
90b40e7e52 [qfcc] Ensure adjstk and with always come first
While I think the reason the dags code moved an instruction before
adjstk and with was they shared a constant with that instruction (which
is a different bug), this ensures other instructions cannot get
reordered in front of adjstk and with, as doing so would cause any such
instructions to access incorrect data.
2022-01-26 15:50:04 +09:00
Bill Currie
0b9b6955aa [qfcc] Implement addressing modes for return
There's still entity.field to go, but basic def and ptr + const offset
seem to work.
2022-01-26 15:48:08 +09:00
Bill Currie
982a090143 [qfcc] Mask off base register bits when printing statements
Fixes a segfault when compiling Ruamoko progs with debug output.
2022-01-26 12:26:50 +09:00
Bill Currie
06d70a32db [qfcc] Rework the functionality of address expressions
The goal was to get lea being used for locals in ruamoko progs because
lea takes the base registers into account while the constant pointer
defs used by v6p cannot. Pointer defs are still used for gobals as they
may be out of reach of 16-bit addressing.

address_expr() has been simplified in that it no longer takes an offset:
the vast majority of the callers never passed one, and the few that did
have been reworked to use other mechanisms. In particular,
offset_pointer_expr does the manipulations needed to add an offset
(unscaled by type size) to a pointer. High-level pointer offsets still
apply a scale, though.

Alias expressions now do a better job of hanling aliasing of aliases by
simply replacing the target type when possible.
2022-01-25 23:39:17 +09:00
Bill Currie
e4bb5c8048 [qfcc] Add pragma to control warning promotion
This allows me to disable -Werror in the Makefile but still have the
build tests work properly and not fail when they shouldn't.
2022-01-25 22:15:28 +09:00
Bill Currie
40f5b8a482 [qfcc] Allow short constants in expr_int
No point in generating an internal error when the value can be converted
to an int.
2022-01-25 12:47:12 +09:00
Bill Currie
8d435040e6 [qfcc] Clean up some type checkes
Using the functions keeps the code a little easier to read.
2022-01-25 12:46:14 +09:00
Bill Currie
a1acdb8951 [qfcc] Print children of uexpr and return expressions
It's possible I lost the child printing when creating the return
expressions, but dot diagrams are much more useful when they don't have
nodes with just pointer values.
2022-01-25 12:29:15 +09:00
Bill Currie
fc73cfc1e0 [qfcc] Rename pointer_expr to deref_pointer_expr
This reflects what it actually does (usually, "pointer_expr" type naming
is creating an expression that represents a pointer).
2022-01-25 12:28:53 +09:00
Bill Currie
37f08f9d4f [qfcc] Build the Ruamoko function parameters
The parameter defs are allocated from the parameter space using a
minimum alignment of 4, and varargs functions get a va_list struct in
place of the ...

An "args" expression is unconditionally injected into the call arguments
list at the place where ... is in the list, with arguments passed
through ... coming after the ...

Arguments get through to functions now, but there's problems with taking
the address of local variables: currently done using constant pointer
defs, which can't work for the base register addressing used in Ruamoko
progs.

With the update to test-bi's printf (and a hack to qfcc for lea),
triangle.r actually works, printing the expected results (but -1 instead
of 1 for equality, though that too is actually expected). qfcc will take
a bit longer because it seems there are some design issues in address
expressions (ambiguity, and a few other things) that have pretty much
always been there.
2022-01-24 23:44:48 +09:00
Bill Currie
7e147e703c [qfcc] Copy def reg into alias def
This fixes incorrect local struct member access in Ruamoko progs.
2022-01-24 18:31:53 +09:00
Bill Currie
5cf7924352 [qfcc] Improve dags handling of auxiliary use ops
The aux use ops need to be counted and given nodes explicitly as they
may refer to defs that are not accessed by other statements other than
by aliases, and those aliases need to be marked live as well as the used
def.
2022-01-24 16:55:55 +09:00
Bill Currie
9fc8f14be6 [qfcc] Put the stack frame exprs into the statements block
dot_expr doesn't follow an expression's next pointer on its own.
make_statements was fine, which is why I didn't notice the mistake until
now.
2022-01-24 16:44:48 +09:00
Bill Currie
739c98fe21 [qfcc] Add adjstk and with to dot_expr
And be more informative with "bad" expression types (print the name if
it's just that I haven't added a printer for a valid type).
2022-01-24 16:42:13 +09:00
Bill Currie
1f802716e1 [qfcc] Pass initialize_def the symtab to use as a parameter
This takes care of an old FIXME.
2022-01-24 12:48:02 +09:00
Bill Currie
9c51c3d2e1 [gamecode] Add a data pointer passed to builtin functions
This is part of the work for #26 (Record resource pointer with builtin
function data). Currently, the data pointer gets as far as the
per-instance VM function table (I don't feel like tackling the job of
converting all the builtin functions tonight). All the builtin modules
that register a resources data block pass that block on to
PR_RegisterBuiltins.
2022-01-24 00:20:05 +09:00
Bill Currie
a6b932025c [gamecode] Provide builtins with information about their parameters
This will make it possible for the engine to set up their parameter
pointers when running Ruamoko progs. At this stage, it doesn't matter
*too* much, except for varargs functions, because no builtin yet takes
anything larger than a float quaternion, but it will be critical when
double or long vec3 and vec4 values are passed.
2022-01-23 22:27:27 +09:00
Bill Currie
e746e39738 [gamecode] Create macros for progs sizeof and alignof
I wound up needing the idioms in too many places.
2022-01-23 14:29:33 +09:00
Bill Currie
3c86660d4a [gamecode] Rename MAX_PARMS to PR_MAXPARAMS 2022-01-23 14:17:25 +09:00
Bill Currie
adf672e7b1 [qfcc] Mark the correct operand as used in stores
This fixes the lost-use test, and windows not dragging properly in
qwaq-curses. Another single-character bug-fix :P
2022-01-23 01:37:57 +09:00
Bill Currie
b6093e0728 [qfcc] Add failing test for lost var use
Storing a variable into a dereference pointer (*p = x) is not marking
the variable as used (due to a mistake while converting to Ruamoko
statement format) resulting in assignments to that variable being
dropped due to it being a dead assignment as the assignment to the
variable and the storing need to be in separate basic blocks (thus the
call in the test, though an if would have worked, I think) for the bug
to trigger.
2022-01-23 01:31:50 +09:00
Bill Currie
ec5830f70b [qfcc] "Use" the correct operands
The problem was a missed change when switching the internal statement
format to Ruamoko: I "used" the statement's operands directly rather
than the rotated ones when emitting v6p progs. Fixes a compile segfault
when NOT optimizing.
2022-01-23 00:59:38 +09:00
Bill Currie
9e4ecc14e9 [qfcc] Fix error in handling argc in test-harness
There was an out-by-one where attempting to run a program with only one
argument would result in the argument not being passed to the program
(two worked). This is actually the source of the error fixed in
9347e4f901 because test-harness.c was the
basis for qwaq's main.c
2022-01-22 15:31:26 +09:00
Bill Currie
e6fbe9fdbc [qfcc] Create .stack for Ruamoko progs
It's rather necessary :)
2022-01-21 20:47:35 +09:00
Bill Currie
2a89a678ec [qfcc] Don't allocate local defs for Ruamoko progs
They don't need the defs thanks to the stack.
2022-01-21 20:46:26 +09:00
Bill Currie
0a5101f88c [qfcc] Specify base register index for local defs
While all base registers can be used for any purpose at any time (this
is why the with instruction has hard-absolute modes: you can never get
permanently lost), qfcc currently uses the convention of register 0 for
globals and register 1 for stack locals (params, locals, function args).
The register used to access a def is stored in the def and that is used
to set the register bits in the instruction opcode.

The def code actually doesn't know anything about any conventions: it
assumes all defs are global for non-temp defs (the function code updates
the defs before emitting code) and the current function provides the
register to use for any temp defs allocated while emitting code.

Seems to work well, but debug is utterly messed up (not surprised, that
will be tricky).
2022-01-21 20:34:43 +09:00
Bill Currie
79bd4dd724 [qfcc] Set up the function stack frame
Still need to get the base register index into the instructions, but I
think this is it for basic code generation. I should be able to start
testing Ruamoko properly fairly soon :)
2022-01-21 20:00:38 +09:00
Bill Currie
616a52efb5 [qfcc] Implement flow analysis for Ruamoko calls
Thanks to the use/def/kill lists attached to statements for pseudo-ops,
it turned out to be a lot easier to implement flow analysis (and thus
dags processing) than I expected. I suspect I should go back and make
the old call code use them too, and probably several other places, as
that will greatly simplify the edge setting.
2022-01-21 17:14:10 +09:00
Bill Currie
c53127707b [qfcc] Set the return of Ruamoko calls
Of course, I had the width of opc wrong :P. But with this, it seems that
unoptimized calls should work once I get the stack frame working.
2022-01-21 13:50:21 +09:00
Bill Currie
33a3f92503 [qfcc] Move .return handling into statements.c
The means that the actual call expression is not in the statement lint
of the enclosing block expression, but just its result, whether the call
is void or not. This actually simplifies several things, but most
importantly will make Ruamoko calls easier to implement.

The test is because I had some trouble with double-calls, and is how I
found the return-postop issue :P
2022-01-21 13:09:23 +09:00
Bill Currie
64da1b603a [qfcc] Add failing test for return of postop
Commit 76b3bedb72 broke more than just the
swap test, but at least I know I need to get an edge in the dag.
Currently, the following code is generated: return and add are reversed.

    ../tools/qfcc/test/return-postop.r:8:   return counter++;
    0001 store.i counter, .tmp0
    0002 return .tmp0
    0003 add.i .tmp0, (1), counter

However, I don't want to deal with it right now, so it's marked XFAIL.
2022-01-21 12:40:59 +09:00
Bill Currie
7bc1396358 [qfcc] Split the function defspace into three spaces
Since Ruamoko now uses the stack for parameters and locals, parameters
need to come after locals in the address space (instead of before, as in
v6 progs). Thus use separate spaces for parameters and locals regardless
of the target, then stitch them together appropriately for the target.
The third space is used for allocating stack space for arguments to
called functions. It us not used for v6 progs, and comes before locals
in Ruamoko progs.

Other than the return value, and optimization (ice, not implemented)
calls in Ruamoko look like they'll work.
2022-01-21 10:20:02 +09:00
Bill Currie
a19349b242 [qfcc] Allow 0 sized highwater allocations in defspaces
This turned out to be needed for functions with no parameters (or no
locals).
2022-01-21 10:16:54 +09:00
Bill Currie
479ec07fd4 [qfcc] Implement ruamoko conversion instructions
Thanks to me having done something right 20 years ago, that was pretty
easy :). The two boolean types aren't supported yet because I haven't
decided on just how to represent their types in qfcc.
2022-01-21 10:14:14 +09:00
Bill Currie
b8b47aaf54 [qfcc] Give finish_function the finishing blow
It's been twitching for over ten years, time to put it out of its
misery.
2022-01-21 00:23:40 +09:00
Bill Currie
17dfd1492f [qfcc] Make virtual defspaces useful for highwater allocation
This seems to be the most reasonable approach to allocating space for
function call parameters without using push and pop (or adding to the
stack pointer), though it's probably good even when using push and pop
to help keep things aligned.
2022-01-20 20:54:12 +09:00
Bill Currie
2b7a8387e7 [qfcc] Get void return statements working
My little test program now builds with the Ruamoko ISA :)

    void cp (int *dst, int *src, int count)
    {
	while (count--) {
	    *dst++ = *src++;
	}
    }

Calls are broken (unimplemented), and non-void returns are not likely to
work either (only partially implemented).
2022-01-20 18:40:55 +09:00
Bill Currie
6487fe7ea7 [qfcc] Allow -1 width to match with 0
I initially wanted them to be separate, but return (and other
instructions where width is encoded in one of the operands) made that
difficult.
2022-01-20 18:39:06 +09:00
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
97034d9dde [simd] Add 2d vector types
For int, long, float and double. I've been meaning to add them for a
while, and they're part of the new Ruamoko instructions set (which is
progressing nicely).
2022-01-02 00:57:55 +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