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