Commit 68a65bfe authored by Matthias Braun's avatar Matthias Braun
Browse files

cleanup and fix some bugs in ir reader/writer

[r26956]
parent cc9831d8
......@@ -83,11 +83,11 @@ static inline unsigned hash_ptr(const void *ptr)
static inline unsigned _hash_combine(unsigned x, unsigned y)
{
unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS);
hash ^= x;
hash = _FIRM_FNV_TIMES_PRIME(hash);
hash ^= y;
return hash;
unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS);
hash ^= x;
hash = _FIRM_FNV_TIMES_PRIME(hash);
hash ^= y;
return hash;
}
#ifdef _MSC_VER
......
......@@ -22,6 +22,9 @@
* @brief Import/export textual representation of firm.
* @author Moritz Kroll
* @version $Id$
*
* Note: The file format is not considered stable yet. So expect
* incompatibilities between file formats of different libfirm versions.
*/
#ifndef FIRM_IR_IRIO_H
#define FIRM_IR_IRIO_H
......@@ -39,6 +42,11 @@
*/
void ir_export(const char *filename);
/**
* same as ir_export but writes to a FILE*
*/
void ir_export_file(FILE *output, const char *outputname);
/**
* Exports the given ir graph to the given file in a textual form.
*
......@@ -47,7 +55,7 @@ void ir_export(const char *filename);
*
* Exports the type graph used by the given graph and the graph itself.
*/
void ir_export_irg(ir_graph *irg, const char *filename);
void ir_export_irg(ir_graph *irg, FILE *output, const char *outputname);
/**
* Imports the data stored in the given file.
......@@ -58,4 +66,9 @@ void ir_export_irg(ir_graph *irg, const char *filename);
*/
void ir_import(const char *filename);
/**
* same as ir_import but imports from a FILE*
*/
void ir_import_file(FILE *input, const char *inputname);
#endif
......@@ -61,7 +61,7 @@ typedef enum ir_segment_t {
/** like constructors, but functions are executed on module exit */
IR_SEGMENT_DESTRUCTORS,
IR_SEGMENT_COUNT
IR_SEGMENT_LAST = IR_SEGMENT_DESTRUCTORS
} ir_segment_t;
/**
......@@ -159,6 +159,12 @@ ir_graph *get_irp_allirg(int pos);
*/
ir_type *get_segment_type(ir_segment_t segment);
/**
* @brief Changes a segment segment type for the program.
* (use with care)
*/
void set_segment_type(ir_segment_t segment, ir_type *new_type);
/**
* Returns the "global" type of the irp.
* Upon creation this is an empty class type.
......@@ -169,6 +175,7 @@ ir_type *get_glob_type(void);
/**
* Returns the "thread local storage" type of the irp.
* Upon creation this is an empty struct type.
* This is a convenience function for get_segment_type(IR_SEGMENT_THREAD_LOCAL)
*/
ir_type *get_tls_type(void);
......@@ -179,13 +186,22 @@ void add_irp_type(ir_type *typ);
shrinks the list by one. */
void remove_irp_type(ir_type *typ);
/** Returns the number of all types in the irp. */
/**
* Returns the number of all types in the irp.
* @deprecated
*/
int get_irp_n_types(void);
/** Returns the type at position pos in the irp. */
/**
* Returns the type at position pos in the irp.
* @deprecated
*/
ir_type *get_irp_type(int pos);
/** Overwrites the type at position pos with another type. */
/**
* Overwrites the type at position pos with another type.
* @deprecated
*/
void set_irp_type(int pos, ir_type *typ);
/** Returns the number of all modes in the irp. */
......
......@@ -1201,12 +1201,12 @@ static void analyse_irp_globals_entity_usage(void) {
int i;
ir_segment_t s;
for (s = IR_SEGMENT_FIRST; s < IR_SEGMENT_COUNT; ++s) {
for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
ir_type *type = get_segment_type(s);
init_entity_usage(type);
}
for (s = IR_SEGMENT_FIRST; s < IR_SEGMENT_COUNT; ++s) {
for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
ir_type *type = get_segment_type(s);
check_initializers(type);
}
......@@ -1221,7 +1221,7 @@ static void analyse_irp_globals_entity_usage(void) {
#ifdef DEBUG_libfirm
if (firm_dbg_get_mask(dbg) & LEVEL_1) {
ir_segment_t s;
for (s = IR_SEGMENT_FIRST; s < IR_SEGMENT_COUNT; ++s) {
for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
print_entity_usage_flags(get_segment_type(s));
}
}
......
......@@ -716,6 +716,7 @@ static void walk_entity(ir_entity *ent, void *env)
void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) {
int i, j, n_types;
walk_env my_env;
ir_segment_t s;
ir_graph *rem = current_ir_graph;
current_ir_graph = get_const_code_irg();
......@@ -726,8 +727,8 @@ void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) {
my_env.env = env;
/* Walk all types that can contain constant entities. */
for (i = 0; i < IR_SEGMENT_COUNT; i++)
walk_types_entities(get_segment_type((ir_segment_t) i), &walk_entity, &my_env);
for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; s++)
walk_types_entities(get_segment_type(s), &walk_entity, &my_env);
n_types = get_irp_n_types();
for (i = 0; i < n_types; i++)
walk_types_entities(get_irp_type(i), &walk_entity, &my_env);
......
This diff is collapsed.
......@@ -76,8 +76,9 @@ static ir_prog *new_incomplete_ir_prog(void)
* @param irp the (yet incomplete) irp
* @param module_name the (module) name for this irp
*/
static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name) {
int i;
static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name)
{
ir_segment_t s;
#define IDENT(x) new_id_from_chars(x, sizeof(x) - 1)
......@@ -91,8 +92,8 @@ static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name) {
= new_type_struct(IDENT("Destructors"));
/* Remove these types from type list. Must be treated differently than
other types. */
for (i = 0; i < IR_SEGMENT_COUNT; ++i) {
remove_irp_type(irp->segment_types[i]);
for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
remove_irp_type(irp->segment_types[s]);
}
/* Set these flags for debugging. */
......@@ -135,10 +136,11 @@ ir_prog *new_ir_prog(const char *name) {
/* frees all memory used by irp. Types in type list, irgs in irg
list and entities in global type must be freed by hand before. */
void free_ir_prog(void) {
int i;
for (i = 0; i < IR_SEGMENT_COUNT; ++i) {
free_type(irp->segment_types[i]);
void free_ir_prog(void)
{
ir_segment_t s;
for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
free_type(irp->segment_types[s]);
}
free_ir_graph(irp->const_code_irg);
......@@ -170,10 +172,19 @@ void set_irp_main_irg(ir_graph *main_irg) {
irp->main_irg = main_irg;
}
ir_type *(get_segment_type)(ir_segment_t segment) {
ir_type *(get_segment_type)(ir_segment_t segment)
{
return _get_segment_type(segment);
}
void set_segment_type(ir_segment_t segment, ir_type *new_type)
{
assert(segment <= IR_SEGMENT_LAST);
irp->segment_types[segment] = new_type;
/* segment types are not in the type list... */
remove_irp_type(new_type);
}
ir_type *(get_glob_type)(void) {
return _get_glob_type();
}
......
......@@ -47,12 +47,8 @@ void add_irp_mode(ir_mode *mode);
static inline ir_type *
_get_segment_type(ir_segment_t segment)
{
ir_type *type;
assert(segment < IR_SEGMENT_COUNT);
type = irp->segment_types[segment];
irp->segment_types[segment] = type;
return type;
assert(segment <= IR_SEGMENT_LAST);
return irp->segment_types[segment];
}
static inline ir_type *
......
......@@ -548,7 +548,7 @@ struct ir_prog {
to allocate nodes the represent values
of constant entities. It is not meant as
a procedure. */
ir_type *segment_types[IR_SEGMENT_COUNT];
ir_type *segment_types[IR_SEGMENT_LAST+1];
ir_type **types; /**< A list of all types in the ir. */
ir_mode **modes; /**< A list of all modes in the ir. */
ir_op **opcodes; /**< A list of all opcodes in the ir. */
......
......@@ -771,6 +771,8 @@ ident *get_class_ident(const ir_type *clss)
const char *get_class_name(const ir_type *clss)
{
if (get_class_ident(clss) == NULL)
return NULL;
return get_id_str(get_class_ident(clss));
}
......@@ -778,7 +780,6 @@ void add_class_member(ir_type *clss, ir_entity *member)
{
assert(clss && (clss->type_op == type_class));
assert(clss != get_entity_type(member) && "recursive type");
assert(get_type_state(clss) != layout_fixed);
ARR_APP1 (ir_entity *, clss->attr.ca.members, member);
}
......@@ -1100,6 +1101,8 @@ ident *get_struct_ident(const ir_type *strct)
const char *get_struct_name(const ir_type *strct)
{
if (get_struct_ident(strct) == NULL)
return NULL;
return get_id_str(get_struct_ident(strct));
}
......@@ -1114,7 +1117,6 @@ void add_struct_member(ir_type *strct, ir_entity *member)
assert(strct && (strct->type_op == type_struct));
assert(get_type_tpop(get_entity_type(member)) != type_method);
assert(strct != get_entity_type(member) && "recursive type");
assert(get_type_state(strct) != layout_fixed);
ARR_APP1 (ir_entity *, strct->attr.sa.members, member);
}
......@@ -1566,6 +1568,8 @@ ident *get_union_ident(const ir_type *uni)
const char *get_union_name(const ir_type *uni)
{
if (get_union_ident(uni) == NULL)
return NULL;
return get_id_str(get_union_ident(uni));
}
......@@ -1579,7 +1583,6 @@ void add_union_member(ir_type *uni, ir_entity *member)
{
assert(uni && (uni->type_op == type_union));
assert(uni != get_entity_type(member) && "recursive type");
assert(get_type_state(uni) != layout_fixed);
ARR_APP1(ir_entity *, uni->attr.ua.members, member);
}
......@@ -1894,6 +1897,8 @@ ident *get_enumeration_ident(const ir_type *enumeration)
const char *get_enumeration_name(const ir_type *enumeration)
{
if (get_enumeration_ident(enumeration) == NULL)
return NULL;
return get_id_str(get_enumeration_ident(enumeration));
}
......@@ -2145,6 +2150,8 @@ ident *get_compound_ident(const ir_type *tp)
const char *get_compound_name(const ir_type *tp)
{
if (get_compound_ident(tp) == NULL)
return NULL;
return get_id_str(get_compound_ident(tp));
}
......
......@@ -102,11 +102,13 @@ static void do_type_walk(type_or_ent tore,
ent = tore.ent;
if (entity_visited(ent))
return;
mark_entity_visited(ent);
break;
case k_type:
tp = tore.typ;
if (type_visited(tp))
return;
mark_type_visited(tp);
break;
default:
break;
......@@ -119,7 +121,6 @@ static void do_type_walk(type_or_ent tore,
/* iterate */
switch (get_kind(tore.ent)) {
case k_entity:
mark_entity_visited(ent);
cont.typ = get_entity_owner(ent);
do_type_walk(cont, pre, post, env);
cont.typ = get_entity_type(ent);
......@@ -142,7 +143,6 @@ static void do_type_walk(type_or_ent tore,
}
break;
case k_type:
mark_type_visited(tp);
switch (get_type_tpop_code(tp)) {
case tpo_class:
n_types = get_class_n_supertypes(tp);
......@@ -291,7 +291,7 @@ void type_walk_prog(type_walk_func *pre, type_walk_func *post, void *env) {
do_type_walk(cont, pre, post, env);
}
for (i = 0; i < IR_SEGMENT_COUNT; ++i) {
for (i = IR_SEGMENT_FIRST; i <= IR_SEGMENT_LAST; ++i) {
cont.typ = get_segment_type((ir_segment_t) i);
if(cont.typ)
do_type_walk(cont, pre, post, env);
......
......@@ -240,7 +240,7 @@ def main(argv):
for node in real_nodes:
if node.name in niynodes:
continue
file.write("\tINSERT(\"" + node.name + "\", tt_iro, iro_" + node.name + ");\n");
file.write("\tINSERT(tt_iro, \"%s\", iro_%s);\n" % (node.name, node.name));
file.close()
main(sys.argv)
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