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