verify that all blocks can be found by walk_block_graph
[libfirm] / ir / ir / iredgeset.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @author    Matthias Braun
23  * @date      12.01.2008
24  * @brief     An edgeset.
25  * @version   $Id$
26  */
27 #ifndef _FIRM_IREDGESET_H_
28 #define _FIRM_IREDGESET_H_
29
30 #include "firm_types.h"
31
32 #define HashSet          ir_edgeset_t
33 #define HashSetIterator  ir_edgeset_iterator_t
34 #define ValueType        ir_edge_t*
35 #define DO_REHASH
36
37 #include "hashset.h"
38
39 #undef DO_REHASH
40 #undef ValueType
41 #undef HashSetIterator
42 #undef HashSet
43
44 typedef struct ir_edgeset_t          ir_edgeset_t;
45 typedef struct ir_edgeset_iterator_t ir_edgeset_iterator_t;
46
47 /**
48  * Initializes a edgeset with default size.
49  *
50  * @param edgeset      Pointer to allocated space for the edgeset
51  */
52 void ir_edgeset_init(ir_edgeset_t *edgeset);
53
54 /**
55  * Destroys a edgeset and frees the memory allocated for hashtable. The memory of
56  * the edgeset itself is not freed.
57  *
58  * @param edgeset   Pointer to the edgeset
59  */
60 void ir_edgeset_destroy(ir_edgeset_t *edgeset);
61
62 /**
63  * Inserts a edge into a edgeset.
64  *
65  * @param edgeset   Pointer to the edgeset
66  * @param edge      edge to insert into the edgeset
67  */
68 ir_edge_t *ir_edgeset_insert(ir_edgeset_t *edgeset, ir_edge_t *edge);
69
70
71 /**
72  * Removes a edge from a edgeset. Does nothing if the edgeset doesn't contain
73  * the edge.
74  *
75  * @param edgeset  Pointer to the edgeset
76  * @param edge     Node to remove from the edgeset
77  */
78 void ir_edgeset_remove(ir_edgeset_t *edgeset, const ir_edge_t *edge);
79
80 /**
81  * Tests whether a edgeset contains a specific edge
82  *
83  * @param edgeset   Pointer to the edgeset
84  * @param edge      The pointer to find
85  * @returns         1 if edgeset contains the edge, 0 else
86  */
87 int ir_edgeset_contains(const ir_edgeset_t *edgeset, const ir_edge_t *edge);
88
89 /**
90  * Initializes a edgeset iterator. Sets the iterator before the first element in
91  * the edgeset.
92  *
93  * @param iterator   Pointer to already allocated iterator memory
94  * @param edgeset       Pointer to the edgeset
95  */
96 void ir_edgeset_iterator_init(ir_edgeset_iterator_t *iterator,
97                               const ir_edgeset_t *edgeset);
98
99 /**
100  * Advances the iterator and returns the current element or NULL if all elements
101  * in the edgeset have been processed.
102  * @attention It is not allowed to use edgeset_insert or edgeset_remove while
103  *            iterating over a edgeset.
104  *
105  * @param iterator  Pointer to the edgeset iterator.
106  * @returns         Next element in the edgeset or NULL
107  */
108 ir_edge_t *ir_edgeset_iterator_next(ir_edgeset_iterator_t *iterator);
109
110 /**
111  * Removes the element the iterator currently points to
112  *
113  * @param edgeset   Pointer to the edgeset
114  * @param iterator  Pointer to the edgeset iterator.
115  */
116 void ir_edgeset_remove_iterator(ir_edgeset_t *edgeset,
117                                 const ir_edgeset_iterator_t *iterator);
118
119 #define foreach_ir_edgeset(edgeset, edge, iter) \
120         for(ir_edgeset_iterator_init(&iter, edgeset), \
121         edge = ir_edgeset_iterator_next(&iter);    \
122                 edge != NULL; edge = ir_edgeset_iterator_next(&iter))
123
124 #endif