Commit 9ab80199 authored by Matthias Braun's avatar Matthias Braun
Browse files

move compound_graph path stuff into own files and add deprecation comments

[r26860]
parent 898744ef
/*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in the
* packaging of this file.
*
* Licensees holding valid libFirm Professional Edition licenses may use
* this file in accordance with the libFirm Commercial License.
* Agreement provided with the Software.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/**
* @file
* @brief Deprecated way to initialize compound entites! (use ir_initializer
* stuff instead)
* Declarations for functions and datastructures to represent compound
* type initializers.
*/
#ifndef FIRM_COMPOUND_PATHS_H
#define FIRM_COMPOUND_PATHS_H
#include "firm_types.h"
typedef struct compound_graph_path compound_graph_path, *ir_compound_graph_path_ptr;
/**
* @deprecated
* Creates a new compound graph path of given length.
*/
compound_graph_path *new_compound_graph_path(ir_type *tp, int length);
/**
* @deprecated
* Returns non-zero if an object is a compound graph path
*/
int is_compound_graph_path(const void *thing);
/**
* @deprecated
* Frees a graph path object
*/
void free_compound_graph_path(compound_graph_path *gr);
/**
* @deprecated
* Returns the length of a graph path
*/
int get_compound_graph_path_length(const compound_graph_path *gr);
/**
* @deprecated
* Get the entity node of an compound graph path at position pos.
*/
ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, int pos);
/**
* @deprecated
* Set the entity node of an compound graph path at position pos.
*/
void set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node);
/**
* @deprecated
* Get the index of an compound graph path at position pos.
*/
int get_compound_graph_path_array_index(const compound_graph_path *gr, int pos);
/**
* @deprecated
* Set the index of an compound graph path at position pos.
*/
void set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index);
/**
* @deprecated
* Get the type of an compound graph path.
*/
ir_type *get_compound_graph_path_type(const compound_graph_path *gr);
/**
* @deprecated
* Checks whether the path up to pos is correct. If the path contains a NULL,
* assumes the path is not complete and returns non-zero.
*/
int is_proper_compound_graph_path(compound_graph_path *gr, int pos);
/**
* @deprecated
* 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(ir_entity *ent, ir_node *val, compound_graph_path *path);
void set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos);
/**
* @deprecated
* Returns the access path for value at position pos.
*/
compound_graph_path *get_compound_ent_value_path(ir_entity *ent, int pos);
/**
* @deprecated
* Returns a constant value given the access path.
* The path must contain array indices for all array element entities.
*/
ir_node *get_compound_ent_value_by_path(ir_entity *ent,
compound_graph_path *path);
/**
* @deprecated
* 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(ir_entity *ent, ir_entity *value_ent);
/**
* @deprecated
* Generates a Path with length 1.
* Beware: Has a bad runtime for array elements (O(|array|) and should be
* avoided there. Use add_compound_ent_value_w_path() instead and create
* the path manually.
*/
void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member);
/**
* @deprecated
* Returns the last member in the path
*/
ir_entity *get_compound_ent_value_member(ir_entity *ent, int pos);
/**
* @deprecated
* Sets the path at pos 0
*/
void set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member,
int pos);
/**
* @deprecated
* Initializes the entity ent which must be of a one dimensional
* array type with the values given in the values array.
* The array must have a lower and an upper bound. Keeps the
* order of values. Does not test whether the number of values
* fits into the given array size. Does not test whether the
* values have the proper mode for the array.
*/
void set_array_entity_values(ir_entity *ent, tarval **values, int num_vals);
/**
* @deprecated
* Return the offset in bits from the last byte address.
*
* 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.
*/
unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos);
/**
* @deprecated
* 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.
*/
unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos);
/**
* @deprecated
* Returns the number of constant values needed to initialize the entity.
* Asserts if the entity has variability_uninitialized.
*/
int get_compound_ent_n_values(ir_entity *ent);
/**
* @deprecated
* Returns a constant value given the position.
*/
ir_node *get_compound_ent_value(ir_entity *ent, int pos);
#endif
......@@ -45,7 +45,6 @@ typedef struct ir_loop ir_loop, *ir_loop_ptr;
typedef struct ir_region ir_region, *ir_region_ptr;
typedef struct ir_reg_tree ir_reg_tree, *ir_reg_tree_ptr;
typedef struct ir_entity ir_entity, *ir_entity_ptr;
typedef struct compound_graph_path compound_graph_path, *ir_compound_graph_path_ptr;
typedef struct _ir_phase ir_phase, *ir_phase_ptr;
typedef struct _ir_extblk ir_extblk, *ir_extblk_ptr;
typedef struct ir_exec_freq ir_exec_freq, *ir_exec_freq_ptr;
......
......@@ -51,8 +51,6 @@
*
* The common fields are:
*
* - firm_kind - A firm_kind tag containing k_type. This is useful
* for dynamically checking whether a node is a ir_node.
* - arity - The number of predecessors in the Firm graph.
* - in - A list with the predecessors in the Firm graph. There are
* routines to access individual elements and to obtain the
......
......@@ -19,7 +19,7 @@
/**
* @file
* Declarations for functions and datastructures to represent types
* @brief Declarations for functions and datastructures to represent types
*/
#ifndef FIRM_TYPEREP_H
#define FIRM_TYPEREP_H
......@@ -497,73 +497,6 @@ void set_initializer_compound_value(ir_initializer_t *initializer,
ir_initializer_t *get_initializer_compound_value(
const ir_initializer_t *initializer, unsigned index);
/** Creates a new compound graph path of given length. */
compound_graph_path *new_compound_graph_path(ir_type *tp, int length);
/** Returns non-zero if an object is a compound graph path */
int is_compound_graph_path(const void *thing);
/** Frees a graph path object */
void free_compound_graph_path(compound_graph_path *gr);
/** Returns the length of a graph path */
int get_compound_graph_path_length(const compound_graph_path *gr);
/** Get the entity node of an compound graph path at position pos. */
ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, int pos);
/** Set the entity node of an compound graph path at position pos. */
void set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node);
/** Get the index of an compound graph path at position pos. */
int get_compound_graph_path_array_index(const compound_graph_path *gr, int pos);
/** Set the index of an compound graph path at position pos. */
void set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index);
/** Get the type of an compound graph path. */
ir_type *get_compound_graph_path_type(const compound_graph_path *gr);
/** Checks whether the path up to pos is correct. If the path contains a NULL,
* assumes the path is not complete and returns non-zero. */
int is_proper_compound_graph_path(compound_graph_path *gr, int pos);
/* 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(ir_entity *ent, ir_node *val, compound_graph_path *path);
void set_compound_ent_value_w_path(ir_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(ir_entity *ent);
/** Returns a constant value given the position. */
ir_node *get_compound_ent_value(ir_entity *ent, int pos);
/** Returns the access path for value at position pos. */
compound_graph_path *get_compound_ent_value_path(ir_entity *ent, int pos);
/** Returns a constant value given the access path.
* The path must contain array indices for all array element entities. */
ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path);
/** 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(ir_entity *ent, ir_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.
Beware: Has a bad runtime for array elements (O(|array|) and should be
avoided there. Use add_compound_ent_value_w_path() instead and create
the path manually. */
void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member);
/** Returns the last member in the path */
ir_entity *get_compound_ent_value_member(ir_entity *ent, int pos);
/** Sets the path at pos 0 */
void set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos);
/** Sets the new style initializers of an entity. */
void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer);
......@@ -573,34 +506,6 @@ int has_entity_initializer(const ir_entity *entity);
/** Return the new style initializers of an entity. */
ir_initializer_t *get_entity_initializer(const ir_entity *entity);
/** Initializes the entity ent which must be of a one dimensional
array type with the values given in the values array.
The array must have a lower and an upper bound. Keeps the
order of values. Does not test whether the number of values
fits into the given array size. Does not test whether the
values have the proper mode for the array. */
void set_array_entity_values(ir_entity *ent, tarval **values, int num_vals);
/**
* Return the offset in bits from the last byte address.
*
* 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.
*/
unsigned get_compound_ent_value_offset_bit_remainder(ir_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.
*/
unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos);
/* --- 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
......@@ -647,13 +552,6 @@ int is_compound_entity(ir_entity *ent);
/** Returns true if the type of the entity is a Method type. */
int is_method_entity(ir_entity *ent);
/** Returns non-zero if ent1 and ent2 have are equal except for their owner.
Two entities are equal if
- they have the same type (the same C-struct)
- ...?
*/
int equal_entity(ir_entity *ent1, ir_entity *ent2);
/** Outputs a unique number for this entity if libfirm is compiled for
* debugging, (configure with --enable-debug) else returns the address
* of the type cast to long.
......@@ -730,7 +628,8 @@ ir_type *get_entity_repr_class(const ir_entity *ent);
* - irg = NULL
* - link = NULL
*/
/* A variable that contains the only unknown entity. */
/** A variable that contains the only unknown entity. */
extern ir_entity *unknown_entity;
/** Returns the @link unknown_entity unknown entity @endlink. */
......@@ -758,8 +657,6 @@ typedef enum acc_bits {
* 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
*/
/**
......@@ -1126,8 +1023,6 @@ ir_entity *get_entity_trans_overwrites_next(const ir_entity *ent);
* relation. Example: (A)(new C()).
* any: Cast operations do not conform with the transitive inheritance
* relation. Example: (B2)(new B1())
*
* @see: tropt.h
*/
/* ----------------------------------------------------------------------- */
......@@ -1260,8 +1155,6 @@ ir_type *skip_tid(ir_type *tp);
* 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.
*
* @see tpop.h
*/
#include "typerep.h"
......
/*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in the
* packaging of this file.
*
* Licensees holding valid libFirm Professional Edition licenses may use
* this file in accordance with the libFirm Commercial License.
* Agreement provided with the Software.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/**
* @file
* @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
* @version $Id$
*/
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include "firm_types.h"
#include "typerep.h"
#include "compound_path_t.h"
#include "xmalloc.h"
#include "type_t.h"
#include "entity_t.h"
#include "irgraph_t.h"
#include "ircons.h"
compound_graph_path *new_compound_graph_path(ir_type *tp, int length)
{
compound_graph_path *res;
assert(is_compound_type(tp));
assert(length > 0);
res = xmalloc(sizeof(*res) + (length-1) * sizeof(res->list[0]));
memset(res, 0, sizeof(*res) + (length-1) * sizeof(res->list[0]));
res->kind = k_ir_compound_graph_path;
res->tp = tp;
res->len = length;
return res;
}
void free_compound_graph_path(compound_graph_path *gr)
{
assert(gr && is_compound_graph_path(gr));
gr->kind = k_BAD;
free(gr);
}
int is_compound_graph_path(const void *thing)
{
return get_kind(thing) == k_ir_compound_graph_path;
}
int is_proper_compound_graph_path(compound_graph_path *gr, int pos)
{
int i;
ir_entity *node;
ir_type *owner = gr->tp;
for (i = 0; i <= pos; i++) {
node = get_compound_graph_path_node(gr, i);
if (node == NULL)
/* Path not yet complete. */
return 1;
if (get_entity_owner(node) != owner)
return 0;
owner = get_entity_type(node);
}
if (pos == get_compound_graph_path_length(gr))
if (!is_atomic_type(owner))
return 0;
return 1;
}
int get_compound_graph_path_length(const compound_graph_path *gr)
{
assert(gr && is_compound_graph_path(gr));
return gr->len;
}
ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, int pos)
{
assert(gr && is_compound_graph_path(gr));
assert(pos >= 0 && pos < gr->len);
return gr->list[pos].node;
}
void set_compound_graph_path_node(compound_graph_path *gr, int pos,
ir_entity *node)
{
assert(gr && is_compound_graph_path(gr));
assert(pos >= 0 && pos < gr->len);
assert(is_entity(node));
gr->list[pos].node = node;
assert(is_proper_compound_graph_path(gr, pos));
}
int get_compound_graph_path_array_index(const compound_graph_path *gr, int pos)
{
assert(gr && is_compound_graph_path(gr));
assert(pos >= 0 && pos < gr->len);
return gr->list[pos].index;
}
void set_compound_graph_path_array_index(compound_graph_path *gr, int pos,
int index)
{
assert(gr && is_compound_graph_path(gr));
assert(pos >= 0 && pos < gr->len);
gr->list[pos].index = index;
}
ir_type *get_compound_graph_path_type(const compound_graph_path *gr)
{
assert(gr && is_compound_graph_path(gr));
return gr->tp;
}
void add_compound_ent_value_w_path(ir_entity *ent, ir_node *val,
compound_graph_path *path)
{
assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
assert(is_compound_graph_path(path));
ARR_APP1(ir_node *, ent->attr.cmpd_attr.values, val);
ARR_APP1(compound_graph_path *, ent->attr.cmpd_attr.val_paths, path);
}
void set_compound_ent_value_w_path(ir_entity *ent, ir_node *val,
compound_graph_path *path, int pos)
{
assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
assert(is_compound_graph_path(path));
assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
ent->attr.cmpd_attr.values[pos] = val;
ent->attr.cmpd_attr.val_paths[pos] = path;
}
compound_graph_path *get_compound_ent_value_path(ir_entity *ent, int pos)
{
assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
assert(!ent->has_initializer);
assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.val_paths));
return ent->attr.cmpd_attr.val_paths[pos];
}
/**
* Returns non-zero, if two compound_graph_pathes are equal
*
* @param path1 the first path
* @param path2 the second path
*/
static int equal_paths(compound_graph_path *path1, compound_graph_path *path2)
{
int i;
int len1 = get_compound_graph_path_length(path1);
int len2 = get_compound_graph_path_length(path2);
if (len2 != len1) return 0;
for (i = 0; i < len1; i++) {
ir_type *tp;
ir_entity *node1 = get_compound_graph_path_node(path1, i);
ir_entity *node2 = get_compound_graph_path_node(path2, i);
if (node1 != node2) return 0;
tp = get_entity_owner(node1);
if (is_Array_type(tp)) {
int index1 = get_compound_graph_path_array_index(path1, i);
int index2 = get_compound_graph_path_array_index(path2, i);
if (index1 != index2)
return 0;
}
}
return 1;
}
/**
* Returns the position of a value with the given path.
* The path must contain array indices for all array element entities.
*
* @todo This implementation is very slow (O(number of initializers * |path|)
* and should be replaced when the new tree oriented
* value representation is finally implemented.
*/
static int get_compound_ent_pos_by_path(ir_entity *ent,
compound_graph_path *path)
{
int i, n_paths = get_compound_ent_n_values(ent);
for (i = 0; i < n_paths; i ++) {
compound_graph_path *gr = get_compound_ent_value_path(ent, i);
if (equal_paths(gr, path))
return i;
}
return -1;
}
ir_node *get_compound_ent_value_by_path(ir_entity *ent,
compound_graph_path *path)
{
int pos = get_compound_ent_pos_by_path(ent, path);
if (pos >= 0)
return get_compound_ent_value(ent, pos);
return NULL;
}
void remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent)
{
int i, n;
assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
n = ARR_LEN(ent->attr.cmpd_attr.val_paths);
for (i = 0; i < n; ++i) {
compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i];
if (path->list[path->len-1].node == value_ent) {
for (; i < n - 1; ++i) {
ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1];
ent->attr.cmpd_attr.values[i] = ent->attr.cmpd_attr.values[i+1];
}
ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, n - 1);
ARR_SETLEN(ir_node*, ent->attr.cmpd_attr.values, n - 1);
break;
}
}
}
void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member)
{
compound_graph_path *path;