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

Use ARRAY_SIZE(x) and size_t instead of sizeof(x) / sizeof(*x) and int.

parent ee5425ca
...@@ -64,17 +64,14 @@ calling_convention_t *arm_decide_calling_convention(const ir_graph *irg, ...@@ -64,17 +64,14 @@ calling_convention_t *arm_decide_calling_convention(const ir_graph *irg,
unsigned n_param_regs_used = 0; unsigned n_param_regs_used = 0;
reg_or_stackslot_t *params; reg_or_stackslot_t *params;
reg_or_stackslot_t *results; reg_or_stackslot_t *results;
int n_param_regs size_t const n_param_regs = ARRAY_SIZE(param_regs);
= sizeof(param_regs)/sizeof(param_regs[0]); size_t const n_result_regs = ARRAY_SIZE(result_regs);
int n_result_regs size_t const n_float_result_regs = ARRAY_SIZE(float_result_regs);
= sizeof(result_regs)/sizeof(result_regs[0]); size_t n_params;
int n_float_result_regs size_t n_results;
= sizeof(float_result_regs)/sizeof(float_result_regs[0]); size_t i;
int n_params; size_t regnum;
int n_results; size_t float_regnum;
int i;
int regnum;
int float_regnum;
calling_convention_t *cconv; calling_convention_t *cconv;
/* determine how parameters are passed */ /* determine how parameters are passed */
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "iropt_t.h" #include "iropt_t.h"
#include "debug.h" #include "debug.h"
#include "error.h" #include "error.h"
#include "util.h"
#include "benode.h" #include "benode.h"
#include "beirg.h" #include "beirg.h"
...@@ -1731,7 +1732,7 @@ static ir_node *gen_Start(ir_node *node) ...@@ -1731,7 +1732,7 @@ static ir_node *gen_Start(ir_node *node)
be_prolog_add_reg(abihelper, param->reg1, arch_register_req_type_none); be_prolog_add_reg(abihelper, param->reg1, arch_register_req_type_none);
} }
/* announce that we need the values of the callee save regs */ /* announce that we need the values of the callee save regs */
for (i = 0; i < (sizeof(callee_saves)/sizeof(callee_saves[0])); ++i) { for (i = 0; i != ARRAY_SIZE(callee_saves); ++i) {
be_prolog_add_reg(abihelper, callee_saves[i], arch_register_req_type_none); be_prolog_add_reg(abihelper, callee_saves[i], arch_register_req_type_none);
} }
...@@ -1771,11 +1772,11 @@ static ir_node *gen_Return(ir_node *node) ...@@ -1771,11 +1772,11 @@ static ir_node *gen_Return(ir_node *node)
dbg_info *dbgi = get_irn_dbg_info(node); dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *mem = get_Return_mem(node); ir_node *mem = get_Return_mem(node);
ir_node *new_mem = be_transform_node(mem); ir_node *new_mem = be_transform_node(mem);
int n_callee_saves = sizeof(callee_saves)/sizeof(callee_saves[0]); size_t n_callee_saves = ARRAY_SIZE(callee_saves);
ir_node *sp_proj = get_stack_pointer_for(node); ir_node *sp_proj = get_stack_pointer_for(node);
int n_res = get_Return_n_ress(node); size_t n_res = get_Return_n_ress(node);
ir_node *bereturn; ir_node *bereturn;
int i; size_t i;
be_epilog_begin(abihelper); be_epilog_begin(abihelper);
be_epilog_set_memory(abihelper, new_mem); be_epilog_set_memory(abihelper, new_mem);
...@@ -1820,25 +1821,24 @@ static ir_node *gen_Call(ir_node *node) ...@@ -1820,25 +1821,24 @@ static ir_node *gen_Call(ir_node *node)
ir_type *type = get_Call_type(node); ir_type *type = get_Call_type(node);
calling_convention_t *cconv = arm_decide_calling_convention(NULL, type); calling_convention_t *cconv = arm_decide_calling_convention(NULL, type);
size_t n_params = get_Call_n_params(node); size_t n_params = get_Call_n_params(node);
size_t n_param_regs = cconv->n_reg_params; size_t const n_param_regs = cconv->n_reg_params;
/* max inputs: memory, callee, register arguments */ /* max inputs: memory, callee, register arguments */
int max_inputs = 2 + n_param_regs; size_t const max_inputs = 2 + n_param_regs;
ir_node **in = ALLOCAN(ir_node*, max_inputs); ir_node **in = ALLOCAN(ir_node*, max_inputs);
ir_node **sync_ins = ALLOCAN(ir_node*, max_inputs); ir_node **sync_ins = ALLOCAN(ir_node*, max_inputs);
struct obstack *obst = be_get_be_obst(irg); struct obstack *obst = be_get_be_obst(irg);
const arch_register_req_t **in_req const arch_register_req_t **in_req
= OALLOCNZ(obst, const arch_register_req_t*, max_inputs); = OALLOCNZ(obst, const arch_register_req_t*, max_inputs);
int in_arity = 0; size_t in_arity = 0;
int sync_arity = 0; size_t sync_arity = 0;
int n_caller_saves size_t const n_caller_saves = ARRAY_SIZE(caller_saves);
= sizeof(caller_saves)/sizeof(caller_saves[0]); ir_entity *entity = NULL;
ir_entity *entity = NULL; ir_node *incsp = NULL;
ir_node *incsp = NULL;
int mem_pos; int mem_pos;
ir_node *res; ir_node *res;
size_t p; size_t p;
int o; size_t o;
int out_arity; size_t out_arity;
assert(n_params == get_method_n_params(type)); assert(n_params == get_method_n_params(type));
......
...@@ -624,7 +624,7 @@ ir_node *be_new_IncSP(const arch_register_t *sp, ir_node *bl, ...@@ -624,7 +624,7 @@ ir_node *be_new_IncSP(const arch_register_t *sp, ir_node *bl,
in[0] = old_sp; in[0] = old_sp;
irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode,
sizeof(in) / sizeof(in[0]), in); ARRAY_SIZE(in), in);
init_node_attr(irn, 1, 1); init_node_attr(irn, 1, 1);
a = (be_incsp_attr_t*)get_irn_generic_attr(irn); a = (be_incsp_attr_t*)get_irn_generic_attr(irn);
a->offset = offset; a->offset = offset;
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "iredges_t.h" #include "iredges_t.h"
#include "debug.h" #include "debug.h"
#include "error.h" #include "error.h"
#include "util.h"
#ifdef _WIN32 #ifdef _WIN32
/* Break into the debugger. The Win32 way. */ /* Break into the debugger. The Win32 way. */
...@@ -968,7 +969,7 @@ static char next_char(void) ...@@ -968,7 +969,7 @@ static char next_char(void)
static unsigned get_token(void) static unsigned get_token(void)
{ {
char c; char c;
int i; size_t i;
/* skip white space */ /* skip white space */
do { do {
...@@ -992,7 +993,7 @@ static unsigned get_token(void) ...@@ -992,7 +993,7 @@ static unsigned get_token(void)
++tok_start; ++tok_start;
--len; --len;
} }
for (i = sizeof(reserved)/sizeof(reserved[0]) - 1; i >= 0; --i) { for (i = ARRAY_SIZE(reserved); i-- != 0;) {
if (strncasecmp(tok_start, reserved[i], len) == 0 && reserved[i][len] == '\0') if (strncasecmp(tok_start, reserved[i], len) == 0 && reserved[i][len] == '\0')
return 256 + i; return 256 + i;
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "irloop_t.h" #include "irloop_t.h"
#include "tv_t.h" #include "tv_t.h"
#include "dbginfo_t.h" #include "dbginfo_t.h"
#include "util.h"
/** /**
* identify a firm object type * identify a firm object type
...@@ -332,7 +333,7 @@ lc_arg_env_t *firm_get_arg_env(void) ...@@ -332,7 +333,7 @@ lc_arg_env_t *firm_get_arg_env(void)
lc_arg_add_std(env); lc_arg_add_std(env);
lc_arg_register(env, "firm", 'F', &firm_handler); lc_arg_register(env, "firm", 'F', &firm_handler);
for (i = 0; i < sizeof(args)/sizeof(args[0]); ++i) for (i = 0; i != ARRAY_SIZE(args); ++i)
lc_arg_register(env, args[i].name, args[i].letter, &firm_handler); lc_arg_register(env, args[i].name, args[i].letter, &firm_handler);
lc_arg_register(env, "firm:ident", 'I', &ident_handler); lc_arg_register(env, "firm:ident", 'I', &ident_handler);
......
...@@ -323,7 +323,7 @@ static graph_entry_t *graph_get_entry(ir_graph *irg, hmap_graph_entry_t *hmap) ...@@ -323,7 +323,7 @@ static graph_entry_t *graph_get_entry(ir_graph *irg, hmap_graph_entry_t *hmap)
elem->block_hash = NULL; elem->block_hash = NULL;
elem->extbb_hash = NULL; elem->extbb_hash = NULL;
for (i = 0; i < sizeof(elem->opt_hash)/sizeof(elem->opt_hash[0]); ++i) for (i = 0; i != ARRAY_SIZE(elem->opt_hash); ++i)
elem->opt_hash[i] = new_pset(opt_cmp, 4); elem->opt_hash[i] = new_pset(opt_cmp, 4);
return (graph_entry_t*)pset_insert(hmap, elem, HASH_PTR(irg)); return (graph_entry_t*)pset_insert(hmap, elem, HASH_PTR(irg));
......
...@@ -558,7 +558,7 @@ static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry) ...@@ -558,7 +558,7 @@ static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry)
simple_dump_real_func_calls(dmp, &entry->cnt[gcnt_acc_real_func_call]); simple_dump_real_func_calls(dmp, &entry->cnt[gcnt_acc_real_func_call]);
simple_dump_tail_recursion(dmp, entry->num_tail_recursion); simple_dump_tail_recursion(dmp, entry->num_tail_recursion);
for (i = 0; i < sizeof(entry->opt_hash)/sizeof(entry->opt_hash[0]); ++i) { for (i = 0; i != ARRAY_SIZE(entry->opt_hash); ++i) {
simple_dump_opt_hash(dmp, entry->opt_hash[i], i); simple_dump_opt_hash(dmp, entry->opt_hash[i], i);
} /* for */ } /* for */
......
...@@ -636,7 +636,7 @@ ir_tarval *get_tarval_all_one(ir_mode *mode) ...@@ -636,7 +636,7 @@ ir_tarval *get_tarval_all_one(ir_mode *mode)
int tarval_is_constant(ir_tarval *tv) int tarval_is_constant(ir_tarval *tv)
{ {
int num_res = sizeof(reserved_tv) / sizeof(reserved_tv[0]); size_t const num_res = ARRAY_SIZE(reserved_tv);
/* reserved tarvals are NOT constants. Note that although /* reserved tarvals are NOT constants. Note that although
tarval_b_true and tarval_b_false are reserved, they are constants of course. */ tarval_b_true and tarval_b_false are reserved, they are constants of course. */
......
Markdown is supported
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