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