Commit graph

2862 commits

Author SHA1 Message Date
Bill Currie
40c97f9570 Tread immediate move statements similarly to assignments.
They're used for structure assignment in near data space. This fixes the
bogus uninitialized warnings on fully initialized structs.
2012-11-24 16:47:44 +09:00
Bill Currie
7f229b7682 Remove execessive html quoting.
Heh, I must have put that in long before I did the quoting functions.
2012-11-24 15:42:21 +09:00
Bill Currie
dbbca47a3b Mark initialized struct/array defs as initalized.
Also, use the initialized flag for setting up the initalized var set in
flow_uninitialized().
2012-11-24 15:26:27 +09:00
Bill Currie
f4604d9db5 Remove gotos that go to the following statement.
eg:
	goto foo:
foo:
	//some code
2012-11-24 15:08:48 +09:00
Bill Currie
738fc65e0f Treat global vars as always live.
This fixes the infloop.r test.
2012-11-24 14:56:30 +09:00
Bill Currie
2478b053de Add a test for writes to global vars in a loop. 2012-11-24 14:53:45 +09:00
Bill Currie
bdafdad0d5 Treat flow control statements separately.
I'm not convinced this is the correct fix for while (count--), but it does
work.
2012-11-24 12:53:51 +09:00
Bill Currie
bc26cd24c8 Make structptr.r a little quieter. 2012-11-22 21:59:01 +09:00
Bill Currie
607d7dd45e Simplify the child match in dagnode_match.
I have no idea why I did it that way when all that's needed is to check the
child pointers. Well, that's modulo.r fixed :)
2012-11-22 21:59:01 +09:00
Bill Currie
64d9bbd230 Make the failure message clearer. 2012-11-22 21:59:01 +09:00
Bill Currie
b920a4dec9 Add a new test case.
It turns out that the optimizer completely breaks (a + b) % (a - b) with v6
code.
2012-11-22 21:59:01 +09:00
Bill Currie
47decd58d0 Support testing v6 progs.
v6 progs return float rather than int (they don't have int).
2012-11-22 21:59:01 +09:00
Bill Currie
eef399209d Add some very evil pragmas.
The evil comment is not just "pragmas are bad, ok?", but switching between
advanced, extended and tradtitional modes when compiling truly is evil and
not guaranteed to work. However, I needed it to make building test cases
easier (it's mostly ok to go from advanced to extended or tradtional, but
going the other way will probably cause all sorts of fun).

In the process, opcode_init now copies the opcode table data rather than
modifying it.
2012-11-22 21:59:01 +09:00
Bill Currie
538879b451 Get automatic dependencies working for the progs files.
Including dependencies on QFCC itself :)
2012-11-22 21:59:01 +09:00
Bill Currie
92d2b4107c Make the --developer and --trace options work. 2012-11-22 21:59:01 +09:00
Bill Currie
a5a7780a21 Fix make dist for qfcc's test. 2012-11-22 21:59:01 +09:00
Bill Currie
99b34232f8 Add a test harness for qfcc.
It's only the beginning, but finally make check is useful for qfcc :)
It even has a failing test :D
2012-11-22 21:59:01 +09:00
Bill Currie
95bd4ad410 Add a test for while (count--) 2012-11-22 21:59:00 +09:00
Bill Currie
49ca09a64f Clean up qfcc's test directory.
I don't remember what half these tests were for :/
2012-11-22 21:58:52 +09:00
Bill Currie
4b5e00afdf Do a bunch of refactoring.
The dag creation loop was getting too messy.
2012-11-21 18:30:44 +09:00
Bill Currie
c5f2e3c4ad Make dag dumping from gdb easier. 2012-11-21 15:03:44 +09:00
Bill Currie
bedde02307 Make flow graphs with dags easier to read.
The node contents are now the dag rather than the dag being attached to the
node.
2012-11-21 13:43:03 +09:00
Bill Currie
c759b73b24 Cope with empty sblocks when producing dot graphs. 2012-11-21 12:23:15 +09:00
Bill Currie
2c09464e80 Don't attach a dag label to its own node.
This kills a = a; statements :)
2012-11-21 12:16:10 +09:00
Bill Currie
0583dc82d3 Treat uninitialized temps as a bug.
It really should be impossible, but I'm not sure where the bug is yet
(though there are uninitialized variables that are false positives that
most definitely are initialized, might be related)
2012-11-21 10:26:41 +09:00
Bill Currie
86968f662e Store the function type in function values.
This fixes IMP msg = nil;
2012-11-21 10:06:15 +09:00
Bill Currie
686937123c Ensure flowvars always point to the var itself.
Pointing to aliases of the var causes all sorts of problems, but this time
it was causing the uninitialized variable detector to miss certain
parameters.
2012-11-21 09:43:59 +09:00
Bill Currie
0dc306c4b7 Fix the initialized var data flow.
Now most false positives have been fixed. Just some problems with aliased
vars (next) and then the usual false positives caused by branches.
2012-11-21 09:42:02 +09:00
Bill Currie
547ea78ad7 Implement uninitialized variable checking.
It currently gets a lot of false positives (globals and parameters?), but
the initial tests for just local vars worked.
2012-11-20 21:49:47 +09:00
Bill Currie
d8a5d6745f Add a param flag to defs.
It is necessary to know if a def is a function parameter so it can be
treated as initialized by the flow analyzer. The support for the flag in
object files is, at this stage, purely for debugging purposes.
2012-11-20 17:50:59 +09:00
Bill Currie
a734feacfd Create the .parN variables for varargs functions.
Ouch, 2 years and this is the first test?
2012-11-20 17:14:58 +09:00
Bill Currie
984aa9a4cf Support entity.field = structvar2 = structvar1;
The structvar2 = structvar1 is implemented as a move expresion, which
address_expr didn't like. Return the address of the source. For indirect
move expressions, this is just the source expression itself.
2012-11-20 17:12:16 +09:00
Bill Currie
5cfeb7809f Fix a missing ; 2012-11-20 17:11:39 +09:00
Bill Currie
b91bb2e915 Add direct moves to expression dumping. 2012-11-20 16:55:19 +09:00
Bill Currie
793112de9a Add some more tests.
structptr.r is actually usable for automated testing when I get around to
it.
2012-11-20 15:39:00 +09:00
Bill Currie
87121b4cf1 Be slightly picky about which nodes to kill.
Constant/label nodes should never be killed because they can (in theory)
never change. While constants /can/ change in the Quake VM, it's not worth
worrying about as there would be much more important things to worry about
(like 2+2 not giving 4).

Due to the hoops one would have to jump through, it is assumed that a
pointer or an offset from that pointer will never overwrite the pointer.
2012-11-20 15:28:57 +09:00
Bill Currie
22d72f33d2 Match pointer dereferences with pointer assignements.
Having the source operand of a pointer assignment available to later
instrctions can make for more efficient code as the value does not need to
be dereferenced later. For this purpose, pointer dereference dag nodes now
store the source operand as their value, and dagnode_match will match x=a.b
with *(a+b)=y so long as both a and b are the same in both nodes. x and y
are irrelevant to the match. The resulting code will be the equivalent of:
    *(a+b) = y;
    x = y;
2012-11-20 15:22:05 +09:00
Bill Currie
36e359e2ee Correct a typo. 2012-11-20 15:19:32 +09:00
Bill Currie
ef0f30935f Kill all dag nodes on pointer assignment.
It's brutal, but it works and is conservatively correct.
2012-11-20 14:30:42 +09:00
Bill Currie
f83cf1748f Allow node() to work for all operand types.
This is a bit of an expermiment to get better dags (more node reuse).
2012-11-20 14:23:43 +09:00
Bill Currie
1472fec7f2 Factor out the live vars magic from dag_create.
The code is messy enough as it is :P
2012-11-20 13:44:36 +09:00
Bill Currie
06a62be1d5 Fix redundant constant values.
I had forgotten to add the new value to the hash table. Oops.
2012-11-20 13:33:57 +09:00
Bill Currie
56103f9a38 Treat global variables as live at the end of a function.
.return and .param_N are not classed as global variables for data flow
analysis. .return is taken care of by return statements, and .param_N by
call statements.

With this, the menus work up to attempting to load the menu plist.
Something is corrupting zmalloc's blocks.
2012-11-19 17:21:35 +09:00
Bill Currie
0dea564cb4 Be more careful of empty sblocks.
Accessing the final statement of an sblock via tail doesn't work in an
empty sblock because tail points to sblock->statements and thus the cast is
invalid. This bug has be lurking for a long time, but for some reason the
cse stuff tickled it (thankfully!!!).
2012-11-19 16:11:07 +09:00
Bill Currie
1e72e3eb20 Make the post-optimization sblocks dump optional. 2012-11-19 15:24:09 +09:00
Bill Currie
bcde7396a0 Don't let generate_assignments guess the type.
It fails when both source and destination are void, but since the dag node
itself does know the correct type, pass in the type rather than guessing.
2012-11-19 15:21:01 +09:00
Bill Currie
68bf013601 Use a dag-local live vars set.
Function calls need to ensure .param_N actually get assigned, and so the
params must be seen as live by the dead variable removal code. However, it
is undesirable to modify the live vars data of the flow node, so make a
local copy.
2012-11-19 15:18:31 +09:00
Bill Currie
d1252813ce Use low_level_type instead of extract_type.
extract_type doesn't understand enums (by design?). qwaq's types.r now
compiles.
2012-11-19 13:49:34 +09:00
Bill Currie
f2cc82469a Use the correct field when dechaining aliases.
op_type and type always confuse me :P
2012-11-19 12:53:08 +09:00
Bill Currie
c03511734d Fix a dreaded uninitialized variable.
Sneaky bastard :P (typo)
2012-11-19 12:52:24 +09:00