QuakeForge  0.7.2.210-815cf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Def handling

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_talias_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_tnew_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 .tmpN where N is a non-negative integer. The type of the temporary def can change throughout its life, but the size will never change.

Temporary defs are bound to the current function (current_func must be valid). They are always allocated from the funciont's local defspace.

def_ttemp_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...
 

Detailed Description

Typedef Documentation

typedef struct def_s def_t

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.

Specify the storage class of a def.

Enumeration Type Documentation

Specify the storage class of a def.

Enumerator
sc_global 

def is globally visibil across units

sc_system 

def may be redefined once

sc_extern 

def is externally allocated

sc_static 

def is private to the current unit

sc_param 

def is an incoming function parameter

sc_local 

def is local to the current function

Function Documentation

def_t* alias_def ( def_t def,
struct type_s type,
int  offset 
)

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.

Parameters
defThe def to be aliased.
typeThe type of the alias.
offsetOffset of the alias relative to the def.
Returns
The def aliasing def.
Todo:
Make aliasing to the same type a no-op?
int def_offset ( def_t def)

Convenience function for obtaining a def's actual offset.

Takes care of an alias def's relative offset.

Parameters
defThe def of which to obtain the offset. May be an alias def.
Returns
The actual offset of the def in the def's defspace.
int def_overlap ( def_t d1,
def_t d2 
)

Determine if two defs overlap.

Parameters
d1The first def to check. May be an alias def.
d2The second def to check. May be an alias def.
Returns
1 if the defs overlap, 2 if d1 fully overlaps d2, otherwise 0.

Defs in different spaces never overlap.

int def_size ( def_t def)

Convenience function for obtaining a def's size.

Whether the def is an alias or not is irrelevant.

Parameters
defThe def of which to obtain the size.
Returns
The size of the def.
void def_to_ddef ( def_t def,
ddef_t ddef,
int  aux 
)

Initialize a vm def from a qfcc def.

Parameters
defThe qfcc def to copy.
ddefThe vm def to be initialized.
auxCopy the field object's type rather than the def's.
Bug:
The def is not verified to be a field def when aux is true.
int def_visit_all ( def_t def,
int  overlap,
int(*)(def_t *, void *)  visit,
void *  data 
)

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.

Parameters
defThe def representing the alias cluster to visit.
overlapIf non-zero, then only defs that overlap def will be visited. If 2, then the given def must fully overlap the visited def.
visitThe 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.
dataPointer to the data needed by visit.
Returns
The value returned by visit returned non-zero, otherwise 0.
void free_def ( def_t def)

Free a def.

If the def has space allocated to it, the space will be freed.

Parameters
defThe 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.

Note
current_func must be valid.
Parameters
tempThe 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().

Parameters
symThe symbol for which to create and initialize a def.
typeThe type of the def. sym_t::type is set to this. If null, the default type is used.
initIf not null, the expressions to use to initialize the def.
spaceThe space from which to allocate space for the def.
storageThe 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.

Parameters
nameThe name for the def. May be null for unnamed defs.
typeThe type for the def. May be null for untyped defs.
spaceThe defspace to which the def belongs. Must not be null for if storage is not sc_extern.
storageThe storage class for the def.
Returns
The new def.
def_t* temp_def ( etype_t  type,
int  size 
)

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.

Note
current_func must be valid.
Parameters
typeThe low-level type of the temporary variable.
sizeThe amount of space to allocate to the temp.
Returns
The def for the temparary variable.
Bug:
size is not checked for validity (must be 1-4).
Todo:
support arbitrary sizes