Commit Graph

1674 Commits

Author SHA1 Message Date
Bill Currie 27b83a8d65 Clean up all extra aborts, using internal_error instead.
Some internal_error calls have no message, but at least things will be more
consistent.
2012-10-26 19:02:02 +09:00
Bill Currie 5530e84ada Call find_type for pascal functions/procedures.
The result of parse_params needs to be passed through find_type before
actually being used. I guess I'd missed this back when I got things working
for qc.
2012-10-26 16:20:57 +09:00
Bill Currie f14d8060e0 Merge qfpc into qfcc.
Since gnu bison and flex are required anyway, no harm in using their api
prefix options. Now, qfcc can compile both QC/Ruamoko and Pascal files
(Pascal is (currently?) NOT supported in progs.src mode), selecting the
language based on the extension: .r, .qc and .c select QC/Ruamoko, .pas and
.p select Pascal, while anything else is treated as an object file (as
before).
2012-10-26 16:01:41 +09:00
Bill Currie 358ea4ef9a Fall back to execve/wait when execvp and waitpid are unavailable. 2012-08-19 13:18:38 +09:00
Bill Currie b6125276e4 Fix the mis-handling of the progs.dat line in preprogs.src
Gah, must have lost a line at some stage. Also, handle line number
directives.
2012-07-14 19:01:47 +09:00
Bill Currie 7444371162 Disable bolding for special chars.
If an escape sequence is used to access a char, the the programmer probably
wanted that char, regardless of the current bolding mode.
2012-07-14 17:47:34 +09:00
Bill Currie 3b8141691e Fix a bunch of continue vs break issues. 2012-07-14 17:26:13 +09:00
Bill Currie 1364bff91b Add an extended mode to qfcc.
Extended mode allows extra keywords (switch, for, etc) that are compatible
with v6 progs.
2012-07-14 17:16:33 +09:00
Bill Currie 4055d9a435 Add support for \s escapes to qfcc.
I guess \s is an fteqcc extention for toggling bold characters. At the
request of freewill.
2012-07-14 11:47:26 +09:00
Bill Currie dbc203b625 And a few more bits of whitespace. 2012-05-23 08:21:27 +09:00
Bill Currie 23a38738fc Massive whitespace cleanup.
Lots of trailing whitespace and otherwise blank lines.
2012-05-22 08:23:22 +09:00
Bill Currie 0036a5e113 Ensure edict_size is never 0.
Avoids division by / in NUM_FOR_EDICT
2012-05-06 21:35:42 +09:00
Bill Currie 1dd5cccda2 Correct some more error messages. 2012-05-06 18:52:05 +09:00
Bill Currie a0788c6cdf Implement constant folding for unary operators.
Including conversions between float and int :)
2012-05-06 18:49:07 +09:00
Bill Currie f781e9078c Correct some typos in error messages. 2012-05-06 18:43:18 +09:00
Bill Currie 954e03c3f7 Report the correct function name for the largest locals.
I must have been tired when I adapted that code.

* taniwha dons brown paper bag
2012-05-06 13:02:11 +09:00
Bill Currie 55ecf94f2d Don't draw arrows leaving return statements.
Return statements never flow to the next block (or any other block, for
that matter), so drawing arrows leaving them not only messes up dot's
graphs, but is quite missleading.
2012-05-05 18:04:10 +09:00
Bill Currie 56410ddc58 Prevent merged if/goto losing its way.
When mering if/goto (ie, if skipping a goto), the rest of the dead code
remover is used to delete the goto. That part of the code unuses the goto's
label. The if was getting the goto's label without the lable's used count
being incremented (the usaged temporarily increases by one). I have no idea
why the problem showed up randomly, but this seems to fix it (it fixes /a/
bug, anyway).
2012-05-04 22:35:20 +09:00
Bill Currie 953e789db2 Handle movement of the final block.
Moving a final block caused segfaults and weird flow graph corruptions.
2012-05-04 19:48:32 +09:00
Bill Currie e8c17c68e6 Fix a segfault when the switch expression errors. 2012-05-04 18:13:11 +09:00
Bill Currie 5df25133b3 Implement code movement for unconditional jumps.
That is, when the destination of the jump is reachable via only the jump.
2012-05-04 18:00:05 +09:00
Bill Currie 33bfac0508 Process all basic blocks for jump threading.
I'd copied the for loop from the dead block removal code, but jump
threading doesn't need to look at the following block...
2012-05-04 14:10:30 +09:00
Bill Currie f169a7732d Factor out label unuse.
I expect to need this more often in the future.
2012-05-04 14:01:39 +09:00
Bill Currie 75aa28cfac Mark all subsequent blocks as reachable after if/goto merge.
If an if/goto merge is done in the first dead block pass, no blocks after
the merge have their rechable flag set because they've never been tested.
2012-05-04 10:58:18 +09:00
Bill Currie 8ddd58f951 Fix the dropping of the block after the merged if/goto.
The naive implementation of the if/goto merging was letting the old target
of the if get dropped because the block would lose its label and thus be
judged unreachable because the preceeding goto block was still in the list.
Instead, when the if/goto are "merged", mark the goto block as unreachable,
the following block as reachable, and break out of the analysis loop to
force the removal of the goto block. Since the dead block removal function
loops until no action is taken, all other dead blocks will be removed.
2012-05-04 10:07:55 +09:00
Bill Currie e866619de6 Output basic block flow diagrams to files.
The output can be controlled via --block-dot (not yet documented). The
files a named <sourcefile>.<function>.<stage>.dot. Currently, stage will be
one of "initial" (after expression to statement conversion), "thread"
(after jump threading), "dead" (after dead block removal), "final" (final
state before actual code emission).
2012-05-04 09:45:51 +09:00
Bill Currie 3da44ace52 Merge if and goto blocks when if only skips over the goto. 2012-05-03 22:21:32 +09:00
Bill Currie 6afdfb5fac Unuse label expressions that are no longer necessary. 2012-05-03 22:20:00 +09:00
Bill Currie 402a578bf8 Add some more helper functions.
Things were getting messy with the strcmps.
2012-05-03 22:17:23 +09:00
Bill Currie 88bed3644e Rename some helper functions. 2012-05-03 22:11:52 +09:00
Bill Currie 159f1bafea Add a little more info to statement flow diagrams.
The relative block number and the label user count are printed now.
2012-05-03 22:09:49 +09:00
Bill Currie 6900907129 Remove dead labels when jump threading.
This lets the dead block removal do a better job.
2012-05-03 19:32:44 +09:00
Bill Currie ab73a267cd Do not unconditionally remove labels from blocks.
Labels can be shared between multiple flow-control instructions, so use the
label's used counter to determine when to remove the label. This was
causing problems with the jump threading.
2012-05-03 19:22:57 +09:00
Bill Currie c79620f04c Make statement blocks more identifiable. 2012-05-03 19:10:44 +09:00
Bill Currie 43b5edf46b Implement jump threading.
First real optimization :)
2012-05-03 17:42:58 +09:00
Bill Currie 78a9ba2557 Make expression alias chains not-a-bug.
The common cause seems to be casting a cast (very common, and I'm not sure
just realiasing the expression would be right). It does't cause any harm
(particularly, it doesn't trigger alias def chains), so I won't worry about
it.
2012-05-03 13:57:31 +09:00
Bill Currie 006882407d Fix the source of alias def chains.
The actual bug might still be elsewhere, but at least now I know the alias
chains were coming from accessing .return and .param_N, which are unions
(not directly usable by the progs engine). Emitting a reference to a union
(or struct) would create an alias def, but an alias expression was created
in the expression tree to simplify return/param access. The double layer
(sometimes 3 or 4) alias isn't really neaded, so rather than layering the
aliases, just re-alias the alaised def.
2012-05-03 13:28:16 +09:00
Bill Currie ec98e3e206 Mark alias def chains as a bug. 2012-05-03 13:27:30 +09:00
Bill Currie 5f676c367f Add a non-error diagnostic that can't be silenced.
It is inteded for flagging buggy conditions in the compiler, particularly
after having fixed the original bug (in case something comes back from the
dead).
2012-05-03 13:24:24 +09:00
Bill Currie 3306039da2 Print the destination type for alias expression bubbles. 2012-05-03 11:55:19 +09:00
Bill Currie e267e0a664 Allow control of progdefs.h CRC writing.
CRC writing defaults to off for non-v6 progs, but on for v6 progs. The
--progdefs option forces CRC writing.
2012-05-03 00:22:24 +09:00
Bill Currie 44fcd76475 Add some missing command line option docs. 2012-05-03 00:03:13 +09:00
Bill Currie 15de69d868 Use dstring for progdefs.h writing.
And finally get qfcc into the thing :P
2012-05-02 23:39:49 +09:00
Bill Currie 04b9b3a11d Fix progdefs.h writing. 2012-05-02 22:44:45 +09:00
Bill Currie ce278b2fbf Ensure .zero does not get a vector field for v6 progs.
v6 progs expects .zero to be only 1 word. The code actually tried to keep
vector out of .zero, but it seems I'd rearranged the structure defintion
without updating the code that kills the vector field. Problem spotted by
divVerent.
2012-05-02 22:29:17 +09:00
Bill Currie e06ee34287 Allow quat * vec in ruamoko. 2012-04-26 12:00:27 +09:00
Bill Currie bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie eefa89e72e Remove the AM_CONDITIONALs from tools.
Now that the tools directories aren't entered when those tools aren't being
built, there's no reason to use AM_CONDITIONAL in there.
2012-02-10 02:50:42 +09:00
Bill Currie c8163fc0de Add an option to prevent the use of default paths.
Despair has things locked down such that running qfcc during a build fails
due to lack of read access to /usr/local/lib. This is actually a good
thing as accidentally hitting old includes/libs (when a file gets deleted
in the tree) hides bugs. Thus, --no-default-paths to turn off default
search paths.
2012-01-04 13:53:04 +09:00
Jeff Teunissen 6ead583195 Ruamoko: Implement infinity.
The special token __INFINITY__, like __FILE__ and friends, will expand to
a floating-point expression containing a value the C compiler considers
infinite. Obviously, this assumes that the system has relatively modern
float hardware -- but if it doesn't, having Ruamoko be able to represent
float infinity is the least of your problems. :)
2011-12-14 12:20:10 -05:00
Bill Currie ea02f3cd44 Fix a missed byteswap when loading qfo files. 2011-11-15 17:36:55 +09:00
Bill Currie a71acc9ae5 Move the essential init code into Sys_Init(). 2011-09-11 14:56:47 +09:00
Bill Currie e42c5a4272 More tests and fix vector/quaternion global dumps. 2011-08-11 14:58:13 +09:00
Bill Currie c6e0e094d8 Fix an unterminated array.
That was sneaky. It took building qfcc on an arm to trigger that bug.
2011-07-30 15:01:16 +09:00
Bill Currie d910c14935 Clean up some doxygen warnings. 2011-07-10 19:12:07 +09:00
Bill Currie 617e70c8e3 Clean up a bunch of bison unused warnings. 2011-06-21 19:52:47 +09:00
Bill Currie 0f7390dd60 Clean up all the "set but not used" warnings.
gcc on my system is failing to treat this specific warning as an error :/
2011-06-19 10:48:02 +09:00
Bill Currie c7612dcd99 Make statement dumps a little more informative. 2011-04-10 09:08:46 +09:00
Bill Currie fd6e341e06 Clean up cast_expr() a little bit. 2011-04-10 00:29:27 +09:00
Bill Currie 57ed603658 Extract values from constant defs. 2011-04-09 12:42:41 +09:00
Bill Currie cc714864a8 Support converting to/from unsigned values. 2011-04-09 11:32:33 +09:00
Bill Currie 55cc0f9206 Bring back the unsigned type (PROGS version bump)
This is only low-level support (the unsigned keyword still does not work),
but sufficient to make switch statements using jump tables work.
2011-04-09 10:07:47 +09:00
Bill Currie b522853765 Ensure the target of def_op relocs gets updated.
These occur only when switch statements use jump tables, thus why the
problem went unnoticed :/
2011-04-08 17:09:40 +09:00
Bill Currie 237f11c472 Fix cast expressions.
Casting between ints and floats needs special treatment to get the
conversion operator, but other casts need to be aliases.
2011-04-08 13:55:26 +09:00
Bill Currie c4a398850a Fix defs as constants for vectors and quaternions. 2011-04-04 21:31:59 +09:00
Bill Currie 38b25e0c38 Do not double-allocate space for immediates.
Caused by changed semantics in def creation.
2011-04-03 13:11:50 +09:00
Bill Currie 92ba110a87 Ensure a field def is emitted for @this. 2011-04-03 13:03:48 +09:00
Bill Currie 7f67e6eb17 Refactor the def handling code a little. 2011-04-03 13:03:22 +09:00
Bill Currie 6d0b13dbf0 Resolve types whenever possible. 2011-04-03 13:02:04 +09:00
Bill Currie 2c9c1bd968 Ensure defs for @self and @this are generated. 2011-04-03 13:00:48 +09:00
Bill Currie 2de7733b6a Fix initialized variable type handling.
Same problem as initialized constants :P
2011-03-30 21:21:38 +09:00
Bill Currie 8e18c76bde Make initialized variables defs rather than immediate constants. 2011-03-30 19:58:09 +09:00
Bill Currie 7dbd2ec172 Allow field aliasing.
Initializing a field variable to another field will set the new field to
point to the same location. No type checking is done.

eg:
.SEL thinkMethod = think;
2011-03-30 09:33:47 +09:00
Bill Currie 550fff5467 Allow assignments between any field types. 2011-03-30 08:14:17 +09:00
Bill Currie 75c3653be4 Implement some missed relocs. 2011-03-30 08:13:13 +09:00
Bill Currie 1911cc1472 Mingw build fixes. 2011-03-27 08:26:42 +09:00
Bill Currie 896791b209 Correct the spelling of "int" and clean up the mess. 2011-03-25 16:53:04 +09:00
Bill Currie 1617f0765e Support the default type without segfaulting. 2011-03-25 09:59:48 +09:00
Bill Currie a7cfe3b215 Preserve the current class across protocol defs.
It seems that protocol defs are allowed in class implementations, so don't
let the protocol def kill the current class for the class implementation.
2011-03-24 11:55:17 +09:00
Bill Currie 71af121665 Detect missing @end tags.
Give a warning when @end is forgotten in class implementations.
2011-03-24 11:44:22 +09:00
Bill Currie 8d3508cf20 Allocate space for temp defs using size rather than type.
Statement operands throw away the high level type information, so store
type size in the operand and use this size for allocating space for temps
rather than using the low-level type.
2011-03-23 21:32:14 +09:00
Bill Currie 9b62c8c126 Rename ty_type_e to ty_meta_e and type_t.ty to type_t.meta 2011-03-22 16:06:47 +09:00
Bill Currie d4be914019 Fix initialized vector variables.
The whole initialized variable system is wonky, but it will do for now.
2011-03-22 15:10:06 +09:00
Bill Currie 6a49861b49 Fix the bogus source file for "redefined" functions. 2011-03-22 13:45:44 +09:00
Bill Currie 7dbd5f656c Fix traditional vector component access. 2011-03-22 13:05:42 +09:00
Bill Currie f1d9570dc8 Fix constant value type handling.
Rename immediate.[ch] to value.[ch] and clean up the mess.

Add convert_value() to convert the type of a value (only scalar types).
2011-03-22 12:24:39 +09:00
Bill Currie 1219df0872 Fix field immediates.
Field immediates need to be treated the same way as pointer immediates when
merging values.
2011-03-21 18:11:46 +09:00
Bill Currie 46093c0937 Use the correct meta type for spacial types.
Although vector and quaternion types have symbol tables, they are not
really structs, so set the meta type to "none", allowing the types to be
encoded correctly.
2011-03-21 17:26:49 +09:00
Bill Currie cefe7e2e94 Use the correct source of defs for field defs. 2011-03-21 17:07:40 +09:00
Bill Currie 0c0f4360da Make field defs "nosave".
The engine treats fielddefs with DEF_SAVEGLOBAL set as bogus.
2011-03-21 17:06:45 +09:00
Bill Currie f5ce9e2004 Fix a merge induced error in overloaded functions. 2011-03-20 19:04:18 +09:00
Bill Currie 1ada2a96cf Merge branch 'master' into qfcc-codegen
Conflicts:
	tools/qfcc/source/expr.c
	tools/qfcc/source/function.c
	tools/qwaq/test.r
2011-03-20 15:58:31 +09:00
Bill Currie a919e5f619 Make class_check_ivars() use class_add_ivars() to add the ivars.
This avoids implementation ivar blocks trashing the ivar offsets in
derived classes.
2011-03-20 13:35:59 +09:00
Bill Currie 8c8a6a4d63 The function return type is the address of the type descriptor... 2011-03-17 20:31:20 +09:00
Bill Currie 01144d23cf Add a new gcc warning option and fix the two bugs it found. 2011-03-17 19:58:56 +09:00
Bill Currie 5aa0b34570 Add the cast statement to the statement block.
*sob*
2011-03-10 20:43:53 +09:00
Bill Currie f663f587fe Fix the missing local defs for builtin functions. 2011-03-10 20:16:35 +09:00
Bill Currie 899af3119b Use the correct type when generating a move expression. 2011-03-10 19:30:21 +09:00
Bill Currie 2129eaaf20 Dereference moves need movepi rather than movei. 2011-03-10 19:29:23 +09:00
Bill Currie cbbbf87e20 Resurrect the stats output. 2011-03-09 15:51:17 +09:00
Bill Currie 8368f57fbf Close a potential buffer overflow. 2011-03-09 11:09:46 +09:00
Bill Currie 4d90eba2ad Remove some unused globals. 2011-03-09 11:08:30 +09:00
Bill Currie 2464a89d37 Preserve relocs across def churning.
Freeing then re-allocating a def to change its storage from external is
really not the right way to do it, but for now this fixes the loss of the
relocs. With this, the menus seem to work :)
2011-03-09 10:52:29 +09:00
Bill Currie 39278ba8cc Explicitly select between direct and indirect moves. 2011-03-09 10:30:57 +09:00
Bill Currie b95cdc33d9 Set instace_size to the correct size. 2011-03-08 22:45:34 +09:00
Bill Currie 55eed1ae07 Make module dumping a little more informative. 2011-03-08 22:43:53 +09:00
Bill Currie 7c770b75c5 Do not creat field defs for local storage.
This prevents field params and local vars from messing up the real field
defs.
2011-03-08 19:56:02 +09:00
Bill Currie f66e20db17 Set the dereferenced type in the field value. 2011-03-08 19:29:36 +09:00
Bill Currie 7198be5726 Treat entities a bit like structures in field_expr ().
Look in the entity field symbol table for the field before looking in the
normal symbol table. This allows entity fields to be accessed even when
the current scope has symbol of the same name. However, checking the
normal symbol table where there is no such field allows for field
variables when I get around to implementing them.
2011-03-08 19:28:11 +09:00
Bill Currie 505bde308e Fix the handling of @system defs.
When treating a def as external, actually say it is external.
2011-03-07 20:53:27 +09:00
Bill Currie 8dbf8a97ea Be more informative with ext/def internal errors. 2011-03-07 20:52:31 +09:00
Bill Currie 6312ccba81 Fix storage class blocks.
@extern { defs }; etc
2011-03-07 20:51:51 +09:00
Bill Currie 4db8ebb6af Support qcc style local function variables. 2011-03-07 20:04:05 +09:00
Bill Currie 853cc53d0f FIx the handling of storage class. 2011-03-07 17:49:01 +09:00
Bill Currie 7649549de6 Handle external field declarations. 2011-03-07 17:23:52 +09:00
Bill Currie 49e446b637 Make field defs global.
It turns out that field defs need to be global after all, so use separate
field def tables in the linker.
2011-03-07 14:45:50 +09:00
Bill Currie 041c5d53b8 Check for the vector being a constant before trying to get its value. 2011-03-07 14:04:36 +09:00
Bill Currie c069bafad8 Support casting from enum to float. 2011-03-07 14:04:05 +09:00
Bill Currie 5a78758781 Support return in void functions in v6 code. 2011-03-07 13:52:28 +09:00
Bill Currie 1246fd9e30 Use the correct size when growing a data space. 2011-03-07 13:36:00 +09:00
Bill Currie 02a70ebe1c Remove the auxfunction manipulation from the compiler proper.
It was broken code in the first place (realloc and pointers), and is
redundant with the new linking process.
2011-03-07 13:33:02 +09:00
Bill Currie 16103f9018 Fix param mangling for qc style functions. 2011-03-07 10:43:38 +09:00
Bill Currie 29cac0fe3a Optionally create *_[xyz] symbols for accessing vector components.
"vector-components" in code options controls this feature. The default is
off for advanced code and on for traditional code. Disabling
vector-components prevents the comonent names polluting the namespace and
reduces the number of globals needed for vector fields if the components
of that field are never used.
2011-03-07 10:21:40 +09:00
Bill Currie 0b3d0011c5 Implement vector and quaternion component access. 2011-03-07 10:02:20 +09:00
Bill Currie f0e47f2334 Clean up some code duplication. 2011-03-07 10:01:21 +09:00
Bill Currie a6f222106e Fix taking the address of normal variables.
Treat them the same as structure variables.
2011-03-07 09:58:51 +09:00
Bill Currie 3c1784d46c Fold constants on both sides of = to ensure correct expression types. 2011-03-07 08:33:30 +09:00
Bill Currie 66447df6b3 Undo the offset relocation of local defs.
The debug info expects local defs to be 0 based, so once relocations in
the progs data have been completed, undo the local def offset relocation
so that the correct offsets will be written to the debug info.
2011-03-06 21:05:25 +09:00
Bill Currie b2f0c9a127 Dump the local defs for functions when debug info is available. 2011-03-06 21:03:12 +09:00
Bill Currie b49d90e769 Do not lose the block expression when taking its address. 2011-03-06 16:32:51 +09:00
Bill Currie c78d15b331 Support taking the address of block expressions that have a result. 2011-03-06 16:05:38 +09:00
Bill Currie 993d05b3d3 Support taking the address of alias expressions.
Taking the address of an alias expression undoes the alias but uses the
aliased type.
2011-03-06 15:58:49 +09:00
Bill Currie b74c644a10 Perform offset field relocations. 2011-03-06 15:41:38 +09:00
Bill Currie 8712d30d1a Make entity field defs static.
Entity field defs need to be static in order to avoid clashing with their
field variables.
2011-03-06 15:41:15 +09:00
Bill Currie c4e9a45d91 Do not lose the entity field defs. 2011-03-06 15:40:07 +09:00
Bill Currie b7aa2f6786 Support access to struct fields in a structure in an entity. 2011-03-06 15:39:27 +09:00
Bill Currie fe3d228658 Maintain a symbol table for entity fields. 2011-03-06 15:38:19 +09:00
Bill Currie c29e0250e4 Make def_field_Ofs reloc dumps more informative. 2011-03-06 15:34:53 +09:00
Bill Currie 02766f0795 Do not try to dump def values from spaces with no data. 2011-03-06 15:33:53 +09:00
Bill Currie 1eb759bb8a Update reloc_names.
I really need to get reloc_names unduplicated.
2011-03-06 15:33:10 +09:00
Bill Currie d1187f0857 Set the edict area size when dumping qfo files. 2011-03-06 13:41:00 +09:00
Bill Currie 7bfaf107ce Set the output file name as early as possible. 2011-03-06 13:40:24 +09:00
Bill Currie 417d1b4442 Fix structure copy into and out of entities. 2011-03-06 13:19:20 +09:00
Bill Currie dc7a78b2ff Fix case label type conversions.
The previous method made too many assumptions.
2011-03-06 11:41:01 +09:00
Bill Currie fe4df03896 Add is_float ().
For now, it checks just floats, but I might one day add doubles.
2011-03-06 11:35:15 +09:00
Bill Currie 85bffbcad0 Add is_integral() to check for integral types (integer, short, enum). 2011-03-06 11:25:12 +09:00
Bill Currie 17a9dff769 Avoid freeing an operand twice.
Due to the way operands are used, they can be freed twice in dead-statement
removal. Detect the double-free and ignore it.
2011-03-06 11:19:09 +09:00
Bill Currie 28f4de94d2 Fix switch statements so the work in the new scheme.
Convert case labels to be the same type as the switch expression.
Use alias expressions for the various test expressions.
2011-03-06 00:29:29 +09:00
Bill Currie 8cfa80b5d4 Implement think expressions. 2011-03-05 18:01:37 +09:00
Bill Currie 7209c61912 Fix initializing local float variables with an integer constant.
Run the assignment expression through fold_constants to handle any
necessary conversions and error checking.
2011-03-05 17:23:58 +09:00