X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fstat%2Fpattern_dmp.c;h=e2536ad8f0ed747e410afee9110d07b3c4a29002;hb=0a9a6a5d9e6f4ec5f77a97c38a4d1b01148ac3f0;hp=f1c57d29371602fc632710d86ab32f1450ff3980;hpb=52f08badd88149bc93425d9aede11f1f889ece71;p=libfirm diff --git a/ir/stat/pattern_dmp.c b/ir/stat/pattern_dmp.c index f1c57d293..e2536ad8f 100644 --- a/ir/stat/pattern_dmp.c +++ b/ir/stat/pattern_dmp.c @@ -39,370 +39,369 @@ typedef void (*DUMP_END_FUNC)(pattern_dumper_t *self); * the pattern dumper */ struct _pattern_dumper_t { - DUMP_NEW_PATTERN_FUNC dump_new_pattern; - DUMP_FINISH_PATTERN_FUNC dump_finish_pattern; - DUMP_NODE_FUNC dump_node; - DUMP_REF_FUNC dump_ref; - DUMP_EDGE_FUNC dump_edge; - DUMP_START_CHILDREN_FUNC dump_start_children; - DUMP_FINISH_CHILDREN_FUNC dump_finish_children; - DUMP_START_FUNC dump_start; - DUMP_END_FUNC dump_end; - void *data; + DUMP_NEW_PATTERN_FUNC dump_new_pattern; + DUMP_FINISH_PATTERN_FUNC dump_finish_pattern; + DUMP_NODE_FUNC dump_node; + DUMP_REF_FUNC dump_ref; + DUMP_EDGE_FUNC dump_edge; + DUMP_START_CHILDREN_FUNC dump_start_children; + DUMP_FINISH_CHILDREN_FUNC dump_finish_children; + DUMP_START_FUNC dump_start; + DUMP_END_FUNC dump_end; + void *data; }; /** * VCG private data */ typedef struct _vcg_private_t { - FILE *f; /**< file to dump to */ - unsigned pattern_id; /**< ID of the pattern */ - unsigned max_pattern; /**< maximum number of pattern to be dumped */ + FILE *f; /**< file to dump to */ + unsigned pattern_id; /**< ID of the pattern */ + unsigned max_pattern; /**< maximum number of pattern to be dumped */ } vcg_private_t; /** - * starts a new VCG graph + * Starts a new VCG graph. */ static void vcg_dump_start(pattern_dumper_t *self) { - vcg_private_t *priv = self->data; - - fprintf(priv->f, - "graph: { title: \"Most found pattern\"\n" - " display_edge_labels: no\n" - " layoutalgorithm: mindepth\n" - " manhattan_edges: yes\n" - " port_sharing: no\n" - " orientation: bottom_to_top\n" - ); -} + vcg_private_t *priv = self->data; + + fprintf(priv->f, + "graph: { title: \"Most found pattern\"\n" + " display_edge_labels: no\n" + " layoutalgorithm: mindepth\n" + " manhattan_edges: yes\n" + " port_sharing: no\n" + " orientation: bottom_to_top\n" + ); +} /* vcg_dump_start */ /** - * ends a new VCG graph + * Ends a new VCG graph. */ static void vcg_dump_end(pattern_dumper_t *self) { - vcg_private_t *priv = self->data; + vcg_private_t *priv = self->data; - fprintf(priv->f, "}\n"); - fclose(priv->f); -} + fprintf(priv->f, "}\n"); + fclose(priv->f); +} /* vcg_dump_end */ -/* - * starts a new pattern +/** + * Starts a new pattern. */ static void vcg_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt) { - vcg_private_t *priv = self->data; - static unsigned nr = 0; + vcg_private_t *priv = self->data; + static unsigned nr = 0; - if (priv->pattern_id > priv->max_pattern) - return; + if (priv->pattern_id > priv->max_pattern) + return; - fprintf(priv->f, - " graph: { title: \"g%u\" label: \"pattern %u\" status:clustered color:yellow\n", - priv->pattern_id, priv->pattern_id ); + fprintf(priv->f, + " graph: { title: \"g%u\" label: \"pattern %u\" status:clustered color:yellow\n", + priv->pattern_id, priv->pattern_id ); - /** add a pseudo node */ - fprintf(priv->f, - " node: {title: \"c%u\" label: \"cnt: %u\" color:red }\n", - ++nr, cnt_to_int(cnt) - ); -} + /* add a pseudo node for the count of this pattern */ + fprintf(priv->f, + " node: {title: \"c%u\" label: \"cnt: %u\" color:red }\n", + ++nr, cnt_to_uint(cnt) + ); +} /* vcg_dump_new_pattern */ /** - * Finishes current pattern + * Finish the current pattern. */ static void vcg_dump_finish_pattern(pattern_dumper_t *self) { - vcg_private_t *priv = self->data; + vcg_private_t *priv = self->data; - if (priv->pattern_id > priv->max_pattern) - return; + if (priv->pattern_id > priv->max_pattern) + return; - fprintf(priv->f, " }\n"); + fprintf(priv->f, " }\n"); - if (priv->pattern_id > 0) - fprintf(priv->f, " edge: { sourcename: \"g%u\" targetname: \"g%u\" linestyle:invisible}\n", - priv->pattern_id, - priv->pattern_id - 1); + if (priv->pattern_id > 0) + fprintf(priv->f, " edge: { sourcename: \"g%u\" targetname: \"g%u\" linestyle:invisible}\n", + priv->pattern_id, + priv->pattern_id - 1); - ++priv->pattern_id; -} + ++priv->pattern_id; +} /* vcg_dump_finish_pattern */ /** - * Dumps a node + * Dumps a node. */ static void vcg_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_code, unsigned mode_code, void *attr) { - vcg_private_t *priv = self->data; - ir_op *op = stat_get_op_from_opcode(op_code); - ir_mode *mode = (ir_mode *)mode_code; - long l = attr ? *(long *)attr : 0; - - if (priv->pattern_id > priv->max_pattern) - return; - - if (attr) { - fprintf(priv->f, " node: {title: \"n%u_%u\" label: \"%s%s %ld n%u\" }\n", - priv->pattern_id, id, get_id_str(op->name), mode ? get_mode_name(mode) : "", l, id); - } - else { - fprintf(priv->f, " node: {title: \"n%u_%u\" label: \"%s%s n%u\" }\n", - priv->pattern_id, id, get_id_str(op->name), mode ? get_mode_name(mode) : "", id); - } -} + vcg_private_t *priv = self->data; + ir_op *op = stat_get_op_from_opcode(op_code); + ir_mode *mode = (ir_mode *)mode_code; + long l = attr ? *(long *)attr : 0; + + if (priv->pattern_id > priv->max_pattern) + return; + + if (attr) { + fprintf(priv->f, " node: {title: \"n%u_%u\" label: \"%s%s %ld n%u\" }\n", + priv->pattern_id, id, get_id_str(op->name), mode ? get_mode_name(mode) : "", l, id); + } else { + fprintf(priv->f, " node: {title: \"n%u_%u\" label: \"%s%s n%u\" }\n", + priv->pattern_id, id, get_id_str(op->name), mode ? get_mode_name(mode) : "", id); + } /* if */ +} /* vcg_dump_node */ /** * Dumps an edge. */ static void vcg_dump_edge(pattern_dumper_t *self, unsigned tgt, unsigned src, unsigned pos, unsigned mode_code) { - vcg_private_t *priv = self->data; + vcg_private_t *priv = self->data; - if (priv->pattern_id > priv->max_pattern) - return; + if (priv->pattern_id > priv->max_pattern) + return; - fprintf(priv->f, " edge: { sourcename: \"n%u_%u\" targetname: \"n%u_%u\" label: \"%u\" }\n", - priv->pattern_id, src, - priv->pattern_id, tgt, - pos - ); -} + fprintf(priv->f, " edge: { sourcename: \"n%u_%u\" targetname: \"n%u_%u\" label: \"%u\" }\n", + priv->pattern_id, src, + priv->pattern_id, tgt, + pos + ); +} /* vcg_dump_edge */ /** * The VCG dumper. */ static pattern_dumper_t vcg_dump = { - vcg_dump_new_pattern, - vcg_dump_finish_pattern, - vcg_dump_node, - NULL, - vcg_dump_edge, - NULL, - NULL, - vcg_dump_start, - vcg_dump_end, - NULL + vcg_dump_new_pattern, + vcg_dump_finish_pattern, + vcg_dump_node, + NULL, + vcg_dump_edge, + NULL, + NULL, + vcg_dump_start, + vcg_dump_end, + NULL }; /** - * starts a new pattern + * Starts a new pattern. */ static void stdout_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt) { - FILE *f = self->data; + FILE *f = self->data; - fprintf(f, "%8u ", cnt_to_int(cnt)); -} + fprintf(f, "%8u ", cnt_to_uint(cnt)); +} /* stdout_dump_new_pattern */ /** - * Finishes current pattern + * Finish the current pattern. */ static void stdout_dump_finish_pattern(pattern_dumper_t *self) { - FILE *f = self->data; + FILE *f = self->data; - fprintf(f, "\n"); -} + fprintf(f, "\n"); +} /* stdout_dump_finish_pattern */ /** - * Dumps a node + * Dumps a node. */ static void stdout_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_code, unsigned mode_code, void *attr) { - FILE *f = self->data; - ir_op *op = stat_get_op_from_opcode(op_code); - ir_mode *mode = (ir_mode *)mode_code; + FILE *f = self->data; + ir_op *op = stat_get_op_from_opcode(op_code); + ir_mode *mode = (ir_mode *)mode_code; - /* if (env->options & OPT_ENC_GRAPH) */ - fprintf(f, "%u:", id); + /* if (env->options & OPT_ENC_GRAPH) */ + fprintf(f, "%u:", id); - fprintf(f, "%s", get_id_str(op->name)); + fprintf(f, "%s", get_id_str(op->name)); - if (mode) - fprintf(f, "%s", get_mode_name(mode)); -} + if (mode) + fprintf(f, "%s", get_mode_name(mode)); +} /* stdout_dump_node */ /** * Dump a ref */ static void stdout_dump_ref(pattern_dumper_t *self, unsigned id) { - FILE *f = self->data; + FILE *f = self->data; - fprintf(f, "REF:%u", id); -} + fprintf(f, "REF:%u", id); +} /* stdout_dump_ref */ /** - * Dump an edge + * Dump an edge. */ static void stdout_dump_edge(pattern_dumper_t *self, unsigned tgt, unsigned src, unsigned pos, unsigned mode_code) { - FILE *f = self->data; + FILE *f = self->data; - if (pos > 0) - fprintf(f, ", "); -} + if (pos > 0) + fprintf(f, ", "); +} /* stdout_dump_edge */ /** - * Start children dumper + * Start the children dumper. */ static void stdout_start_children(pattern_dumper_t *self, unsigned id) { - FILE *f = self->data; + FILE *f = self->data; - fprintf(f, "("); -} + fprintf(f, "("); +} /* stdout_start_children */ /** - * finishes the children dumper + * Finish the children dumper. */ static void stdout_finish_children(pattern_dumper_t *self, unsigned id) { - FILE *f = self->data; + FILE *f = self->data; - fprintf(f, ")"); -} + fprintf(f, ")"); +} /* stdout_finish_children */ /** * The stdout dumper. */ static const pattern_dumper_t stdout_dump = { - stdout_dump_new_pattern, - stdout_dump_finish_pattern, - stdout_dump_node, - stdout_dump_ref, - stdout_dump_edge, - stdout_start_children, - stdout_finish_children, - NULL, - NULL, - NULL + stdout_dump_new_pattern, + stdout_dump_finish_pattern, + stdout_dump_node, + stdout_dump_ref, + stdout_dump_edge, + stdout_start_children, + stdout_finish_children, + NULL, + NULL, + NULL }; /* ------------------------------------ API ------------------------------------- */ /* - * starts a new pattern + * Starts a new pattern. */ void pattern_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt) { - if (self->dump_new_pattern) - self->dump_new_pattern(self, cnt); -} + if (self->dump_new_pattern) + self->dump_new_pattern(self, cnt); +} /* pattern_dump_new_pattern */ /* - * Finishes current pattern + * Finish the current pattern. */ void pattern_dump_finish_pattern(pattern_dumper_t *self) { - if (self->dump_finish_pattern) - self->dump_finish_pattern(self); -} + if (self->dump_finish_pattern) + self->dump_finish_pattern(self); +} /* pattern_dump_finish_pattern */ /* - * Dumps a node + * Dumps a node. */ void pattern_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_code, unsigned mode_code, void *attr) { - if (self->dump_node) - self->dump_node(self, id, op_code, mode_code, attr); -} + if (self->dump_node) + self->dump_node(self, id, op_code, mode_code, attr); +} /* pattern_dump_node */ /* - * Dump a ref + * Dump a ref. */ void pattern_dump_ref(pattern_dumper_t *self, unsigned id) { - if (self->dump_ref) - self->dump_ref(self, id); -} + if (self->dump_ref) + self->dump_ref(self, id); +} /* pattern_dump_ref */ /* - * Dump an edge + * Dump an edge. */ void pattern_dump_edge(pattern_dumper_t *self, unsigned tgt, unsigned src, unsigned pos, unsigned mode_code) { - if (self->dump_edge) - self->dump_edge(self, tgt, src, pos, mode_code); -} + if (self->dump_edge) + self->dump_edge(self, tgt, src, pos, mode_code); +} /* pattern_dump_edge */ /* - * Start children dumper + * Start the children dumper. */ void pattern_start_children(pattern_dumper_t *self, unsigned id) { - if (self->dump_start_children) - self->dump_start_children(self, id); -} + if (self->dump_start_children) + self->dump_start_children(self, id); +} /* pattern_start_children */ /* - * finishes the children dumper + * Finish the the children dumper. */ void pattern_finish_children(pattern_dumper_t *self, unsigned id) { - if (self->dump_finish_children) - self->dump_finish_children(self, id); -} + if (self->dump_finish_children) + self->dump_finish_children(self, id); +} /* pattern_finish_children */ /* - * finishes the dumper + * Finish the the dumper. */ void pattern_end(pattern_dumper_t *self) { - if (self->dump_end) - self->dump_end(self); + if (self->dump_end) + self->dump_end(self); - free(self); -} + free(self); +} /* pattern_end */ /** * pattern dumper factory for text dumper */ pattern_dumper_t *new_text_dumper(void) { - pattern_dumper_t *res = malloc(sizeof(*res)); + pattern_dumper_t *res = malloc(sizeof(*res)); - if (res) { - memcpy(res, &stdout_dump, sizeof(*res)); - res->data = stdout; + if (res) { + memcpy(res, &stdout_dump, sizeof(*res)); + res->data = stdout; - if (res->dump_start) - res->dump_start(res); - } - return res; -} + if (res->dump_start) + res->dump_start(res); + } /* if */ + return res; +} /* new_text_dumper */ /** * pattern dumper factory for vcg dumper */ pattern_dumper_t *new_vcg_dumper(const char *vcg_name, unsigned max_pattern) { - pattern_dumper_t *res = malloc(sizeof(*res) + sizeof(vcg_private_t)); - vcg_private_t *priv; + pattern_dumper_t *res = malloc(sizeof(*res) + sizeof(vcg_private_t)); + vcg_private_t *priv; - if (res) { - FILE *f; + if (res) { + FILE *f; - memcpy(res, &vcg_dump, sizeof(*res)); + memcpy(res, &vcg_dump, sizeof(*res)); - priv = (vcg_private_t *)(res + 1); - memset(priv, 0, sizeof(*priv)); + priv = (vcg_private_t *)(res + 1); + memset(priv, 0, sizeof(*priv)); - f = fopen(vcg_name, "w"); - priv->f = f; - priv->pattern_id = 0; - priv->max_pattern = max_pattern ? max_pattern : (unsigned)-1; - res->data = priv; + f = fopen(vcg_name, "w"); + priv->f = f; + priv->pattern_id = 0; + priv->max_pattern = max_pattern ? max_pattern : (unsigned)-1; + res->data = priv; - if (res->dump_start) - res->dump_start(res); - } + if (res->dump_start) + res->dump_start(res); + } /* if */ - return res; -} + return res; +} /* new_vcg_dumper */