** Authors: Martin Trapp, Christian Schaefer &
** Goetz Lindenmaier
**
-** type.h: datastructures to hold type information.
+
+@@@@@@@ Improve documentation: distinguish fields that are
+set by the frontend and contain knowledge specified by the source
+program from fields containing information derived by analysis/optimization
+or lowering phases.
+
+
+** type.h: datastructures to hold type information.
+**
+** This module supplies datastructures 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.
+** 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.
+**
+**
+** General datastructure
+** =====================
+**
+** Firm distinguishes several different type constructs. These are
+** implemented as structs. A union of the individual structs constructs
+** the firm node "type".
+**
+** All type constructs have the following fields:
+**
+** kind A firm_kind tag containing k_type_class. This is useful
+** for dynamically checking the sort of a type. Automatically
+** generated.
+**
+** name An identifier specifying the type name. Set by the frontend.
+**
+** visit A counter for walks of the type information.
+**
+**
+** General functionality
+** =====================
+**
+** is_type(t) Returns true if t is a type node, else false.
+**
+**
+** type_class
+** ==========
+**
+** Type_class represents class types. A list of fields and
+** methods is associated with a class. Further a class can
+** inherit from and bequest to other classes.
+**
+** fields:
+** -------
+**
+** **member All entities belonging to this class. This are methodes
+** which have type_method or fields that can have any of the
+** following types: k_type_class, k_type_strct, k_type_union,
+** k_type_array, k_type_enumeration, k_type_pointer, k_type_primitive.
+**
+** **subtypes A list of direct subclasses.
+**
+** **supertypes A list of direct superclasses.
+**
+**
+** type_strct
+** ==========
+**
+** Type_strct represents aggregate types that consist of a list
+** of fields.
+**
+** fields:
+** -------
+**
+** **member All entities belonging to this class. This are the fields
+** that can have any of the following types: k_type_class,
+** k_type_strct, k_type_union, k_type_array, k_type_enumeration,
+** k_type_pointer, k_type_primitive.
+**
+** type_method
+** ===========
+**
+** Type_method represents method, function and procedure types.
+**
+** fields:
+** -------
+**
+** arity Number of parameters to the procedure. @@@ better n_params
+** A procedure in FIRM has only call by value parameters.
+**
+** **param_type A list with the types of parameters. This list is ordered.
+** The nth type in this list corresponds to the nth element
+** in the parameter tuple that is a result of the start node.
+** (See ircons.h for more information.)
+**
+** n_res The number of results of the method. In general, procedures
+** have zero results, functions one.
+**
+** **res_type A list with the types of parameters. This list is ordered.
+** The nth type in this list corresponds to the nth input to
+** Return nodes. (See ircons.h for more information.)
+**
+**
+** type_union
+** ==========
+**
+** Type_union represents union types.
+**
+** fields:
+** -------
+**
+** **unioned_type A list of unioned types.
+**
+**
+** type_array
+** ==========
+**
+** Type_array represents rectangular multi dimensional arrays.
+**
+** fields:
+** -------
+**
+** n_dimensions Number of array dimensions.
+**
+** *lower_bound Lower bounds of dimensions. Mostly all 0.
+**
+** *upper_bound Upper bounds or dimensions.
+**
+** *element_type The type of the array elements.
+**
+**
+** type_enumeration
+** ================
+**
+** Enumeration types. These need not necessarily be represented explicitly
+** by Firm types, as the frontend can lower them to integer constants as
+** well. For debugging purposes or similar tasks this information is useful.
+**
+** fields:
+** -------
+**
+** **enum The target values representing the constants used to
+** represent individual enumerations.
+**
+** **enum_name Idents containing the source program name of the enumeration
+** constants
+**
+** type_pointer
+** ============
+**
+** Pointer types.
+**
+** fields:
+** -------
+**
+** *mode The mode used to implement a pointer. @@@ So far this field
+** is constant and set to mode_P. Maybe we will move this
+** to a global constant (irprog), or are there processors
+** that require a set of different pointer modes?
+**
+** *points_to The type of the entity this pointer points to.
+**
+** type_primitive
+** ==============
+**
+** Primitive types are types that represent indivisible data values that
+** map directly to modes.
+**
+** fields:
+** -------
+**
+** mode The mode to be used for this type.
+**
*/
# ifndef _TYPE_H_
# include "common.h"
# include "ident.h"
# include "irmode.h"
+/*CS*/
+//# include "entity.h"
+
+#ifndef _ENTITY_TYPEDEF_
+#define _ENTITY_TYPEDEF_
+/* to resolve recursion between entity.h and type.h */
+typedef struct entity entity;
+#endif
/* for recursive type definiton */
+//#ifndef _TYPE_TYPEDEF_
+//#define _TYPE_TYPEDEF_
+/* to resolve recursion between entity.h and irgraph.h */
typedef union type type;
+//#endif
+
/* visited flag to traverse the type information */
extern unsigned long type_visited;
/** TYPE_CLASS **/
/*******************************************************************/
-typedef struct {
+typedef struct type_class type_class;
+
+struct type_class {
firm_kind kind;
- ident *name;
- /** needs list with it's entities -- does it really??
- Entities can be added during their creation.
- int n_members;
- entity **member; **/
- unsigned long visit; /* visited counter for walks of the type information */
-} type_class;
+ ident *name; /* needs list with it's entities
+ does it really??
+ Entities can be added during their creation. */
+ struct entity **members; /* to represent inheritance */
+ type_class **subtypes; /* direct subtypes */
+ type_class **supertypes; /* direct supertypes */
+ unsigned long visit; /* visited counter for walks of
+ the type information */
+};
/* create a new type_class */
type_class *new_type_class (ident *name);
/* manipulate fields of type_class */
-char *get_class_name (type_class *clss);
-ident *get_class_ident (type_class *clss);
-/*
+
+const char *get_class_name (type_class *class);
+ident *get_class_ident (type_class *class);
+
+/* Not necessary now!
void set_class_name (type_class *class, char *name);
void set_class_ident (type_class *class, ident* ident);
*/
+void add_class_member (type_class *class, entity *member);
+entity *get_class_member (type_class *class, int pos);
+void set_class_member (type_class *class, entity *member, int pos);
+
+void add_class_subtype (type_class *class, type_class *subtype);
+type_class *get_class_subtype (type_class *class, int pos);
+void set_class_subtype (type_class *class, type_class *subtype, int pos);
+
+void add_class_supertype (type_class *class, type_class *supertype);
+type_class *get_class_supertype (type_class *class, int pos);
+void set_class_supertype (type_class *class, type_class *supertype, int pos);
+
+
+/* get_class_entity_arr
+ get_class_n_entities
+ get_class_entity(class, pos)
+ set_class_entity(class, pos, entity)
+ get_class_sub_arr
+ ...
+ get_class_super_arr
+*/
+
/*******************************************************************/
/** TYPE_STRCT **/
/*******************************************************************/
typedef struct {
firm_kind kind;
- ident *name; // do I need the name, or is the name in entity sufficient?
- int arity; /* number of parameters, better n_params */
- type **param_type; /* code generation needs this information.
- Should it be generated by the frontend,
- or does this impose unnecessary work for
- optimizatinos that change the parameters of
- methods? */
- int n_res; /* number of results */
- type **res_type;
- /** needs pointer to it's ir_graph ??
- ir_graph *graph; **/
- unsigned long visit; /* visited counter for walks of the type information */
+ ident *name; /* Name of the method type. Usually method
+ types are not explicitly named (but the entity). */
+ int arity; /* number of parameters, better n_params */
+ type **param_type; /* code generation needs this information.
+ Should it be generated by the frontend,
+ or does this impose unnecessary work for
+ optimizations that change the parameters of
+ methods? */
+ int n_res; /* number of results */
+ type **res_type; /* array with result types */
+ unsigned long visit; /* visited counter for walks of the type information */
} type_method;
/* create a new type_method */
type_method *new_type_method (ident *name, int arity, int n_res);
/* manipulate fields of type_method */
-
char *get_method_name (type_method *method);
ident *get_method_ident (type_method *method);
-/* GL 9.2.2000: who commened these in?
- I think it's not safe to have these methods.
- Please add changes to Changes file.
+/*
void set_method_name (type_method *method, char *name);
void set_method_ident (type_method *method, ident* ident); */
inline type *get_method_res_type(type_method *method, int pos);
inline void set_method_res_type(type_method *method, int pos, type* type);
-/*
-ir_graph *get_method_graph(type_method *method);
-void *get_method_graph(type_method *method, ir_graph* graph);
-*/
/*******************************************************************/
/** TYPE_UNION **/
typedef struct {
firm_kind kind;
- ident *name; // do I need a name?
+ ident *name; /* do I need a name? */
int n_types;
/* type **unioned_type; ... or something like that? */
unsigned long visit; /* visited counter for walks of the type information */
typedef struct {
firm_kind kind;
ident *name;
- int n_dimensions; /* Extend Sel to select from multidimensional arrays. This */
- int *lower_bound; /* will allow to generate explicit array index computations */
- int *upper_bound; /* by replacing a single FIRM node. As long as this is not
- done create arrays with arrays as elements. */
- /* Should I use tarval? */
+ int n_dimensions;
+ int *lower_bound;
+ int *upper_bound;
type *element_type;
unsigned long visit; /* visited counter for walks of the type information */
} type_array;
typedef struct {
firm_kind kind;
ident *name;
- /* int n_enums;
- ir_node **enum * Contains all constant nodes that represent a member
- of the enum -- enumerators. */
- // is ir_node the propper array member?
+ /*
+ tarval **enum * Contains all constant nodes that represent a member
+ of the enum -- enumerators. */
+ /*
+ ident **enum_name * Contains the names of the enum fields as specified by
+ the source program */
+ /* is ir_node the propper array member? */
unsigned long visit; /* visited counter for walks of the type information */
} type_enumeration;
typedef struct {
firm_kind kind;
ident *name;
- ir_mode *mode; /* The mode to be used for this type */
+ ir_mode *mode; /* The mode to be used for this type */
unsigned long visit; /* visited counter for walks of the type information */
} type_primitive;
type_primitive primitive;
};
+
int is_type(void *thing);