move backend into libfirm
[libfirm] / ir / common / irtools.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irtools.h
4  * Purpose:     Some often needed tool-functions
5  * Author:      Michael Beck
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2006 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12 #ifndef _FIRM_COMMON_IRTOOLS_H_
13 #define _FIRM_COMMON_IRTOOLS_H_
14
15 #include "firm_config.h"
16 #include "firm_types.h"
17
18 #ifdef WITH_LIBCORE
19 #include <libcore/lc_opts.h>
20 lc_opt_entry_t *firm_opt_get_root(void);
21 #endif
22
23 #include "pset.h"
24
25 #undef MIN
26 #undef MAX
27 #define MAX(x, y) ((x) > (y) ? (x) : (y))
28 #define MIN(x, y) ((x) < (y) ? (x) : (y))
29
30 /**
31  * Three valued compare as demanded by e.g. qsort(3)
32  * @param c A number.
33  * @param d Another number.
34  * @return 0 if c == d, -1 if c < d, 1 if c > d.
35  */
36 #define QSORT_CMP(c, d) (((c) > (d)) - ((c) < (d)))
37
38
39 /**
40  * convert an integer into pointer
41  */
42 #define INT_TO_PTR(v)   ((void *)((char *)0 + (v)))
43
44 /**
45  * convert a pointer into an integer
46  */
47 #define PTR_TO_INT(v)   ((int)((char *)(v) - (char *)0))
48
49 /**
50  * Dump a pset containing Firm objects.
51  */
52 void firm_pset_dump(pset *set);
53
54 /**
55  * The famous clear_link() walker-function.
56  * Do not implement it by yourself, use this one
57  */
58 void firm_clear_link(ir_node *n, void *env);
59
60 /**
61  * Copies a node to a new irg. The Ins of the new node point to
62  * the predecessors on the old irg.  n->link points to the new node.
63  *
64  * @param n    The node to be copied
65  * @param irg  the new irg
66  *
67  * Does NOT copy standard nodes like Start, End etc that are fixed
68  * in an irg. Instead, the corresponding nodes of the new irg are returned.
69  * Note further, that the new nodes have no block.
70  */
71 void copy_irn_to_irg(ir_node *n, ir_graph *irg);
72
73 /**
74  * Creates an exact copy of a node.
75  * The copy resists on the same graph in the same block.
76  *
77  * @param n   the node to copy
78  *
79  * @note If the copy is not changed, the next CSE operation will
80  *       replace it by the original, so beware.
81  */
82 ir_node *exact_copy(const ir_node *n);
83
84 #endif /* _FIRM_COMMON_IRTOOLS_H_ */