X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firio.c;h=56a4a5c09f05fc287b2cdb1a4bd3d3e6bef38994;hb=41eca21e7add2e4f30f14c46600a23839852b3fc;hp=81a896896803543db44a2031d30aebc9c367a729;hpb=25d8d92be55cf80b6282347048063dfe5434980c;p=libfirm diff --git a/ir/ir/irio.c b/ir/ir/irio.c index 81a896896..56a4a5c09 100644 --- a/ir/ir/irio.c +++ b/ir/ir/irio.c @@ -126,7 +126,7 @@ static int symbol_cmp(const void *elt, const void *key, size_t size) const symbol_t *keyentry = (const symbol_t *) key; (void) size; res = entry->typetag - keyentry->typetag; - if(res) return res; + if (res) return res; return strcmp(entry->str, keyentry->str); } @@ -144,7 +144,7 @@ static void symtbl_init(void) symbol_t key; /* Only initialize once */ - if(symtbl != NULL) + if (symtbl != NULL) return; symtbl = new_set(symbol_cmp, 256); @@ -299,9 +299,12 @@ static void write_align(io_env_t *env, ir_node *irn) { ir_align align; - if(is_Load(irn)) align = get_Load_align(irn); - else if(is_Store(irn)) align = get_Store_align(irn); - else assert(0 && "Invalid optype for write_align"); + if (is_Load(irn)) + align = get_Load_align(irn); + else if (is_Store(irn)) + align = get_Store_align(irn); + else + panic("Invalid optype for write_align"); fputs(get_align_name(align), env->file); fputc(' ', env->file); @@ -333,7 +336,7 @@ static void write_initializer(io_env_t *env, ir_initializer_t *ini) fputs(get_initializer_kind_name(ini_kind), f); fputc(' ', f); - switch(ini_kind) + switch (ini_kind) { case IR_INITIALIZER_CONST: fprintf(f, "%ld ", get_irn_node_nr(get_initializer_const_value(ini))); @@ -350,7 +353,7 @@ static void write_initializer(io_env_t *env, ir_initializer_t *ini) { unsigned i, n = get_initializer_compound_n_entries(ini); fprintf(f, "%d ", n); - for(i = 0; i < n; i++) + for (i = 0; i < n; i++) write_initializer(env, get_initializer_compound_value(ini, i)); break; } @@ -370,9 +373,12 @@ static void write_volatility(io_env_t *env, ir_node *irn) { ir_volatility vol; - if(is_Load(irn)) vol = get_Load_volatility(irn); - else if(is_Store(irn)) vol = get_Store_volatility(irn); - else assert(0 && "Invalid optype for write_volatility"); + if (is_Load(irn)) + vol = get_Load_volatility(irn); + else if (is_Store(irn)) + vol = get_Store_volatility(irn); + else + panic("Invalid optype for write_volatility"); fputs(get_volatility_name(vol), env->file); fputc(' ', env->file); @@ -394,10 +400,9 @@ static void export_type_common(io_env_t *env, ir_type *tp) static void export_type_pre(io_env_t *env, ir_type *tp) { FILE *f = env->file; - int i; - // skip types to be handled by post walker - switch(get_type_tpop_code(tp)) + /* skip types to be handled by post walker */ + switch (get_type_tpop_code(tp)) { case tpo_array: case tpo_method: @@ -407,7 +412,7 @@ static void export_type_pre(io_env_t *env, ir_type *tp) export_type_common(env, tp); - switch(get_type_tpop_code(tp)) + switch (get_type_tpop_code(tp)) { case tpo_class: /* TODO: inheritance stuff not supported yet */ @@ -437,10 +442,10 @@ static void export_type_pre(io_env_t *env, ir_type *tp) static void export_type_post(io_env_t *env, ir_type *tp) { FILE *f = env->file; - int i; + int i, n, nparams, nresults; - // skip types already handled by pre walker - switch(get_type_tpop_code(tp)) + /* skip types already handled by pre walker */ + switch (get_type_tpop_code(tp)) { case tpo_class: case tpo_primitive: @@ -452,40 +457,40 @@ static void export_type_post(io_env_t *env, ir_type *tp) export_type_common(env, tp); - switch(get_type_tpop_code(tp)) + switch (get_type_tpop_code(tp)) { case tpo_array: - { - int n = get_array_n_dimensions(tp); + n = get_array_n_dimensions(tp); fprintf(f, "%i %ld ", n, get_type_nr(get_array_element_type(tp))); - for(i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { ir_node *lower = get_array_lower_bound(tp, i); ir_node *upper = get_array_upper_bound(tp, i); - if(is_Const(lower)) fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(lower))); - else panic("Lower array bound is not constant"); - - if(is_Const(upper)) fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(upper))); - else if(is_Unknown(upper)) fputs("unknown ", f); - else panic("Upper array bound is not constant"); + if (is_Const(lower)) + fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(lower))); + else + panic("Lower array bound is not constant"); + + if (is_Const(upper)) + fprintf(f, "%ld ", get_tarval_long(get_Const_tarval(upper))); + else if (is_Unknown(upper)) + fputs("unknown ", f); + else + panic("Upper array bound is not constant"); } break; - } case tpo_method: - { - int nparams = get_method_n_params(tp); - int nresults = get_method_n_ress(tp); + nparams = get_method_n_params(tp); + nresults = get_method_n_ress(tp); fprintf(f, "0x%X 0x%X %i %i ", get_method_calling_convention(tp), get_method_additional_properties(tp), nparams, nresults); - for(i = 0; i < nparams; i++) + for (i = 0; i < nparams; i++) fprintf(f, "%ld ", get_type_nr(get_method_param_type(tp, i))); - for(i = 0; i < nresults; i++) + for (i = 0; i < nresults; i++) fprintf(f, "%ld ", get_type_nr(get_method_res_type(tp, i))); fprintf(f, "%d ", get_method_first_variadic_param_index(tp)); break; - } case tpo_pointer: write_mode(env, get_type_mode(tp)); @@ -516,35 +521,28 @@ static void export_entity(io_env_t *env, ir_entity *ent) get_peculiarity_name(get_entity_peculiarity(ent)), get_volatility_name(get_entity_volatility(ent))); - // TODO: inheritance stuff for class entities not supported yet - if(is_Class_type(owner) && owner != get_glob_type()) + /* TODO: inheritance stuff for class entities not supported yet */ + if (is_Class_type(owner) && owner != get_glob_type()) printf("Inheritance of class entities not supported yet!\n"); - if(get_entity_variability(ent) != variability_uninitialized - && get_entity_visibility(ent) != visibility_external_allocated) + if (get_entity_variability(ent) != variability_uninitialized && + get_entity_visibility(ent) != visibility_external_allocated) { - if(is_compound_entity(ent)) - { - if(has_entity_initializer(ent)) - { + if (is_compound_entity(ent)) { + if (has_entity_initializer(ent)) { fputs("initializer ", env->file); write_initializer(env, get_entity_initializer(ent)); - } - else - { + } else { int i, n = get_compound_ent_n_values(ent); fputs("noninitializer ", env->file); fprintf(env->file, "%d ", n); - for(i = 0; i < n; i++) - { + 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); fprintf(env->file, "%ld %ld ", get_entity_nr(member), get_irn_node_nr(irn)); } } - } - else - { + } else { ir_node *irn = get_atomic_ent_value(ent); fprintf(env->file, "%ld ", get_irn_node_nr(irn)); } @@ -556,7 +554,7 @@ static void export_entity(io_env_t *env, ir_entity *ent) static void export_type_or_ent_pre(type_or_ent tore, void *ctx) { io_env_t *env = (io_env_t *) ctx; - if(get_kind(tore.typ) == k_type) + if (get_kind(tore.typ) == k_type) export_type_pre(env, tore.typ); } @@ -564,7 +562,7 @@ static void export_type_or_ent_post(type_or_ent tore, void *ctx) { io_env_t *env = (io_env_t *) ctx; - switch(get_kind(tore.ent)) + switch (get_kind(tore.ent)) { case k_entity: export_entity(env, tore.ent); @@ -575,7 +573,7 @@ static void export_type_or_ent_post(type_or_ent tore, void *ctx) break; default: - printf("export_type_or_ent_post: Unknown type or entity.\n"); + panic("export_type_or_ent_post: Unknown type or entity."); break; } } @@ -586,17 +584,16 @@ static void export_node(ir_node *irn, void *ctx) int i, n; unsigned opcode = get_irn_opcode(irn); - if(env->ignoreblocks && opcode == iro_Block) + if (env->ignoreblocks && opcode == iro_Block) return; n = get_irn_arity(irn); fprintf(env->file, "\t%s %ld [ ", get_irn_opname(irn), get_irn_node_nr(irn)); - for(i = -1; i < n; i++) - { + for (i = -1; i < n; i++) { ir_node *pred = get_irn_n(irn, i); - if(pred == NULL) { + if (pred == NULL) { /* Anchor node may have NULL predecessors */ assert(is_Anchor(irn)); fputs("-1 ", env->file); @@ -607,7 +604,7 @@ static void export_node(ir_node *irn, void *ctx) fprintf(env->file, "] { "); - switch(opcode) + switch (opcode) { #include "gen_irio_export.inl" } @@ -620,16 +617,15 @@ static void export_modes(io_env_t *env) fputs("modes {\n", env->file); - for(i = 0; i < n_modes; i++) - { + for (i = 0; i < n_modes; i++) { ir_mode *mode = get_irp_mode(i); - switch(get_mode_sort(mode)) + switch (get_mode_sort(mode)) { case irms_auxiliary: case irms_control_flow: case irms_memory: case irms_internal_boolean: - // skip "internal" modes, which may not be user defined + /* skip "internal" modes, which may not be user defined */ continue; } @@ -637,8 +633,7 @@ static void export_modes(io_env_t *env) get_mode_sort(mode), get_mode_size_bits(mode), get_mode_sign(mode), get_mode_arithmetic_name(get_mode_arithmetic(mode)), get_mode_modulo_shift(mode), get_mode_n_vector_elems(mode)); - if(mode_is_reference(mode)) - { + if (mode_is_reference(mode)) { write_mode(env, get_reference_mode_signed_eq(mode)); write_mode(env, get_reference_mode_unsigned_eq(mode)); } @@ -655,8 +650,7 @@ void ir_export(const char *filename) int i, n_irgs = get_irp_n_irgs(); env.file = fopen(filename, "wt"); - if(!env.file) - { + if (!env.file) { perror(filename); return; } @@ -668,8 +662,7 @@ void ir_export(const char *filename) type_walk_plus_frames(export_type_or_ent_pre, export_type_or_ent_post, &env); /* TODO: Visit frame types and "types for value params"? */ - for(i = 0; i < n_irgs; i++) - { + for (i = 0; i < n_irgs; i++) { ir_graph *irg = get_irp_irg(i); ir_type *valuetype = get_irg_value_param_type(irg); @@ -698,8 +691,7 @@ void ir_export_irg(ir_graph *irg, const char *filename) io_env_t env; env.file = fopen(filename, "wt"); - if(!env.file) - { + if (!env.file) { perror(filename); return; } @@ -743,7 +735,7 @@ static void restore_lex_state(io_env_t *env, lex_state_t *state) static int read_c(io_env_t *env) { int ch = fgetc(env->file); - switch(ch) + switch (ch) { case '\t': env->col += 4; @@ -764,10 +756,10 @@ static int read_c(io_env_t *env) /** Returns the first non-whitespace character or EOF. **/ static int skip_ws(io_env_t *env) { - while(1) + while (1) { int ch = read_c(env); - switch(ch) + switch (ch) { case ' ': case '\t': @@ -785,42 +777,38 @@ static void skip_to(io_env_t *env, char to_ch) { int ch; do - { ch = read_c(env); - } - while(ch != to_ch && ch != EOF); + while (ch != to_ch && ch != EOF); } static int expect_char(io_env_t *env, char ch) { int curch = skip_ws(env); - if(curch != ch) - { + if (curch != ch) { printf("Unexpected char '%c', expected '%c' in line %i:%i\n", curch, ch, env->line, env->col); return 0; } return 1; } -#define EXPECT(c) if(expect_char(env, (c))) {} else return 0 -#define EXPECT_OR_EXIT(c) if(expect_char(env, (c))) {} else exit(1) +#define EXPECT(c) if (expect_char(env, (c))) {} else return 0 +#define EXPECT_OR_EXIT(c) if (expect_char(env, (c))) {} else exit(1) inline static const char *read_str_to(io_env_t *env, char *buf, size_t bufsize) { size_t i; - for(i = 0; i < bufsize - 1; i++) - { + for (i = 0; i < bufsize - 1; i++) { int ch = read_c(env); - if(ch == EOF) break; - switch(ch) + if (ch == EOF) break; + switch (ch) { case ' ': case '\t': case '\n': case '\r': - if(i != 0) + if (i != 0) goto endofword; - i--; // skip whitespace + i--; /* skip whitespace */ break; default: @@ -843,20 +831,17 @@ static const char *read_qstr_to(io_env_t *env, char *buf, size_t bufsize) { size_t i; EXPECT_OR_EXIT('\"'); - for(i = 0; i < bufsize - 1; i++) - { + for (i = 0; i < bufsize - 1; i++) { int ch = read_c(env); - if(ch == EOF) - { + if (ch == EOF) { printf("Unexpected end of quoted string!\n"); exit(1); } - if(ch == '\"') break; + if (ch == '\"') break; buf[i] = ch; } - if(i == bufsize - 1) - { + if (i == bufsize - 1) { printf("Quoted string too long!\n"); exit(1); } @@ -884,17 +869,15 @@ static long read_long(io_env_t *env) static ir_node *get_node_or_null(io_env_t *env, long nodenr) { ir_node *node = (ir_node *) get_id(env, nodenr); - if(node && node->kind != k_ir_node) - { + if (node && node->kind != k_ir_node) panic("Irn ID %ld collides with something else in line %i:%i\n", nodenr, env->line, env->col); - } return node; } static ir_node *get_node(io_env_t *env, long nodenr) { ir_node *node = get_node_or_null(env, nodenr); - if(!node) + if (!node) panic("Unknown node: %ld in line %i:%i\n", nodenr, env->line, env->col); return node; @@ -903,8 +886,7 @@ static ir_node *get_node(io_env_t *env, long nodenr) static ir_node *get_node_or_dummy(io_env_t *env, long nodenr) { ir_node *node = get_node_or_null(env, nodenr); - if(!node) - { + if (node == NULL) { node = new_Dummy(mode_X); set_id(env, nodenr, node); } @@ -914,14 +896,10 @@ static ir_node *get_node_or_dummy(io_env_t *env, long nodenr) static ir_type *get_type(io_env_t *env, long typenr) { ir_type *type = (ir_type *) get_id(env, typenr); - if(!type) - { + if (type == NULL) panic("Unknown type: %ld in line %i:%i\n", typenr, env->line, env->col); - } - else if(type->kind != k_type) - { + else if (type->kind != k_type) panic("Type ID %ld collides with something else in line %i:%i\n", typenr, env->line, env->col); - } return type; } @@ -933,15 +911,11 @@ static ir_type *read_type(io_env_t *env) static ir_entity *get_entity(io_env_t *env, long entnr) { ir_entity *entity = (ir_entity *) get_id(env, entnr); - if(!entity) - { + if (entity == NULL) { printf("Unknown entity: %ld in line %i:%i\n", entnr, env->line, env->col); exit(1); - } - else if(entity->kind != k_entity) - { + } else if (entity->kind != k_entity) panic("Entity ID %ld collides with something else in line %i:%i\n", entnr, env->line, env->col); - } return entity; } @@ -958,10 +932,9 @@ static ir_mode *read_mode(io_env_t *env) read_str_to(env, buf, sizeof(buf)); n = get_irp_n_modes(); - for(i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { ir_mode *mode = get_irp_mode(i); - if(!strcmp(buf, get_mode_name(mode))) + if (!strcmp(buf, get_mode_name(mode))) return mode; } @@ -971,7 +944,7 @@ static ir_mode *read_mode(io_env_t *env) static const char *get_typetag_name(typetag_t typetag) { - switch(typetag) + switch (typetag) { case tt_align: return "align"; case tt_allocation: return "allocation"; @@ -996,7 +969,7 @@ static unsigned read_enum(io_env_t *env, typetag_t typetag) { static char buf[128]; unsigned code = symbol(read_str_to(env, buf, sizeof(buf)), typetag); - if(code != SYMERROR) + if (code != SYMERROR) return code; printf("Invalid %s: \"%s\" in %i:%i\n", get_typetag_name(typetag), buf, env->line, env->col); @@ -1022,7 +995,7 @@ static ir_cons_flags get_cons_flags(io_env_t *env) ir_cons_flags flags = cons_none; op_pin_state pinstate = read_pin_state(env); - switch(pinstate) + switch (pinstate) { case op_pin_state_floats: flags |= cons_floats; break; case op_pin_state_pinned: break; @@ -1030,8 +1003,10 @@ static ir_cons_flags get_cons_flags(io_env_t *env) panic("Error in %i:%i: Invalid pinstate: %s", env->line, env->col, get_op_pin_state_name(pinstate)); } - if(read_volatility(env) == volatility_is_volatile) flags |= cons_volatile; - if(read_align(env) == align_non_aligned) flags |= cons_unaligned; + if (read_volatility(env) == volatility_is_volatile) + flags |= cons_volatile; + if (read_align(env) == align_non_aligned) + flags |= cons_unaligned; return flags; } @@ -1049,7 +1024,7 @@ static ir_initializer_t *read_initializer(io_env_t *env) FILE *f = env->file; ir_initializer_kind_t ini_kind = read_initializer_kind(env); - switch(ini_kind) + switch (ini_kind) { case IR_INITIALIZER_CONST: { @@ -1067,8 +1042,7 @@ static ir_initializer_t *read_initializer(io_env_t *env) { unsigned i, n = (unsigned) read_long(env); ir_initializer_t *ini = create_initializer_compound(n); - for(i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { ir_initializer_t *curini = read_initializer(env); set_initializer_compound_value(ini, i, curini); } @@ -1098,10 +1072,8 @@ static void import_type(io_env_t *env, keyword_t kwkind) const char *kindstr; - if(kwkind == kw_frametype) - { - if(symbol(tpop, tt_tpo) != tpo_class) - { + if (kwkind == kw_frametype) { + if (symbol(tpop, tt_tpo) != tpo_class) { printf("Frame type must be a class type in line %i:%i\n", env->line, env->col); skip_to(env, '\n'); return; @@ -1111,11 +1083,8 @@ static void import_type(io_env_t *env, keyword_t kwkind) set_type_size_bytes(type, size); kindstr = "frametype"; - } - else if(kwkind == kw_valuetype) - { - if(symbol(tpop, tt_tpo) != tpo_struct) - { + } else if (kwkind == kw_valuetype) { + if (symbol(tpop, tt_tpo) != tpo_struct) { printf("Value type must be a struct type in line %i:%i\n", env->line, env->col); skip_to(env, '\n'); return; @@ -1125,10 +1094,8 @@ static void import_type(io_env_t *env, keyword_t kwkind) set_type_size_bytes(type, size); kindstr = "valuetype"; - } - else - { - switch(symbol(tpop, tt_tpo)) + } else { + switch (symbol(tpop, tt_tpo)) { case tpo_array: { @@ -1137,17 +1104,14 @@ static void import_type(io_env_t *env, keyword_t kwkind) ir_type *elemtype = get_type(env, elemtypenr); type = new_type_array(id, ndims, elemtype); - for(i = 0; i < ndims; i++) - { + for (i = 0; i < ndims; i++) { const char *str = read_str(env); - if(strcmp(str, "unknown")) - { + if (strcmp(str, "unknown") != 0) { long lowerbound = strtol(str, NULL, 0); set_array_lower_bound_int(type, i, lowerbound); } str = read_str(env); - if(strcmp(str, "unknown")) - { + if (strcmp(str, "unknown") != 0) { long upperbound = strtol(str, NULL, 0); set_array_upper_bound_int(type, i, upperbound); } @@ -1171,15 +1135,13 @@ static void import_type(io_env_t *env, keyword_t kwkind) type = new_type_method(id, nparams, nresults); - for(i = 0; i < nparams; i++) - { + for (i = 0; i < nparams; i++) { long typenr = read_long(env); ir_type *paramtype = get_type(env, typenr); set_method_param_type(type, i, paramtype); } - for(i = 0; i < nresults; i++) - { + for (i = 0; i < nresults; i++) { long typenr = read_long(env); ir_type *restype = get_type(env, typenr); @@ -1187,10 +1149,9 @@ static void import_type(io_env_t *env, keyword_t kwkind) } variaindex = (int) read_long(env); - if(variaindex != -1) - { + if (variaindex != -1) { set_method_variadicity(type, variadicity_variadic); - if(variaindex != nparams) + if (variaindex != nparams) set_method_first_variadic_param_index(type, variaindex); } @@ -1225,10 +1186,10 @@ static void import_type(io_env_t *env, keyword_t kwkind) break; case tpo_unknown: - return; // ignore unknown type + return; /* ignore unknown type */ default: - if(typenr != 0) // ignore global type + if (typenr != 0) /* ignore global type */ printf("Unknown type kind: \"%s\" in line %i:%i\n", tpop, env->line, env->col); skip_to(env, '\n'); return; @@ -1239,7 +1200,7 @@ static void import_type(io_env_t *env, keyword_t kwkind) set_type_alignment_bytes(type, align); set_type_visibility(type, vis); - if(state == layout_fixed) + if (state == layout_fixed) ARR_APP1(ir_type *, env->fixedtypes, type); set_id(env, typenr, type); @@ -1260,7 +1221,8 @@ static void import_entity(io_env_t *env) ir_type *ownertype = !ownertypenr ? get_glob_type() : get_type(env, ownertypenr); ir_entity *entity = new_entity(ownertype, new_id_from_str(name), type); - if(*ld_name) set_entity_ld_ident(entity, new_id_from_str(ld_name)); + if (*ld_name) + set_entity_ld_ident(entity, new_id_from_str(ld_name)); set_entity_offset (entity, (int) read_long(env)); set_entity_offset_bits_remainder(entity, (unsigned char) read_long(env)); set_entity_allocation (entity, read_allocation(env)); @@ -1269,28 +1231,21 @@ static void import_entity(io_env_t *env) set_entity_peculiarity(entity, read_peculiarity(env)); set_entity_volatility (entity, read_volatility(env)); - if(get_entity_variability(entity) != variability_uninitialized - && get_entity_visibility(entity) != visibility_external_allocated) + if (get_entity_variability(entity) != variability_uninitialized && + get_entity_visibility(entity) != visibility_external_allocated) { - if(is_compound_entity(entity)) - { - if(!strcmp(read_str_to(env, buf2, sizeof(buf2)), "initializer")) - { + if (is_compound_entity(entity)) { + if (!strcmp(read_str_to(env, buf2, sizeof(buf2)), "initializer")) { set_entity_initializer(entity, read_initializer(env)); - } - else - { + } else { int i, n = (int) read_long(env); - for(i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { ir_entity *member = get_entity(env, read_long(env)); ir_node *irn = get_node_or_dummy(env, read_long(env)); add_compound_ent_value(entity, irn, member); } } - } - else - { + } else { ir_node *irn = get_node_or_dummy(env, read_long(env)); set_atomic_ent_value(entity, irn); } @@ -1304,6 +1259,7 @@ static void import_entity(io_env_t *env) static int parse_typegraph(io_env_t *env) { const char *kind; + keyword_t kwkind; lex_state_t oldstate; EXPECT('{'); @@ -1312,14 +1268,14 @@ static int parse_typegraph(io_env_t *env) current_ir_graph = get_const_code_irg(); - // parse all types first - while(1) - { + /* parse all types first */ + while (1) { kind = read_str(env); - if(kind[0] == '}' && !kind[1]) break; + if (kind[0] == '}' && kind[1] == '\0') + break; - keyword_t kwkind = (keyword_t) symbol(kind, tt_keyword); - switch(kwkind) + kwkind = (keyword_t) symbol(kind, tt_keyword); + switch (kwkind) { case kw_type: case kw_frametype: @@ -1333,15 +1289,15 @@ static int parse_typegraph(io_env_t *env) } } - // now parse rest + /* now parse rest */ restore_lex_state(env, &oldstate); - while(1) - { + while (1) { kind = read_str(env); - if(kind[0] == '}' && !kind[1]) break; + if (kind[0] == '}' && kind[1] == '\0') + break; - switch(symbol(kind, tt_keyword)) + switch (symbol(kind, tt_keyword)) { case kw_type: case kw_frametype: @@ -1366,18 +1322,17 @@ static int read_node_header(io_env_t *env, long *nodenr, long **preds, const cha { int numpreds; *nodename = read_str(env); - if((*nodename)[0] == '}' && !(*nodename)[1]) return -1; // end-of-graph + if ((*nodename)[0] == '}' && !(*nodename)[1]) return -1; /* end-of-graph */ *nodenr = read_long(env); ARR_RESIZE(ir_node *, *preds, 0); EXPECT('['); - for(numpreds = 0; !feof(env->file); numpreds++) - { + for (numpreds = 0; !feof(env->file); numpreds++) { char *endptr; ARR_APP1(long, *preds, read_long2(env, &endptr)); - if(*endptr == ']') break; + if (*endptr == ']') break; } return numpreds; } @@ -1396,19 +1351,17 @@ static int parse_graph(io_env_t *env, ir_graph *irg) EXPECT('{'); - while(1) - { + while (1) { numpreds = read_node_header(env, &nodenr, &preds, &nodename); - if(numpreds == -1) break; // end-of-graph - if(!numpreds) - { + if (numpreds == -1) break; /* end-of-graph */ + if (!numpreds) { printf("Node %s %ld is missing predecessors!", nodename, nodenr); ret = 0; break; } ARR_RESIZE(ir_node *, prednodes, numpreds); - for(i = 0; i < numpreds - 1; i++) + for (i = 0; i < numpreds - 1; i++) prednodes[i] = get_node_or_dummy(env, preds[i + 1]); node = get_node_or_null(env, nodenr); @@ -1416,14 +1369,14 @@ static int parse_graph(io_env_t *env, ir_graph *irg) EXPECT('{'); - switch(symbol(nodename, tt_iro)) + switch (symbol(nodename, tt_iro)) { case iro_End: { ir_node *newendblock = get_node(env, preds[0]); newnode = get_irg_end(current_ir_graph); exchange(get_nodes_block(newnode), newendblock); - for(i = 0; i < numpreds - 1; i++) + for (i = 0; i < numpreds - 1; i++) add_irn_n(newnode, prednodes[i]); break; } @@ -1438,8 +1391,7 @@ static int parse_graph(io_env_t *env, ir_graph *irg) case iro_Block: { - if(preds[0] != nodenr) - { + if (preds[0] != nodenr) { printf("Invalid block: preds[0] != nodenr (%ld != %ld)\n", preds[0], nodenr); ret = 0; @@ -1452,7 +1404,7 @@ static int parse_graph(io_env_t *env, ir_graph *irg) case iro_Anchor: newnode = current_ir_graph->anchor; - for(i = 0; i < numpreds - 1; i++) + for (i = 0; i < numpreds - 1; i++) set_irn_n(newnode, i, prednodes[i]); set_irn_n(newnode, -1, get_node(env, preds[0])); break; @@ -1474,17 +1426,16 @@ static int parse_graph(io_env_t *env, ir_graph *irg) EXPECT('}'); - if(!newnode) - { + if (!newnode) { notsupported: panic("Node type not supported yet: %s in line %i:%i\n", nodename, env->line, env->col); } - if(node) + if (node) exchange(node, newnode); /* Always update hash entry to avoid more uses of id nodes */ set_id(env, nodenr, newnode); - //printf("Insert %s %ld\n", nodename, nodenr); + /* printf("Insert %s %ld\n", nodename, nodenr); */ } endloop: @@ -1497,16 +1448,17 @@ endloop: static int parse_modes(io_env_t *env) { const char *kind; + keyword_t kwkind; EXPECT('{'); - while(1) - { + while (1) { kind = read_str(env); - if(kind[0] == '}' && !kind[1]) break; + if (kind[0] == '}' && kind[1] == '\0') + break; - keyword_t kwkind = (keyword_t) symbol(kind, tt_keyword); - switch(kwkind) + kwkind = (keyword_t) symbol(kind, tt_keyword); + switch (kwkind) { case kw_mode: { @@ -1520,7 +1472,7 @@ static int parse_modes(io_env_t *env) ir_mode *mode = new_ir_mode(name, sort, size, sign, arith, modulo_shift); - if(mode_is_reference(mode)) + if (mode_is_reference(mode)) { set_reference_mode_signed_eq(mode, read_mode(env)); set_reference_mode_unsigned_eq(mode, read_mode(env)); @@ -1533,6 +1485,7 @@ static int parse_modes(io_env_t *env) break; } } + return 1; } /** Imports an previously exported textual representation of an (maybe partial) irp */ @@ -1551,8 +1504,7 @@ void ir_import(const char *filename) env->fixedtypes = NEW_ARR_F(ir_type *, 0); env->file = fopen(filename, "rt"); - if(!env->file) - { + if (!env->file) { perror(filename); exit(1); } @@ -1560,18 +1512,17 @@ void ir_import(const char *filename) set_optimize(0); do_node_verification(FIRM_VERIFICATION_OFF); - while(1) - { + while (1) { const char *str = read_str(env); - if(!*str) break; - switch(symbol(str, tt_keyword)) + if (!*str) break; + switch (symbol(str, tt_keyword)) { case kw_modes: - if(!parse_modes(env)) goto end; + if (!parse_modes(env)) goto end; break; case kw_typegraph: - if(!parse_typegraph(env)) goto end; + if (!parse_typegraph(env)) goto end; break; case kw_irg: @@ -1581,11 +1532,11 @@ void ir_import(const char *filename) ir_graph *irg = new_ir_graph(irgent, 0); set_irg_frame_type(irg, get_type(env, read_long(env))); valuetypeid = read_long(env); - if(valuetypeid != -1) + if (valuetypeid != -1) set_method_value_param_type(get_entity_type(irgent), get_type(env, valuetypeid)); - if(!parse_graph(env, irg)) goto end; + if (!parse_graph(env, irg)) goto end; break; } @@ -1594,7 +1545,7 @@ void ir_import(const char *filename) ir_graph *constirg = get_const_code_irg(); long bodyblockid = read_long(env); set_id(env, bodyblockid, constirg->current_block); - if(!parse_graph(env, constirg)) goto end; + if (!parse_graph(env, constirg)) goto end; break; } } @@ -1602,7 +1553,7 @@ void ir_import(const char *filename) end: n = ARR_LEN(env->fixedtypes); - for(i = 0; i < n; i++) + for (i = 0; i < n; i++) set_type_state(env->fixedtypes[i], layout_fixed); DEL_ARR_F(env->fixedtypes);