Commit Graph

560 Commits

Author SHA1 Message Date
Bill Currie 4b64912793 Begin doing some data flow analysis.
In te beginning, live variables.
2012-11-15 13:44:08 +09:00
Bill Currie c00e666668 Expose find_operands.
It has proven to be a generally useful function, not just for dags.
2012-11-15 13:44:08 +09:00
Bill Currie 0a2ce6d381 Fix some doxygen comments. 2012-11-15 13:44:08 +09:00
Bill Currie 0b49bd343c Collect information on statements that set or use vars.
First, it turns out using daglabels wasn't such a workable plan (due to
labels being flushed every sblock). Instead, flowvars are used. Each actual
variable (whether normal or temp) has a pointer to the flowvar attached to
that variable.

For each variable, the statements that use or define the variable are
recorded in the appropriate set attached to each (flow)variable.
2012-11-15 13:44:08 +09:00
Bill Currie acedc65de1 Make an array of statements for the function.
With this, sets can be used to represent statements.
2012-11-15 13:44:07 +09:00
Bill Currie 98245f6d00 Bury a dead field. 2012-11-15 13:44:07 +09:00
Bill Currie 8844ac61a2 Rename dump_flow to dump_sblock and move to dot_sblock.c 2012-11-15 13:44:07 +09:00
Bill Currie acde6ca0a0 Handle jumpb statements in dot_sblock and flow graphs. 2012-11-15 13:44:07 +09:00
Bill Currie ffa08a99c2 Store the initializer expression in the def.
Initially, this will be used for collecting the targets of a jumpb
instruction.
2012-11-15 13:44:07 +09:00
Bill Currie d7177a78e9 Rewrite the flow graph code.
The flow graph nodes are now properly separated from the graph, and edge
information is stored in the graph struct. This actually made for much
cleaner code (partly thanks to the use of sets and set iterators).

Flow graph reduction has been (temporarily) ripped out as the entire
approach was wrong. There was also a bug in that I didn't really understand
the dragon book about selecting nodes and thus messed things up. The
depth-first search tree "fixed" the problem, but was really the wrong
solution (sledge hammer :P).

Also, now that I understand that dot's directed graphs must be acyclic, I
now have much better control over the graphs (back edges need to be
flipped).
2012-11-15 13:44:07 +09:00
Bill Currie b9599a7119 Better set memory management.
At the cost of one pointer per set, sets can now be allocated and freed
more efficiently (especially since malloc might round things up).
2012-11-15 13:44:07 +09:00
Bill Currie 2385cf65c2 Rename setstate_t to set_iter_t.
After all, it is an iterator :).
2012-11-15 13:44:07 +09:00
Bill Currie 8c5a2b3d11 Implement depth-first searching for flow graphs.
This fixes the bogusly irreducible graphs.
2012-11-15 13:44:07 +09:00
Bill Currie 53622dbb99 Perform graph reduction on the function's flow graph.
The reduction is performed itteratively until the graph is irreducible, but
such that each reduction wraps the previous graph. Unfortunately, due
depth-first searching not being implemented, graphs that should be reduced
(ie, those with natural loops).
2012-11-15 13:44:07 +09:00
Bill Currie 388b6e6e8f Add set_size ().
Return the number of members in the set.
2012-11-15 13:44:07 +09:00
Bill Currie 8567508963 Rewrite set_first() and add set_next().
set_first() now returns a pointer to a setstate_t struct that holds the
state necessary for scanning a set. set_next() will automatically delete
the state block when the end of the set is reached. set_delstate() is also
provided to allow early termination of the scan.
2012-11-15 13:44:07 +09:00
Bill Currie 2da038ce0f Bring back dot_flow.c.
However, it produces simplified flow graphs (ie, just nodes and edges, no
statements, though later on data flow information will be added).
2012-11-15 13:44:07 +09:00
Bill Currie 8b374305d2 Rename dot_flow.c and print_flow.
They're now dot_sblock.c and print_sblock. The new names both better
reflect their purpose and free up "flow" for outputting the real flow
analysis graphs.
2012-11-15 13:44:07 +09:00
Bill Currie c483770121 Rework flow.c with the aim of graph reduction.
Much of the data recently added to sblock_t has been moved to flownode_t.
No graph reduction is carried out yet, but the initial (innermost level)
graph has been built.
2012-11-15 13:44:07 +09:00
Bill Currie da446fd343 Detect natural loops.
Non-nested loops that have the same head-node are merged into one loop.
However, loop nesting is not currently detected (next step).
2012-11-15 13:44:07 +09:00
Bill Currie 8fb958603c Add set_first.
It returns the first element of a set. If the set is empty, -1 (unsigned)
is returned.
2012-11-15 13:44:07 +09:00
Bill Currie 1fead50f4e Calculate the dominators of each node in the flow graph.
The dominators are represented by sets using the node numbers.
2012-11-15 13:44:07 +09:00
Bill Currie 964ea7f9fe Add set_as_string for debug output. 2012-11-15 13:44:07 +09:00
Bill Currie 7853bf1859 Calculate a node's successors and predecessors.
The dot graphs are a little odd (arrow heads on the wrong end of the
predecessor edges), but things seem to be correct.
2012-11-15 13:44:06 +09:00
Bill Currie 739ebc522c Begin working on flow analysis.
For now, variable and flow graph node maps are built.
2012-11-15 13:44:06 +09:00
Bill Currie f30010b367 Add some docs to function.h 2012-11-15 13:44:06 +09:00
Bill Currie cdc790d0c8 Add a set type and support code. 2012-11-15 13:44:06 +09:00
Bill Currie dc9d2a982e Make the returned dag a linked list of root-nodes.
A dag can have mulitple "root" nodes (ie, nodes with no parents).
2012-11-15 13:44:06 +09:00
Bill Currie a22260030a Use value for pointer operands.
This allows daglabels on pointer operands without a redundant daglabel
pointer.
2012-11-15 13:44:06 +09:00
Bill Currie 0c58cd9067 Generate only one daglabel for value operands.
As each value is now unique, their labels can also be unique, which will
improve CSE.
2012-11-15 13:44:06 +09:00
Bill Currie 0ccf4093e4 Handle attached identifier labels correctly.
I'd forgotten I had the prev field. Makes for much cleaner code.
2012-11-15 13:44:06 +09:00
Bill Currie 28ce35f1c1 Make values independent objects.
values are now uniquely allocated (for the current object file). With
this, constants in dags will work.
2012-11-15 13:44:06 +09:00
Bill Currie dbf1aa8f72 Attach dags to statement blocks.
Now, if a dag is attached to a statement block, it will be included in the
flowgraph with that statement block.
2012-11-15 13:44:06 +09:00
Bill Currie d9354255a3 Avoid double-printing dag nodes. 2012-11-15 13:44:05 +09:00
Bill Currie 7b2e426545 Support temp operands in dags. 2012-11-15 13:44:05 +09:00
Bill Currie 8015e1b1e9 Put the dags stuff into a qfcc sub-section.
Not much point writting docs if they can't be found.
2012-11-15 13:44:05 +09:00
Bill Currie aa2943709e Start work on building dags from basic blocks.
Doesn't compile and the design is in flux anyway, but I want to get back to
iqm.
2012-11-15 13:44:05 +09:00
Bill Currie 60108c688c Change dags from binary to trinary.
I'd forgotten some instructions take three inputs that can benefit from
CSE.
2012-11-15 13:44:05 +09:00
Bill Currie 0fefeb73fe Initial support for basic block dags.
Currently, only dumping to dot, but that seems to be a very sensible place
to start: debug support.
2012-11-15 13:44:05 +09:00
Bill Currie d5c831b6da Add a little test case for accessing types.
Using ruamoko to access ruamoko type encodings is actually quite pleasant
:)
2012-11-15 13:40:11 +09:00
Bill Currie 552142497e Support progs.dat when dumping type encodings.
Knock up a quick and dirty progs-to-qfo "converter" (strings and types
only) to re-use the qfo types dumper.
2012-11-15 11:58:13 +09:00
Bill Currie 9691b50f0f Make .type_encodings more useful.
Rather than just a pointer, it is now a struct with a pointer and size
indicating the extent of the type encodings block.
2012-11-15 11:57:16 +09:00
Bill Currie 453ac11bc3 Correct some comments. 2012-11-14 17:13:14 +09:00
Bill Currie e05c12e16d Make linker_add_def take a pointer for the value.
While it looks like I might not use it for the type encodings, it should be
useful in the future.
2012-11-14 13:12:58 +09:00
Bill Currie 5b7b49b100 Add a QFO_TYPE macro to get a qfot_type_t pointer.
In the end, it wasn't used, but it could be handy in the future.
2012-11-13 21:45:54 +09:00
Bill Currie 93b007b1f8 Take care of relocs when defining external defs.
For most of the cases, some relocs may have been lost, but they were
certainly lost for type encodings. Now that all seems to be fixed.
2012-11-12 16:14:09 +09:00
Bill Currie c96718493a A bit of a cleanup before fixing class type defs.
All internal structs now have "proper" names, and fit the naming convention
(eg, obj_module (like objective-c's types, but obj instead of objc). Some
redundant types got removed (holdovers from before proper struct tag
handling).

Also, it has proven to be unnecessary to build internal classes, so
make_class and make_class_struct are gone, too.
2012-11-12 11:12:33 +09:00
Bill Currie d13ce81b4f Ensure the type's encoding string is valid.
When encoding a type to a qfo file, the type's encoding string is written
and thus needs to be valid prior to actually doing the encoding. The
problem occurs mostly in self-referential structs (particularly, obj_class)
because the struct is being encoded prior to the pointer to the struct.
2012-11-11 20:22:48 +09:00
Bill Currie 86091856be Revamp the static class creation.
Type names are cleaned up, as is the creation. Also, the class pointer in
the type encoding now gets emitted. However, Still need to actually create
_OBJ_CLASS_Class and fix the type encoding reloc handling in the linker.
2012-11-10 12:56:19 +09:00
Bill Currie 9095e1eabc Rework build_switch to use initialize_def.
This required support for label reference expressions, whose purpose is to
represent the address of a label.
2012-11-09 12:22:34 +09:00
Bill Currie afbab60c25 Create linker_find_def.
It turns out I didn't need it, but it could be useful in the future, so
I'll leave it in.
2012-11-09 11:57:06 +09:00
Bill Currie eb86a66ce5 Do some class object type renaming.
type_object -> type_obj_object
type_Class -> type_obj_class
type_ClassPtr -> type_Class

In the process, one more FIXME is gone :)
2012-11-08 20:58:48 +09:00
Bill Currie 377f8f9d56 Use an explicit flag for class initialization.
Much cleaner than messing with class_Class, which is about to go away.
2012-11-08 17:14:33 +09:00
Bill Currie 7e293a38e8 Check for double-chaining of types.
Chaining a type twice will form a loop in the type list, causing find_type
to go into an infinite loop.
2012-11-08 17:14:33 +09:00
Bill Currie a3a22f2a1b Add the ability to dump qfo type encoding. 2012-11-08 17:06:38 +09:00
Bill Currie ed4018fd8d Clear out the function overloading tables between compiles.
Fixes some issues with multiple compiles (especially mixed languages!).
2012-11-01 20:53:33 +09:00
Bill Currie f8bdd909cc Separate out C and html quoting into separate functions.
Dot sometimes wants normal C quotes, othertimes html. Quite annoying,
really, but this is cleaner anyway.
2012-10-30 12:31:22 +09:00
Bill Currie 034139b806 Move some code around so it's more accessible. 2012-10-27 11:43:29 +09:00
Bill Currie 144387c3e3 Add shared.h to the dist files. 2012-10-26 16:16:46 +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 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 23a38738fc Massive whitespace cleanup.
Lots of trailing whitespace and otherwise blank lines.
2012-05-22 08:23:22 +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 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 cb8fe4eb38 Correct a "spelling" error. 2012-05-03 11:54:36 +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 bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +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
Bill Currie d910c14935 Clean up some doxygen warnings. 2011-07-10 19:12:07 +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 c4a398850a Fix defs as constants for vectors and quaternions. 2011-04-04 21:31:59 +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 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 8368f57fbf Close a potential buffer overflow. 2011-03-09 11:09:46 +09:00
Bill Currie 39278ba8cc Explicitly select between direct and indirect moves. 2011-03-09 10:30:57 +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 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 fe3d228658 Maintain a symbol table for entity fields. 2011-03-06 15:38:19 +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 8cfa80b5d4 Implement think expressions. 2011-03-05 18:01:37 +09:00
Bill Currie 8eb5fd653a Perform the relocations!!!
line numbers seem to be broken, but the code itself looks good.
2011-03-05 08:41:14 +09:00
Bill Currie 7fb22bd1e4 Make D_STRING() more useful and add D_GETSTR() 2011-03-04 21:28:12 +09:00
Bill Currie d6d8b5b49d Generate the debug symbol file. 2011-03-04 18:46:05 +09:00
Bill Currie 4192ef835c Delay initialization of obj_module_t as long as possible.
This keeps the type descriptor out of progs that never use any
Objective-QC features.
2011-03-04 08:25:50 +09:00
Bill Currie c99f3aba0e Add the new header files for make dist. 2011-03-04 00:11:13 +09:00
Bill Currie c5ecc170b6 Give labels a usage count to detect unused labels. 2011-03-03 15:28:49 +09:00
Bill Currie d937172243 Create and use alias operands for alias expressions.
This avoids the alias expression modifying the operand used in other
expressions.
2011-03-03 13:46:07 +09:00
Bill Currie 45de7327dc Implement alias expressions (finally).
Alias expressions are like cast expressions, but never do any conversions.
2011-03-03 11:06:10 +09:00
Bill Currie c12211d8bb Support enum results for boolean expressions.
eg enum BOOL x = a && b;
2011-03-02 22:46:55 +09:00
Bill Currie 4a99f8dcbd Write the linker output to progs.dat.
There is much breakage, but qfcc now produces a progs.dat from either
progs.src or object files. Better yet, the progs.src result is passed
through the linker, removing much duplicate code.
2011-03-02 20:51:00 +09:00
Bill Currie 29985efcef Expose some linker functions to the rest of the compiler.
They proved to be useful for cleaning up the final compilation stages.
2011-03-02 20:48:55 +09:00
Bill Currie ecb995a8f7 Rewrite qfo_to_progs() to go direct from qfo to progs.dat.
Relocs and debug info is currently broken.
2011-03-02 19:06:43 +09:00
Bill Currie 824d8bfc3c Remove some now unnecessary functions. 2011-03-02 14:21:20 +09:00
Bill Currie 9f126ed805 Add some quick type access macros. 2011-03-01 15:18:12 +09:00
Bill Currie b544196c21 Change ptrfld to fldptr for consistency with type.h. 2011-02-28 23:12:32 +09:00
Bill Currie 8b661bbb89 Rename qfo_reloc_t's def to target and correct its usage. 2011-02-27 11:37:24 +09:00
Bill Currie 4f6d18a328 Encode the basic type for functions, fields and pointers.
Very important for distinguishing them from other types.
2011-02-27 00:33:16 +09:00
Bill Currie 55043310fc Fix the QFO_POINTER macro 2011-02-27 00:31:52 +09:00