Commit dd6793ed authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Remove compound path initializers.

parent af4023e8
......@@ -6,7 +6,6 @@ libfirminclude_HEADERS = \
callgraph.h \
cdep.h \
cgana.h \
compound_path.h \
dbginfo.h \
end.h \
execfreq.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
* @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"
#include "begin.h"
/**
* path into compound types
* @deprecated
*/
typedef struct compound_graph_path compound_graph_path;
/**
* @deprecated
* Creates a new compound graph path of given length.
*/
FIRM_API compound_graph_path *new_compound_graph_path(ir_type *tp, size_t length);
/**
* @deprecated
* Returns non-zero if an object is a compound graph path
*/
FIRM_API int is_compound_graph_path(const void *thing);
/**
* @deprecated
* Frees a graph path object
*/
FIRM_API void free_compound_graph_path(compound_graph_path *gr);
/**
* @deprecated
* Returns the length of a graph path
*/
FIRM_API size_t get_compound_graph_path_length(const compound_graph_path *gr);
/**
* @deprecated
* Returns the entity node of an compound graph path at position pos.
*/
ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, size_t pos);
/**
* @deprecated
* Sets the entity node of an compound graph path at position pos.
*/
FIRM_API void set_compound_graph_path_node(compound_graph_path *gr, size_t pos,
ir_entity *node);
/**
* @deprecated
* Returns the index of an compound graph path at position pos.
*/
FIRM_API long get_compound_graph_path_array_index(const compound_graph_path *gr, size_t pos);
/**
* @deprecated
* Sets the index of an compound graph path at position pos.
*/
FIRM_API void set_compound_graph_path_array_index(compound_graph_path *gr, size_t pos, long index);
/**
* @deprecated
* Returns the type of an compound graph path.
*/
FIRM_API 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.
*/
FIRM_API int is_proper_compound_graph_path(compound_graph_path *gr, size_t 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.
*/
FIRM_API void add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path);
/**
* @deprecated
* Sets initializer value for a compound ent path
*/
FIRM_API void set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, size_t pos);
/**
* @deprecated
* Returns the access path for value at position pos.
*/
FIRM_API compound_graph_path *get_compound_ent_value_path(const ir_entity *ent, size_t pos);
/**
* @deprecated
* Returns a constant value given the access path.
* The path must contain array indices for all array element entities.
*/
FIRM_API ir_node *get_compound_ent_value_by_path(const 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.
*/
FIRM_API 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.
*/
FIRM_API void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member);
/**
* @deprecated
* Returns the last member in the path
*/
FIRM_API ir_entity *get_compound_ent_value_member(const ir_entity *ent, size_t pos);
/**
* @deprecated
* Sets the path at pos 0
*/
FIRM_API void set_compound_ent_value(ir_entity *ent, ir_node *val,
ir_entity *member, size_t 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.
*/
FIRM_API void set_array_entity_values(ir_entity *ent, ir_tarval **values, size_t num_vals);
/**
* @deprecated
* Returns 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.
*/
FIRM_API unsigned get_compound_ent_value_offset_bit_remainder(const ir_entity *ent, size_t pos);
/**
* @deprecated
* Returns 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.
*/
FIRM_API unsigned get_compound_ent_value_offset_bytes(const ir_entity *ent, size_t pos);
/**
* @deprecated
* Returns the number of constant values needed to initialize the entity.
* Asserts if the entity has variability_uninitialized.
*/
FIRM_API size_t get_compound_ent_n_values(const ir_entity *ent);
/**
* @deprecated
* Returns a constant value given the position.
*/
FIRM_API ir_node *get_compound_ent_value(const ir_entity *ent, size_t pos);
/**
* @deprecated
* return 1 if entity has a compound_graph-style initializer
*/
FIRM_API int entity_has_compound_ent_values(const ir_entity *entity);
#include "end.h"
#endif
......@@ -64,7 +64,6 @@ typedef enum {
k_ir_op, /**< An IR opcode. */
k_tarval, /**< A tarval. */
k_ir_loop, /**< A loop. */
k_ir_compound_graph_path, /**< A compound graph path, see entity.h. */
k_ir_prog, /**< A program representation (irp). */
k_ir_graph_pass, /**< An ir_graph pass. */
k_ir_prog_pass, /**< An ir_prog pass. */
......
......@@ -50,7 +50,6 @@ struct obstack;
* - @%N The node number of an ir node.
* - @%m The mode name of an ir mode.
* - @%B The block node number of the nodes block.
* - @%P A compound graph path.
* - @%I An ident.
* - @%D Print as many white spaces as given in the parameter.
* - @%G A debug info (if available) from the given ir node.
......
......@@ -232,7 +232,6 @@ libfirm_la_SOURCES = \
stat/stat_dmp.c \
stat/statev.c \
stat/stat_timing.c \
tr/compound_path.c \
tr/entity.c \
tr/tpop.c \
tr/tr_inheritance.c \
......
......@@ -511,19 +511,6 @@ static void add_method_address(ir_entity *ent, pset *set)
if (ent->initializer != NULL) {
add_method_address_inititializer(get_entity_initializer(ent), set);
} else if (entity_has_compound_ent_values(ent)) {
size_t i, n;
for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
ir_node *irn = get_compound_ent_value(ent, i);
/* let's check if it's the address of a function */
if (is_SymConst_addr_ent(irn)) {
ir_entity *ent2 = get_SymConst_entity(irn);
if (is_Method_type(get_entity_type(ent2)))
pset_insert_ptr(set, ent2);
}
}
}
}
......
......@@ -1104,18 +1104,6 @@ static void check_initializer(ir_entity *ent)
if (ent->initializer != NULL) {
check_initializer_nodes(ent->initializer);
} else if (entity_has_compound_ent_values(ent)) {
size_t i, n;
for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
ir_node *irn = get_compound_ent_value(ent, i);
/* let's check if it's an address */
if (is_SymConst_addr_ent(irn)) {
ir_entity *symconst_ent = get_SymConst_entity(irn);
set_entity_usage(symconst_ent, ir_usage_unknown);
}
}
}
}
......
......@@ -375,7 +375,6 @@ static int entity_is_string_const(const ir_entity *ent)
{
ir_type *type, *element_type;
ir_mode *mode;
int i, c, n;
type = get_entity_type(ent);
......@@ -397,26 +396,6 @@ static int entity_is_string_const(const ir_entity *ent)
if (ent->initializer != NULL) {
return initializer_is_string_const(ent->initializer);
} else if (entity_has_compound_ent_values(ent)) {
int found_printable = 0;
/* if it contains only printable chars and a 0 at the end */
n = get_compound_ent_n_values(ent);
for (i = 0; i < n; ++i) {
ir_node *irn = get_compound_ent_value(ent, i);
if (! is_Const(irn))
return 0;
c = (int) get_tarval_long(get_Const_tarval(irn));
if (isgraph(c) || isspace(c))
found_printable = 1;
else if (c != 0)
return 0;
if (i == n - 1 && c != '\0')
return 0;
}
return found_printable;
}
return 0;
......@@ -658,55 +637,6 @@ const char *be_gas_insn_label_prefix(void)
return ".LE";
}
/**
* Return the tarval of an atomic initializer.
*
* @param init a node representing the initializer (on the const code irg)
*
* @return the tarval
*/
static ir_tarval *get_atomic_init_tv(ir_node *init)
{
for (;;) {
ir_mode *mode = get_irn_mode(init);
switch (get_irn_opcode(init)) {
case iro_Cast:
init = get_Cast_op(init);
continue;
case iro_Conv:
init = get_Conv_op(init);
continue;
case iro_Const:
return get_Const_tarval(init);
case iro_SymConst:
switch (get_SymConst_kind(init)) {
case symconst_type_size:
return new_tarval_from_long(get_type_size_bytes(get_SymConst_type(init)), mode);
case symconst_type_align:
return new_tarval_from_long(get_type_alignment_bytes(get_SymConst_type(init)), mode);
case symconst_ofs_ent:
return new_tarval_from_long(get_entity_offset(get_SymConst_entity(init)), mode);
case symconst_enum_const:
return get_enumeration_value(get_SymConst_enum(init));
default:
return NULL;
}
default:
return NULL;
}
}
}
/**
* Dump an atomic value.
*
......@@ -822,62 +752,6 @@ static void emit_size_type(size_t size)
}
}
/**
* Dump a string constant.
* No checks are made!!
*
* @param ent The entity to dump.
*/
static void emit_string_cst(const ir_entity *ent)
{
int i, len;
int output_len;
ir_type *type;
int type_size;
int remaining_space;
len = get_compound_ent_n_values(ent);
output_len = len;
if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
be_emit_cstring("\t.ascii \"");
} else {
be_emit_cstring("\t.string \"");
output_len -= 1;
}
for (i = 0; i < output_len; ++i) {
ir_node *irn;
int c;
irn = get_compound_ent_value(ent, i);
c = (int) get_tarval_long(get_Const_tarval(irn));
switch (c) {
case '"' : be_emit_cstring("\\\""); break;
case '\n': be_emit_cstring("\\n"); break;
case '\r': be_emit_cstring("\\r"); break;
case '\t': be_emit_cstring("\\t"); break;
case '\\': be_emit_cstring("\\\\"); break;
default :
if (isprint(c))
be_emit_char(c);
else
be_emit_irprintf("\\%03o", c);
break;
}
}
be_emit_cstring("\"\n");
be_emit_write_line();
type = get_entity_type(ent);
type_size = get_type_size_bytes(type);
remaining_space = type_size - len;
assert(remaining_space >= 0);
if (remaining_space > 0) {
be_emit_irprintf("\t.space\t%d, 0\n", remaining_space);
}
}
static size_t emit_string_initializer(const ir_initializer_t *initializer)
{
size_t i, len;
......@@ -1329,117 +1203,6 @@ static void emit_initializer(be_gas_decl_env_t *env, const ir_entity *entity)
xfree(vals);
}
static void emit_compound_graph_init(be_gas_decl_env_t *env,
const ir_entity *ent)
{
normal_or_bitfield *vals;
int i, j, n;
unsigned k, last_ofs;
if (entity_is_string_const(ent)) {
emit_string_cst(ent);
return;
}
n = get_compound_ent_n_values(ent);
/* Find the initializer size. Sorrily gcc support a nasty feature:
The last field of a compound may be a flexible array. This allows
initializers bigger than the type size. */
last_ofs = get_type_size_bytes(get_entity_type(ent));
for (i = 0; i < n; ++i) {
unsigned offset = get_compound_ent_value_offset_bytes(ent, i);
unsigned bits_remainder = get_compound_ent_value_offset_bit_remainder(ent, i);
ir_node *value = get_compound_ent_value(ent, i);
unsigned value_len = get_mode_size_bits(get_irn_mode(value));
offset += (value_len + bits_remainder + 7) >> 3;
if (offset > last_ofs) {
last_ofs = offset;
}
}
/*
* In the worst case, every initializer allocates one byte.
* Moreover, initializer might be big, do not allocate on stack.
*/
vals = XMALLOCNZ(normal_or_bitfield, last_ofs);
/* collect the values and store them at the offsets */
for (i = 0; i < n; ++i) {
unsigned offset = get_compound_ent_value_offset_bytes(ent, i);
int offset_bits = get_compound_ent_value_offset_bit_remainder(ent, i);
ir_node *value = get_compound_ent_value(ent, i);
int value_len = get_mode_size_bits(get_irn_mode(value));
assert(offset_bits >= 0);
if (offset_bits != 0 ||
(value_len != 8 && value_len != 16 && value_len != 32 && value_len != 64)) {
ir_tarval *tv = get_atomic_init_tv(value);
unsigned char curr_bits, last_bits = 0;
if (tv == NULL) {
panic("Couldn't get numeric value for bitfield initializer '%s'",
get_entity_ld_name(ent));
}
/* normalize offset */
offset += offset_bits >> 3;
offset_bits &= 7;
for (j = 0; value_len + offset_bits > 0; ++j) {
assert(offset + j < last_ofs);
assert(vals[offset + j].kind == BITFIELD || vals[offset + j].v.value == NULL);
vals[offset + j].kind = BITFIELD;
curr_bits = get_tarval_sub_bits(tv, j);
vals[offset + j].v.bf_val |= (last_bits >> (8 - offset_bits)) | (curr_bits << offset_bits);
value_len -= 8;
last_bits = curr_bits;
}
} else {
int i;
assert(offset < last_ofs);
assert(vals[offset].kind == NORMAL);
for (i = 1; i < value_len / 8; ++i) {
assert(vals[offset + i].v.value == NULL);
}
vals[offset].v.value = value;
}
}
/* now write them sorted */
for (k = 0; k < last_ofs; ) {
int space = 0, skip = 0;
if (vals[k].kind == NORMAL) {
if (vals[k].v.value != NULL) {
emit_node_data(env, vals[k].v.value, vals[k].type);
skip = get_mode_size_bytes(get_irn_mode(vals[k].v.value)) - 1;
} else {
space = 1;
}
} else {
assert(vals[k].kind == BITFIELD);
be_emit_irprintf("\t.byte\t%d\n", vals[k].v.bf_val);
}
++k;
while (k < last_ofs && vals[k].kind == NORMAL && vals[k].v.value == NULL) {
++space;
++k;
}
space -= skip;
assert(space >= 0);
/* a gap */
if (space > 0) {
be_emit_irprintf("\t.space\t%d, 0\n", space);
be_emit_write_line();
}
}
xfree(vals);
}
static void emit_align(unsigned p2alignment)
{
be_emit_irprintf("\t.p2align\t%u\n", log2_floor(p2alignment));
......@@ -1712,8 +1475,6 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
be_emit_irprintf("\t.space %u, 0\n", get_type_size_bytes(type));
be_emit_write_line();
}
} else if (entity_has_compound_ent_values(entity)) {
emit_compound_graph_init(env, entity);
} else {
assert(entity->initializer != NULL);
emit_initializer(env, entity);
......
......@@ -689,7 +689,6 @@ static void show_firm_object(void *firm_thing)
case k_ir_op:
case k_tarval:
case k_ir_loop:
case k_ir_compound_graph_path:
case k_ir_prog:
fprintf(f, "NIY\n");
break;
......
......@@ -118,12 +118,10 @@ static int firm_emit(lc_appendable_t *app,
void *X = (void*)arg->v_ptr;
firm_kind *obj = (firm_kind*)X;
size_t i, n;
ir_node *block;
char add[64];
char buf[256];
char tv_buf[256];
ir_entity *ent;
buf[0] = '\0';
add[0] = '\0';
......@@ -225,24 +223,6 @@ static int firm_emit(lc_appendable_t *app,
snprintf(buf, sizeof(buf), "%s%s", A("op"), get_op_name(op));
break;
}
case k_ir_compound_graph_path: {
compound_graph_path *path = (compound_graph_path*)X;
n = get_compound_graph_path_length(path);
for (i = 0; i < n; ++i) {
ent = get_compound_graph_path_node(path, i);
strncat(buf, ".", sizeof(buf)-1);
strncat(buf, get_entity_name(ent), sizeof(buf)-1);
if (is_Array_type(get_entity_owner(ent))) {
snprintf(add, sizeof(add), "[%ld]",
get_compound_graph_path_array_index(path, i));
strncat(buf, add, sizeof(buf)-1);
}
}
add[0] = '\0';
break;
}
default:
snprintf(buf, sizeof(buf), "UNKWN");
......@@ -321,7 +301,6 @@ lc_arg_env_t *firm_get_arg_env(void)
{"firm:irn_nr", 'N'},
{"firm:mode", 'm'},
{"firm:block", 'B'},
{"firm:cg_path", 'P'},
};