Commit 6cd6e689 authored by Matthias Braun's avatar Matthias Braun
Browse files

make modelist global

It was a member of ir_prog before but not correctly handled.
parent 789a7c70
......@@ -29,6 +29,8 @@
#include "firm_types.h"
#include "begin.h"
#include <stddef.h>
/**
* @defgroup ir_mode Value Modes
* This module specifies the modes that type the firm nodes. It defines
......@@ -426,6 +428,12 @@ FIRM_API int is_reinterpret_cast(const ir_mode *src, const ir_mode *dst);
*/
FIRM_API ir_type *get_type_for_mode(const ir_mode *mode);
/** Returns number of known modes. */
FIRM_API size_t ir_get_n_modes(void);
/** Returns known mode number @p num. */
FIRM_API ir_mode *ir_get_mode(size_t num);
/** @} */
#include "end.h"
......
......@@ -230,12 +230,6 @@ FIRM_API ir_type *get_irp_type(size_t pos);
*/
FIRM_API void set_irp_type(size_t pos, ir_type *typ);
/** Returns the number of all modes in the irp. */
FIRM_API size_t get_irp_n_modes(void);
/** Returns the mode at position pos in the irp. */
FIRM_API ir_mode *get_irp_mode(size_t pos);
/** Returns the graph for global constants of the current irp.
*
* Returns an irgraph that only contains constant expressions for
......
......@@ -1410,8 +1410,8 @@ static void set_tarval_output_modes(void)
{
size_t i;
for (i = get_irp_n_modes(); i > 0;) {
ir_mode *mode = get_irp_mode(--i);
for (i = ir_get_n_modes(); i > 0;) {
ir_mode *mode = ir_get_mode(--i);
if (mode_is_int(mode))
set_tarval_mode_output_option(mode, &mo_integer);
......
......@@ -1074,13 +1074,14 @@ static void write_mode(write_env_t *env, ir_mode *mode)
static void write_modes(write_env_t *env)
{
size_t i, n_modes = get_irp_n_modes();
size_t n_modes = ir_get_n_modes();
size_t i;
write_symbol(env, "modes");
fputs("{\n", env->file);
for (i = 0; i < n_modes; i++) {
ir_mode *mode = get_irp_mode(i);
ir_mode *mode = ir_get_mode(i);
if (!mode_is_int(mode) && !mode_is_reference(mode)
&& !mode_is_float(mode)) {
/* skip internal modes */
......@@ -1548,11 +1549,11 @@ static ir_entity *read_entity_ref(read_env_t *env)
static ir_mode *read_mode_ref(read_env_t *env)
{
char *str = read_string(env);
size_t n = get_irp_n_modes();
size_t n = ir_get_n_modes();
size_t i;
for (i = 0; i < n; i++) {
ir_mode *mode = get_irp_mode(i);
ir_mode *mode = ir_get_mode(i);
if (strcmp(str, get_mode_name(mode)) == 0) {
obstack_free(&env->obst, str);
return mode;
......
......@@ -223,7 +223,6 @@ static ir_mode *register_mode(ir_mode *mode)
mode->kind = k_ir_mode;
mode->type = new_type_primitive(mode);
ARR_APP1(ir_mode*, mode_list, mode);
add_irp_mode(mode);
set_mode_values(mode);
hook_new_mode(mode);
return mode;
......@@ -676,6 +675,17 @@ ir_type *(get_type_for_mode) (const ir_mode *mode)
return get_type_for_mode_(mode);
}
size_t ir_get_n_modes(void)
{
return ARR_LEN(mode_list);
}
ir_mode *ir_get_mode(size_t num)
{
assert(num < ARR_LEN(mode_list));
return mode_list[num];
}
void finish_mode(void)
{
obstack_free(&modes, 0);
......
......@@ -57,7 +57,6 @@ static ir_prog *new_incomplete_ir_prog(void)
res->kind = k_ir_prog;
res->graphs = NEW_ARR_F(ir_graph *, 0);
res->types = NEW_ARR_F(ir_type *, 0);
res->modes = NEW_ARR_F(ir_mode *, 0);
res->global_asms = NEW_ARR_F(ident *, 0);
res->last_label_nr = 1; /* 0 is reserved as non-label */
res->max_irg_idx = 0;
......@@ -148,7 +147,6 @@ void free_ir_prog(void)
DEL_ARR_F(irp->graphs);
DEL_ARR_F(irp->types);
DEL_ARR_F(irp->modes);
DEL_ARR_F(irp->global_asms);
......@@ -285,23 +283,6 @@ void set_irp_type(size_t pos, ir_type *typ)
irp->types[pos] = typ;
}
size_t (get_irp_n_modes)(void)
{
return get_irp_n_modes_();
}
ir_mode *(get_irp_mode)(size_t pos)
{
return get_irp_mode_(pos);
}
void add_irp_mode(ir_mode *mode)
{
assert(mode != NULL);
assert(irp);
ARR_APP1(ir_mode *, irp->modes, mode);
}
void set_irp_prog_name(ident *name)
{
irp->name = name;
......
......@@ -35,9 +35,6 @@
#include "array.h"
/** Adds mode to the list of modes in irp. */
void add_irp_mode(ir_mode *mode);
/* inline functions */
static inline ir_type *get_segment_type_(ir_segment_t segment)
{
......@@ -81,18 +78,6 @@ static inline ir_type *get_irp_type_(size_t pos)
return irp->types[pos];
}
static inline size_t get_irp_n_modes_(void)
{
assert(irp->modes);
return ARR_LEN(irp->modes);
}
static inline ir_mode *get_irp_mode_(size_t pos)
{
assert(irp && irp->modes);
return irp->modes[pos];
}
/** Returns a new, unique number to number nodes or the like. */
static inline long get_irp_new_node_nr(void)
{
......@@ -153,8 +138,6 @@ void remove_irp_type(ir_type *typ);
#define get_irp_irg(pos) get_irp_irg_(pos)
#define get_irp_n_types() get_irp_n_types_()
#define get_irp_type(pos) get_irp_type_(pos)
#define get_irp_n_modes() get_irp_n_modes_()
#define get_irp_mode(pos) get_irp_mode_(pos)
#define get_const_code_irg() get_const_code_irg_()
#define get_segment_type(s) get_segment_type_(s)
#define get_glob_type() get_glob_type_()
......
......@@ -629,7 +629,6 @@ struct ir_prog {
ir_type *none_type; /**< unique 'none'-type */
ir_type *code_type; /**< unique 'code'-type */
ir_type *unknown_type; /**< unique 'unknown'-type */
ir_mode **modes; /**< A list of all modes in the ir. */
ident **global_asms; /**< An array of global ASM insertions. */
/* -- states of and access to generated information -- */
......
......@@ -2698,14 +2698,14 @@ static void setup_modes(void)
unsigned size_bits = env->params->doubleword_size;
ir_mode *doubleword_signed = NULL;
ir_mode *doubleword_unsigned = NULL;
size_t n_modes = get_irp_n_modes();
size_t n_modes = ir_get_n_modes();
ir_mode_arithmetic arithmetic;
unsigned modulo_shift;
size_t i;
/* search for doubleword modes... */
for (i = 0; i < n_modes; ++i) {
ir_mode *mode = get_irp_mode(i);
ir_mode *mode = ir_get_mode(i);
if (!mode_is_int(mode))
continue;
if (get_mode_size_bits(mode) != size_bits)
......
......@@ -397,10 +397,10 @@ static int addr_cmp(const void *p1, const void *p2, size_t size)
*/
static size_t find_mode_index(const ir_mode *mode)
{
size_t i, n = get_irp_n_modes();
size_t i, n = ir_get_n_modes();
for (i = 0; i < n; ++i) {
if (get_irp_mode(i) == mode)
if (ir_get_mode(i) == mode)
return i;
}
/* should really not happen */
......
......@@ -147,7 +147,7 @@ static void vcg_dump_node(pattern_dumper_t *self, unsigned id,
{
vcg_private_t *priv = (vcg_private_t*)self->data;
ir_op *op = stat_get_op_from_opcode(op_code);
ir_mode *mode = get_irp_mode(mode_code);
ir_mode *mode = ir_get_mode(mode_code);
long l = attr ? *(long *)attr : 0;
if (priv->pattern_id > priv->max_pattern)
......@@ -224,7 +224,7 @@ static void stdout_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_co
{
FILE *f = (FILE*)self->data;
ir_op *op = stat_get_op_from_opcode(op_code);
ir_mode *mode = get_irp_mode(mode_code);
ir_mode *mode = ir_get_mode(mode_code);
(void) attr;
/* if (env->options & OPT_ENC_GRAPH) */
......
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