Commit graph

1272 commits

Author SHA1 Message Date
Bill Currie
e27f3fd7c3 Copy the method's params into the method symbol. 2011-02-06 15:14:42 +09:00
Bill Currie
00bba1eb3a Fix creation of uninitialized global variables. 2011-02-06 14:37:25 +09:00
Bill Currie
59d3dc6ae0 Check early for assignment of a class pointer to id. 2011-02-06 14:35:17 +09:00
Bill Currie
2f7b892452 Fix passing messages to classes.
Rename class_pointer_def() to class_pointer_symbol() and use it when a
class name is used as the receiver of a message.
2011-02-06 14:34:40 +09:00
Bill Currie
67957a14df Bring back convert_name(), but siimplified.
It is now mainly for converting __FILE__ etc, handling expression symbols,
and checking for undefined identifiers.
2011-02-06 14:29:14 +09:00
Bill Currie
d03fdc5e67 Correctly calculate the size of the ivars of a class.
Need to include the size of the super class ivars.
2011-02-05 00:04:35 +09:00
Bill Currie
690ae1cb57 Fix send_message(). 2011-02-04 23:49:25 +09:00
Bill Currie
29fbc3b073 Struct and ivar declarations now seem to work.
However, not bit-fields.
2011-02-04 23:48:58 +09:00
Bill Currie
1f6abb2cce Minor cleanups to message_expr().
Fix for class names no longer being pointers to the class.
2011-02-04 23:22:51 +09:00
Bill Currie
eff3957487 Resurrect the address expression code for arrays etc.
This fixes selector finding.
2011-02-04 23:20:37 +09:00
Bill Currie
c542e1a453 Possibly fix normal methods. 2011-02-04 22:31:23 +09:00
Bill Currie
d9446c5eb0 Fix builtin methods. 2011-02-04 22:31:22 +09:00
Bill Currie
d0ecbb38b8 Copy the spec bits and storage class for QC functions. 2011-02-04 15:25:21 +09:00
Bill Currie
f721144ca5 Rewrite emit_ivars to use emit_structure.
The old code was broken anyway :) (it was segfaulting).
2011-02-04 15:11:47 +09:00
Bill Currie
acb3c0da11 Fix class initialization. 2011-02-04 14:29:47 +09:00
Bill Currie
04b86fcdb7 Move the Objective-QC structs from type.c to class.c 2011-02-04 12:07:32 +09:00
Bill Currie
7b22bfba63 Better Objective-QC keyword detection.
Use a flag in the keyword struct rather than checking for "@" in the
keyword. This catches such keywords as "id" and "Protocol" as well.
2011-02-04 08:38:58 +09:00
Bill Currie
993bee4f59 Do not count unimplemented methods.
The method emitter skips unimplemented methods, so counting them when
figuring out how many methods to emit leads to a segfault.
2011-02-04 08:26:16 +09:00
Bill Currie
e04ed72afa Increment the index when emitting array elements.
Oops :)
2011-02-04 08:25:27 +09:00
Bill Currie
d7853682af Fix conversion of nil to a real type. 2011-02-03 21:37:15 +09:00
Bill Currie
f44a26e268 Fix type chaining when dealing with decls. 2011-02-03 21:32:58 +09:00
Bill Currie
54c8a10fe4 Don't trip over incomplete structs (again:P) 2011-02-03 21:31:14 +09:00
Bill Currie
12d8658ece Create a typedef for obj_module_t. 2011-02-03 18:05:46 +09:00
Bill Currie
b07392b818 Allow ivars to use C syntax declarations. 2011-02-03 18:04:41 +09:00
Bill Currie
dc6296e9b1 Allow ivars to use typedefs and other classes. 2011-02-03 18:03:37 +09:00
Bill Currie
2203903bb2 Temporarily splice the class's ivar chain into the symbol table.
The root class's ivar symbol table needs to be connected to the global
symbol table while building the current class's ivar symbol table. This
allows access to other classes and typedefs.
2011-02-03 18:02:49 +09:00
Bill Currie
79df3d2cca Put newly created classes into the symbol table. 2011-02-03 17:28:49 +09:00
Bill Currie
564b7b9968 Use abstract_decl instead of type wherever a generic type is needed. 2011-02-03 10:53:59 +09:00
Bill Currie
a208aed6ef Fix a segfault when encoding incomplete structs. 2011-02-03 10:52:42 +09:00
Bill Currie
22ccd41164 Give struct types a name.
Use the struct/union's name (minus "tag ") for the type name.
2011-02-03 10:52:12 +09:00
Bill Currie
d12cdca758 Functions and enums now seem to be working properly.
find_type now operates recursively (depth-first) so built up typechains
work as expected.

@overload is treated as a specifier (directly as a storage class, similaar
to typedef).
2011-02-03 10:48:12 +09:00
Bill Currie
52799a4e1c Must merge specifiers :P 2011-02-02 22:59:08 +09:00
Bill Currie
4420a7125e Ensure structs get added to the symbol table. 2011-02-02 22:53:53 +09:00
Bill Currie
a4eaa2a89b Allow typedefed types and classes in parameters. 2011-02-02 21:58:53 +09:00
Bill Currie
aeecdc84dc Get typedef working. 2011-02-02 21:58:11 +09:00
Bill Currie
cca829aa6b Remove a stray semicolon from the grammar. 2011-02-02 21:57:41 +09:00
Bill Currie
400abe7fce Allow freeing of typechains. 2011-02-02 15:15:24 +09:00
Bill Currie
1fe031e8cb Build C style var/func/abs decl types from the outside in.
QuakeC style are built from the inside out.
2011-02-02 15:15:04 +09:00
Bill Currie
7fb8c8247e Don't do a find_type on the parsed function.
This is needed for C style declarations, but breaks QuakeC style. The fix
is to do the find_type once the return type has been filled in.
2011-02-02 15:08:59 +09:00
Bill Currie
1452da676d Allow types to be built from the outside in.
This is required for C style decl processing.
2011-02-02 15:07:44 +09:00
Bill Currie
ac91e9376b The big type-system rewrite. Horribly broken :)
While broken, it is good enough to compile modulo.r.

This gives qfcc C's type system with QC specifics bolted on top (rather
than trying to cram C's type system into QC's). Pointers and arrays now
use C syntax and semantics (though I think there's a lot of breakage in
there at the moment). Functions themselves are still dual mode: both QC
style and C style are available.
2011-02-01 21:23:03 +09:00
Bill Currie
d11d128c96 Avoid segfaulting on errors. 2011-02-01 21:18:39 +09:00
Bill Currie
80ce179bc2 Scan the param list for problems with void. 2011-02-01 21:18:08 +09:00
Bill Currie
c53001800a Create a struct for representing specifiers.
The specifiers are yet to come (next few commits), but this will be
necessary when they do.
2011-02-01 21:15:51 +09:00
Bill Currie
917c5f08b0 Make a var representing the default type.
The default type for vars is integer for ruamoko and float for v6 qc.
2011-02-01 21:12:02 +09:00
Bill Currie
54c14eb899 Add "return" to pascal.
I'm still not sure I'll keep it, but it's useful for testing.
2011-01-30 22:16:59 +09:00
Bill Currie
e7424e1496 Don't segfault on bare return statements.
I will probably need to do something about the required operand for v6
progs, but this will do for now.
2011-01-30 21:43:56 +09:00
Bill Currie
440a13b649 Untwist params' knickers for pascal, too. 2011-01-30 21:42:10 +09:00
Bill Currie
861ab93274 Don't type-check against the wrong type :P 2011-01-29 09:56:08 +09:00
Bill Currie
afc6605739 Don't set the space for external defs. 2011-01-29 09:55:14 +09:00
Bill Currie
d80a3413e5 Fix a segfault when freeing locations.
When chasing linked lists with a double pointer, must check the first
dereference and not the pointer itself.
2011-01-29 09:54:47 +09:00
Bill Currie
e1226bd3f1 Quaternions aren't vectors :P 2011-01-28 21:57:04 +09:00
Bill Currie
2cce903cc9 Set the default storage class for local vars. 2011-01-28 21:56:17 +09:00
Bill Currie
bc7d42d176 Immediate constants now work, though still not shared. 2011-01-28 21:39:01 +09:00
Bill Currie
3c95667b79 Print data contents for most simple types. 2011-01-28 21:21:29 +09:00
Bill Currie
4476074021 Print more addresses as hex. 2011-01-28 18:03:26 +09:00
Bill Currie
4837e0bd18 Fix most of the FIXMEs in qfcc.c.
Functions and defs seem to be relocated correctly. Constants are very
broken, however.
2011-01-28 15:17:30 +09:00
Bill Currie
834417b8c8 Add "debug" diagnotic printing, and use it.
Debug diagnostics are silent for verbosity levels less than 1.
2011-01-28 13:28:45 +09:00
Bill Currie
a37bdd9fb5 Free removed sblocks. 2011-01-28 13:23:20 +09:00
Bill Currie
80424f6ad5 Ensure functions are always properly terminated.
Control that reaches the end of a function must see a return statement.
2011-01-28 13:14:30 +09:00
Bill Currie
9159daf99d Do simple unreachable block analysis and dead block removal. 2011-01-28 11:45:04 +09:00
Bill Currie
90a2738459 Add the label to the block to which it refers. 2011-01-28 11:41:53 +09:00
Bill Currie
c158b14286 Remove the labels list from the pr struct.
I'm not sure they were ever needed.
2011-01-28 11:40:25 +09:00
Bill Currie
4738c767a2 Fix branch label handling.
Conditional branches and goto now go to the correct location.
2011-01-27 21:11:32 +09:00
Bill Currie
95b17d9fd4 Rename add_statement_ref to add_statement_def_ref. 2011-01-27 21:10:37 +09:00
Bill Currie
bd78b8a7ee Enable more end-of-compilation code. 2011-01-27 15:44:12 +09:00
Bill Currie
cdea1d07aa Produce code for progs.src mode.
Separate compilation will take fixing object files.

The generated code is broken due to various relocation fixups being
broken, and float immediates seem to be badly broken.

Debug information is broken too.
2011-01-27 15:44:11 +09:00
Bill Currie
c7bbd40df6 Give special treatment to opcodes that have void operand types. 2011-01-27 15:44:11 +09:00
Bill Currie
71b5decbe8 Get assignments to .return working.
I really do not like the mechanism I currently use for handling pointer
derefences vs pointer assignments, but this will have to do for now until
I can get qfcc producing code again.
2011-01-27 15:44:11 +09:00
Bill Currie
56106892c8 The & operator produces a pointer, not void. 2011-01-27 15:44:10 +09:00
Bill Currie
1c3cc571f1 Pascal variables need defs too. 2011-01-27 15:44:10 +09:00
Bill Currie
f532fbc6df Convert all integer operands to float for v6 progs.
Converting only opc is no longer enough.
2011-01-27 15:43:59 +09:00
Bill Currie
1ed1efbdfb Implement the ROTL macro correctly.
Bit rotation requires unsigned ints.
2011-01-27 15:43:50 +09:00
Bill Currie
a6e65488ec Remove the "test" parameter from test_expr.
The parameter became redundant at some stage.
2011-01-27 08:31:51 +09:00
Bill Currie
f7d60397fb Set the type for zer_def used by labels. 2011-01-26 22:43:59 +09:00
Bill Currie
36c99a8da1 Get function def creation working again. 2011-01-26 14:48:22 +09:00
Bill Currie
5231e8e9f8 Handle .zero, .return and .param* properly. 2011-01-26 08:01:24 +09:00
Bill Currie
4966120e3b Untwist param's knickers. 2011-01-25 20:21:41 +09:00
Bill Currie
6ce3c5a59a Get statments being emitted to the code segment.
The first function seems to work fine, but there's a problems with the
scope of params causing params to get their knickers in a twist (tangled
linked list).
2011-01-25 15:46:48 +09:00
Bill Currie
fd3b594ca5 Move label relocs to the relevant statement block. 2011-01-25 15:45:31 +09:00
Bill Currie
849d013f5e Allocate space for function parameters. 2011-01-25 15:43:57 +09:00
Bill Currie
f45919df09 Need alias defs after all. 2011-01-25 15:42:26 +09:00
Bill Currie
a648f043de Give functions their own defspace.
The defspace is propogated through the function's sub-scopes.
2011-01-25 12:34:45 +09:00
Bill Currie
27c5139612 Give defspaces some backing memory.
I'm not sure I want all defspaces to have backing memory, but this will do
for now.
2011-01-25 12:16:13 +09:00
Bill Currie
34ffce50fa Ensure current_symtab gets set at the start of parsing.
current_symtab must be set even if the first thing encountered is a syntax
error.
2011-01-25 12:16:13 +09:00
Bill Currie
69b889756d Fix a misplaced ! 2011-01-25 12:16:13 +09:00
Bill Currie
726f293d0d Allocate space for defs and handle basic initializations.
Block initializers (arrays and structs) are still broken.
2011-01-25 12:16:13 +09:00
Bill Currie
30701980bc Get QC cfunctions and defs working. 2011-01-25 12:16:13 +09:00
Bill Currie
ade2e92ea4 Fix the immediate breakage in immediate handling. 2011-01-25 09:08:11 +09:00
Bill Currie
7e914b8c53 Fix copyright headers.
Add forgotten templates and fill in the information in places I had
forgotten. I hope I got the dates right (timezone issues).
2011-01-25 09:01:37 +09:00
Bill Currie
49b7c2d527 Document make_symbol 2011-01-25 09:01:37 +09:00
Bill Currie
0624408317 Move the diagnostic functions into their own file. 2011-01-24 21:54:57 +09:00
Bill Currie
d618e51dc8 Move save_string and make_string into strpool
Might not be the perfect place, but at least they're strongly related.
2011-01-24 21:32:48 +09:00
Bill Currie
483cbeba03 Fix a few FIXMEs. 2011-01-24 21:13:37 +09:00
Bill Currie
afc5b2827d Simplify def handling, use far data.
Since there is now a proper symbol table, defs are now just references to
memory locations and the symbol table takes care of duplicates.

Also, start using far data for ObjQC structures.

The qfo functions have been stubbed out until I figure out what to do with
object files in the new scheme.
2011-01-24 15:41:43 +09:00
Bill Currie
ce02fe8660 Fix the order of paramenters in the tree output.
Also get call nodes looking a little better.
2011-01-23 12:59:30 +09:00
Bill Currie
a79b6f0a6c Partially implement casts. 2011-01-23 11:53:08 +09:00
Bill Currie
bf626c9e00 Fix some simple fixmes 2011-01-23 11:13:56 +09:00
Bill Currie
20b14af024 Add "is_math" type check and use for unary +/-. 2011-01-23 11:12:58 +09:00
Bill Currie
341f370662 Rename is_math() to is_math_op(). 2011-01-23 11:12:05 +09:00
Bill Currie
dea6771d92 Create type_nil for passing nil into ... 2011-01-22 16:41:31 +09:00
Bill Currie
4ac80c2932 Get qfcc running again.
It segs when it tries to link, but that's because a real object file has
not been created yet. However, I can get my tree and flow diagrams :)
2011-01-22 15:52:57 +09:00
Bill Currie
55d3d17807 Add a missing break.
"return" falling through to "goto" was bad news :)
2011-01-22 15:52:01 +09:00
Bill Currie
d5f669af7a Nuke temp reference counting.
The whole reason for this crazy developement branch :)
2011-01-22 11:40:53 +09:00
Bill Currie
3b462e16cf Produce flow diagrams of the basic blocks. 2011-01-22 11:40:53 +09:00
Bill Currie
246778b5de Use function pointer tables instead of switch.
This seems to be better for complicated code. switch seems to be better
suited for relatively simple code.
2011-01-22 11:40:53 +09:00
Bill Currie
2f09efe547 Break out print_expr into its own file. 2011-01-21 20:31:40 +09:00
Bill Currie
bcb2667b73 Possibly get vector calls working. 2011-01-21 19:40:46 +09:00
Bill Currie
52b561f7cb Nuke bind expressions.
Since I'm planning on implementing CSE and other optimizations, they're
rather redundant (and I'm having trouble getting them to work).
2011-01-21 19:07:58 +09:00
Bill Currie
0d01930056 Link a bool to its block rather than the block's head.
This makes the flow make a little more sense.
2011-01-21 18:50:17 +09:00
Bill Currie
977c48d728 Make operator type overrides clear. 2011-01-21 15:57:53 +09:00
Bill Currie
aec9f256a7 Get calls mostly working.
Bind seems to be broken, but parameters seem to be being set correctly.
2011-01-21 15:54:53 +09:00
Bill Currie
5c5fa67e43 Minor tweaks of the expression tree output. 2011-01-21 15:34:42 +09:00
Bill Currie
96fae582e3 Implement bind expressions. 2011-01-21 11:27:40 +09:00
Bill Currie
4a24393d8d Temp expressions now use operands instead of defs. 2011-01-21 11:26:43 +09:00
Bill Currie
2998e578fb Get very basic deref assignments working.
More complicated expressions will not work yet.
2011-01-21 10:59:16 +09:00
Bill Currie
ff6e2584da Handle block sub-expressions that produce results. 2011-01-21 10:57:47 +09:00
Bill Currie
16e013ff5d Allow the operand to override the symbol's type. 2011-01-21 10:56:32 +09:00
Bill Currie
3f2793ef72 Get a lot of statements being generated. 2011-01-20 23:26:13 +09:00
Bill Currie
e45ea4b2ae Move the statement printing near the top of the file. 2011-01-20 18:07:24 +09:00
Bill Currie
35b7278967 Re-disable the next-edge constraints.
This gives a flatter layout.
2011-01-20 15:36:10 +09:00
Bill Currie
08e387ebac Slight improvement to branch instruction nodes/labels. 2011-01-20 15:33:13 +09:00
Bill Currie
f8cc347dce Print expressions as dot files.
While the resulting images can be a little confusing, they're much easier
to read than my cryptic postfix notation.
2011-01-20 15:23:19 +09:00
Bill Currie
0594609b3a Get the label from the right expression. 2011-01-19 22:25:43 +09:00
Bill Currie
5deda9c9b9 Clean out ex_def as ex_symbol replaces it. 2011-01-19 22:25:04 +09:00
Bill Currie
b5424bca7d Start work on getting expressions converted to internal statements. 2011-01-19 15:47:45 +09:00
Bill Currie
f2ef24d0cc Make symbols use the new value struct for constants. 2011-01-19 11:09:54 +09:00
Bill Currie
e08efe036b Move the constant expression values into their own struct. 2011-01-19 08:43:24 +09:00
Bill Currie
ff6e1b4d6c Get functions attempting to generate code.
However, the statements are only printed as expressions.
2011-01-19 08:38:09 +09:00
Bill Currie
87ce9f5333 Get basic function creation working.
Even more FIXMEs, but the pascal parser can now create functions. The
function records even get emitted.
2011-01-18 12:47:13 +09:00
Bill Currie
b186173d18 Fix a segfault in structure finalization. 2011-01-18 08:59:44 +09:00
Bill Currie
21c0c960ae Initialize data before types.
This is needed for string data. It might be better to init saved strings
separately, but this works for now.
2011-01-18 08:58:43 +09:00
Bill Currie
3fe7a7250a Handle unnamed structures in make_structure.
Symbols may not have null names.
2011-01-18 08:56:47 +09:00
Bill Currie
ea3895805b Rewrite much to use symbols and symtabs. Gut emit.c. Massive breakage.
That which isn't rewritten is horribly broken. However, this does include a
nice mechanism for building QC structs for emitting data.

emit.c has been gutted in the spirit of "throw one away".

There is much work to be done to get even variables emitted, let alone
code. Things should be a little more fun from here on.
2011-01-17 22:34:41 +09:00
Bill Currie
85de101aa3 Break out the defspace code.
This also makes some improvements to the free block handling code.
2011-01-17 22:34:41 +09:00
Bill Currie
d3a98af783 Make internal_error globally available. 2011-01-17 22:34:41 +09:00
Bill Currie
537b930ba6 Add new_symbol_type to ease creation of typed symbols.
This is inteded for code generation functions that need to create
variables and structures.
2011-01-17 12:04:41 +09:00
Bill Currie
ffea505678 Cleanup QC's constant handling based on QP. 2011-01-14 12:10:28 +09:00
Bill Currie
c38ea0b1bc Correct the spelling of "nil". 2011-01-14 12:07:40 +09:00
Bill Currie
fb8b3d1211 Rework the lexer and parser to use symbols instead of defs.
Currently parses the test program just fine, but code generation is very
very broken.
2011-01-13 14:58:16 +09:00
Bill Currie
8f71986306 Add symbol expressions (like def expressions).
They will eventually replace def expressions. Currently quite broken.
2011-01-13 14:54:24 +09:00
Bill Currie
008f4e1929 Don't return .return in advanced mode. 2011-01-13 14:50:25 +09:00
Bill Currie
5b8725ca66 Rewrite the symbol (table) management in light of actual usage. 2011-01-13 14:48:38 +09:00
Bill Currie
ac14db7b1b Create a function to ease param list building.
This is especially useful for QuakePascal, but it will mean I'll be able to
get rid of the parameter reversals in Ruamoko later on.
2011-01-13 14:45:53 +09:00
Bill Currie
258c896e4d Create a function to build if/else blocks. 2011-01-13 14:33:16 +09:00
Bill Currie
638f4445cc More return code cleanup.
Don't use the true void return in traditional mode.
Prefer the true void return over "done" at the end of functions.
Don't emit the above if the last emitted statement is a return and there is
no label at the end of the function.
2011-01-13 00:46:46 +09:00
Bill Currie
3c9991364b Add a "void return" instruction.
I got fed up with always having to explicty return something.
2011-01-13 00:29:56 +09:00
Bill Currie
9ce9b70484 Add variadic functions.
Already extending QuakePascal, and many basics aren't there yet :P
2011-01-12 23:39:59 +09:00
Bill Currie
02b3dde83b Make QuakePascal programs runnable.
Generate a mini-main function (".main", to avoid namespace pollution) that
calls the function named by "program", and make qwaq check for ".main" as
well as "main". If both are present, ".main" will take priority.
2011-01-12 23:39:22 +09:00
Bill Currie
332b7da127 Minor header cleanup. 2011-01-12 23:34:15 +09:00