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 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
37 * Library routines to manipulate expression data types.
43 * Return true if the argument is a simple scalar. (Or a far-
44 * absolute, which counts.)
46 int is_simple(expr * vect)
48 while (vect->type && !vect->value)
52 if (vect->type != EXPR_SIMPLE)
56 } while (vect->type && !vect->value);
57 if (vect->type && vect->type < EXPR_SEGBASE + SEG_ABS)
63 * Return true if the argument is a simple scalar, _NOT_ a far-
66 int is_really_simple(expr * vect)
68 while (vect->type && !vect->value)
72 if (vect->type != EXPR_SIMPLE)
76 } while (vect->type && !vect->value);
83 * Return true if the argument is relocatable (i.e. a simple
84 * scalar, plus at most one segment-base, plus possibly a WRT).
86 int is_reloc(expr * vect)
88 while (vect->type && !vect->value) /* skip initial value-0 terms */
90 if (!vect->type) /* trivially return true if nothing */
91 return 1; /* is present apart from value-0s */
92 if (vect->type < EXPR_SIMPLE) /* false if a register is present */
94 if (vect->type == EXPR_SIMPLE) { /* skip over a pure number term... */
97 } while (vect->type && !vect->value);
98 if (!vect->type) /* ...returning true if that's all */
101 if (vect->type == EXPR_WRT) { /* skip over a WRT term... */
104 } while (vect->type && !vect->value);
105 if (!vect->type) /* ...returning true if that's all */
108 if (vect->value != 0 && vect->value != 1)
109 return 0; /* segment base multiplier non-unity */
110 do { /* skip over _one_ seg-base term... */
112 } while (vect->type && !vect->value);
113 if (!vect->type) /* ...returning true if that's all */
115 return 0; /* And return false if there's more */
119 * Return true if the argument contains an `unknown' part.
121 int is_unknown(expr * vect)
123 while (vect->type && vect->type < EXPR_UNKNOWN)
125 return (vect->type == EXPR_UNKNOWN);
129 * Return true if the argument contains nothing but an `unknown'
132 int is_just_unknown(expr * vect)
134 while (vect->type && !vect->value)
136 return (vect->type == EXPR_UNKNOWN);
140 * Return the scalar part of a relocatable vector. (Including
141 * simple scalar vectors - those qualify as relocatable.)
143 int64_t reloc_value(expr * vect)
145 while (vect->type && !vect->value)
149 if (vect->type == EXPR_SIMPLE)
156 * Return the segment number of a relocatable vector, or NO_SEG for
159 int32_t reloc_seg(expr * vect)
161 while (vect->type && (vect->type == EXPR_WRT || !vect->value))
163 if (vect->type == EXPR_SIMPLE) {
166 } while (vect->type && (vect->type == EXPR_WRT || !vect->value));
171 return vect->type - EXPR_SEGBASE;
175 * Return the WRT segment number of a relocatable vector, or NO_SEG
176 * if no WRT part is present.
178 int32_t reloc_wrt(expr * vect)
180 while (vect->type && vect->type < EXPR_WRT)
182 if (vect->type == EXPR_WRT) {