Commit 21cd22b1 authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

added types none and unknown for analyses

[r1755]
parent e1b25da9
* 22.8.2003 Goetz
Firm const nodes should have a type.
In jack all nodes are typed now, except the Const nodes. Only const from
tarval is typed.
* 14.8.2003 Goetz * 14.8.2003 Goetz
Diverse dynamische arrays haben ein erstes, unverwendetes element. Z.B. Diverse dynamische arrays haben ein erstes, unverwendetes element. Z.B.
class members. Entfernen um Speicher zu sparen. class members. Entfernen um Speicher zu sparen.
......
This diff is collapsed.
...@@ -19,15 +19,17 @@ ...@@ -19,15 +19,17 @@
# include "tpop_t.h" # include "tpop_t.h"
# include "type_t.h" # include "type_t.h"
tp_op *type_class; tp_op *get_type_class () { return type_class; } tp_op *type_class; tp_op *get_tpop_class (void) { return type_class; }
tp_op *type_struct; tp_op *get_type_struct () { return type_struct; } tp_op *type_struct; tp_op *get_tpop_struct (void) { return type_struct; }
tp_op *type_method; tp_op *get_type_method () { return type_method; } tp_op *type_method; tp_op *get_tpop_method (void) { return type_method; }
tp_op *type_union; tp_op *get_type_union () { return type_union; } tp_op *type_union; tp_op *get_tpop_union (void) { return type_union; }
tp_op *type_array; tp_op *get_type_array () { return type_array; } tp_op *type_array; tp_op *get_tpop_array (void) { return type_array; }
tp_op *type_enumeration; tp_op *get_type_enumeration() { return type_enumeration; } tp_op *type_enumeration; tp_op *get_tpop_enumeration(void) { return type_enumeration; }
tp_op *type_pointer; tp_op *get_type_pointer () { return type_pointer; } tp_op *type_pointer; tp_op *get_tpop_pointer (void) { return type_pointer; }
tp_op *type_primitive; tp_op *get_type_primitive () { return type_primitive; } tp_op *type_primitive; tp_op *get_tpop_primitive (void) { return type_primitive; }
tp_op *type_id; tp_op *get_type_id () { return type_id; } tp_op *type_id; tp_op *get_tpop_id (void) { return type_id; }
tp_op *tpop_none; tp_op *get_tpop_none (void) { return tpop_none; }
tp_op *tpop_unknown; tp_op *get_tpop_unknown (void) { return tpop_unknown; }
tp_op * tp_op *
new_tpop (tp_opcode code, ident *name, size_t attr_size) new_tpop (tp_opcode code, ident *name, size_t attr_size)
...@@ -44,15 +46,17 @@ new_tpop (tp_opcode code, ident *name, size_t attr_size) ...@@ -44,15 +46,17 @@ new_tpop (tp_opcode code, ident *name, size_t attr_size)
void void
init_tpop(void) init_tpop(void)
{ {
type_class = new_tpop (tpo_class , id_from_str("class" , 5), sizeof (cls_attr)); type_class = new_tpop (tpo_class , id_from_str("class" , 5), sizeof (cls_attr));
type_struct = new_tpop (tpo_struct , id_from_str("struct" , 6), sizeof (stc_attr)); type_struct = new_tpop (tpo_struct , id_from_str("struct" , 6), sizeof (stc_attr));
type_method = new_tpop (tpo_method , id_from_str("method" , 6), sizeof (mtd_attr)); type_method = new_tpop (tpo_method , id_from_str("method" , 6), sizeof (mtd_attr));
type_union = new_tpop (tpo_union , id_from_str("union" , 5), sizeof (uni_attr)); type_union = new_tpop (tpo_union , id_from_str("union" , 5), sizeof (uni_attr));
type_array = new_tpop (tpo_array , id_from_str("array" , 5), sizeof (arr_attr)); type_array = new_tpop (tpo_array , id_from_str("array" , 5), sizeof (arr_attr));
type_enumeration = new_tpop (tpo_enumeration, id_from_str("enumeration",11), sizeof (enm_attr)); type_enumeration = new_tpop (tpo_enumeration, id_from_str("enumeration" ,11), sizeof (enm_attr));
type_pointer = new_tpop (tpo_pointer , id_from_str("pointer" , 7), sizeof (ptr_attr)); type_pointer = new_tpop (tpo_pointer , id_from_str("pointer" , 7), sizeof (ptr_attr));
type_primitive = new_tpop (tpo_primitive , id_from_str("primitive" , 9), /* sizeof (pri_attr) */ 0); type_primitive = new_tpop (tpo_primitive , id_from_str("primitive" , 9), /* sizeof (pri_attr) */ 0);
type_id = new_tpop (tpo_id , id_from_str("type_id" , 7), /* sizeof (id_attr) */ 0); type_id = new_tpop (tpo_id , id_from_str("type_id" , 7), /* sizeof (id_attr) */ 0);
tpop_none = new_tpop (tpo_none , id_from_str("type_none" , 9), /* sizeof (non_attr) */ 0);
tpop_unknown = new_tpop (tpo_unknown , id_from_str("type_unknown",12), /* sizeof (ukn_attr) */ 0);
} }
/* Returns the string for the tp_opcode. */ /* Returns the string for the tp_opcode. */
......
/* /**
*
* @file tpop.h
*
* Project: libFIRM * Project: libFIRM
* File name: ir/tr/tpop.h * File name: ir/tr/tpop.h
* Purpose: Opcode of types. * Purpose: Opcode of types.
* Author: Goetz Lindenmaier * Author: Goetz Lindenmaier
* Modified by: * Modified by:
* Created: * Created:
* CVS-ID: $Id$
* Copyright: (c) 2001-2003 Universität Karlsruhe * Copyright: (c) 2001-2003 Universität Karlsruhe
* Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/ * CVS-ID: $Id$
# ifndef _TYPEOP_H_
# define _TYPEOP_H_
#include "ident.h"
/**
* @file tpop.h
* *
* This module specifies the kinds of types available in firm. * This module specifies the kinds of types available in firm.
* *
* @author Goetz Lindenmaier
*
* They are called type opcodes. These include classes, structs, methods, unions, * They are called type opcodes. These include classes, structs, methods, unions,
* arrays, enumerations, pointers and primitive types. * arrays, enumerations, pointers and primitive types.
* Special types with own opcodes are the id type, a type representing an unknown
* type and a type used to specify that something has no type.
*
* @see type.h
*/ */
# ifndef _TYPEOP_H_
# define _TYPEOP_H_
#include "ident.h"
/** /**
* an enum for the type kinds. * An enum for the type kinds.
* For each type kind exists a typecode to identify it. * For each type kind exists a typecode to identify it.
*/ */
typedef enum { typedef enum {
tpo_uninitialized = 0, /* not a type opcode */
tpo_class, tpo_class,
tpo_struct, tpo_struct,
tpo_method, tpo_method,
...@@ -39,7 +41,10 @@ typedef enum { ...@@ -39,7 +41,10 @@ typedef enum {
tpo_enumeration, tpo_enumeration,
tpo_pointer, tpo_pointer,
tpo_primitive, tpo_primitive,
tpo_id tpo_id,
tpo_none,
tpo_unknown,
tpo_max /* not a type opcode */
} tp_opcode; } tp_opcode;
/** /**
...@@ -87,7 +92,7 @@ ident *get_tpop_ident (tp_op *op); ...@@ -87,7 +92,7 @@ ident *get_tpop_ident (tp_op *op);
* of the library. * of the library.
*/ */
extern tp_op *type_class; extern tp_op *type_class;
tp_op *get_type_class(void); tp_op *get_tpop_class(void);
/** /**
* This type opcode marks that the corresponding type is a compound type * This type opcode marks that the corresponding type is a compound type
...@@ -99,7 +104,7 @@ tp_op *get_type_class(void); ...@@ -99,7 +104,7 @@ tp_op *get_type_class(void);
* of the library. * of the library.
*/ */
extern tp_op *type_struct; extern tp_op *type_struct;
tp_op *get_type_struct(void); tp_op *get_tpop_struct(void);
/** /**
* This type opcode marks that the corresponding type is a method type. * This type opcode marks that the corresponding type is a method type.
...@@ -109,7 +114,7 @@ tp_op *get_type_struct(void); ...@@ -109,7 +114,7 @@ tp_op *get_type_struct(void);
* of the library. * of the library.
*/ */
extern tp_op *type_method; extern tp_op *type_method;
tp_op *get_type_method(void); tp_op *get_tpop_method(void);
/** /**
* This type opcode marks that the corresponding type is a union type. * This type opcode marks that the corresponding type is a union type.
...@@ -119,7 +124,7 @@ tp_op *get_type_method(void); ...@@ -119,7 +124,7 @@ tp_op *get_type_method(void);
* of the library. * of the library.
*/ */
extern tp_op *type_union; extern tp_op *type_union;
tp_op *get_type_union(void); tp_op *get_tpop_union(void);
/** /**
* This type opcode marks that the corresponding type is an array type. * This type opcode marks that the corresponding type is an array type.
...@@ -130,7 +135,7 @@ tp_op *get_type_union(void); ...@@ -130,7 +135,7 @@ tp_op *get_type_union(void);
* of the library. * of the library.
*/ */
extern tp_op *type_array; extern tp_op *type_array;
tp_op *get_type_array(void); tp_op *get_tpop_array(void);
/** /**
* This type opcode marks that the corresponding type is an enumeration type. * This type opcode marks that the corresponding type is an enumeration type.
...@@ -142,7 +147,7 @@ tp_op *get_type_array(void); ...@@ -142,7 +147,7 @@ tp_op *get_type_array(void);
* of the library. * of the library.
*/ */
extern tp_op *type_enumeration; extern tp_op *type_enumeration;
tp_op *get_type_enumeration(void); tp_op *get_tpop_enumeration(void);
/** /**
* This type opcode marks that the corresponding type is a pointer type. * This type opcode marks that the corresponding type is a pointer type.
...@@ -152,7 +157,7 @@ tp_op *get_type_enumeration(void); ...@@ -152,7 +157,7 @@ tp_op *get_type_enumeration(void);
* of the library. * of the library.
*/ */
extern tp_op *type_pointer; extern tp_op *type_pointer;
tp_op *get_type_pointer(void); tp_op *get_tpop_pointer(void);
/** /**
* This type opcode marks that the corresponding type is a primitive type. * This type opcode marks that the corresponding type is a primitive type.
...@@ -163,7 +168,7 @@ tp_op *get_type_pointer(void); ...@@ -163,7 +168,7 @@ tp_op *get_type_pointer(void);
* of the library. * of the library.
*/ */
extern tp_op *type_primitive; extern tp_op *type_primitive;
tp_op *get_type_primitive(void); tp_op *get_tpop_primitive(void);
/** /**
* This type opcode is an auxiliary opcode dedicated to support transformations * This type opcode is an auxiliary opcode dedicated to support transformations
...@@ -171,7 +176,7 @@ tp_op *get_type_primitive(void); ...@@ -171,7 +176,7 @@ tp_op *get_type_primitive(void);
* *
* If a type is changed to another type with another * If a type is changed to another type with another
* opcode the new type will be allocated with new memory. All nodes refering * opcode the new type will be allocated with new memory. All nodes refering
* to the old type need to be changed to refer the new one. This is simplified * to the old type need to be changed to refer to the new one. This is simplified
* by turning the old type into an id type that merely forwards to the new type * by turning the old type into an id type that merely forwards to the new type
* that now replaces the old one. * that now replaces the old one.
* type_ids should never be visible out of the type module. All access routines * type_ids should never be visible out of the type module. All access routines
...@@ -183,6 +188,28 @@ tp_op *get_type_primitive(void); ...@@ -183,6 +188,28 @@ tp_op *get_type_primitive(void);
* of the library. * of the library.
*/ */
extern tp_op *type_id; extern tp_op *type_id;
tp_op *get_type_id(void); tp_op *get_tpop_id(void);
/**
* This type opcode is an auxiliary opcode dedicated to support type analyses.
*
* Types with this opcode represents that there is no type.
* The type can be used to initialize fields of the type* that actually can not
* contain a type or that are initialized for an analysis. There exists exactly
* one type with this opcode.
*/
extern tp_op *tpop_none;
tp_op *get_tpop_none(void);
/**
* This type opcode is an auxiliary opcode dedicated to support type analyses.
*
* Types with this opcode represents that there could be a type, but it is not
* known. This type can be used to initialize fields before an analysis (not known
* yet) or to represent the top of a lattice (could not be determined). There exists
* exactly one type with this opcode.
*/
extern tp_op *tpop_unknown;
tp_op *get_tpop_unknown(void);
# endif /*_TYPEOP_H_ */ # endif /*_TYPEOP_H_ */
...@@ -46,7 +46,7 @@ struct tp_op { ...@@ -46,7 +46,7 @@ struct tp_op {
* @return A new type opcode. * @return A new type opcode.
* *
*/ */
tp_op * new_tpop (tp_opcode code, ident *name, size_t attr_size); tp_op *new_tpop (tp_opcode code, ident *name, size_t attr_size);
/** /**
* Initialize the tpop module. * Initialize the tpop module.
......
...@@ -57,6 +57,10 @@ ...@@ -57,6 +57,10 @@
/** TYPE **/ /** TYPE **/
/*******************************************************************/ /*******************************************************************/
type *none_type; type *get_none_type(void) { return none_type; }
type *unknown_type; type *get_unknown_type(void) { return unknown_type; }
#ifdef DEBUG_libfirm #ifdef DEBUG_libfirm
/** Returns a new, unique number to number nodes or the like. */ /** Returns a new, unique number to number nodes or the like. */
int get_irp_new_node_nr(void); int get_irp_new_node_nr(void);
...@@ -67,8 +71,18 @@ static ident *value_params_suffix = NULL; ...@@ -67,8 +71,18 @@ static ident *value_params_suffix = NULL;
static ident *value_ress_suffix = NULL; static ident *value_ress_suffix = NULL;
void init_type(void) { void init_type(void) {
value_params_suffix = id_from_str(VALUE_PARAMS_SUFFIX, strlen(VALUE_PARAMS_SUFFIX)); value_params_suffix = new_id_from_str(VALUE_PARAMS_SUFFIX);
value_ress_suffix = id_from_str(VALUE_RESS_SUFFIX, strlen(VALUE_RESS_SUFFIX)); value_ress_suffix = new_id_from_str(VALUE_RESS_SUFFIX);
/* construct none and unknown type. */
none_type = new_type(tpop_none, mode_BAD, new_id_from_str("type_none"));
set_type_size (none_type, 0);
set_type_state (none_type, layout_fixed);
remove_irp_type(none_type);
unknown_type = new_type(tpop_unknown, mode_ANY, new_id_from_str("type_unknown"));
set_type_size (unknown_type, 0);
set_type_state (unknown_type, layout_fixed);
remove_irp_type(unknown_type);
} }
unsigned long type_visited; unsigned long type_visited;
...@@ -77,6 +91,8 @@ INLINE unsigned long get_master_type_visited() { return type_visited; } ...@@ -77,6 +91,8 @@ INLINE unsigned long get_master_type_visited() { return type_visited; }
INLINE void inc_master_type_visited() { type_visited++; } INLINE void inc_master_type_visited() { type_visited++; }
void free_type(type *tp) { void free_type(type *tp) {
if ((get_type_tpop(tp) == tpop_none) || (get_type_tpop(tp) == tpop_unknown))
return;
/* Remove from list of all types */ /* Remove from list of all types */
remove_irp_type(tp); remove_irp_type(tp);
/* Free the attributes of the type. */ /* Free the attributes of the type. */
...@@ -170,12 +186,16 @@ ir_mode* get_type_mode(type *tp) { ...@@ -170,12 +186,16 @@ ir_mode* get_type_mode(type *tp) {
void set_type_mode(type *tp, ir_mode* m) { void set_type_mode(type *tp, ir_mode* m) {
assert(tp && tp->kind == k_type); assert(tp && tp->kind == k_type);
assert(((tp->type_op != type_primitive) || mode_is_data(m)) && assert(((tp->type_op != type_primitive) || mode_is_data(m)) &&
/* Modes of primitives must be data */ /* Modes of primitives must be data */
((tp->type_op != type_enumeration) || mode_is_int(m))); ((tp->type_op != type_enumeration) || mode_is_int(m)) &&
/* Modes of enumerations must be integers */ /* Modes of enumerations must be integers */
((tp->type_op != type_pointer) || mode_is_reference(m)) );
/* Modes of pointers must be references. */
if ((tp->type_op == type_primitive) || (tp->type_op == type_enumeration)) { if ((tp->type_op == type_primitive) ||
(tp->type_op == type_enumeration) ||
(tp->type_op == type_pointer) ) {
/* For pointer, primitive and enumeration size depends on the mode. */ /* For pointer, primitive and enumeration size depends on the mode. */
assert((get_mode_size_bytes(m) != -1) && "unorthodox modes not implemented"); assert((get_mode_size_bytes(m) != -1) && "unorthodox modes not implemented");
tp->size = get_mode_size_bytes(m); tp->size = get_mode_size_bytes(m);
...@@ -200,7 +220,7 @@ get_type_nr(type *tp) { ...@@ -200,7 +220,7 @@ get_type_nr(type *tp) {
#ifdef DEBUG_libfirm #ifdef DEBUG_libfirm
return tp->nr; return tp->nr;
#else #else
return 0; return (long)tp;
#endif #endif
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* known in the compiled program. This includes types specified * known in the compiled program. This includes types specified
* in the program as well as types defined by the language. In the * in the program as well as types defined by the language. In the
* view of the intermediate representation there is no difference * view of the intermediate representation there is no difference
* between these types. * between these types. Finally it specifies some auxiliary types.
* *
* There exist several kinds of types, arranged by the structure of * There exist several kinds of types, arranged by the structure of
* the type. A type is described by a set of attributes. Some of * the type. A type is described by a set of attributes. Some of
...@@ -120,7 +120,8 @@ typedef struct type type; ...@@ -120,7 +120,8 @@ typedef struct type type;
# include "type_or_entity.h" # include "type_or_entity.h"
/** Frees the memory used by the type. Does not free the entities /** Frees the memory used by the type. Does not free the entities
belonging to the type, except for the array element entity. */ belonging to the type, except for the array element entity.
Does not free if tp is "none" or "unknown". */
void free_type(type *tp); void free_type(type *tp);
tp_op* get_type_tpop(type *tp); tp_op* get_type_tpop(type *tp);
...@@ -142,7 +143,7 @@ typedef enum { ...@@ -142,7 +143,7 @@ typedef enum {
layout_fixed /**< The layout is fixed, all component/member entities layout_fixed /**< The layout is fixed, all component/member entities
have an offset assigned. Size of the type is known. have an offset assigned. Size of the type is known.
Arrays can be accessed by explicit address Arrays can be accessed by explicit address
computation. Default for pointer, primitive ane method computation. Default for pointer, primitive and method
types. */ types. */
} type_state; } type_state;
...@@ -164,7 +165,7 @@ ir_mode* get_type_mode(type *tp); ...@@ -164,7 +165,7 @@ ir_mode* get_type_mode(type *tp);
/** Sets the mode of a type. /** Sets the mode of a type.
* *
* Only has an effect on primitive and enumeration types. * Only has an effect on primitive, enumeration and pointer types.
*/ */
void set_type_mode(type *tp, ir_mode* m); void set_type_mode(type *tp, ir_mode* m);
...@@ -761,6 +762,51 @@ type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db); ...@@ -761,6 +762,51 @@ type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db);
bool is_primitive_type (type *primitive); bool is_primitive_type (type *primitive);
/**
* @page none_type
*
* This type is an auxiliary type dedicated to support type analyses.
*
* The none type represents that there is no type. The type can be used to
* initialize fields of type* that actually can not contain a type or that
* are initialized for an analysis. There exists exactly one type none.
* This type is not on the type list in ir_prog. It is
* allocated when initializing the type module.
*
* The following values are set:
* mode: mode_BAD
* name: "type_none"
* state: layout_fixed
* size: 0
*/
/* A variable that contains the only none type. */
extern type *none_type;
/* Returns the none type */
type *get_none_type(void);
/**
* @page unknown_type
*
* This type is an auxiliary type dedicated to support type analyses.
*
* The unknown type represents that there could be a type, but it is not
* known. This type can be used to initialize fields before an analysis (not known
* yet) or to represent the top of a lattice (could not be determined). There exists
* exactly one type unknown. This type is not on the type list in ir_prog. It is
* allocated when initializing the type module.
*
* The following values are set:
* mode: mode_ANY
* name: "type_unknown"
* state: layout_fixed
* size: 0
*/
/* A variable that contains the only unknown type. */
extern type *unknown_type;
/* Returns the none type */
type *get_unknown_type(void);
/** /**
* Checks whether a type is atomic. * Checks whether a type is atomic.
* @param tp - any type * @param tp - any type
...@@ -805,8 +851,11 @@ entity *get_compound_member(type *tp, int pos); ...@@ -805,8 +851,11 @@ entity *get_compound_member(type *tp, int pos);
int is_compound_type(type *tp); int is_compound_type(type *tp);
/** Outputs a unique number for this type if libfirm is compiled for /**
debugging, (configure with --enable-debug) else returns 0. */ * 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.
*/
INLINE long get_type_nr(type *tp); INLINE long get_type_nr(type *tp);
# endif /* _TYPE_H_ */ # endif /* _TYPE_H_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment