Commit 9f1d937f authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

more handling for compound graph path ,

more verification

[r5323]
parent 4759d876
......@@ -696,6 +696,53 @@ get_compound_ent_value_path(entity *ent, int pos) {
return ent->val_paths[pos];
}
static int equal_paths(compound_graph_path *path1, int *visited_indicees, 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 false;
for (i = 0; i < len1; i++) {
entity *node1 = get_compound_graph_path_node(path1, i);
entity *node2 = get_compound_graph_path_node(path2, i);
if (node1 != node2) return false;
type *tp = get_entity_owner(node1);
if (is_Array_type(tp)) {
/* Compute the index of this node. */
assert(get_array_n_dimensions(tp) == 1 && "multidim not implemented");
long low = get_array_lower_bound_int(tp, 0);
if (low+visited_indicees[i] < get_compound_graph_path_array_index(path2, i)) {
visited_indicees[i]++;
return false;
} else {
assert(low+visited_indicees[i] == get_compound_graph_path_array_index(path2, i));
}
}
}
return true;
}
/* Returns the position of a value with the given path.
* The path must contain array indicees for all array element entities. */
int get_compound_ent_pos_by_path(entity *ent, compound_graph_path *path) {
int i, n_paths = get_compound_ent_n_values(ent);
int *visited_indicees = (int *)xcalloc(get_compound_graph_path_length(path), sizeof(int));
for (i = 0; i < n_paths; i ++) {
if (equal_paths(get_compound_ent_value_path(ent, i), visited_indicees, path))
return i;
}
assert(0 && "path not found");
return -1;
}
/* Returns a constant value given the access path.
* The path must contain array indicees for all array element entities. */
ir_node *get_compound_ent_value_by_path(entity *ent, compound_graph_path *path) {
return get_compound_ent_value(ent, get_compound_ent_pos_by_path(ent, path));
}
void
remove_compound_ent_value(entity *ent, entity *value_ent) {
int i;
......@@ -889,7 +936,7 @@ static int get_next_index(entity *elem_ent) {
* array bounds must be representable as ints.
*
* (If the bounds are not representable as ints we have to represent
* the indices as firm nodes. But the still we must be able to
* the indices as firm nodes. But still we must be able to
* evaluate the index against the upper bound.)
*/
void compute_compound_ent_array_indicees(entity *ent) {
......@@ -947,7 +994,6 @@ void compute_compound_ent_array_indicees(entity *ent) {
set_compound_graph_path_array_index (path, j, get_next_index(node));
}
}
}
/** resize: double the allocated buffer */
......
......@@ -376,7 +376,7 @@ void set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *n
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);
/** Checks wether the path up to pos is correct. If the path contains a NULL,
/** Checks whether the path up to pos is correct. If the path contains a NULL,
* assumes the path is not complete and returns 'true'. */
int is_proper_compound_graph_path(compound_graph_path *gr, int pos);
......@@ -389,8 +389,16 @@ void set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph
* Asserts if the entity has variability_uninitialized.
* */
int get_compound_ent_n_values(entity *ent);
/** Returns a constant value given the position. */
ir_node *get_compound_ent_value(entity *ent, int pos);
/** Returns the access path for value at position pos. */
compound_graph_path *get_compound_ent_value_path(entity *ent, int pos);
/** Returns the position of a value with the given path.
* The path must contain array indicees for all array element entities. */
int get_compound_ent_pos_by_path(entity *ent, compound_graph_path *path);
/** Returns a constant value given the access path.
* The path must contain array indicees for all array element entities. */
ir_node *get_compound_ent_value_by_path(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
......
......@@ -39,6 +39,7 @@
# define _ENTITY_T_H_
#include "firm_common_t.h"
#include "firm_config.h"
# include "entity.h"
# include "typegmod.h"
......@@ -52,9 +53,9 @@ struct compound_graph_path {
type *tp; /**< The type this path belongs to. */
int len; /**< length of the path */
int *arr_indicees; /**< List of array indeces. To compute position of
array elements */
array elements */
entity *nodes[1]; /**< List of entities of length len to express the
access path. */
access path. */
};
/** the type of an entity */
......
......@@ -169,6 +169,8 @@ static int constants_on_wrong_irg(entity *ent) {
*/
static int check_entity(entity *ent) {
int rem_vpi;
type *tp = get_entity_type(ent);
type *owner = get_entity_owner(ent);
current_ir_graph = get_const_code_irg();
if (constants_on_wrong_irg(ent)) {
......@@ -198,6 +200,21 @@ static int check_entity(entity *ent) {
}
}
/* Entities in global type are not dynamic or automatic allocated. */
if (owner == get_glob_type()) {
assert(get_entity_allocation(ent) != allocation_dynamic &&
get_entity_allocation(ent) != allocation_automatic);
}
if (get_entity_variability(ent) != variability_uninitialized) {
if (is_atomic_type(tp)) {
ir_node *val = get_atomic_ent_value(ent);
if (val)
assert(get_irn_mode(val) == get_type_mode(tp) &&
"Mode of constant in entity must match type.");
}
}
return no_error;
}
......
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