]>
Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* expr.c -operands, expressions- |
c593cf41 | 2 | Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc. |
2ed83a59 | 3 | |
a39116f1 | 4 | This file is part of GAS, the GNU Assembler. |
2ed83a59 | 5 | |
a39116f1 RP |
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 | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
2ed83a59 | 10 | |
a39116f1 RP |
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. | |
2ed83a59 | 15 | |
a39116f1 RP |
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 | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
fecd2382 RP |
19 | |
20 | /* | |
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. | |
25 | */ | |
26 | ||
27 | #include <ctype.h> | |
28 | #include <string.h> | |
29 | ||
30 | #include "as.h" | |
31 | ||
32 | #include "obstack.h" | |
33 | ||
c593cf41 | 34 | #if __STDC__ == 1 |
2ed83a59 | 35 | static void clean_up_expression (expressionS * expressionP); |
fecd2382 | 36 | #else /* __STDC__ */ |
2ed83a59 | 37 | static void clean_up_expression (); /* Internal. */ |
c593cf41 | 38 | #endif /* not __STDC__ */ |
fecd2382 RP |
39 | extern const char EXP_CHARS[]; /* JF hide MD floating pt stuff all the same place */ |
40 | extern const char FLT_CHARS[]; | |
41 | ||
fecd2382 RP |
42 | /* |
43 | * Build any floating-point literal here. | |
44 | * Also build any bignum literal here. | |
45 | */ | |
46 | ||
2ed83a59 | 47 | /* LITTLENUM_TYPE generic_buffer [6]; *//* JF this is a hack */ |
fecd2382 RP |
48 | /* Seems atof_machine can backscan through generic_bignum and hit whatever |
49 | happens to be loaded before it in memory. And its way too complicated | |
50 | for me to fix right. Thus a hack. JF: Just make generic_bignum bigger, | |
51 | and never write into the early words, thus they'll always be zero. | |
52 | I hate Dean's floating-point code. Bleh. | |
a39116f1 | 53 | */ |
2ed83a59 KR |
54 | LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6]; |
55 | FLONUM_TYPE generic_floating_point_number = | |
fecd2382 | 56 | { |
2ed83a59 KR |
57 | &generic_bignum[6], /* low (JF: Was 0) */ |
58 | &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high JF: (added +6) */ | |
59 | 0, /* leader */ | |
60 | 0, /* exponent */ | |
61 | 0 /* sign */ | |
62 | }; | |
fecd2382 RP |
63 | /* If nonzero, we've been asked to assemble nan, +inf or -inf */ |
64 | int generic_floating_point_magic; | |
65 | \f | |
2ed83a59 KR |
66 | floating_constant (expressionP) |
67 | expressionS *expressionP; | |
c593cf41 SC |
68 | { |
69 | /* input_line_pointer->*/ | |
70 | /* floating-point constant. */ | |
71 | int error_code; | |
72 | ||
73 | error_code = atof_generic | |
2ed83a59 KR |
74 | (&input_line_pointer, ".", EXP_CHARS, |
75 | &generic_floating_point_number); | |
c593cf41 SC |
76 | |
77 | if (error_code) | |
c593cf41 | 78 | { |
2ed83a59 KR |
79 | if (error_code == ERROR_EXPONENT_OVERFLOW) |
80 | { | |
81 | as_bad ("bad floating-point constant: exponent overflow, probably assembling junk"); | |
82 | } | |
83 | else | |
84 | { | |
85 | as_bad ("bad floating-point constant: unknown error code=%d.", error_code); | |
86 | } | |
c593cf41 | 87 | } |
c593cf41 SC |
88 | expressionP->X_seg = SEG_BIG; |
89 | /* input_line_pointer->just after constant, */ | |
90 | /* which may point to whitespace. */ | |
2ed83a59 | 91 | expressionP->X_add_number = -1; |
c593cf41 SC |
92 | } |
93 | ||
94 | ||
95 | ||
2ed83a59 KR |
96 | integer_constant (radix, expressionP) |
97 | int radix; | |
98 | expressionS *expressionP; | |
c593cf41 | 99 | { |
2ed83a59 | 100 | register char *digit_2; /*->2nd digit of number. */ |
c593cf41 | 101 | char c; |
2ed83a59 KR |
102 | |
103 | register valueT number; /* offset or (absolute) value */ | |
104 | register short int digit; /* value of next digit in current radix */ | |
105 | register short int maxdig = 0;/* highest permitted digit value. */ | |
106 | register int too_many_digits = 0; /* if we see >= this number of */ | |
107 | register char *name; /* points to name of symbol */ | |
108 | register symbolS *symbolP; /* points to symbol */ | |
109 | ||
110 | int small; /* true if fits in 32 bits. */ | |
111 | extern char hex_value[]; /* in hex_value.c */ | |
112 | ||
c593cf41 SC |
113 | /* may be bignum, or may fit in 32 bits. */ |
114 | /* | |
115 | * most numbers fit into 32 bits, and we want this case to be fast. | |
116 | * so we pretend it will fit into 32 bits. if, after making up a 32 | |
117 | * bit number, we realise that we have scanned more digits than | |
118 | * comfortably fit into 32 bits, we re-scan the digits coding | |
119 | * them into a bignum. for decimal and octal numbers we are conservative: some | |
120 | * numbers may be assumed bignums when in fact they do fit into 32 bits. | |
121 | * numbers of any radix can have excess leading zeros: we strive | |
122 | * to recognise this and cast them back into 32 bits. | |
123 | * we must check that the bignum really is more than 32 | |
124 | * bits, and change it back to a 32-bit number if it fits. | |
125 | * the number we are looking for is expected to be positive, but | |
126 | * if it fits into 32 bits as an unsigned number, we let it be a 32-bit | |
127 | * number. the cavalier approach is for speed in ordinary cases. | |
128 | */ | |
2ed83a59 KR |
129 | |
130 | switch (radix) | |
f8701a3f | 131 | { |
2ed83a59 | 132 | |
f8701a3f SC |
133 | case 2: |
134 | maxdig = 2; | |
135 | too_many_digits = 33; | |
136 | break; | |
137 | case 8: | |
138 | maxdig = radix = 8; | |
139 | too_many_digits = 11; | |
140 | break; | |
141 | case 16: | |
2ed83a59 KR |
142 | |
143 | ||
f8701a3f SC |
144 | maxdig = radix = 16; |
145 | too_many_digits = 9; | |
146 | break; | |
147 | case 10: | |
148 | maxdig = radix = 10; | |
149 | too_many_digits = 11; | |
150 | } | |
c593cf41 SC |
151 | c = *input_line_pointer; |
152 | input_line_pointer++; | |
153 | digit_2 = input_line_pointer; | |
2ed83a59 | 154 | for (number = 0; (digit = hex_value[c]) < maxdig; c = *input_line_pointer++) |
f8701a3f SC |
155 | { |
156 | number = number * radix + digit; | |
157 | } | |
c593cf41 SC |
158 | /* c contains character after number. */ |
159 | /* input_line_pointer->char after c. */ | |
160 | small = input_line_pointer - digit_2 < too_many_digits; | |
2ed83a59 | 161 | if (!small) |
c593cf41 | 162 | { |
f8701a3f SC |
163 | /* |
164 | * we saw a lot of digits. manufacture a bignum the hard way. | |
165 | */ | |
2ed83a59 KR |
166 | LITTLENUM_TYPE *leader; /*->high order littlenum of the bignum. */ |
167 | LITTLENUM_TYPE *pointer; /*->littlenum we are frobbing now. */ | |
f8701a3f | 168 | long carry; |
2ed83a59 | 169 | |
f8701a3f | 170 | leader = generic_bignum; |
2ed83a59 KR |
171 | generic_bignum[0] = 0; |
172 | generic_bignum[1] = 0; | |
f8701a3f | 173 | /* we could just use digit_2, but lets be mnemonic. */ |
2ed83a59 | 174 | input_line_pointer = --digit_2; /*->1st digit. */ |
f8701a3f | 175 | c = *input_line_pointer++; |
2ed83a59 | 176 | for (; (carry = hex_value[c]) < maxdig; c = *input_line_pointer++) |
f8701a3f SC |
177 | { |
178 | for (pointer = generic_bignum; | |
179 | pointer <= leader; | |
180 | pointer++) | |
181 | { | |
182 | long work; | |
2ed83a59 KR |
183 | |
184 | work = carry + radix * *pointer; | |
f8701a3f SC |
185 | *pointer = work & LITTLENUM_MASK; |
186 | carry = work >> LITTLENUM_NUMBER_OF_BITS; | |
187 | } | |
188 | if (carry) | |
189 | { | |
190 | if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1) | |
2ed83a59 | 191 | { /* room to grow a longer bignum. */ |
f8701a3f SC |
192 | *++leader = carry; |
193 | } | |
194 | } | |
195 | } | |
196 | /* again, c is char after number, */ | |
197 | /* input_line_pointer->after c. */ | |
2ed83a59 KR |
198 | know (sizeof (int) * 8 == 32); |
199 | know (LITTLENUM_NUMBER_OF_BITS == 16); | |
f8701a3f SC |
200 | /* hence the constant "2" in the next line. */ |
201 | if (leader < generic_bignum + 2) | |
2ed83a59 | 202 | { /* will fit into 32 bits. */ |
f8701a3f | 203 | number = |
2ed83a59 KR |
204 | ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) |
205 | | (generic_bignum[0] & LITTLENUM_MASK); | |
f8701a3f SC |
206 | small = 1; |
207 | } | |
208 | else | |
209 | { | |
2ed83a59 | 210 | number = leader - generic_bignum + 1; /* number of littlenums in the bignum. */ |
c593cf41 | 211 | } |
c593cf41 | 212 | } |
2ed83a59 KR |
213 | if (small) |
214 | { | |
f8701a3f | 215 | /* |
2ed83a59 KR |
216 | * here with number, in correct radix. c is the next char. |
217 | * note that unlike un*x, we allow "011f" "0x9f" to | |
218 | * both mean the same as the (conventional) "9f". this is simply easier | |
219 | * than checking for strict canonical form. syntax sux! | |
f8701a3f | 220 | */ |
2ed83a59 KR |
221 | |
222 | switch (c) | |
223 | { | |
224 | ||
225 | #ifdef LOCAL_LABELS_FB | |
226 | case 'b': | |
227 | { | |
228 | /* | |
229 | * backward ref to local label. | |
230 | * because it is backward, expect it to be defined. | |
231 | */ | |
232 | /* Construct a local label. */ | |
233 | name = fb_label_name ((int) number, 0); | |
234 | ||
235 | /* seen before, or symbol is defined: ok */ | |
236 | symbolP = symbol_find (name); | |
237 | if ((symbolP != NULL) && (S_IS_DEFINED (symbolP))) | |
238 | { | |
239 | ||
240 | /* local labels are never absolute. don't waste time | |
241 | checking absoluteness. */ | |
242 | know (SEG_NORMAL (S_GET_SEGMENT (symbolP))); | |
243 | ||
244 | expressionP->X_add_symbol = symbolP; | |
245 | expressionP->X_seg = S_GET_SEGMENT (symbolP); | |
246 | ||
247 | } | |
248 | else | |
249 | { /* either not seen or not defined. */ | |
250 | as_bad ("backw. ref to unknown label \"%d:\", 0 assumed.", number); | |
251 | expressionP->X_seg = SEG_ABSOLUTE; | |
252 | } | |
253 | ||
254 | expressionP->X_add_number = 0; | |
255 | break; | |
256 | } /* case 'b' */ | |
257 | ||
258 | case 'f': | |
259 | { | |
260 | /* | |
261 | * forward reference. expect symbol to be undefined or | |
262 | * unknown. undefined: seen it before. unknown: never seen | |
263 | * it before. | |
264 | * construct a local label name, then an undefined symbol. | |
265 | * don't create a xseg frag for it: caller may do that. | |
266 | * just return it as never seen before. | |
267 | */ | |
268 | name = fb_label_name ((int) number, 1); | |
269 | symbolP = symbol_find_or_make (name); | |
270 | /* we have no need to check symbol properties. */ | |
c593cf41 | 271 | #ifndef many_segments |
2ed83a59 KR |
272 | /* since "know" puts its arg into a "string", we |
273 | can't have newlines in the argument. */ | |
274 | know (S_GET_SEGMENT (symbolP) == SEG_UNKNOWN || S_GET_SEGMENT (symbolP) == SEG_TEXT || S_GET_SEGMENT (symbolP) == SEG_DATA); | |
c593cf41 | 275 | #endif |
2ed83a59 KR |
276 | expressionP->X_add_symbol = symbolP; |
277 | expressionP->X_seg = SEG_UNKNOWN; | |
278 | expressionP->X_subtract_symbol = NULL; | |
279 | expressionP->X_add_number = 0; | |
280 | ||
281 | break; | |
282 | } /* case 'f' */ | |
283 | ||
f8701a3f | 284 | #endif /* LOCAL_LABELS_FB */ |
2ed83a59 | 285 | |
f8701a3f | 286 | #ifdef LOCAL_LABELS_DOLLAR |
f8701a3f | 287 | |
2ed83a59 KR |
288 | case '$': |
289 | { | |
290 | ||
291 | /* If the dollar label is *currently* defined, then this is just | |
292 | another reference to it. If it is not *currently* defined, | |
293 | then this is a fresh instantiation of that number, so create | |
294 | it. */ | |
295 | ||
296 | if (dollar_label_defined (number)) | |
297 | { | |
298 | name = dollar_label_name (number, 0); | |
299 | symbolP = symbol_find (name); | |
300 | know (symbolP != NULL); | |
301 | } | |
302 | else | |
303 | { | |
304 | name = dollar_label_name (number, 1); | |
305 | symbolP = symbol_find_or_make (name); | |
306 | } | |
307 | ||
308 | expressionP->X_add_symbol = symbolP; | |
309 | expressionP->X_add_number = 0; | |
310 | expressionP->X_seg = S_GET_SEGMENT (symbolP); | |
311 | ||
312 | break; | |
313 | } /* case '$' */ | |
314 | ||
f8701a3f | 315 | #endif /* LOCAL_LABELS_DOLLAR */ |
2ed83a59 KR |
316 | |
317 | default: | |
318 | { | |
319 | expressionP->X_add_number = number; | |
320 | expressionP->X_seg = SEG_ABSOLUTE; | |
321 | input_line_pointer--; /* restore following character. */ | |
322 | break; | |
323 | } /* really just a number */ | |
324 | ||
325 | } /* switch on char following the number */ | |
326 | ||
327 | ||
328 | } | |
329 | else | |
330 | { /* not a small number */ | |
c593cf41 | 331 | expressionP->X_add_number = number; |
2ed83a59 KR |
332 | expressionP->X_seg = SEG_BIG; |
333 | input_line_pointer--; /*->char following number. */ | |
334 | } /* if (small) */ | |
335 | } /* integer_constant() */ | |
c593cf41 SC |
336 | |
337 | ||
fecd2382 RP |
338 | /* |
339 | * Summary of operand(). | |
340 | * | |
341 | * in: Input_line_pointer points to 1st char of operand, which may | |
342 | * be a space. | |
343 | * | |
344 | * out: A expressionS. X_seg determines how to understand the rest of the | |
345 | * expressionS. | |
346 | * The operand may have been empty: in this case X_seg == SEG_ABSENT. | |
347 | * Input_line_pointer->(next non-blank) char after operand. | |
348 | * | |
349 | */ | |
350 | \f | |
c593cf41 SC |
351 | |
352 | ||
fecd2382 | 353 | static segT |
c593cf41 | 354 | operand (expressionP) |
2ed83a59 | 355 | register expressionS *expressionP; |
fecd2382 | 356 | { |
c593cf41 | 357 | register char c; |
2ed83a59 KR |
358 | register symbolS *symbolP; /* points to symbol */ |
359 | register char *name; /* points to name of symbol */ | |
c593cf41 SC |
360 | /* invented for humans only, hope */ |
361 | /* optimising compiler flushes it! */ | |
2ed83a59 | 362 | register short int radix; /* 2, 8, 10 or 16, 0 when floating */ |
c593cf41 SC |
363 | /* 0 means we saw start of a floating- */ |
364 | /* point constant. */ | |
365 | ||
366 | /* digits, assume it is a bignum. */ | |
367 | ||
2ed83a59 KR |
368 | SKIP_WHITESPACE (); /* leading whitespace is part of operand. */ |
369 | c = *input_line_pointer++; /* input_line_pointer->past char in c. */ | |
c593cf41 SC |
370 | |
371 | switch (c) | |
fecd2382 | 372 | { |
2ed83a59 KR |
373 | #ifdef MRI |
374 | case '%': | |
375 | integer_constant (2, expressionP); | |
c593cf41 | 376 | break; |
2ed83a59 KR |
377 | case '@': |
378 | integer_constant (8, expressionP); | |
c593cf41 | 379 | break; |
2ed83a59 KR |
380 | case '$': |
381 | integer_constant (16, expressionP); | |
c593cf41 | 382 | break; |
2ed83a59 | 383 | #endif |
c593cf41 SC |
384 | case '1': |
385 | case '2': | |
386 | case '3': | |
387 | case '4': | |
388 | case '5': | |
389 | case '6': | |
390 | case '7': | |
2ed83a59 KR |
391 | case '8': |
392 | case '9': | |
393 | input_line_pointer--; | |
394 | ||
395 | integer_constant (10, expressionP); | |
c593cf41 SC |
396 | break; |
397 | ||
2ed83a59 KR |
398 | case '0': |
399 | /* non-decimal radix */ | |
400 | ||
401 | ||
402 | c = *input_line_pointer; | |
403 | switch (c) | |
404 | { | |
405 | ||
406 | default: | |
407 | if (c && strchr (FLT_CHARS, c)) | |
408 | { | |
409 | input_line_pointer++; | |
410 | floating_constant (expressionP); | |
411 | } | |
412 | else | |
413 | { | |
414 | /* The string was only zero */ | |
415 | expressionP->X_add_symbol = 0; | |
416 | expressionP->X_add_number = 0; | |
417 | expressionP->X_seg = SEG_ABSOLUTE; | |
418 | } | |
419 | ||
420 | break; | |
421 | ||
422 | case 'x': | |
423 | case 'X': | |
424 | input_line_pointer++; | |
425 | integer_constant (16, expressionP); | |
426 | break; | |
427 | ||
428 | case 'b': | |
429 | #ifdef LOCAL_LABELS_FB | |
430 | if (!*input_line_pointer | |
431 | || (!strchr ("+-.0123456789", *input_line_pointer) | |
432 | && !strchr (EXP_CHARS, *input_line_pointer))) | |
433 | { | |
434 | input_line_pointer--; | |
435 | integer_constant (10, expressionP); | |
436 | break; | |
437 | } | |
438 | #endif | |
439 | case 'B': | |
440 | input_line_pointer++; | |
441 | integer_constant (2, expressionP); | |
442 | break; | |
443 | ||
444 | case '0': | |
445 | case '1': | |
446 | case '2': | |
447 | case '3': | |
448 | case '4': | |
449 | case '5': | |
450 | case '6': | |
451 | case '7': | |
452 | integer_constant (8, expressionP); | |
453 | break; | |
454 | ||
455 | case 'f': | |
456 | #ifdef LOCAL_LABELS_FB | |
457 | /* if it says '0f' and the line ends or it doesn't look like | |
d841bc49 | 458 | a floating point #, its a local label ref. dtrt */ |
2ed83a59 KR |
459 | /* likewise for the b's. xoxorich. */ |
460 | if (c == 'f' | |
461 | && (!*input_line_pointer || | |
462 | (!strchr ("+-.0123456789", *input_line_pointer) && | |
463 | !strchr (EXP_CHARS, *input_line_pointer)))) | |
464 | { | |
465 | input_line_pointer -= 1; | |
466 | integer_constant (10, expressionP); | |
467 | break; | |
468 | } | |
469 | #endif | |
470 | ||
471 | case 'd': | |
472 | case 'D': | |
473 | case 'F': | |
474 | case 'r': | |
475 | case 'e': | |
476 | case 'E': | |
477 | case 'g': | |
478 | case 'G': | |
479 | ||
480 | input_line_pointer++; | |
481 | floating_constant (expressionP); | |
482 | break; | |
483 | ||
484 | #ifdef LOCAL_LABELS_DOLLAR | |
485 | case '$': | |
486 | integer_constant (10, expressionP); | |
487 | break; | |
488 | #endif | |
489 | } | |
490 | ||
c593cf41 | 491 | break; |
2ed83a59 KR |
492 | case '(': |
493 | /* didn't begin with digit & not a name */ | |
494 | { | |
495 | (void) expression (expressionP); | |
496 | /* Expression() will pass trailing whitespace */ | |
497 | if (*input_line_pointer++ != ')') | |
498 | { | |
499 | as_bad ("Missing ')' assumed"); | |
500 | input_line_pointer--; | |
501 | } | |
502 | /* here with input_line_pointer->char after "(...)" */ | |
503 | } | |
504 | return expressionP->X_seg; | |
c593cf41 SC |
505 | |
506 | ||
2ed83a59 | 507 | case '\'': |
d841bc49 KR |
508 | /* Warning: to conform to other people's assemblers NO ESCAPEMENT is |
509 | permitted for a single quote. The next character, parity errors and | |
510 | all, is taken as the value of the operand. VERY KINKY. */ | |
2ed83a59 KR |
511 | expressionP->X_add_number = *input_line_pointer++; |
512 | expressionP->X_seg = SEG_ABSOLUTE; | |
513 | break; | |
514 | ||
515 | case '~': | |
516 | case '-': | |
517 | case '+': | |
518 | ||
519 | { | |
520 | /* unary operator: hope for SEG_ABSOLUTE */ | |
521 | switch (operand (expressionP)) | |
522 | { | |
523 | case SEG_ABSOLUTE: | |
524 | /* input_line_pointer -> char after operand */ | |
525 | if (c == '-') | |
526 | { | |
527 | expressionP->X_add_number = -expressionP->X_add_number; | |
d841bc49 KR |
528 | /* Notice: '-' may overflow: no warning is given. This is |
529 | compatible with other people's assemblers. Sigh. */ | |
2ed83a59 KR |
530 | } |
531 | else | |
532 | { | |
533 | expressionP->X_add_number = ~expressionP->X_add_number; | |
534 | } | |
535 | break; | |
536 | ||
537 | case SEG_TEXT: | |
538 | case SEG_DATA: | |
539 | case SEG_BSS: | |
540 | case SEG_PASS1: | |
541 | case SEG_UNKNOWN: | |
542 | if (c == '-') | |
543 | { /* JF I hope this hack works */ | |
544 | expressionP->X_subtract_symbol = expressionP->X_add_symbol; | |
545 | expressionP->X_add_symbol = 0; | |
546 | expressionP->X_seg = SEG_DIFFERENCE; | |
547 | break; | |
548 | } | |
549 | default: /* unary on non-absolute is unsuported */ | |
550 | as_warn ("Unary operator %c ignored because bad operand follows", c); | |
a39116f1 | 551 | break; |
2ed83a59 | 552 | /* Expression undisturbed from operand(). */ |
c593cf41 | 553 | } |
c593cf41 | 554 | } |
c593cf41 | 555 | |
c593cf41 | 556 | |
2ed83a59 KR |
557 | |
558 | break; | |
559 | ||
560 | case '.': | |
561 | if (!is_part_of_name (*input_line_pointer)) | |
562 | { | |
85825401 | 563 | char *fake; |
2ed83a59 KR |
564 | extern struct obstack frags; |
565 | ||
85825401 ILT |
566 | /* JF: '.' is pseudo symbol with value of current location |
567 | in current segment. */ | |
568 | #ifdef DOT_LABEL_PREFIX | |
569 | fake = ".L0\001"; | |
570 | #else | |
571 | fake = "L0\001"; | |
572 | #endif | |
573 | symbolP = symbol_new (fake, | |
2ed83a59 KR |
574 | now_seg, |
575 | (valueT) (obstack_next_free (&frags) - frag_now->fr_literal), | |
576 | frag_now); | |
c593cf41 | 577 | |
2ed83a59 KR |
578 | expressionP->X_add_number = 0; |
579 | expressionP->X_add_symbol = symbolP; | |
580 | expressionP->X_seg = now_seg; | |
581 | break; | |
582 | ||
583 | } | |
584 | else | |
585 | { | |
586 | goto isname; | |
587 | ||
588 | ||
589 | } | |
590 | case ',': | |
591 | case '\n': | |
0bd77bc4 | 592 | eol: |
2ed83a59 KR |
593 | /* can't imagine any other kind of operand */ |
594 | expressionP->X_seg = SEG_ABSENT; | |
595 | input_line_pointer--; | |
596 | md_operand (expressionP); | |
597 | break; | |
0bd77bc4 | 598 | |
2ed83a59 | 599 | default: |
0bd77bc4 KR |
600 | if (is_end_of_line[c]) |
601 | goto eol; | |
2ed83a59 KR |
602 | if (is_name_beginner (c)) /* here if did not begin with a digit */ |
603 | { | |
604 | /* | |
d841bc49 KR |
605 | * Identifier begins here. |
606 | * This is kludged for speed, so code is repeated. | |
607 | */ | |
2ed83a59 KR |
608 | isname: |
609 | name = --input_line_pointer; | |
610 | c = get_symbol_end (); | |
611 | symbolP = symbol_find_or_make (name); | |
d841bc49 KR |
612 | /* If we have an absolute symbol or a reg, then we know its value |
613 | now. */ | |
2ed83a59 KR |
614 | expressionP->X_seg = S_GET_SEGMENT (symbolP); |
615 | switch (expressionP->X_seg) | |
616 | { | |
617 | case SEG_ABSOLUTE: | |
618 | case SEG_REGISTER: | |
619 | expressionP->X_add_number = S_GET_VALUE (symbolP); | |
620 | break; | |
621 | ||
622 | default: | |
623 | expressionP->X_add_number = 0; | |
624 | expressionP->X_add_symbol = symbolP; | |
625 | } | |
626 | *input_line_pointer = c; | |
627 | expressionP->X_subtract_symbol = NULL; | |
628 | } | |
629 | else | |
630 | { | |
631 | as_bad ("Bad expression"); | |
632 | expressionP->X_add_number = 0; | |
633 | expressionP->X_seg = SEG_ABSOLUTE; | |
634 | ||
635 | } | |
c593cf41 SC |
636 | |
637 | } | |
c593cf41 SC |
638 | |
639 | ||
2ed83a59 KR |
640 | |
641 | ||
642 | ||
643 | ||
c593cf41 SC |
644 | |
645 | /* | |
646 | * It is more 'efficient' to clean up the expressionS when they are created. | |
647 | * Doing it here saves lines of code. | |
648 | */ | |
649 | clean_up_expression (expressionP); | |
2ed83a59 KR |
650 | SKIP_WHITESPACE (); /*->1st char after operand. */ |
651 | know (*input_line_pointer != ' '); | |
c593cf41 | 652 | return (expressionP->X_seg); |
2ed83a59 | 653 | } /* operand() */ |
fecd2382 | 654 | \f |
2ed83a59 | 655 | |
fecd2382 RP |
656 | /* Internal. Simplify a struct expression for use by expr() */ |
657 | ||
658 | /* | |
659 | * In: address of a expressionS. | |
660 | * The X_seg field of the expressionS may only take certain values. | |
661 | * Now, we permit SEG_PASS1 to make code smaller & faster. | |
662 | * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT. | |
663 | * Out: expressionS may have been modified: | |
664 | * 'foo-foo' symbol references cancelled to 0, | |
665 | * which changes X_seg from SEG_DIFFERENCE to SEG_ABSOLUTE; | |
666 | * Unused fields zeroed to help expr(). | |
667 | */ | |
668 | ||
669 | static void | |
c593cf41 | 670 | clean_up_expression (expressionP) |
2ed83a59 | 671 | register expressionS *expressionP; |
fecd2382 | 672 | { |
c593cf41 | 673 | switch (expressionP->X_seg) |
2ed83a59 KR |
674 | { |
675 | case SEG_ABSENT: | |
676 | case SEG_PASS1: | |
677 | expressionP->X_add_symbol = NULL; | |
678 | expressionP->X_subtract_symbol = NULL; | |
679 | expressionP->X_add_number = 0; | |
680 | break; | |
681 | ||
682 | case SEG_BIG: | |
683 | case SEG_ABSOLUTE: | |
684 | expressionP->X_subtract_symbol = NULL; | |
685 | expressionP->X_add_symbol = NULL; | |
686 | break; | |
687 | ||
688 | case SEG_UNKNOWN: | |
689 | expressionP->X_subtract_symbol = NULL; | |
690 | break; | |
691 | ||
692 | case SEG_DIFFERENCE: | |
693 | /* | |
a39116f1 RP |
694 | * It does not hurt to 'cancel' NULL==NULL |
695 | * when comparing symbols for 'eq'ness. | |
696 | * It is faster to re-cancel them to NULL | |
697 | * than to check for this special case. | |
698 | */ | |
2ed83a59 KR |
699 | if (expressionP->X_subtract_symbol == expressionP->X_add_symbol |
700 | || (expressionP->X_subtract_symbol | |
701 | && expressionP->X_add_symbol | |
702 | && expressionP->X_subtract_symbol->sy_frag == expressionP->X_add_symbol->sy_frag | |
703 | && S_GET_VALUE (expressionP->X_subtract_symbol) == S_GET_VALUE (expressionP->X_add_symbol))) | |
704 | { | |
705 | expressionP->X_subtract_symbol = NULL; | |
706 | expressionP->X_add_symbol = NULL; | |
707 | expressionP->X_seg = SEG_ABSOLUTE; | |
a39116f1 | 708 | } |
2ed83a59 | 709 | break; |
c593cf41 | 710 | |
2ed83a59 KR |
711 | case SEG_REGISTER: |
712 | expressionP->X_add_symbol = NULL; | |
713 | expressionP->X_subtract_symbol = NULL; | |
714 | break; | |
c593cf41 | 715 | |
2ed83a59 KR |
716 | default: |
717 | if (SEG_NORMAL (expressionP->X_seg)) | |
718 | { | |
719 | expressionP->X_subtract_symbol = NULL; | |
a39116f1 | 720 | } |
2ed83a59 KR |
721 | else |
722 | { | |
723 | BAD_CASE (expressionP->X_seg); | |
a39116f1 | 724 | } |
2ed83a59 KR |
725 | break; |
726 | } | |
727 | } /* clean_up_expression() */ | |
fecd2382 RP |
728 | \f |
729 | /* | |
730 | * expr_part () | |
731 | * | |
732 | * Internal. Made a function because this code is used in 2 places. | |
733 | * Generate error or correct X_?????_symbol of expressionS. | |
734 | */ | |
735 | ||
736 | /* | |
737 | * symbol_1 += symbol_2 ... well ... sort of. | |
738 | */ | |
739 | ||
740 | static segT | |
c593cf41 | 741 | expr_part (symbol_1_PP, symbol_2_P) |
2ed83a59 KR |
742 | symbolS **symbol_1_PP; |
743 | symbolS *symbol_2_P; | |
fecd2382 | 744 | { |
2ed83a59 | 745 | segT return_value; |
a39116f1 | 746 | #ifndef MANY_SEGMENTS |
2ed83a59 KR |
747 | know ((*symbol_1_PP) == NULL || (S_GET_SEGMENT (*symbol_1_PP) == SEG_TEXT) || (S_GET_SEGMENT (*symbol_1_PP) == SEG_DATA) || (S_GET_SEGMENT (*symbol_1_PP) == SEG_BSS) || (!S_IS_DEFINED (*symbol_1_PP))); |
748 | know (symbol_2_P == NULL || (S_GET_SEGMENT (symbol_2_P) == SEG_TEXT) || (S_GET_SEGMENT (symbol_2_P) == SEG_DATA) || (S_GET_SEGMENT (symbol_2_P) == SEG_BSS) || (!S_IS_DEFINED (symbol_2_P))); | |
a39116f1 | 749 | #endif |
2ed83a59 | 750 | if (*symbol_1_PP) |
fecd2382 | 751 | { |
2ed83a59 | 752 | if (!S_IS_DEFINED (*symbol_1_PP)) |
fecd2382 | 753 | { |
c593cf41 | 754 | if (symbol_2_P) |
fecd2382 | 755 | { |
2ed83a59 KR |
756 | return_value = SEG_PASS1; |
757 | *symbol_1_PP = NULL; | |
fecd2382 | 758 | } |
c593cf41 | 759 | else |
fecd2382 | 760 | { |
2ed83a59 KR |
761 | know (!S_IS_DEFINED (*symbol_1_PP)); |
762 | return_value = SEG_UNKNOWN; | |
fecd2382 RP |
763 | } |
764 | } | |
c593cf41 | 765 | else |
fecd2382 | 766 | { |
c593cf41 | 767 | if (symbol_2_P) |
fecd2382 | 768 | { |
2ed83a59 | 769 | if (!S_IS_DEFINED (symbol_2_P)) |
fecd2382 | 770 | { |
2ed83a59 | 771 | *symbol_1_PP = NULL; |
c593cf41 | 772 | return_value = SEG_PASS1; |
fecd2382 | 773 | } |
c593cf41 | 774 | else |
fecd2382 | 775 | { |
c593cf41 | 776 | /* {seg1} - {seg2} */ |
2ed83a59 KR |
777 | as_bad ("Expression too complex, 2 symbolS forgotten: \"%s\" \"%s\"", |
778 | S_GET_NAME (*symbol_1_PP), S_GET_NAME (symbol_2_P)); | |
779 | *symbol_1_PP = NULL; | |
c593cf41 | 780 | return_value = SEG_ABSOLUTE; |
fecd2382 RP |
781 | } |
782 | } | |
c593cf41 | 783 | else |
fecd2382 | 784 | { |
2ed83a59 | 785 | return_value = S_GET_SEGMENT (*symbol_1_PP); |
fecd2382 RP |
786 | } |
787 | } | |
788 | } | |
c593cf41 | 789 | else |
fecd2382 | 790 | { /* (* symbol_1_PP) == NULL */ |
c593cf41 | 791 | if (symbol_2_P) |
fecd2382 | 792 | { |
2ed83a59 KR |
793 | *symbol_1_PP = symbol_2_P; |
794 | return_value = S_GET_SEGMENT (symbol_2_P); | |
fecd2382 | 795 | } |
c593cf41 | 796 | else |
fecd2382 | 797 | { |
2ed83a59 | 798 | *symbol_1_PP = NULL; |
c593cf41 | 799 | return_value = SEG_ABSOLUTE; |
fecd2382 RP |
800 | } |
801 | } | |
a39116f1 | 802 | #ifndef MANY_SEGMENTS |
2ed83a59 | 803 | know (return_value == SEG_ABSOLUTE || return_value == SEG_TEXT || return_value == SEG_DATA || return_value == SEG_BSS || return_value == SEG_UNKNOWN || return_value == SEG_PASS1); |
a39116f1 | 804 | #endif |
2ed83a59 | 805 | know ((*symbol_1_PP) == NULL || (S_GET_SEGMENT (*symbol_1_PP) == return_value)); |
c593cf41 | 806 | return (return_value); |
fecd2382 RP |
807 | } /* expr_part() */ |
808 | \f | |
809 | /* Expression parser. */ | |
810 | ||
811 | /* | |
812 | * We allow an empty expression, and just assume (absolute,0) silently. | |
813 | * Unary operators and parenthetical expressions are treated as operands. | |
814 | * As usual, Q==quantity==operand, O==operator, X==expression mnemonics. | |
815 | * | |
816 | * We used to do a aho/ullman shift-reduce parser, but the logic got so | |
817 | * warped that I flushed it and wrote a recursive-descent parser instead. | |
818 | * Now things are stable, would anybody like to write a fast parser? | |
819 | * Most expressions are either register (which does not even reach here) | |
820 | * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common. | |
821 | * So I guess it doesn't really matter how inefficient more complex expressions | |
822 | * are parsed. | |
823 | * | |
824 | * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK. | |
825 | * Also, we have consumed any leading or trailing spaces (operand does that) | |
826 | * and done all intervening operators. | |
827 | */ | |
828 | ||
829 | typedef enum | |
830 | { | |
2ed83a59 KR |
831 | O_illegal, /* (0) what we get for illegal op */ |
832 | ||
833 | O_multiply, /* (1) * */ | |
834 | O_divide, /* (2) / */ | |
835 | O_modulus, /* (3) % */ | |
836 | O_left_shift, /* (4) < */ | |
837 | O_right_shift, /* (5) > */ | |
838 | O_bit_inclusive_or, /* (6) | */ | |
839 | O_bit_or_not, /* (7) ! */ | |
840 | O_bit_exclusive_or, /* (8) ^ */ | |
841 | O_bit_and, /* (9) & */ | |
842 | O_add, /* (10) + */ | |
843 | O_subtract /* (11) - */ | |
844 | } | |
845 | ||
fecd2382 RP |
846 | operatorT; |
847 | ||
848 | #define __ O_illegal | |
849 | ||
2ed83a59 KR |
850 | static const operatorT op_encoding[256] = |
851 | { /* maps ASCII->operators */ | |
852 | ||
853 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
854 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
855 | ||
856 | __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __, | |
857 | __, __, O_multiply, O_add, __, O_subtract, __, O_divide, | |
858 | __, __, __, __, __, __, __, __, | |
859 | __, __, __, __, O_left_shift, __, O_right_shift, __, | |
860 | __, __, __, __, __, __, __, __, | |
861 | __, __, __, __, __, __, __, __, | |
862 | __, __, __, __, __, __, __, __, | |
863 | __, __, __, __, __, __, O_bit_exclusive_or, __, | |
864 | __, __, __, __, __, __, __, __, | |
865 | __, __, __, __, __, __, __, __, | |
866 | __, __, __, __, __, __, __, __, | |
867 | __, __, __, __, O_bit_inclusive_or, __, __, __, | |
868 | ||
869 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
870 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
871 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
872 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
873 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
874 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
875 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | |
876 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __ | |
877 | }; | |
fecd2382 RP |
878 | |
879 | ||
880 | /* | |
881 | * Rank Examples | |
882 | * 0 operand, (expression) | |
883 | * 1 + - | |
884 | * 2 & ^ ! | | |
885 | * 3 * / % << >> | |
886 | */ | |
887 | static const operator_rankT | |
2ed83a59 KR |
888 | op_rank[] = |
889 | {0, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1}; | |
fecd2382 RP |
890 | \f |
891 | /* Return resultP->X_seg. */ | |
2ed83a59 KR |
892 | segT |
893 | expr (rank, resultP) | |
894 | register operator_rankT rank; /* Larger # is higher rank. */ | |
895 | register expressionS *resultP; /* Deliver result here. */ | |
fecd2382 | 896 | { |
2ed83a59 KR |
897 | expressionS right; |
898 | register operatorT op_left; | |
899 | register char c_left; /* 1st operator character. */ | |
900 | register operatorT op_right; | |
c593cf41 SC |
901 | register char c_right; |
902 | ||
2ed83a59 KR |
903 | know (rank >= 0); |
904 | (void) operand (resultP); | |
905 | know (*input_line_pointer != ' '); /* Operand() gobbles spaces. */ | |
906 | c_left = *input_line_pointer; /* Potential operator character. */ | |
907 | op_left = op_encoding[c_left]; | |
908 | while (op_left != O_illegal && op_rank[(int) op_left] > rank) | |
fecd2382 | 909 | { |
2ed83a59 KR |
910 | input_line_pointer++; /*->after 1st character of operator. */ |
911 | /* Operators "<<" and ">>" have 2 characters. */ | |
912 | if (*input_line_pointer == c_left && (c_left == '<' || c_left == '>')) | |
fecd2382 | 913 | { |
2ed83a59 | 914 | input_line_pointer++; |
fecd2382 | 915 | } /*->after operator. */ |
c593cf41 | 916 | if (SEG_ABSENT == expr (op_rank[(int) op_left], &right)) |
fecd2382 | 917 | { |
2ed83a59 KR |
918 | as_warn ("Missing operand value assumed absolute 0."); |
919 | resultP->X_add_number = 0; | |
920 | resultP->X_subtract_symbol = NULL; | |
921 | resultP->X_add_symbol = NULL; | |
c593cf41 | 922 | resultP->X_seg = SEG_ABSOLUTE; |
fecd2382 | 923 | } |
2ed83a59 KR |
924 | know (*input_line_pointer != ' '); |
925 | c_right = *input_line_pointer; | |
926 | op_right = op_encoding[c_right]; | |
927 | if (*input_line_pointer == c_right && (c_right == '<' || c_right == '>')) | |
fecd2382 | 928 | { |
2ed83a59 | 929 | input_line_pointer++; |
fecd2382 | 930 | } /*->after operator. */ |
2ed83a59 | 931 | know ((int) op_right == 0 || op_rank[(int) op_right] <= op_rank[(int) op_left]); |
c593cf41 SC |
932 | /* input_line_pointer->after right-hand quantity. */ |
933 | /* left-hand quantity in resultP */ | |
934 | /* right-hand quantity in right. */ | |
935 | /* operator in op_left. */ | |
2ed83a59 | 936 | if (resultP->X_seg == SEG_PASS1 || right.X_seg == SEG_PASS1) |
fecd2382 | 937 | { |
c593cf41 | 938 | resultP->X_seg = SEG_PASS1; |
fecd2382 | 939 | } |
c593cf41 | 940 | else |
fecd2382 | 941 | { |
c593cf41 | 942 | if (resultP->X_seg == SEG_BIG) |
fecd2382 | 943 | { |
2ed83a59 KR |
944 | as_warn ("Left operand of %c is a %s. Integer 0 assumed.", |
945 | c_left, resultP->X_add_number > 0 ? "bignum" : "float"); | |
c593cf41 SC |
946 | resultP->X_seg = SEG_ABSOLUTE; |
947 | resultP->X_add_symbol = 0; | |
948 | resultP->X_subtract_symbol = 0; | |
949 | resultP->X_add_number = 0; | |
fecd2382 | 950 | } |
2ed83a59 | 951 | if (right.X_seg == SEG_BIG) |
fecd2382 | 952 | { |
2ed83a59 KR |
953 | as_warn ("Right operand of %c is a %s. Integer 0 assumed.", |
954 | c_left, right.X_add_number > 0 ? "bignum" : "float"); | |
955 | right.X_seg = SEG_ABSOLUTE; | |
956 | right.X_add_symbol = 0; | |
957 | right.X_subtract_symbol = 0; | |
958 | right.X_add_number = 0; | |
fecd2382 | 959 | } |
c593cf41 | 960 | if (op_left == O_subtract) |
fecd2382 | 961 | { |
c593cf41 SC |
962 | /* |
963 | * Convert - into + by exchanging symbolS and negating number. | |
964 | * I know -infinity can't be negated in 2's complement: | |
965 | * but then it can't be subtracted either. This trick | |
966 | * does not cause any further inaccuracy. | |
967 | */ | |
968 | ||
2ed83a59 | 969 | register symbolS *symbolP; |
c593cf41 | 970 | |
2ed83a59 KR |
971 | right.X_add_number = -right.X_add_number; |
972 | symbolP = right.X_add_symbol; | |
973 | right.X_add_symbol = right.X_subtract_symbol; | |
974 | right.X_subtract_symbol = symbolP; | |
c593cf41 | 975 | if (symbolP) |
fecd2382 | 976 | { |
2ed83a59 | 977 | right.X_seg = SEG_DIFFERENCE; |
fecd2382 | 978 | } |
c593cf41 | 979 | op_left = O_add; |
fecd2382 | 980 | } |
c593cf41 SC |
981 | \f |
982 | if (op_left == O_add) | |
fecd2382 | 983 | { |
2ed83a59 KR |
984 | segT seg1; |
985 | segT seg2; | |
a39116f1 | 986 | #ifndef MANY_SEGMENTS |
2ed83a59 KR |
987 | |
988 | know (resultP->X_seg == SEG_DATA || resultP->X_seg == SEG_TEXT || resultP->X_seg == SEG_BSS || resultP->X_seg == SEG_UNKNOWN || resultP->X_seg == SEG_DIFFERENCE || resultP->X_seg == SEG_ABSOLUTE || resultP->X_seg == SEG_PASS1 || resultP->X_seg == SEG_REGISTER); | |
989 | ||
990 | know (right.X_seg == SEG_DATA || right.X_seg == SEG_TEXT || right.X_seg == SEG_BSS || right.X_seg == SEG_UNKNOWN || right.X_seg == SEG_DIFFERENCE || right.X_seg == SEG_ABSOLUTE || right.X_seg == SEG_PASS1); | |
a39116f1 | 991 | #endif |
2ed83a59 | 992 | clean_up_expression (&right); |
c593cf41 SC |
993 | clean_up_expression (resultP); |
994 | ||
2ed83a59 KR |
995 | seg1 = expr_part (&resultP->X_add_symbol, right.X_add_symbol); |
996 | seg2 = expr_part (&resultP->X_subtract_symbol, right.X_subtract_symbol); | |
997 | if (seg1 == SEG_PASS1 || seg2 == SEG_PASS1) | |
998 | { | |
999 | need_pass_2 = 1; | |
1000 | resultP->X_seg = SEG_PASS1; | |
1001 | } | |
1002 | else if (seg2 == SEG_ABSOLUTE) | |
1003 | resultP->X_seg = seg1; | |
c593cf41 SC |
1004 | else if (seg1 != SEG_UNKNOWN |
1005 | && seg1 != SEG_ABSOLUTE | |
1006 | && seg2 != SEG_UNKNOWN | |
2ed83a59 KR |
1007 | && seg1 != seg2) |
1008 | { | |
1009 | know (seg2 != SEG_ABSOLUTE); | |
1010 | know (resultP->X_subtract_symbol); | |
a39116f1 | 1011 | #ifndef MANY_SEGMENTS |
2ed83a59 KR |
1012 | know (seg1 == SEG_TEXT || seg1 == SEG_DATA || seg1 == SEG_BSS); |
1013 | know (seg2 == SEG_TEXT || seg2 == SEG_DATA || seg2 == SEG_BSS); | |
a39116f1 | 1014 | #endif |
2ed83a59 KR |
1015 | know (resultP->X_add_symbol); |
1016 | know (resultP->X_subtract_symbol); | |
1017 | as_bad ("Expression too complex: forgetting %s - %s", | |
1018 | S_GET_NAME (resultP->X_add_symbol), | |
1019 | S_GET_NAME (resultP->X_subtract_symbol)); | |
1020 | resultP->X_seg = SEG_ABSOLUTE; | |
1021 | /* Clean_up_expression() will do the rest. */ | |
1022 | } | |
1023 | else | |
1024 | resultP->X_seg = SEG_DIFFERENCE; | |
c593cf41 | 1025 | |
2ed83a59 | 1026 | resultP->X_add_number += right.X_add_number; |
c593cf41 | 1027 | clean_up_expression (resultP); |
2ed83a59 | 1028 | } |
c593cf41 | 1029 | else |
fecd2382 | 1030 | { /* Not +. */ |
2ed83a59 | 1031 | if (resultP->X_seg == SEG_UNKNOWN || right.X_seg == SEG_UNKNOWN) |
fecd2382 | 1032 | { |
c593cf41 SC |
1033 | resultP->X_seg = SEG_PASS1; |
1034 | need_pass_2 = 1; | |
fecd2382 | 1035 | } |
c593cf41 | 1036 | else |
fecd2382 | 1037 | { |
c593cf41 SC |
1038 | resultP->X_subtract_symbol = NULL; |
1039 | resultP->X_add_symbol = NULL; | |
1040 | /* Will be SEG_ABSOLUTE. */ | |
2ed83a59 | 1041 | if (resultP->X_seg != SEG_ABSOLUTE || right.X_seg != SEG_ABSOLUTE) |
fecd2382 | 1042 | { |
2ed83a59 KR |
1043 | as_bad ("Relocation error. Absolute 0 assumed."); |
1044 | resultP->X_seg = SEG_ABSOLUTE; | |
c593cf41 | 1045 | resultP->X_add_number = 0; |
fecd2382 | 1046 | } |
c593cf41 | 1047 | else |
fecd2382 | 1048 | { |
c593cf41 | 1049 | switch (op_left) |
fecd2382 RP |
1050 | { |
1051 | case O_bit_inclusive_or: | |
2ed83a59 | 1052 | resultP->X_add_number |= right.X_add_number; |
c593cf41 SC |
1053 | break; |
1054 | ||
fecd2382 | 1055 | case O_modulus: |
2ed83a59 | 1056 | if (right.X_add_number) |
fecd2382 | 1057 | { |
2ed83a59 | 1058 | resultP->X_add_number %= right.X_add_number; |
fecd2382 | 1059 | } |
c593cf41 | 1060 | else |
fecd2382 | 1061 | { |
2ed83a59 | 1062 | as_warn ("Division by 0. 0 assumed."); |
c593cf41 | 1063 | resultP->X_add_number = 0; |
fecd2382 | 1064 | } |
c593cf41 SC |
1065 | break; |
1066 | ||
fecd2382 | 1067 | case O_bit_and: |
2ed83a59 | 1068 | resultP->X_add_number &= right.X_add_number; |
c593cf41 SC |
1069 | break; |
1070 | ||
fecd2382 | 1071 | case O_multiply: |
2ed83a59 | 1072 | resultP->X_add_number *= right.X_add_number; |
c593cf41 SC |
1073 | break; |
1074 | ||
fecd2382 | 1075 | case O_divide: |
2ed83a59 | 1076 | if (right.X_add_number) |
fecd2382 | 1077 | { |
2ed83a59 | 1078 | resultP->X_add_number /= right.X_add_number; |
fecd2382 | 1079 | } |
c593cf41 | 1080 | else |
fecd2382 | 1081 | { |
2ed83a59 KR |
1082 | as_warn ("Division by 0. 0 assumed."); |
1083 | resultP->X_add_number = 0; | |
fecd2382 | 1084 | } |
2ed83a59 KR |
1085 | break; |
1086 | ||
fecd2382 | 1087 | case O_left_shift: |
2ed83a59 KR |
1088 | resultP->X_add_number <<= right.X_add_number; |
1089 | break; | |
1090 | ||
fecd2382 | 1091 | case O_right_shift: |
2ed83a59 KR |
1092 | resultP->X_add_number >>= right.X_add_number; |
1093 | break; | |
1094 | ||
fecd2382 | 1095 | case O_bit_exclusive_or: |
2ed83a59 KR |
1096 | resultP->X_add_number ^= right.X_add_number; |
1097 | break; | |
1098 | ||
fecd2382 | 1099 | case O_bit_or_not: |
2ed83a59 KR |
1100 | resultP->X_add_number |= ~right.X_add_number; |
1101 | break; | |
1102 | ||
fecd2382 | 1103 | default: |
2ed83a59 KR |
1104 | BAD_CASE (op_left); |
1105 | break; | |
1106 | } /* switch(operator) */ | |
fecd2382 RP |
1107 | } |
1108 | } /* If we have to force need_pass_2. */ | |
1109 | } /* If operator was +. */ | |
1110 | } /* If we didn't set need_pass_2. */ | |
2ed83a59 | 1111 | op_left = op_right; |
fecd2382 | 1112 | } /* While next operator is >= this rank. */ |
2ed83a59 | 1113 | return (resultP->X_seg); |
fecd2382 RP |
1114 | } |
1115 | \f | |
1116 | /* | |
1117 | * get_symbol_end() | |
1118 | * | |
1119 | * This lives here because it belongs equally in expr.c & read.c. | |
1120 | * Expr.c is just a branch office read.c anyway, and putting it | |
1121 | * here lessens the crowd at read.c. | |
1122 | * | |
1123 | * Assume input_line_pointer is at start of symbol name. | |
1124 | * Advance input_line_pointer past symbol name. | |
1125 | * Turn that character into a '\0', returning its former value. | |
1126 | * This allows a string compare (RMS wants symbol names to be strings) | |
1127 | * of the symbol name. | |
1128 | * There will always be a char following symbol name, because all good | |
1129 | * lines end in end-of-line. | |
1130 | */ | |
1131 | char | |
2ed83a59 | 1132 | get_symbol_end () |
fecd2382 | 1133 | { |
2ed83a59 KR |
1134 | register char c; |
1135 | ||
1136 | while (is_part_of_name (c = *input_line_pointer++)) | |
1137 | ; | |
1138 | *--input_line_pointer = 0; | |
1139 | return (c); | |
fecd2382 RP |
1140 | } |
1141 | ||
a39116f1 | 1142 | |
2ed83a59 KR |
1143 | unsigned int |
1144 | get_single_number () | |
a39116f1 | 1145 | { |
2ed83a59 KR |
1146 | expressionS exp; |
1147 | operand (&exp); | |
1148 | return exp.X_add_number; | |
1149 | ||
a39116f1 | 1150 | } |
2ed83a59 | 1151 | |
8b228fe9 | 1152 | /* end of expr.c */ |