Commit Graph

152 Commits

Author SHA1 Message Date
Bill Currie 9ccfe8aefc [qfcc] Rewrite init_elements
The end goal was to fix erroneous non-constant initializer errors for
the following (ie, nested initializer blocks):

    typedef struct { int x; int y; } Point;
    typedef struct { int width; int height; } Extent;
    typedef struct Rect_s { Point offset; Extent extent; } Rect;
    Rect makeRect (int xpos, int ypos, int xlen, int ylen)
    {
	Rect rect = {{xpos, ypos}, {xlen, ylen}};
	return rect;
    }

However, it turned out that nested initializer blocks for local
variables did not work at all in that the relocations were lost because
fake defs were being created for the generated instructions.

Thus, instead of creating fake defs, simply record the offset relative
to the base def, the type, and the basic type initializer expression,
then generate instructions that all refer to the correct def but with a
relative offset.

Other than using the new element system, static initializers are largely
unaffected.
2020-03-05 11:05:13 +09:00
Bill Currie b186332da0 [qfcc] Make initialization of external vars an error 2020-03-03 17:33:56 +09:00
Bill Currie caa297b756 [qfcc] Remove type alias encoding
It proved to be too fragile in its current implementation. It broke
pointers to incomplete structs and switch enum checking, and getting it
to work for other things was overly invasive. I still want the encoding,
but need to come up with something more robust.a
2020-03-01 16:13:18 +09:00
Bill Currie b4aebc120e [qfcc] Treat { } as nil for initializing compound types 2020-02-27 20:30:39 +09:00
Bill Currie 27ae5ccfce Fix ICE after incomplete type error
Attempting to define a variable with an incomplete type is an error, and
results in a default size 1 of allocated, but I forgot to set default
alignment when implementing alignment.
2020-02-24 00:07:39 +09:00
Bill Currie 607fd2e30e Allow constant initialized globals in advanced code
Use -C const-initializers to enable (or no-const-initializers to disable
in traditional/extended code).
2020-02-23 22:51:00 +09:00
Bill Currie e23aa40994 Implicitly cast unadorned floating point constants
Floating point constants without f or d adornments will automatically
cast, without warnings, to the type appropriate to the rest of the
expression.
2020-02-23 22:28:54 +09:00
Bill Currie 6bcc2c49ab Use helper functions for type checks
They hide the evil details of aliased types. More to come :/
2020-02-19 21:41:46 +09:00
Bill Currie 6ce99afa5b Catch double demotion in global initializers
Local initializers are handled by regular assignments
2020-02-15 23:49:12 +09:00
Bill Currie e4eb793fb3 Treat aliased values as constant
One step closer to cast address initializers working.
2020-02-15 23:49:12 +09:00
Bill Currie a4a57b6ffd Implement aligned allocations 2020-02-15 23:49:12 +09:00
Bill Currie b996fb7aa4 Make operand->type actual type instead of low-level
And clean up the resulting mess. This fixes struct copy, but uncovers
another bug :/
2019-06-17 23:38:34 +09:00
Bill Currie bf0543f7fb Be paranoid about temp var sizes
Prevents array index errors.
2019-06-10 00:19:48 +09:00
Bill Currie 28a2b96800 Implement automatic array sizing from initializer 2019-06-09 23:11:38 +09:00
Bill Currie d9c9686288 Make initialized globals non-constant
This is for modern code. Traditional code still treats initialized
globals as constant and nosave. This will make a bit of a mess of
modern code that expects traditional behavior.
2019-06-09 19:23:23 +09:00
Bill Currie 607ec3124e More dead code removal.
I have no idea why this hung around. It appears to be old array/struct
initialization.
2018-10-15 22:12:40 +09:00
Bill Currie ff5c1cd4c2 Clean up redundant type parameter to initialize_def. 2018-10-15 22:11:20 +09:00
Bill Currie 78e0a8dc52 Support assigning non-constant vector expressions. 2018-10-12 22:05:17 +09:00
Bill Currie 3295370328 Expose and use field_expr().
This may cause problems later on, but it is needed for the binary_expr()
cleanup.
2013-09-27 23:15:57 +09:00
Bill Currie ca0b03687f Change the naming of ALLOC's free-list.
Rather than prefixing free_ to the supplied name, suffix _freelist to the
supplied name. The biggest advantage of this is it allows the free-list to
be a structure member. It also cleans up the name-space a little.
2013-03-08 22:16:31 +09:00
Bill Currie 3af031c33d Move the rest of the obj specific stuff into class.c.
This gives better hiding of implementation details.
2012-12-20 10:10:41 +09:00
Bill Currie 45c753f639 Catch attempts to create a static instance of a class.
It is actually an error to create a static instance of a class.
2012-12-20 10:10:41 +09:00
Bill Currie 463e41082a Support struct style initializers for vectors and quaternions.
The current implementation probably needs more work, but for the case where
I needed it, it does the job.
grid.r💯     vector      size = {range, range, 0};
0115 store.f range, size
0116 store.f range, [$2ac]
0117 store.f .zero, [$2ad]
2012-12-16 14:24:19 +09:00
Bill Currie 2dc60d4f9a Allow tests for full overlap of defs.
Not actually used yet, but I imagine I'll want it.
2012-12-13 14:42:51 +09:00
Bill Currie 204a0b3f72 Make def_visit_all return the actual result of visit.
This way, def_visit_all is a little more useful (though I think I might
redo the one case that's using this feature).
2012-12-13 09:47:00 +09:00
Bill Currie 75be251d65 Create and use def_visit_all.
Even though it turned out there were only two copies of the def alias
handling code, I got tired of writing it. The code is easier to read, too
:)
2012-12-12 12:01:31 +09:00
Bill Currie 045947706e Compare the base def spaces in def_overlap.
The space field in alias defs is always null and thus aliases would never
overlap the aliased def. Oops.
2012-12-11 19:51:34 +09:00
Bill Currie b5a72320bb Make alias defs and temps more obvious in dumps. 2012-12-11 12:26:48 +09:00
Bill Currie 8f274f5b1d Add convenience functions for getting a def's offset and size. 2012-12-10 14:40:43 +09:00
Bill Currie 4f70b48370 Add a function to check if two defs overlap.
Very useful for alias handling :)
2012-12-10 13:23:45 +09:00
Bill Currie eb8fd55677 Move set.c into libQFutil.
Also move the ALLOC/FREE macros from qfcc.h to QF/alloc.h (needed to for
set.c).

Both modules are more generally useful than just for qfcc (eg, set
builtins for ruamoko).
2012-12-06 20:52:53 +09:00
Bill Currie 7071a46936 Make convert_value create a new value.
It operating in-place proved to be troublesome.
2012-12-05 22:16:08 +09:00
Bill Currie 2904c619c1 Don't bother creating an alias for a def of the same type. 2012-12-05 19:43:27 +09:00
Bill Currie 6074a6648f Do some sanity checking on storage class and defspace type.
Params and locals in virtual spaces, static vars in backed. Otherwise,
whatever (for now). Now func-static.r aborts :)
2012-12-04 14:18:17 +09:00
Bill Currie 98a0afa38f Add and use FREE() to complement ALLOC().
Now it will be easy to test memory access with valgrind (just compile with
DEBUG_QFCC_MEMORY defined).
2012-12-04 13:23:31 +09:00
Bill Currie 0872961269 Do a little bit of cleanup. 2012-12-04 12:48:52 +09:00
Bill Currie 7412a45c65 Attach alias defs to their base def.
With this, alias defs become singletons based on the def they alias and the
type and offset of the alias. Thus, the removal of the free_def call in
emit.c.
2012-12-03 12:40:00 +09:00
Bill Currie 919ea8192a Make alias_def take an offset.
alias_def now always creates an offset def (though the usual case has an
offset of 0). The if the alias escapes the bounds of the base def, an
internal error will be generated.
2012-12-03 11:50:26 +09:00
Bill Currie 9d0332ae30 Make alaising a def to a larger type an internal error.
It really doesn't seem wise to allow the compiler to do so as it would
overwrite unrelated defs. The only time such a thing is valid is the return
statement (silly vm design), and that's read-only.
2012-12-03 11:38:55 +09:00
Bill Currie 9ca5a9e86c Make aliasing an alias def an internal error.
I haven't seen the bug message show up, so it seems safe, and is probably a
good idea with what I have in mind.
2012-12-03 11:36:14 +09:00
Bill Currie 5725c5124c Rename the storage_class_t enum values.
With the intoduction of the statement type enum came a prefix clash. As
"st" makes sense for "statement type", I decided that "storage class"
should be "sc". Although there haven't been any problems as of yet, I
decided it would be a good idea to clean up the clash now. It also helps
avoid confusion (I was a bit surprised after working with st_assign etc to
be reminded of st_extern etc).
2012-12-02 10:11:30 +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 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 158e261a8f Give reusable temps their own linked list.
The next field is used for linking all defs in a space. Oops.
2012-11-19 10:33:03 +09:00
Bill Currie 1af4d5eeed Ensure reused temps have the correct type.
The type of a temp may change through its life as it's really the location
and name that are reused.
2012-11-19 10:31:22 +09:00
Bill Currie 0c3aeb30aa Reuse tempary variables.
Now that I've got nice code, it was worth doing. Unfortunatly, bsearch
style switch statements have problems.
switch.r:14: BUG: temp users went negative: <tmp 0x21b6840:-1>
switch.r:14: BUG: temp users went negative: <tmp 0x21b6840:-2>
switch.r:14: BUG: temp users went negative: <tmp 0x21b6840:-3>
switch.r:14: BUG: temp users went negative: <tmp 0x21b67d0:-1>
2012-11-18 19:10:18 +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 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 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 cc24e2e67e Initialize global string vars correctly.
Ouch, I'd fixed that for arrays, but not normal vars.
2012-11-09 12:23:04 +09:00