typos fixed
[libfirm] / ir / tr / entity.h
index 39914b5..b6910ee 100644 (file)
@@ -1,8 +1,14 @@
 /*
-*  Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-*  All rights reserved.
-*
-*/
+ * Project:     libFIRM
+ * File name:   ir/tr/entity.h
+ * Purpose:     Representation of all program known entities.
+ * Author:      Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1998-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 /**
 *  @file entity.h
 *                    basic type of the language or a class itself.
 *  - type *owner:    The class this entity belongs to.  In case of local
 *                   variables the method they are defined in.
-*  - int offset:     Offset in byte for this entity.  Fixed when layout
+*  - int offset:     Offset in bits for this entity.  Fixed when layout
 *                   of owner is determined.
 *  - ir_graph *irg:  If (type == method_type) this is the corresponding irg.
-*                   The ir_graph constructor automatically sets this field.
+*                The ir_graph constructor automatically sets this field.
 *                    If (type != method_type) access of this field will cause
 *                    an assertion.
 */
@@ -89,7 +95,7 @@ typedef struct ir_graph ir_graph;
  *   @param variability A flag indicating the variability of this entity (values:
  *              uninitialized, initalized, part_constant, constant)
  *   @param volatility @@@
- *   @param offset     The offset of the entity within the compound object.  Only set
+ *   @param offset     The offset of the entity within the compound object in bits.  Only set
  *              if the owner in the state "layout_fixed".
  *   @param overwrites A list of entities overwritten by this entity.  This list is only
  *              existent if the owner of this entity is a class.  The members in
@@ -169,10 +175,10 @@ entity     *copy_entity_name (entity *old, ident *new_name);
 void        free_entity (entity *ent);
 
 /** Returns the name of an entity. */
-const char *get_entity_name     (entity *ent);
+const char *get_entity_name     (const entity *ent);
 
 /** Returns the ident of an entity. */
-ident      *get_entity_ident    (entity *ent);
+ident      *get_entity_ident    (const entity *ent);
 
 /** Returns the mangled name of the entity.
  *
@@ -186,7 +192,7 @@ ident      *get_entity_ld_ident (entity *ent);
 void        set_entity_ld_ident (entity *ent, ident *ld_ident);
 
 /** Returns the mangled name of the entity as a string. */
-const char *get_entity_ld_name (entity *end);
+const char *get_entity_ld_name (entity *ent);
 
 /** Returns the owner of the entity. */
 type       *get_entity_owner (entity *ent);
@@ -195,8 +201,8 @@ type       *get_entity_owner (entity *ent);
    ent to owner!! */
 void        set_entity_owner (entity *ent, type *owner);
 
-/** Asserts if the type owner is neither a compound type or an array */
-INLINE void assert_legal_owner_of_ent(type *owner);
+/** Asserts if the type owner is either a compound type or an array */
+void assert_legal_owner_of_ent(type *owner);
 
 /** Returns the type of an entity. */
 type     *get_entity_type (entity *ent);
@@ -206,117 +212,200 @@ void      set_entity_type (entity *ent, type *tp);
 
 /** The allocation type. */
 typedef enum {
-  automatic_allocated, /**< The entity is allocated during runtime, implicitly
-                         as component of a compound type.   This is the default. */
-  parameter_allocated, /**< The entity is a parameter.  It is also automatic allocated.
-                         We distinguish the allocation of paramters from the allocation
-                         of local variables as their placement depends on the calling
-                         conventions. */
-  dynamic_allocated,   /**< The entity is allocated during runtime, explicitly
-                         by an Alloc node. */
-  static_allocated     /**< The entity is allocated statically.  We can use a
-                          SymConst(?) as address of the entity. */
+  allocation_automatic, /**< The entity is allocated during runtime, implicitly
+                 as component of a compound type.   This is the default. */
+  allocation_parameter, /**< The entity is a parameter.  It is also automatic allocated.
+                 We distinguish the allocation of parameters from the allocation
+                 of local variables as their placement depends on the calling
+                 conventions. */
+  allocation_dynamic,   /**< The entity is allocated during runtime, explicitly
+                 by an Alloc node. */
+  allocation_static     /**< The entity is allocated statically.  We can use a
+                             Const as address of the entity. */
 } ent_allocation;
 
 /** Returns the allocation type of an entity. */
-ent_allocation get_entity_allocation (entity *ent);
+ent_allocation get_entity_allocation (const entity *ent);
 
 /** Sets the allocation type of an entity. */
 void           set_entity_allocation (entity *ent, ent_allocation al);
 
+/** Return the name of the allocation type. */
+const char *get_allocation_name(ent_allocation vis);
+
 /**
  * This enumeration flags the visibility of entities.  This is necessary
  * for partial compilation.
  */
 typedef enum {
-  local,              /**< The entity is only visible locally.  This is the default. */
-  external_visible,   /**< The entity is visible to other external program parts, but
-                        it is defined here.  It may not be optimized away.  The entity must
-                        be static_allocated. */
-  external_allocated  /**< The entity is defined and allocated externally.  This compilation
-                        must not allocate memory for this entity. The entity must
-                        be static_allocated.  This can also be an external defined
-                        method. */
+  visibility_local,              /**< The entity is only visible locally.  This is the default. */
+  visibility_external_visible,   /**< The entity is visible to other external program parts, but
+                          it is defined here.  It may not be optimized away.  The entity must
+                              be static_allocated. */
+  visibility_external_allocated  /**< The entity is defined and allocated externally.  This compilation
+                          must not allocate memory for this entity. The entity must
+                              be static_allocated.  This can also be an external defined
+                          method. */
 } ent_visibility;
 
 /** Returns the visibility of an entity. */
-ent_visibility get_entity_visibility (entity *ent);
+ent_visibility get_entity_visibility (const entity *ent);
 
 /** Sets the visibility of an entity. */
 void           set_entity_visibility (entity *ent, ent_visibility vis);
 
+/** Return the name of the visibility */
+const char *get_visibility_name(ent_visibility vis);
+
 /** This enumeration flags the variability of entities. */
 typedef enum {
-  uninitialized,    /**< The content of the entity is completely unknown. */
-  initialized,      /**< After allocation the entity is initalized with the
-                      value given somewhere in the entity. */
-  part_constant,    /**< For entities of compound types.  Some members of the entity
-                      are constant.  The others are uninitialized.  Those members
-                      given a value for are constant. */
-  constant          /**< The entity is constant. */
+  variability_uninitialized,    /**< The content of the entity is completely unknown. */
+  variability_initialized,      /**< After allocation the entity is initalized with the
+                             value given somewhere in the entity. */
+  variability_part_constant,    /**< For entities of compound types.
+                                    The members of the entity are mixed constant,
+                                    initialized or uninitialized. */
+  variability_constant          /**< The entity is constant. */
 } ent_variability;
 
 /** Returns the variability of an entity. */
-ent_variability get_entity_variability (entity *ent);
+ent_variability get_entity_variability (const entity *ent);
 
 /** Sets the variability of an entity. */
 void            set_entity_variability (entity *ent, ent_variability var);
 
+/** Return the name of the variablity. */
+const char *get_variability_name(ent_variability var);
+
 /** This enumeration flags the volatility of entities. */
 typedef enum {
-  non_volatile,    /**< The entity is not volatile */
-  is_volatile      /**< The entity is volatile */
+  volatility_non_volatile,    /**< The entity is not volatile */
+  volatility_is_volatile      /**< The entity is volatile */
 } ent_volatility;
 
 /** Returns the volatility of an entity. */
-ent_volatility get_entity_volatility (entity *ent);
+ent_volatility get_entity_volatility (const entity *ent);
 
 /** Sets the volatility of an entity. */
 void           set_entity_volatility (entity *ent, ent_volatility vol);
 
-/** Returns the offset of an entity (in a compound). Only set if layout = fixed. */
-int       get_entity_offset (entity *ent);
+/** Return the name of the volatility. */
+const char *get_volatility_name(ent_volatility var);
+
+/** This enumeration flags the stickyness of an entity. */
+typedef enum {
+  stickyness_unsticky,          /**< The entity can be removed from
+                                   the program, unless contraindicated
+                                   by other attributes */
+  stickyness_sticky             /**< The entity must remain in the
+                                   program in any case */
+} ent_stickyness;
+
+/** Get the entity's stickyness */
+ent_stickyness get_entity_stickyness(const entity *ent);
+
+/** Set the entity's stickyness */
+void      set_entity_stickyness(entity *ent, ent_stickyness stickyness);
+
+/** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */
+int       get_entity_offset_bytes(const entity *ent);
 
-/** Sets the offset of an entity (in a compound). */
-void      set_entity_offset (entity *ent, int offset);
+/** Returns the offset of an entity (in a compound) in bits. Only set if layout = fixed. */
+int       get_entity_offset_bits(const entity *ent);
+
+/** Sets the offset of an entity (in a compound) in bytes. */
+void      set_entity_offset_bytes(entity *ent, int offset);
+
+/** Sets the offset of an entity (in a compound) in bits. */
+void      set_entity_offset_bits(entity *ent, int offset);
 
 /** Returns the stored intermediate information. */
-void*   get_entity_link(entity *ent);
+void*   get_entity_link(const entity *ent);
 
 /** Stores new intermediate information. */
 void    set_entity_link(entity *ent, void *l);
 
 /* -- Fields of method entities -- */
-/* The entity knows the corresponding irg if the entity is a method.
+/** The entity knows the corresponding irg if the entity is a method.
    This allows to get from a Call to the called irg.
    Only entities of peculiarity "existent" can have a corresponding irg,
    else the field is fixed to NULL.  (Get returns NULL, set asserts.) */
-ir_graph *get_entity_irg(entity *ent);
+ir_graph *get_entity_irg(const entity *ent);
 void      set_entity_irg(entity *ent, ir_graph *irg);
 
-/* For the definition of enumeration peculiarity see type.h */
-peculiarity get_entity_peculiarity (entity *ent);
+/** Return the peculiarity of an entity. */
+peculiarity get_entity_peculiarity (const entity *ent);
+
+/** Sets the peculiarity of an entity. */
 void        set_entity_peculiarity (entity *ent, peculiarity pec);
 
+/** Return the name of the peculiarity. */
+const char *get_peculiarity_name(peculiarity var);
+
 /* -- Representation of constant values of entites -- */
+/** Returns true if the the node is representable as code on
+ *  const_code_irg. */
+int      is_irn_const_expression(ir_node *n);
 /* Set current_ir_graph to get_const_code_irg() to generate a constant
    expression. */
-/* Copies a firm subgraph that complies to the restrictions for
-   constant expressions to current_block in current_ir_graph. */
+
+/**
+ * Copies a firm subgraph that complies to the restrictions for
+ * constant expressions to current_block in current_ir_graph.
+ */
 ir_node *copy_const_value(ir_node *n);
 
-/* Set has no effect for entities of type method. */
+/* Set has no effect for existent entities of type method. */
 ir_node *get_atomic_ent_value(entity *ent);
 void     set_atomic_ent_value(entity *ent, ir_node *val);
 
-/* A value of a compound entity is a pair of a value and the corresponding
-   member of the compound. */
-void     add_compound_ent_value(entity *ent, ir_node *val, entity *member);
+/* The following type describes a path to a leave in the compound graph.
+   Node 0 in the path must be an entity of type tp given in the constructor.  If
+   the type of this element is compound, the path node 1 is an element of the type
+   of node 0 an so forth, until an entity of atomic type is reached. */
+#ifndef _COMPOUND_GRAPH_PATH_TYPEDEF_
+#define _COMPOUND_GRAPH_PATH_TYPEDEF_
+typedef struct compound_graph_path compound_graph_path;
+#endif /* _COMPOUND_GRAPH_PATH_TYPEDEF_ */
+compound_graph_path *new_compound_graph_path(type *tp, int length);
+int     is_compound_graph_path(void *thing);
+void    free_compound_graph_path (compound_graph_path *gr);
+int     get_compound_graph_path_length(compound_graph_path *gr);
+entity *get_compound_graph_path_node(compound_graph_path *gr, int pos);
+void    set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node);
+int     get_compound_graph_path_array_index(compound_graph_path *gr, int pos);
+void    set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index);
+
+/* A value of a compound entity is a pair of a value and the description of the
+   corresponding access path to the member of the compound.  */
+void     add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path);
+void     set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos);
+/** Returns the number of constant values needed to initialize the entity.
+ *
+ *  Asserts if the entity has variability_uninitialized.
+ * */
 int      get_compound_ent_n_values(entity *ent);
 ir_node *get_compound_ent_value(entity *ent, int pos);
+compound_graph_path *get_compound_ent_value_path(entity *ent, int pos);
+
+/** Removes all constant entries where the path ends at value_ent. Does not
+   free the memory of the paths.  (The same path might be used for several
+   constant entities. */
+void     remove_compound_ent_value(entity *ent, entity *value_ent);
+
+/* Some languages support only trivial access paths, i.e., the member is a
+   direct, atomic member of the constant entities type. In this case the
+   corresponding entity can be accessed directly.  The following functions
+   allow direct access. */
+
+/** generates a Path with length 1 */
+void     add_compound_ent_value(entity *ent, ir_node *val, entity *member);
+
+/** Returns the last member in the path */
 entity  *get_compound_ent_value_member(entity *ent, int pos);
+
+/** Sets the path at pos 0 */
 void     set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos);
-void     remove_compound_ent_value(entity *ent, entity *value_ent);
 
 /** Inits the entity ent witch must be of a one dimensional
    array type with the values given in the values array.
@@ -326,6 +415,48 @@ void     remove_compound_ent_value(entity *ent, entity *value_ent);
    values have the proper mode for the array. */
 void set_array_entity_values(entity *ent, tarval **values, int num_vals);
 
+/** Return the overall offset of value at position pos in bits.
+ *
+ * This requires that the layout of all concerned types is fixed.
+ *
+ * @param ent Any entity of compound type with at least pos initialization values.
+ * @param pos The position of the value for which the offset is requested.
+ */
+int  get_compound_ent_value_offset_bits(entity *ent, int pos);
+
+/** Return the overall offset of value at position pos in bytes.
+ *
+ * This requires that the layout of all concerned types is fixed.
+ * Asserts if bit offset is not byte aligned.
+ *
+ * @param ent Any entity of compound type with at least pos initialization values.
+ * @param pos The position of the value for which the offset is requested.
+ */
+int  get_compound_ent_value_offset_bytes(entity *ent, int pos);
+
+/** Compute the array indicees in compound graph paths of initialized entities.
+ *
+ * All arrays must have fixed lower and upper bounds.  One array can
+ * have an open upper bound.  If there are several open bounds, we do
+ * nothing.  There must be initializer elements for all array
+ * elements.  Uses the link field in the array element entities.  The
+ * array bounds must be representable as ints.
+ *
+ * @param ent Any entity.
+ */
+void compute_compound_ent_array_indicees(entity *ent);
+
+/** Sort the values of the compound entity by their overall offset.
+ *
+ * This requires that the layout of all concerned types is fixed.
+ * If the entity has no initialization information the method just
+ * returns.  This is needed to dump the entity in a backend.
+ *
+ * @param ent Any entity.
+ */
+void sort_compound_ent_values(entity *ent);
+
+
 /* --- Fields of entities with a class type as owner --- */
 /* Overwrites is a field that specifies that an access to the overwritten
    entity in the supertype must use this entity.  It's a list as with
@@ -358,7 +489,7 @@ void    remove_entity_overwrittenby(entity *ent, entity *overwrites);
  *   @return
  *       true if the thing is an entity, else false
  */
-int is_entity (void *thing);
+int is_entity (const void *thing);
 
 /** Returns true if the type of the entity is a primitive, pointer
    enumeration or method type. */
@@ -377,7 +508,7 @@ bool equal_entity(entity *ent1, entity *ent2);
 
 /** Outputs a unique number for this entity if libfirm is compiled for
    debugging, (configure with --enable-debug) else returns 0. */
-INLINE long get_entity_nr(entity *ent);
+long get_entity_nr(entity *ent);
 
 /** Returns the entitys visited count. */
 unsigned long get_entity_visited(entity *ent);
@@ -394,5 +525,48 @@ bool        entity_visited(entity *ent);
 /** Returns true if this entity was not visited. */
 bool        entity_not_visited(entity *ent);
 
+/** Returns the dynamically referenced entity if the static entity and the
+ *  dynamic type are given. */
+entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent);
+
+/**
+ * @page unknown_entity
+ *
+ *  This entity is an auxiliary entity dedicated to support analyses.
+ *
+ *  The unknown entity represents that there could be an entity, but it is not
+ *  known.  This entity 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 entity unknown. This entity has as owner and as type the unknown type. It is
+ *  allocated when initializing the entity module.
+ *
+ *  The entity can take the role of any entity, also methods.  It returns default
+ *  values in these cases.
+ *
+ *  The following values are set:
+ *    name          = "unknown_entity"
+ *    ld_name       = "unknown_entity"
+ *    owner         = unknown_type
+ *    type          = unknown_type
+ *    visibility    = visibility_external_allocated
+ *    offset        = -1
+ *    variability   = variability_uninitialized
+ *    value         = SymConst(unknown_entity)
+ *    values        = NULL
+ *    val_paths     = NULL
+ *    peculiarity   = peculiarity_existent
+ *    volatility    = volatility_non_volatile
+ *    stickyness    = stickyness_unsticky
+ *    ld_name       = NULL
+ *    overwrites    = NULL
+ *    overwrittenby = NULL
+ *    irg           = NULL
+ *    link          = NULL
+ *
+ */
+/* A variable that contains the only unknown entity. */
+extern entity *unknown_entity;
+/* Returns the unknown entity */
+entity *get_unknown_entity(void);
 
 # endif /* _ENTITY_H_ */