1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, Inc.,
10 * 51 Franklin St, Fifth Floor, Boston MA 02110-1301, USA; version 2.1,
11 * or, at your option, any later version, incorporated herein by
14 * Patches submitted to this file are required to be dual licensed
15 * under the LGPL 2.1+ and the 2-clause BSD license:
17 * Copyright 1996-2009 the NASM Authors - All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above
26 * copyright notice, this list of conditions and the following
27 * disclaimer in the documentation and/or other materials provided
28 * with the distribution.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
31 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
32 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
41 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * ----------------------------------------------------------------------- */
49 * Library routines to manipulate expression data types.
55 * Return true if the argument is a simple scalar. (Or a far-
56 * absolute, which counts.)
58 int is_simple(expr
* vect
)
60 while (vect
->type
&& !vect
->value
)
64 if (vect
->type
!= EXPR_SIMPLE
)
68 } while (vect
->type
&& !vect
->value
);
69 if (vect
->type
&& vect
->type
< EXPR_SEGBASE
+ SEG_ABS
)
75 * Return true if the argument is a simple scalar, _NOT_ a far-
78 int is_really_simple(expr
* vect
)
80 while (vect
->type
&& !vect
->value
)
84 if (vect
->type
!= EXPR_SIMPLE
)
88 } while (vect
->type
&& !vect
->value
);
95 * Return true if the argument is relocatable (i.e. a simple
96 * scalar, plus at most one segment-base, plus possibly a WRT).
98 int is_reloc(expr
* vect
)
100 while (vect
->type
&& !vect
->value
) /* skip initial value-0 terms */
102 if (!vect
->type
) /* trivially return true if nothing */
103 return 1; /* is present apart from value-0s */
104 if (vect
->type
< EXPR_SIMPLE
) /* false if a register is present */
106 if (vect
->type
== EXPR_SIMPLE
) { /* skip over a pure number term... */
109 } while (vect
->type
&& !vect
->value
);
110 if (!vect
->type
) /* ...returning true if that's all */
113 if (vect
->type
== EXPR_WRT
) { /* skip over a WRT term... */
116 } while (vect
->type
&& !vect
->value
);
117 if (!vect
->type
) /* ...returning true if that's all */
120 if (vect
->value
!= 0 && vect
->value
!= 1)
121 return 0; /* segment base multiplier non-unity */
122 do { /* skip over _one_ seg-base term... */
124 } while (vect
->type
&& !vect
->value
);
125 if (!vect
->type
) /* ...returning true if that's all */
127 return 0; /* And return false if there's more */
131 * Return true if the argument contains an `unknown' part.
133 int is_unknown(expr
* vect
)
135 while (vect
->type
&& vect
->type
< EXPR_UNKNOWN
)
137 return (vect
->type
== EXPR_UNKNOWN
);
141 * Return true if the argument contains nothing but an `unknown'
144 int is_just_unknown(expr
* vect
)
146 while (vect
->type
&& !vect
->value
)
148 return (vect
->type
== EXPR_UNKNOWN
);
152 * Return the scalar part of a relocatable vector. (Including
153 * simple scalar vectors - those qualify as relocatable.)
155 int64_t reloc_value(expr
* vect
)
157 while (vect
->type
&& !vect
->value
)
161 if (vect
->type
== EXPR_SIMPLE
)
168 * Return the segment number of a relocatable vector, or NO_SEG for
171 int32_t reloc_seg(expr
* vect
)
173 while (vect
->type
&& (vect
->type
== EXPR_WRT
|| !vect
->value
))
175 if (vect
->type
== EXPR_SIMPLE
) {
178 } while (vect
->type
&& (vect
->type
== EXPR_WRT
|| !vect
->value
));
183 return vect
->type
- EXPR_SEGBASE
;
187 * Return the WRT segment number of a relocatable vector, or NO_SEG
188 * if no WRT part is present.
190 int32_t reloc_wrt(expr
* vect
)
192 while (vect
->type
&& vect
->type
< EXPR_WRT
)
194 if (vect
->type
== EXPR_WRT
) {