]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* expr.c -operands, expressions- |
f7e42eb4 | 2 | Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
08ea7020 AM |
3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, |
4 | 2012 Free Software Foundation, Inc. | |
252b5132 RH |
5 | |
6 | This file is part of GAS, the GNU Assembler. | |
7 | ||
8 | GAS is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 10 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
11 | any later version. |
12 | ||
13 | GAS is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
20 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
21 | 02110-1301, USA. */ | |
252b5132 | 22 | |
929b12bc KH |
23 | /* This is really a branch office of as-read.c. I split it out to clearly |
24 | distinguish the world of expressions from the world of statements. | |
25 | (It also gives smaller files to re-compile.) | |
26 | Here, "operand"s are of expressions, not instructions. */ | |
252b5132 | 27 | |
252b5132 RH |
28 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
29 | ||
30 | #include "as.h" | |
3882b010 | 31 | #include "safe-ctype.h" |
252b5132 RH |
32 | #include "obstack.h" |
33 | ||
d85733c8 JB |
34 | #ifdef HAVE_LIMITS_H |
35 | #include <limits.h> | |
36 | #endif | |
37 | #ifndef CHAR_BIT | |
38 | #define CHAR_BIT 8 | |
39 | #endif | |
40 | ||
dd625418 KH |
41 | static void floating_constant (expressionS * expressionP); |
42 | static valueT generic_bignum_to_int32 (void); | |
6d4d30bb | 43 | #ifdef BFD64 |
dd625418 | 44 | static valueT generic_bignum_to_int64 (void); |
6d4d30bb | 45 | #endif |
dd625418 KH |
46 | static void integer_constant (int radix, expressionS * expressionP); |
47 | static void mri_char_constant (expressionS *); | |
dd625418 | 48 | static void clean_up_expression (expressionS * expressionP); |
9497f5ac | 49 | static segT operand (expressionS *, enum expr_mode); |
1e9cc1c2 | 50 | static operatorT operatorf (int *); |
252b5132 RH |
51 | |
52 | extern const char EXP_CHARS[], FLT_CHARS[]; | |
53 | ||
54 | /* We keep a mapping of expression symbols to file positions, so that | |
55 | we can provide better error messages. */ | |
56 | ||
e6c774b4 | 57 | struct expr_symbol_line { |
252b5132 RH |
58 | struct expr_symbol_line *next; |
59 | symbolS *sym; | |
60 | char *file; | |
61 | unsigned int line; | |
62 | }; | |
63 | ||
64 | static struct expr_symbol_line *expr_symbol_lines; | |
65 | \f | |
66 | /* Build a dummy symbol to hold a complex expression. This is how we | |
67 | build expressions up out of other expressions. The symbol is put | |
68 | into the fake section expr_section. */ | |
69 | ||
70 | symbolS * | |
dd625418 | 71 | make_expr_symbol (expressionS *expressionP) |
252b5132 RH |
72 | { |
73 | expressionS zero; | |
252b5132 RH |
74 | symbolS *symbolP; |
75 | struct expr_symbol_line *n; | |
76 | ||
77 | if (expressionP->X_op == O_symbol | |
78 | && expressionP->X_add_number == 0) | |
79 | return expressionP->X_add_symbol; | |
80 | ||
81 | if (expressionP->X_op == O_big) | |
82 | { | |
83 | /* This won't work, because the actual value is stored in | |
02000999 AM |
84 | generic_floating_point_number or generic_bignum, and we are |
85 | going to lose it if we haven't already. */ | |
252b5132 | 86 | if (expressionP->X_add_number > 0) |
0e389e77 | 87 | as_bad (_("bignum invalid")); |
252b5132 | 88 | else |
0e389e77 | 89 | as_bad (_("floating point number invalid")); |
252b5132 RH |
90 | zero.X_op = O_constant; |
91 | zero.X_add_number = 0; | |
92 | zero.X_unsigned = 0; | |
93 | clean_up_expression (&zero); | |
94 | expressionP = &zero; | |
95 | } | |
96 | ||
252b5132 RH |
97 | /* Putting constant symbols in absolute_section rather than |
98 | expr_section is convenient for the old a.out code, for which | |
99 | S_GET_SEGMENT does not always retrieve the value put in by | |
100 | S_SET_SEGMENT. */ | |
756d1d01 | 101 | symbolP = symbol_create (FAKE_LABEL_NAME, |
252b5132 RH |
102 | (expressionP->X_op == O_constant |
103 | ? absolute_section | |
5a918ce7 JB |
104 | : expressionP->X_op == O_register |
105 | ? reg_section | |
106 | : expr_section), | |
252b5132 | 107 | 0, &zero_address_frag); |
49309057 | 108 | symbol_set_value_expression (symbolP, expressionP); |
252b5132 RH |
109 | |
110 | if (expressionP->X_op == O_constant) | |
6386f3a7 | 111 | resolve_symbol_value (symbolP); |
252b5132 RH |
112 | |
113 | n = (struct expr_symbol_line *) xmalloc (sizeof *n); | |
114 | n->sym = symbolP; | |
115 | as_where (&n->file, &n->line); | |
116 | n->next = expr_symbol_lines; | |
117 | expr_symbol_lines = n; | |
118 | ||
119 | return symbolP; | |
120 | } | |
121 | ||
122 | /* Return the file and line number for an expr symbol. Return | |
123 | non-zero if something was found, 0 if no information is known for | |
124 | the symbol. */ | |
125 | ||
126 | int | |
dd625418 | 127 | expr_symbol_where (symbolS *sym, char **pfile, unsigned int *pline) |
252b5132 RH |
128 | { |
129 | register struct expr_symbol_line *l; | |
130 | ||
131 | for (l = expr_symbol_lines; l != NULL; l = l->next) | |
132 | { | |
133 | if (l->sym == sym) | |
134 | { | |
135 | *pfile = l->file; | |
136 | *pline = l->line; | |
137 | return 1; | |
138 | } | |
139 | } | |
140 | ||
141 | return 0; | |
142 | } | |
143 | \f | |
144 | /* Utilities for building expressions. | |
145 | Since complex expressions are recorded as symbols for use in other | |
146 | expressions these return a symbolS * and not an expressionS *. | |
147 | These explicitly do not take an "add_number" argument. */ | |
148 | /* ??? For completeness' sake one might want expr_build_symbol. | |
149 | It would just return its argument. */ | |
150 | ||
151 | /* Build an expression for an unsigned constant. | |
152 | The corresponding one for signed constants is missing because | |
153 | there's currently no need for it. One could add an unsigned_p flag | |
154 | but that seems more clumsy. */ | |
155 | ||
156 | symbolS * | |
dd625418 | 157 | expr_build_uconstant (offsetT value) |
252b5132 RH |
158 | { |
159 | expressionS e; | |
160 | ||
161 | e.X_op = O_constant; | |
162 | e.X_add_number = value; | |
163 | e.X_unsigned = 1; | |
164 | return make_expr_symbol (&e); | |
165 | } | |
166 | ||
252b5132 RH |
167 | /* Build an expression for the current location ('.'). */ |
168 | ||
169 | symbolS * | |
dd625418 | 170 | expr_build_dot (void) |
252b5132 RH |
171 | { |
172 | expressionS e; | |
173 | ||
174 | current_location (&e); | |
e66a3432 | 175 | return symbol_clone_if_forward_ref (make_expr_symbol (&e)); |
252b5132 RH |
176 | } |
177 | \f | |
929b12bc KH |
178 | /* Build any floating-point literal here. |
179 | Also build any bignum literal here. */ | |
252b5132 RH |
180 | |
181 | /* Seems atof_machine can backscan through generic_bignum and hit whatever | |
182 | happens to be loaded before it in memory. And its way too complicated | |
183 | for me to fix right. Thus a hack. JF: Just make generic_bignum bigger, | |
184 | and never write into the early words, thus they'll always be zero. | |
185 | I hate Dean's floating-point code. Bleh. */ | |
186 | LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6]; | |
e6c774b4 KH |
187 | |
188 | FLONUM_TYPE generic_floating_point_number = { | |
bc4466dc KH |
189 | &generic_bignum[6], /* low. (JF: Was 0) */ |
190 | &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high. JF: (added +6) */ | |
191 | 0, /* leader. */ | |
192 | 0, /* exponent. */ | |
193 | 0 /* sign. */ | |
252b5132 | 194 | }; |
929b12bc | 195 | |
252b5132 RH |
196 | \f |
197 | static void | |
dd625418 | 198 | floating_constant (expressionS *expressionP) |
252b5132 | 199 | { |
929b12bc | 200 | /* input_line_pointer -> floating-point constant. */ |
252b5132 RH |
201 | int error_code; |
202 | ||
203 | error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS, | |
204 | &generic_floating_point_number); | |
205 | ||
206 | if (error_code) | |
207 | { | |
208 | if (error_code == ERROR_EXPONENT_OVERFLOW) | |
209 | { | |
0e389e77 | 210 | as_bad (_("bad floating-point constant: exponent overflow")); |
252b5132 RH |
211 | } |
212 | else | |
213 | { | |
0e389e77 AM |
214 | as_bad (_("bad floating-point constant: unknown error code=%d"), |
215 | error_code); | |
252b5132 RH |
216 | } |
217 | } | |
218 | expressionP->X_op = O_big; | |
929b12bc KH |
219 | /* input_line_pointer -> just after constant, which may point to |
220 | whitespace. */ | |
252b5132 RH |
221 | expressionP->X_add_number = -1; |
222 | } | |
223 | ||
929b12bc | 224 | static valueT |
dd625418 | 225 | generic_bignum_to_int32 (void) |
252b5132 RH |
226 | { |
227 | valueT number = | |
228 | ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) | |
229 | | (generic_bignum[0] & LITTLENUM_MASK); | |
230 | number &= 0xffffffff; | |
231 | return number; | |
232 | } | |
233 | ||
234 | #ifdef BFD64 | |
929b12bc | 235 | static valueT |
dd625418 | 236 | generic_bignum_to_int64 (void) |
252b5132 | 237 | { |
929b12bc KH |
238 | valueT number = |
239 | ((((((((valueT) generic_bignum[3] & LITTLENUM_MASK) | |
240 | << LITTLENUM_NUMBER_OF_BITS) | |
241 | | ((valueT) generic_bignum[2] & LITTLENUM_MASK)) | |
242 | << LITTLENUM_NUMBER_OF_BITS) | |
243 | | ((valueT) generic_bignum[1] & LITTLENUM_MASK)) | |
244 | << LITTLENUM_NUMBER_OF_BITS) | |
245 | | ((valueT) generic_bignum[0] & LITTLENUM_MASK)); | |
252b5132 RH |
246 | return number; |
247 | } | |
248 | #endif | |
249 | ||
250 | static void | |
dd625418 | 251 | integer_constant (int radix, expressionS *expressionP) |
252b5132 | 252 | { |
929b12bc | 253 | char *start; /* Start of number. */ |
252b5132 RH |
254 | char *suffix = NULL; |
255 | char c; | |
929b12bc KH |
256 | valueT number; /* Offset or (absolute) value. */ |
257 | short int digit; /* Value of next digit in current radix. */ | |
258 | short int maxdig = 0; /* Highest permitted digit value. */ | |
259 | int too_many_digits = 0; /* If we see >= this number of. */ | |
260 | char *name; /* Points to name of symbol. */ | |
261 | symbolS *symbolP; /* Points to symbol. */ | |
252b5132 | 262 | |
929b12bc | 263 | int small; /* True if fits in 32 bits. */ |
252b5132 | 264 | |
929b12bc | 265 | /* May be bignum, or may fit in 32 bits. */ |
252b5132 RH |
266 | /* Most numbers fit into 32 bits, and we want this case to be fast. |
267 | so we pretend it will fit into 32 bits. If, after making up a 32 | |
268 | bit number, we realise that we have scanned more digits than | |
269 | comfortably fit into 32 bits, we re-scan the digits coding them | |
270 | into a bignum. For decimal and octal numbers we are | |
271 | conservative: Some numbers may be assumed bignums when in fact | |
272 | they do fit into 32 bits. Numbers of any radix can have excess | |
273 | leading zeros: We strive to recognise this and cast them back | |
274 | into 32 bits. We must check that the bignum really is more than | |
275 | 32 bits, and change it back to a 32-bit number if it fits. The | |
276 | number we are looking for is expected to be positive, but if it | |
277 | fits into 32 bits as an unsigned number, we let it be a 32-bit | |
929b12bc | 278 | number. The cavalier approach is for speed in ordinary cases. */ |
252b5132 RH |
279 | /* This has been extended for 64 bits. We blindly assume that if |
280 | you're compiling in 64-bit mode, the target is a 64-bit machine. | |
281 | This should be cleaned up. */ | |
282 | ||
283 | #ifdef BFD64 | |
284 | #define valuesize 64 | |
285 | #else /* includes non-bfd case, mostly */ | |
286 | #define valuesize 32 | |
287 | #endif | |
288 | ||
f805106c | 289 | if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0) |
252b5132 RH |
290 | { |
291 | int flt = 0; | |
292 | ||
293 | /* In MRI mode, the number may have a suffix indicating the | |
02000999 AM |
294 | radix. For that matter, it might actually be a floating |
295 | point constant. */ | |
3882b010 | 296 | for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++) |
252b5132 RH |
297 | { |
298 | if (*suffix == 'e' || *suffix == 'E') | |
299 | flt = 1; | |
300 | } | |
301 | ||
302 | if (suffix == input_line_pointer) | |
303 | { | |
304 | radix = 10; | |
305 | suffix = NULL; | |
306 | } | |
307 | else | |
308 | { | |
309 | c = *--suffix; | |
3882b010 | 310 | c = TOUPPER (c); |
fee9cbc7 AM |
311 | /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB, |
312 | we distinguish between 'B' and 'b'. This is the case for | |
313 | Z80. */ | |
314 | if ((NUMBERS_WITH_SUFFIX && LOCAL_LABELS_FB ? *suffix : c) == 'B') | |
252b5132 RH |
315 | radix = 2; |
316 | else if (c == 'D') | |
317 | radix = 10; | |
318 | else if (c == 'O' || c == 'Q') | |
319 | radix = 8; | |
320 | else if (c == 'H') | |
321 | radix = 16; | |
322 | else if (suffix[1] == '.' || c == 'E' || flt) | |
323 | { | |
324 | floating_constant (expressionP); | |
325 | return; | |
326 | } | |
327 | else | |
328 | { | |
329 | radix = 10; | |
330 | suffix = NULL; | |
331 | } | |
332 | } | |
333 | } | |
334 | ||
335 | switch (radix) | |
336 | { | |
337 | case 2: | |
338 | maxdig = 2; | |
339 | too_many_digits = valuesize + 1; | |
340 | break; | |
341 | case 8: | |
342 | maxdig = radix = 8; | |
343 | too_many_digits = (valuesize + 2) / 3 + 1; | |
344 | break; | |
345 | case 16: | |
346 | maxdig = radix = 16; | |
347 | too_many_digits = (valuesize + 3) / 4 + 1; | |
348 | break; | |
349 | case 10: | |
350 | maxdig = radix = 10; | |
929b12bc | 351 | too_many_digits = (valuesize + 11) / 4; /* Very rough. */ |
252b5132 RH |
352 | } |
353 | #undef valuesize | |
354 | start = input_line_pointer; | |
355 | c = *input_line_pointer++; | |
356 | for (number = 0; | |
357 | (digit = hex_value (c)) < maxdig; | |
358 | c = *input_line_pointer++) | |
359 | { | |
360 | number = number * radix + digit; | |
361 | } | |
929b12bc KH |
362 | /* c contains character after number. */ |
363 | /* input_line_pointer->char after c. */ | |
252b5132 RH |
364 | small = (input_line_pointer - start - 1) < too_many_digits; |
365 | ||
929b12bc | 366 | if (radix == 16 && c == '_') |
252b5132 RH |
367 | { |
368 | /* This is literal of the form 0x333_0_12345678_1. | |
02000999 | 369 | This example is equivalent to 0x00000333000000001234567800000001. */ |
252b5132 RH |
370 | |
371 | int num_little_digits = 0; | |
372 | int i; | |
929b12bc | 373 | input_line_pointer = start; /* -> 1st digit. */ |
252b5132 RH |
374 | |
375 | know (LITTLENUM_NUMBER_OF_BITS == 16); | |
376 | ||
929b12bc | 377 | for (c = '_'; c == '_'; num_little_digits += 2) |
252b5132 RH |
378 | { |
379 | ||
929b12bc KH |
380 | /* Convert one 64-bit word. */ |
381 | int ndigit = 0; | |
252b5132 RH |
382 | number = 0; |
383 | for (c = *input_line_pointer++; | |
384 | (digit = hex_value (c)) < maxdig; | |
385 | c = *(input_line_pointer++)) | |
386 | { | |
387 | number = number * radix + digit; | |
388 | ndigit++; | |
389 | } | |
390 | ||
391 | /* Check for 8 digit per word max. */ | |
929b12bc | 392 | if (ndigit > 8) |
0e389e77 | 393 | as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word")); |
252b5132 | 394 | |
929b12bc KH |
395 | /* Add this chunk to the bignum. |
396 | Shift things down 2 little digits. */ | |
252b5132 | 397 | know (LITTLENUM_NUMBER_OF_BITS == 16); |
929b12bc KH |
398 | for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1); |
399 | i >= 2; | |
400 | i--) | |
401 | generic_bignum[i] = generic_bignum[i - 2]; | |
252b5132 | 402 | |
929b12bc | 403 | /* Add the new digits as the least significant new ones. */ |
252b5132 RH |
404 | generic_bignum[0] = number & 0xffffffff; |
405 | generic_bignum[1] = number >> 16; | |
406 | } | |
407 | ||
929b12bc | 408 | /* Again, c is char after number, input_line_pointer->after c. */ |
252b5132 RH |
409 | |
410 | if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1) | |
411 | num_little_digits = SIZE_OF_LARGE_NUMBER - 1; | |
412 | ||
9c2799c2 | 413 | gas_assert (num_little_digits >= 4); |
252b5132 RH |
414 | |
415 | if (num_little_digits != 8) | |
0e389e77 | 416 | as_bad (_("a bignum with underscores must have exactly 4 words")); |
252b5132 RH |
417 | |
418 | /* We might have some leading zeros. These can be trimmed to give | |
929b12bc KH |
419 | us a change to fit this constant into a small number. */ |
420 | while (generic_bignum[num_little_digits - 1] == 0 | |
421 | && num_little_digits > 1) | |
252b5132 | 422 | num_little_digits--; |
929b12bc | 423 | |
252b5132 RH |
424 | if (num_little_digits <= 2) |
425 | { | |
929b12bc | 426 | /* will fit into 32 bits. */ |
252b5132 RH |
427 | number = generic_bignum_to_int32 (); |
428 | small = 1; | |
429 | } | |
430 | #ifdef BFD64 | |
431 | else if (num_little_digits <= 4) | |
432 | { | |
433 | /* Will fit into 64 bits. */ | |
434 | number = generic_bignum_to_int64 (); | |
435 | small = 1; | |
436 | } | |
437 | #endif | |
438 | else | |
439 | { | |
440 | small = 0; | |
929b12bc KH |
441 | |
442 | /* Number of littlenums in the bignum. */ | |
443 | number = num_little_digits; | |
252b5132 RH |
444 | } |
445 | } | |
446 | else if (!small) | |
447 | { | |
929b12bc KH |
448 | /* We saw a lot of digits. manufacture a bignum the hard way. */ |
449 | LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum. */ | |
450 | LITTLENUM_TYPE *pointer; /* -> littlenum we are frobbing now. */ | |
252b5132 RH |
451 | long carry; |
452 | ||
453 | leader = generic_bignum; | |
454 | generic_bignum[0] = 0; | |
455 | generic_bignum[1] = 0; | |
456 | generic_bignum[2] = 0; | |
457 | generic_bignum[3] = 0; | |
929b12bc | 458 | input_line_pointer = start; /* -> 1st digit. */ |
252b5132 | 459 | c = *input_line_pointer++; |
929b12bc | 460 | for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++) |
252b5132 | 461 | { |
929b12bc | 462 | for (pointer = generic_bignum; pointer <= leader; pointer++) |
252b5132 RH |
463 | { |
464 | long work; | |
465 | ||
466 | work = carry + radix * *pointer; | |
467 | *pointer = work & LITTLENUM_MASK; | |
468 | carry = work >> LITTLENUM_NUMBER_OF_BITS; | |
469 | } | |
470 | if (carry) | |
471 | { | |
472 | if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1) | |
473 | { | |
929b12bc | 474 | /* Room to grow a longer bignum. */ |
252b5132 RH |
475 | *++leader = carry; |
476 | } | |
477 | } | |
478 | } | |
929b12bc KH |
479 | /* Again, c is char after number. */ |
480 | /* input_line_pointer -> after c. */ | |
252b5132 RH |
481 | know (LITTLENUM_NUMBER_OF_BITS == 16); |
482 | if (leader < generic_bignum + 2) | |
483 | { | |
929b12bc | 484 | /* Will fit into 32 bits. */ |
252b5132 RH |
485 | number = generic_bignum_to_int32 (); |
486 | small = 1; | |
487 | } | |
488 | #ifdef BFD64 | |
489 | else if (leader < generic_bignum + 4) | |
490 | { | |
491 | /* Will fit into 64 bits. */ | |
492 | number = generic_bignum_to_int64 (); | |
493 | small = 1; | |
494 | } | |
495 | #endif | |
496 | else | |
497 | { | |
929b12bc KH |
498 | /* Number of littlenums in the bignum. */ |
499 | number = leader - generic_bignum + 1; | |
252b5132 RH |
500 | } |
501 | } | |
502 | ||
60bcf0fa NC |
503 | if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) |
504 | && suffix != NULL | |
f805106c | 505 | && input_line_pointer - 1 == suffix) |
252b5132 RH |
506 | c = *input_line_pointer++; |
507 | ||
508 | if (small) | |
509 | { | |
929b12bc KH |
510 | /* Here with number, in correct radix. c is the next char. |
511 | Note that unlike un*x, we allow "011f" "0x9f" to both mean | |
512 | the same as the (conventional) "9f". | |
513 | This is simply easier than checking for strict canonical | |
514 | form. Syntax sux! */ | |
252b5132 RH |
515 | |
516 | if (LOCAL_LABELS_FB && c == 'b') | |
517 | { | |
929b12bc KH |
518 | /* Backward ref to local label. |
519 | Because it is backward, expect it to be defined. */ | |
252b5132 RH |
520 | /* Construct a local label. */ |
521 | name = fb_label_name ((int) number, 0); | |
522 | ||
929b12bc | 523 | /* Seen before, or symbol is defined: OK. */ |
252b5132 RH |
524 | symbolP = symbol_find (name); |
525 | if ((symbolP != NULL) && (S_IS_DEFINED (symbolP))) | |
526 | { | |
929b12bc KH |
527 | /* Local labels are never absolute. Don't waste time |
528 | checking absoluteness. */ | |
252b5132 RH |
529 | know (SEG_NORMAL (S_GET_SEGMENT (symbolP))); |
530 | ||
531 | expressionP->X_op = O_symbol; | |
532 | expressionP->X_add_symbol = symbolP; | |
533 | } | |
534 | else | |
535 | { | |
929b12bc | 536 | /* Either not seen or not defined. */ |
252b5132 RH |
537 | /* @@ Should print out the original string instead of |
538 | the parsed number. */ | |
0e389e77 | 539 | as_bad (_("backward ref to unknown label \"%d:\""), |
252b5132 RH |
540 | (int) number); |
541 | expressionP->X_op = O_constant; | |
542 | } | |
543 | ||
544 | expressionP->X_add_number = 0; | |
545 | } /* case 'b' */ | |
546 | else if (LOCAL_LABELS_FB && c == 'f') | |
547 | { | |
929b12bc KH |
548 | /* Forward reference. Expect symbol to be undefined or |
549 | unknown. undefined: seen it before. unknown: never seen | |
550 | it before. | |
551 | ||
552 | Construct a local label name, then an undefined symbol. | |
553 | Don't create a xseg frag for it: caller may do that. | |
554 | Just return it as never seen before. */ | |
252b5132 RH |
555 | name = fb_label_name ((int) number, 1); |
556 | symbolP = symbol_find_or_make (name); | |
929b12bc | 557 | /* We have no need to check symbol properties. */ |
252b5132 | 558 | #ifndef many_segments |
929b12bc | 559 | /* Since "know" puts its arg into a "string", we |
252b5132 RH |
560 | can't have newlines in the argument. */ |
561 | know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section); | |
562 | #endif | |
563 | expressionP->X_op = O_symbol; | |
564 | expressionP->X_add_symbol = symbolP; | |
565 | expressionP->X_add_number = 0; | |
566 | } /* case 'f' */ | |
567 | else if (LOCAL_LABELS_DOLLAR && c == '$') | |
568 | { | |
569 | /* If the dollar label is *currently* defined, then this is just | |
570 | another reference to it. If it is not *currently* defined, | |
571 | then this is a fresh instantiation of that number, so create | |
572 | it. */ | |
573 | ||
574 | if (dollar_label_defined ((long) number)) | |
575 | { | |
576 | name = dollar_label_name ((long) number, 0); | |
577 | symbolP = symbol_find (name); | |
578 | know (symbolP != NULL); | |
579 | } | |
580 | else | |
581 | { | |
582 | name = dollar_label_name ((long) number, 1); | |
583 | symbolP = symbol_find_or_make (name); | |
584 | } | |
585 | ||
586 | expressionP->X_op = O_symbol; | |
587 | expressionP->X_add_symbol = symbolP; | |
588 | expressionP->X_add_number = 0; | |
589 | } /* case '$' */ | |
590 | else | |
591 | { | |
592 | expressionP->X_op = O_constant; | |
252b5132 | 593 | expressionP->X_add_number = number; |
bc4466dc | 594 | input_line_pointer--; /* Restore following character. */ |
929b12bc | 595 | } /* Really just a number. */ |
252b5132 RH |
596 | } |
597 | else | |
598 | { | |
bc4466dc | 599 | /* Not a small number. */ |
252b5132 | 600 | expressionP->X_op = O_big; |
929b12bc KH |
601 | expressionP->X_add_number = number; /* Number of littlenums. */ |
602 | input_line_pointer--; /* -> char following number. */ | |
252b5132 RH |
603 | } |
604 | } | |
605 | ||
606 | /* Parse an MRI multi character constant. */ | |
607 | ||
608 | static void | |
dd625418 | 609 | mri_char_constant (expressionS *expressionP) |
252b5132 RH |
610 | { |
611 | int i; | |
612 | ||
613 | if (*input_line_pointer == '\'' | |
614 | && input_line_pointer[1] != '\'') | |
615 | { | |
616 | expressionP->X_op = O_constant; | |
617 | expressionP->X_add_number = 0; | |
618 | return; | |
619 | } | |
620 | ||
621 | /* In order to get the correct byte ordering, we must build the | |
622 | number in reverse. */ | |
623 | for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--) | |
624 | { | |
625 | int j; | |
626 | ||
627 | generic_bignum[i] = 0; | |
628 | for (j = 0; j < CHARS_PER_LITTLENUM; j++) | |
629 | { | |
630 | if (*input_line_pointer == '\'') | |
631 | { | |
632 | if (input_line_pointer[1] != '\'') | |
633 | break; | |
634 | ++input_line_pointer; | |
635 | } | |
636 | generic_bignum[i] <<= 8; | |
637 | generic_bignum[i] += *input_line_pointer; | |
638 | ++input_line_pointer; | |
639 | } | |
640 | ||
641 | if (i < SIZE_OF_LARGE_NUMBER - 1) | |
642 | { | |
643 | /* If there is more than one littlenum, left justify the | |
02000999 AM |
644 | last one to make it match the earlier ones. If there is |
645 | only one, we can just use the value directly. */ | |
252b5132 RH |
646 | for (; j < CHARS_PER_LITTLENUM; j++) |
647 | generic_bignum[i] <<= 8; | |
648 | } | |
649 | ||
650 | if (*input_line_pointer == '\'' | |
651 | && input_line_pointer[1] != '\'') | |
652 | break; | |
653 | } | |
654 | ||
655 | if (i < 0) | |
656 | { | |
0e389e77 | 657 | as_bad (_("character constant too large")); |
252b5132 RH |
658 | i = 0; |
659 | } | |
660 | ||
661 | if (i > 0) | |
662 | { | |
663 | int c; | |
664 | int j; | |
665 | ||
666 | c = SIZE_OF_LARGE_NUMBER - i; | |
667 | for (j = 0; j < c; j++) | |
668 | generic_bignum[j] = generic_bignum[i + j]; | |
669 | i = c; | |
670 | } | |
671 | ||
672 | know (LITTLENUM_NUMBER_OF_BITS == 16); | |
673 | if (i > 2) | |
674 | { | |
675 | expressionP->X_op = O_big; | |
676 | expressionP->X_add_number = i; | |
677 | } | |
678 | else | |
679 | { | |
680 | expressionP->X_op = O_constant; | |
681 | if (i < 2) | |
682 | expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK; | |
683 | else | |
684 | expressionP->X_add_number = | |
685 | (((generic_bignum[1] & LITTLENUM_MASK) | |
686 | << LITTLENUM_NUMBER_OF_BITS) | |
687 | | (generic_bignum[0] & LITTLENUM_MASK)); | |
688 | } | |
689 | ||
690 | /* Skip the final closing quote. */ | |
691 | ++input_line_pointer; | |
692 | } | |
693 | ||
694 | /* Return an expression representing the current location. This | |
695 | handles the magic symbol `.'. */ | |
696 | ||
b7adb16d | 697 | void |
dd625418 | 698 | current_location (expressionS *expressionp) |
252b5132 RH |
699 | { |
700 | if (now_seg == absolute_section) | |
701 | { | |
702 | expressionp->X_op = O_constant; | |
703 | expressionp->X_add_number = abs_section_offset; | |
704 | } | |
705 | else | |
706 | { | |
252b5132 | 707 | expressionp->X_op = O_symbol; |
4a826962 | 708 | expressionp->X_add_symbol = &dot_symbol; |
252b5132 RH |
709 | expressionp->X_add_number = 0; |
710 | } | |
711 | } | |
712 | ||
929b12bc KH |
713 | /* In: Input_line_pointer points to 1st char of operand, which may |
714 | be a space. | |
715 | ||
3b37fd66 | 716 | Out: An expressionS. |
929b12bc KH |
717 | The operand may have been empty: in this case X_op == O_absent. |
718 | Input_line_pointer->(next non-blank) char after operand. */ | |
252b5132 RH |
719 | |
720 | static segT | |
9497f5ac | 721 | operand (expressionS *expressionP, enum expr_mode mode) |
252b5132 RH |
722 | { |
723 | char c; | |
929b12bc KH |
724 | symbolS *symbolP; /* Points to symbol. */ |
725 | char *name; /* Points to name of symbol. */ | |
252b5132 RH |
726 | segT segment; |
727 | ||
728 | /* All integers are regarded as unsigned unless they are negated. | |
729 | This is because the only thing which cares whether a number is | |
730 | unsigned is the code in emit_expr which extends constants into | |
731 | bignums. It should only sign extend negative numbers, so that | |
732 | something like ``.quad 0x80000000'' is not sign extended even | |
733 | though it appears negative if valueT is 32 bits. */ | |
734 | expressionP->X_unsigned = 1; | |
735 | ||
929b12bc | 736 | /* Digits, assume it is a bignum. */ |
252b5132 | 737 | |
929b12bc | 738 | SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */ |
bc4466dc | 739 | c = *input_line_pointer++; /* input_line_pointer -> past char in c. */ |
252b5132 | 740 | |
b75c0c92 AM |
741 | if (is_end_of_line[(unsigned char) c]) |
742 | goto eol; | |
743 | ||
252b5132 RH |
744 | switch (c) |
745 | { | |
746 | case '1': | |
747 | case '2': | |
748 | case '3': | |
749 | case '4': | |
750 | case '5': | |
751 | case '6': | |
752 | case '7': | |
753 | case '8': | |
754 | case '9': | |
755 | input_line_pointer--; | |
756 | ||
60bcf0fa | 757 | integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) |
929b12bc | 758 | ? 0 : 10, |
411863a4 | 759 | expressionP); |
252b5132 RH |
760 | break; |
761 | ||
ed6d6fd3 FCE |
762 | #ifdef LITERAL_PREFIXDOLLAR_HEX |
763 | case '$': | |
c68012fb JJ |
764 | /* $L is the start of a local label, not a hex constant. */ |
765 | if (* input_line_pointer == 'L') | |
766 | goto isname; | |
ed6d6fd3 FCE |
767 | integer_constant (16, expressionP); |
768 | break; | |
769 | #endif | |
770 | ||
977e771a FCE |
771 | #ifdef LITERAL_PREFIXPERCENT_BIN |
772 | case '%': | |
773 | integer_constant (2, expressionP); | |
774 | break; | |
775 | #endif | |
776 | ||
252b5132 | 777 | case '0': |
929b12bc | 778 | /* Non-decimal radix. */ |
252b5132 | 779 | |
f805106c | 780 | if (NUMBERS_WITH_SUFFIX || flag_m68k_mri) |
252b5132 RH |
781 | { |
782 | char *s; | |
783 | ||
02000999 | 784 | /* Check for a hex or float constant. */ |
252b5132 RH |
785 | for (s = input_line_pointer; hex_p (*s); s++) |
786 | ; | |
02000999 | 787 | if (*s == 'h' || *s == 'H' || *input_line_pointer == '.') |
252b5132 RH |
788 | { |
789 | --input_line_pointer; | |
790 | integer_constant (0, expressionP); | |
791 | break; | |
792 | } | |
929b12bc | 793 | } |
252b5132 RH |
794 | c = *input_line_pointer; |
795 | switch (c) | |
796 | { | |
797 | case 'o': | |
798 | case 'O': | |
799 | case 'q': | |
800 | case 'Q': | |
801 | case '8': | |
802 | case '9': | |
f805106c | 803 | if (NUMBERS_WITH_SUFFIX || flag_m68k_mri) |
252b5132 RH |
804 | { |
805 | integer_constant (0, expressionP); | |
806 | break; | |
807 | } | |
808 | /* Fall through. */ | |
809 | default: | |
810 | default_case: | |
811 | if (c && strchr (FLT_CHARS, c)) | |
812 | { | |
813 | input_line_pointer++; | |
814 | floating_constant (expressionP); | |
3882b010 | 815 | expressionP->X_add_number = - TOLOWER (c); |
252b5132 RH |
816 | } |
817 | else | |
818 | { | |
929b12bc | 819 | /* The string was only zero. */ |
252b5132 RH |
820 | expressionP->X_op = O_constant; |
821 | expressionP->X_add_number = 0; | |
822 | } | |
823 | ||
824 | break; | |
825 | ||
826 | case 'x': | |
827 | case 'X': | |
ab266a97 | 828 | if (flag_m68k_mri) |
252b5132 RH |
829 | goto default_case; |
830 | input_line_pointer++; | |
831 | integer_constant (16, expressionP); | |
832 | break; | |
833 | ||
834 | case 'b': | |
6dc19fc4 | 835 | if (LOCAL_LABELS_FB && ! (flag_m68k_mri || NUMBERS_WITH_SUFFIX)) |
252b5132 RH |
836 | { |
837 | /* This code used to check for '+' and '-' here, and, in | |
838 | some conditions, fall through to call | |
839 | integer_constant. However, that didn't make sense, | |
840 | as integer_constant only accepts digits. */ | |
841 | /* Some of our code elsewhere does permit digits greater | |
842 | than the expected base; for consistency, do the same | |
843 | here. */ | |
844 | if (input_line_pointer[1] < '0' | |
845 | || input_line_pointer[1] > '9') | |
846 | { | |
847 | /* Parse this as a back reference to label 0. */ | |
848 | input_line_pointer--; | |
849 | integer_constant (10, expressionP); | |
850 | break; | |
851 | } | |
852 | /* Otherwise, parse this as a binary number. */ | |
853 | } | |
854 | /* Fall through. */ | |
855 | case 'B': | |
856 | input_line_pointer++; | |
6dc19fc4 | 857 | if (flag_m68k_mri || NUMBERS_WITH_SUFFIX) |
252b5132 RH |
858 | goto default_case; |
859 | integer_constant (2, expressionP); | |
860 | break; | |
861 | ||
862 | case '0': | |
863 | case '1': | |
864 | case '2': | |
865 | case '3': | |
866 | case '4': | |
867 | case '5': | |
868 | case '6': | |
869 | case '7': | |
6dc19fc4 | 870 | integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX) |
929b12bc KH |
871 | ? 0 : 8, |
872 | expressionP); | |
252b5132 RH |
873 | break; |
874 | ||
875 | case 'f': | |
876 | if (LOCAL_LABELS_FB) | |
877 | { | |
878 | /* If it says "0f" and it could possibly be a floating point | |
879 | number, make it one. Otherwise, make it a local label, | |
880 | and try to deal with parsing the rest later. */ | |
881 | if (!input_line_pointer[1] | |
271bb601 HPN |
882 | || (is_end_of_line[0xff & input_line_pointer[1]]) |
883 | || strchr (FLT_CHARS, 'f') == NULL) | |
252b5132 RH |
884 | goto is_0f_label; |
885 | { | |
886 | char *cp = input_line_pointer + 1; | |
887 | int r = atof_generic (&cp, ".", EXP_CHARS, | |
888 | &generic_floating_point_number); | |
889 | switch (r) | |
890 | { | |
891 | case 0: | |
892 | case ERROR_EXPONENT_OVERFLOW: | |
893 | if (*cp == 'f' || *cp == 'b') | |
929b12bc | 894 | /* Looks like a difference expression. */ |
252b5132 RH |
895 | goto is_0f_label; |
896 | else if (cp == input_line_pointer + 1) | |
897 | /* No characters has been accepted -- looks like | |
929b12bc | 898 | end of operand. */ |
252b5132 RH |
899 | goto is_0f_label; |
900 | else | |
901 | goto is_0f_float; | |
902 | default: | |
903 | as_fatal (_("expr.c(operand): bad atof_generic return val %d"), | |
904 | r); | |
905 | } | |
906 | } | |
907 | ||
908 | /* Okay, now we've sorted it out. We resume at one of these | |
909 | two labels, depending on what we've decided we're probably | |
910 | looking at. */ | |
911 | is_0f_label: | |
912 | input_line_pointer--; | |
913 | integer_constant (10, expressionP); | |
914 | break; | |
915 | ||
916 | is_0f_float: | |
929b12bc | 917 | /* Fall through. */ |
252b5132 RH |
918 | ; |
919 | } | |
920 | ||
921 | case 'd': | |
922 | case 'D': | |
6dc19fc4 | 923 | if (flag_m68k_mri || NUMBERS_WITH_SUFFIX) |
252b5132 RH |
924 | { |
925 | integer_constant (0, expressionP); | |
926 | break; | |
927 | } | |
928 | /* Fall through. */ | |
929 | case 'F': | |
930 | case 'r': | |
931 | case 'e': | |
932 | case 'E': | |
933 | case 'g': | |
934 | case 'G': | |
935 | input_line_pointer++; | |
936 | floating_constant (expressionP); | |
3882b010 | 937 | expressionP->X_add_number = - TOLOWER (c); |
252b5132 RH |
938 | break; |
939 | ||
940 | case '$': | |
941 | if (LOCAL_LABELS_DOLLAR) | |
942 | { | |
943 | integer_constant (10, expressionP); | |
944 | break; | |
945 | } | |
946 | else | |
947 | goto default_case; | |
948 | } | |
949 | ||
950 | break; | |
951 | ||
b585bc2c | 952 | #ifndef NEED_INDEX_OPERATOR |
252b5132 | 953 | case '[': |
fcaed75e JB |
954 | # ifdef md_need_index_operator |
955 | if (md_need_index_operator()) | |
956 | goto de_fault; | |
957 | # endif | |
958 | /* FALLTHROUGH */ | |
b585bc2c | 959 | #endif |
fcaed75e | 960 | case '(': |
929b12bc | 961 | /* Didn't begin with digit & not a name. */ |
259af69e | 962 | segment = expr (0, expressionP, mode); |
929b12bc | 963 | /* expression () will pass trailing whitespace. */ |
f7c88872 AM |
964 | if ((c == '(' && *input_line_pointer != ')') |
965 | || (c == '[' && *input_line_pointer != ']')) | |
fbacee5b | 966 | as_bad (_("missing '%c'"), c == '(' ? ')' : ']'); |
f7c88872 | 967 | else |
929b12bc | 968 | input_line_pointer++; |
252b5132 | 969 | SKIP_WHITESPACE (); |
929b12bc | 970 | /* Here with input_line_pointer -> char after "(...)". */ |
252b5132 RH |
971 | return segment; |
972 | ||
abd63a32 | 973 | #ifdef TC_M68K |
252b5132 RH |
974 | case 'E': |
975 | if (! flag_m68k_mri || *input_line_pointer != '\'') | |
976 | goto de_fault; | |
977 | as_bad (_("EBCDIC constants are not supported")); | |
978 | /* Fall through. */ | |
979 | case 'A': | |
980 | if (! flag_m68k_mri || *input_line_pointer != '\'') | |
981 | goto de_fault; | |
982 | ++input_line_pointer; | |
983 | /* Fall through. */ | |
abd63a32 | 984 | #endif |
252b5132 RH |
985 | case '\'': |
986 | if (! flag_m68k_mri) | |
987 | { | |
988 | /* Warning: to conform to other people's assemblers NO | |
929b12bc | 989 | ESCAPEMENT is permitted for a single quote. The next |
252b5132 | 990 | character, parity errors and all, is taken as the value |
929b12bc | 991 | of the operand. VERY KINKY. */ |
252b5132 RH |
992 | expressionP->X_op = O_constant; |
993 | expressionP->X_add_number = *input_line_pointer++; | |
994 | break; | |
995 | } | |
996 | ||
997 | mri_char_constant (expressionP); | |
998 | break; | |
999 | ||
abd63a32 | 1000 | #ifdef TC_M68K |
252b5132 RH |
1001 | case '"': |
1002 | /* Double quote is the bitwise not operator in MRI mode. */ | |
1003 | if (! flag_m68k_mri) | |
1004 | goto de_fault; | |
1005 | /* Fall through. */ | |
abd63a32 | 1006 | #endif |
252b5132 | 1007 | case '~': |
929b12bc | 1008 | /* '~' is permitted to start a label on the Delta. */ |
252b5132 RH |
1009 | if (is_name_beginner (c)) |
1010 | goto isname; | |
1011 | case '!': | |
1012 | case '-': | |
43c3ab55 | 1013 | case '+': |
252b5132 | 1014 | { |
fcaed75e JB |
1015 | #ifdef md_operator |
1016 | unary: | |
1017 | #endif | |
9497f5ac | 1018 | operand (expressionP, mode); |
252b5132 RH |
1019 | if (expressionP->X_op == O_constant) |
1020 | { | |
929b12bc | 1021 | /* input_line_pointer -> char after operand. */ |
252b5132 RH |
1022 | if (c == '-') |
1023 | { | |
958b5f01 | 1024 | expressionP->X_add_number = - expressionP->X_add_number; |
929b12bc KH |
1025 | /* Notice: '-' may overflow: no warning is given. |
1026 | This is compatible with other people's | |
1027 | assemblers. Sigh. */ | |
252b5132 RH |
1028 | expressionP->X_unsigned = 0; |
1029 | } | |
1030 | else if (c == '~' || c == '"') | |
1031 | expressionP->X_add_number = ~ expressionP->X_add_number; | |
43c3ab55 | 1032 | else if (c == '!') |
252b5132 RH |
1033 | expressionP->X_add_number = ! expressionP->X_add_number; |
1034 | } | |
02000999 AM |
1035 | else if (expressionP->X_op == O_big |
1036 | && expressionP->X_add_number <= 0 | |
1037 | && c == '-' | |
1038 | && (generic_floating_point_number.sign == '+' | |
1039 | || generic_floating_point_number.sign == 'P')) | |
1040 | { | |
1041 | /* Negative flonum (eg, -1.000e0). */ | |
1042 | if (generic_floating_point_number.sign == '+') | |
1043 | generic_floating_point_number.sign = '-'; | |
1044 | else | |
1045 | generic_floating_point_number.sign = 'N'; | |
1046 | } | |
b2221023 MM |
1047 | else if (expressionP->X_op == O_big |
1048 | && expressionP->X_add_number > 0) | |
1049 | { | |
1050 | int i; | |
1051 | ||
1052 | if (c == '~' || c == '-') | |
1053 | { | |
1054 | for (i = 0; i < expressionP->X_add_number; ++i) | |
1055 | generic_bignum[i] = ~generic_bignum[i]; | |
93d90f46 AM |
1056 | |
1057 | /* Extend the bignum to at least the size of .octa. */ | |
1058 | if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER) | |
1059 | { | |
1060 | expressionP->X_add_number = SIZE_OF_LARGE_NUMBER; | |
1061 | for (; i < expressionP->X_add_number; ++i) | |
1062 | generic_bignum[i] = ~(LITTLENUM_TYPE) 0; | |
1063 | } | |
1064 | ||
b2221023 MM |
1065 | if (c == '-') |
1066 | for (i = 0; i < expressionP->X_add_number; ++i) | |
1067 | { | |
1068 | generic_bignum[i] += 1; | |
1069 | if (generic_bignum[i]) | |
1070 | break; | |
1071 | } | |
1072 | } | |
1073 | else if (c == '!') | |
1074 | { | |
b2221023 | 1075 | for (i = 0; i < expressionP->X_add_number; ++i) |
93d90f46 AM |
1076 | if (generic_bignum[i] != 0) |
1077 | break; | |
1078 | expressionP->X_add_number = i >= expressionP->X_add_number; | |
1079 | expressionP->X_op = O_constant; | |
1080 | expressionP->X_unsigned = 1; | |
b2221023 MM |
1081 | } |
1082 | } | |
252b5132 RH |
1083 | else if (expressionP->X_op != O_illegal |
1084 | && expressionP->X_op != O_absent) | |
1085 | { | |
43c3ab55 JB |
1086 | if (c != '+') |
1087 | { | |
1088 | expressionP->X_add_symbol = make_expr_symbol (expressionP); | |
1089 | if (c == '-') | |
1090 | expressionP->X_op = O_uminus; | |
1091 | else if (c == '~' || c == '"') | |
1092 | expressionP->X_op = O_bit_not; | |
1093 | else | |
1094 | expressionP->X_op = O_logical_not; | |
1095 | expressionP->X_add_number = 0; | |
1096 | } | |
252b5132 RH |
1097 | } |
1098 | else | |
1099 | as_warn (_("Unary operator %c ignored because bad operand follows"), | |
1100 | c); | |
1101 | } | |
1102 | break; | |
1103 | ||
abd63a32 | 1104 | #if defined (DOLLAR_DOT) || defined (TC_M68K) |
252b5132 | 1105 | case '$': |
929b12bc | 1106 | /* '$' is the program counter when in MRI mode, or when |
02000999 | 1107 | DOLLAR_DOT is defined. */ |
252b5132 RH |
1108 | #ifndef DOLLAR_DOT |
1109 | if (! flag_m68k_mri) | |
1110 | goto de_fault; | |
1111 | #endif | |
4fa6945e | 1112 | if (DOLLAR_AMBIGU && hex_p (*input_line_pointer)) |
252b5132 | 1113 | { |
4fa6945e NC |
1114 | /* In MRI mode and on Z80, '$' is also used as the prefix |
1115 | for a hexadecimal constant. */ | |
252b5132 RH |
1116 | integer_constant (16, expressionP); |
1117 | break; | |
1118 | } | |
1119 | ||
1120 | if (is_part_of_name (*input_line_pointer)) | |
1121 | goto isname; | |
1122 | ||
1123 | current_location (expressionP); | |
1124 | break; | |
abd63a32 | 1125 | #endif |
252b5132 RH |
1126 | |
1127 | case '.': | |
1128 | if (!is_part_of_name (*input_line_pointer)) | |
1129 | { | |
1130 | current_location (expressionP); | |
1131 | break; | |
1132 | } | |
1133 | else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0 | |
1134 | && ! is_part_of_name (input_line_pointer[8])) | |
1135 | || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0 | |
1136 | && ! is_part_of_name (input_line_pointer[7]))) | |
1137 | { | |
1138 | int start; | |
1139 | ||
1140 | start = (input_line_pointer[1] == 't' | |
1141 | || input_line_pointer[1] == 'T'); | |
1142 | input_line_pointer += start ? 8 : 7; | |
1143 | SKIP_WHITESPACE (); | |
1144 | if (*input_line_pointer != '(') | |
1145 | as_bad (_("syntax error in .startof. or .sizeof.")); | |
1146 | else | |
1147 | { | |
1148 | char *buf; | |
1149 | ||
1150 | ++input_line_pointer; | |
1151 | SKIP_WHITESPACE (); | |
1152 | name = input_line_pointer; | |
1153 | c = get_symbol_end (); | |
1154 | ||
1155 | buf = (char *) xmalloc (strlen (name) + 10); | |
1156 | if (start) | |
1157 | sprintf (buf, ".startof.%s", name); | |
1158 | else | |
1159 | sprintf (buf, ".sizeof.%s", name); | |
1160 | symbolP = symbol_make (buf); | |
1161 | free (buf); | |
1162 | ||
1163 | expressionP->X_op = O_symbol; | |
1164 | expressionP->X_add_symbol = symbolP; | |
1165 | expressionP->X_add_number = 0; | |
1166 | ||
1167 | *input_line_pointer = c; | |
1168 | SKIP_WHITESPACE (); | |
1169 | if (*input_line_pointer != ')') | |
1170 | as_bad (_("syntax error in .startof. or .sizeof.")); | |
1171 | else | |
1172 | ++input_line_pointer; | |
1173 | } | |
1174 | break; | |
1175 | } | |
1176 | else | |
1177 | { | |
1178 | goto isname; | |
1179 | } | |
b75c0c92 | 1180 | |
252b5132 | 1181 | case ',': |
252b5132 | 1182 | eol: |
929b12bc | 1183 | /* Can't imagine any other kind of operand. */ |
252b5132 RH |
1184 | expressionP->X_op = O_absent; |
1185 | input_line_pointer--; | |
1186 | break; | |
1187 | ||
abd63a32 | 1188 | #ifdef TC_M68K |
252b5132 RH |
1189 | case '%': |
1190 | if (! flag_m68k_mri) | |
1191 | goto de_fault; | |
1192 | integer_constant (2, expressionP); | |
1193 | break; | |
1194 | ||
1195 | case '@': | |
1196 | if (! flag_m68k_mri) | |
1197 | goto de_fault; | |
1198 | integer_constant (8, expressionP); | |
1199 | break; | |
1200 | ||
1201 | case ':': | |
1202 | if (! flag_m68k_mri) | |
1203 | goto de_fault; | |
1204 | ||
1205 | /* In MRI mode, this is a floating point constant represented | |
02000999 | 1206 | using hexadecimal digits. */ |
252b5132 RH |
1207 | |
1208 | ++input_line_pointer; | |
1209 | integer_constant (16, expressionP); | |
1210 | break; | |
1211 | ||
1212 | case '*': | |
1213 | if (! flag_m68k_mri || is_part_of_name (*input_line_pointer)) | |
1214 | goto de_fault; | |
1215 | ||
1216 | current_location (expressionP); | |
1217 | break; | |
abd63a32 | 1218 | #endif |
252b5132 RH |
1219 | |
1220 | default: | |
fcaed75e | 1221 | #if defined(md_need_index_operator) || defined(TC_M68K) |
252b5132 | 1222 | de_fault: |
abd63a32 | 1223 | #endif |
929b12bc | 1224 | if (is_name_beginner (c)) /* Here if did not begin with a digit. */ |
252b5132 | 1225 | { |
929b12bc KH |
1226 | /* Identifier begins here. |
1227 | This is kludged for speed, so code is repeated. */ | |
252b5132 RH |
1228 | isname: |
1229 | name = --input_line_pointer; | |
1230 | c = get_symbol_end (); | |
1231 | ||
fcaed75e JB |
1232 | #ifdef md_operator |
1233 | { | |
1e9cc1c2 | 1234 | operatorT op = md_operator (name, 1, &c); |
fcaed75e | 1235 | |
1e9cc1c2 | 1236 | switch (op) |
fcaed75e JB |
1237 | { |
1238 | case O_uminus: | |
1239 | *input_line_pointer = c; | |
1240 | c = '-'; | |
1241 | goto unary; | |
1242 | case O_bit_not: | |
1243 | *input_line_pointer = c; | |
1244 | c = '~'; | |
1245 | goto unary; | |
1246 | case O_logical_not: | |
1247 | *input_line_pointer = c; | |
1248 | c = '!'; | |
1249 | goto unary; | |
1250 | case O_illegal: | |
1251 | as_bad (_("invalid use of operator \"%s\""), name); | |
1252 | break; | |
1253 | default: | |
1254 | break; | |
1255 | } | |
1e9cc1c2 | 1256 | if (op != O_absent && op != O_illegal) |
fcaed75e JB |
1257 | { |
1258 | *input_line_pointer = c; | |
1259 | expr (9, expressionP, mode); | |
1260 | expressionP->X_add_symbol = make_expr_symbol (expressionP); | |
1261 | expressionP->X_op_symbol = NULL; | |
1262 | expressionP->X_add_number = 0; | |
1e9cc1c2 | 1263 | expressionP->X_op = op; |
fcaed75e JB |
1264 | break; |
1265 | } | |
1266 | } | |
1267 | #endif | |
1268 | ||
252b5132 RH |
1269 | #ifdef md_parse_name |
1270 | /* This is a hook for the backend to parse certain names | |
02000999 AM |
1271 | specially in certain contexts. If a name always has a |
1272 | specific value, it can often be handled by simply | |
1273 | entering it in the symbol table. */ | |
9497f5ac | 1274 | if (md_parse_name (name, expressionP, mode, &c)) |
252b5132 RH |
1275 | { |
1276 | *input_line_pointer = c; | |
1277 | break; | |
1278 | } | |
1279 | #endif | |
1280 | ||
1281 | #ifdef TC_I960 | |
1282 | /* The MRI i960 assembler permits | |
1283 | lda sizeof code,g13 | |
1284 | FIXME: This should use md_parse_name. */ | |
1285 | if (flag_mri | |
1286 | && (strcasecmp (name, "sizeof") == 0 | |
1287 | || strcasecmp (name, "startof") == 0)) | |
1288 | { | |
1289 | int start; | |
1290 | char *buf; | |
1291 | ||
1292 | start = (name[1] == 't' | |
1293 | || name[1] == 'T'); | |
1294 | ||
1295 | *input_line_pointer = c; | |
1296 | SKIP_WHITESPACE (); | |
1297 | ||
1298 | name = input_line_pointer; | |
1299 | c = get_symbol_end (); | |
1300 | ||
1301 | buf = (char *) xmalloc (strlen (name) + 10); | |
1302 | if (start) | |
1303 | sprintf (buf, ".startof.%s", name); | |
1304 | else | |
1305 | sprintf (buf, ".sizeof.%s", name); | |
1306 | symbolP = symbol_make (buf); | |
1307 | free (buf); | |
1308 | ||
1309 | expressionP->X_op = O_symbol; | |
1310 | expressionP->X_add_symbol = symbolP; | |
1311 | expressionP->X_add_number = 0; | |
1312 | ||
1313 | *input_line_pointer = c; | |
1314 | SKIP_WHITESPACE (); | |
1315 | ||
1316 | break; | |
929b12bc | 1317 | } |
252b5132 RH |
1318 | #endif |
1319 | ||
1320 | symbolP = symbol_find_or_make (name); | |
1321 | ||
1322 | /* If we have an absolute symbol or a reg, then we know its | |
1323 | value now. */ | |
1324 | segment = S_GET_SEGMENT (symbolP); | |
c969da64 RS |
1325 | if (mode != expr_defer |
1326 | && segment == absolute_section | |
1327 | && !S_FORCE_RELOC (symbolP, 0)) | |
252b5132 RH |
1328 | { |
1329 | expressionP->X_op = O_constant; | |
1330 | expressionP->X_add_number = S_GET_VALUE (symbolP); | |
1331 | } | |
9497f5ac | 1332 | else if (mode != expr_defer && segment == reg_section) |
252b5132 RH |
1333 | { |
1334 | expressionP->X_op = O_register; | |
1335 | expressionP->X_add_number = S_GET_VALUE (symbolP); | |
1336 | } | |
1337 | else | |
1338 | { | |
1339 | expressionP->X_op = O_symbol; | |
1340 | expressionP->X_add_symbol = symbolP; | |
1341 | expressionP->X_add_number = 0; | |
1342 | } | |
1343 | *input_line_pointer = c; | |
1344 | } | |
1345 | else | |
1346 | { | |
1347 | /* Let the target try to parse it. Success is indicated by changing | |
1348 | the X_op field to something other than O_absent and pointing | |
927781e2 | 1349 | input_line_pointer past the expression. If it can't parse the |
252b5132 RH |
1350 | expression, X_op and input_line_pointer should be unchanged. */ |
1351 | expressionP->X_op = O_absent; | |
1352 | --input_line_pointer; | |
1353 | md_operand (expressionP); | |
1354 | if (expressionP->X_op == O_absent) | |
1355 | { | |
1356 | ++input_line_pointer; | |
0e389e77 | 1357 | as_bad (_("bad expression")); |
252b5132 RH |
1358 | expressionP->X_op = O_constant; |
1359 | expressionP->X_add_number = 0; | |
1360 | } | |
1361 | } | |
1362 | break; | |
1363 | } | |
1364 | ||
929b12bc KH |
1365 | /* It is more 'efficient' to clean up the expressionS when they are |
1366 | created. Doing it here saves lines of code. */ | |
252b5132 | 1367 | clean_up_expression (expressionP); |
929b12bc | 1368 | SKIP_WHITESPACE (); /* -> 1st char after operand. */ |
252b5132 RH |
1369 | know (*input_line_pointer != ' '); |
1370 | ||
1371 | /* The PA port needs this information. */ | |
1372 | if (expressionP->X_add_symbol) | |
49309057 | 1373 | symbol_mark_used (expressionP->X_add_symbol); |
252b5132 | 1374 | |
3df4e177 MR |
1375 | if (mode != expr_defer) |
1376 | { | |
1377 | expressionP->X_add_symbol | |
1378 | = symbol_clone_if_forward_ref (expressionP->X_add_symbol); | |
1379 | expressionP->X_op_symbol | |
1380 | = symbol_clone_if_forward_ref (expressionP->X_op_symbol); | |
1381 | } | |
9497f5ac | 1382 | |
252b5132 RH |
1383 | switch (expressionP->X_op) |
1384 | { | |
1385 | default: | |
1386 | return absolute_section; | |
1387 | case O_symbol: | |
1388 | return S_GET_SEGMENT (expressionP->X_add_symbol); | |
1389 | case O_register: | |
1390 | return reg_section; | |
1391 | } | |
929b12bc | 1392 | } |
252b5132 | 1393 | \f |
929b12bc KH |
1394 | /* Internal. Simplify a struct expression for use by expr (). */ |
1395 | ||
3b37fd66 | 1396 | /* In: address of an expressionS. |
929b12bc KH |
1397 | The X_op field of the expressionS may only take certain values. |
1398 | Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT. | |
1399 | ||
1400 | Out: expressionS may have been modified: | |
929b12bc | 1401 | Unused fields zeroed to help expr (). */ |
252b5132 RH |
1402 | |
1403 | static void | |
dd625418 | 1404 | clean_up_expression (expressionS *expressionP) |
252b5132 RH |
1405 | { |
1406 | switch (expressionP->X_op) | |
1407 | { | |
1408 | case O_illegal: | |
1409 | case O_absent: | |
1410 | expressionP->X_add_number = 0; | |
1411 | /* Fall through. */ | |
1412 | case O_big: | |
1413 | case O_constant: | |
1414 | case O_register: | |
1415 | expressionP->X_add_symbol = NULL; | |
1416 | /* Fall through. */ | |
1417 | case O_symbol: | |
1418 | case O_uminus: | |
1419 | case O_bit_not: | |
1420 | expressionP->X_op_symbol = NULL; | |
1421 | break; | |
252b5132 RH |
1422 | default: |
1423 | break; | |
1424 | } | |
1425 | } | |
1426 | \f | |
929b12bc KH |
1427 | /* Expression parser. */ |
1428 | ||
1429 | /* We allow an empty expression, and just assume (absolute,0) silently. | |
1430 | Unary operators and parenthetical expressions are treated as operands. | |
1431 | As usual, Q==quantity==operand, O==operator, X==expression mnemonics. | |
1432 | ||
3b37fd66 | 1433 | We used to do an aho/ullman shift-reduce parser, but the logic got so |
929b12bc KH |
1434 | warped that I flushed it and wrote a recursive-descent parser instead. |
1435 | Now things are stable, would anybody like to write a fast parser? | |
1436 | Most expressions are either register (which does not even reach here) | |
1437 | or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common. | |
1438 | So I guess it doesn't really matter how inefficient more complex expressions | |
1439 | are parsed. | |
1440 | ||
1441 | After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK. | |
1442 | Also, we have consumed any leading or trailing spaces (operand does that) | |
1443 | and done all intervening operators. | |
1444 | ||
1445 | This returns the segment of the result, which will be | |
1446 | absolute_section or the segment of a symbol. */ | |
252b5132 RH |
1447 | |
1448 | #undef __ | |
1449 | #define __ O_illegal | |
fb7ccfc1 AM |
1450 | #ifndef O_SINGLE_EQ |
1451 | #define O_SINGLE_EQ O_illegal | |
1452 | #endif | |
252b5132 | 1453 | |
b041f888 KH |
1454 | /* Maps ASCII -> operators. */ |
1455 | static const operatorT op_encoding[256] = { | |
252b5132 RH |
1456 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, |
1457 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1458 | ||
1459 | __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __, | |
1460 | __, __, O_multiply, O_add, __, O_subtract, __, O_divide, | |
1461 | __, __, __, __, __, __, __, __, | |
fb7ccfc1 | 1462 | __, __, __, __, O_lt, O_SINGLE_EQ, O_gt, __, |
252b5132 RH |
1463 | __, __, __, __, __, __, __, __, |
1464 | __, __, __, __, __, __, __, __, | |
1465 | __, __, __, __, __, __, __, __, | |
b585bc2c RH |
1466 | __, __, __, |
1467 | #ifdef NEED_INDEX_OPERATOR | |
1468 | O_index, | |
1469 | #else | |
1470 | __, | |
1471 | #endif | |
1472 | __, __, O_bit_exclusive_or, __, | |
252b5132 RH |
1473 | __, __, __, __, __, __, __, __, |
1474 | __, __, __, __, __, __, __, __, | |
1475 | __, __, __, __, __, __, __, __, | |
1476 | __, __, __, __, O_bit_inclusive_or, __, __, __, | |
1477 | ||
1478 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1479 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1480 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1481 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1482 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1483 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1484 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
1485 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __ | |
1486 | }; | |
1487 | ||
929b12bc KH |
1488 | /* Rank Examples |
1489 | 0 operand, (expression) | |
1490 | 1 || | |
1491 | 2 && | |
07a7a145 | 1492 | 3 == <> < <= >= > |
929b12bc KH |
1493 | 4 + - |
1494 | 5 used for * / % in MRI mode | |
1495 | 6 & ^ ! | | |
1496 | 7 * / % << >> | |
1497 | 8 unary - unary ~ | |
1498 | */ | |
1035ad42 | 1499 | static operator_rankT op_rank[O_max] = { |
252b5132 RH |
1500 | 0, /* O_illegal */ |
1501 | 0, /* O_absent */ | |
1502 | 0, /* O_constant */ | |
1503 | 0, /* O_symbol */ | |
1504 | 0, /* O_symbol_rva */ | |
1505 | 0, /* O_register */ | |
16887944 | 1506 | 0, /* O_big */ |
b585bc2c RH |
1507 | 9, /* O_uminus */ |
1508 | 9, /* O_bit_not */ | |
1509 | 9, /* O_logical_not */ | |
1510 | 8, /* O_multiply */ | |
1511 | 8, /* O_divide */ | |
1512 | 8, /* O_modulus */ | |
1513 | 8, /* O_left_shift */ | |
1514 | 8, /* O_right_shift */ | |
1515 | 7, /* O_bit_inclusive_or */ | |
1516 | 7, /* O_bit_or_not */ | |
1517 | 7, /* O_bit_exclusive_or */ | |
1518 | 7, /* O_bit_and */ | |
1519 | 5, /* O_add */ | |
1520 | 5, /* O_subtract */ | |
1521 | 4, /* O_eq */ | |
1522 | 4, /* O_ne */ | |
1523 | 4, /* O_lt */ | |
1524 | 4, /* O_le */ | |
1525 | 4, /* O_ge */ | |
1526 | 4, /* O_gt */ | |
1527 | 3, /* O_logical_and */ | |
1528 | 2, /* O_logical_or */ | |
1529 | 1, /* O_index */ | |
252b5132 RH |
1530 | }; |
1531 | ||
1532 | /* Unfortunately, in MRI mode for the m68k, multiplication and | |
1533 | division have lower precedence than the bit wise operators. This | |
1534 | function sets the operator precedences correctly for the current | |
1535 | mode. Also, MRI uses a different bit_not operator, and this fixes | |
1536 | that as well. */ | |
1537 | ||
16887944 AM |
1538 | #define STANDARD_MUL_PRECEDENCE 8 |
1539 | #define MRI_MUL_PRECEDENCE 6 | |
252b5132 RH |
1540 | |
1541 | void | |
dd625418 | 1542 | expr_set_precedence (void) |
252b5132 RH |
1543 | { |
1544 | if (flag_m68k_mri) | |
1545 | { | |
1546 | op_rank[O_multiply] = MRI_MUL_PRECEDENCE; | |
1547 | op_rank[O_divide] = MRI_MUL_PRECEDENCE; | |
1548 | op_rank[O_modulus] = MRI_MUL_PRECEDENCE; | |
1549 | } | |
1550 | else | |
1551 | { | |
1552 | op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE; | |
1553 | op_rank[O_divide] = STANDARD_MUL_PRECEDENCE; | |
1554 | op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE; | |
1555 | } | |
1556 | } | |
1557 | ||
fcaed75e | 1558 | void |
1e9cc1c2 | 1559 | expr_set_rank (operatorT op, operator_rankT rank) |
fcaed75e | 1560 | { |
1e9cc1c2 NC |
1561 | gas_assert (op >= O_md1 && op < ARRAY_SIZE (op_rank)); |
1562 | op_rank[op] = rank; | |
fcaed75e JB |
1563 | } |
1564 | ||
252b5132 RH |
1565 | /* Initialize the expression parser. */ |
1566 | ||
1567 | void | |
dd625418 | 1568 | expr_begin (void) |
252b5132 RH |
1569 | { |
1570 | expr_set_precedence (); | |
1571 | ||
1572 | /* Verify that X_op field is wide enough. */ | |
1573 | { | |
1574 | expressionS e; | |
1575 | e.X_op = O_max; | |
9c2799c2 | 1576 | gas_assert (e.X_op == O_max); |
252b5132 RH |
1577 | } |
1578 | } | |
1579 | \f | |
6fad6acb AM |
1580 | /* Return the encoding for the operator at INPUT_LINE_POINTER, and |
1581 | sets NUM_CHARS to the number of characters in the operator. | |
1582 | Does not advance INPUT_LINE_POINTER. */ | |
252b5132 RH |
1583 | |
1584 | static inline operatorT | |
1e9cc1c2 | 1585 | operatorf (int *num_chars) |
252b5132 RH |
1586 | { |
1587 | int c; | |
1588 | operatorT ret; | |
1589 | ||
1590 | c = *input_line_pointer & 0xff; | |
6fad6acb | 1591 | *num_chars = 1; |
252b5132 | 1592 | |
b75c0c92 AM |
1593 | if (is_end_of_line[c]) |
1594 | return O_illegal; | |
1595 | ||
fcaed75e JB |
1596 | #ifdef md_operator |
1597 | if (is_name_beginner (c)) | |
1598 | { | |
1599 | char *name = input_line_pointer; | |
91d6fa6a | 1600 | char ec = get_symbol_end (); |
fcaed75e | 1601 | |
91d6fa6a | 1602 | ret = md_operator (name, 2, &ec); |
fcaed75e JB |
1603 | switch (ret) |
1604 | { | |
1605 | case O_absent: | |
91d6fa6a | 1606 | *input_line_pointer = ec; |
fcaed75e JB |
1607 | input_line_pointer = name; |
1608 | break; | |
1609 | case O_uminus: | |
1610 | case O_bit_not: | |
1611 | case O_logical_not: | |
1612 | as_bad (_("invalid use of operator \"%s\""), name); | |
1613 | ret = O_illegal; | |
1614 | /* FALLTHROUGH */ | |
1615 | default: | |
91d6fa6a | 1616 | *input_line_pointer = ec; |
fcaed75e JB |
1617 | *num_chars = input_line_pointer - name; |
1618 | input_line_pointer = name; | |
1619 | return ret; | |
1620 | } | |
1621 | } | |
1622 | #endif | |
1623 | ||
252b5132 RH |
1624 | switch (c) |
1625 | { | |
1626 | default: | |
fcaed75e JB |
1627 | ret = op_encoding[c]; |
1628 | #ifdef md_operator | |
1629 | if (ret == O_illegal) | |
1630 | { | |
1631 | char *start = input_line_pointer; | |
1632 | ||
1633 | ret = md_operator (NULL, 2, NULL); | |
1634 | if (ret != O_illegal) | |
1635 | *num_chars = input_line_pointer - start; | |
1636 | input_line_pointer = start; | |
1637 | } | |
1638 | #endif | |
1639 | return ret; | |
252b5132 | 1640 | |
3e4caed2 NS |
1641 | case '+': |
1642 | case '-': | |
8c9f705e | 1643 | return op_encoding[c]; |
3e4caed2 | 1644 | |
252b5132 RH |
1645 | case '<': |
1646 | switch (input_line_pointer[1]) | |
1647 | { | |
1648 | default: | |
1649 | return op_encoding[c]; | |
1650 | case '<': | |
1651 | ret = O_left_shift; | |
1652 | break; | |
1653 | case '>': | |
1654 | ret = O_ne; | |
1655 | break; | |
1656 | case '=': | |
1657 | ret = O_le; | |
1658 | break; | |
1659 | } | |
6fad6acb | 1660 | *num_chars = 2; |
252b5132 RH |
1661 | return ret; |
1662 | ||
1663 | case '=': | |
1664 | if (input_line_pointer[1] != '=') | |
1665 | return op_encoding[c]; | |
1666 | ||
6fad6acb | 1667 | *num_chars = 2; |
252b5132 RH |
1668 | return O_eq; |
1669 | ||
1670 | case '>': | |
1671 | switch (input_line_pointer[1]) | |
1672 | { | |
1673 | default: | |
1674 | return op_encoding[c]; | |
1675 | case '>': | |
1676 | ret = O_right_shift; | |
1677 | break; | |
1678 | case '=': | |
1679 | ret = O_ge; | |
1680 | break; | |
1681 | } | |
6fad6acb | 1682 | *num_chars = 2; |
252b5132 RH |
1683 | return ret; |
1684 | ||
1685 | case '!': | |
723a8472 | 1686 | switch (input_line_pointer[1]) |
252b5132 | 1687 | { |
723a8472 NC |
1688 | case '!': |
1689 | /* We accept !! as equivalent to ^ for MRI compatibility. */ | |
1690 | *num_chars = 2; | |
1691 | return O_bit_exclusive_or; | |
1692 | case '=': | |
1693 | /* We accept != as equivalent to <>. */ | |
1694 | *num_chars = 2; | |
1695 | return O_ne; | |
1696 | default: | |
252b5132 RH |
1697 | if (flag_m68k_mri) |
1698 | return O_bit_inclusive_or; | |
1699 | return op_encoding[c]; | |
1700 | } | |
252b5132 RH |
1701 | |
1702 | case '|': | |
1703 | if (input_line_pointer[1] != '|') | |
1704 | return op_encoding[c]; | |
1705 | ||
6fad6acb | 1706 | *num_chars = 2; |
252b5132 RH |
1707 | return O_logical_or; |
1708 | ||
1709 | case '&': | |
1710 | if (input_line_pointer[1] != '&') | |
1711 | return op_encoding[c]; | |
1712 | ||
6fad6acb | 1713 | *num_chars = 2; |
252b5132 RH |
1714 | return O_logical_and; |
1715 | } | |
1716 | ||
929b12bc | 1717 | /* NOTREACHED */ |
252b5132 RH |
1718 | } |
1719 | ||
1720 | /* Parse an expression. */ | |
1721 | ||
1722 | segT | |
dd625418 | 1723 | expr (int rankarg, /* Larger # is higher rank. */ |
9497f5ac NC |
1724 | expressionS *resultP, /* Deliver result here. */ |
1725 | enum expr_mode mode /* Controls behavior. */) | |
252b5132 | 1726 | { |
0561a208 | 1727 | operator_rankT rank = (operator_rankT) rankarg; |
252b5132 RH |
1728 | segT retval; |
1729 | expressionS right; | |
1730 | operatorT op_left; | |
1731 | operatorT op_right; | |
6fad6acb | 1732 | int op_chars; |
252b5132 | 1733 | |
db557034 | 1734 | know (rankarg >= 0); |
252b5132 | 1735 | |
26346241 AM |
1736 | /* Save the value of dot for the fixup code. */ |
1737 | if (rank == 0) | |
1738 | dot_value = frag_now_fix (); | |
1739 | ||
9497f5ac | 1740 | retval = operand (resultP, mode); |
252b5132 | 1741 | |
929b12bc KH |
1742 | /* operand () gobbles spaces. */ |
1743 | know (*input_line_pointer != ' '); | |
252b5132 | 1744 | |
1e9cc1c2 | 1745 | op_left = operatorf (&op_chars); |
252b5132 RH |
1746 | while (op_left != O_illegal && op_rank[(int) op_left] > rank) |
1747 | { | |
1748 | segT rightseg; | |
08ea7020 | 1749 | offsetT frag_off; |
252b5132 | 1750 | |
6fad6acb | 1751 | input_line_pointer += op_chars; /* -> after operator. */ |
252b5132 | 1752 | |
34a7d6c6 | 1753 | right.X_md = 0; |
9497f5ac | 1754 | rightseg = expr (op_rank[(int) op_left], &right, mode); |
252b5132 RH |
1755 | if (right.X_op == O_absent) |
1756 | { | |
1757 | as_warn (_("missing operand; zero assumed")); | |
1758 | right.X_op = O_constant; | |
1759 | right.X_add_number = 0; | |
1760 | right.X_add_symbol = NULL; | |
1761 | right.X_op_symbol = NULL; | |
1762 | } | |
1763 | ||
1764 | know (*input_line_pointer != ' '); | |
1765 | ||
b585bc2c RH |
1766 | if (op_left == O_index) |
1767 | { | |
1768 | if (*input_line_pointer != ']') | |
1769 | as_bad ("missing right bracket"); | |
1770 | else | |
1771 | { | |
1772 | ++input_line_pointer; | |
1773 | SKIP_WHITESPACE (); | |
1774 | } | |
1775 | } | |
1776 | ||
1e9cc1c2 | 1777 | op_right = operatorf (&op_chars); |
252b5132 | 1778 | |
fcaed75e | 1779 | know (op_right == O_illegal || op_left == O_index |
929b12bc | 1780 | || op_rank[(int) op_right] <= op_rank[(int) op_left]); |
fcaed75e JB |
1781 | know ((int) op_left >= (int) O_multiply); |
1782 | #ifndef md_operator | |
1783 | know ((int) op_left <= (int) O_index); | |
1784 | #else | |
1785 | know ((int) op_left < (int) O_max); | |
1786 | #endif | |
252b5132 | 1787 | |
929b12bc KH |
1788 | /* input_line_pointer->after right-hand quantity. */ |
1789 | /* left-hand quantity in resultP. */ | |
1790 | /* right-hand quantity in right. */ | |
1791 | /* operator in op_left. */ | |
252b5132 RH |
1792 | |
1793 | if (resultP->X_op == O_big) | |
1794 | { | |
1795 | if (resultP->X_add_number > 0) | |
1796 | as_warn (_("left operand is a bignum; integer 0 assumed")); | |
1797 | else | |
1798 | as_warn (_("left operand is a float; integer 0 assumed")); | |
1799 | resultP->X_op = O_constant; | |
1800 | resultP->X_add_number = 0; | |
1801 | resultP->X_add_symbol = NULL; | |
1802 | resultP->X_op_symbol = NULL; | |
1803 | } | |
1804 | if (right.X_op == O_big) | |
1805 | { | |
1806 | if (right.X_add_number > 0) | |
1807 | as_warn (_("right operand is a bignum; integer 0 assumed")); | |
1808 | else | |
1809 | as_warn (_("right operand is a float; integer 0 assumed")); | |
1810 | right.X_op = O_constant; | |
1811 | right.X_add_number = 0; | |
1812 | right.X_add_symbol = NULL; | |
1813 | right.X_op_symbol = NULL; | |
1814 | } | |
1815 | ||
1816 | /* Optimize common cases. */ | |
800eeca4 JW |
1817 | #ifdef md_optimize_expr |
1818 | if (md_optimize_expr (resultP, op_left, &right)) | |
1819 | { | |
929b12bc KH |
1820 | /* Skip. */ |
1821 | ; | |
800eeca4 JW |
1822 | } |
1823 | else | |
1824 | #endif | |
5a918ce7 JB |
1825 | #ifndef md_register_arithmetic |
1826 | # define md_register_arithmetic 1 | |
1827 | #endif | |
1828 | if (op_left == O_add && right.X_op == O_constant | |
1829 | && (md_register_arithmetic || resultP->X_op != O_register)) | |
252b5132 RH |
1830 | { |
1831 | /* X + constant. */ | |
1832 | resultP->X_add_number += right.X_add_number; | |
1833 | } | |
1834 | /* This case comes up in PIC code. */ | |
1835 | else if (op_left == O_subtract | |
1836 | && right.X_op == O_symbol | |
1837 | && resultP->X_op == O_symbol | |
99630778 | 1838 | && retval == rightseg |
bfff1642 NC |
1839 | #ifdef md_allow_local_subtract |
1840 | && md_allow_local_subtract (resultP, & right, rightseg) | |
1841 | #endif | |
c969da64 RS |
1842 | && ((SEG_NORMAL (rightseg) |
1843 | && !S_FORCE_RELOC (resultP->X_add_symbol, 0) | |
1844 | && !S_FORCE_RELOC (right.X_add_symbol, 0)) | |
99630778 AM |
1845 | || right.X_add_symbol == resultP->X_add_symbol) |
1846 | && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol), | |
1847 | symbol_get_frag (right.X_add_symbol), | |
1848 | &frag_off)) | |
252b5132 RH |
1849 | { |
1850 | resultP->X_add_number -= right.X_add_number; | |
99630778 | 1851 | resultP->X_add_number -= frag_off / OCTETS_PER_BYTE; |
252b5132 RH |
1852 | resultP->X_add_number += (S_GET_VALUE (resultP->X_add_symbol) |
1853 | - S_GET_VALUE (right.X_add_symbol)); | |
1854 | resultP->X_op = O_constant; | |
1855 | resultP->X_add_symbol = 0; | |
1856 | } | |
5a918ce7 JB |
1857 | else if (op_left == O_subtract && right.X_op == O_constant |
1858 | && (md_register_arithmetic || resultP->X_op != O_register)) | |
252b5132 RH |
1859 | { |
1860 | /* X - constant. */ | |
1861 | resultP->X_add_number -= right.X_add_number; | |
1862 | } | |
5a918ce7 JB |
1863 | else if (op_left == O_add && resultP->X_op == O_constant |
1864 | && (md_register_arithmetic || right.X_op != O_register)) | |
252b5132 RH |
1865 | { |
1866 | /* Constant + X. */ | |
1867 | resultP->X_op = right.X_op; | |
1868 | resultP->X_add_symbol = right.X_add_symbol; | |
1869 | resultP->X_op_symbol = right.X_op_symbol; | |
1870 | resultP->X_add_number += right.X_add_number; | |
1871 | retval = rightseg; | |
1872 | } | |
1873 | else if (resultP->X_op == O_constant && right.X_op == O_constant) | |
1874 | { | |
1875 | /* Constant OP constant. */ | |
1876 | offsetT v = right.X_add_number; | |
1877 | if (v == 0 && (op_left == O_divide || op_left == O_modulus)) | |
1878 | { | |
1879 | as_warn (_("division by zero")); | |
1880 | v = 1; | |
1881 | } | |
d85733c8 JB |
1882 | if ((valueT) v >= sizeof(valueT) * CHAR_BIT |
1883 | && (op_left == O_left_shift || op_left == O_right_shift)) | |
1884 | { | |
1885 | as_warn_value_out_of_range (_("shift count"), v, 0, | |
1886 | sizeof(valueT) * CHAR_BIT - 1, | |
1887 | NULL, 0); | |
1888 | resultP->X_add_number = v = 0; | |
1889 | } | |
252b5132 RH |
1890 | switch (op_left) |
1891 | { | |
fcaed75e | 1892 | default: goto general; |
252b5132 RH |
1893 | case O_multiply: resultP->X_add_number *= v; break; |
1894 | case O_divide: resultP->X_add_number /= v; break; | |
1895 | case O_modulus: resultP->X_add_number %= v; break; | |
1896 | case O_left_shift: resultP->X_add_number <<= v; break; | |
1897 | case O_right_shift: | |
1898 | /* We always use unsigned shifts, to avoid relying on | |
02000999 | 1899 | characteristics of the compiler used to compile gas. */ |
252b5132 RH |
1900 | resultP->X_add_number = |
1901 | (offsetT) ((valueT) resultP->X_add_number >> (valueT) v); | |
1902 | break; | |
1903 | case O_bit_inclusive_or: resultP->X_add_number |= v; break; | |
1904 | case O_bit_or_not: resultP->X_add_number |= ~v; break; | |
1905 | case O_bit_exclusive_or: resultP->X_add_number ^= v; break; | |
1906 | case O_bit_and: resultP->X_add_number &= v; break; | |
7b383517 BE |
1907 | /* Constant + constant (O_add) is handled by the |
1908 | previous if statement for constant + X, so is omitted | |
1909 | here. */ | |
252b5132 RH |
1910 | case O_subtract: resultP->X_add_number -= v; break; |
1911 | case O_eq: | |
1912 | resultP->X_add_number = | |
958b5f01 | 1913 | resultP->X_add_number == v ? ~ (offsetT) 0 : 0; |
252b5132 RH |
1914 | break; |
1915 | case O_ne: | |
1916 | resultP->X_add_number = | |
958b5f01 | 1917 | resultP->X_add_number != v ? ~ (offsetT) 0 : 0; |
252b5132 RH |
1918 | break; |
1919 | case O_lt: | |
1920 | resultP->X_add_number = | |
958b5f01 | 1921 | resultP->X_add_number < v ? ~ (offsetT) 0 : 0; |
252b5132 RH |
1922 | break; |
1923 | case O_le: | |
1924 | resultP->X_add_number = | |
958b5f01 | 1925 | resultP->X_add_number <= v ? ~ (offsetT) 0 : 0; |
252b5132 RH |
1926 | break; |
1927 | case O_ge: | |
1928 | resultP->X_add_number = | |
958b5f01 | 1929 | resultP->X_add_number >= v ? ~ (offsetT) 0 : 0; |
252b5132 RH |
1930 | break; |
1931 | case O_gt: | |
1932 | resultP->X_add_number = | |
958b5f01 | 1933 | resultP->X_add_number > v ? ~ (offsetT) 0 : 0; |
252b5132 RH |
1934 | break; |
1935 | case O_logical_and: | |
1936 | resultP->X_add_number = resultP->X_add_number && v; | |
1937 | break; | |
1938 | case O_logical_or: | |
1939 | resultP->X_add_number = resultP->X_add_number || v; | |
1940 | break; | |
1941 | } | |
1942 | } | |
1943 | else if (resultP->X_op == O_symbol | |
1944 | && right.X_op == O_symbol | |
1945 | && (op_left == O_add | |
1946 | || op_left == O_subtract | |
1947 | || (resultP->X_add_number == 0 | |
1948 | && right.X_add_number == 0))) | |
1949 | { | |
1950 | /* Symbol OP symbol. */ | |
1951 | resultP->X_op = op_left; | |
1952 | resultP->X_op_symbol = right.X_add_symbol; | |
1953 | if (op_left == O_add) | |
1954 | resultP->X_add_number += right.X_add_number; | |
1955 | else if (op_left == O_subtract) | |
e0890092 AM |
1956 | { |
1957 | resultP->X_add_number -= right.X_add_number; | |
c969da64 RS |
1958 | if (retval == rightseg |
1959 | && SEG_NORMAL (retval) | |
1960 | && !S_FORCE_RELOC (resultP->X_add_symbol, 0) | |
1961 | && !S_FORCE_RELOC (right.X_add_symbol, 0)) | |
e0890092 AM |
1962 | { |
1963 | retval = absolute_section; | |
1964 | rightseg = absolute_section; | |
1965 | } | |
1966 | } | |
252b5132 RH |
1967 | } |
1968 | else | |
1969 | { | |
fcaed75e | 1970 | general: |
252b5132 RH |
1971 | /* The general case. */ |
1972 | resultP->X_add_symbol = make_expr_symbol (resultP); | |
1973 | resultP->X_op_symbol = make_expr_symbol (&right); | |
1974 | resultP->X_op = op_left; | |
1975 | resultP->X_add_number = 0; | |
1976 | resultP->X_unsigned = 1; | |
1977 | } | |
1978 | ||
e0890092 AM |
1979 | if (retval != rightseg) |
1980 | { | |
1e0f6894 AM |
1981 | if (retval == undefined_section) |
1982 | ; | |
1983 | else if (rightseg == undefined_section) | |
1984 | retval = rightseg; | |
1985 | else if (retval == expr_section) | |
1986 | ; | |
1987 | else if (rightseg == expr_section) | |
1988 | retval = rightseg; | |
1989 | else if (retval == reg_section) | |
1990 | ; | |
1991 | else if (rightseg == reg_section) | |
1992 | retval = rightseg; | |
1993 | else if (rightseg == absolute_section) | |
1994 | ; | |
1995 | else if (retval == absolute_section) | |
1996 | retval = rightseg; | |
e0890092 | 1997 | #ifdef DIFF_EXPR_OK |
1e0f6894 AM |
1998 | else if (op_left == O_subtract) |
1999 | ; | |
e0890092 | 2000 | #endif |
1e0f6894 | 2001 | else |
e0890092 AM |
2002 | as_bad (_("operation combines symbols in different segments")); |
2003 | } | |
2004 | ||
252b5132 | 2005 | op_left = op_right; |
929b12bc | 2006 | } /* While next operator is >= this rank. */ |
252b5132 RH |
2007 | |
2008 | /* The PA port needs this information. */ | |
2009 | if (resultP->X_add_symbol) | |
49309057 | 2010 | symbol_mark_used (resultP->X_add_symbol); |
252b5132 | 2011 | |
9497f5ac NC |
2012 | if (rank == 0 && mode == expr_evaluate) |
2013 | resolve_expression (resultP); | |
2014 | ||
252b5132 RH |
2015 | return resultP->X_op == O_constant ? absolute_section : retval; |
2016 | } | |
9497f5ac NC |
2017 | |
2018 | /* Resolve an expression without changing any symbols/sub-expressions | |
2019 | used. */ | |
2020 | ||
2021 | int | |
2022 | resolve_expression (expressionS *expressionP) | |
2023 | { | |
2024 | /* Help out with CSE. */ | |
2025 | valueT final_val = expressionP->X_add_number; | |
2026 | symbolS *add_symbol = expressionP->X_add_symbol; | |
14610ad1 | 2027 | symbolS *orig_add_symbol = add_symbol; |
9497f5ac NC |
2028 | symbolS *op_symbol = expressionP->X_op_symbol; |
2029 | operatorT op = expressionP->X_op; | |
2030 | valueT left, right; | |
2031 | segT seg_left, seg_right; | |
2032 | fragS *frag_left, *frag_right; | |
08ea7020 | 2033 | offsetT frag_off; |
9497f5ac NC |
2034 | |
2035 | switch (op) | |
2036 | { | |
2037 | default: | |
2038 | return 0; | |
2039 | ||
2040 | case O_constant: | |
2041 | case O_register: | |
2042 | left = 0; | |
2043 | break; | |
2044 | ||
2045 | case O_symbol: | |
2046 | case O_symbol_rva: | |
2e1e12b1 | 2047 | if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)) |
9497f5ac NC |
2048 | return 0; |
2049 | ||
2050 | break; | |
2051 | ||
2052 | case O_uminus: | |
2053 | case O_bit_not: | |
2054 | case O_logical_not: | |
2e1e12b1 | 2055 | if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)) |
9497f5ac NC |
2056 | return 0; |
2057 | ||
2058 | if (seg_left != absolute_section) | |
2059 | return 0; | |
2060 | ||
2061 | if (op == O_logical_not) | |
2062 | left = !left; | |
2063 | else if (op == O_uminus) | |
2064 | left = -left; | |
2065 | else | |
2066 | left = ~left; | |
2067 | op = O_constant; | |
2068 | break; | |
2069 | ||
2070 | case O_multiply: | |
2071 | case O_divide: | |
2072 | case O_modulus: | |
2073 | case O_left_shift: | |
2074 | case O_right_shift: | |
2075 | case O_bit_inclusive_or: | |
2076 | case O_bit_or_not: | |
2077 | case O_bit_exclusive_or: | |
2078 | case O_bit_and: | |
2079 | case O_add: | |
2080 | case O_subtract: | |
2081 | case O_eq: | |
2082 | case O_ne: | |
2083 | case O_lt: | |
2084 | case O_le: | |
2085 | case O_ge: | |
2086 | case O_gt: | |
2087 | case O_logical_and: | |
2088 | case O_logical_or: | |
2e1e12b1 JB |
2089 | if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left) |
2090 | || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right)) | |
9497f5ac NC |
2091 | return 0; |
2092 | ||
2093 | /* Simplify addition or subtraction of a constant by folding the | |
2094 | constant into X_add_number. */ | |
2095 | if (op == O_add) | |
2096 | { | |
2097 | if (seg_right == absolute_section) | |
2098 | { | |
2099 | final_val += right; | |
2100 | op = O_symbol; | |
2101 | break; | |
2102 | } | |
2103 | else if (seg_left == absolute_section) | |
2104 | { | |
2105 | final_val += left; | |
2106 | left = right; | |
2107 | seg_left = seg_right; | |
2e1e12b1 | 2108 | add_symbol = op_symbol; |
14610ad1 | 2109 | orig_add_symbol = expressionP->X_op_symbol; |
9497f5ac NC |
2110 | op = O_symbol; |
2111 | break; | |
2112 | } | |
2113 | } | |
2114 | else if (op == O_subtract) | |
2115 | { | |
2116 | if (seg_right == absolute_section) | |
2117 | { | |
2118 | final_val -= right; | |
2119 | op = O_symbol; | |
2120 | break; | |
2121 | } | |
2122 | } | |
2123 | ||
2124 | /* Equality and non-equality tests are permitted on anything. | |
2125 | Subtraction, and other comparison operators are permitted if | |
2e1e12b1 JB |
2126 | both operands are in the same section. |
2127 | Shifts by constant zero are permitted on anything. | |
2128 | Multiplies, bit-ors, and bit-ands with constant zero are | |
2129 | permitted on anything. | |
2130 | Multiplies and divides by constant one are permitted on | |
2131 | anything. | |
2132 | Binary operations with both operands being the same register | |
2133 | or undefined symbol are permitted if the result doesn't depend | |
2134 | on the input value. | |
2135 | Otherwise, both operands must be absolute. We already handled | |
2136 | the case of addition or subtraction of a constant above. */ | |
99630778 | 2137 | frag_off = 0; |
9497f5ac NC |
2138 | if (!(seg_left == absolute_section |
2139 | && seg_right == absolute_section) | |
2140 | && !(op == O_eq || op == O_ne) | |
2141 | && !((op == O_subtract | |
2142 | || op == O_lt || op == O_le || op == O_ge || op == O_gt) | |
2143 | && seg_left == seg_right | |
99630778 AM |
2144 | && (finalize_syms |
2145 | || frag_offset_fixed_p (frag_left, frag_right, &frag_off)) | |
2e1e12b1 JB |
2146 | && (seg_left != reg_section || left == right) |
2147 | && (seg_left != undefined_section || add_symbol == op_symbol))) | |
2148 | { | |
2149 | if ((seg_left == absolute_section && left == 0) | |
2150 | || (seg_right == absolute_section && right == 0)) | |
2151 | { | |
2152 | if (op == O_bit_exclusive_or || op == O_bit_inclusive_or) | |
2153 | { | |
14610ad1 | 2154 | if (!(seg_right == absolute_section && right == 0)) |
2e1e12b1 JB |
2155 | { |
2156 | seg_left = seg_right; | |
2157 | left = right; | |
2158 | add_symbol = op_symbol; | |
14610ad1 | 2159 | orig_add_symbol = expressionP->X_op_symbol; |
2e1e12b1 JB |
2160 | } |
2161 | op = O_symbol; | |
2162 | break; | |
2163 | } | |
2164 | else if (op == O_left_shift || op == O_right_shift) | |
2165 | { | |
14610ad1 | 2166 | if (!(seg_left == absolute_section && left == 0)) |
2e1e12b1 JB |
2167 | { |
2168 | op = O_symbol; | |
2169 | break; | |
2170 | } | |
2171 | } | |
2172 | else if (op != O_multiply | |
2173 | && op != O_bit_or_not && op != O_bit_and) | |
2174 | return 0; | |
2175 | } | |
2176 | else if (op == O_multiply | |
2177 | && seg_left == absolute_section && left == 1) | |
2178 | { | |
2179 | seg_left = seg_right; | |
2180 | left = right; | |
2181 | add_symbol = op_symbol; | |
14610ad1 | 2182 | orig_add_symbol = expressionP->X_op_symbol; |
2e1e12b1 JB |
2183 | op = O_symbol; |
2184 | break; | |
2185 | } | |
2186 | else if ((op == O_multiply || op == O_divide) | |
2187 | && seg_right == absolute_section && right == 1) | |
2188 | { | |
2189 | op = O_symbol; | |
2190 | break; | |
2191 | } | |
14610ad1 AM |
2192 | else if (!(left == right |
2193 | && ((seg_left == reg_section && seg_right == reg_section) | |
2194 | || (seg_left == undefined_section | |
2195 | && seg_right == undefined_section | |
2196 | && add_symbol == op_symbol)))) | |
2e1e12b1 JB |
2197 | return 0; |
2198 | else if (op == O_bit_and || op == O_bit_inclusive_or) | |
2199 | { | |
2200 | op = O_symbol; | |
2201 | break; | |
2202 | } | |
2203 | else if (op != O_bit_exclusive_or && op != O_bit_or_not) | |
2204 | return 0; | |
2205 | } | |
9497f5ac | 2206 | |
99630778 | 2207 | right += frag_off / OCTETS_PER_BYTE; |
9497f5ac NC |
2208 | switch (op) |
2209 | { | |
2210 | case O_add: left += right; break; | |
2211 | case O_subtract: left -= right; break; | |
2212 | case O_multiply: left *= right; break; | |
2213 | case O_divide: | |
2214 | if (right == 0) | |
2215 | return 0; | |
2216 | left = (offsetT) left / (offsetT) right; | |
2217 | break; | |
2218 | case O_modulus: | |
2219 | if (right == 0) | |
2220 | return 0; | |
2221 | left = (offsetT) left % (offsetT) right; | |
2222 | break; | |
2223 | case O_left_shift: left <<= right; break; | |
2224 | case O_right_shift: left >>= right; break; | |
2225 | case O_bit_inclusive_or: left |= right; break; | |
2226 | case O_bit_or_not: left |= ~right; break; | |
2227 | case O_bit_exclusive_or: left ^= right; break; | |
2228 | case O_bit_and: left &= right; break; | |
2229 | case O_eq: | |
2230 | case O_ne: | |
2231 | left = (left == right | |
2232 | && seg_left == seg_right | |
2233 | && (finalize_syms || frag_left == frag_right) | |
2e1e12b1 | 2234 | && (seg_left != undefined_section |
9497f5ac NC |
2235 | || add_symbol == op_symbol) |
2236 | ? ~ (valueT) 0 : 0); | |
2237 | if (op == O_ne) | |
2238 | left = ~left; | |
2239 | break; | |
2240 | case O_lt: | |
2241 | left = (offsetT) left < (offsetT) right ? ~ (valueT) 0 : 0; | |
2242 | break; | |
2243 | case O_le: | |
2244 | left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0; | |
2245 | break; | |
2246 | case O_ge: | |
2247 | left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0; | |
2248 | break; | |
2249 | case O_gt: | |
2250 | left = (offsetT) left > (offsetT) right ? ~ (valueT) 0 : 0; | |
2251 | break; | |
2252 | case O_logical_and: left = left && right; break; | |
2253 | case O_logical_or: left = left || right; break; | |
2254 | default: abort (); | |
2255 | } | |
2256 | ||
2257 | op = O_constant; | |
2258 | break; | |
2259 | } | |
2260 | ||
2261 | if (op == O_symbol) | |
2262 | { | |
2263 | if (seg_left == absolute_section) | |
2264 | op = O_constant; | |
2265 | else if (seg_left == reg_section && final_val == 0) | |
2266 | op = O_register; | |
087d837e | 2267 | else if (!symbol_same_p (add_symbol, orig_add_symbol)) |
2e1e12b1 JB |
2268 | final_val += left; |
2269 | expressionP->X_add_symbol = add_symbol; | |
9497f5ac NC |
2270 | } |
2271 | expressionP->X_op = op; | |
2272 | ||
2273 | if (op == O_constant || op == O_register) | |
2274 | final_val += left; | |
2275 | expressionP->X_add_number = final_val; | |
2276 | ||
2277 | return 1; | |
2278 | } | |
252b5132 | 2279 | \f |
929b12bc KH |
2280 | /* This lives here because it belongs equally in expr.c & read.c. |
2281 | expr.c is just a branch office read.c anyway, and putting it | |
2282 | here lessens the crowd at read.c. | |
2283 | ||
2284 | Assume input_line_pointer is at start of symbol name. | |
2285 | Advance input_line_pointer past symbol name. | |
2286 | Turn that character into a '\0', returning its former value. | |
2287 | This allows a string compare (RMS wants symbol names to be strings) | |
2288 | of the symbol name. | |
2289 | There will always be a char following symbol name, because all good | |
2290 | lines end in end-of-line. */ | |
2291 | ||
252b5132 | 2292 | char |
dd625418 | 2293 | get_symbol_end (void) |
252b5132 RH |
2294 | { |
2295 | char c; | |
2296 | ||
2297 | /* We accept \001 in a name in case this is being called with a | |
2298 | constructed string. */ | |
2299 | if (is_name_beginner (c = *input_line_pointer++) || c == '\001') | |
58b5739a RH |
2300 | { |
2301 | while (is_part_of_name (c = *input_line_pointer++) | |
2302 | || c == '\001') | |
2303 | ; | |
2304 | if (is_name_ender (c)) | |
2305 | c = *input_line_pointer++; | |
2306 | } | |
252b5132 RH |
2307 | *--input_line_pointer = 0; |
2308 | return (c); | |
2309 | } | |
2310 | ||
252b5132 | 2311 | unsigned int |
dd625418 | 2312 | get_single_number (void) |
252b5132 RH |
2313 | { |
2314 | expressionS exp; | |
9497f5ac | 2315 | operand (&exp, expr_normal); |
252b5132 | 2316 | return exp.X_add_number; |
252b5132 | 2317 | } |