From: Michael Beck Date: Thu, 15 May 2008 10:15:52 +0000 (+0000) Subject: dumps now new style initializers X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=e030f08f83164a988b67fcf0c0422418f0a16666;p=libfirm dumps now new style initializers [r19623] --- diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 35360851b..4be2f5e67 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -58,6 +58,7 @@ #include "irhooks.h" #include "dbginfo_t.h" #include "irtools.h" +#include "irprintf.h" #include "irvrfy.h" @@ -732,15 +733,11 @@ int dump_node_opcode(FILE *F, ir_node *n) /* implementation for default nodes */ switch (get_irn_opcode(n)) { - case iro_Const: { - int res; - char buf[1024]; - res = tarval_snprintf(buf, sizeof(buf), get_Const_tarval(n)); - assert(res < (int) sizeof(buf) && "buffer to small for tarval_snprintf"); - fprintf(F, buf); - } break; + case iro_Const: + ir_fprintf(F, "%T", get_Const_tarval(n)); + break; - case iro_SymConst: { + case iro_SymConst: switch (get_SymConst_kind(n)) { case symconst_addr_name: /* don't use get_SymConst_ptr_info as it mangles the name. */ @@ -768,14 +765,14 @@ int dump_node_opcode(FILE *F, ir_node *n) fprintf(F, "SymC %lu label", get_SymConst_label(n)); break; } - } break; + break; - case iro_Filter: { + case iro_Filter: if (!get_interprocedural_view()) fprintf(F, "Proj'"); else goto default_case; - } break; + break; case iro_Proj: { ir_node *pred = get_Proj_pred(n); @@ -790,13 +787,13 @@ int dump_node_opcode(FILE *F, ir_node *n) case iro_Start: case iro_End: case iro_EndExcept: - case iro_EndReg: { + case iro_EndReg: if (get_interprocedural_view()) { fprintf(F, "%s %s", get_irn_opname(n), get_ent_dump_name(get_irg_entity(get_irn_irg(n)))); break; } else goto default_case; - } + case iro_CallBegin: { ir_node *addr = get_CallBegin_ptr(n); ir_entity *ent = NULL; diff --git a/ir/ir/irdumptxt.c b/ir/ir/irdumptxt.c index e7e5cebc6..aa71c16ea 100644 --- a/ir/ir/irdumptxt.c +++ b/ir/ir/irdumptxt.c @@ -47,6 +47,7 @@ #include "irgwalk.h" #include "tv_t.h" #include "irprintf.h" +#include "error.h" #include "irdom.h" #include "field_temperature.h" @@ -549,6 +550,77 @@ static void dump_type_list(FILE *F, ir_type *tp, char *prefix, fprintf(F, "\n"); } +static int need_nl = 1; + +/** + * Dump initializers. + */ +static void dump_ir_initializers_to_file(FILE *F, const char *prefix, + const ir_initializer_t *initializer, ir_type *type) { + tarval *tv; + ir_node *value; + + if (need_nl) { + fprintf(F, "\n%s ", prefix); + need_nl = 0; + } + switch (get_initializer_kind(initializer)) { + case IR_INITIALIZER_NULL: + fprintf(F, "\t = "); + break; + case IR_INITIALIZER_TARVAL: + tv = get_initializer_tarval_value(initializer); + ir_fprintf(F, "\t = %F", tv); + break; + case IR_INITIALIZER_CONST: + value = get_initializer_const_value(initializer); + fprintf(F, "\t = "); + dump_node_opcode(F, value); + break; + case IR_INITIALIZER_COMPOUND: + if (is_Array_type(type)) { + size_t i, n = get_initializer_compound_n_entries(initializer); + ir_type *element_type = get_array_element_type(type); + for (i = 0; i < n; ++i) { + ir_initializer_t *sub_initializer + = get_initializer_compound_value(initializer, i); + + if (need_nl) { + fprintf(F, "\n%s ", prefix); + need_nl = 0; + } + fprintf(F, "[%d]", i); + dump_ir_initializers_to_file(F, prefix, sub_initializer, element_type); + } + } else { + size_t i, n; + assert(is_compound_type(type)); + n = get_compound_n_members(type); + for (i = 0; i < n; ++i) { + ir_entity *member = get_compound_member(type, i); + ir_type *subtype = get_entity_type(member); + ir_initializer_t *sub_initializer; + + assert(i < get_initializer_compound_n_entries(initializer)); + sub_initializer + = get_initializer_compound_value(initializer, i); + + if (need_nl) { + fprintf(F, "\n%s ", prefix); + need_nl = 0; + } + ir_fprintf(F, ".%F", member); + dump_ir_initializers_to_file(F, prefix, sub_initializer, subtype); + } + } + break; + default: + panic("invalid ir_initializer kind found"); + } + need_nl = 1; +} + + void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, char *prefix, unsigned verbosity) { int i, j; ir_type *owner, *type; @@ -665,26 +737,34 @@ void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, char *prefix, unsigned if (verbosity & dump_verbosity_entconsts) { if (get_entity_variability(ent) != variability_uninitialized) { - if (is_atomic_entity(ent)) { - fprintf(F, "%s atomic value: ", prefix); - dump_node_opcode(F, get_atomic_ent_value(ent)); + if (ent->has_initializer) { + const ir_initializer_t *initializer = get_entity_initializer(ent); + fprintf(F, "\n%s Initializers:"); + need_nl = 1; + dump_ir_initializers_to_file(F, prefix, initializer, get_entity_type(ent)); } else { - fprintf(F, "%s compound values:", prefix); - for (i = 0; i < get_compound_ent_n_values(ent); ++i) { - compound_graph_path *path = get_compound_ent_value_path(ent, i); - ir_entity *ent0 = get_compound_graph_path_node(path, 0); - fprintf(F, "\n%s %3d:%u ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0)); - if (get_type_state(type) == layout_fixed) - fprintf(F, "(%3u:%u) ", get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i)); - fprintf(F, "%s", get_entity_name(ent)); - for (j = 0; j < get_compound_graph_path_length(path); ++j) { - ir_entity *node = get_compound_graph_path_node(path, j); - fprintf(F, ".%s", get_entity_name(node)); - if (is_Array_type(get_entity_owner(node))) - fprintf(F, "[%d]", get_compound_graph_path_array_index(path, j)); + /* old compound_graph_path based initializers */ + if (is_atomic_entity(ent)) { + fprintf(F, "%s atomic value: ", prefix); + dump_node_opcode(F, get_atomic_ent_value(ent)); + } else { + fprintf(F, "%s compound values:", prefix); + for (i = 0; i < get_compound_ent_n_values(ent); ++i) { + compound_graph_path *path = get_compound_ent_value_path(ent, i); + ir_entity *ent0 = get_compound_graph_path_node(path, 0); + fprintf(F, "\n%s %3d:%u ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0)); + if (get_type_state(type) == layout_fixed) + fprintf(F, "(%3u:%u) ", get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i)); + fprintf(F, "%s", get_entity_name(ent)); + for (j = 0; j < get_compound_graph_path_length(path); ++j) { + ir_entity *node = get_compound_graph_path_node(path, j); + fprintf(F, ".%s", get_entity_name(node)); + if (is_Array_type(get_entity_owner(node))) + fprintf(F, "[%d]", get_compound_graph_path_array_index(path, j)); + } + fprintf(F, "\t = "); + dump_node_opcode(F, get_compound_ent_value(ent, i)); } - fprintf(F, "\t = "); - dump_node_opcode(F, get_compound_ent_value(ent, i)); } } fprintf(F, "\n");