Commit graph

211 commits

Author SHA1 Message Date
Bill Currie
e535fd51b7 [qfcc] Make passing int constants through ... ok
That is, passing int constants through ... in Ruamoko progs is no longer
a warning (still is for v6p and v6 progs). I got tired of getting the
warning for sizeof expressions when int through ... hasn't been a
problem for even most v6p progs, and was intended to not be a problem
for Ruamoko progs.
2023-09-14 18:33:06 +09:00
Bill Currie
b35f4c82a4 [qfcc] Implement field access for multi-vector expressions
Of course as an r-value (I think), but it makes getting only the desired
part of a geometric algebra expression much nicer.
2023-09-10 13:13:49 +09:00
Bill Currie
ed824405fe [qfcc] Support struct access to full algebra vectors
This makes them actually useable. Multi-vector expressions and variables
will be done soon.
2023-09-09 23:08:38 +09:00
Bill Currie
53d9fee586 [qfcc] Support the extended extend instruction
That... feels odd :)
2023-08-25 17:20:28 +09:00
Bill Currie
0d639510e3 [qfcc] Add a function to create typed zero expressions
Sometimes, nil's untyped 0 isn't really suitable.
2023-08-23 15:38:32 +09:00
Bill Currie
cfcacfbf28 [qfcc] Use scatter-gather for multivec expressions
This makes working with them much easier, and the type system reflects
what's in the multi-vector. Unfortunately, that does mean that large
algebras will wind up having a LOT of types, but it allows for efficient
storage of sparse multi-vectors:

    auto v = 4*(e1 + e032 + e123);

results in:

    0005 0213 1:0008<00000008>4:void     0:0000<00000000>?:invalid
              0:0044<00000044>4:void          assign (<void>), v
    0006 0213 1:000c<0000000c>4:void     0:0000<00000000>?:invalid
              0:0048<00000048>4:void          assign (<void>), {v + 4}

Where the two source vectors are:

    44:1 0 .imm float:18e [4, 0, 0, 0]
    48:1 0 .imm float:1aa [4, 0, 0, 4]

They just happen to be adjacent, but don't need to be.
2023-08-23 15:38:32 +09:00
Bill Currie
2e91b29580 [qfcc] Start work on implementing geometric algebra
This gets only some very basics working:
 * Algebra (multi-vector) types: eg @algebra(float(3,0,1)).
 * Algebra scopes (using either the above or @algebra(TYPE_NAME) where
   the above was used in a typedef.
 * Basis blades (eg, e12) done via procedural symbols that evaluate to
   suitable constants based on the basis group for the blade.
 * Addition and subtraction of multi-vectors (only partially tested).
 * Assignment of sub-algebra multi-vectors to full-algebra multi-vectors
   (missing elements zeroed).

There's still much work to be done, but I thought it time to get
something into git.
2023-08-21 17:58:20 +09:00
Bill Currie
dfb7862419 [qfcc] Use the progs VM to help with constant folding
Due to joys of pointers and the like, it's a bit of a bolt-on for now,
but it works nicely for basic math ops which is what I wanted, and the
code is generated from the expression.
2023-08-21 17:47:55 +09:00
Bill Currie
dbd3d6502a Nuke qboolean from orbit
I never liked it, but with C2x coming out, it's best to handle bools
properly. I haven't gone through all the uses of int as bool (I'll leave
that for fixing when I encounter them), but this gets QF working with
both c2x (really, gnu2x because of raw strings).
2023-06-13 18:06:11 +09:00
Bill Currie
5d9823af30 [qfcc] Implement designated initializers
Conforms fairly closely to GCC's C implementation.
2023-05-27 12:47:33 +09:00
Bill Currie
09a3e257e8 [qfcc] Fully initialize local structural defs
I think the current build_element_chain implementation does a reasonable
job, but I'm in the process of getting designated initializers working,
thus it will become important to ensure uninitialized members get
initialized.
2023-05-26 21:56:19 +09:00
Bill Currie
95b8424ddf [qfcc] Use new extend instruction instead of swizzle
While swizzle does work, it requires the source to be properly aligned
and thus is not really the best choice. The extend instruction has no
alignment requirements (at all) and thus is much better suited to
converting a scalar to a vector type.

Fixes #30
2022-08-18 18:18:19 +09:00
Bill Currie
ef9960c6f9 [qfcc] Implement support for the swizzle operator
The destination operand must be a full four component vector, but the
source can be smaller and small sources do not need to be aligned: the
offset of the source operand and the swizzle indices are adjusted. The
adjustments are done during final statement emission in order to avoid
confusing the data flow analyser (and that's when def offsets are known).
2022-05-01 14:35:24 +09:00
Bill Currie
9cccb7a4d4 [qfcc] Implement ulong, long and uint constants
Finally :P
2022-04-29 18:12:47 +09:00
Bill Currie
1eb8b61b83 [qfcc] Clean up handling of value expressions
I'd created new_value_expr some time ago, but never used it...
Also, replace convert_* with cast_expr to the appropriate type (removes
a pile of value check and create code).
2022-04-29 16:59:55 +09:00
Bill Currie
04f60e5ff1 [qfcc] Rework vector expression handling
Use with quaternions and vectors is a little broken in that
vec4/quaternion and vec3/vector are not the same types (by design) and
thus a cast is needed (not what I want, though). However, creating
vectors (that happen to be int due to int constants) does seem to be
working nicely otherwise.
2022-04-29 16:59:55 +09:00
Bill Currie
85d851572f [qfcc] Implement constant casts for the new vector types
Nicely, I was able to reuse the generated conversion code used by the
progs engine to do the work in qfcc, just needed appropriate definitions
for the operand macros, and to set up the conversion code. Helped
greatly by the new value load/store functions.
2022-04-29 16:59:55 +09:00
Bill Currie
1ce026d168 [qfcc] Implement bounced return pointer calls
This is achieved by marking a void function with the void_return
attribute and then calling that function in an @return expression.
@return can be used only inside a void function and only with void
functions marked with the void_return attribute. As this is intended for
Objective-QC message forwarding, it is deliberately "difficult" to use
as returning a larger than expected value is unlikely to end well for
the calling function.

However, as a convenience, "@return nil" is allowed (in a void
function). It always returns an integer (which, of course,can be
interpreted as a pointer). This is safe because if the return value is
ignored, it will go into the progs return buffer, and if it is not
ignored, it is the smallest value that can be returned.
2022-02-05 19:30:08 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
9cb3ee01d6 [qfcc] Add pointer value check
Extraction is a little more complicated, though, so undecided on that.
2020-03-17 11:19:12 +09:00
Bill Currie
c3f04384d5 [qfcc] Make a general integral value extractor
All too often I just want the value.
2020-03-17 11:18:37 +09:00
Bill Currie
888192a9ea [qfcc] Resurrect ex_def expression type
It turns out to be useful still as using symbol expressions isn't always
appropriate and the workarounds were getting nasty.
2020-03-17 01:42:46 +09:00
Bill Currie
a0c28a5ac5 [qfcc] Support pointers to temp operands
This is necessary for correctly taking the address of operands.
2020-03-16 14:24:47 +09:00
Bill Currie
72f4b8ccb5 [qfcc] Give address operands a good expression
That is, those created by operand_address. The dag code needs the
expression that is attached to the statement to have the correct
expression type in order to do the right thing with the operands and
aliasing, especially when generating temps. This fixes assignchain when
optimizing (all tests pass again).
2020-03-14 19:26:47 +09:00
Bill Currie
eca976e5ae [qfcc] Expose l-value checking
Needed for assignment chains.
2020-03-14 17:45:54 +09:00
Bill Currie
7cc51c9ca3 [qfcc] Save block expression creator's address
I've already found the bug that necessitated it (and the creator was
innocent), but it will help later.
2020-03-14 12:27:23 +09:00
Bill Currie
f738639d68 Revert "[qfcc} Mark some more functions as pure"
This reverts commit 65b48c734c.

I forgot that get_type calls convert_name, which most definitely is not
pure. Fixes the segfault in scheme.
2020-03-13 19:58:34 +09:00