replaced inline by __inline to allow to be compiled in gcc and msvc modes
[libfirm] / ir / be / benodesets.h
index cdfa147..8fbc556 100644 (file)
@@ -1,12 +1,35 @@
+/*
+ * Copyright (C) 1995-2007 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.
+ */
+
 /**
- * A lightweight wrapper around pset to store IR nodes.
+ * @file
+ * @brief       A lightweight wrapper around pset to store IR nodes.
+ * @author      Michael Beck
+ * @version     $Id$
+ *
  * In some algorithms we want a more deterministic behavior
  * which the pset_ptr did not guarantee due to it's hash function
  */
-#ifndef _BENODESETS_H
-#define _BENODESETS_H
+#ifndef FIRM_BE_BENODESETS_H
+#define FIRM_BE_BENODESETS_H
 
-#include "firm_types.h"
+#include "irnode.h"
 #include "pset.h"
 
 typedef struct pset nodeset;
@@ -14,7 +37,7 @@ typedef struct pset nodeset;
 /**
  * Calculates a hash value for a node.
  */
-unsigned nodeset_hash(ir_node *n);
+unsigned nodeset_hash(const ir_node *n);
 
 /**
  * Creates a new nodeset.
@@ -25,7 +48,15 @@ unsigned nodeset_hash(ir_node *n);
  * @returns
  *    created nodeset
  */
-#define new_nodeset(slots) new_pset(pset_default_ptr_cmp, (slots))
+static INLINE nodeset *new_nodeset(int slots)
+{
+       return new_pset(pset_default_ptr_cmp, slots);
+}
+
+/*
+ * Define some convenience macros.
+ */
+#define new_nodeset_default()    new_nodeset(64)
 
 /**
  * Deletes a nodeset.
@@ -35,14 +66,20 @@ unsigned nodeset_hash(ir_node *n);
  * @note
  *    This does NOT delete the elements of this node set, just it's pointers!
  */
-#define del_nodeset(nset) del_pset(nset)
+static INLINE void del_nodeset(nodeset *nset)
+{
+       del_pset(nset);
+}
 
 /**
  * Returns the number of nodes in a nodeset.
  *
  * @param nset   the nodeset
  */
-#define nodeset_count(nset) pset_count(nset)
+static INLINE int nodeset_count(nodeset *nset)
+{
+       return pset_count(nset);
+}
 
 /**
  * Searches a node in a node set.
@@ -53,7 +90,10 @@ unsigned nodeset_hash(ir_node *n);
  * @return
  *    the pointer of the found node in the nodeset or NULL if it was not found
  */
-#define nodeset_find(nset, key)  (ir_node *)pset_find((nset), (key), nodeset_hash(key))
+static INLINE ir_node *nodeset_find(nodeset *nset, ir_node *key)
+{
+       return (ir_node *) pset_find(nset, key, nodeset_hash(key));
+}
 
 /**
  * Inserts a node into a pset.
@@ -68,7 +108,10 @@ unsigned nodeset_hash(ir_node *n);
  *    that should be inserted is already in the set, this functions does
  *    nothing but returning its already existing set_entry.
  */
-#define nodeset_insert(nset, key) (ir_node *)pset_insert((nset), (key), nodeset_hash(key))
+static INLINE ir_node *nodeset_insert(nodeset *nset, ir_node *key)
+{
+       return (ir_node *) pset_insert(nset, key, nodeset_hash(key));
+}
 
 /**
  * Removes a node from a nodeset.
@@ -85,7 +128,10 @@ unsigned nodeset_hash(ir_node *n);
  *    Further, it is allowed to remove elements during an iteration
  *    including the current one.
  */
-#define nodeset_remove(nset, key)  (ir_node *)pset_remove((nset), (key), nodeset_hash(key))
+static INLINE ir_node *nodeset_remove(nodeset *nset, ir_node *key)
+{
+       return (ir_node *) pset_remove(nset, key, nodeset_hash(key));
+}
 
 /**
  * Returns the first node of a nodeset.
@@ -94,7 +140,10 @@ unsigned nodeset_hash(ir_node *n);
  *
  * @return a node or NULL if the set is empty
  */
-#define nodeset_first(nset)  (ir_node *)pset_first(nset)
+static INLINE ir_node *nodeset_first(nodeset *nset)
+{
+       return (ir_node *) pset_first(nset);
+}
 
 /**
  * Returns the next node of a nodeset.
@@ -103,7 +152,10 @@ unsigned nodeset_hash(ir_node *n);
  *
  * @return a node or NULL if the iteration is finished
  */
-#define nodeset_next(nset)  (ir_node *)pset_next(nset)
+static INLINE ir_node *nodeset_next(nodeset *nset)
+{
+       return (ir_node *) pset_next(nset);
+}
 
 /**
  * Breaks the iteration of a set. Must be called before
@@ -112,6 +164,17 @@ unsigned nodeset_hash(ir_node *n);
  *
  * @param nset  the nodeset
  */
-#define nodeset_break(nset)  pset_break(nset)
+static INLINE void nodeset_break(nodeset *nset)
+{
+       pset_break(nset);
+}
+
+/**
+ * Iterate over a node set.
+ *
+ * @param nset  the nodeset
+ * @param irn   the iterator node
+ */
+#define foreach_nodeset(nset, irn)     for (irn = nodeset_first(nset); irn; irn = nodeset_next(nset))
 
-#endif /* _BENODESETS_H */
+#endif /* FIRM_BE_BENODESETS_H */