added edge OVERWRITES in vcg output
[libfirm] / ir / tv / tv.h
1 /* Declarations for Target Values.
2    Copyright (C) 1995, 1996 Christian von Roques
3
4 Discussion of new interface, proposals by Prof. Waite:
5 (email of 13.6.2001)
6 > 1. You say that you plan to replace the tv module.  That replacement is
7 >    absolutely essential for an ANSI C translator:  Section 6.1.3.2 of the
8 >    standard says that the representation of an integer_constant depends
9 >    upon its value as well as any suffixes that are attached to it.  The
10 >    possible Firm modes for such a constant are i, I, l, and L.  The
11 >    current tv module provides only one integer conversion routine, and
12 >    that requires conversion by the client.  Since the type of the value
13 >    argument is long, this may preclude the representation of an unsigned
14 >    long constant.
15 >
16 >    There is a similar problem with floating constants.  Floating
17 >    constants can be suffixed in C, and the mode depends upon the suffix.
18 >    It can indicate that the constant is of type long double, which your
19 >    current tv module is incapable of representing.
20 >
21 >    Your tv module interface accepts two kinds of information: modes and
22 >    values.  Values obtained from the program text might be uninterpreted
23 >    strings, strings interpreted as integers, and strings interpreted as
24 >    reals.  Values provided by the compiler are usually integers.  Modes are
25 >    always Firm modes.  It seems to me that the tv module should provide
26 >    tarval* constructors for three of the four kinds of values.  Each of these
27 >    constructors should have an ir_mode parameter and one or more parameters
28 >    appropriate for the kind of value.  As is currently the case, one
29 >    constructor should be provided for both compiler-generated integers and
30 >    source strings interpreted as integers.  (This avoids problems of
31 >    different conversion radices -- the client does the conversion.)  For
32 >    symmetry, the constructor for source strings interpreted as reals should
33 >    accept a long double parameter and require the client to do the
34 >    conversion.
35
36 */
37
38 #ifndef _TV_H
39 #define _TV_H
40
41 # include "irmode.h"
42 # include "entity.h"
43 # include "bool.h"
44
45 #ifndef _TARVAL_TYPEDEF_
46 #define _TARVAL_TYPEDEF_
47 typedef struct tarval tarval;
48 #endif
49
50 #include "gmp.h"
51 #undef __need_size_t            /* erroneously defined by 1.3.2's gmp.h */
52
53 /* how to represent target types on host */
54 typedef float  tarval_f;
55 typedef double tarval_d;
56 typedef long   tarval_chil;
57 typedef unsigned long tarval_CHIL;
58 typedef MP_INT tarval_Z;
59 typedef struct {
60   /* if ent then xname is missing or mangled from ent,
61      else if xname then xname is a linker symbol that is not mangled
62        from an entity,
63      else this is tarval_p_void.
64      if this tarval describes a symbolic address of another tarval, tv points
65      to this val */
66   const char *xname;
67   entity *ent;
68   tarval *tv;
69 } tarval_p;
70 typedef struct {
71   unsigned char *p;             /* may contain embedded 0, not 0-terminated */
72   size_t n;
73 } tarval_s;
74 typedef tarval_s tarval_B;
75
76 struct tarval {
77   union {
78     tarval_f f;                 /* float */
79     tarval_d d;                 /* double */
80     tarval_chil chil;           /* signed integral */
81     tarval_CHIL CHIL;           /* unsigned integral */
82     tarval_Z Z;                 /* universal int */
83     tarval_p p;                 /* pointer */
84     bool b;                     /* boolean */
85     tarval_B B;                 /* universal bits */
86     tarval_s s;                 /* string */
87   } u;
88   ir_mode *mode;
89 };
90
91 extern tarval *tarval_bad;
92 /* We should have a tarval_undefined */
93 extern tarval *tarval_b_false;
94 extern tarval *tarval_b_true;
95 extern tarval *tarval_d_NaN;
96 extern tarval *tarval_d_Inf;
97 extern tarval *tarval_p_void;
98 extern tarval *tarval_mode_null[];
99 extern tarval *tarval_mode_min[];
100 extern tarval *tarval_mode_max[];
101
102 void tarval_init_1 (void);
103 void tarval_init_2 (void);
104
105 /* Hash function on tarvals */
106 unsigned tarval_hash (tarval *);
107
108 /* ************************ Constructors for tarvals ************************ */
109 tarval *tarval_Z_from_str (const char *, size_t, int base);
110 tarval *tarval_B_from_str (const char *, size_t);
111 tarval *tarval_d_from_str (const char *, size_t);
112 tarval *tarval_s_from_str (const char *, size_t);
113 tarval *tarval_S_from_str (const char *, size_t);
114 tarval *tarval_from_long  (ir_mode *, long);
115 tarval *tarval_p_from_str (const char *);
116 tarval *tarval_p_from_entity (entity *);
117
118 tarval *tarval_convert_to (tarval *, ir_mode *);
119
120 /* Building an irm_C, irm_s, irm_S or irm_B target value step by step. */
121 void tarval_start (void);
122 void tarval_append (const char *, size_t);
123 void tarval_append1 (char);
124 tarval *tarval_finish_as (ir_mode *);
125 tarval *tarval_cancel (void); /* returns tarval_bad */
126
127 \f
128 /* The flags for projecting a comparison result */
129 typedef enum {
130   irpn_False=0,         /* false */
131   irpn_Eq,              /* equal */
132   irpn_Lt,              /* less */
133   irpn_Le,              /* less or equal */
134   irpn_Gt,              /* greater */
135   irpn_Ge,              /* greater of equal */
136   irpn_Lg,              /* less or greater */
137   irpn_Leg,             /* less, equal or greater = ordered */
138   irpn_Uo,              /* unordered */
139   irpn_Ue,              /* unordered or equal */
140   irpn_Ul,              /* unordered or less */
141   irpn_Ule,             /* unordered, less or equal */
142   irpn_Ug,              /* unordered or greater */
143   irpn_Uge,             /* unordered, greater or equal */
144   irpn_Ne,              /* unordered, less or greater = not equal */
145   irpn_True,            /* true */
146   irpn_notmask = irpn_Leg
147 } ir_pncmp;
148
149 /* ******************** Arithmethic operations on tarvals ******************** */
150 /* Compare a with b and return an ir_pncmp describing the relation
151    between a and b.  This is either Uo, Lt, Eq, Gt, or False if a or b
152    are symbolic pointers which can not be compared at all. */
153 ir_pncmp tarval_comp (tarval *a, tarval *b);
154
155 tarval *tarval_neg (tarval *a);
156 tarval *tarval_add (tarval *, tarval *);
157 tarval *tarval_sub (tarval *, tarval *);
158 tarval *tarval_mul (tarval *, tarval *);
159 tarval *tarval_quo (tarval *, tarval *);
160 tarval *tarval_div (tarval *, tarval *);
161 tarval *tarval_mod (tarval *, tarval *);
162 tarval *tarval_abs (tarval *);
163 tarval *tarval_and (tarval *, tarval *);
164 tarval *tarval_or  (tarval *, tarval *);
165 tarval *tarval_eor (tarval *, tarval *);
166 tarval *tarval_shl (tarval *, tarval *);
167 tarval *tarval_shr (tarval *, tarval *);
168
169 /* Identifying some tarvals */
170 long tarval_classify (tarval *);
171 long tarval_ord (tarval *, int *fail);
172
173 /* moved to tv_t.h
174    int tarval_print (XP_PAR1, const xprintf_info *, XP_PARN); */
175
176 /* return a mode-specific value */
177
178 tarval_f tv_val_f (tarval *tv);
179 tarval_d tv_val_d (tarval *tv);
180 tarval_chil tv_val_chil (tarval *tv);
181 tarval_CHIL tv_val_CHIL (tarval *tv);
182 tarval_Z tv_val_Z (tarval *tv);
183 tarval_p tv_val_p (tarval *tv);
184 bool     tv_val_b (tarval *tv);
185 tarval_B tv_val_B (tarval *tv);
186 tarval_s tv_val_s (tarval *tv);
187
188 #ifdef NDEBUG
189 #define TARVAL_VRFY(val) ((void)0)
190 #else
191 #define TARVAL_VRFY(val) _tarval_vrfy ((val))
192 extern void _tarval_vrfy (const tarval *);
193 #endif
194
195 #ifdef STATS
196 void tarval_stats (void);
197 #else
198 #define tarval_stats() ((void)0)
199 #endif
200
201 ir_mode *get_tv_mode (tarval *tv);
202
203 #endif