1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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)
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.
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. */
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.)
27 #define MASK_CHAR ((int)(unsigned char)-1)
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
60 #define NOP_OPCODE 0x00
63 char *input_line_pointer; /*->next char of source file to parse. */
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!)! */
72 /* The m88k unfortunately uses @ as a label beginner. */
76 /* used by is_... macros. our ctype[] */
77 const char lex_type[256] =
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,
99 * Out: 1 if this character ends a line.
102 char is_end_of_line[256] =
105 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
107 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
109 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
111 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
112 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
115 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
117 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
118 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
119 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
129 /* Functions private to this file. */
131 static char *buffer; /* 1st char of each buffer of lines is here. */
132 static char *buffer_limit; /*->1 + last char in buffer. */
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. */
140 int target_big_endian;
142 static char *old_buffer; /* JF a hack */
143 static char *old_input;
144 static char *old_limit;
146 /* Variables for handling include file directory list. */
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 */
153 #ifndef WORKING_DOT_WORD
154 struct broken_word *broken_words;
155 int new_broken_words;
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));
175 obj_read_begin_hook ();
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 (¬es, 5090);
180 obstack_begin (&cond_obstack, 990);
182 #define BIGNUM_BEGIN_SIZE (16)
183 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
184 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
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. */
192 /* set up pseudo-op tables */
194 struct hash_control *po_hash;
196 static const pseudo_typeS potable[] =
198 {"abort", s_abort, 0},
199 {"align", s_align_ptwo, 0},
200 {"ascii", stringer, 0},
201 {"asciz", stringer, 1},
207 {"double", float_cons, 'd'},
209 {"eject", listing_eject, 0}, /* Formfeed listing */
212 {"endif", s_endif, 0},
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},
222 {"float", float_cons, 'f'},
223 {"global", s_globl, 0},
224 {"globl", s_globl, 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},
234 {"lcomm", s_lcomm, 0},
235 {"lflags", listing_flags, 0}, /* Listing flags */
236 {"list", listing_list, 1}, /* Turn listing on */
239 {"nolist", listing_list, 0}, /* Turn listing off */
240 {"octa", big_cons, 16},
242 {"psize", listing_psize, 0}, /* set paper size */
244 {"quad", big_cons, 8},
245 {"sbttl", listing_title, 1}, /* Subtitle of listing */
250 {"single", float_cons, 'f'},
252 {"space", s_space, 0},
255 {"title", listing_title, 0}, /* Listing title */
260 {NULL} /* end sentinel */
266 char *errtxt; /* error text */
267 const pseudo_typeS *pop;
269 po_hash = hash_new ();
271 /* Do the target-specific pseudo ops. */
272 for (pop = md_pseudo_table; pop->poc_name; pop++)
274 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
275 if (errtxt && *errtxt)
277 as_fatal ("error constructing md pseudo-op table");
281 /* Now object specific. Skip any that were in the target table. */
282 for (pop = obj_pseudo_table; pop->poc_name; pop++)
284 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
285 if (errtxt && *errtxt)
287 if (!strcmp (errtxt, "exists"))
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. */
296 as_fatal ("error constructing obj pseudo-op table");
297 } /* if overridden */
301 /* Now portable ones. Skip any that we've seen already. */
302 for (pop = potable; pop->poc_name; pop++)
304 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
305 if (errtxt && *errtxt)
307 if (!strcmp (errtxt, "exists"))
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. */
316 as_fatal ("error constructing obj pseudo-op table");
317 } /* if overridden */
324 #define HANDLE_CONDITIONAL_ASSEMBLY() \
325 if (ignore_input ()) \
327 while (! is_end_of_line[*input_line_pointer++]) \
328 if (input_line_pointer == buffer_limit) \
334 /* read_a_source_file()
336 * We read the file, putting things into a web that
337 * represents what we have been reading.
340 read_a_source_file (name)
344 register char *s; /* string of symbol, '\0' appended */
348 buffer = input_scrub_new_file (name);
351 listing_newline ("");
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)
361 /* We have more of this buffer to parse. */
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.
368 if (input_line_pointer[-1] == '\n')
370 bump_line_counters ();
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))
376 char *line_start = input_line_pointer;
377 char c = get_symbol_end ();
379 *input_line_pointer = c;
381 input_line_pointer++;
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.
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!)
402 if ((c = *input_line_pointer++) == '\t'
407 c = *input_line_pointer++;
409 know (c != ' '); /* No further leading whitespace. */
412 * C is the 1st significant character.
413 * Input_line_pointer points after that character.
415 if (is_name_beginner (c))
416 { /* want user-defined label or pseudo/opcode */
417 HANDLE_CONDITIONAL_ASSEMBLY ();
419 s = --input_line_pointer;
420 c = get_symbol_end (); /* name's delimiter */
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.
428 if (TC_START_LABEL(c, input_line_pointer))
430 colon (s); /* user-defined label */
431 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
432 /* Input_line_pointer->after ':'. */
437 else if (c == '=' || input_line_pointer[1] == '=')
440 demand_empty_rest_of_line ();
443 { /* expect pseudo-op or machine instruction */
445 if (!done_pseudo (s))
453 * WARNING: c has next char, which may be end-of-line.
454 * We lookup the pseudo-op table with s+1 because we
455 * already know that the pseudo-op begins with a '.'.
458 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
460 /* Print the error msg now, while we still can */
463 as_bad ("Unknown pseudo-op: `%s'", s);
464 *input_line_pointer = c;
469 /* Put it back for error messages etc. */
470 *input_line_pointer = c;
471 /* The following skip of whitespace is compulsory.
472 A well shaped space is sometimes all that separates
473 keyword from operands. */
474 if (c == ' ' || c == '\t')
476 input_line_pointer++;
477 } /* Skip seperator after keyword. */
479 * Input_line is restored.
480 * Input_line_pointer->1st non-blank char
481 * after pseudo-operation.
485 ignore_rest_of_line ();
490 (*pop->poc_handler) (pop->poc_val);
491 } /* if we have one */
495 { /* machine instruction */
496 /* WARNING: c has char, which may be end-of-line. */
497 /* Also: input_line_pointer->`\0` where c was. */
498 *input_line_pointer = c;
499 while (!is_end_of_line[*input_line_pointer])
501 input_line_pointer++;
504 c = *input_line_pointer;
505 *input_line_pointer = '\0';
507 md_assemble (s); /* Assemble 1 instruction. */
509 *input_line_pointer++ = c;
511 /* We resume loop AFTER the end-of-line from this instruction */
516 } /* if (is_name_beginner(c) */
519 if (is_end_of_line[c])
522 } /* empty statement */
525 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
527 { /* local label ("4:") */
528 char *backup = input_line_pointer;
530 HANDLE_CONDITIONAL_ASSEMBLY ();
534 while (isdigit (*input_line_pointer))
536 temp = (temp * 10) + *input_line_pointer - '0';
537 ++input_line_pointer;
538 } /* read the whole number */
540 #ifdef LOCAL_LABELS_DOLLAR
541 if (*input_line_pointer == '$'
542 && *(input_line_pointer + 1) == ':')
544 input_line_pointer += 2;
546 if (dollar_label_defined (temp))
548 as_fatal ("label \"%d$\" redefined", temp);
551 define_dollar_label (temp);
552 colon (dollar_label_name (temp, 0));
555 #endif /* LOCAL_LABELS_DOLLAR */
557 #ifdef LOCAL_LABELS_FB
558 if (*input_line_pointer++ == ':')
560 fb_label_instance_inc (temp);
561 colon (fb_label_name (temp, 0));
564 #endif /* LOCAL_LABELS_FB */
566 input_line_pointer = backup;
567 } /* local label ("4:") */
568 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
570 if (c && strchr (line_comment_chars, c))
571 { /* Its a comment. Better say APP or NO_APP */
577 extern char *scrub_string, *scrub_last_string;
579 bump_line_counters ();
580 s = input_line_pointer;
581 if (strncmp (s, "APP\n", 4))
582 continue; /* We ignore it */
585 ends = strstr (s, "#NO_APP\n");
592 /* The end of the #APP wasn't in this buffer. We
593 keep reading in buffers until we find the #NO_APP
594 that goes with this #APP There is one. The specs
596 tmp_len = buffer_limit - s;
597 tmp_buf = xmalloc (tmp_len + 1);
598 memcpy (tmp_buf, s, tmp_len);
601 new_tmp = input_scrub_next_buffer (&buffer);
605 buffer_limit = new_tmp;
606 input_line_pointer = buffer;
607 ends = strstr (buffer, "#NO_APP\n");
611 num = buffer_limit - buffer;
613 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
614 memcpy (tmp_buf, buffer + tmp_len, num);
619 input_line_pointer = ends ? ends + 8 : NULL;
627 input_line_pointer = ends + 8;
629 new_buf = xmalloc (100);
634 scrub_last_string = ends;
639 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
643 if (new_tmp == new_buf + new_length)
645 new_buf = xrealloc (new_buf, new_length + 100);
646 new_tmp = new_buf + new_length;
654 old_input = input_line_pointer;
655 old_limit = buffer_limit;
657 input_line_pointer = new_buf;
658 buffer_limit = new_tmp;
662 HANDLE_CONDITIONAL_ASSEMBLY ();
664 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
665 input_line_pointer--; /* Report unknown char as ignored. */
666 ignore_rest_of_line ();
667 } /* while (input_line_pointer<buffer_limit) */
670 bump_line_counters ();
674 input_line_pointer = old_input;
675 buffer_limit = old_limit;
680 } /* while (more buffers to scan) */
681 input_scrub_close (); /* Close the input file */
683 } /* read_a_source_file() */
688 as_fatal (".abort detected. Abandoning ship.");
691 /* For machines where ".align 4" means align to a 4 byte boundary. */
696 register unsigned int temp;
697 register long temp_fill;
699 unsigned long max_alignment = 1 << 15;
701 if (is_end_of_line[*input_line_pointer])
702 temp = arg; /* Default value from pseudo-op table */
704 temp = get_absolute_expression ();
706 if (temp > max_alignment)
708 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
712 * For the sparc, `.align (1<<n)' actually means `.align n'
713 * so we have to convert it.
717 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
721 as_bad ("Alignment not a power of 2");
724 if (*input_line_pointer == ',')
726 input_line_pointer++;
727 temp_fill = get_absolute_expression ();
729 else if (now_seg != data_section && now_seg != bss_section)
730 temp_fill = NOP_OPCODE;
733 /* Only make a frag if we HAVE to. . . */
734 if (temp && !need_pass_2)
735 frag_align (temp, (int) temp_fill);
737 record_alignment (now_seg, temp);
739 demand_empty_rest_of_line ();
740 } /* s_align_bytes() */
742 /* For machines where ".align 4" means align to 2**4 boundary. */
747 register long temp_fill;
748 long max_alignment = 15;
750 temp = get_absolute_expression ();
751 if (temp > max_alignment)
752 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
755 as_bad ("Alignment negative. 0 assumed.");
758 if (*input_line_pointer == ',')
760 input_line_pointer++;
761 temp_fill = get_absolute_expression ();
763 /* @@ Fix this right for BFD! */
764 else if (now_seg != data_section && now_seg != bss_section)
765 temp_fill = NOP_OPCODE;
768 /* Only make a frag if we HAVE to. . . */
769 if (temp && !need_pass_2)
770 frag_align (temp, (int) temp_fill);
772 record_alignment (now_seg, temp);
774 demand_empty_rest_of_line ();
775 } /* s_align_ptwo() */
784 register symbolS *symbolP;
786 name = input_line_pointer;
787 c = get_symbol_end ();
788 /* just after name is now '\0' */
789 p = input_line_pointer;
792 if (*input_line_pointer != ',')
794 as_bad ("Expected comma after symbol-name: rest of line ignored.");
795 ignore_rest_of_line ();
798 input_line_pointer++; /* skip ',' */
799 if ((temp = get_absolute_expression ()) < 0)
801 as_warn (".COMMon length (%d.) <0! Ignored.", temp);
802 ignore_rest_of_line ();
806 symbolP = symbol_find_or_make (name);
808 if (S_IS_DEFINED (symbolP))
810 as_bad ("Ignoring attempt to re-define symbol");
811 ignore_rest_of_line ();
814 if (S_GET_VALUE (symbolP))
816 if (S_GET_VALUE (symbolP) != temp)
817 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
818 S_GET_NAME (symbolP),
819 S_GET_VALUE (symbolP),
824 S_SET_VALUE (symbolP, temp);
825 S_SET_EXTERNAL (symbolP);
828 if ( (!temp) || !flagseen['1'])
829 S_GET_OTHER(symbolP) = const_flag;
830 #endif /* not OBJ_VMS */
831 know (symbolP->sy_frag == &zero_address_frag);
832 demand_empty_rest_of_line ();
841 temp = get_absolute_expression ();
844 section = text_section;
848 section = data_section;
851 subseg_set (section, (subsegT) temp);
853 subseg_new (section, (subsegT) temp);
859 demand_empty_rest_of_line ();
862 /* Handle the .appfile pseudo-op. This is automatically generated by
863 do_scrub_next_char when a preprocessor # line comment is seen with
864 a file name. This default definition may be overridden by the
865 object or CPU specific pseudo-ops. This function is also the
866 default definition for .file; the APPFILE argument is 1 for
867 .appfile, 0 for .file. */
876 /* Some assemblers tolerate immediately following '"' */
877 if ((s = demand_copy_string (&length)) != 0)
879 /* If this is a fake .appfile, a fake newline was inserted into
880 the buffer. Passing -2 to new_logical_line tells it to
882 new_logical_line (s, appfile ? -2 : -1);
883 demand_empty_rest_of_line ();
886 listing_source_file (s);
890 c_dot_file_symbol (s);
891 #endif /* OBJ_COFF */
897 /* Handle the .appline pseudo-op. This is automatically generated by
898 do_scrub_next_char when a preprocessor # line comment is seen.
899 This default definition may be overridden by the object or CPU
900 specific pseudo-ops. */
907 /* The given number is that of the next line. */
908 l = get_absolute_expression () - 1;
909 new_logical_line ((char *) NULL, l);
912 listing_source_line (l);
914 demand_empty_rest_of_line ();
920 long temp_repeat = 0;
922 register long temp_fill = 0;
926 temp_repeat = get_absolute_expression ();
927 if (*input_line_pointer == ',')
929 input_line_pointer++;
930 temp_size = get_absolute_expression ();
931 if (*input_line_pointer == ',')
933 input_line_pointer++;
934 temp_fill = get_absolute_expression ();
937 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
938 #define BSD_FILL_SIZE_CROCK_8 (8)
939 if (temp_size > BSD_FILL_SIZE_CROCK_8)
941 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
942 temp_size = BSD_FILL_SIZE_CROCK_8;
946 as_warn ("Size negative: .fill ignored.");
949 else if (temp_repeat <= 0)
951 as_warn ("Repeat < 0, .fill ignored");
955 if (temp_size && !need_pass_2)
957 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
958 memset (p, 0, (int) temp_size);
959 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
960 * flavoured AS. The following bizzare behaviour is to be
961 * compatible with above. I guess they tried to take up to 8
962 * bytes from a 4-byte expression and they forgot to sign
963 * extend. Un*x Sux. */
964 #define BSD_FILL_SIZE_CROCK_4 (4)
965 md_number_to_chars (p, temp_fill,
966 (temp_size > BSD_FILL_SIZE_CROCK_4
967 ? BSD_FILL_SIZE_CROCK_4
969 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
970 * but emits no error message because it seems a legal thing to do.
971 * It is a degenerate case of .fill but could be emitted by a compiler.
974 demand_empty_rest_of_line ();
986 name = input_line_pointer;
987 c = get_symbol_end ();
988 symbolP = symbol_find_or_make (name);
989 *input_line_pointer = c;
991 S_SET_EXTERNAL (symbolP);
994 input_line_pointer++;
996 if (*input_line_pointer == '\n')
1001 demand_empty_rest_of_line ();
1005 s_lcomm (needs_align)
1006 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1007 (alignment); 0 if it was an ".lcomm" (2 args only) */
1010 register char *name;
1014 register symbolS *symbolP;
1015 segT current_seg = now_seg;
1016 subsegT current_subseg = now_subseg;
1017 const int max_alignment = 15;
1019 segT bss_seg = bss_section;
1021 name = input_line_pointer;
1022 c = get_symbol_end ();
1023 p = input_line_pointer;
1026 if (*input_line_pointer != ',')
1028 as_bad ("Expected comma after name");
1029 ignore_rest_of_line ();
1033 ++input_line_pointer;
1035 if (*input_line_pointer == '\n')
1037 as_bad ("Missing size expression");
1041 if ((temp = get_absolute_expression ()) < 0)
1043 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1044 ignore_rest_of_line ();
1050 /* For MIPS ECOFF, small objects are put in .sbss. */
1051 if (temp <= bfd_get_gp_size (stdoutput))
1052 bss_seg = subseg_new (".sbss", 1);
1060 if (*input_line_pointer != ',')
1062 as_bad ("Expected comma after size");
1063 ignore_rest_of_line ();
1066 input_line_pointer++;
1068 if (*input_line_pointer == '\n')
1070 as_bad ("Missing alignment");
1073 align = get_absolute_expression ();
1074 if (align > max_alignment)
1076 align = max_alignment;
1077 as_warn ("Alignment too large: %d. assumed.", align);
1082 as_warn ("Alignment negative. 0 assumed.");
1084 record_alignment (bss_seg, align);
1085 } /* if needs align */
1088 symbolP = symbol_find_or_make (name);
1092 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1093 S_GET_OTHER (symbolP) == 0 &&
1094 S_GET_DESC (symbolP) == 0 &&
1095 #endif /* OBJ_AOUT or OBJ_BOUT */
1096 (S_GET_SEGMENT (symbolP) == bss_seg
1097 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1101 #ifdef BFD_ASSEMBLER
1102 subseg_set (bss_seg, 1);
1104 subseg_new (bss_seg, 1);
1108 frag_align (align, 0);
1109 /* detach from old frag */
1110 if (S_GET_SEGMENT (symbolP) == bss_seg)
1111 symbolP->sy_frag->fr_symbol = NULL;
1113 symbolP->sy_frag = frag_now;
1114 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1118 S_SET_SEGMENT (symbolP, bss_seg);
1121 /* The symbol may already have been created with a preceding
1122 ".globl" directive -- be careful not to step on storage class
1123 in that case. Otherwise, set it to static. */
1124 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1126 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1128 #endif /* OBJ_COFF */
1132 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1135 #ifdef BFD_ASSEMBLER
1136 subseg_set (current_seg, current_subseg);
1138 subseg_new (current_seg, current_subseg);
1141 demand_empty_rest_of_line ();
1159 register char *name;
1162 register segT segment;
1164 register symbolS *symbolP;
1167 /* we permit ANY defined expression: BSD4.2 demands constants */
1168 name = input_line_pointer;
1169 c = get_symbol_end ();
1170 p = input_line_pointer;
1173 if (*input_line_pointer != ',')
1176 as_bad ("Expected comma after name \"%s\"", name);
1178 ignore_rest_of_line ();
1181 input_line_pointer++;
1182 val = get_absolute_expression ();
1184 symbolP = symbol_find_or_make (name);
1186 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1187 symbolP->sy_desc == 0) out of this test because coff doesn't have
1188 those fields, and I can't see when they'd ever be tripped. I
1189 don't think I understand why they were here so I may have
1190 introduced a bug. As recently as 1.37 didn't have this test
1191 anyway. xoxorich. */
1193 if (S_GET_SEGMENT (symbolP) == undefined_section
1194 && S_GET_VALUE (symbolP) == 0)
1196 /* The name might be an undefined .global symbol; be sure to
1197 keep the "external" bit. */
1198 S_SET_SEGMENT (symbolP, segment);
1199 S_SET_VALUE (symbolP, val);
1203 as_bad ("Symbol %s already defined", name);
1206 demand_empty_rest_of_line ();
1212 register segT segment;
1214 register long temp_fill;
1216 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1217 thing as a sub-segment-relative origin. Any absolute origin is
1218 given a warning, then assumed to be segment-relative. Any
1219 segmented origin expression ("foo+42") had better be in the right
1220 segment or the .org is ignored.
1222 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1223 we never know sub-segment sizes when we are reading code. BSD
1224 will crash trying to emit negative numbers of filler bytes in
1225 certain .orgs. We don't crash, but see as-write for that code.
1227 Don't make frag if need_pass_2==1. */
1228 segment = get_known_segmented_expression (&exp);
1229 if (*input_line_pointer == ',')
1231 input_line_pointer++;
1232 temp_fill = get_absolute_expression ();
1238 if (segment != now_seg && segment != absolute_section)
1239 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1240 segment_name (segment), segment_name (now_seg));
1241 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1242 exp.X_add_number, (char *) 0);
1244 } /* if (ok to make frag) */
1245 demand_empty_rest_of_line ();
1251 register char *name;
1252 register char delim;
1253 register char *end_name;
1254 register symbolS *symbolP;
1257 * Especial apologies for the random logic:
1258 * this just grew, and could be parsed much more simply!
1261 name = input_line_pointer;
1262 delim = get_symbol_end ();
1263 end_name = input_line_pointer;
1267 if (*input_line_pointer != ',')
1270 as_bad ("Expected comma after name \"%s\"", name);
1272 ignore_rest_of_line ();
1276 input_line_pointer++;
1279 if (name[0] == '.' && name[1] == '\0')
1281 /* Turn '. = mumble' into a .org mumble */
1282 register segT segment;
1286 segment = get_known_segmented_expression (&exp);
1290 if (segment != now_seg && segment != absolute_section)
1291 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1292 segment_name (segment),
1293 segment_name (now_seg));
1294 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1295 exp.X_add_number, (char *) 0);
1297 } /* if (ok to make frag) */
1303 if ((symbolP = symbol_find (name)) == NULL
1304 && (symbolP = md_undefined_symbol (name)) == NULL)
1306 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1308 /* "set" symbols are local unless otherwise specified. */
1309 SF_SET_LOCAL (symbolP);
1310 #endif /* OBJ_COFF */
1312 } /* make a new symbol */
1314 symbol_table_insert (symbolP);
1317 pseudo_set (symbolP);
1318 demand_empty_rest_of_line ();
1326 register long temp_fill;
1329 /* Just like .fill, but temp_size = 1 */
1330 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1332 temp_fill = get_absolute_expression ();
1336 input_line_pointer--; /* Backup over what was not a ','. */
1341 temp_repeat *= mult;
1343 if (temp_repeat <= 0)
1345 as_warn ("Repeat < 0, .space ignored");
1346 ignore_rest_of_line ();
1351 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1352 temp_repeat, (char *) 0);
1355 demand_empty_rest_of_line ();
1363 temp = get_absolute_expression ();
1364 #ifdef BFD_ASSEMBLER
1365 subseg_set (text_section, (subsegT) temp);
1367 subseg_new (text_section, (subsegT) temp);
1369 demand_empty_rest_of_line ();
1374 demand_empty_rest_of_line ()
1377 if (is_end_of_line[*input_line_pointer])
1379 input_line_pointer++;
1383 ignore_rest_of_line ();
1385 /* Return having already swallowed end-of-line. */
1386 } /* Return pointing just after end-of-line. */
1389 ignore_rest_of_line () /* For suspect lines: gives warning. */
1391 if (!is_end_of_line[*input_line_pointer])
1393 if (isprint (*input_line_pointer))
1394 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1395 *input_line_pointer);
1397 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1398 *input_line_pointer);
1399 while (input_line_pointer < buffer_limit
1400 && !is_end_of_line[*input_line_pointer])
1402 input_line_pointer++;
1405 input_line_pointer++; /* Return pointing just after end-of-line. */
1406 know (is_end_of_line[input_line_pointer[-1]]);
1412 * In: Pointer to a symbol.
1413 * Input_line_pointer->expression.
1415 * Out: Input_line_pointer->just after any whitespace after expression.
1416 * Tried to set symbol to value of expression.
1417 * Will change symbols type, value, and frag;
1420 pseudo_set (symbolP)
1424 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1426 #endif /* OBJ_AOUT or OBJ_BOUT */
1428 know (symbolP); /* NULL pointer is logic error. */
1429 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1430 /* @@ Fix this right for BFD. */
1431 ext = S_IS_EXTERNAL (symbolP);
1432 #endif /* OBJ_AOUT or OBJ_BOUT */
1434 (void) expression (&exp);
1436 if (exp.X_op == O_illegal)
1437 as_bad ("illegal expression; zero assumed");
1438 else if (exp.X_op == O_absent)
1439 as_bad ("missing expression; zero assumed");
1440 else if (exp.X_op == O_big)
1441 as_bad ("%s number invalid; zero assumed",
1442 exp.X_add_number > 0 ? "bignum" : "floating point");
1443 else if (exp.X_op == O_subtract
1444 && (S_GET_SEGMENT (exp.X_add_symbol)
1445 == S_GET_SEGMENT (exp.X_op_symbol))
1446 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1447 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1449 exp.X_op = O_constant;
1450 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1451 - S_GET_VALUE (exp.X_op_symbol));
1459 exp.X_add_number = 0;
1462 S_SET_SEGMENT (symbolP, absolute_section);
1463 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1464 /* @@ Fix this right for BFD. */
1466 S_SET_EXTERNAL (symbolP);
1468 S_CLEAR_EXTERNAL (symbolP);
1469 #endif /* OBJ_AOUT or OBJ_BOUT */
1470 S_SET_VALUE (symbolP, exp.X_add_number);
1471 symbolP->sy_frag = &zero_address_frag;
1475 S_SET_SEGMENT (symbolP, reg_section);
1476 S_SET_VALUE (symbolP, exp.X_add_number);
1477 symbolP->sy_frag = &zero_address_frag;
1481 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1482 symbolP->sy_value = exp;
1485 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1486 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1487 /* @@ Fix this right for BFD! */
1489 S_SET_EXTERNAL (symbolP);
1491 S_CLEAR_EXTERNAL (symbolP);
1492 #endif /* OBJ_AOUT or OBJ_BOUT */
1493 S_SET_VALUE (symbolP,
1494 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1495 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1500 /* The value is some complex expression.
1501 FIXME: Should we set the segment to anything? */
1502 symbolP->sy_value = exp;
1510 * CONStruct more frag of .bytes, or .words etc.
1511 * Should need_pass_2 be 1 then emit no frag(s).
1512 * This understands EXPRESSIONS, as opposed to big_cons().
1516 * This has a split personality. We use expression() to read the
1517 * value. We can detect if the value won't fit in a byte or word.
1518 * But we can't detect if expression() discarded significant digits
1519 * in the case of a long. Not worth the crocks required to fix it.
1522 /* Select a parser for cons expressions. */
1524 /* Some targets need to parse the expression in various fancy ways.
1525 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1526 (for example, the HPPA does this). Otherwise, you can define
1527 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1528 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1529 are defined, which is the normal case, then only simple expressions
1532 #ifndef TC_PARSE_CONS_EXPRESSION
1533 #ifdef BITFIELD_CONS_EXPRESSIONS
1534 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1536 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1539 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1541 parse_mri_cons PARAMS ((expressionS *exp));
1543 #ifdef REPEAT_CONS_EXPRESSIONS
1544 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1546 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1549 /* If we haven't gotten one yet, just call expression. */
1550 #ifndef TC_PARSE_CONS_EXPRESSION
1551 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1555 /* worker to do .byte etc statements */
1556 /* clobbers input_line_pointer, checks */
1560 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1564 if (is_it_end_of_statement ())
1566 demand_empty_rest_of_line ();
1572 TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
1573 emit_expr (&exp, nbytes);
1575 while (*input_line_pointer++ == ',');
1577 input_line_pointer--; /* Put terminator back into stream. */
1578 demand_empty_rest_of_line ();
1581 /* Put the contents of expression EXP into the object file using
1582 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1585 emit_expr (exp, nbytes)
1587 unsigned int nbytes;
1592 /* Don't do anything if we are going to make another pass. */
1598 if (op == O_absent || op == O_illegal)
1600 as_warn ("zero assumed for missing expression");
1601 exp->X_add_number = 0;
1604 else if (op == O_big)
1606 as_bad ("%s number invalid; zero assumed",
1607 exp->X_add_number > 0 ? "bignum" : "floating point");
1608 exp->X_add_number = 0;
1611 else if (op == O_register)
1613 as_warn ("register value used as expression");
1617 p = frag_more (nbytes);
1619 #ifndef WORKING_DOT_WORD
1620 /* If we have the difference of two symbols in a word, save it on
1621 the broken_words list. See the code in write.c. */
1622 if (op == O_subtract && nbytes == 2)
1624 struct broken_word *x;
1626 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1627 x->next_broken_word = broken_words;
1630 x->word_goes_here = p;
1632 x->add = exp->X_add_symbol;
1633 x->sub = exp->X_op_symbol;
1634 x->addnum = exp->X_add_number;
1641 if (op == O_constant)
1646 register long unmask;
1648 /* JF << of >= number of bits in the object is undefined. In
1649 particular SPARC (Sun 4) has problems */
1650 if (nbytes >= sizeof (long))
1653 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1655 unmask = ~mask; /* Do store these bits. */
1658 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1659 mask = ~(unmask >> 1); /* Includes sign bit now. */
1662 get = exp->X_add_number;
1664 if ((get & mask) != 0 && (get & mask) != mask)
1665 { /* Leading bits contain both 0s & 1s. */
1666 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
1668 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1672 md_number_to_chars (p, (long) 0, nbytes);
1674 /* Now we need to generate a fixS to record the symbol value.
1675 This is easy for BFD. For other targets it can be more
1676 complex. For very complex cases (currently, the HPPA and
1677 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1678 want. For simpler cases, you can define TC_CONS_RELOC to be
1679 the name of the reloc code that should be stored in the fixS.
1680 If neither is defined, the code uses NO_RELOC if it is
1681 defined, and otherwise uses 0. */
1683 #ifdef BFD_ASSEMBLER
1684 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1685 /* @@ Should look at CPU word size. */
1688 #ifdef TC_CONS_FIX_NEW
1689 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1691 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1692 it is defined, otherwise use NO_RELOC if it is defined,
1694 #ifndef TC_CONS_RELOC
1696 #define TC_CONS_RELOC NO_RELOC
1698 #define TC_CONS_RELOC 0
1701 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1703 #endif /* TC_CONS_FIX_NEW */
1704 #endif /* BFD_ASSEMBLER */
1708 #ifdef BITFIELD_CONS_EXPRESSIONS
1710 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1711 w:x,y:z, where w and y are bitwidths and x and y are values. They
1712 then pack them all together. We do a little better in that we allow
1713 them in words, longs, etc. and we'll pack them in target byte order
1716 The rules are: pack least significat bit first, if a field doesn't
1717 entirely fit, put it in the next unit. Overflowing the bitfield is
1718 explicitly *not* even a warning. The bitwidth should be considered
1721 To use this function the tc-XXX.h file should define
1722 BITFIELD_CONS_EXPRESSIONS. */
1725 parse_bitfield_cons (exp, nbytes)
1727 unsigned int nbytes;
1729 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1730 char *hold = input_line_pointer;
1732 (void) expression (exp);
1734 if (*input_line_pointer == ':')
1740 unsigned long width;
1742 if (*input_line_pointer != ':')
1744 input_line_pointer = hold;
1746 } /* next piece is not a bitfield */
1748 /* In the general case, we can't allow
1749 full expressions with symbol
1750 differences and such. The relocation
1751 entries for symbols not defined in this
1752 assembly would require arbitrary field
1753 widths, positions, and masks which most
1754 of our current object formats don't
1757 In the specific case where a symbol
1758 *is* defined in this assembly, we
1759 *could* build fixups and track it, but
1760 this could lead to confusion for the
1761 backends. I'm lazy. I'll take any
1762 SEG_ABSOLUTE. I think that means that
1763 you can use a previous .set or
1764 .equ type symbol. xoxorich. */
1766 if (exp->X_op == O_absent)
1768 as_warn ("using a bit field width of zero");
1769 exp->X_add_number = 0;
1770 exp->X_op = O_constant;
1771 } /* implied zero width bitfield */
1773 if (exp->X_op != O_constant)
1775 *input_line_pointer = '\0';
1776 as_bad ("field width \"%s\" too complex for a bitfield", hold);
1777 *input_line_pointer = ':';
1778 demand_empty_rest_of_line ();
1782 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
1784 as_warn ("field width %d too big to fit in %d bytes: truncated to %d bits",
1785 width, nbytes, (BITS_PER_CHAR * nbytes));
1786 width = BITS_PER_CHAR * nbytes;
1789 if (width > bits_available)
1791 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1792 input_line_pointer = hold;
1793 exp->X_add_number = value;
1797 hold = ++input_line_pointer; /* skip ':' */
1799 (void) expression (exp);
1800 if (exp->X_op != O_constant)
1802 char cache = *input_line_pointer;
1804 *input_line_pointer = '\0';
1805 as_bad ("field value \"%s\" too complex for a bitfield", hold);
1806 *input_line_pointer = cache;
1807 demand_empty_rest_of_line ();
1811 value |= ((~(-1 << width) & exp->X_add_number)
1812 << ((BITS_PER_CHAR * nbytes) - bits_available));
1814 if ((bits_available -= width) == 0
1815 || is_it_end_of_statement ()
1816 || *input_line_pointer != ',')
1819 } /* all the bitfields we're gonna get */
1821 hold = ++input_line_pointer;
1822 (void) expression (exp);
1823 } /* forever loop */
1825 exp->X_add_number = value;
1826 exp->X_op = O_constant;
1827 } /* if looks like a bitfield */
1828 } /* parse_bitfield_cons() */
1830 #endif /* BITFIELD_CONS_EXPRESSIONS */
1835 parse_mri_cons (exp, nbytes)
1837 unsigned int nbytes;
1839 if (*input_line_pointer == '\'')
1841 /* An MRI style string, cut into as many bytes as will fit into
1842 a nbyte chunk, left justify if necessary, and separate with
1843 commas so we can try again later */
1845 unsigned int result = 0;
1846 input_line_pointer++;
1847 for (scan = 0; scan < nbytes; scan++)
1849 if (*input_line_pointer == '\'')
1851 if (input_line_pointer[1] == '\'')
1853 input_line_pointer++;
1858 result = (result << 8) | (*input_line_pointer++);
1862 while (scan < nbytes)
1867 /* Create correct expression */
1868 exp->X_op = O_constant;
1869 exp->X_add_number = result;
1870 /* Fake it so that we can read the next char too */
1871 if (input_line_pointer[0] != '\'' ||
1872 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1874 input_line_pointer -= 2;
1875 input_line_pointer[0] = ',';
1876 input_line_pointer[1] = '\'';
1879 input_line_pointer++;
1887 #ifdef REPEAT_CONS_EXPRESSIONS
1889 /* Parse a repeat expression for cons. This is used by the MIPS
1890 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1891 object file COUNT times.
1893 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1896 parse_repeat_cons (exp, nbytes)
1898 unsigned int nbytes;
1905 if (*input_line_pointer != ':')
1907 /* No repeat count. */
1911 ++input_line_pointer;
1912 expression (&count);
1913 if (count.X_op != O_constant
1914 || count.X_add_number <= 0)
1916 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1920 /* The cons function is going to output this expression once. So we
1921 output it count - 1 times. */
1922 for (i = count.X_add_number - 1; i > 0; i--)
1923 emit_expr (exp, nbytes);
1926 #endif /* REPEAT_CONS_EXPRESSIONS */
1931 * CONStruct more frag(s) of .quads, or .octa etc.
1932 * Makes 0 or more new frags.
1933 * If need_pass_2 == 1, generate no frag.
1934 * This understands only bignums, not expressions. Cons() understands
1937 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1939 * This creates objects with struct obstack_control objs, destroying
1940 * any context objs held about a partially completed object. Beware!
1943 * I think it sucks to have 2 different types of integers, with 2
1944 * routines to read them, store them etc.
1945 * It would be nicer to permit bignums in expressions and only
1946 * complain if the result overflowed. However, due to "efficiency"...
1948 /* worker to do .quad etc statements */
1949 /* clobbers input_line_pointer, checks */
1951 /* 8=.quad 16=.octa ... */
1955 register int nbytes;
1957 register char c; /* input_line_pointer->c. */
1959 register long length; /* Number of chars in an object. */
1960 register int digit; /* Value of 1 digit. */
1961 register int carry; /* For multi-precision arithmetic. */
1962 register int work; /* For multi-precision arithmetic. */
1963 register char *p; /* For multi-precision arithmetic. */
1965 extern const char hex_value[]; /* In hex_value.c. */
1968 * The following awkward logic is to parse ZERO or more strings,
1969 * comma seperated. Recall an expression includes its leading &
1970 * trailing blanks. We fake a leading ',' if there is (supposed to
1971 * be) a 1st expression, and keep demanding 1 expression for each ','.
1973 if (is_it_end_of_statement ())
1975 c = 0; /* Skip loop. */
1979 c = ','; /* Do loop. */
1980 --input_line_pointer;
1984 ++input_line_pointer;
1986 c = *input_line_pointer;
1987 /* C contains 1st non-blank character of what we hope is a number. */
1990 c = *++input_line_pointer;
1991 if (c == 'x' || c == 'X')
1993 c = *++input_line_pointer;
2006 * This feature (?) is here to stop people worrying about
2007 * mysterious zero constants: which is what they get when
2008 * they completely omit digits.
2010 if (hex_value[c] >= radix)
2012 as_bad ("Missing digits. 0 assumed.");
2014 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
2015 for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
2017 /* Multiply existing number by radix, then add digit. */
2019 for (p = bignum_low; p <= bignum_high; p++)
2021 work = (*p & MASK_CHAR) * radix + carry;
2022 *p = work & MASK_CHAR;
2023 carry = work >> BITS_PER_CHAR;
2028 *bignum_high = carry & MASK_CHAR;
2029 know ((carry & ~MASK_CHAR) == 0);
2032 length = bignum_high - bignum_low + 1;
2033 if (length > nbytes)
2035 as_warn ("Most significant bits truncated in integer constant.");
2039 register long leading_zeroes;
2041 for (leading_zeroes = nbytes - length;
2051 char *src = bignum_low;
2052 p = frag_more (nbytes);
2053 if (target_big_endian)
2056 for (i = nbytes - 1; i >= 0; i--)
2060 memcpy (p, bignum_low, (int) nbytes);
2062 /* C contains character after number. */
2064 c = *input_line_pointer;
2065 /* C contains 1st non-blank character after number. */
2067 demand_empty_rest_of_line ();
2070 /* Extend bignum by 1 char. */
2074 register long length;
2077 if (bignum_high >= bignum_limit)
2079 length = bignum_limit - bignum_low;
2080 bignum_low = xrealloc (bignum_low, length + length);
2081 bignum_high = bignum_low + length;
2082 bignum_limit = bignum_low + length + length;
2084 } /* grow_bignum(); */
2089 * CONStruct some more frag chars of .floats .ffloats etc.
2090 * Makes 0 or more new frags.
2091 * If need_pass_2 == 1, no frags are emitted.
2092 * This understands only floating literals, not expressions. Sorry.
2094 * A floating constant is defined by atof_generic(), except it is preceded
2095 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2096 * reading, I decided to be incompatible. This always tries to give you
2097 * rounded bits to the precision of the pseudo-op. Former AS did premature
2098 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2099 * a choice of 2 flavours of noise according to which of 2 floating-point
2100 * scanners you directed AS to use.
2102 * In: input_line_pointer->whitespace before, or '0' of flonum.
2106 void /* JF was static, but can't be if VAX.C is goning to use it */
2107 float_cons (float_type) /* Worker to do .float etc statements. */
2108 /* Clobbers input_line-pointer, checks end-of-line. */
2109 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2112 int length; /* Number of chars in an object. */
2113 register char *err; /* Error from scanning floating literal. */
2114 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2116 if (is_it_end_of_statement ())
2118 demand_empty_rest_of_line ();
2124 /* input_line_pointer->1st char of a flonum (we hope!). */
2127 /* Skip any 0{letter} that may be present. Don't even check if the
2128 * letter is legal. Someone may invent a "z" format and this routine
2129 * has no use for such information. Lusers beware: you get
2130 * diagnostics if your input is ill-conditioned.
2132 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2133 input_line_pointer += 2;
2135 err = md_atof (float_type, temp, &length);
2136 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2140 as_bad ("Bad floating literal: %s", err);
2141 ignore_rest_of_line ();
2151 #ifdef REPEAT_CONS_EXPRESSIONS
2152 if (*input_line_pointer == ':')
2154 expressionS count_exp;
2156 ++input_line_pointer;
2157 expression (&count_exp);
2158 if (count_exp.X_op != O_constant
2159 || count_exp.X_add_number <= 0)
2161 as_warn ("unresolvable or nonpositive repeat count; using 1");
2164 count = count_exp.X_add_number;
2168 while (--count >= 0)
2170 p = frag_more (length);
2171 memcpy (p, temp, length);
2176 while (*input_line_pointer++ == ',');
2178 --input_line_pointer; /* Put terminator back into stream. */
2179 demand_empty_rest_of_line ();
2180 } /* float_cons() */
2185 * We read 0 or more ',' seperated, double-quoted strings.
2187 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2192 stringer (append_zero) /* Worker to do .ascii etc statements. */
2193 /* Checks end-of-line. */
2194 register int append_zero; /* 0: don't append '\0', else 1 */
2196 register unsigned int c;
2199 * The following awkward logic is to parse ZERO or more strings,
2200 * comma seperated. Recall a string expression includes spaces
2201 * before the opening '\"' and spaces after the closing '\"'.
2202 * We fake a leading ',' if there is (supposed to be)
2203 * a 1st, expression. We keep demanding expressions for each
2206 if (is_it_end_of_statement ())
2208 c = 0; /* Skip loop. */
2209 ++input_line_pointer; /* Compensate for end of loop. */
2213 c = ','; /* Do loop. */
2215 while (c == ',' || c == '<' || c == '"')
2218 switch (*input_line_pointer)
2221 ++input_line_pointer; /*->1st char of string. */
2222 while (is_a_char (c = next_char_of_string ()))
2224 FRAG_APPEND_1_CHAR (c);
2228 FRAG_APPEND_1_CHAR (0);
2230 know (input_line_pointer[-1] == '\"');
2233 input_line_pointer++;
2234 c = get_single_number ();
2235 FRAG_APPEND_1_CHAR (c);
2236 if (*input_line_pointer != '>')
2238 as_bad ("Expected <nn>");
2240 input_line_pointer++;
2243 input_line_pointer++;
2247 c = *input_line_pointer;
2250 demand_empty_rest_of_line ();
2253 /* FIXME-SOMEDAY: I had trouble here on characters with the
2254 high bits set. We'll probably also have trouble with
2255 multibyte chars, wide chars, etc. Also be careful about
2256 returning values bigger than 1 byte. xoxorich. */
2259 next_char_of_string ()
2261 register unsigned int c;
2263 c = *input_line_pointer++ & CHAR_MASK;
2271 switch (c = *input_line_pointer++)
2301 break; /* As itself. */
2316 for (number = 0; isdigit (c); c = *input_line_pointer++)
2318 number = number * 8 + c - '0';
2322 --input_line_pointer;
2326 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2327 as_warn ("Unterminated string: Newline inserted.");
2333 #ifdef ONLY_STANDARD_ESCAPES
2334 as_bad ("Bad escaped character in string, '?' assumed");
2336 #endif /* ONLY_STANDARD_ESCAPES */
2339 } /* switch on escaped char */
2344 } /* switch on char */
2346 } /* next_char_of_string() */
2349 get_segmented_expression (expP)
2350 register expressionS *expP;
2352 register segT retval;
2354 retval = expression (expP);
2355 if (expP->X_op == O_illegal
2356 || expP->X_op == O_absent
2357 || expP->X_op == O_big)
2359 as_bad ("expected address expression; zero assumed");
2360 expP->X_op = O_constant;
2361 expP->X_add_number = 0;
2362 retval = absolute_section;
2368 get_known_segmented_expression (expP)
2369 register expressionS *expP;
2371 register segT retval;
2373 if ((retval = get_segmented_expression (expP)) == undefined_section)
2375 /* There is no easy way to extract the undefined symbol from the
2377 if (expP->X_add_symbol != NULL
2378 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2379 as_warn ("symbol \"%s\" undefined; zero assumed",
2380 S_GET_NAME (expP->X_add_symbol));
2382 as_warn ("some symbol undefined; zero assumed");
2383 retval = absolute_section;
2384 expP->X_op = O_constant;
2385 expP->X_add_number = 0;
2387 know (retval == absolute_section || SEG_NORMAL (retval));
2389 } /* get_known_segmented_expression() */
2391 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2392 get_absolute_expression ()
2397 if (exp.X_op != O_constant)
2399 if (exp.X_op != O_absent)
2400 as_bad ("bad absolute expression; zero assumed");
2401 exp.X_add_number = 0;
2403 return exp.X_add_number;
2406 char /* return terminator */
2407 get_absolute_expression_and_terminator (val_pointer)
2408 long *val_pointer; /* return value of expression */
2410 *val_pointer = get_absolute_expression ();
2411 return (*input_line_pointer++);
2415 * demand_copy_C_string()
2417 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2418 * Give a warning if that happens.
2421 demand_copy_C_string (len_pointer)
2426 if ((s = demand_copy_string (len_pointer)) != 0)
2430 for (len = *len_pointer;
2439 as_bad ("This string may not contain \'\\0\'");
2447 * demand_copy_string()
2449 * Demand string, but return a safe (=private) copy of the string.
2450 * Return NULL if we can't read a string here.
2453 demand_copy_string (lenP)
2456 register unsigned int c;
2462 if (*input_line_pointer == '\"')
2464 input_line_pointer++; /* Skip opening quote. */
2466 while (is_a_char (c = next_char_of_string ()))
2468 obstack_1grow (¬es, c);
2471 /* JF this next line is so demand_copy_C_string will return a null
2472 termanated string. */
2473 obstack_1grow (¬es, '\0');
2474 retval = obstack_finish (¬es);
2478 as_warn ("Missing string");
2480 ignore_rest_of_line ();
2484 } /* demand_copy_string() */
2487 * is_it_end_of_statement()
2489 * In: Input_line_pointer->next character.
2491 * Do: Skip input_line_pointer over all whitespace.
2493 * Out: 1 if input_line_pointer->end-of-line.
2496 is_it_end_of_statement ()
2499 return (is_end_of_line[*input_line_pointer]);
2500 } /* is_it_end_of_statement() */
2506 register symbolS *symbolP; /* symbol we are working with */
2508 input_line_pointer++;
2509 if (*input_line_pointer == '=')
2510 input_line_pointer++;
2512 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2513 input_line_pointer++;
2515 if (sym_name[0] == '.' && sym_name[1] == '\0')
2517 /* Turn '. = mumble' into a .org mumble */
2518 register segT segment;
2522 segment = get_known_segmented_expression (&exp);
2525 if (segment != now_seg && segment != absolute_section)
2526 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2527 segment_name (segment),
2528 segment_name (now_seg));
2529 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2530 exp.X_add_number, (char *) 0);
2532 } /* if (ok to make frag) */
2536 symbolP = symbol_find_or_make (sym_name);
2537 pseudo_set (symbolP);
2541 /* .include -- include a file at this point. */
2554 filename = demand_copy_string (&i);
2555 demand_empty_rest_of_line ();
2556 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2557 for (i = 0; i < include_dir_count; i++)
2559 strcpy (path, include_dirs[i]);
2561 strcat (path, filename);
2562 if (0 != (try = fopen (path, "r")))
2571 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2572 newbuf = input_scrub_include_file (path, input_line_pointer);
2573 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2577 add_include_dir (path)
2582 if (include_dir_count == 0)
2584 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2585 include_dirs[0] = "."; /* Current dir */
2586 include_dir_count = 2;
2590 include_dir_count++;
2591 include_dirs = (char **) realloc (include_dirs,
2592 include_dir_count * sizeof (*include_dirs));
2595 include_dirs[include_dir_count - 1] = path; /* New one */
2598 if (i > include_dir_maxlen)
2599 include_dir_maxlen = i;
2600 } /* add_include_dir() */
2606 while (!is_end_of_line[*input_line_pointer])
2608 ++input_line_pointer;
2610 ++input_line_pointer;