more tarval cleanup
[libfirm] / ir / tv / tv_t.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  * @brief    Representation of and static computations on target machine
23  *           values -- private header.
24  * @date     2003
25  * @author   Mathias Heil
26  * @version  $Id$
27  */
28 #ifndef FIRM_TV_TV_T_H
29 #define FIRM_TV_TV_T_H
30
31 #include "firm_config.h"
32 #include "firm_common.h"
33
34 #include <assert.h>
35 #include "irmode.h"
36 #include "tv.h"
37
38 /** Debugging aid for the firmEvaluator: Marks for reserved tarvals values. */
39 enum reserved_id {
40         resid_tarval_bad         = 1,  /**< tarval_bad marker. */
41         resid_tarval_undefined   = 2,  /**< tarval_undefined marker. */
42         resid_tarval_b_false     = 3,  /**< tarval_b_false marker. */
43         resid_tarval_b_true      = 4,  /**< tarval_b_true marker. */
44         resid_tarval_unreachable = 5,  /**< tarval_unreachable marker. */
45         resid_tarval_reachable   = 6   /**< tarval_reachable marker. */
46 };
47
48 /**
49  * Initialization of the tarval module.
50  *
51  * Call before init_mode().
52  *
53  * @param null_value
54  *            The reference mode NULL value, typical 0l
55  * @param support_quad_precision
56  *            If non-zero, activate support for quad precision
57  */
58 void init_tarval_1(long null_value, int support_quad_precision);
59
60 /**
61  * Initialization of the tarval module.
62  *
63  * Call after init_mode().
64  */
65 void init_tarval_2(void);
66
67 /**
68  * Free all memory occupied by the tarval module.
69  */
70 void finish_tarval(void);
71
72 /**
73  * This struct represents the afore mentioned tarvals.
74  *
75  * A tarval struct consists of an internal representation of the
76  * value and some additional fields further describing the value.
77  *
78  * ATTRIBUTES:
79  *   - ir_mode *mode     The mode of the stored value
80  *   - void *value       The internal representation
81  *
82  * @sa
83  *   irmode.h for predefined modes
84  */
85 struct tarval {
86         firm_kind kind;         /**< must be k_tarval */
87         ir_mode   *mode;        /**< the mode of the stored value */
88         const void *value;      /**< the value stored in an internal way... */
89         unsigned int length;    /**< the length of the stored value */
90 };
91
92 /* inline functions */
93 /*
94  * Access routines for tarval fields ========================================
95  */
96 static INLINE ir_mode *
97 _get_tarval_mode(const tarval *tv) {
98         assert(tv);
99         return tv->mode;
100 }
101
102 static INLINE tarval *
103 _get_tarval_bad(void) {
104         return tarval_bad;
105 }
106
107 static INLINE tarval *
108 _get_tarval_undefined(void) {
109         return tarval_undefined;
110 }
111
112 static INLINE tarval *
113 _get_tarval_b_false(void) {
114         return tarval_b_false;
115 }
116
117 static INLINE tarval *
118 _get_tarval_b_true(void) {
119         return tarval_b_true;
120 }
121
122 static INLINE tarval *
123 _get_tarval_reachable(void) {
124         return tarval_reachable;
125 }
126
127 static INLINE tarval *
128 _get_tarval_unreachable(void) {
129         return tarval_unreachable;
130 }
131
132 static INLINE int
133 _is_tarval(const void *thing) {
134         return get_kind(thing) == k_tarval;
135 }
136
137 #define get_tarval_mode(tv)      _get_tarval_mode(tv)
138 #define get_tarval_bad()         _get_tarval_bad()
139 #define get_tarval_undefined()   _get_tarval_undefined()
140 #define get_tarval_b_false()     _get_tarval_b_false()
141 #define get_tarval_b_true()      _get_tarval_b_true()
142 #define get_tarval_unreachable() _get_tarval_unreachable()
143 #define get_tarval_reachable()   _get_tarval_reachable()
144 #define get_tarval_P_void()      _get_tarval_P_void()
145 #define is_tarval(thing)         _is_tarval(thing)
146
147 #endif /* FIRM_TV_TV_T_H */