bepeephole: Inline be_peephole_new_node() into its only caller.
[libfirm] / ir / stat / pattern_dmp.c
index ef7136a..32394b1 100644 (file)
@@ -1,32 +1,15 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
  * @file
  * @brief   Statistics for Firm. Dumping patterns.
  * @author  Michael Beck
- * @version $Id$
  */
 #include "config.h"
 
-#ifdef FIRM_STATISTICS
-
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -50,7 +33,7 @@ typedef void (*DUMP_END_FUNC)(pattern_dumper_t *self);
 /**
  * the pattern dumper
  */
-struct _pattern_dumper_t {
+struct pattern_dumper_t {
        DUMP_NEW_PATTERN_FUNC      dump_new_pattern;
        DUMP_FINISH_PATTERN_FUNC   dump_finish_pattern;
        DUMP_NODE_FUNC             dump_node;
@@ -66,7 +49,7 @@ struct _pattern_dumper_t {
 /**
  * VCG private data
  */
-typedef struct _vcg_private_t {
+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 */
@@ -77,7 +60,7 @@ typedef struct _vcg_private_t {
  */
 static void vcg_dump_start(pattern_dumper_t *self)
 {
-       vcg_private_t *priv = self->data;
+       vcg_private_t *priv = (vcg_private_t*)self->data;
 
        fprintf(priv->f,
                "graph: { title: \"Most found pattern\"\n"
@@ -87,25 +70,25 @@ static void vcg_dump_start(pattern_dumper_t *self)
                "  port_sharing: no\n"
                "  orientation: bottom_to_top\n"
                );
-}  /* vcg_dump_start */
+}
 
 /**
  * Ends a new VCG graph.
  */
 static void vcg_dump_end(pattern_dumper_t *self)
 {
-       vcg_private_t *priv = self->data;
+       vcg_private_t *priv = (vcg_private_t*)self->data;
 
        fprintf(priv->f, "}\n");
        fclose(priv->f);
-}  /* vcg_dump_end */
+}
 
 /**
  * Starts a new pattern.
  */
 static void vcg_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt)
 {
-       vcg_private_t *priv = self->data;
+       vcg_private_t *priv = (vcg_private_t*)self->data;
        static unsigned nr = 0;
 
        if (priv->pattern_id > priv->max_pattern)
@@ -120,14 +103,14 @@ static void vcg_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt)
                "    node: {title: \"c%u\" label: \"cnt: %u\" color:red }\n",
                ++nr, cnt_to_uint(cnt)
        );
-}  /* vcg_dump_new_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 = (vcg_private_t*)self->data;
 
        if (priv->pattern_id > priv->max_pattern)
                return;
@@ -140,7 +123,7 @@ static void vcg_dump_finish_pattern(pattern_dumper_t *self)
                        priv->pattern_id - 1);
 
        ++priv->pattern_id;
-}  /* vcg_dump_finish_pattern */
+}
 
 /**
  * Dumps a node.
@@ -148,9 +131,9 @@ static void vcg_dump_finish_pattern(pattern_dumper_t *self)
 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;
+       vcg_private_t *priv = (vcg_private_t*)self->data;
        ir_op *op           = stat_get_op_from_opcode(op_code);
-       ir_mode *mode       = stat_mode_for_index(mode_code);
+       ir_mode *mode       = ir_get_mode(mode_code);
        long l              = attr ? *(long *)attr : 0;
 
        if (priv->pattern_id > priv->max_pattern)
@@ -162,15 +145,15 @@ static void vcg_dump_node(pattern_dumper_t *self, unsigned 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 = (vcg_private_t*)self->data;
        (void) mode_code;
 
        if (priv->pattern_id > priv->max_pattern)
@@ -181,7 +164,7 @@ static void vcg_dump_edge(pattern_dumper_t *self, unsigned tgt, unsigned src, un
                priv->pattern_id, tgt,
                pos
        );
-}  /* vcg_dump_edge */
+}
 
 /**
  * The VCG dumper.
@@ -204,10 +187,10 @@ static pattern_dumper_t vcg_dump = {
  */
 static void stdout_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt)
 {
-       FILE *f = self->data;
+       FILE *f = (FILE*)self->data;
 
        fprintf(f, "%8u ", cnt_to_uint(cnt));
-}  /* stdout_dump_new_pattern */
+}
 
 
 /**
@@ -215,19 +198,19 @@ static void stdout_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt)
  */
 static void stdout_dump_finish_pattern(pattern_dumper_t *self)
 {
-       FILE *f = self->data;
+       FILE *f = (FILE*)self->data;
 
        fprintf(f, "\n");
-}  /* stdout_dump_finish_pattern */
+}
 
 /**
  * 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;
+       FILE *f       = (FILE*)self->data;
        ir_op *op     = stat_get_op_from_opcode(op_code);
-       ir_mode *mode = stat_mode_for_index(mode_code);
+       ir_mode *mode = ir_get_mode(mode_code);
        (void) attr;
 
        /* if (env->options & OPT_ENC_GRAPH) */
@@ -237,24 +220,24 @@ static void stdout_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_co
 
        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 = (FILE*)self->data;
 
        fprintf(f, "REF:%u", id);
-}  /* stdout_dump_ref */
+}
 
 /**
  * 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 = (FILE*)self->data;
        (void) tgt;
        (void) src;
        (void) pos;
@@ -262,29 +245,29 @@ static void stdout_dump_edge(pattern_dumper_t *self, unsigned tgt, unsigned src,
 
        if (pos > 0)
                fprintf(f, ", ");
-}  /* stdout_dump_edge */
+}
 
 /**
  * Start the children dumper.
  */
 static void stdout_start_children(pattern_dumper_t *self, unsigned id)
 {
-       FILE *f = self->data;
+       FILE *f = (FILE*)self->data;
        (void) id;
 
        fprintf(f, "(");
-}  /* stdout_start_children */
+}
 
 /**
  * Finish the children dumper.
  */
 static void stdout_finish_children(pattern_dumper_t *self, unsigned id)
 {
-       FILE *f = self->data;
+       FILE *f = (FILE*)self->data;
        (void) id;
 
        fprintf(f, ")");
-}  /* stdout_finish_children */
+}
 
 /**
  * The stdout dumper.
@@ -311,7 +294,7 @@ void pattern_dump_new_pattern(pattern_dumper_t *self, counter_t *cnt)
 {
        if (self->dump_new_pattern)
                self->dump_new_pattern(self, cnt);
-}  /* pattern_dump_new_pattern */
+}
 
 
 /*
@@ -321,7 +304,7 @@ void pattern_dump_finish_pattern(pattern_dumper_t *self)
 {
        if (self->dump_finish_pattern)
                self->dump_finish_pattern(self);
-}  /* pattern_dump_finish_pattern */
+}
 
 
 /*
@@ -331,7 +314,7 @@ void pattern_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_code, un
 {
        if (self->dump_node)
                self->dump_node(self, id, op_code, mode_code, attr);
-}  /* pattern_dump_node */
+}
 
 /*
  * Dump a ref.
@@ -340,7 +323,7 @@ void pattern_dump_ref(pattern_dumper_t *self, unsigned id)
 {
        if (self->dump_ref)
                self->dump_ref(self, id);
-}  /* pattern_dump_ref */
+}
 
 /*
  * Dump an edge.
@@ -349,7 +332,7 @@ void pattern_dump_edge(pattern_dumper_t *self, unsigned tgt, unsigned src, unsig
 {
        if (self->dump_edge)
                self->dump_edge(self, tgt, src, pos, mode_code);
-}  /* pattern_dump_edge */
+}
 
 /*
  * Start the children dumper.
@@ -358,7 +341,7 @@ void pattern_start_children(pattern_dumper_t *self, unsigned id)
 {
        if (self->dump_start_children)
                self->dump_start_children(self, id);
-}  /* pattern_start_children */
+}
 
 /*
  * Finish the the children dumper.
@@ -367,7 +350,7 @@ void pattern_finish_children(pattern_dumper_t *self, unsigned id)
 {
        if (self->dump_finish_children)
                self->dump_finish_children(self, id);
-}  /* pattern_finish_children */
+}
 
 /*
  * Finish the the dumper.
@@ -378,31 +361,29 @@ void pattern_end(pattern_dumper_t *self)
                self->dump_end(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 = XMALLOC(pattern_dumper_t);
 
-       if (res) {
-               memcpy(res, &stdout_dump, sizeof(*res));
-               res->data = stdout;
+       *res = stdout_dump;
+       res->data = stdout;
 
-               if (res->dump_start)
-                       res->dump_start(res);
-       }  /* if */
+       if (res->dump_start)
+               res->dump_start(res);
        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));
+       pattern_dumper_t *res = (pattern_dumper_t*)malloc(sizeof(*res) + sizeof(vcg_private_t));
        vcg_private_t *priv;
 
        if (res) {
@@ -421,9 +402,7 @@ pattern_dumper_t *new_vcg_dumper(const char *vcg_name, unsigned max_pattern)
 
                if (res->dump_start)
                        res->dump_start(res);
-       }  /* if */
+       }
 
        return res;
-}  /* new_vcg_dumper */
-
-#endif /* FIRM_STATISTICS */
+}