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