Fixed size_t related warnings.
[libfirm] / ir / common / irtools.h
1 /*
2  * Copyright (C) 1995-2011 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  * @brief     Some often needed tool-functions
23  * @author    Michael Beck
24  * @version   $Id$
25  */
26 #ifndef FIRM_COMMON_IRTOOLS_H
27 #define FIRM_COMMON_IRTOOLS_H
28
29 #include "firm_types.h"
30
31 #include "lc_opts.h"
32 lc_opt_entry_t *firm_opt_get_root(void);
33
34 #include "pset.h"
35
36 #undef MIN
37 #undef MAX
38 #define MAX(x, y) ((x) > (y) ? (x) : (y))
39 #define MIN(x, y) ((x) < (y) ? (x) : (y))
40
41 /* calculate the address of the one past last element of an array whose size is
42  * known statically */
43 #define ENDOF(x) ((x) + sizeof(x) / sizeof(*(x)))
44
45 /**
46  * Three valued compare as demanded by e.g. qsort(3)
47  * @param c A number.
48  * @param d Another number.
49  * @return 0 if c == d, -1 if c < d, 1 if c > d.
50  */
51 #define QSORT_CMP(c, d) (((c) > (d)) - ((c) < (d)))
52
53
54 /**
55  * convert an integer into pointer
56  */
57 #define INT_TO_PTR(v)   ((void *)((char *)0 + (v)))
58
59 /**
60  * convert a pointer into an integer
61  */
62 #define PTR_TO_INT(v)   (((char *)(v) - (char *)0))
63
64 /**
65  * Dump a pset containing Firm objects.
66  */
67 void firm_pset_dump(pset *set);
68
69 /**
70  * The famous clear_link() walker-function.
71  * Sets all links fields of visited nodes to NULL.
72  * Do not implement it by yourself, use this one.
73  */
74 void firm_clear_link(ir_node *n, void *env);
75
76 /**
77  * The famous clear_link_and_block_lists() walker-function.
78  * Sets all links fields of visited nodes to NULL.
79  * Additionally, clear all Phi-lists of visited blocks.
80  * Do not implement it by yourself, use this one
81  */
82 void firm_clear_node_and_phi_links(ir_node *n, void *env);
83
84 /**
85  * Creates an exact copy of a node with same inputs and attributes in the
86  * same block.
87  *
88  * @param node   the node to copy
89  */
90 ir_node *exact_copy(const ir_node *node);
91
92 /**
93  * Create an exact copy of a node with same inputs and attributes in the same
94  * block but puts the node on a graph which might be different than the graph
95  * of the original node.
96  * Note: You have to fixup the inputs/block later
97  */
98 ir_node *irn_copy_into_irg(const ir_node *node, ir_graph *irg);
99
100 /**
101  * This is a helper function used by some routines copying irg graphs
102  * This assumes that we have "old" nodes which have been copied to "new"
103  * nodes; The inputs of the new nodes still point to old nodes.
104  *
105  * Given an old(!) node this function rewires the matching new_node
106  * so that all its inputs point to new nodes afterwards.
107  */
108 void irn_rewire_inputs(ir_node *node);
109
110 /**
111  * @deprecated
112  * Copies a node to a new irg. The Ins of the new node point to
113  * the predecessors on the old irg.  n->link points to the new node.
114  *
115  * @param n    The node to be copied
116  * @param irg  the new irg
117  *
118  * Does NOT copy standard nodes like Start, End etc that are fixed
119  * in an irg. Instead, the corresponding nodes of the new irg are returned.
120  * Note further, that the new nodes have no block.
121  */
122 void copy_irn_to_irg(ir_node *n, ir_graph *irg);
123
124 #endif