libFirm
Type System

Datastructure to hold type information. More...

Modules

 Array
 The array type represents linear arrangement of objects of the same type.
 
 Class
 If the type opcode is set to type_class the type represents class types.
 
 Code
 
 Compound
 
 Frame
 
 Method
 A method type represents a method, function or procedure type.
 
 Pointer
 Pointer types:
 
 Primitive
 Primitive types are types that represent atomic data values that map directly to modes.
 
 Segment
 Segment types represent segments in the object file.
 
 Struct
 A struct type represents aggregate types that consist of a list of fields.
 
 Traversing
 
 Union
 The union type represents union types.
 
 Unknown
 This type is an auxiliary type dedicated to support type analyses.
 

Macros

#define is_SuperClass_of(high, low)   is_SubClass_of(low, high)
 Returns true if high is superclass of low. More...
 
#define is_SuperClass_ptr_of(low, high)   is_SubClass_ptr_of(high, low)
 Superclass check for pointers to classes. More...
 

Typedefs

typedef struct ir_type ir_type
 Type. More...
 

Enumerations

enum  tp_opcode {
  tpo_uninitialized = 0, tpo_struct, tpo_union, tpo_class,
  tpo_segment, tpo_method, tpo_array, tpo_pointer,
  tpo_primitive, tpo_code, tpo_unknown, tpo_last = tpo_unknown
}
 An enum for the type kinds. More...
 
enum  inh_transitive_closure_state { inh_transitive_closure_none, inh_transitive_closure_valid, inh_transitive_closure_invalid, inh_transitive_closure_max }
 The state of the transitive closure. More...
 
enum  ir_type_state { layout_undefined, layout_fixed }
 The state of the type layout. More...
 

Functions

const char * get_type_opcode_name (tp_opcode opcode)
 Returns the name of the type opcode opcode. More...
 
int is_SubClass_of (const ir_type *low, const ir_type *high)
 Returns true if low is subclass of high. More...
 
int is_SubClass_ptr_of (ir_type *low, ir_type *high)
 Subclass check for pointers to classes. More...
 
int is_overwritten_by (ir_entity *high, ir_entity *low)
 Returns true if high is (transitive) overwritten by low. More...
 
ir_entityresolve_ent_polymorphy (ir_type *dynamic_class, ir_entity *static_ent)
 Resolve polymorphism in the inheritance relation. More...
 
void set_irp_inh_transitive_closure_state (inh_transitive_closure_state s)
 Sets the transitive closure of sub/superclass state for the whole program. More...
 
void invalidate_irp_inh_transitive_closure_state (void)
 Sets the transitive closure of sub/superclass state for the whole program to inh_transitive_closure_invalid. More...
 
inh_transitive_closure_state get_irp_inh_transitive_closure_state (void)
 Returns the transitive closure of sub/superclass state for the whole program. More...
 
void compute_inh_transitive_closure (void)
 Compute transitive closure of the subclass/superclass and overwrites/overwrittenby relation. More...
 
void free_inh_transitive_closure (void)
 Free memory occupied by the transitive closure information. More...
 
ir_typeget_class_trans_subtype_first (const ir_type *tp)
 Start iteration over all transitive subtypes of tp. More...
 
ir_typeget_class_trans_subtype_next (const ir_type *tp)
 Returns next type in a subtype iteration started by get_class_trans_subtype_first() More...
 
int is_class_trans_subtype (const ir_type *tp, const ir_type *subtp)
 Check if subtp is a subtype of tp. More...
 
ir_typeget_class_trans_supertype_first (const ir_type *tp)
 Start iteration over all transitive supertypes of tp. More...
 
ir_typeget_class_trans_supertype_next (const ir_type *tp)
 Returns next type in a supertype iteration started by get_class_trans_supertype_first() More...
 
ir_entityget_entity_trans_overwrittenby_first (const ir_entity *ent)
 Start iteration over all entities that transitive overwrite entity ent. More...
 
ir_entityget_entity_trans_overwrittenby_next (const ir_entity *ent)
 Returns next entity in a overwrittenby iteration started by get_entity_trans_overwrittenby_first() More...
 
ir_entityget_entity_trans_overwrites_first (const ir_entity *ent)
 Start iteration over all transitive overwritten entities, overwritten by entity ent. More...
 
ir_entityget_entity_trans_overwrites_next (const ir_entity *ent)
 Returns next entity in a overwrites iteration started by get_entity_trans_overwrites_first() More...
 
int check_type (const ir_type *tp)
 Checks a type. More...
 
int tr_verify (void)
 Walks the type information and performs a set of sanity checks. More...
 
void free_type (ir_type *tp)
 Frees the memory used by the type. More...
 
tp_opcode get_type_opcode (const ir_type *type)
 Returns opcode of type type. More...
 
void ir_print_type (char *buffer, size_t buffer_size, const ir_type *tp)
 construct a string representing the type. More...
 
const char * get_type_state_name (ir_type_state s)
 Returns a human readable string for the enum entry. More...
 
ir_type_state get_type_state (const ir_type *tp)
 Returns the type layout state of a type. More...
 
void set_type_state (ir_type *tp, ir_type_state state)
 Sets the type layout state of a type. More...
 
ir_modeget_type_mode (const ir_type *tp)
 Returns the mode of a type. More...
 
unsigned get_type_size (const ir_type *tp)
 Returns the size of a type in bytes. More...
 
void set_type_size (ir_type *tp, unsigned size)
 Sets the size of a type in bytes. More...
 
unsigned get_type_alignment (const ir_type *tp)
 Returns the alignment of a type in bytes. More...
 
void set_type_alignment (ir_type *tp, unsigned align)
 Sets the alignment of a type in bytes. More...
 
ir_visited_t get_type_visited (const ir_type *tp)
 Returns the visited counter of a type. More...
 
void set_type_visited (ir_type *tp, ir_visited_t num)
 Sets the visited counter of a type to num. More...
 
void mark_type_visited (ir_type *tp)
 Sets visited field in type to type_visited. More...
 
int type_visited (const ir_type *tp)
 Returns non-zero if the type is already visited. More...
 
void * get_type_link (const ir_type *tp)
 Returns the associated link field of a type. More...
 
void set_type_link (ir_type *tp, void *l)
 Sets the associated link field of a type. More...
 
void inc_master_type_visited (void)
 Increments type visited reference counter by one. More...
 
void set_master_type_visited (ir_visited_t val)
 Sets type visited reference counter. More...
 
ir_visited_t get_master_type_visited (void)
 Returns type visited reference counter. More...
 
void set_type_dbg_info (ir_type *tp, type_dbg_info *db)
 Sets the debug information of a type. More...
 
type_dbg_infoget_type_dbg_info (const ir_type *tp)
 Returns the debug information of a type. More...
 
long get_type_nr (const ir_type *tp)
 Outputs a unique number for this type if libfirm is compiled for debugging, (configure with –enable-debug) else returns the address of the type cast to long. More...
 
int is_atomic_type (const ir_type *tp)
 Checks whether a type is atomic. More...
 

Detailed Description

Datastructure to hold type information.

This module supplies a data structure to represent all types known in the compiled program. This includes types specified in the program as well as types defined by the language. In the view of the intermediate representation there is no difference between these types. Finally it specifies some auxiliary types.

There exist several kinds of types, arranged by the structure of the type. A type is described by a set of attributes. Some of these attributes are common to all types, others depend on the kind of the type.

Types are different from the modes defined in irmode: Types are on the level of the programming language, modes at the level of the target processor.

Macro Definition Documentation

#define is_SuperClass_of (   high,
  low 
)    is_SubClass_of(low, high)

Returns true if high is superclass of low.

Low is a subclass of high if low == high or if low is a subclass of a subclass of high. I.e, we search in all subtypes of high for low. @@ this can be implemented more efficient if we know the set of all subclasses of high.

Definition at line 744 of file typerep.h.

#define is_SuperClass_ptr_of (   low,
  high 
)    is_SubClass_ptr_of(high, low)

Superclass check for pointers to classes.

Dereferences at both types the same amount of pointer types (as many as possible). If the remaining types are both class types and superclasses, returns true, else false. Can also be called with two class types.

Definition at line 752 of file typerep.h.

Typedef Documentation

typedef struct ir_type ir_type

Type.

Definition at line 71 of file firm_types.h.

Enumeration Type Documentation

The state of the transitive closure.

Enumerator
inh_transitive_closure_none 

Closure is not computed, can not be accessed.

inh_transitive_closure_valid 

Closure computed and valid.

inh_transitive_closure_invalid 

Closure invalid, but can be accessed.

inh_transitive_closure_max 

Invalid value.

Definition at line 785 of file typerep.h.

The state of the type layout.

Enumerator
layout_undefined 

The layout of this type is not defined.

Address computation to access fields is not possible, fields must be accessed by Sel nodes. This is the default value except for pointer, primitive and method types.

layout_fixed 

The layout is fixed, all component/member entities have an offset assigned.

Size of the type is known. Arrays can be accessed by explicit address computation. Default for pointer, primitive and method types.

Definition at line 890 of file typerep.h.

enum tp_opcode

An enum for the type kinds.

For each type kind exists a typecode to identify it.

Enumerator
tpo_uninitialized 
tpo_struct 

A struct type.

tpo_union 

An union type.

tpo_class 

A class type.

tpo_segment 

A segment type.

tpo_method 

A method type.

tpo_array 

An array type.

tpo_pointer 

A pointer type.

tpo_primitive 

A primitive type.

tpo_code 

a piece of code (a basic block)

tpo_unknown 

Special code for the Unknown type.

tpo_last 

Definition at line 702 of file typerep.h.

Function Documentation

int check_type ( const ir_type tp)

Checks a type.

Returns
non-zero if no errors were found
void compute_inh_transitive_closure ( void  )

Compute transitive closure of the subclass/superclass and overwrites/overwrittenby relation.

This function walks over the ir (O(#types+#entities)) to compute the transitive closure.

void free_inh_transitive_closure ( void  )

Free memory occupied by the transitive closure information.

void free_type ( ir_type tp)

Frees the memory used by the type.

Removes the type from the type list and frees all entities belonging to the type.

ir_type* get_class_trans_subtype_first ( const ir_type tp)

Start iteration over all transitive subtypes of tp.

ir_type* get_class_trans_subtype_next ( const ir_type tp)

Returns next type in a subtype iteration started by get_class_trans_subtype_first()

ir_type* get_class_trans_supertype_first ( const ir_type tp)

Start iteration over all transitive supertypes of tp.

ir_type* get_class_trans_supertype_next ( const ir_type tp)

Returns next type in a supertype iteration started by get_class_trans_supertype_first()

ir_entity* get_entity_trans_overwrites_first ( const ir_entity ent)

Start iteration over all transitive overwritten entities, overwritten by entity ent.

ir_entity* get_entity_trans_overwrites_next ( const ir_entity ent)

Returns next entity in a overwrites iteration started by get_entity_trans_overwrites_first()

ir_entity* get_entity_trans_overwrittenby_first ( const ir_entity ent)

Start iteration over all entities that transitive overwrite entity ent.

ir_entity* get_entity_trans_overwrittenby_next ( const ir_entity ent)

Returns next entity in a overwrittenby iteration started by get_entity_trans_overwrittenby_first()

inh_transitive_closure_state get_irp_inh_transitive_closure_state ( void  )

Returns the transitive closure of sub/superclass state for the whole program.

ir_visited_t get_master_type_visited ( void  )

Returns type visited reference counter.

See also
Visited Counters
unsigned get_type_alignment ( const ir_type tp)

Returns the alignment of a type in bytes.

type_dbg_info* get_type_dbg_info ( const ir_type tp)

Returns the debug information of a type.

Parameters
tpThe type.
void* get_type_link ( const ir_type tp)

Returns the associated link field of a type.

ir_mode* get_type_mode ( const ir_type tp)

Returns the mode of a type.

Returns NULL for all non atomic types.

long get_type_nr ( const ir_type tp)

Outputs a unique number for this type if libfirm is compiled for debugging, (configure with –enable-debug) else returns the address of the type cast to long.

tp_opcode get_type_opcode ( const ir_type type)

Returns opcode of type type.

const char* get_type_opcode_name ( tp_opcode  opcode)

Returns the name of the type opcode opcode.

unsigned get_type_size ( const ir_type tp)

Returns the size of a type in bytes.

ir_type_state get_type_state ( const ir_type tp)

Returns the type layout state of a type.

const char* get_type_state_name ( ir_type_state  s)

Returns a human readable string for the enum entry.

ir_visited_t get_type_visited ( const ir_type tp)

Returns the visited counter of a type.

See also
Visited Counters
void inc_master_type_visited ( void  )

Increments type visited reference counter by one.

See also
Visited Counters, mark_type_visited(), type_visited()
void invalidate_irp_inh_transitive_closure_state ( void  )

Sets the transitive closure of sub/superclass state for the whole program to inh_transitive_closure_invalid.

void ir_print_type ( char *  buffer,
size_t  buffer_size,
const ir_type tp 
)

construct a string representing the type.

This uses the info retrieved by the type_dbg_info if available. Otherwise it tries to create an approximate textual representation of the type. Keep in mind that this representation is not unique for each type, might abstract away some details. The main intention of this is creating human redable strings giving an idea of the type.

int is_atomic_type ( const ir_type tp)

Checks whether a type is atomic.

Parameters
tpany type
Returns
true if type is primitive or pointer
int is_class_trans_subtype ( const ir_type tp,
const ir_type subtp 
)

Check if subtp is a subtype of tp.

This function checks the full transitive closure of the subtype relation and not just direct subtyping.

Returns
1 if it is a subtype, 0 otherwise
int is_overwritten_by ( ir_entity high,
ir_entity low 
)

Returns true if high is (transitive) overwritten by low.

Returns false if high == low.

int is_SubClass_of ( const ir_type low,
const ir_type high 
)

Returns true if low is subclass of high.

Low is a subclass of high if low == high or if low is a subclass of a subclass of high. I.e, we search in all subtypes of high for low. @@ this can be implemented more efficient if we know the set of all subclasses of high.

int is_SubClass_ptr_of ( ir_type low,
ir_type high 
)

Subclass check for pointers to classes.

Dereferences at both types the same amount of pointer types (as many as possible). If the remaining types are both class types and subclasses, returns true, else false. Can also be called with two class types.

void mark_type_visited ( ir_type tp)

Sets visited field in type to type_visited.

See also
Visited Counters
ir_entity* resolve_ent_polymorphy ( ir_type dynamic_class,
ir_entity static_ent 
)

Resolve polymorphism in the inheritance relation.

Returns the dynamically referenced entity if the static entity and the dynamic type are given. Searches downwards in overwritten tree.

void set_irp_inh_transitive_closure_state ( inh_transitive_closure_state  s)

Sets the transitive closure of sub/superclass state for the whole program.

void set_master_type_visited ( ir_visited_t  val)

Sets type visited reference counter.

See also
Visited Counters
void set_type_alignment ( ir_type tp,
unsigned  align 
)

Sets the alignment of a type in bytes.

void set_type_dbg_info ( ir_type tp,
type_dbg_info db 
)

Sets the debug information of a type.

Parameters
tpThe type.
dbThe debug info.
void set_type_link ( ir_type tp,
void *  l 
)

Sets the associated link field of a type.

void set_type_size ( ir_type tp,
unsigned  size 
)

Sets the size of a type in bytes.

For primitive, pointer and method types the size is always fixed. This call is legal but has no effect.

void set_type_state ( ir_type tp,
ir_type_state  state 
)

Sets the type layout state of a type.

For primitives, pointer and method types the layout is always fixed. This call is legal but has no effect.

void set_type_visited ( ir_type tp,
ir_visited_t  num 
)

Sets the visited counter of a type to num.

See also
Visited Counters
int tr_verify ( void  )

Walks the type information and performs a set of sanity checks.

Returns
0 in case of an error
int type_visited ( const ir_type tp)

Returns non-zero if the type is already visited.

See also
Visited Counters