* gmon.h, gprof.h: structs of chars used to hold external
[deliverable/binutils-gdb.git] / gas / read.c
1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #if 0
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
25 */
26 #else
27 #define MASK_CHAR ((int)(unsigned char)-1)
28 #endif
29
30
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
33
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
35
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
38
39 /* for isdigit() */
40 #include <ctype.h>
41
42 #include "as.h"
43 #ifdef BFD_ASSEMBLER
44 #include "subsegs.h"
45 #endif
46
47 #include "obstack.h"
48 #include "listing.h"
49
50
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
53 #endif
54
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
57 * on it
58 */
59 #ifndef NOP_OPCODE
60 #define NOP_OPCODE 0x00
61 #endif
62
63 char *input_line_pointer; /*->next char of source file to parse. */
64
65 #if BITS_PER_CHAR != 8
66 /* The following table is indexed by[(char)] and will break if
67 a char does not have exactly 256 states (hopefully 0:255!)! */
68 die horribly;
69 #endif
70
71 /* used by is_... macros. our ctype[] */
72 const char lex_type[256] =
73 {
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
76 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
77 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
78 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
79 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
80 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
81 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 };
90
91
92 /*
93 * In: a character.
94 * Out: 1 if this character ends a line.
95 */
96 #define _ (0)
97 char is_end_of_line[256] =
98 {
99 #ifdef CR_EOL
100 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
101 #else
102 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
103 #endif
104 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
105 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
106 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
107 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
108 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
109 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
110 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
111 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
112 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
113 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
115 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
116 };
117 #undef _
118
119 /* Functions private to this file. */
120
121 static char *buffer; /* 1st char of each buffer of lines is here. */
122 static char *buffer_limit; /*->1 + last char in buffer. */
123
124 static char *bignum_low; /* Lowest char of bignum. */
125 static char *bignum_limit; /* 1st illegal address of bignum. */
126 static char *bignum_high; /* Highest char of bignum. */
127 /* May point to (bignum_start-1). */
128 /* Never >= bignum_limit. */
129
130 int target_big_endian;
131
132 static char *old_buffer; /* JF a hack */
133 static char *old_input;
134 static char *old_limit;
135
136 /* Variables for handling include file directory list. */
137
138 char **include_dirs; /* List of pointers to directories to
139 search for .include's */
140 int include_dir_count; /* How many are in the list */
141 int include_dir_maxlen = 1;/* Length of longest in list */
142
143 #ifndef WORKING_DOT_WORD
144 struct broken_word *broken_words;
145 int new_broken_words;
146 #endif
147
148 static char *demand_copy_string PARAMS ((int *lenP));
149 int is_it_end_of_statement PARAMS ((void));
150 unsigned int next_char_of_string PARAMS ((void));
151 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
152 static void grow_bignum PARAMS ((void));
153 static void pobegin PARAMS ((void));
154
155 extern int listing;
156 \f
157
158 void
159 read_begin ()
160 {
161 const char *p;
162
163 pobegin ();
164 obj_read_begin_hook ();
165
166 obstack_begin (&notes, 5000);
167 obstack_begin (&cond_obstack, 960);
168
169 #define BIGNUM_BEGIN_SIZE (16)
170 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
171 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
172
173 /* Use machine dependent syntax */
174 for (p = line_separator_chars; *p; p++)
175 is_end_of_line[*p] = 1;
176 /* Use more. FIXME-SOMEDAY. */
177 }
178 \f
179 /* set up pseudo-op tables */
180
181 struct hash_control *po_hash;
182
183 static const pseudo_typeS potable[] =
184 {
185 {"abort", s_abort, 0},
186 {"align", s_align_ptwo, 0},
187 {"ascii", stringer, 0},
188 {"asciz", stringer, 1},
189 /* block */
190 {"byte", cons, 1},
191 {"comm", s_comm, 0},
192 {"data", s_data, 0},
193 /* dim */
194 {"double", float_cons, 'd'},
195 /* dsect */
196 {"eject", listing_eject, 0}, /* Formfeed listing */
197 {"else", s_else, 0},
198 {"end", s_end, 0},
199 {"endif", s_endif, 0},
200 /* endef */
201 {"equ", s_set, 0},
202 /* err */
203 /* extend */
204 {"extern", s_ignore, 0}, /* We treat all undef as ext */
205 {"appfile", s_app_file, 1},
206 {"appline", s_app_line, 0},
207 {"file", s_app_file, 0},
208 {"fill", s_fill, 0},
209 {"float", float_cons, 'f'},
210 {"global", s_globl, 0},
211 {"globl", s_globl, 0},
212 {"hword", cons, 2},
213 {"if", s_if, 0},
214 {"ifdef", s_ifdef, 0},
215 {"ifeqs", s_ifeqs, 0},
216 {"ifndef", s_ifdef, 1},
217 {"ifnes", s_ifeqs, 1},
218 {"ifnotdef", s_ifdef, 1},
219 {"include", s_include, 0},
220 {"int", cons, 4},
221 {"lcomm", s_lcomm, 0},
222 {"lflags", listing_flags, 0}, /* Listing flags */
223 {"list", listing_list, 1}, /* Turn listing on */
224 {"long", cons, 4},
225 {"lsym", s_lsym, 0},
226 {"nolist", listing_list, 0}, /* Turn listing off */
227 {"octa", big_cons, 16},
228 {"org", s_org, 0},
229 {"psize", listing_psize, 0}, /* set paper size */
230 /* print */
231 {"quad", big_cons, 8},
232 {"sbttl", listing_title, 1}, /* Subtitle of listing */
233 /* scl */
234 /* sect */
235 {"set", s_set, 0},
236 {"short", cons, 2},
237 {"single", float_cons, 'f'},
238 /* size */
239 {"space", s_space, 0},
240 /* tag */
241 {"text", s_text, 0},
242 {"title", listing_title, 0}, /* Listing title */
243 /* type */
244 /* use */
245 /* val */
246 {"word", cons, 2},
247 {NULL} /* end sentinel */
248 };
249
250 static void
251 pobegin ()
252 {
253 char *errtxt; /* error text */
254 const pseudo_typeS *pop;
255
256 po_hash = hash_new ();
257
258 /* Do the target-specific pseudo ops. */
259 for (pop = md_pseudo_table; pop->poc_name; pop++)
260 {
261 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
262 if (errtxt && *errtxt)
263 {
264 as_fatal ("error constructing md pseudo-op table");
265 } /* on error */
266 } /* for each op */
267
268 /* Now object specific. Skip any that were in the target table. */
269 for (pop = obj_pseudo_table; pop->poc_name; pop++)
270 {
271 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
272 if (errtxt && *errtxt)
273 {
274 if (!strcmp (errtxt, "exists"))
275 {
276 #ifdef DIE_ON_OVERRIDES
277 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
278 #endif /* DIE_ON_OVERRIDES */
279 continue; /* OK if target table overrides. */
280 }
281 else
282 {
283 as_fatal ("error constructing obj pseudo-op table");
284 } /* if overridden */
285 } /* on error */
286 } /* for each op */
287
288 /* Now portable ones. Skip any that we've seen already. */
289 for (pop = potable; pop->poc_name; pop++)
290 {
291 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
292 if (errtxt && *errtxt)
293 {
294 if (!strcmp (errtxt, "exists"))
295 {
296 #ifdef DIE_ON_OVERRIDES
297 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
298 #endif /* DIE_ON_OVERRIDES */
299 continue; /* OK if target table overrides. */
300 }
301 else
302 {
303 as_fatal ("error constructing obj pseudo-op table");
304 } /* if overridden */
305 } /* on error */
306 } /* for each op */
307
308 return;
309 } /* pobegin() */
310 \f
311 #define HANDLE_CONDITIONAL_ASSEMBLY() \
312 if (ignore_input ()) \
313 { \
314 while (! is_end_of_line[*input_line_pointer++]) \
315 if (input_line_pointer == buffer_limit) \
316 break; \
317 continue; \
318 }
319
320
321 /* read_a_source_file()
322 *
323 * We read the file, putting things into a web that
324 * represents what we have been reading.
325 */
326 void
327 read_a_source_file (name)
328 char *name;
329 {
330 register char c;
331 register char *s; /* string of symbol, '\0' appended */
332 register int temp;
333 /* register struct frag * fragP; JF unused *//* a frag we just made */
334 pseudo_typeS *pop;
335
336 buffer = input_scrub_new_file (name);
337
338 listing_file (name);
339 listing_newline ("");
340
341 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
342 { /* We have another line to parse. */
343 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
344 contin: /* JF this goto is my fault I admit it.
345 Someone brave please re-write the whole
346 input section here? Pleeze??? */
347 while (input_line_pointer < buffer_limit)
348 {
349 /* We have more of this buffer to parse. */
350
351 /*
352 * We now have input_line_pointer->1st char of next line.
353 * If input_line_pointer [-1] == '\n' then we just
354 * scanned another line: so bump line counters.
355 */
356 if (input_line_pointer[-1] == '\n')
357 {
358 bump_line_counters ();
359
360 #ifdef MRI
361 /* Text at the start of a line must be a label, we run down and stick a colon in */
362 if (is_name_beginner (*input_line_pointer))
363 {
364 char *line_start = input_line_pointer;
365 char c = get_symbol_end ();
366 colon (line_start);
367 *input_line_pointer = c;
368 if (c == ':')
369 input_line_pointer++;
370
371 }
372 #endif
373 }
374
375
376 /*
377 * We are at the begining of a line, or similar place.
378 * We expect a well-formed assembler statement.
379 * A "symbol-name:" is a statement.
380 *
381 * Depending on what compiler is used, the order of these tests
382 * may vary to catch most common case 1st.
383 * Each test is independent of all other tests at the (top) level.
384 * PLEASE make a compiler that doesn't use this assembler.
385 * It is crufty to waste a compiler's time encoding things for this
386 * assembler, which then wastes more time decoding it.
387 * (And communicating via (linear) files is silly!
388 * If you must pass stuff, please pass a tree!)
389 */
390 if ((c = *input_line_pointer++) == '\t'
391 || c == ' '
392 || c == '\f'
393 || c == 0)
394 {
395 c = *input_line_pointer++;
396 }
397 know (c != ' '); /* No further leading whitespace. */
398 LISTING_NEWLINE ();
399 /*
400 * C is the 1st significant character.
401 * Input_line_pointer points after that character.
402 */
403 if (is_name_beginner (c))
404 { /* want user-defined label or pseudo/opcode */
405 HANDLE_CONDITIONAL_ASSEMBLY ();
406
407 s = --input_line_pointer;
408 c = get_symbol_end (); /* name's delimiter */
409 /*
410 * C is character after symbol.
411 * That character's place in the input line is now '\0'.
412 * S points to the beginning of the symbol.
413 * [In case of pseudo-op, s->'.'.]
414 * Input_line_pointer->'\0' where c was.
415 */
416 if (TC_START_LABEL(c, input_line_pointer))
417 {
418 colon (s); /* user-defined label */
419 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
420 /* Input_line_pointer->after ':'. */
421 SKIP_WHITESPACE ();
422
423
424 }
425 else if (c == '=' || input_line_pointer[1] == '=')
426 {
427 equals (s);
428 demand_empty_rest_of_line ();
429 }
430 else
431 { /* expect pseudo-op or machine instruction */
432 #ifdef MRI
433 if (!done_pseudo (s))
434
435 #else
436 if (*s == '.')
437 {
438 /*
439 * PSEUDO - OP.
440 *
441 * WARNING: c has next char, which may be end-of-line.
442 * We lookup the pseudo-op table with s+1 because we
443 * already know that the pseudo-op begins with a '.'.
444 */
445
446 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
447
448 /* Print the error msg now, while we still can */
449 if (!pop)
450 {
451 as_bad ("Unknown pseudo-op: `%s'", s);
452 *input_line_pointer = c;
453 s_ignore (0);
454 break;
455 }
456
457 /* Put it back for error messages etc. */
458 *input_line_pointer = c;
459 /* The following skip of whitespace is compulsory.
460 A well shaped space is sometimes all that separates
461 keyword from operands. */
462 if (c == ' ' || c == '\t')
463 {
464 input_line_pointer++;
465 } /* Skip seperator after keyword. */
466 /*
467 * Input_line is restored.
468 * Input_line_pointer->1st non-blank char
469 * after pseudo-operation.
470 */
471 if (!pop)
472 {
473 ignore_rest_of_line ();
474 break;
475 }
476 else
477 {
478 (*pop->poc_handler) (pop->poc_val);
479 } /* if we have one */
480 }
481 else
482 #endif
483 { /* machine instruction */
484 /* WARNING: c has char, which may be end-of-line. */
485 /* Also: input_line_pointer->`\0` where c was. */
486 *input_line_pointer = c;
487 while (!is_end_of_line[*input_line_pointer])
488 {
489 input_line_pointer++;
490 }
491
492 c = *input_line_pointer;
493 *input_line_pointer = '\0';
494
495 md_assemble (s); /* Assemble 1 instruction. */
496
497 *input_line_pointer++ = c;
498
499 /* We resume loop AFTER the end-of-line from this instruction */
500 } /* if (*s=='.') */
501
502 } /* if c==':' */
503 continue;
504 } /* if (is_name_beginner(c) */
505
506
507 if (is_end_of_line[c])
508 {
509 continue;
510 } /* empty statement */
511
512
513 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
514 if (isdigit (c))
515 { /* local label ("4:") */
516 char *backup = input_line_pointer;
517
518 HANDLE_CONDITIONAL_ASSEMBLY ();
519
520 temp = c - '0';
521
522 while (isdigit (*input_line_pointer))
523 {
524 temp = (temp * 10) + *input_line_pointer - '0';
525 ++input_line_pointer;
526 } /* read the whole number */
527
528 #ifdef LOCAL_LABELS_DOLLAR
529 if (*input_line_pointer == '$'
530 && *(input_line_pointer + 1) == ':')
531 {
532 input_line_pointer += 2;
533
534 if (dollar_label_defined (temp))
535 {
536 as_fatal ("label \"%d$\" redefined", temp);
537 }
538
539 define_dollar_label (temp);
540 colon (dollar_label_name (temp, 0));
541 continue;
542 }
543 #endif /* LOCAL_LABELS_DOLLAR */
544
545 #ifdef LOCAL_LABELS_FB
546 if (*input_line_pointer++ == ':')
547 {
548 fb_label_instance_inc (temp);
549 colon (fb_label_name (temp, 0));
550 continue;
551 }
552 #endif /* LOCAL_LABELS_FB */
553
554 input_line_pointer = backup;
555 } /* local label ("4:") */
556 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
557
558 if (c && strchr (line_comment_chars, c))
559 { /* Its a comment. Better say APP or NO_APP */
560 char *ends;
561 char *new_buf;
562 char *new_tmp;
563 int new_length;
564 char *tmp_buf = 0;
565 extern char *scrub_string, *scrub_last_string;
566
567 bump_line_counters ();
568 s = input_line_pointer;
569 if (strncmp (s, "APP\n", 4))
570 continue; /* We ignore it */
571 s += 4;
572
573 ends = strstr (s, "#NO_APP\n");
574
575 if (!ends)
576 {
577 int tmp_len;
578 int num;
579
580 /* The end of the #APP wasn't in this buffer. We
581 keep reading in buffers until we find the #NO_APP
582 that goes with this #APP There is one. The specs
583 guarentee it. . . */
584 tmp_len = buffer_limit - s;
585 tmp_buf = xmalloc (tmp_len + 1);
586 bcopy (s, tmp_buf, tmp_len);
587 do
588 {
589 new_tmp = input_scrub_next_buffer (&buffer);
590 if (!new_tmp)
591 break;
592 else
593 buffer_limit = new_tmp;
594 input_line_pointer = buffer;
595 ends = strstr (buffer, "#NO_APP\n");
596 if (ends)
597 num = ends - buffer;
598 else
599 num = buffer_limit - buffer;
600
601 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
602 bcopy (buffer, tmp_buf + tmp_len, num);
603 tmp_len += num;
604 }
605 while (!ends);
606
607 input_line_pointer = ends ? ends + 8 : NULL;
608
609 s = tmp_buf;
610 ends = s + tmp_len;
611
612 }
613 else
614 {
615 input_line_pointer = ends + 8;
616 }
617 new_buf = xmalloc (100);
618 new_length = 100;
619 new_tmp = new_buf;
620
621 scrub_string = s;
622 scrub_last_string = ends;
623 for (;;)
624 {
625 int ch;
626
627 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
628 if (ch == EOF)
629 break;
630 *new_tmp++ = ch;
631 if (new_tmp == new_buf + new_length)
632 {
633 new_buf = xrealloc (new_buf, new_length + 100);
634 new_tmp = new_buf + new_length;
635 new_length += 100;
636 }
637 }
638
639 if (tmp_buf)
640 free (tmp_buf);
641 old_buffer = buffer;
642 old_input = input_line_pointer;
643 old_limit = buffer_limit;
644 buffer = new_buf;
645 input_line_pointer = new_buf;
646 buffer_limit = new_tmp;
647 continue;
648 }
649
650 HANDLE_CONDITIONAL_ASSEMBLY ();
651
652 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
653 input_line_pointer--; /* Report unknown char as ignored. */
654 ignore_rest_of_line ();
655 } /* while (input_line_pointer<buffer_limit) */
656 if (old_buffer)
657 {
658 bump_line_counters ();
659 if (old_input != 0)
660 {
661 buffer = old_buffer;
662 input_line_pointer = old_input;
663 buffer_limit = old_limit;
664 old_buffer = 0;
665 goto contin;
666 }
667 }
668 } /* while (more buffers to scan) */
669 input_scrub_close (); /* Close the input file */
670
671 } /* read_a_source_file() */
672
673 void
674 s_abort ()
675 {
676 as_fatal (".abort detected. Abandoning ship.");
677 } /* s_abort() */
678
679 /* For machines where ".align 4" means align to a 4 byte boundary. */
680 void
681 s_align_bytes (arg)
682 int arg;
683 {
684 register unsigned int temp;
685 register long temp_fill;
686 unsigned int i = 0;
687 unsigned long max_alignment = 1 << 15;
688
689 if (is_end_of_line[*input_line_pointer])
690 temp = arg; /* Default value from pseudo-op table */
691 else
692 temp = get_absolute_expression ();
693
694 if (temp > max_alignment)
695 {
696 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
697 }
698
699 /*
700 * For the sparc, `.align (1<<n)' actually means `.align n'
701 * so we have to convert it.
702 */
703 if (temp != 0)
704 {
705 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
706 ;
707 }
708 if (temp != 1)
709 as_bad ("Alignment not a power of 2");
710
711 temp = i;
712 if (*input_line_pointer == ',')
713 {
714 input_line_pointer++;
715 temp_fill = get_absolute_expression ();
716 }
717 else if (now_seg != data_section && now_seg != bss_section)
718 temp_fill = NOP_OPCODE;
719 else
720 temp_fill = 0;
721 /* Only make a frag if we HAVE to. . . */
722 if (temp && !need_pass_2)
723 frag_align (temp, (int) temp_fill);
724
725 record_alignment (now_seg, temp);
726
727 demand_empty_rest_of_line ();
728 } /* s_align_bytes() */
729
730 /* For machines where ".align 4" means align to 2**4 boundary. */
731 void
732 s_align_ptwo ()
733 {
734 register int temp;
735 register long temp_fill;
736 long max_alignment = 15;
737
738 temp = get_absolute_expression ();
739 if (temp > max_alignment)
740 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
741 else if (temp < 0)
742 {
743 as_bad ("Alignment negative. 0 assumed.");
744 temp = 0;
745 }
746 if (*input_line_pointer == ',')
747 {
748 input_line_pointer++;
749 temp_fill = get_absolute_expression ();
750 }
751 /* @@ Fix this right for BFD! */
752 else if (now_seg != data_section && now_seg != bss_section)
753 temp_fill = NOP_OPCODE;
754 else
755 temp_fill = 0;
756 /* Only make a frag if we HAVE to. . . */
757 if (temp && !need_pass_2)
758 frag_align (temp, (int) temp_fill);
759
760 record_alignment (now_seg, temp);
761
762 demand_empty_rest_of_line ();
763 } /* s_align_ptwo() */
764
765 void
766 s_comm ()
767 {
768 register char *name;
769 register char c;
770 register char *p;
771 register int temp;
772 register symbolS *symbolP;
773
774 name = input_line_pointer;
775 c = get_symbol_end ();
776 /* just after name is now '\0' */
777 p = input_line_pointer;
778 *p = c;
779 SKIP_WHITESPACE ();
780 if (*input_line_pointer != ',')
781 {
782 as_bad ("Expected comma after symbol-name: rest of line ignored.");
783 ignore_rest_of_line ();
784 return;
785 }
786 input_line_pointer++; /* skip ',' */
787 if ((temp = get_absolute_expression ()) < 0)
788 {
789 as_warn (".COMMon length (%d.) <0! Ignored.", temp);
790 ignore_rest_of_line ();
791 return;
792 }
793 *p = 0;
794 symbolP = symbol_find_or_make (name);
795 *p = c;
796 if (S_IS_DEFINED (symbolP))
797 {
798 as_bad ("Ignoring attempt to re-define symbol");
799 ignore_rest_of_line ();
800 return;
801 }
802 if (S_GET_VALUE (symbolP))
803 {
804 if (S_GET_VALUE (symbolP) != temp)
805 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
806 S_GET_NAME (symbolP),
807 S_GET_VALUE (symbolP),
808 temp);
809 }
810 else
811 {
812 S_SET_VALUE (symbolP, temp);
813 S_SET_EXTERNAL (symbolP);
814 }
815 #ifdef OBJ_VMS
816 if ( (!temp) || !flagseen['1'])
817 S_GET_OTHER(symbolP) = const_flag;
818 #endif /* not OBJ_VMS */
819 know (symbolP->sy_frag == &zero_address_frag);
820 demand_empty_rest_of_line ();
821 } /* s_comm() */
822
823 void
824 s_data ()
825 {
826 register int temp;
827
828 temp = get_absolute_expression ();
829 #ifdef BFD_ASSEMBLER
830 subseg_set (data_section, (subsegT) temp);
831 #else
832 subseg_new (data_section, (subsegT) temp);
833 #endif
834
835 #ifdef OBJ_VMS
836 const_flag = 0;
837 #endif
838 demand_empty_rest_of_line ();
839 }
840
841 /* Handle the .appfile pseudo-op. This is automatically generated by
842 do_scrub_next_char when a preprocessor # line comment is seen with
843 a file name. This default definition may be overridden by the
844 object or CPU specific pseudo-ops. This function is also the
845 default definition for .file; the APPFILE argument is 1 for
846 .appfile, 0 for .file. */
847
848 void
849 s_app_file (appfile)
850 int appfile;
851 {
852 register char *s;
853 int length;
854
855 /* Some assemblers tolerate immediately following '"' */
856 if ((s = demand_copy_string (&length)) != 0)
857 {
858 /* If this is a fake .appfile, a fake newline was inserted into
859 the buffer. Passing -2 to new_logical_line tells it to
860 account for it. */
861 new_logical_line (s, appfile ? -2 : -1);
862 demand_empty_rest_of_line ();
863 #ifdef LISTING
864 if (listing)
865 listing_source_file (s);
866 #endif
867 }
868 #ifdef OBJ_COFF
869 c_dot_file_symbol (s);
870 #endif /* OBJ_COFF */
871 } /* s_app_file() */
872
873 /* Handle the .appline pseudo-op. This is automatically generated by
874 do_scrub_next_char when a preprocessor # line comment is seen.
875 This default definition may be overridden by the object or CPU
876 specific pseudo-ops. */
877
878 void
879 s_app_line ()
880 {
881 int l;
882
883 /* The given number is that of the next line. */
884 l = get_absolute_expression () - 1;
885 new_logical_line ((char *) NULL, l);
886 #ifdef LISTING
887 if (listing)
888 listing_source_line (l);
889 #endif
890 demand_empty_rest_of_line ();
891 }
892
893 void
894 s_fill ()
895 {
896 long temp_repeat = 0;
897 long temp_size = 1;
898 register long temp_fill = 0;
899 char *p;
900
901
902 temp_repeat = get_absolute_expression ();
903 if (*input_line_pointer == ',')
904 {
905 input_line_pointer++;
906 temp_size = get_absolute_expression ();
907 if (*input_line_pointer == ',')
908 {
909 input_line_pointer++;
910 temp_fill = get_absolute_expression ();
911 }
912 }
913 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
914 #define BSD_FILL_SIZE_CROCK_8 (8)
915 if (temp_size > BSD_FILL_SIZE_CROCK_8)
916 {
917 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
918 temp_size = BSD_FILL_SIZE_CROCK_8;
919 }
920 if (temp_size < 0)
921 {
922 as_warn ("Size negative: .fill ignored.");
923 temp_size = 0;
924 }
925 else if (temp_repeat <= 0)
926 {
927 as_warn ("Repeat < 0, .fill ignored");
928 temp_size = 0;
929 }
930
931 if (temp_size && !need_pass_2)
932 {
933 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
934 memset (p, 0, (int) temp_size);
935 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
936 * flavoured AS. The following bizzare behaviour is to be
937 * compatible with above. I guess they tried to take up to 8
938 * bytes from a 4-byte expression and they forgot to sign
939 * extend. Un*x Sux. */
940 #define BSD_FILL_SIZE_CROCK_4 (4)
941 md_number_to_chars (p, temp_fill,
942 (temp_size > BSD_FILL_SIZE_CROCK_4
943 ? BSD_FILL_SIZE_CROCK_4
944 : (int) temp_size));
945 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
946 * but emits no error message because it seems a legal thing to do.
947 * It is a degenerate case of .fill but could be emitted by a compiler.
948 */
949 }
950 demand_empty_rest_of_line ();
951 }
952
953 void
954 s_globl ()
955 {
956 register char *name;
957 register int c;
958 register symbolS *symbolP;
959
960 do
961 {
962 name = input_line_pointer;
963 c = get_symbol_end ();
964 symbolP = symbol_find_or_make (name);
965 *input_line_pointer = c;
966 SKIP_WHITESPACE ();
967 S_SET_EXTERNAL (symbolP);
968 if (c == ',')
969 {
970 input_line_pointer++;
971 SKIP_WHITESPACE ();
972 if (*input_line_pointer == '\n')
973 c = '\n';
974 }
975 }
976 while (c == ',');
977 demand_empty_rest_of_line ();
978 } /* s_globl() */
979
980 void
981 s_lcomm (needs_align)
982 /* 1 if this was a ".bss" directive, which may require a 3rd argument
983 (alignment); 0 if it was an ".lcomm" (2 args only) */
984 int needs_align;
985 {
986 register char *name;
987 register char c;
988 register char *p;
989 register int temp;
990 register symbolS *symbolP;
991 segT current_seg = now_seg;
992 subsegT current_subseg = now_subseg;
993 const int max_alignment = 15;
994 int align = 0;
995 segT bss_seg = bss_section;
996
997 name = input_line_pointer;
998 c = get_symbol_end ();
999 p = input_line_pointer;
1000 *p = c;
1001 SKIP_WHITESPACE ();
1002 if (*input_line_pointer != ',')
1003 {
1004 as_bad ("Expected comma after name");
1005 ignore_rest_of_line ();
1006 return;
1007 }
1008
1009 ++input_line_pointer;
1010
1011 if (*input_line_pointer == '\n')
1012 {
1013 as_bad ("Missing size expression");
1014 return;
1015 }
1016
1017 if ((temp = get_absolute_expression ()) < 0)
1018 {
1019 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1020 ignore_rest_of_line ();
1021 return;
1022 }
1023
1024 #ifdef TC_MIPS
1025 #ifdef OBJ_ECOFF
1026 /* For MIPS ECOFF, small objects are put in .sbss. */
1027 if (temp <= bfd_get_gp_size (stdoutput))
1028 bss_seg = subseg_new (".sbss", 1);
1029 #endif
1030 #endif
1031
1032 if (needs_align)
1033 {
1034 align = 0;
1035 SKIP_WHITESPACE ();
1036 if (*input_line_pointer != ',')
1037 {
1038 as_bad ("Expected comma after size");
1039 ignore_rest_of_line ();
1040 return;
1041 }
1042 input_line_pointer++;
1043 SKIP_WHITESPACE ();
1044 if (*input_line_pointer == '\n')
1045 {
1046 as_bad ("Missing alignment");
1047 return;
1048 }
1049 align = get_absolute_expression ();
1050 if (align > max_alignment)
1051 {
1052 align = max_alignment;
1053 as_warn ("Alignment too large: %d. assumed.", align);
1054 }
1055 else if (align < 0)
1056 {
1057 align = 0;
1058 as_warn ("Alignment negative. 0 assumed.");
1059 }
1060 record_alignment (bss_seg, align);
1061 } /* if needs align */
1062
1063 *p = 0;
1064 symbolP = symbol_find_or_make (name);
1065 *p = c;
1066
1067 if (
1068 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1069 S_GET_OTHER (symbolP) == 0 &&
1070 S_GET_DESC (symbolP) == 0 &&
1071 #endif /* OBJ_AOUT or OBJ_BOUT */
1072 (S_GET_SEGMENT (symbolP) == bss_seg
1073 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1074 {
1075 char *p;
1076
1077 #ifdef BFD_ASSEMBLER
1078 subseg_set (bss_seg, 1);
1079 #else
1080 subseg_new (bss_seg, 1);
1081 #endif
1082
1083 if (align)
1084 frag_align (align, 0);
1085 /* detach from old frag */
1086 if (S_GET_SEGMENT (symbolP) == bss_seg)
1087 symbolP->sy_frag->fr_symbol = NULL;
1088
1089 symbolP->sy_frag = frag_now;
1090 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1091 temp, (char *)0);
1092 *p = 0;
1093
1094 S_SET_SEGMENT (symbolP, bss_seg);
1095
1096 #ifdef OBJ_COFF
1097 /* The symbol may already have been created with a preceding
1098 ".globl" directive -- be careful not to step on storage class
1099 in that case. Otherwise, set it to static. */
1100 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1101 {
1102 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1103 }
1104 #endif /* OBJ_COFF */
1105 }
1106 else
1107 {
1108 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1109 }
1110
1111 #ifdef BFD_ASSEMBLER
1112 subseg_set (current_seg, current_subseg);
1113 #else
1114 subseg_new (current_seg, current_subseg);
1115 #endif
1116
1117 demand_empty_rest_of_line ();
1118 } /* s_lcomm() */
1119
1120 void
1121 s_long ()
1122 {
1123 cons (4);
1124 }
1125
1126 void
1127 s_int ()
1128 {
1129 cons (4);
1130 }
1131
1132 void
1133 s_lsym ()
1134 {
1135 register char *name;
1136 register char c;
1137 register char *p;
1138 register segT segment;
1139 expressionS exp;
1140 register symbolS *symbolP;
1141
1142 /* we permit ANY defined expression: BSD4.2 demands constants */
1143 name = input_line_pointer;
1144 c = get_symbol_end ();
1145 p = input_line_pointer;
1146 *p = c;
1147 SKIP_WHITESPACE ();
1148 if (*input_line_pointer != ',')
1149 {
1150 *p = 0;
1151 as_bad ("Expected comma after name \"%s\"", name);
1152 *p = c;
1153 ignore_rest_of_line ();
1154 return;
1155 }
1156 input_line_pointer++;
1157 segment = expression (&exp);
1158 if (segment != absolute_section
1159 && segment != reg_section
1160 && ! SEG_NORMAL (segment))
1161 {
1162 as_bad ("Bad expression: %s", segment_name (segment));
1163 ignore_rest_of_line ();
1164 return;
1165 }
1166 *p = 0;
1167 symbolP = symbol_find_or_make (name);
1168
1169 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1170 symbolP->sy_desc == 0) out of this test because coff doesn't have
1171 those fields, and I can't see when they'd ever be tripped. I
1172 don't think I understand why they were here so I may have
1173 introduced a bug. As recently as 1.37 didn't have this test
1174 anyway. xoxorich. */
1175
1176 if (S_GET_SEGMENT (symbolP) == undefined_section
1177 && S_GET_VALUE (symbolP) == 0)
1178 {
1179 /* The name might be an undefined .global symbol; be sure to
1180 keep the "external" bit. */
1181 S_SET_SEGMENT (symbolP, segment);
1182 S_SET_VALUE (symbolP, (valueT) (exp.X_add_number));
1183 }
1184 else
1185 {
1186 as_bad ("Symbol %s already defined", name);
1187 }
1188 *p = c;
1189 demand_empty_rest_of_line ();
1190 } /* s_lsym() */
1191
1192 void
1193 s_org ()
1194 {
1195 register segT segment;
1196 expressionS exp;
1197 register long temp_fill;
1198 register char *p;
1199 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1200 thing as a sub-segment-relative origin. Any absolute origin is
1201 given a warning, then assumed to be segment-relative. Any
1202 segmented origin expression ("foo+42") had better be in the right
1203 segment or the .org is ignored.
1204
1205 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1206 we never know sub-segment sizes when we are reading code. BSD
1207 will crash trying to emit negative numbers of filler bytes in
1208 certain .orgs. We don't crash, but see as-write for that code.
1209
1210 Don't make frag if need_pass_2==1. */
1211 segment = get_known_segmented_expression (&exp);
1212 if (*input_line_pointer == ',')
1213 {
1214 input_line_pointer++;
1215 temp_fill = get_absolute_expression ();
1216 }
1217 else
1218 temp_fill = 0;
1219 if (!need_pass_2)
1220 {
1221 if (segment != now_seg && segment != absolute_section)
1222 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1223 segment_name (segment), segment_name (now_seg));
1224 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1225 exp.X_add_number, (char *) 0);
1226 *p = temp_fill;
1227 } /* if (ok to make frag) */
1228 demand_empty_rest_of_line ();
1229 } /* s_org() */
1230
1231 void
1232 s_set ()
1233 {
1234 register char *name;
1235 register char delim;
1236 register char *end_name;
1237 register symbolS *symbolP;
1238
1239 /*
1240 * Especial apologies for the random logic:
1241 * this just grew, and could be parsed much more simply!
1242 * Dean in haste.
1243 */
1244 name = input_line_pointer;
1245 delim = get_symbol_end ();
1246 end_name = input_line_pointer;
1247 *end_name = delim;
1248 SKIP_WHITESPACE ();
1249
1250 if (*input_line_pointer != ',')
1251 {
1252 *end_name = 0;
1253 as_bad ("Expected comma after name \"%s\"", name);
1254 *end_name = delim;
1255 ignore_rest_of_line ();
1256 return;
1257 }
1258
1259 input_line_pointer++;
1260 *end_name = 0;
1261
1262 if (name[0] == '.' && name[1] == '\0')
1263 {
1264 /* Turn '. = mumble' into a .org mumble */
1265 register segT segment;
1266 expressionS exp;
1267 register char *ptr;
1268
1269 segment = get_known_segmented_expression (&exp);
1270
1271 if (!need_pass_2)
1272 {
1273 if (segment != now_seg && segment != absolute_section)
1274 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1275 segment_name (segment),
1276 segment_name (now_seg));
1277 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1278 exp.X_add_number, (char *) 0);
1279 *ptr = 0;
1280 } /* if (ok to make frag) */
1281
1282 *end_name = delim;
1283 return;
1284 }
1285
1286 if ((symbolP = symbol_find (name)) == NULL
1287 && (symbolP = md_undefined_symbol (name)) == NULL)
1288 {
1289 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1290 #ifdef OBJ_COFF
1291 /* "set" symbols are local unless otherwise specified. */
1292 SF_SET_LOCAL (symbolP);
1293 #endif /* OBJ_COFF */
1294
1295 } /* make a new symbol */
1296
1297 symbol_table_insert (symbolP);
1298
1299 *end_name = delim;
1300 pseudo_set (symbolP);
1301 demand_empty_rest_of_line ();
1302 } /* s_set() */
1303
1304 void
1305 s_space (mult)
1306 int mult;
1307 {
1308 long temp_repeat;
1309 register long temp_fill;
1310 register char *p;
1311
1312 /* Just like .fill, but temp_size = 1 */
1313 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1314 {
1315 temp_fill = get_absolute_expression ();
1316 }
1317 else
1318 {
1319 input_line_pointer--; /* Backup over what was not a ','. */
1320 temp_fill = 0;
1321 }
1322 if (mult)
1323 {
1324 temp_repeat *= mult;
1325 }
1326 if (temp_repeat <= 0)
1327 {
1328 as_warn ("Repeat < 0, .space ignored");
1329 ignore_rest_of_line ();
1330 return;
1331 }
1332 if (!need_pass_2)
1333 {
1334 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1335 temp_repeat, (char *) 0);
1336 *p = temp_fill;
1337 }
1338 demand_empty_rest_of_line ();
1339 } /* s_space() */
1340
1341 void
1342 s_text ()
1343 {
1344 register int temp;
1345
1346 temp = get_absolute_expression ();
1347 #ifdef BFD_ASSEMBLER
1348 subseg_set (text_section, (subsegT) temp);
1349 #else
1350 subseg_new (text_section, (subsegT) temp);
1351 #endif
1352 demand_empty_rest_of_line ();
1353 } /* s_text() */
1354 \f
1355
1356 void
1357 demand_empty_rest_of_line ()
1358 {
1359 SKIP_WHITESPACE ();
1360 if (is_end_of_line[*input_line_pointer])
1361 {
1362 input_line_pointer++;
1363 }
1364 else
1365 {
1366 ignore_rest_of_line ();
1367 }
1368 /* Return having already swallowed end-of-line. */
1369 } /* Return pointing just after end-of-line. */
1370
1371 void
1372 ignore_rest_of_line () /* For suspect lines: gives warning. */
1373 {
1374 if (!is_end_of_line[*input_line_pointer])
1375 {
1376 if (isprint (*input_line_pointer))
1377 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1378 *input_line_pointer);
1379 else
1380 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1381 *input_line_pointer);
1382 while (input_line_pointer < buffer_limit
1383 && !is_end_of_line[*input_line_pointer])
1384 {
1385 input_line_pointer++;
1386 }
1387 }
1388 input_line_pointer++; /* Return pointing just after end-of-line. */
1389 know (is_end_of_line[input_line_pointer[-1]]);
1390 }
1391
1392 /*
1393 * pseudo_set()
1394 *
1395 * In: Pointer to a symbol.
1396 * Input_line_pointer->expression.
1397 *
1398 * Out: Input_line_pointer->just after any whitespace after expression.
1399 * Tried to set symbol to value of expression.
1400 * Will change symbols type, value, and frag;
1401 * May set need_pass_2 == 1.
1402 */
1403 void
1404 pseudo_set (symbolP)
1405 symbolS *symbolP;
1406 {
1407 expressionS exp;
1408 register segT segment;
1409 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1410 int ext;
1411 #endif /* OBJ_AOUT or OBJ_BOUT */
1412
1413 know (symbolP); /* NULL pointer is logic error. */
1414 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1415 /* @@ Fix this right for BFD. */
1416 ext = S_IS_EXTERNAL (symbolP);
1417 #endif /* OBJ_AOUT or OBJ_BOUT */
1418
1419 if ((segment = expression (&exp)) == absent_section)
1420 {
1421 as_bad ("Missing expression: absolute 0 assumed");
1422 exp.X_seg = absolute_section;
1423 exp.X_add_number = 0;
1424 }
1425
1426 if (segment == reg_section)
1427 {
1428 S_SET_SEGMENT (symbolP, reg_section);
1429 S_SET_VALUE (symbolP, exp.X_add_number);
1430 symbolP->sy_frag = &zero_address_frag;
1431 }
1432 else if (segment == big_section)
1433 {
1434 as_bad ("%s number invalid. Absolute 0 assumed.",
1435 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1436 S_SET_SEGMENT (symbolP, absolute_section);
1437 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1438 /* @@ Fix this right for BFD. */
1439 ext ? S_SET_EXTERNAL (symbolP) :
1440 S_CLEAR_EXTERNAL (symbolP);
1441 #endif /* OBJ_AOUT or OBJ_BOUT */
1442 S_SET_VALUE (symbolP, 0);
1443 symbolP->sy_frag = &zero_address_frag;
1444 }
1445 else if (segment == absent_section)
1446 {
1447 as_warn ("No expression: Using absolute 0");
1448 S_SET_SEGMENT (symbolP, absolute_section);
1449 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1450 /* @@ Fix this right for BFD. */
1451 ext ? S_SET_EXTERNAL (symbolP) :
1452 S_CLEAR_EXTERNAL (symbolP);
1453 #endif /* OBJ_AOUT or OBJ_BOUT */
1454 S_SET_VALUE (symbolP, 0);
1455 symbolP->sy_frag = &zero_address_frag;
1456 }
1457 else if (segment == diff_section)
1458 {
1459 if (exp.X_add_symbol && exp.X_subtract_symbol
1460 && (S_GET_SEGMENT (exp.X_add_symbol) ==
1461 S_GET_SEGMENT (exp.X_subtract_symbol)))
1462 {
1463 if (exp.X_add_symbol->sy_frag == exp.X_subtract_symbol->sy_frag)
1464 {
1465 exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
1466 S_GET_VALUE (exp.X_subtract_symbol);
1467 goto abs;
1468 }
1469 as_bad ("Invalid expression: separation between symbols `%s'",
1470 S_GET_NAME (exp.X_add_symbol));
1471 as_bad (" and `%s' may not be constant",
1472 S_GET_NAME (exp.X_subtract_symbol));
1473 need_pass_2++;
1474 }
1475 else
1476 {
1477 as_bad ("Complex expression. Absolute segment assumed.");
1478 goto abs;
1479 }
1480 }
1481 else if (segment == absolute_section)
1482 {
1483 abs:
1484 S_SET_SEGMENT (symbolP, absolute_section);
1485 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1486 /* @@ Fix this right for BFD. */
1487 ext ? S_SET_EXTERNAL (symbolP) :
1488 S_CLEAR_EXTERNAL (symbolP);
1489 #endif /* OBJ_AOUT or OBJ_BOUT */
1490 S_SET_VALUE (symbolP, exp.X_add_number);
1491 symbolP->sy_frag = &zero_address_frag;
1492 }
1493 else if (segment == pass1_section)
1494 {
1495 symbolP->sy_forward = exp.X_add_symbol;
1496 as_bad ("Unknown expression");
1497 know (need_pass_2 == 1);
1498 }
1499 else if (segment == undefined_section)
1500 {
1501 symbolP->sy_forward = exp.X_add_symbol;
1502 }
1503 else
1504 {
1505 #ifndef BFD_ASSEMBLER
1506 #ifndef MANY_SEGMENTS
1507 switch (segment)
1508 {
1509 case SEG_DATA:
1510 case SEG_TEXT:
1511 case SEG_BSS:
1512 break;
1513
1514 default:
1515 as_fatal ("failed sanity check.");
1516 } /* switch on segment */
1517 #endif
1518 #endif
1519 S_SET_SEGMENT (symbolP, segment);
1520 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1521 /* @@ Fix this right for BFD! */
1522 if (ext)
1523 {
1524 S_SET_EXTERNAL (symbolP);
1525 }
1526 else
1527 {
1528 S_CLEAR_EXTERNAL (symbolP);
1529 } /* if external */
1530 #endif /* OBJ_AOUT or OBJ_BOUT */
1531
1532 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1533 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1534 }
1535 }
1536 \f
1537 /*
1538 * cons()
1539 *
1540 * CONStruct more frag of .bytes, or .words etc.
1541 * Should need_pass_2 be 1 then emit no frag(s).
1542 * This understands EXPRESSIONS, as opposed to big_cons().
1543 *
1544 * Bug (?)
1545 *
1546 * This has a split personality. We use expression() to read the
1547 * value. We can detect if the value won't fit in a byte or word.
1548 * But we can't detect if expression() discarded significant digits
1549 * in the case of a long. Not worth the crocks required to fix it.
1550 */
1551
1552 /* worker to do .byte etc statements */
1553 /* clobbers input_line_pointer, checks */
1554 /* end-of-line. */
1555 void
1556 cons (nbytes)
1557 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1558 {
1559 register char c;
1560 register long mask; /* High-order bits we will left-truncate, */
1561 /* but includes sign bit also. */
1562 register long get; /* what we get */
1563 register long use; /* get after truncation. */
1564 register long unmask; /* what bits we will store */
1565 register char *p;
1566 register segT segment;
1567 expressionS exp;
1568
1569 /*
1570 * Input_line_pointer->1st char after pseudo-op-code and could legally
1571 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1572 */
1573 /* JF << of >= number of bits in the object is undefined. In particular
1574 SPARC (Sun 4) has problems */
1575
1576 if (nbytes >= sizeof (long))
1577 {
1578 mask = 0;
1579 }
1580 else
1581 {
1582 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1583 } /* bigger than a long */
1584
1585 unmask = ~mask; /* Do store these bits. */
1586
1587 #ifdef NEVER
1588 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1589 mask = ~(unmask >> 1); /* Includes sign bit now. */
1590 #endif
1591
1592 /*
1593 * The following awkward logic is to parse ZERO or more expressions,
1594 * comma seperated. Recall an expression includes its leading &
1595 * trailing blanks. We fake a leading ',' if there is (supposed to
1596 * be) a 1st expression, and keep demanding 1 expression for each ','.
1597 */
1598 if (is_it_end_of_statement ())
1599 {
1600 c = 0; /* Skip loop. */
1601 input_line_pointer++; /* Matches end-of-loop 'correction'. */
1602 }
1603 else
1604 {
1605 c = ',';
1606 } /* if the end else fake it */
1607
1608 /* Do loop. */
1609 while (c == ',')
1610 {
1611 #ifdef WANT_BITFIELDS
1612 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1613 /* used for error messages and rescanning */
1614 char *hold = input_line_pointer;
1615 #endif /* WANT_BITFIELDS */
1616 #ifdef MRI
1617 if (*input_line_pointer == '\'')
1618 {
1619 /* An MRI style string, cut into as many bytes as will fit
1620 into a nbyte chunk, left justify if necessary, and sepatate
1621 with commas so we can try again later */
1622 int scan = 0;
1623 unsigned int result = 0;
1624 input_line_pointer++;
1625 for (scan = 0; scan < nbytes; scan++)
1626 {
1627 if (*input_line_pointer == '\'')
1628 {
1629 if (input_line_pointer[1] == '\'')
1630 {
1631 input_line_pointer++;
1632 }
1633 else
1634 break;
1635 }
1636 result = (result << 8) | (*input_line_pointer++);
1637 }
1638
1639 /* Left justify */
1640 while (scan < nbytes)
1641 {
1642 result <<= 8;
1643 scan++;
1644 }
1645 /* Create correct expression */
1646 exp.X_add_symbol = 0;
1647 exp.X_add_number = result;
1648 exp.X_seg = segment = absolute_section;
1649 /* Fake it so that we can read the next char too */
1650 if (input_line_pointer[0] != '\'' ||
1651 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1652 {
1653 input_line_pointer -= 2;
1654 input_line_pointer[0] = ',';
1655 input_line_pointer[1] = '\'';
1656 }
1657 else
1658 input_line_pointer++;
1659
1660 }
1661 else
1662 #endif
1663 /* At least scan over the expression. */
1664 segment = expression (&exp);
1665
1666 #ifdef WANT_BITFIELDS
1667 /* Some other assemblers, (eg, asm960), allow
1668 bitfields after ".byte" as w:x,y:z, where w and
1669 y are bitwidths and x and y are values. They
1670 then pack them all together. We do a little
1671 better in that we allow them in words, longs,
1672 etc. and we'll pack them in target byte order
1673 for you.
1674
1675 The rules are: pack least significat bit first,
1676 if a field doesn't entirely fit, put it in the
1677 next unit. Overflowing the bitfield is
1678 explicitly *not* even a warning. The bitwidth
1679 should be considered a "mask".
1680
1681 FIXME-SOMEDAY: If this is considered generally
1682 useful, this logic should probably be reworked.
1683 xoxorich. */
1684
1685 if (*input_line_pointer == ':')
1686 { /* bitfields */
1687 long value = 0;
1688
1689 for (;;)
1690 {
1691 unsigned long width;
1692
1693 if (*input_line_pointer != ':')
1694 {
1695 input_line_pointer = hold;
1696 break;
1697 } /* next piece is not a bitfield */
1698
1699 /* In the general case, we can't allow
1700 full expressions with symbol
1701 differences and such. The relocation
1702 entries for symbols not defined in this
1703 assembly would require arbitrary field
1704 widths, positions, and masks which most
1705 of our current object formats don't
1706 support.
1707
1708 In the specific case where a symbol
1709 *is* defined in this assembly, we
1710 *could* build fixups and track it, but
1711 this could lead to confusion for the
1712 backends. I'm lazy. I'll take any
1713 SEG_ABSOLUTE. I think that means that
1714 you can use a previous .set or
1715 .equ type symbol. xoxorich. */
1716
1717 if (segment == absent_section)
1718 {
1719 as_warn ("Using a bit field width of zero.");
1720 exp.X_add_number = 0;
1721 segment = absolute_section;
1722 } /* implied zero width bitfield */
1723
1724 if (segment != absolute_section)
1725 {
1726 *input_line_pointer = '\0';
1727 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
1728 *input_line_pointer = ':';
1729 demand_empty_rest_of_line ();
1730 return;
1731 } /* too complex */
1732
1733 if ((width = exp.X_add_number) > (BITS_PER_CHAR * nbytes))
1734 {
1735 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1736 width, nbytes, (BITS_PER_CHAR * nbytes));
1737 width = BITS_PER_CHAR * nbytes;
1738 } /* too big */
1739
1740 if (width > bits_available)
1741 {
1742 /* FIXME-SOMEDAY: backing up and
1743 reparsing is wasteful */
1744 input_line_pointer = hold;
1745 exp.X_add_number = value;
1746 break;
1747 } /* won't fit */
1748
1749 hold = ++input_line_pointer; /* skip ':' */
1750
1751 if ((segment = expression (&exp)) != absolute_section)
1752 {
1753 char cache = *input_line_pointer;
1754
1755 *input_line_pointer = '\0';
1756 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
1757 *input_line_pointer = cache;
1758 demand_empty_rest_of_line ();
1759 return;
1760 } /* too complex */
1761
1762 value |= (~(-1 << width) & exp.X_add_number)
1763 << ((BITS_PER_CHAR * nbytes) - bits_available);
1764
1765 if ((bits_available -= width) == 0
1766 || is_it_end_of_statement ()
1767 || *input_line_pointer != ',')
1768 {
1769 break;
1770 } /* all the bitfields we're gonna get */
1771
1772 hold = ++input_line_pointer;
1773 segment = expression (&exp);
1774 } /* forever loop */
1775
1776 exp.X_add_number = value;
1777 segment = absolute_section;
1778 } /* if looks like a bitfield */
1779 #endif /* WANT_BITFIELDS */
1780
1781 if (!need_pass_2)
1782 { /* Still worthwhile making frags. */
1783
1784 /* Don't call this if we are going to junk this pass anyway! */
1785 know (segment != pass1_section);
1786
1787 if (segment == diff_section && exp.X_add_symbol == NULL)
1788 {
1789 as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1790 S_GET_NAME (exp.X_subtract_symbol),
1791 segment_name (S_GET_SEGMENT (exp.X_subtract_symbol)));
1792 segment = absolute_section;
1793 /* Leave exp . X_add_number alone. */
1794 }
1795 p = frag_more (nbytes);
1796 if (segment == big_section)
1797 {
1798 as_bad ("%s number invalid. Absolute 0 assumed.",
1799 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1800 md_number_to_chars (p, (long) 0, nbytes);
1801 }
1802 else if (segment == absent_section)
1803 {
1804 as_warn ("0 assumed for missing expression");
1805 exp.X_add_number = 0;
1806 know (exp.X_add_symbol == NULL);
1807 goto abs_sec;
1808 }
1809 else if (segment == absolute_section)
1810 {
1811 abs_sec:
1812 get = exp.X_add_number;
1813 use = get & unmask;
1814 if ((get & mask) && (get & mask) != mask)
1815 { /* Leading bits contain both 0s & 1s. */
1816 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
1817 }
1818 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1819 }
1820 else if (segment == diff_section)
1821 {
1822 #ifndef WORKING_DOT_WORD
1823 if (nbytes == 2)
1824 {
1825 struct broken_word *x;
1826
1827 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1828 x->next_broken_word = broken_words;
1829 broken_words = x;
1830 x->frag = frag_now;
1831 x->word_goes_here = p;
1832 x->dispfrag = 0;
1833 x->add = exp.X_add_symbol;
1834 x->sub = exp.X_subtract_symbol;
1835 x->addnum = exp.X_add_number;
1836 x->added = 0;
1837 new_broken_words++;
1838 goto after_switch;
1839 }
1840 #endif
1841 goto defalt;
1842 }
1843 else
1844 /* undefined_section, others */
1845 {
1846 defalt:
1847 md_number_to_chars (p, (long) 0, nbytes);
1848 #ifdef BFD_ASSEMBLER
1849 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1850 exp.X_add_symbol, exp.X_subtract_symbol,
1851 exp.X_add_number, 0,
1852 /* @@ Should look at CPU word size. */
1853 BFD_RELOC_32);
1854 #else
1855 #ifdef TC_NS32K
1856 fix_new_ns32k (frag_now, p - frag_now->fr_literal, nbytes,
1857 exp.X_add_symbol, exp.X_subtract_symbol,
1858 exp.X_add_number, 0, 0, 2, 0, 0);
1859 #else
1860 #if defined(TC_SPARC) || defined(TC_A29K)
1861 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1862 exp.X_add_symbol, exp.X_subtract_symbol,
1863 exp.X_add_number, 0, RELOC_32);
1864 #else
1865 #if defined(TC_H8300)
1866 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1867 exp.X_add_symbol, exp.X_subtract_symbol,
1868 exp.X_add_number, 0, R_RELWORD);
1869
1870 #else
1871 #ifdef NO_RELOC
1872 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1873 exp.X_add_symbol, exp.X_subtract_symbol,
1874 exp.X_add_number, 0, NO_RELOC);
1875 #else
1876 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1877 exp.X_add_symbol, exp.X_subtract_symbol,
1878 exp.X_add_number, 0, 0);
1879 #endif /* NO_RELOC */
1880 #endif /* tc_h8300 */
1881 #endif /* tc_sparc|tc_a29k */
1882 #endif /* TC_NS32K */
1883 #endif /* BFD_ASSEMBLER */
1884 } /* switch(segment) */
1885 after_switch:
1886 ;
1887 } /* if (!need_pass_2) */
1888 c = *input_line_pointer++;
1889 } /* while(c==',') */
1890 input_line_pointer--; /* Put terminator back into stream. */
1891 demand_empty_rest_of_line ();
1892 } /* cons() */
1893 \f
1894 /*
1895 * big_cons()
1896 *
1897 * CONStruct more frag(s) of .quads, or .octa etc.
1898 * Makes 0 or more new frags.
1899 * If need_pass_2 == 1, generate no frag.
1900 * This understands only bignums, not expressions. Cons() understands
1901 * expressions.
1902 *
1903 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1904 *
1905 * This creates objects with struct obstack_control objs, destroying
1906 * any context objs held about a partially completed object. Beware!
1907 *
1908 *
1909 * I think it sucks to have 2 different types of integers, with 2
1910 * routines to read them, store them etc.
1911 * It would be nicer to permit bignums in expressions and only
1912 * complain if the result overflowed. However, due to "efficiency"...
1913 */
1914 /* worker to do .quad etc statements */
1915 /* clobbers input_line_pointer, checks */
1916 /* end-of-line. */
1917 /* 8=.quad 16=.octa ... */
1918
1919 void
1920 big_cons (nbytes)
1921 register int nbytes;
1922 {
1923 register char c; /* input_line_pointer->c. */
1924 register int radix;
1925 register long length; /* Number of chars in an object. */
1926 register int digit; /* Value of 1 digit. */
1927 register int carry; /* For multi-precision arithmetic. */
1928 register int work; /* For multi-precision arithmetic. */
1929 register char *p; /* For multi-precision arithmetic. */
1930
1931 extern const char hex_value[]; /* In hex_value.c. */
1932
1933 /*
1934 * The following awkward logic is to parse ZERO or more strings,
1935 * comma seperated. Recall an expression includes its leading &
1936 * trailing blanks. We fake a leading ',' if there is (supposed to
1937 * be) a 1st expression, and keep demanding 1 expression for each ','.
1938 */
1939 if (is_it_end_of_statement ())
1940 {
1941 c = 0; /* Skip loop. */
1942 }
1943 else
1944 {
1945 c = ','; /* Do loop. */
1946 --input_line_pointer;
1947 }
1948 while (c == ',')
1949 {
1950 ++input_line_pointer;
1951 SKIP_WHITESPACE ();
1952 c = *input_line_pointer;
1953 /* C contains 1st non-blank character of what we hope is a number. */
1954 if (c == '0')
1955 {
1956 c = *++input_line_pointer;
1957 if (c == 'x' || c == 'X')
1958 {
1959 c = *++input_line_pointer;
1960 radix = 16;
1961 }
1962 else
1963 {
1964 radix = 8;
1965 }
1966 }
1967 else
1968 {
1969 radix = 10;
1970 }
1971 /*
1972 * This feature (?) is here to stop people worrying about
1973 * mysterious zero constants: which is what they get when
1974 * they completely omit digits.
1975 */
1976 if (hex_value[c] >= radix)
1977 {
1978 as_bad ("Missing digits. 0 assumed.");
1979 }
1980 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
1981 for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
1982 {
1983 /* Multiply existing number by radix, then add digit. */
1984 carry = digit;
1985 for (p = bignum_low; p <= bignum_high; p++)
1986 {
1987 work = (*p & MASK_CHAR) * radix + carry;
1988 *p = work & MASK_CHAR;
1989 carry = work >> BITS_PER_CHAR;
1990 }
1991 if (carry)
1992 {
1993 grow_bignum ();
1994 *bignum_high = carry & MASK_CHAR;
1995 know ((carry & ~MASK_CHAR) == 0);
1996 }
1997 }
1998 length = bignum_high - bignum_low + 1;
1999 if (length > nbytes)
2000 {
2001 as_warn ("Most significant bits truncated in integer constant.");
2002 }
2003 else
2004 {
2005 register long leading_zeroes;
2006
2007 for (leading_zeroes = nbytes - length;
2008 leading_zeroes;
2009 leading_zeroes--)
2010 {
2011 grow_bignum ();
2012 *bignum_high = 0;
2013 }
2014 }
2015 if (!need_pass_2)
2016 {
2017 char *src = bignum_low;
2018 p = frag_more (nbytes);
2019 if (target_big_endian)
2020 {
2021 int i;
2022 for (i = nbytes - 1; i >= 0; i--)
2023 p[i] = *src++;
2024 }
2025 else
2026 bcopy (bignum_low, p, (int) nbytes);
2027 }
2028 /* C contains character after number. */
2029 SKIP_WHITESPACE ();
2030 c = *input_line_pointer;
2031 /* C contains 1st non-blank character after number. */
2032 }
2033 demand_empty_rest_of_line ();
2034 } /* big_cons() */
2035
2036 /* Extend bignum by 1 char. */
2037 static void
2038 grow_bignum ()
2039 {
2040 register long length;
2041
2042 bignum_high++;
2043 if (bignum_high >= bignum_limit)
2044 {
2045 length = bignum_limit - bignum_low;
2046 bignum_low = xrealloc (bignum_low, length + length);
2047 bignum_high = bignum_low + length;
2048 bignum_limit = bignum_low + length + length;
2049 }
2050 } /* grow_bignum(); */
2051 \f
2052 /*
2053 * float_cons()
2054 *
2055 * CONStruct some more frag chars of .floats .ffloats etc.
2056 * Makes 0 or more new frags.
2057 * If need_pass_2 == 1, no frags are emitted.
2058 * This understands only floating literals, not expressions. Sorry.
2059 *
2060 * A floating constant is defined by atof_generic(), except it is preceded
2061 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2062 * reading, I decided to be incompatible. This always tries to give you
2063 * rounded bits to the precision of the pseudo-op. Former AS did premature
2064 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2065 * a choice of 2 flavours of noise according to which of 2 floating-point
2066 * scanners you directed AS to use.
2067 *
2068 * In: input_line_pointer->whitespace before, or '0' of flonum.
2069 *
2070 */
2071
2072 void /* JF was static, but can't be if VAX.C is goning to use it */
2073 float_cons (float_type) /* Worker to do .float etc statements. */
2074 /* Clobbers input_line-pointer, checks end-of-line. */
2075 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2076 {
2077 register char *p;
2078 register char c;
2079 int length; /* Number of chars in an object. */
2080 register char *err; /* Error from scanning floating literal. */
2081 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2082
2083 /*
2084 * The following awkward logic is to parse ZERO or more strings,
2085 * comma seperated. Recall an expression includes its leading &
2086 * trailing blanks. We fake a leading ',' if there is (supposed to
2087 * be) a 1st expression, and keep demanding 1 expression for each ','.
2088 */
2089 if (is_it_end_of_statement ())
2090 {
2091 c = 0; /* Skip loop. */
2092 ++input_line_pointer; /*->past termintor. */
2093 }
2094 else
2095 {
2096 c = ','; /* Do loop. */
2097 }
2098 while (c == ',')
2099 {
2100 /* input_line_pointer->1st char of a flonum (we hope!). */
2101 SKIP_WHITESPACE ();
2102 /* Skip any 0{letter} that may be present. Don't even check if the
2103 * letter is legal. Someone may invent a "z" format and this routine
2104 * has no use for such information. Lusers beware: you get
2105 * diagnostics if your input is ill-conditioned.
2106 */
2107
2108 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2109 input_line_pointer += 2;
2110
2111 err = md_atof (float_type, temp, &length);
2112 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2113 know (length > 0);
2114 if (err && *err)
2115 {
2116 as_bad ("Bad floating literal: %s", err);
2117 ignore_rest_of_line ();
2118 /* Input_line_pointer->just after end-of-line. */
2119 c = 0; /* Break out of loop. */
2120 }
2121 else
2122 {
2123 if (!need_pass_2)
2124 {
2125 p = frag_more (length);
2126 bcopy (temp, p, length);
2127 }
2128 SKIP_WHITESPACE ();
2129 c = *input_line_pointer++;
2130 /* C contains 1st non-white character after number. */
2131 /* input_line_pointer->just after terminator (c). */
2132 }
2133 }
2134 --input_line_pointer; /*->terminator (is not ','). */
2135 demand_empty_rest_of_line ();
2136 } /* float_cons() */
2137 \f
2138 /*
2139 * stringer()
2140 *
2141 * We read 0 or more ',' seperated, double-quoted strings.
2142 *
2143 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2144 */
2145
2146
2147 void
2148 stringer (append_zero) /* Worker to do .ascii etc statements. */
2149 /* Checks end-of-line. */
2150 register int append_zero; /* 0: don't append '\0', else 1 */
2151 {
2152 register unsigned int c;
2153
2154 /*
2155 * The following awkward logic is to parse ZERO or more strings,
2156 * comma seperated. Recall a string expression includes spaces
2157 * before the opening '\"' and spaces after the closing '\"'.
2158 * We fake a leading ',' if there is (supposed to be)
2159 * a 1st, expression. We keep demanding expressions for each
2160 * ','.
2161 */
2162 if (is_it_end_of_statement ())
2163 {
2164 c = 0; /* Skip loop. */
2165 ++input_line_pointer; /* Compensate for end of loop. */
2166 }
2167 else
2168 {
2169 c = ','; /* Do loop. */
2170 }
2171 while (c == ',' || c == '<' || c == '"')
2172 {
2173 SKIP_WHITESPACE ();
2174 switch (*input_line_pointer)
2175 {
2176 case '\"':
2177 ++input_line_pointer; /*->1st char of string. */
2178 while (is_a_char (c = next_char_of_string ()))
2179 {
2180 FRAG_APPEND_1_CHAR (c);
2181 }
2182 if (append_zero)
2183 {
2184 FRAG_APPEND_1_CHAR (0);
2185 }
2186 know (input_line_pointer[-1] == '\"');
2187 break;
2188 case '<':
2189 input_line_pointer++;
2190 c = get_single_number ();
2191 FRAG_APPEND_1_CHAR (c);
2192 if (*input_line_pointer != '>')
2193 {
2194 as_bad ("Expected <nn>");
2195 }
2196 input_line_pointer++;
2197 break;
2198 case ',':
2199 input_line_pointer++;
2200 break;
2201 }
2202 SKIP_WHITESPACE ();
2203 c = *input_line_pointer;
2204 }
2205
2206 demand_empty_rest_of_line ();
2207 } /* stringer() */
2208 \f
2209 /* FIXME-SOMEDAY: I had trouble here on characters with the
2210 high bits set. We'll probably also have trouble with
2211 multibyte chars, wide chars, etc. Also be careful about
2212 returning values bigger than 1 byte. xoxorich. */
2213
2214 unsigned int
2215 next_char_of_string ()
2216 {
2217 register unsigned int c;
2218
2219 c = *input_line_pointer++ & CHAR_MASK;
2220 switch (c)
2221 {
2222 case '\"':
2223 c = NOT_A_CHAR;
2224 break;
2225
2226 case '\\':
2227 switch (c = *input_line_pointer++)
2228 {
2229 case 'b':
2230 c = '\b';
2231 break;
2232
2233 case 'f':
2234 c = '\f';
2235 break;
2236
2237 case 'n':
2238 c = '\n';
2239 break;
2240
2241 case 'r':
2242 c = '\r';
2243 break;
2244
2245 case 't':
2246 c = '\t';
2247 break;
2248
2249 #ifdef BACKSLASH_V
2250 case 'v':
2251 c = '\013';
2252 break;
2253 #endif
2254
2255 case '\\':
2256 case '"':
2257 break; /* As itself. */
2258
2259 case '0':
2260 case '1':
2261 case '2':
2262 case '3':
2263 case '4':
2264 case '5':
2265 case '6':
2266 case '7':
2267 case '8':
2268 case '9':
2269 {
2270 long number;
2271
2272 for (number = 0; isdigit (c); c = *input_line_pointer++)
2273 {
2274 number = number * 8 + c - '0';
2275 }
2276 c = number & 0xff;
2277 }
2278 --input_line_pointer;
2279 break;
2280
2281 case '\n':
2282 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2283 as_warn ("Unterminated string: Newline inserted.");
2284 c = '\n';
2285 break;
2286
2287 default:
2288
2289 #ifdef ONLY_STANDARD_ESCAPES
2290 as_bad ("Bad escaped character in string, '?' assumed");
2291 c = '?';
2292 #endif /* ONLY_STANDARD_ESCAPES */
2293
2294 break;
2295 } /* switch on escaped char */
2296 break;
2297
2298 default:
2299 break;
2300 } /* switch on char */
2301 return (c);
2302 } /* next_char_of_string() */
2303 \f
2304 static segT
2305 get_segmented_expression (expP)
2306 register expressionS *expP;
2307 {
2308 register segT retval;
2309
2310 retval = expression (expP);
2311 if (retval == pass1_section
2312 || retval == absent_section
2313 || retval == big_section)
2314 {
2315 as_bad ("Expected address expression: absolute 0 assumed");
2316 retval = expP->X_seg = absolute_section;
2317 expP->X_add_number = 0;
2318 expP->X_add_symbol = expP->X_subtract_symbol = 0;
2319 }
2320 return (retval); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2321 }
2322
2323 static segT
2324 get_known_segmented_expression (expP)
2325 register expressionS *expP;
2326 {
2327 register segT retval;
2328 register CONST char *name1;
2329 register CONST char *name2;
2330
2331 if ((retval = get_segmented_expression (expP)) == undefined_section)
2332 {
2333 name1 = expP->X_add_symbol ? S_GET_NAME (expP->X_add_symbol) : "";
2334 name2 = expP->X_subtract_symbol ?
2335 S_GET_NAME (expP->X_subtract_symbol) :
2336 "";
2337 if (name1 && name2)
2338 {
2339 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2340 name1, name2);
2341 }
2342 else
2343 {
2344 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2345 name1 ? name1 : name2);
2346 }
2347 retval = expP->X_seg = absolute_section;
2348 expP->X_add_number = 0;
2349 expP->X_add_symbol = expP->X_subtract_symbol = NULL;
2350 }
2351 know (retval == absolute_section
2352 || retval == diff_section
2353 || SEG_NORMAL (retval));
2354 return (retval);
2355
2356 } /* get_known_segmented_expression() */
2357
2358
2359
2360 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2361 get_absolute_expression ()
2362 {
2363 expressionS exp;
2364 register segT s;
2365
2366 if ((s = expression (&exp)) != absolute_section)
2367 {
2368 if (s != absent_section)
2369 {
2370 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2371 }
2372 exp.X_add_number = 0;
2373 }
2374 return (exp.X_add_number);
2375 }
2376
2377 char /* return terminator */
2378 get_absolute_expression_and_terminator (val_pointer)
2379 long *val_pointer; /* return value of expression */
2380 {
2381 *val_pointer = get_absolute_expression ();
2382 return (*input_line_pointer++);
2383 }
2384 \f
2385 /*
2386 * demand_copy_C_string()
2387 *
2388 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2389 * Give a warning if that happens.
2390 */
2391 char *
2392 demand_copy_C_string (len_pointer)
2393 int *len_pointer;
2394 {
2395 register char *s;
2396
2397 if ((s = demand_copy_string (len_pointer)) != 0)
2398 {
2399 register int len;
2400
2401 for (len = *len_pointer;
2402 len > 0;
2403 len--)
2404 {
2405 if (*s == 0)
2406 {
2407 s = 0;
2408 len = 1;
2409 *len_pointer = 0;
2410 as_bad ("This string may not contain \'\\0\'");
2411 }
2412 }
2413 }
2414 return (s);
2415 }
2416 \f
2417 /*
2418 * demand_copy_string()
2419 *
2420 * Demand string, but return a safe (=private) copy of the string.
2421 * Return NULL if we can't read a string here.
2422 */
2423 static char *
2424 demand_copy_string (lenP)
2425 int *lenP;
2426 {
2427 register unsigned int c;
2428 register int len;
2429 char *retval;
2430
2431 len = 0;
2432 SKIP_WHITESPACE ();
2433 if (*input_line_pointer == '\"')
2434 {
2435 input_line_pointer++; /* Skip opening quote. */
2436
2437 while (is_a_char (c = next_char_of_string ()))
2438 {
2439 obstack_1grow (&notes, c);
2440 len++;
2441 }
2442 /* JF this next line is so demand_copy_C_string will return a null
2443 termanated string. */
2444 obstack_1grow (&notes, '\0');
2445 retval = obstack_finish (&notes);
2446 }
2447 else
2448 {
2449 as_warn ("Missing string");
2450 retval = NULL;
2451 ignore_rest_of_line ();
2452 }
2453 *lenP = len;
2454 return (retval);
2455 } /* demand_copy_string() */
2456 \f
2457 /*
2458 * is_it_end_of_statement()
2459 *
2460 * In: Input_line_pointer->next character.
2461 *
2462 * Do: Skip input_line_pointer over all whitespace.
2463 *
2464 * Out: 1 if input_line_pointer->end-of-line.
2465 */
2466 int
2467 is_it_end_of_statement ()
2468 {
2469 SKIP_WHITESPACE ();
2470 return (is_end_of_line[*input_line_pointer]);
2471 } /* is_it_end_of_statement() */
2472
2473 void
2474 equals (sym_name)
2475 char *sym_name;
2476 {
2477 register symbolS *symbolP; /* symbol we are working with */
2478
2479 input_line_pointer++;
2480 if (*input_line_pointer == '=')
2481 input_line_pointer++;
2482
2483 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2484 input_line_pointer++;
2485
2486 if (sym_name[0] == '.' && sym_name[1] == '\0')
2487 {
2488 /* Turn '. = mumble' into a .org mumble */
2489 register segT segment;
2490 expressionS exp;
2491 register char *p;
2492
2493 segment = get_known_segmented_expression (&exp);
2494 if (!need_pass_2)
2495 {
2496 if (segment != now_seg && segment != absolute_section)
2497 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2498 segment_name (segment),
2499 segment_name (now_seg));
2500 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2501 exp.X_add_number, (char *) 0);
2502 *p = 0;
2503 } /* if (ok to make frag) */
2504 }
2505 else
2506 {
2507 symbolP = symbol_find_or_make (sym_name);
2508 pseudo_set (symbolP);
2509 }
2510 } /* equals() */
2511
2512 /* .include -- include a file at this point. */
2513
2514 /* ARGSUSED */
2515 void
2516 s_include (arg)
2517 int arg;
2518 {
2519 char *newbuf;
2520 char *filename;
2521 int i;
2522 FILE *try;
2523 char *path;
2524
2525 filename = demand_copy_string (&i);
2526 demand_empty_rest_of_line ();
2527 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2528 for (i = 0; i < include_dir_count; i++)
2529 {
2530 strcpy (path, include_dirs[i]);
2531 strcat (path, "/");
2532 strcat (path, filename);
2533 if (0 != (try = fopen (path, "r")))
2534 {
2535 fclose (try);
2536 goto gotit;
2537 }
2538 }
2539 free (path);
2540 path = filename;
2541 gotit:
2542 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2543 newbuf = input_scrub_include_file (path, input_line_pointer);
2544 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2545 } /* s_include() */
2546
2547 void
2548 add_include_dir (path)
2549 char *path;
2550 {
2551 int i;
2552
2553 if (include_dir_count == 0)
2554 {
2555 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2556 include_dirs[0] = "."; /* Current dir */
2557 include_dir_count = 2;
2558 }
2559 else
2560 {
2561 include_dir_count++;
2562 include_dirs = (char **) realloc (include_dirs,
2563 include_dir_count * sizeof (*include_dirs));
2564 }
2565
2566 include_dirs[include_dir_count - 1] = path; /* New one */
2567
2568 i = strlen (path);
2569 if (i > include_dir_maxlen)
2570 include_dir_maxlen = i;
2571 } /* add_include_dir() */
2572
2573 void
2574 s_ignore (arg)
2575 int arg;
2576 {
2577 while (!is_end_of_line[*input_line_pointer])
2578 {
2579 ++input_line_pointer;
2580 }
2581 ++input_line_pointer;
2582
2583 return;
2584 } /* s_ignore() */
2585
2586 /* end of read.c */
This page took 0.100041 seconds and 4 git commands to generate.