Data Structures | |
struct | def_s |
Represent a memory location that holds a QuakeC/Ruamoko object. More... | |
Typedefs | |
typedef struct def_s | def_t |
Represent a memory location that holds a QuakeC/Ruamoko object. More... | |
typedef enum storage_class_e | storage_class_t |
Specify the storage class of a def. More... | |
Enumerations | |
enum | storage_class_e { sc_global, sc_system, sc_extern, sc_static, sc_param, sc_local } |
Specify the storage class of a def. More... | |
Functions | |
def_t * | alias_def (def_t *def, struct type_s *type, int offset) |
Create a def that aliases another def. More... | |
int | def_offset (def_t *def) |
Convenience function for obtaining a def's actual offset. More... | |
int | def_overlap (def_t *d1, def_t *d2) |
Determine if two defs overlap. More... | |
int | def_size (def_t *def) |
Convenience function for obtaining a def's size. More... | |
void | def_to_ddef (def_t *def, ddef_t *ddef, int aux) |
Initialize a vm def from a qfcc def. More... | |
int | def_visit_all (def_t *def, int overlap, int(*visit)(def_t *, void *), void *data) |
Visit all defs that alias the given def, including itself. More... | |
void | free_def (def_t *def) |
Free a def. More... | |
void | initialize_def (struct symbol_s *sym, struct type_s *type, struct expr_s *init, struct defspace_s *space, storage_class_t storage) |
Initialize a def referenced by the given symbol. More... | |
def_t * | new_def (const char *name, struct type_s *type, struct defspace_s *space, storage_class_t storage) |
Create a new def. More... | |
Temporary defs | |
Temporary defs are used for recycling memory for tempary variables. They always have names in the form of Temporary defs are bound to the current function (current_func must be valid). They are always allocated from the funciont's local defspace. | |
def_t * | temp_def (etype_t type, int size) |
Get a temporary def. More... | |
void | free_temp_def (def_t *temp) |
Free a tempary def so it may be recycled. More... | |
Represent a memory location that holds a QuakeC/Ruamoko object.
The object represented by the def may be of any type (either internally defined by qfcc (float, int, vector, etc) or user defined (structs, arrays etc)).
Unless the def is external (ie, declared to be in another compilation unit), defs are always attached to a defspace. Storage for the def's object is allocated from that space.
typedef enum storage_class_e storage_class_t |
Specify the storage class of a def.
enum storage_class_e |
Specify the storage class of a def.
Create a def that aliases another def.
Aliasing a def to the same type is useless, but not checked. Aliasing a def to a type larger than the def's type will generate an internal error.
If the offset is negative, or the offset plus the size of the aliasing type is greater than the size of the def's type, then an internal error will be generated.
The alias def keeps track of its base def and is attached to the base def so any aliases of that def can be found.
For any combination of type and offset, there will be only one alias def created.
def | The def to be aliased. |
type | The type of the alias. |
offset | Offset of the alias relative to the def. |
Convenience function for obtaining a def's actual offset.
Takes care of an alias def's relative offset.
def | The def of which to obtain the offset. May be an alias def. |
Determine if two defs overlap.
d1 | The first def to check. May be an alias def. |
d2 | The second def to check. May be an alias def. |
Defs in different spaces never overlap.
Convenience function for obtaining a def's size.
Whether the def is an alias or not is irrelevant.
def | The def of which to obtain the size. |
Initialize a vm def from a qfcc def.
def | The qfcc def to copy. |
ddef | The vm def to be initialized. |
aux | Copy the field object's type rather than the def's. |
Visit all defs that alias the given def, including itself.
First, the given def is visited, and then every candidate def connected to the given def via the aliasing links will be visited. Candidate defs are those that overlap the given def when overlap is true, otherwise every connected def is a candidate. overlap has no meaning if the given def is not an alias def as all alias defs connected to the given def are guaranteed to overlap with the given def. Any def will be visited at most once.
The visit function may return non-zero to terminate the loop early. Any data needed by visit should be made available via data, which will be passed on to visit via the second parameter. The first parameter of visit is the def currently being visted.
This function is useful also for defs that are not alias defs and do not have any aliases: visit will be called for the def and then the function will return.
def | The def representing the alias cluster to visit. |
overlap | If non-zero, then only defs that overlap def will be visited. If 2, then the given def must fully overlap the visited def. |
visit | The function to call when visiting a def. The first parameter is the def being visited, and the second parameter is data passed on. If non-zero is returned, the pass through the alias cluster will terminate. |
data | Pointer to the data needed by visit. |
void free_def | ( | def_t * | def | ) |
Free a def.
If the def has space allocated to it, the space will be freed.
def | The def to be freed. |
void free_temp_def | ( | def_t * | temp | ) |
Free a tempary def so it may be recycled.
The temp is put into a list of free temp defs maintained by current_func.
temp | The temp def to be recycled. |
void initialize_def | ( | struct symbol_s * | sym, |
struct type_s * | type, | ||
struct expr_s * | init, | ||
struct defspace_s * | space, | ||
storage_class_t | storage | ||
) |
Initialize a def referenced by the given symbol.
The symbol is checked for redefinition. (FIXME check rules)
If type is null, then the def will be given the default type (as specified by type_default).
If an initializer expressions is given (init is not null), then it must be a constant expression (eg, 2 + 3) for non-local defs. Aggregate types (structs, arrays (unions?)) use block expressions where each expression in the block initializes one element of the aggregate. Nested aggregates simply use nested block expressions. As for simple types, each expression in a block expression must also be constant for non-local defs.
For space and storage, see new_def().
sym | The symbol for which to create and initialize a def. |
type | The type of the def. sym_t::type is set to this. If null, the default type is used. |
init | If not null, the expressions to use to initialize the def. |
space | The space from which to allocate space for the def. |
storage | The storage class of the def. |
def_t* new_def | ( | const char * | name, |
struct type_s * | type, | ||
struct defspace_s * | space, | ||
storage_class_t | storage | ||
) |
Create a new def.
Defs may be unnamed.
Untyped defs (used by type encodings) never allocate space for the def.
If storage is not sc_extern and type is not null, space of the size specified by type will be allocated to the def from the defspace specified by space.
name | The name for the def. May be null for unnamed defs. |
type | The type for the def. May be null for untyped defs. |
space | The defspace to which the def belongs. Must not be null for if storage is not sc_extern. |
storage | The storage class for the def. |
Get a temporary def.
If the current function has a free temp def of the same size as size, then that def will be recycled, otherwise a new temp will be created. When a new temp is created, its name is set to .tmpN
where N
comes from function_t::temp_num, which is then incremented.
type | The low-level type of the temporary variable. |
size | The amount of space to allocate to the temp. |