/*
- * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
/** Returns the member at position pos, 0 <= pos < n_member */
FIRM_API ir_entity *get_class_member(const ir_type *clss, size_t pos);
-/** Returns index of mem in clss, -1 if not contained. */
+#define INVALID_MEMBER_INDEX ((size_t)-1)
+
+/** Returns index of mem in clss, INVALID_MEMBER_INDEX if not contained. */
FIRM_API size_t get_class_member_index(const ir_type *clss, ir_entity *mem);
/** Finds the member with name 'name'. If several members with the same
/* nothing */
break;
case iro_Call:
+ {
+ size_t i, n;
/* we must handle Call nodes specially, because their call address input
do not expose a method address. */
set_irn_link(node, MARK);
- for (i = get_Call_n_params(node) - 1; i >= 0; --i) {
+ for (i = 0, n = get_Call_n_params(node); i < n; ++i) {
ir_node *pred = get_Call_param(node, i);
if (mode_is_reference(get_irn_mode(pred))) {
free_mark(pred, set);
}
}
break;
+ }
default:
/* other nodes: Alle anderen Knoten nehmen wir als Verr�ter an, bis
* jemand das Gegenteil implementiert. */
static size_t get_free_methods(ir_entity ***free_methods)
{
eset *free_set = eset_create();
- size_t i, n;
- int j;
+ size_t i, n, j, m;
ir_entity **arr;
ir_entity *ent;
ir_graph *irg;
/* insert all methods that are used in global variables initializers */
tp = get_glob_type();
- for (j = get_class_n_members(tp) - 1; j >= 0; --j) {
+ for (j = 0, m = get_class_n_members(tp); j < m; ++j) {
ent = get_class_member(tp, j);
add_method_address(ent, free_set);
}
tp = get_tls_type();
- for (j = get_class_n_members(tp) - 1; j >= 0; --j) {
+ for (j = 0, m = get_class_n_members(tp); j < m; ++j) {
ent = get_class_member(tp, j);
add_method_address(ent, free_set);
}
/*
- * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
void *X = (void*)arg->v_ptr;
firm_kind *obj = (firm_kind*)X;
- int i, n;
+ size_t i, n;
ir_node *block;
char add[64];
char buf[256];
int r_find_value(ir_graph *irg, ir_node *value)
{
- int i;
+ size_t i;
ir_node *bl = irg->current_block;
- for (i = ARR_LEN(bl->attr.block.graph_arr) - 1; i >= 1; --i)
- if (bl->attr.block.graph_arr[i] == value)
+ for (i = ARR_LEN(bl->attr.block.graph_arr); i > 1;) {
+ if (bl->attr.block.graph_arr[--i] == value)
return i - 1;
+ }
return -1;
}
void irp_finalize_cons(void)
{
- int i;
- for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+ size_t i, n;
+ for (i = 0, n = get_irp_n_irgs(); i < n; ++i) {
irg_finalize_cons(get_irp_irg(i));
}
irp->phase_state = phase_high;
/*
- * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
void set_irp_loopinfo_inconsistent(void)
{
- int i;
- for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+ size_t i, n;
+ for (i = 0, n = get_irp_n_irgs(); i < n; ++i) {
set_irg_loopinfo_inconsistent(get_irp_irg(i));
}
}
/*
- * Copyright (C) 1995-2009 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
#include "irnode_t.h"
#include "irprog.h"
#include "irgraph_t.h"
+#include "irprintf.h"
#include "ircons.h"
#include "irgmod.h"
#include "irflag_t.h"
static void export_type_post(io_env_t *env, ir_type *tp)
{
FILE *f = env->file;
- int i;
+ size_t i;
/* skip types already handled by pre walker */
switch (get_type_tpop_code(tp)) {
switch (get_type_tpop_code(tp)) {
case tpo_array: {
- int n = get_array_n_dimensions(tp);
- fprintf(f, "%d %ld ", n, get_type_nr(get_array_element_type(tp)));
+ size_t n = get_array_n_dimensions(tp);
+ ir_fprintf(f, "%zu %ld ", n, get_type_nr(get_array_element_type(tp)));
for (i = 0; i < n; i++) {
ir_node *lower = get_array_lower_bound(tp, i);
ir_node *upper = get_array_upper_bound(tp, i);
}
case tpo_method: {
- int nparams = get_method_n_params(tp);
- int nresults = get_method_n_ress(tp);
- fprintf(f, "%u %u %d %d ", get_method_calling_convention(tp),
+ size_t nparams = get_method_n_params(tp);
+ size_t nresults = get_method_n_ress(tp);
+ ir_fprintf(f, "%u %u %zu %zu ", get_method_calling_convention(tp),
get_method_additional_properties(tp), nparams, nresults);
for (i = 0; i < nparams; i++)
write_long(env, get_type_nr(get_method_param_type(tp, i)));
for (i = 0; i < nresults; i++)
write_long(env, get_type_nr(get_method_res_type(tp, i)));
- fprintf(f, "%lu ",
- (unsigned long) get_method_first_variadic_param_index(tp));
+ ir_fprintf(f, "%zu ", get_method_first_variadic_param_index(tp));
break;
}
fputs("initializer ", env->file);
write_initializer(env, get_entity_initializer(ent));
} else if (entity_has_compound_ent_values(ent)) {
- int i, n = get_compound_ent_n_values(ent);
+ size_t i, n = get_compound_ent_n_values(ent);
fputs("compoundgraph ", env->file);
- fprintf(env->file, "%d ", n);
+ ir_fprintf(env->file, "%zu ", n);
for (i = 0; i < n; i++) {
ir_entity *member = get_compound_ent_value_member(ent, i);
ir_node *irn = get_compound_ent_value(ent, i);
static void export_modes(io_env_t *env)
{
- int i, n_modes = get_irp_n_modes();
+ size_t i, n_modes = get_irp_n_modes();
fputs("modes {\n", env->file);
void ir_export_file(FILE *file, const char *outputname)
{
io_env_t env;
- int i, n_irgs = get_irp_n_irgs();
+ size_t i, n_irgs = get_irp_n_irgs();
(void) outputname;
env.file = file;
static ir_mode *read_mode(io_env_t *env)
{
char *str = read_word(env);
- int i, n;
+ size_t i, n;
n = get_irp_n_modes();
for (i = 0; i < n; i++) {
firm_verification_t oldver = get_node_verification_mode();
io_env_t ioenv;
io_env_t *env = &ioenv;
- int i, n;
+ size_t i, n;
symtbl_init();
{
ir_type *lowered, *ptr_tp, *value_type;
ir_type **params, **results, *res_tp;
- int *param_map;
+ size_t *param_map;
ir_mode *modes[MAX_REGISTER_RET_VAL];
- int n_ress, n_params, nn_ress, nn_params, i, first_variadic;
+ size_t n_ress, n_params, nn_ress, nn_params, i, first_variadic;
add_hidden hidden_params;
int changed = 0;
ir_variadicity var;
n_params = get_method_n_params(mtp);
NEW_ARR_A(ir_type *, params, n_params + n_ress);
- NEW_ARR_A(int, param_map, n_params + n_ress);
+ NEW_ARR_A(size_t, param_map, n_params + n_ress);
first_variadic = get_method_first_variadic_param_index(mtp);
address will be transmitted as a hidden parameter. */
ptr_tp = lp->find_pointer_type(res_tp, get_modeP_data(), lp->def_ptr_alignment);
params[nn_params] = ptr_tp;
- param_map[nn_params] = -1 - i;
+ param_map[nn_params] = n_params + i;
++nn_params;
changed++;
if (lp->flags & LF_RETURN_HIDDEN)
if (is_compound_type(res_tp)) {
params[nn_params] = lp->find_pointer_type(res_tp, get_modeP_data(), lp->def_ptr_alignment);
- param_map[nn_params] = -1 - i;
+ param_map[nn_params] = n_params + i;
++nn_params;
} else {
results[nn_ress++] = res_tp;
/* set new param positions */
for (i = 0; i < nn_params; ++i) {
ir_entity *ent = get_method_value_param_ent(lowered, i);
- int pos = param_map[i];
+ size_t pos = param_map[i];
ident *id;
set_entity_link(ent, INT_TO_PTR(pos));
- if (pos < 0) {
+ if (pos >= n_params) {
/* formally return value, ignore for now */
continue;
}
* Walker environment for fix_args_and_collect_calls().
*/
typedef struct wlk_env_t {
- int arg_shift; /**< The Argument index shift for parameters. */
- int first_hidden; /**< The index of the first hidden argument. */
+ size_t arg_shift; /**< The Argument index shift for parameters. */
+ size_t first_hidden; /**< The index of the first hidden argument. */
struct obstack obst; /**< An obstack to allocate the data on. */
cl_entry *cl_list; /**< The call list. */
pmap *dummy_map; /**< A map for finding the dummy arguments. */
static void fix_args_and_collect_calls(ir_node *n, void *ctx)
{
wlk_env *env = (wlk_env*)ctx;
- int i;
ir_type *ctp;
ir_node *ptr;
ir_entity *ent = get_Sel_entity(n);
if (get_entity_owner(ent) == env->value_params) {
- int pos = get_struct_member_index(env->value_params, ent) + env->arg_shift;
+ size_t pos = get_struct_member_index(env->value_params, ent) + env->arg_shift;
ir_entity *new_ent;
new_ent = get_method_value_param_ent(env->lowered_mtp, pos);
ctp = get_Call_type(n);
if (env->params->flags & LF_COMPOUND_RETURN) {
/* check for compound returns */
- for (i = get_method_n_ress(ctp) -1; i >= 0; --i) {
+ size_t i, n_res;
+ for (i = 0, n_res = get_method_n_ress(ctp); i < n_res; ++i) {
if (is_compound_type(get_method_res_type(ctp, i))) {
/*
* This is a call with a compound return. As the result
* @param entry the call list
* @param env the environment
*/
-static void add_hidden_param(ir_graph *irg, int n_com, ir_node **ins, cl_entry *entry, wlk_env *env)
+static void add_hidden_param(ir_graph *irg, size_t n_com, ir_node **ins, cl_entry *entry, wlk_env *env)
{
ir_node *p, *n, *src, *mem, *blk;
ir_entity *ent;
ir_type *owner;
- int n_args;
+ size_t n_args;
n_args = 0;
for (p = entry->copyb; p; p = n) {
ir_node *call, **new_in;
ir_type *ctp, *lowered_mtp;
add_hidden hidden_params;
- int i, n_params, n_com, pos;
+ size_t i, n_res, n_params, n_com, pos;
new_in = NEW_ARR_F(ir_node *, 0);
for (p = env->cl_list; p; p = p->next) {
n_params = get_Call_n_params(call);
n_com = 0;
- for (i = get_method_n_ress(ctp) - 1; i >= 0; --i) {
+ for (i = 0, n_res = get_method_n_ress(ctp); i < n_res; ++i) {
if (is_compound_type(get_method_res_type(ctp, i)))
++n_com;
}
ir_graph *rem = current_ir_graph;
ir_entity *ent = get_irg_entity(irg);
ir_type *mtp, *lowered_mtp, *tp, *ft;
- int i, j, k, n_ress = 0, n_ret_com = 0;
+ size_t i, j, k, n_ress = 0, n_ret_com = 0;
size_t n_cr_opt;
ir_node **new_in, *ret, *endbl, *bl, *mem, *copy;
cr_pair *cr_opt;
}
if (n_ret_com) {
+ int idx;
+
/*
* Now fix the Return node of the current graph.
*/
/* STEP 1: find the return. This is simple, we have normalized the graph. */
endbl = get_irg_end_block(irg);
ret = NULL;
- for (i = get_Block_n_cfgpreds(endbl) - 1; i >= 0; --i) {
- ir_node *pred = get_Block_cfgpred(endbl, i);
+ for (idx = get_Block_n_cfgpreds(endbl) - 1; idx >= 0; --idx) {
+ ir_node *pred = get_Block_cfgpred(endbl, idx);
if (is_Return(pred)) {
ret = pred;
*/
static int must_be_lowered(const lower_params_t *lp, ir_type *tp)
{
- int i, n_ress;
+ size_t i, n_ress;
ir_type *res_tp;
if (is_Method_type(tp)) {
static void adjust_method_type(ir_type *method_type)
{
- int i;
- int n_params;
- int n_res;
+ size_t i;
+ size_t n_params;
+ size_t n_res;
n_params = get_method_n_params(method_type);
for (i = 0; i < n_params; ++i) {
static void compute_down_closure(ir_type *tp)
{
pset *myset, *subset;
- int i, n_subtypes, n_members, n_supertypes;
+ size_t i, n_subtypes, n_members, n_supertypes;
ir_visited_t master_visited = get_master_type_visited();
assert(is_Class_type(tp));
n_members = get_class_n_members(tp);
for (i = 0; i < n_members; ++i) {
ir_entity *mem = get_class_member(tp, i);
- int j, n_overwrittenby = get_entity_n_overwrittenby(mem);
+ size_t j, n_overwrittenby = get_entity_n_overwrittenby(mem);
myset = get_entity_map(mem, d_down);
for (j = 0; j < n_overwrittenby; ++j) {
static void compute_up_closure(ir_type *tp)
{
pset *myset, *subset;
- int i, n_subtypes, n_members, n_supertypes;
+ size_t i, n_subtypes, n_members, n_supertypes;
ir_visited_t master_visited = get_master_type_visited();
assert(is_Class_type(tp));
n_members = get_class_n_members(tp);
for (i = 0; i < n_members; ++i) {
ir_entity *mem = get_class_member(tp, i);
- int j, n_overwrites = get_entity_n_overwrites(mem);
+ size_t j, n_overwrites = get_entity_n_overwrites(mem);
myset = get_entity_map(mem, d_up);
for (j = 0; j < n_overwrites; ++j) {
for (i = 0; i < n_types; ++i) {
ir_type *tp = get_irp_type(i);
if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
- int j, n_subtypes = get_class_n_subtypes(tp);
+ size_t j, n_subtypes = get_class_n_subtypes(tp);
int has_unmarked_subtype = 0;
assert(get_type_visited(tp) < get_master_type_visited()-1);
for (i = 0; i < n_types; ++i) {
ir_type *tp = get_irp_type(i);
if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
- int j, n_supertypes = get_class_n_supertypes(tp);
+ size_t j, n_supertypes = get_class_n_supertypes(tp);
int has_unmarked_supertype = 0;
assert(get_type_visited(tp) < get_master_type_visited()-1);
/** Returns true if low is subclass of high. */
static int check_is_SubClass_of(ir_type *low, ir_type *high)
{
- int i, n_subtypes;
+ size_t i, n_subtypes;
/* depth first search from high downwards. */
n_subtypes = get_class_n_subtypes(high);
int is_overwritten_by(ir_entity *high, ir_entity *low)
{
- int i, n_overwrittenby;
+ size_t i, n_overwrittenby;
assert(is_entity(low) && is_entity(high));
if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
*/
static ir_entity *do_resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *static_ent)
{
- int i, n_overwrittenby;
+ size_t i, n_overwrittenby;
if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
/*
- * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
*/
static int check_class(ir_type *tp)
{
- int i, j, k;
- int found;
+ size_t i, n, j, m;
- for (i = get_class_n_members(tp) - 1; i >= 0; --i) {
+ for (i = 0, n = get_class_n_members(tp); i < n; ++i) {
ir_entity *mem = get_class_member(tp, i);
ASSERT_AND_RET_DBG(
mem,
"NULL members not allowed",
error_null_mem,
- ir_fprintf(stderr, "Type verification error:\n%+F member %d is NULL\n", tp, i)
+ ir_fprintf(stderr, "Type verification error:\n%+F member %zu is NULL\n", tp, i)
);
ASSERT_AND_RET_DBG(
show_ent_overwrite_cnt(mem)
);
- for (j = get_entity_n_overwrites(mem) - 1; j >= 0; --j) {
+ for (j = 0, m = get_entity_n_overwrites(mem); j < m; ++j) {
ir_entity *ovw = get_entity_overwrites(mem, j);
- /*printf(" overwrites: "); DDME(ovw);*/
+ size_t k, n_super;
+
/* Check whether ovw is member of one of tp's supertypes. If so,
- the representation is correct. */
- found = 0;
- for (k = get_class_n_supertypes(tp) - 1; k >= 0; --k) {
- if (get_class_member_index(get_class_supertype(tp, k), ovw) != (size_t)-1) {
- found = 1;
+ the representation is correct. */
+ for (k = 0, n_super = get_class_n_supertypes(tp); k < n_super; ++k) {
+ if (get_class_member_index(get_class_supertype(tp, k), ovw) != INVALID_MEMBER_INDEX) {
+ ASSERT_AND_RET_DBG(
+ 0,
+ "overwrites an entity not contained in direct supertype",
+ error_ent_not_cont,
+ show_ent_not_supertp(mem, ovw)
+ );
break;
}
}
- ASSERT_AND_RET_DBG(
- found,
- "overwrites an entity not contained in direct supertype",
- error_ent_not_cont,
- show_ent_not_supertp(mem, ovw)
- );
}
}
return 0;
/**
* Check an array.
*/
-static int check_array(ir_type *tp)
+static int check_array(const ir_type *tp)
{
- int i, n_dim = get_array_n_dimensions(tp);
+ size_t i, n_dim = get_array_n_dimensions(tp);
for (i = 0; i < n_dim; ++i) {
ASSERT_AND_RET_DBG(
has_array_lower_bound(tp, i) || has_array_upper_bound(tp, i),
"array bound missing",
1,
- ir_fprintf(stderr, "%+F in dimension %d\n", tp, i)
+ ir_fprintf(stderr, "%+F in dimension %zu\n", tp, i)
);
}
return 0;
ir_type *constructors;
ir_type *destructors;
ir_type *thread_locals;
- int i;
+ size_t i, n;
ir_segment_t s;
if (empty == NULL)
}
constructors = get_segment_type(IR_SEGMENT_CONSTRUCTORS);
- for (i = get_compound_n_members(constructors)-1; i >= 0; --i) {
+ for (i = 0, n = get_compound_n_members(constructors); i < n; ++i) {
const ir_entity *entity = get_compound_member(constructors, i);
ASSERT_AND_RET(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER,
"entity without LINKAGE_HIDDEN_USER in constructors is pointless",
"entity in constructors should have ld_ident=''", 1);
}
destructors = get_segment_type(IR_SEGMENT_DESTRUCTORS);
- for (i = get_compound_n_members(destructors)-1; i >= 0; --i) {
+ for (i = 0, n = get_compound_n_members(destructors); i < n; ++i) {
const ir_entity *entity = get_compound_member(destructors, i);
ASSERT_AND_RET(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER,
"entity without LINKAGE_HIDDEN_USER in destructors is pointless",
"entity in destructors should have ld_ident=''", 1);
}
thread_locals = get_segment_type(IR_SEGMENT_THREAD_LOCAL);
- for (i = get_compound_n_members(thread_locals)-1; i >= 0; --i) {
+ for (i = 0, n = get_compound_n_members(thread_locals); i < n; ++i) {
const ir_entity *entity = get_compound_member(thread_locals, i);
/* this is odd and should not be allowed I think */
ASSERT_AND_RET(!is_method_entity(entity),
else if (is_Array_type(tp))
align = get_type_alignment_bytes(get_array_element_type(tp));
else if (is_compound_type(tp)) {
- int i, n = get_compound_n_members(tp);
+ size_t i, n = get_compound_n_members(tp);
align = 0;
for (i = 0; i < n; ++i) {
void free_class_entities(ir_type *clss)
{
- int i;
+ size_t i, n;
assert(clss && (clss->type_op == type_class));
- for (i = get_class_n_members(clss) - 1; i >= 0; --i)
+ for (i = 0, n = get_class_n_members(clss); i < n; ++i)
free_entity(get_class_member(clss, i));
/* do NOT free the type info here. It belongs to another class */
}
if (get_class_member(clss, i) == mem)
return i;
}
- return (size_t)-1;
+ return INVALID_MEMBER_INDEX;
}
ir_entity *(get_class_member)(const ir_type *clss, size_t pos)
ir_entity *get_class_member_by_name(ir_type *clss, ident *name)
{
- int i, n_mem;
+ size_t i, n_mem;
assert(clss && (clss->type_op == type_class));
n_mem = get_class_n_members(clss);
for (i = 0; i < n_mem; ++i) {
ir_entity *mem = get_class_member(clss, i);
- if (get_entity_ident(mem) == name) return mem;
+ if (get_entity_ident(mem) == name)
+ return mem;
}
return NULL;
}
void free_struct_entities(ir_type *strct)
{
- int i;
+ size_t i, n;
assert(strct && (strct->type_op == type_struct));
- for (i = get_struct_n_members(strct)-1; i >= 0; --i)
+ for (i = 0, n = get_struct_n_members(strct); i < n; ++i)
free_entity(get_struct_member(strct, i));
}
* @param len number of fields
* @param tps array of field types with length len
*/
-static ir_type *build_value_type(char const* name, int len, tp_ent_pair *tps)
+static ir_type *build_value_type(char const* name, size_t len, tp_ent_pair *tps)
{
- int i;
+ size_t i;
ir_type *res = new_type_struct(new_id_from_str(name));
res->flags |= tf_value_param_type;
/* Remove type from type list. Must be treated differently than other types. */
remove_irp_type(res);
- for (i = 0; i < len; i++) {
+ for (i = 0; i < len; ++i) {
ident *id = tps[i].param_name;
/* use res as default if corresponding type is not yet set. */
void free_union_entities(ir_type *uni)
{
- int i;
+ size_t i, n;
assert(uni && (uni->type_op == type_union));
- for (i = get_union_n_members(uni) - 1; i >= 0; --i)
+ for (i = 0, n = get_union_n_members(uni); i < n; ++i)
free_entity(get_union_member(uni, i));
}
ir_type *clone_frame_type(ir_type *type)
{
ir_type *res;
- int i, n;
+ size_t i, n;
assert(is_frame_type(type));
/* the entity link resource should be allocated if this function is called */
ident *name;
char buf[32];
unsigned frame_align;
- int i, offset, frame_size;
+ int offset, frame_size;
static unsigned area_cnt = 0;
static ir_type *a_byte = NULL;
frame_size = get_type_size_bytes(frame_type);
if (at_start) {
+ size_t i, n;
/* fix all offsets so far */
- for (i = get_class_n_members(frame_type) - 1; i >= 0; --i) {
+ for (i = 0, n = get_class_n_members(frame_type); i < n; ++i) {
ir_entity *ent = get_class_member(frame_type, i);
set_entity_offset(ent, get_entity_offset(ent) + size);
type_walk_func *post,
void *env)
{
- int i, n_types, n_mem;
+ size_t i, n_types, n_mem;
ir_entity *ent = NULL;
ir_type *tp = NULL;
ir_node *n;