- Put typical case of pass construction into irtools
[libfirm] / ir / common / irtools.h
index 2367fc5..5a8162e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
 #ifndef FIRM_COMMON_IRTOOLS_H
 #define FIRM_COMMON_IRTOOLS_H
 
-#include "firm_config.h"
 #include "firm_types.h"
 
-#ifdef WITH_LIBCORE
-#include <libcore/lc_opts.h>
+#include "lc_opts.h"
 lc_opt_entry_t *firm_opt_get_root(void);
-#endif
 
 #include "pset.h"
 
@@ -41,6 +38,10 @@ lc_opt_entry_t *firm_opt_get_root(void);
 #define MAX(x, y) ((x) > (y) ? (x) : (y))
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 
+/* calculate the address of the one past last element of an array whose size is
+ * known statically */
+#define ENDOF(x) ((x) + sizeof(x) / sizeof(*(x)))
+
 /**
  * Three valued compare as demanded by e.g. qsort(3)
  * @param c A number.
@@ -67,10 +68,19 @@ void firm_pset_dump(pset *set);
 
 /**
  * The famous clear_link() walker-function.
- * Do not implement it by yourself, use this one
+ * Sets all links fields of visited nodes to NULL.
+ * Do not implement it by yourself, use this one.
  */
 void firm_clear_link(ir_node *n, void *env);
 
+/**
+ * The famous clear_link_and_block_lists() walker-function.
+ * Sets all links fields of visited nodes to NULL.
+ * Additionally, clear all Phi-lists of visited blocks.
+ * Do not implement it by yourself, use this one
+ */
+void firm_clear_node_and_phi_links(ir_node *n, void *env);
+
 /**
  * Copies a node to a new irg. The Ins of the new node point to
  * the predecessors on the old irg.  n->link points to the new node.
@@ -95,4 +105,36 @@ void copy_irn_to_irg(ir_node *n, ir_graph *irg);
  */
 ir_node *exact_copy(const ir_node *n);
 
+/**
+ * Creates an ir_graph pass for running void function(ir_graph *irg).
+ * Uses the default verifier and dumper.
+ * The pass returns always 0.
+ *
+ * @param name     the name of this pass
+ * @param verify   should this pass be verified?
+ * @param dump     should this pass result be dumped?
+ * @param params   The parameters for the if conversion.
+ *
+ * @return  the newly created ir_graph pass
+ */
+ir_graph_pass_t *def_graph_pass(
+       const char *name, int verify, int dump,
+       void (*function)(ir_graph *irg));
+
+/**
+ * Creates an ir_graph pass for running int function(ir_graph *irg).
+ * Uses the default verifier and dumper.
+ * The pass returns the return value of function.
+ *
+ * @param name     the name of this pass
+ * @param verify   should this pass be verified?
+ * @param dump     should this pass result be dumped?
+ * @param params   The parameters for the if conversion.
+ *
+ * @return  the newly created ir_graph pass
+ */
+ir_graph_pass_t *def_graph_pass_ret(
+       const char *name, int verify, int dump,
+       int (*function)(ir_graph *irg));
+
 #endif