1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
28 #define MASK_CHAR ((int)(unsigned char)-1)
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
47 #include "libiberty.h"
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 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
74 /* The m88k unfortunately uses @ as a label beginner. */
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 /* The Delta 68k assembler permits % inside label names. */
88 /* used by is_... macros. our ctype[] */
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
93 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
94 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
95 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
97 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
98 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 * Out: 1 if this character ends a line.
114 char is_end_of_line[256] =
117 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
119 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
129 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
130 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
133 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
135 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
136 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
141 /* Functions private to this file. */
143 static char *buffer; /* 1st char of each buffer of lines is here. */
144 static char *buffer_limit; /*->1 + last char in buffer. */
146 #ifdef TARGET_BYTES_BIG_ENDIAN
147 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
148 instead of to 0 or 1. */
149 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
150 #undef TARGET_BYTES_BIG_ENDIAN
151 #define TARGET_BYTES_BIG_ENDIAN 1
153 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
155 int target_big_endian /* = 0 */;
158 static char *old_buffer; /* JF a hack */
159 static char *old_input;
160 static char *old_limit;
162 /* Variables for handling include file directory list. */
164 char **include_dirs; /* List of pointers to directories to
165 search for .include's */
166 int include_dir_count; /* How many are in the list */
167 int include_dir_maxlen = 1;/* Length of longest in list */
169 #ifndef WORKING_DOT_WORD
170 struct broken_word *broken_words;
171 int new_broken_words;
174 /* The current offset into the absolute section. We don't try to
175 build frags in the absolute section, since no data can be stored
176 there. We just keep track of the current offset. */
177 addressT abs_section_offset;
179 /* If this line had an MRI style label, it is stored in this variable.
180 This is used by some of the MRI pseudo-ops. */
183 /* This global variable is used to support MRI common sections. We
184 translate such sections into a common symbol. This variable is
185 non-NULL when we are in an MRI common section. */
186 symbolS *mri_common_symbol;
188 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
189 need to align to an even byte boundary unless the next pseudo-op is
190 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
192 static int mri_pending_align;
194 static int scrub_from_string PARAMS ((char **));
195 static void do_align PARAMS ((int, char *));
196 static int hex_float PARAMS ((int, char *));
197 static void do_org PARAMS ((segT, expressionS *, int));
198 char *demand_copy_string PARAMS ((int *lenP));
199 int is_it_end_of_statement PARAMS ((void));
200 static segT get_segmented_expression PARAMS ((expressionS *expP));
201 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
202 static void pobegin PARAMS ((void));
203 static int get_line_sb PARAMS ((sb *));
212 obj_read_begin_hook ();
214 /* Something close -- but not too close -- to a multiple of 1024.
215 The debugging malloc I'm using has 24 bytes of overhead. */
216 obstack_begin (¬es, 5090);
217 obstack_begin (&cond_obstack, 990);
219 /* Use machine dependent syntax */
220 for (p = line_separator_chars; *p; p++)
221 is_end_of_line[(unsigned char) *p] = 1;
222 /* Use more. FIXME-SOMEDAY. */
228 /* set up pseudo-op tables */
230 static struct hash_control *po_hash;
232 static const pseudo_typeS potable[] =
234 {"abort", s_abort, 0},
235 {"align", s_align_ptwo, 0},
236 {"ascii", stringer, 0},
237 {"asciz", stringer, 1},
238 {"balign", s_align_bytes, 0},
242 {"common", s_mri_common, 0},
243 {"common.s", s_mri_common, 1},
247 {"dc.d", float_cons, 'd'},
249 {"dc.s", float_cons, 'f'},
251 {"dc.x", float_cons, 'x'},
253 {"dcb.b", s_space, 1},
254 {"dcb.d", s_float_space, 'd'},
255 {"dcb.l", s_space, 4},
256 {"dcb.s", s_float_space, 'f'},
257 {"dcb.w", s_space, 2},
258 {"dcb.x", s_float_space, 'x'},
260 {"ds.b", s_space, 1},
261 {"ds.d", s_space, 8},
262 {"ds.l", s_space, 4},
263 {"ds.p", s_space, 12},
264 {"ds.s", s_space, 4},
265 {"ds.w", s_space, 2},
266 {"ds.x", s_space, 12},
271 {"double", float_cons, 'd'},
273 {"eject", listing_eject, 0}, /* Formfeed listing */
275 {"elsec", s_else, 0},
277 {"endc", s_endif, 0},
278 {"endif", s_endif, 0},
282 {"exitm", s_mexit, 0},
284 {"extern", s_ignore, 0}, /* We treat all undef as ext */
285 {"appfile", s_app_file, 1},
286 {"appline", s_app_line, 0},
288 {"file", s_app_file, 0},
290 {"float", float_cons, 'f'},
291 {"format", s_ignore, 0},
292 {"global", s_globl, 0},
293 {"globl", s_globl, 0},
295 {"if", s_if, (int) O_ne},
297 {"ifdef", s_ifdef, 0},
298 {"ifeq", s_if, (int) O_eq},
299 {"ifeqs", s_ifeqs, 0},
300 {"ifge", s_if, (int) O_ge},
301 {"ifgt", s_if, (int) O_gt},
302 {"ifle", s_if, (int) O_le},
303 {"iflt", s_if, (int) O_lt},
305 {"ifndef", s_ifdef, 1},
306 {"ifne", s_if, (int) O_ne},
307 {"ifnes", s_ifeqs, 1},
308 {"ifnotdef", s_ifdef, 1},
309 {"include", s_include, 0},
313 {"lcomm", s_lcomm, 0},
314 {"lflags", listing_flags, 0}, /* Listing flags */
315 {"list", listing_list, 1}, /* Turn listing on */
316 {"llen", listing_psize, 1},
319 {"macro", s_macro, 0},
320 {"mexit", s_mexit, 0},
321 {"noformat", s_ignore, 0},
322 {"nolist", listing_list, 0}, /* Turn listing off */
323 {"nopage", listing_nopage, 0},
325 {"offset", s_struct, 0},
327 {"p2align", s_align_ptwo, 0},
328 {"page", listing_eject, 0},
329 {"plen", listing_psize, 0},
330 {"psize", listing_psize, 0}, /* set paper size */
335 {"sbttl", listing_title, 1}, /* Subtitle of listing */
340 {"single", float_cons, 'f'},
342 {"space", s_space, 0},
343 {"spc", s_ignore, 0},
344 {"stabd", s_stab, 'd'},
345 {"stabn", s_stab, 'n'},
346 {"stabs", s_stab, 's'},
347 {"string", stringer, 1},
348 {"struct", s_struct, 0},
352 /* This is for gcc to use. It's only just been added (2/94), so gcc
353 won't be able to use it for a while -- probably a year or more.
354 But once this has been released, check with gcc maintainers
355 before deleting it or even changing the spelling. */
356 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
357 /* If we're folding case -- done for some targets, not necessarily
358 all -- the above string in an input file will be converted to
359 this one. Match it either way... */
360 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
362 {"title", listing_title, 0}, /* Listing title */
363 {"ttl", listing_title, 0},
368 {"xdef", s_globl, 0},
369 {"xref", s_ignore, 0},
370 {"xstabs", s_xstab, 's'},
372 {"zero", s_space, 0},
373 {NULL} /* end sentinel */
376 static int pop_override_ok = 0;
377 static const char *pop_table_name;
381 const pseudo_typeS *table;
384 const pseudo_typeS *pop;
385 for (pop = table; pop->poc_name; pop++)
387 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
388 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
389 as_fatal ("error constructing %s pseudo-op table", pop_table_name);
393 #ifndef md_pop_insert
394 #define md_pop_insert() pop_insert(md_pseudo_table)
397 #ifndef obj_pop_insert
398 #define obj_pop_insert() pop_insert(obj_pseudo_table)
404 po_hash = hash_new ();
406 /* Do the target-specific pseudo ops. */
407 pop_table_name = "md";
410 /* Now object specific. Skip any that were in the target table. */
411 pop_table_name = "obj";
415 /* Now portable ones. Skip any that we've seen already. */
416 pop_table_name = "standard";
417 pop_insert (potable);
420 #define HANDLE_CONDITIONAL_ASSEMBLY() \
421 if (ignore_input ()) \
423 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
424 if (input_line_pointer == buffer_limit) \
430 /* This function is used when scrubbing the characters between #APP
433 static char *scrub_string;
434 static char *scrub_string_end;
437 scrub_from_string (from)
442 *from = scrub_string;
443 size = scrub_string_end - scrub_string;
444 scrub_string = scrub_string_end;
448 /* read_a_source_file()
450 * We read the file, putting things into a web that
451 * represents what we have been reading.
454 read_a_source_file (name)
458 register char *s; /* string of symbol, '\0' appended */
462 buffer = input_scrub_new_file (name);
465 listing_newline ("");
467 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
468 { /* We have another line to parse. */
469 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
470 contin: /* JF this goto is my fault I admit it.
471 Someone brave please re-write the whole
472 input section here? Pleeze??? */
473 while (input_line_pointer < buffer_limit)
475 /* We have more of this buffer to parse. */
478 * We now have input_line_pointer->1st char of next line.
479 * If input_line_pointer [-1] == '\n' then we just
480 * scanned another line: so bump line counters.
482 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
484 #ifdef md_start_line_hook
485 md_start_line_hook ();
488 if (input_line_pointer[-1] == '\n')
489 bump_line_counters ();
494 #ifdef LABELS_WITHOUT_COLONS
499 /* Text at the start of a line must be a label, we
500 run down and stick a colon in. */
501 if (is_name_beginner (*input_line_pointer))
503 char *line_start = input_line_pointer;
506 HANDLE_CONDITIONAL_ASSEMBLY ();
508 c = get_symbol_end ();
510 /* In MRI mode, the EQU pseudoop must be
511 handled specially. */
514 char *rest = input_line_pointer + 1;
518 if (*rest == ' ' || *rest == '\t')
520 if ((strncasecmp (rest, "EQU", 3) == 0
521 || strncasecmp (rest, "SET", 3) == 0)
522 && (rest[3] == ' ' || rest[3] == '\t'))
524 input_line_pointer = rest + 3;
530 line_label = colon (line_start);
532 *input_line_pointer = c;
534 input_line_pointer++;
540 * We are at the begining of a line, or similar place.
541 * We expect a well-formed assembler statement.
542 * A "symbol-name:" is a statement.
544 * Depending on what compiler is used, the order of these tests
545 * may vary to catch most common case 1st.
546 * Each test is independent of all other tests at the (top) level.
547 * PLEASE make a compiler that doesn't use this assembler.
548 * It is crufty to waste a compiler's time encoding things for this
549 * assembler, which then wastes more time decoding it.
550 * (And communicating via (linear) files is silly!
551 * If you must pass stuff, please pass a tree!)
553 if ((c = *input_line_pointer++) == '\t'
558 c = *input_line_pointer++;
560 know (c != ' '); /* No further leading whitespace. */
563 * C is the 1st significant character.
564 * Input_line_pointer points after that character.
566 if (is_name_beginner (c))
568 /* want user-defined label or pseudo/opcode */
569 HANDLE_CONDITIONAL_ASSEMBLY ();
571 s = --input_line_pointer;
572 c = get_symbol_end (); /* name's delimiter */
574 * C is character after symbol.
575 * That character's place in the input line is now '\0'.
576 * S points to the beginning of the symbol.
577 * [In case of pseudo-op, s->'.'.]
578 * Input_line_pointer->'\0' where c was.
580 if (TC_START_LABEL(c, input_line_pointer))
584 char *rest = input_line_pointer + 1;
586 /* In MRI mode, \tsym: set 0 is permitted. */
590 if (*rest == ' ' || *rest == '\t')
592 if ((strncasecmp (rest, "EQU", 3) == 0
593 || strncasecmp (rest, "SET", 3) == 0)
594 && (rest[3] == ' ' || rest[3] == '\t'))
596 input_line_pointer = rest + 3;
602 line_label = colon (s); /* user-defined label */
603 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
604 /* Input_line_pointer->after ':'. */
610 || (input_line_pointer[1] == '='
611 #ifdef TC_EQUAL_IN_INSN
612 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
617 demand_empty_rest_of_line ();
620 { /* expect pseudo-op or machine instruction */
623 #define IGNORE_OPCODE_CASE
624 #ifdef IGNORE_OPCODE_CASE
642 /* The MRI assembler and the m88k use pseudo-ops
644 pop = (pseudo_typeS *) hash_find (po_hash, s);
645 if (pop != NULL && pop->poc_handler == NULL)
650 || (! flag_mri && *s == '.'))
655 * WARNING: c has next char, which may be end-of-line.
656 * We lookup the pseudo-op table with s+1 because we
657 * already know that the pseudo-op begins with a '.'.
661 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
663 /* In MRI mode, we may need to insert an
664 automatic alignment directive. What a hack
666 if (mri_pending_align
668 || ! ((pop->poc_handler == cons
669 && pop->poc_val == 1)
670 || (pop->poc_handler == s_space
671 && pop->poc_val == 1))))
673 do_align (1, (char *) NULL);
674 mri_pending_align = 0;
677 /* Print the error msg now, while we still can */
680 as_bad ("Unknown pseudo-op: `%s'", s);
681 *input_line_pointer = c;
686 /* Put it back for error messages etc. */
687 *input_line_pointer = c;
688 /* The following skip of whitespace is compulsory.
689 A well shaped space is sometimes all that separates
690 keyword from operands. */
691 if (c == ' ' || c == '\t')
692 input_line_pointer++;
694 * Input_line is restored.
695 * Input_line_pointer->1st non-blank char
696 * after pseudo-operation.
698 (*pop->poc_handler) (pop->poc_val);
700 /* If that was .end, just get out now. */
701 if (pop->poc_handler == s_end)
705 { /* machine instruction */
708 if (mri_pending_align)
710 do_align (1, (char *) NULL);
711 mri_pending_align = 0;
714 /* WARNING: c has char, which may be end-of-line. */
715 /* Also: input_line_pointer->`\0` where c was. */
716 *input_line_pointer = c;
717 while (!is_end_of_line[(unsigned char) *input_line_pointer]
719 #ifdef TC_EOL_IN_INSN
720 || TC_EOL_IN_INSN (input_line_pointer)
724 if (flag_mri && *input_line_pointer == '\'')
726 input_line_pointer++;
729 c = *input_line_pointer;
730 *input_line_pointer = '\0';
732 #ifdef OBJ_GENERATE_ASM_LINENO
733 if (generate_asm_lineno == 0)
735 if (ecoff_no_current_file ())
736 generate_asm_lineno = 1;
738 if (generate_asm_lineno == 1)
743 as_where (&s, &lineno);
744 OBJ_GENERATE_ASM_LINENO (s, lineno);
753 if (check_macro (s, &out, '\0', &err))
757 *input_line_pointer++ = c;
758 input_scrub_include_sb (&out,
762 input_scrub_next_buffer (&input_line_pointer);
767 md_assemble (s); /* Assemble 1 instruction. */
769 *input_line_pointer++ = c;
771 /* We resume loop AFTER the end-of-line from
776 } /* if (is_name_beginner(c) */
779 /* Empty statement? */
780 if (is_end_of_line[(unsigned char) c])
783 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
786 /* local label ("4:") */
787 char *backup = input_line_pointer;
789 HANDLE_CONDITIONAL_ASSEMBLY ();
793 while (isdigit (*input_line_pointer))
795 temp = (temp * 10) + *input_line_pointer - '0';
796 ++input_line_pointer;
797 } /* read the whole number */
799 if (LOCAL_LABELS_DOLLAR
800 && *input_line_pointer == '$'
801 && *(input_line_pointer + 1) == ':')
803 input_line_pointer += 2;
805 if (dollar_label_defined (temp))
807 as_fatal ("label \"%d$\" redefined", temp);
810 define_dollar_label (temp);
811 colon (dollar_label_name (temp, 0));
816 && *input_line_pointer++ == ':')
818 fb_label_instance_inc (temp);
819 colon (fb_label_name (temp, 0));
823 input_line_pointer = backup;
824 } /* local label ("4:") */
826 if (c && strchr (line_comment_chars, c))
827 { /* Its a comment. Better say APP or NO_APP */
831 unsigned int new_length;
834 bump_line_counters ();
835 s = input_line_pointer;
836 if (strncmp (s, "APP\n", 4))
837 continue; /* We ignore it */
840 ends = strstr (s, "#NO_APP\n");
844 unsigned int tmp_len;
847 /* The end of the #APP wasn't in this buffer. We
848 keep reading in buffers until we find the #NO_APP
849 that goes with this #APP There is one. The specs
851 tmp_len = buffer_limit - s;
852 tmp_buf = xmalloc (tmp_len + 1);
853 memcpy (tmp_buf, s, tmp_len);
856 new_tmp = input_scrub_next_buffer (&buffer);
860 buffer_limit = new_tmp;
861 input_line_pointer = buffer;
862 ends = strstr (buffer, "#NO_APP\n");
866 num = buffer_limit - buffer;
868 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
869 memcpy (tmp_buf + tmp_len, buffer, num);
874 input_line_pointer = ends ? ends + 8 : NULL;
882 input_line_pointer = ends + 8;
886 scrub_string_end = ends;
888 new_length = ends - s;
889 new_buf = (char *) xmalloc (new_length);
896 space = (new_buf + new_length) - new_tmp;
897 size = do_scrub_chars (scrub_from_string, new_tmp, space);
905 new_buf = xrealloc (new_buf, new_length + 100);
906 new_tmp = new_buf + new_length;
913 old_input = input_line_pointer;
914 old_limit = buffer_limit;
916 input_line_pointer = new_buf;
917 buffer_limit = new_tmp;
921 HANDLE_CONDITIONAL_ASSEMBLY ();
923 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
924 input_line_pointer--; /* Report unknown char as ignored. */
925 ignore_rest_of_line ();
926 } /* while (input_line_pointer<buffer_limit) */
928 #ifdef md_after_pass_hook
929 md_after_pass_hook ();
935 bump_line_counters ();
939 input_line_pointer = old_input;
940 buffer_limit = old_limit;
945 } /* while (more buffers to scan) */
948 input_scrub_close (); /* Close the input file */
955 as_fatal (".abort detected. Abandoning ship.");
958 /* Guts of .align directive. */
965 md_do_align (n, fill, just_record_alignment);
969 /* @@ Fix this right for BFD! */
971 static char nop_opcode = NOP_OPCODE;
973 if (now_seg != data_section && now_seg != bss_section)
982 /* Only make a frag if we HAVE to. . . */
983 if (n && !need_pass_2)
984 frag_align (n, *fill);
987 just_record_alignment:
990 record_alignment (now_seg, n);
993 /* For machines where ".align 4" means align to a 4 byte boundary. */
998 register unsigned int temp;
1001 unsigned long max_alignment = 1 << 15;
1003 if (is_end_of_line[(unsigned char) *input_line_pointer])
1004 temp = arg; /* Default value from pseudo-op table */
1006 temp = get_absolute_expression ();
1008 if (temp > max_alignment)
1010 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1013 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1014 have to convert it. */
1017 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1021 as_bad ("Alignment not a power of 2");
1024 if (*input_line_pointer == ',')
1026 input_line_pointer++;
1027 temp_fill = get_absolute_expression ();
1028 do_align (temp, &temp_fill);
1031 do_align (temp, (char *) 0);
1033 demand_empty_rest_of_line ();
1036 /* For machines where ".align 4" means align to 2**4 boundary. */
1038 s_align_ptwo (ignore)
1043 long max_alignment = 15;
1045 temp = get_absolute_expression ();
1046 if (temp > max_alignment)
1047 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1050 as_bad ("Alignment negative. 0 assumed.");
1053 if (*input_line_pointer == ',')
1055 input_line_pointer++;
1056 temp_fill = get_absolute_expression ();
1057 do_align (temp, &temp_fill);
1060 do_align (temp, (char *) 0);
1062 demand_empty_rest_of_line ();
1069 register char *name;
1073 register symbolS *symbolP;
1075 name = input_line_pointer;
1076 c = get_symbol_end ();
1077 /* just after name is now '\0' */
1078 p = input_line_pointer;
1081 if (*input_line_pointer != ',')
1083 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1084 ignore_rest_of_line ();
1087 input_line_pointer++; /* skip ',' */
1088 if ((temp = get_absolute_expression ()) < 0)
1090 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1091 ignore_rest_of_line ();
1095 symbolP = symbol_find_or_make (name);
1097 if (S_IS_DEFINED (symbolP))
1099 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1100 S_GET_NAME (symbolP));
1101 ignore_rest_of_line ();
1104 if (S_GET_VALUE (symbolP))
1106 if (S_GET_VALUE (symbolP) != (valueT) temp)
1107 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1108 S_GET_NAME (symbolP),
1109 (long) S_GET_VALUE (symbolP),
1114 S_SET_VALUE (symbolP, (valueT) temp);
1115 S_SET_EXTERNAL (symbolP);
1119 extern int flag_one;
1120 if ( (!temp) || !flag_one)
1121 S_GET_OTHER(symbolP) = const_flag;
1123 #endif /* not OBJ_VMS */
1124 know (symbolP->sy_frag == &zero_address_frag);
1125 demand_empty_rest_of_line ();
1128 /* The MRI COMMON pseudo-op. We handle this by creating a common
1129 symbol with the appropriate name. We make s_space do the right
1130 thing by increasing the size. */
1133 s_mri_common (small)
1150 name = input_line_pointer;
1151 if (! isdigit ((unsigned char) *name))
1152 c = get_symbol_end ();
1157 ++input_line_pointer;
1159 while (isdigit ((unsigned char) *input_line_pointer));
1160 c = *input_line_pointer;
1161 *input_line_pointer = '\0';
1163 if (line_label != NULL)
1165 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1166 + (input_line_pointer - name)
1168 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1173 sym = symbol_find_or_make (name);
1174 *input_line_pointer = c;
1178 if (*input_line_pointer != ',')
1182 ++input_line_pointer;
1183 align = get_absolute_expression ();
1186 if (S_IS_DEFINED (sym))
1188 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1189 if (! S_IS_COMMON (sym))
1192 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1193 ignore_rest_of_line ();
1198 S_SET_EXTERNAL (sym);
1199 mri_common_symbol = sym;
1203 S_SET_ALIGN (sym, align);
1206 if (line_label != NULL)
1208 line_label->sy_value.X_op = O_symbol;
1209 line_label->sy_value.X_add_symbol = sym;
1210 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1211 line_label->sy_frag = &zero_address_frag;
1212 S_SET_SEGMENT (line_label, expr_section);
1215 /* FIXME: We just ignore the small argument, which distinguishes
1216 COMMON and COMMON.S. I don't know what we can do about it. */
1218 /* Ignore the type and hptype. */
1219 if (*input_line_pointer == ',')
1220 input_line_pointer += 2;
1221 if (*input_line_pointer == ',')
1222 input_line_pointer += 2;
1223 demand_empty_rest_of_line ();
1233 temp = get_absolute_expression ();
1234 if (flag_readonly_data_in_text)
1236 section = text_section;
1240 section = data_section;
1242 subseg_set (section, (subsegT) temp);
1247 demand_empty_rest_of_line ();
1250 /* Handle the .appfile pseudo-op. This is automatically generated by
1251 do_scrub_chars when a preprocessor # line comment is seen with a
1252 file name. This default definition may be overridden by the object
1253 or CPU specific pseudo-ops. This function is also the default
1254 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1258 s_app_file (appfile)
1264 /* Some assemblers tolerate immediately following '"' */
1265 if ((s = demand_copy_string (&length)) != 0)
1267 /* If this is a fake .appfile, a fake newline was inserted into
1268 the buffer. Passing -2 to new_logical_line tells it to
1270 new_logical_line (s, appfile ? -2 : -1);
1271 demand_empty_rest_of_line ();
1274 listing_source_file (s);
1282 /* Handle the .appline pseudo-op. This is automatically generated by
1283 do_scrub_chars when a preprocessor # line comment is seen. This
1284 default definition may be overridden by the object or CPU specific
1293 /* The given number is that of the next line. */
1294 l = get_absolute_expression () - 1;
1296 /* Some of the back ends can't deal with non-positive line numbers.
1297 Besides, it's silly. */
1298 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1301 new_logical_line ((char *) NULL, l);
1304 listing_source_line (l);
1307 demand_empty_rest_of_line ();
1310 /* Handle the .end pseudo-op. Actually, the real work is done in
1311 read_a_source_file. */
1319 /* The MRI assembler permits the start symbol to follow .end,
1320 but we don't support that. */
1322 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1323 as_warn ("start address not supported");
1327 /* Handle the MRI fail pseudo-op. */
1335 temp = get_absolute_expression ();
1337 as_warn (".fail %ld encountered", (long) temp);
1339 as_bad (".fail %ld encountered", (long) temp);
1340 demand_empty_rest_of_line ();
1347 long temp_repeat = 0;
1349 register long temp_fill = 0;
1353 temp_repeat = get_absolute_expression ();
1354 if (*input_line_pointer == ',')
1356 input_line_pointer++;
1357 temp_size = get_absolute_expression ();
1358 if (*input_line_pointer == ',')
1360 input_line_pointer++;
1361 temp_fill = get_absolute_expression ();
1364 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1365 #define BSD_FILL_SIZE_CROCK_8 (8)
1366 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1368 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1369 temp_size = BSD_FILL_SIZE_CROCK_8;
1373 as_warn ("Size negative: .fill ignored.");
1376 else if (temp_repeat <= 0)
1378 as_warn ("Repeat < 0, .fill ignored");
1382 if (temp_size && !need_pass_2)
1384 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1385 memset (p, 0, (unsigned int) temp_size);
1386 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1387 * flavoured AS. The following bizzare behaviour is to be
1388 * compatible with above. I guess they tried to take up to 8
1389 * bytes from a 4-byte expression and they forgot to sign
1390 * extend. Un*x Sux. */
1391 #define BSD_FILL_SIZE_CROCK_4 (4)
1392 md_number_to_chars (p, (valueT) temp_fill,
1393 (temp_size > BSD_FILL_SIZE_CROCK_4
1394 ? BSD_FILL_SIZE_CROCK_4
1395 : (int) temp_size));
1396 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1397 * but emits no error message because it seems a legal thing to do.
1398 * It is a degenerate case of .fill but could be emitted by a compiler.
1401 demand_empty_rest_of_line ();
1414 name = input_line_pointer;
1415 c = get_symbol_end ();
1416 symbolP = symbol_find_or_make (name);
1417 *input_line_pointer = c;
1419 S_SET_EXTERNAL (symbolP);
1422 input_line_pointer++;
1424 if (*input_line_pointer == '\n')
1429 demand_empty_rest_of_line ();
1432 /* Handle the MRI IRP and IRPC pseudo-ops. */
1444 as_where (&file, &line);
1447 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1448 sb_add_char (&s, *input_line_pointer++);
1452 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1454 as_bad_where (file, line, "%s", err);
1458 input_scrub_include_sb (&out, input_line_pointer);
1460 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1464 s_lcomm (needs_align)
1465 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1466 (alignment); 0 if it was an ".lcomm" (2 args only) */
1469 register char *name;
1473 register symbolS *symbolP;
1474 segT current_seg = now_seg;
1475 subsegT current_subseg = now_subseg;
1476 const int max_alignment = 15;
1478 segT bss_seg = bss_section;
1480 name = input_line_pointer;
1481 c = get_symbol_end ();
1482 p = input_line_pointer;
1486 /* Accept an optional comma after the name. The comma used to be
1487 required, but Irix 5 cc does not generate it. */
1488 if (*input_line_pointer == ',')
1490 ++input_line_pointer;
1494 if (*input_line_pointer == '\n')
1496 as_bad ("Missing size expression");
1500 if ((temp = get_absolute_expression ()) < 0)
1502 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1503 ignore_rest_of_line ();
1507 #if defined (TC_MIPS) || defined (TC_ALPHA)
1508 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1509 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1511 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1512 if (temp <= bfd_get_gp_size (stdoutput))
1514 bss_seg = subseg_new (".sbss", 1);
1515 seg_info (bss_seg)->bss = 1;
1521 /* FIXME. This needs to be machine independent. */
1531 record_alignment(bss_seg, align);
1538 if (*input_line_pointer != ',')
1540 as_bad ("Expected comma after size");
1541 ignore_rest_of_line ();
1544 input_line_pointer++;
1546 if (*input_line_pointer == '\n')
1548 as_bad ("Missing alignment");
1551 align = get_absolute_expression ();
1552 if (align > max_alignment)
1554 align = max_alignment;
1555 as_warn ("Alignment too large: %d. assumed.", align);
1560 as_warn ("Alignment negative. 0 assumed.");
1562 record_alignment (bss_seg, align);
1563 } /* if needs align */
1566 /* Assume some objects may require alignment on some systems. */
1570 align = ffs (temp) - 1;
1571 if (temp % (1 << align))
1578 symbolP = symbol_find_or_make (name);
1582 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1583 S_GET_OTHER (symbolP) == 0 &&
1584 S_GET_DESC (symbolP) == 0 &&
1585 #endif /* OBJ_AOUT or OBJ_BOUT */
1586 (S_GET_SEGMENT (symbolP) == bss_seg
1587 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1591 subseg_set (bss_seg, 1);
1594 frag_align (align, 0);
1595 /* detach from old frag */
1596 if (S_GET_SEGMENT (symbolP) == bss_seg)
1597 symbolP->sy_frag->fr_symbol = NULL;
1599 symbolP->sy_frag = frag_now;
1600 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1604 S_SET_SEGMENT (symbolP, bss_seg);
1607 /* The symbol may already have been created with a preceding
1608 ".globl" directive -- be careful not to step on storage class
1609 in that case. Otherwise, set it to static. */
1610 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1612 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1614 #endif /* OBJ_COFF */
1617 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1618 S_GET_NAME (symbolP));
1620 subseg_set (current_seg, current_subseg);
1622 demand_empty_rest_of_line ();
1629 register char *name;
1633 register symbolS *symbolP;
1635 /* we permit ANY defined expression: BSD4.2 demands constants */
1636 name = input_line_pointer;
1637 c = get_symbol_end ();
1638 p = input_line_pointer;
1641 if (*input_line_pointer != ',')
1644 as_bad ("Expected comma after name \"%s\"", name);
1646 ignore_rest_of_line ();
1649 input_line_pointer++;
1651 if (exp.X_op != O_constant
1652 && exp.X_op != O_register)
1654 as_bad ("bad expression");
1655 ignore_rest_of_line ();
1659 symbolP = symbol_find_or_make (name);
1661 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1662 symbolP->sy_desc == 0) out of this test because coff doesn't have
1663 those fields, and I can't see when they'd ever be tripped. I
1664 don't think I understand why they were here so I may have
1665 introduced a bug. As recently as 1.37 didn't have this test
1666 anyway. xoxorich. */
1668 if (S_GET_SEGMENT (symbolP) == undefined_section
1669 && S_GET_VALUE (symbolP) == 0)
1671 /* The name might be an undefined .global symbol; be sure to
1672 keep the "external" bit. */
1673 S_SET_SEGMENT (symbolP,
1674 (exp.X_op == O_constant
1677 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1681 as_bad ("Symbol %s already defined", name);
1684 demand_empty_rest_of_line ();
1687 /* Read a line into an sb. */
1693 if (input_line_pointer >= buffer_limit)
1695 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1696 if (buffer_limit == 0)
1700 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1701 sb_add_char (line, *input_line_pointer++);
1702 while (is_end_of_line[(unsigned char) *input_line_pointer])
1704 if (*input_line_pointer == '\n')
1706 bump_line_counters ();
1709 ++input_line_pointer;
1714 /* Define a macro. This is an interface to macro.c, which is shared
1715 between gas and gasp. */
1727 as_where (&file, &line);
1730 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1731 sb_add_char (&s, *input_line_pointer++);
1734 if (line_label != NULL)
1735 sb_add_string (&label, S_GET_NAME (line_label));
1737 demand_empty_rest_of_line ();
1739 err = define_macro (0, &s, &label, get_line_sb);
1741 as_bad_where (file, line, "%s", err);
1744 if (line_label != NULL)
1746 S_SET_SEGMENT (line_label, undefined_section);
1747 S_SET_VALUE (line_label, 0);
1748 line_label->sy_frag = &zero_address_frag;
1755 /* Handle the .mexit pseudo-op, which immediately exits a macro
1762 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1765 /* Handle changing the location counter. */
1768 do_org (segment, exp, fill)
1773 if (segment != now_seg && segment != absolute_section)
1774 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1775 segment_name (segment), segment_name (now_seg));
1777 if (now_seg == absolute_section)
1780 as_warn ("ignoring fill value in absolute section");
1781 if (exp->X_op != O_constant)
1783 as_bad ("only constant offsets supported in absolute section");
1784 exp->X_add_number = 0;
1786 abs_section_offset = exp->X_add_number;
1792 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
1793 exp->X_add_number, (char *) NULL);
1802 register segT segment;
1804 register long temp_fill;
1806 /* The MRI assembler has a different meaning for .org. It means to
1807 create an absolute section at a given address. We can't support
1808 that--use a linker script instead. */
1811 as_bad ("MRI style ORG pseudo-op not supported");
1812 ignore_rest_of_line ();
1816 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1817 thing as a sub-segment-relative origin. Any absolute origin is
1818 given a warning, then assumed to be segment-relative. Any
1819 segmented origin expression ("foo+42") had better be in the right
1820 segment or the .org is ignored.
1822 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1823 we never know sub-segment sizes when we are reading code. BSD
1824 will crash trying to emit negative numbers of filler bytes in
1825 certain .orgs. We don't crash, but see as-write for that code.
1827 Don't make frag if need_pass_2==1. */
1828 segment = get_known_segmented_expression (&exp);
1829 if (*input_line_pointer == ',')
1831 input_line_pointer++;
1832 temp_fill = get_absolute_expression ();
1838 do_org (segment, &exp, temp_fill);
1840 demand_empty_rest_of_line ();
1843 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
1844 called by the obj-format routine which handles section changing
1845 when in MRI mode. It will create a new section, and return it. It
1846 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
1847 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
1848 BFD_ASSEMBLER is defined, the flags will be set in the section. */
1860 name = input_line_pointer;
1861 if (! isdigit ((unsigned char) *name))
1862 c = get_symbol_end ();
1867 ++input_line_pointer;
1869 while (isdigit ((unsigned char) *input_line_pointer));
1870 c = *input_line_pointer;
1871 *input_line_pointer = '\0';
1874 name = strdup (name);
1876 as_fatal ("virtual memory exhausted");
1878 *input_line_pointer = c;
1880 seg = subseg_new (name, 0);
1882 if (*input_line_pointer == ',')
1886 ++input_line_pointer;
1887 align = get_absolute_expression ();
1888 record_alignment (seg, align);
1892 if (*input_line_pointer == ',')
1894 c = *++input_line_pointer;
1895 c = toupper ((unsigned char) c);
1896 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
1899 as_bad ("unrecognized section type");
1900 ++input_line_pointer;
1902 #ifdef BFD_ASSEMBLER
1906 flags = SEC_NO_FLAGS;
1909 else if (*type == 'D')
1911 else if (*type == 'R')
1913 if (flags != SEC_NO_FLAGS)
1915 if (! bfd_set_section_flags (stdoutput, seg, flags))
1916 as_warn ("error setting flags for \"%s\": %s",
1917 bfd_section_name (stdoutput, seg),
1918 bfd_errmsg (bfd_get_error ()));
1924 /* Ignore the HP type. */
1925 if (*input_line_pointer == ',')
1926 input_line_pointer += 2;
1928 demand_empty_rest_of_line ();
1931 /* Handle the .rept pseudo-op. */
1941 count = get_absolute_expression ();
1944 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
1946 as_bad ("rept without endr");
1952 sb_add_sb (&many, &one);
1956 input_scrub_include_sb (&many, input_line_pointer);
1958 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1965 register char *name;
1966 register char delim;
1967 register char *end_name;
1968 register symbolS *symbolP;
1971 * Especial apologies for the random logic:
1972 * this just grew, and could be parsed much more simply!
1975 name = input_line_pointer;
1976 delim = get_symbol_end ();
1977 end_name = input_line_pointer;
1981 if (*input_line_pointer != ',')
1984 as_bad ("Expected comma after name \"%s\"", name);
1986 ignore_rest_of_line ();
1990 input_line_pointer++;
1993 if (name[0] == '.' && name[1] == '\0')
1995 /* Turn '. = mumble' into a .org mumble */
1996 register segT segment;
1999 segment = get_known_segmented_expression (&exp);
2002 do_org (segment, &exp, 0);
2008 if ((symbolP = symbol_find (name)) == NULL
2009 && (symbolP = md_undefined_symbol (name)) == NULL)
2011 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2013 /* "set" symbols are local unless otherwise specified. */
2014 SF_SET_LOCAL (symbolP);
2015 #endif /* OBJ_COFF */
2017 } /* make a new symbol */
2019 symbol_table_insert (symbolP);
2022 pseudo_set (symbolP);
2023 demand_empty_rest_of_line ();
2034 #ifdef md_flush_pending_output
2035 md_flush_pending_output ();
2038 /* Just like .fill, but temp_size = 1 */
2040 if (exp.X_op == O_constant)
2044 repeat = exp.X_add_number;
2049 if (! flag_mri || repeat < 0)
2050 as_warn (".space repeat count is %s, ignored",
2051 repeat ? "negative" : "zero");
2052 ignore_rest_of_line ();
2056 /* If we are in the absolute section, just bump the offset. */
2057 if (now_seg == absolute_section)
2059 abs_section_offset += repeat;
2060 demand_empty_rest_of_line ();
2064 /* If we are secretly in an MRI common section, then creating
2065 space just increases the size of the common symbol. */
2066 if (mri_common_symbol != NULL)
2068 S_SET_VALUE (mri_common_symbol,
2069 S_GET_VALUE (mri_common_symbol) + repeat);
2070 demand_empty_rest_of_line ();
2075 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2076 repeat, (char *) 0);
2080 if (now_seg == absolute_section)
2082 as_bad ("space allocation too complex in absolute section");
2083 subseg_set (text_section, 0);
2085 if (mri_common_symbol != NULL)
2087 as_bad ("space allocation too complex in common section");
2088 mri_common_symbol = NULL;
2091 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2092 make_expr_symbol (&exp), 0L, (char *) 0);
2095 if (*input_line_pointer == ',')
2097 input_line_pointer++;
2098 temp_fill = get_absolute_expression ();
2108 demand_empty_rest_of_line ();
2111 /* This is like s_space, but the value is a floating point number with
2112 the given precision. This is for the MRI dcb.s pseudo-op and
2116 s_float_space (float_type)
2121 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2123 count = get_absolute_expression ();
2126 if (*input_line_pointer != ',')
2128 as_bad ("missing value");
2129 ignore_rest_of_line ();
2133 ++input_line_pointer;
2137 /* Skip any 0{letter} that may be present. Don't even check if the
2138 * letter is legal. */
2139 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2140 input_line_pointer += 2;
2142 /* Accept :xxxx, where the x's are hex digits, for a floating point
2143 with the exact digits specified. */
2144 if (input_line_pointer[0] == ':')
2146 flen = hex_float (float_type, temp);
2149 ignore_rest_of_line ();
2157 err = md_atof (float_type, temp, &flen);
2158 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2162 as_bad ("Bad floating literal: %s", err);
2163 ignore_rest_of_line ();
2168 while (--count >= 0)
2172 p = frag_more (flen);
2173 memcpy (p, temp, (unsigned int) flen);
2176 demand_empty_rest_of_line ();
2179 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2185 abs_section_offset = get_absolute_expression ();
2186 subseg_set (absolute_section, 0);
2187 demand_empty_rest_of_line ();
2196 temp = get_absolute_expression ();
2197 subseg_set (text_section, (subsegT) temp);
2198 demand_empty_rest_of_line ();
2200 const_flag &= ~IN_DEFAULT_SECTION;
2206 demand_empty_rest_of_line ()
2209 if (is_end_of_line[(unsigned char) *input_line_pointer])
2211 input_line_pointer++;
2215 ignore_rest_of_line ();
2217 /* Return having already swallowed end-of-line. */
2218 } /* Return pointing just after end-of-line. */
2221 ignore_rest_of_line () /* For suspect lines: gives warning. */
2223 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2225 if (isprint (*input_line_pointer))
2226 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2227 *input_line_pointer);
2229 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2230 *input_line_pointer);
2231 while (input_line_pointer < buffer_limit
2232 && !is_end_of_line[(unsigned char) *input_line_pointer])
2234 input_line_pointer++;
2237 input_line_pointer++; /* Return pointing just after end-of-line. */
2238 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2244 * In: Pointer to a symbol.
2245 * Input_line_pointer->expression.
2247 * Out: Input_line_pointer->just after any whitespace after expression.
2248 * Tried to set symbol to value of expression.
2249 * Will change symbols type, value, and frag;
2252 pseudo_set (symbolP)
2256 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2258 #endif /* OBJ_AOUT or OBJ_BOUT */
2260 know (symbolP); /* NULL pointer is logic error. */
2261 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2262 ext = S_IS_EXTERNAL (symbolP);
2263 #endif /* OBJ_AOUT or OBJ_BOUT */
2265 (void) expression (&exp);
2267 if (exp.X_op == O_illegal)
2268 as_bad ("illegal expression; zero assumed");
2269 else if (exp.X_op == O_absent)
2270 as_bad ("missing expression; zero assumed");
2271 else if (exp.X_op == O_big)
2272 as_bad ("%s number invalid; zero assumed",
2273 exp.X_add_number > 0 ? "bignum" : "floating point");
2274 else if (exp.X_op == O_subtract
2275 && (S_GET_SEGMENT (exp.X_add_symbol)
2276 == S_GET_SEGMENT (exp.X_op_symbol))
2277 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2278 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2280 exp.X_op = O_constant;
2281 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2282 - S_GET_VALUE (exp.X_op_symbol));
2290 exp.X_add_number = 0;
2293 S_SET_SEGMENT (symbolP, absolute_section);
2294 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2296 S_SET_EXTERNAL (symbolP);
2298 S_CLEAR_EXTERNAL (symbolP);
2299 #endif /* OBJ_AOUT or OBJ_BOUT */
2300 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2301 symbolP->sy_frag = &zero_address_frag;
2305 S_SET_SEGMENT (symbolP, reg_section);
2306 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2307 symbolP->sy_frag = &zero_address_frag;
2311 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2312 || exp.X_add_number != 0)
2313 symbolP->sy_value = exp;
2316 symbolS *s = exp.X_add_symbol;
2318 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2319 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2321 S_SET_EXTERNAL (symbolP);
2323 S_CLEAR_EXTERNAL (symbolP);
2324 #endif /* OBJ_AOUT or OBJ_BOUT */
2325 S_SET_VALUE (symbolP,
2326 exp.X_add_number + S_GET_VALUE (s));
2327 symbolP->sy_frag = s->sy_frag;
2328 copy_symbol_attributes (symbolP, s);
2333 /* The value is some complex expression.
2334 FIXME: Should we set the segment to anything? */
2335 symbolP->sy_value = exp;
2343 * CONStruct more frag of .bytes, or .words etc.
2344 * Should need_pass_2 be 1 then emit no frag(s).
2345 * This understands EXPRESSIONS.
2349 * This has a split personality. We use expression() to read the
2350 * value. We can detect if the value won't fit in a byte or word.
2351 * But we can't detect if expression() discarded significant digits
2352 * in the case of a long. Not worth the crocks required to fix it.
2355 /* Select a parser for cons expressions. */
2357 /* Some targets need to parse the expression in various fancy ways.
2358 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2359 (for example, the HPPA does this). Otherwise, you can define
2360 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2361 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2362 are defined, which is the normal case, then only simple expressions
2366 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2368 #ifndef TC_PARSE_CONS_EXPRESSION
2369 #ifdef BITFIELD_CONS_EXPRESSIONS
2370 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2372 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2374 #ifdef REPEAT_CONS_EXPRESSIONS
2375 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2377 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2380 /* If we haven't gotten one yet, just call expression. */
2381 #ifndef TC_PARSE_CONS_EXPRESSION
2382 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2386 /* worker to do .byte etc statements */
2387 /* clobbers input_line_pointer, checks */
2390 cons_worker (nbytes, rva)
2391 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
2398 #ifdef md_flush_pending_output
2399 md_flush_pending_output ();
2402 if (is_it_end_of_statement ())
2404 demand_empty_rest_of_line ();
2408 /* In MRI mode, the operands end at the first unquoted space. */
2414 for (s = input_line_pointer;
2415 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
2420 inquote = ! inquote;
2430 /* If this is an .rva pseudoop then stick
2431 an extra reloc in for this word. */
2433 char *p = frag_more (0);
2434 exp.X_op = O_absent;
2436 #ifdef BFD_ASSEMBLER
2437 reloc = BFD_RELOC_RVA;
2440 reloc = TC_RVA_RELOC;
2445 fix_new_exp (frag_now, p - frag_now->fr_literal,
2446 nbytes, &exp, 0, reloc);
2450 parse_mri_cons (&exp, (unsigned int) nbytes);
2452 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
2453 emit_expr (&exp, (unsigned int) nbytes);
2456 while (*input_line_pointer++ == ','
2457 && (! flag_mri || input_line_pointer < stop));
2459 /* In MRI mode, after an odd number of bytes, we must align to an
2460 even word boundary, unless the next instruction is a dc.b, ds.b
2462 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2463 mri_pending_align = 1;
2465 input_line_pointer--; /* Put terminator back into stream. */
2469 input_line_pointer = stop;
2470 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2471 ++input_line_pointer;
2474 demand_empty_rest_of_line ();
2482 cons_worker (size, 0);
2489 cons_worker (size, 1);
2493 /* Put the contents of expression EXP into the object file using
2494 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2497 emit_expr (exp, nbytes)
2499 unsigned int nbytes;
2503 valueT extra_digit = 0;
2505 /* Don't do anything if we are going to make another pass. */
2511 /* Allow `.word 0' in the absolute section. */
2512 if (now_seg == absolute_section)
2514 if (op != O_constant || exp->X_add_number != 0)
2515 as_bad ("attempt to store value in absolute section");
2516 abs_section_offset += nbytes;
2520 /* Handle a negative bignum. */
2522 && exp->X_add_number == 0
2523 && exp->X_add_symbol->sy_value.X_op == O_big
2524 && exp->X_add_symbol->sy_value.X_add_number > 0)
2527 unsigned long carry;
2529 exp = &exp->X_add_symbol->sy_value;
2531 /* Negate the bignum: one's complement each digit and add 1. */
2533 for (i = 0; i < exp->X_add_number; i++)
2537 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
2540 generic_bignum[i] = next & LITTLENUM_MASK;
2541 carry = next >> LITTLENUM_NUMBER_OF_BITS;
2544 /* We can ignore any carry out, because it will be handled by
2545 extra_digit if it is needed. */
2547 extra_digit = (valueT) -1;
2551 if (op == O_absent || op == O_illegal)
2553 as_warn ("zero assumed for missing expression");
2554 exp->X_add_number = 0;
2557 else if (op == O_big && exp->X_add_number <= 0)
2559 as_bad ("floating point number invalid; zero assumed");
2560 exp->X_add_number = 0;
2563 else if (op == O_register)
2565 as_warn ("register value used as expression");
2569 p = frag_more ((int) nbytes);
2571 #ifndef WORKING_DOT_WORD
2572 /* If we have the difference of two symbols in a word, save it on
2573 the broken_words list. See the code in write.c. */
2574 if (op == O_subtract && nbytes == 2)
2576 struct broken_word *x;
2578 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
2579 x->next_broken_word = broken_words;
2582 x->word_goes_here = p;
2584 x->add = exp->X_add_symbol;
2585 x->sub = exp->X_op_symbol;
2586 x->addnum = exp->X_add_number;
2593 /* If we have an integer, but the number of bytes is too large to
2594 pass to md_number_to_chars, handle it as a bignum. */
2595 if (op == O_constant && nbytes > sizeof (valueT))
2600 if (! exp->X_unsigned && exp->X_add_number < 0)
2601 extra_digit = (valueT) -1;
2602 val = (valueT) exp->X_add_number;
2606 generic_bignum[gencnt] = val & LITTLENUM_MASK;
2607 val >>= LITTLENUM_NUMBER_OF_BITS;
2611 op = exp->X_op = O_big;
2612 exp->X_add_number = gencnt;
2615 if (op == O_constant)
2617 register valueT get;
2618 register valueT use;
2619 register valueT mask;
2620 register valueT unmask;
2622 /* JF << of >= number of bits in the object is undefined. In
2623 particular SPARC (Sun 4) has problems */
2624 if (nbytes >= sizeof (valueT))
2627 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
2629 unmask = ~mask; /* Do store these bits. */
2632 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2633 mask = ~(unmask >> 1); /* Includes sign bit now. */
2636 get = exp->X_add_number;
2638 if ((get & mask) != 0 && (get & mask) != mask)
2639 { /* Leading bits contain both 0s & 1s. */
2640 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
2642 /* put bytes in right order. */
2643 md_number_to_chars (p, use, (int) nbytes);
2645 else if (op == O_big)
2648 LITTLENUM_TYPE *nums;
2650 know (nbytes % CHARS_PER_LITTLENUM == 0);
2652 size = exp->X_add_number * CHARS_PER_LITTLENUM;
2655 as_warn ("Bignum truncated to %d bytes", nbytes);
2659 if (target_big_endian)
2661 while (nbytes > size)
2663 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2664 nbytes -= CHARS_PER_LITTLENUM;
2665 p += CHARS_PER_LITTLENUM;
2668 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
2672 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2673 size -= CHARS_PER_LITTLENUM;
2674 p += CHARS_PER_LITTLENUM;
2679 nums = generic_bignum;
2682 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2684 size -= CHARS_PER_LITTLENUM;
2685 p += CHARS_PER_LITTLENUM;
2686 nbytes -= CHARS_PER_LITTLENUM;
2691 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2692 nbytes -= CHARS_PER_LITTLENUM;
2693 p += CHARS_PER_LITTLENUM;
2699 memset (p, 0, nbytes);
2701 /* Now we need to generate a fixS to record the symbol value.
2702 This is easy for BFD. For other targets it can be more
2703 complex. For very complex cases (currently, the HPPA and
2704 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2705 want. For simpler cases, you can define TC_CONS_RELOC to be
2706 the name of the reloc code that should be stored in the fixS.
2707 If neither is defined, the code uses NO_RELOC if it is
2708 defined, and otherwise uses 0. */
2710 #ifdef BFD_ASSEMBLER
2711 #ifdef TC_CONS_FIX_NEW
2712 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2714 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
2715 /* @@ Should look at CPU word size. */
2716 nbytes == 2 ? BFD_RELOC_16
2717 : nbytes == 8 ? BFD_RELOC_64
2721 #ifdef TC_CONS_FIX_NEW
2722 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2724 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
2725 it is defined, otherwise use NO_RELOC if it is defined,
2727 #ifndef TC_CONS_RELOC
2729 #define TC_CONS_RELOC NO_RELOC
2731 #define TC_CONS_RELOC 0
2734 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
2736 #endif /* TC_CONS_FIX_NEW */
2737 #endif /* BFD_ASSEMBLER */
2741 #ifdef BITFIELD_CONS_EXPRESSIONS
2743 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
2744 w:x,y:z, where w and y are bitwidths and x and y are values. They
2745 then pack them all together. We do a little better in that we allow
2746 them in words, longs, etc. and we'll pack them in target byte order
2749 The rules are: pack least significat bit first, if a field doesn't
2750 entirely fit, put it in the next unit. Overflowing the bitfield is
2751 explicitly *not* even a warning. The bitwidth should be considered
2754 To use this function the tc-XXX.h file should define
2755 BITFIELD_CONS_EXPRESSIONS. */
2758 parse_bitfield_cons (exp, nbytes)
2760 unsigned int nbytes;
2762 unsigned int bits_available = BITS_PER_CHAR * nbytes;
2763 char *hold = input_line_pointer;
2765 (void) expression (exp);
2767 if (*input_line_pointer == ':')
2773 unsigned long width;
2775 if (*input_line_pointer != ':')
2777 input_line_pointer = hold;
2779 } /* next piece is not a bitfield */
2781 /* In the general case, we can't allow
2782 full expressions with symbol
2783 differences and such. The relocation
2784 entries for symbols not defined in this
2785 assembly would require arbitrary field
2786 widths, positions, and masks which most
2787 of our current object formats don't
2790 In the specific case where a symbol
2791 *is* defined in this assembly, we
2792 *could* build fixups and track it, but
2793 this could lead to confusion for the
2794 backends. I'm lazy. I'll take any
2795 SEG_ABSOLUTE. I think that means that
2796 you can use a previous .set or
2797 .equ type symbol. xoxorich. */
2799 if (exp->X_op == O_absent)
2801 as_warn ("using a bit field width of zero");
2802 exp->X_add_number = 0;
2803 exp->X_op = O_constant;
2804 } /* implied zero width bitfield */
2806 if (exp->X_op != O_constant)
2808 *input_line_pointer = '\0';
2809 as_bad ("field width \"%s\" too complex for a bitfield", hold);
2810 *input_line_pointer = ':';
2811 demand_empty_rest_of_line ();
2815 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
2817 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2818 width, nbytes, (BITS_PER_CHAR * nbytes));
2819 width = BITS_PER_CHAR * nbytes;
2822 if (width > bits_available)
2824 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2825 input_line_pointer = hold;
2826 exp->X_add_number = value;
2830 hold = ++input_line_pointer; /* skip ':' */
2832 (void) expression (exp);
2833 if (exp->X_op != O_constant)
2835 char cache = *input_line_pointer;
2837 *input_line_pointer = '\0';
2838 as_bad ("field value \"%s\" too complex for a bitfield", hold);
2839 *input_line_pointer = cache;
2840 demand_empty_rest_of_line ();
2844 value |= ((~(-1 << width) & exp->X_add_number)
2845 << ((BITS_PER_CHAR * nbytes) - bits_available));
2847 if ((bits_available -= width) == 0
2848 || is_it_end_of_statement ()
2849 || *input_line_pointer != ',')
2852 } /* all the bitfields we're gonna get */
2854 hold = ++input_line_pointer;
2855 (void) expression (exp);
2856 } /* forever loop */
2858 exp->X_add_number = value;
2859 exp->X_op = O_constant;
2860 exp->X_unsigned = 1;
2861 } /* if looks like a bitfield */
2862 } /* parse_bitfield_cons() */
2864 #endif /* BITFIELD_CONS_EXPRESSIONS */
2866 /* Handle an MRI style string expression. */
2869 parse_mri_cons (exp, nbytes)
2871 unsigned int nbytes;
2873 if (*input_line_pointer != '\''
2874 && (input_line_pointer[1] != '\''
2875 || (*input_line_pointer != 'A'
2876 && *input_line_pointer != 'E')))
2877 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
2881 unsigned int result = 0;
2883 /* An MRI style string. Cut into as many bytes as will fit into
2884 a nbyte chunk, left justify if necessary, and separate with
2885 commas so we can try again later. */
2886 if (*input_line_pointer == 'A')
2887 ++input_line_pointer;
2888 else if (*input_line_pointer == 'E')
2890 as_bad ("EBCDIC constants are not supported");
2891 ++input_line_pointer;
2894 input_line_pointer++;
2895 for (scan = 0; scan < nbytes; scan++)
2897 if (*input_line_pointer == '\'')
2899 if (input_line_pointer[1] == '\'')
2901 input_line_pointer++;
2906 result = (result << 8) | (*input_line_pointer++);
2910 while (scan < nbytes)
2915 /* Create correct expression */
2916 exp->X_op = O_constant;
2917 exp->X_add_number = result;
2918 /* Fake it so that we can read the next char too */
2919 if (input_line_pointer[0] != '\'' ||
2920 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2922 input_line_pointer -= 2;
2923 input_line_pointer[0] = ',';
2924 input_line_pointer[1] = '\'';
2927 input_line_pointer++;
2931 #ifdef REPEAT_CONS_EXPRESSIONS
2933 /* Parse a repeat expression for cons. This is used by the MIPS
2934 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2935 object file COUNT times.
2937 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2940 parse_repeat_cons (exp, nbytes)
2942 unsigned int nbytes;
2949 if (*input_line_pointer != ':')
2951 /* No repeat count. */
2955 ++input_line_pointer;
2956 expression (&count);
2957 if (count.X_op != O_constant
2958 || count.X_add_number <= 0)
2960 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2964 /* The cons function is going to output this expression once. So we
2965 output it count - 1 times. */
2966 for (i = count.X_add_number - 1; i > 0; i--)
2967 emit_expr (exp, nbytes);
2970 #endif /* REPEAT_CONS_EXPRESSIONS */
2972 /* Parse a floating point number represented as a hex constant. This
2973 permits users to specify the exact bits they want in the floating
2977 hex_float (float_type, bytes)
3011 as_bad ("Unknown floating type type '%c'", float_type);
3015 /* It would be nice if we could go through expression to parse the
3016 hex constant, but if we get a bignum it's a pain to sort it into
3017 the buffer correctly. */
3019 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3023 /* The MRI assembler accepts arbitrary underscores strewn about
3024 through the hex constant, so we ignore them as well. */
3025 if (*input_line_pointer == '_')
3027 ++input_line_pointer;
3033 as_warn ("Floating point constant too large");
3036 d = hex_value (*input_line_pointer) << 4;
3037 ++input_line_pointer;
3038 while (*input_line_pointer == '_')
3039 ++input_line_pointer;
3040 if (hex_p (*input_line_pointer))
3042 d += hex_value (*input_line_pointer);
3043 ++input_line_pointer;
3045 if (target_big_endian)
3048 bytes[length - i - 1] = d;
3054 if (target_big_endian)
3055 memset (bytes + i, 0, length - i);
3057 memset (bytes, 0, length - i);
3066 * CONStruct some more frag chars of .floats .ffloats etc.
3067 * Makes 0 or more new frags.
3068 * If need_pass_2 == 1, no frags are emitted.
3069 * This understands only floating literals, not expressions. Sorry.
3071 * A floating constant is defined by atof_generic(), except it is preceded
3072 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3073 * reading, I decided to be incompatible. This always tries to give you
3074 * rounded bits to the precision of the pseudo-op. Former AS did premature
3075 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3076 * a choice of 2 flavours of noise according to which of 2 floating-point
3077 * scanners you directed AS to use.
3079 * In: input_line_pointer->whitespace before, or '0' of flonum.
3084 float_cons (float_type)
3085 /* Clobbers input_line-pointer, checks end-of-line. */
3086 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3089 int length; /* Number of chars in an object. */
3090 register char *err; /* Error from scanning floating literal. */
3091 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3093 if (is_it_end_of_statement ())
3095 demand_empty_rest_of_line ();
3101 /* input_line_pointer->1st char of a flonum (we hope!). */
3104 /* Skip any 0{letter} that may be present. Don't even check if the
3105 * letter is legal. Someone may invent a "z" format and this routine
3106 * has no use for such information. Lusers beware: you get
3107 * diagnostics if your input is ill-conditioned.
3109 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3110 input_line_pointer += 2;
3112 /* Accept :xxxx, where the x's are hex digits, for a floating
3113 point with the exact digits specified. */
3114 if (input_line_pointer[0] == ':')
3116 ++input_line_pointer;
3117 length = hex_float (float_type, temp);
3120 ignore_rest_of_line ();
3126 err = md_atof (float_type, temp, &length);
3127 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3131 as_bad ("Bad floating literal: %s", err);
3132 ignore_rest_of_line ();
3143 #ifdef REPEAT_CONS_EXPRESSIONS
3144 if (*input_line_pointer == ':')
3146 expressionS count_exp;
3148 ++input_line_pointer;
3149 expression (&count_exp);
3150 if (count_exp.X_op != O_constant
3151 || count_exp.X_add_number <= 0)
3153 as_warn ("unresolvable or nonpositive repeat count; using 1");
3156 count = count_exp.X_add_number;
3160 while (--count >= 0)
3162 p = frag_more (length);
3163 memcpy (p, temp, (unsigned int) length);
3168 while (*input_line_pointer++ == ',');
3170 --input_line_pointer; /* Put terminator back into stream. */
3171 demand_empty_rest_of_line ();
3172 } /* float_cons() */
3177 * We read 0 or more ',' seperated, double-quoted strings.
3179 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3184 stringer (append_zero) /* Worker to do .ascii etc statements. */
3185 /* Checks end-of-line. */
3186 register int append_zero; /* 0: don't append '\0', else 1 */
3188 register unsigned int c;
3190 #ifdef md_flush_pending_output
3191 md_flush_pending_output ();
3195 * The following awkward logic is to parse ZERO or more strings,
3196 * comma seperated. Recall a string expression includes spaces
3197 * before the opening '\"' and spaces after the closing '\"'.
3198 * We fake a leading ',' if there is (supposed to be)
3199 * a 1st, expression. We keep demanding expressions for each
3202 if (is_it_end_of_statement ())
3204 c = 0; /* Skip loop. */
3205 ++input_line_pointer; /* Compensate for end of loop. */
3209 c = ','; /* Do loop. */
3211 while (c == ',' || c == '<' || c == '"')
3214 switch (*input_line_pointer)
3217 ++input_line_pointer; /*->1st char of string. */
3218 while (is_a_char (c = next_char_of_string ()))
3220 FRAG_APPEND_1_CHAR (c);
3224 FRAG_APPEND_1_CHAR (0);
3226 know (input_line_pointer[-1] == '\"');
3229 input_line_pointer++;
3230 c = get_single_number ();
3231 FRAG_APPEND_1_CHAR (c);
3232 if (*input_line_pointer != '>')
3234 as_bad ("Expected <nn>");
3236 input_line_pointer++;
3239 input_line_pointer++;
3243 c = *input_line_pointer;
3246 demand_empty_rest_of_line ();
3249 /* FIXME-SOMEDAY: I had trouble here on characters with the
3250 high bits set. We'll probably also have trouble with
3251 multibyte chars, wide chars, etc. Also be careful about
3252 returning values bigger than 1 byte. xoxorich. */
3255 next_char_of_string ()
3257 register unsigned int c;
3259 c = *input_line_pointer++ & CHAR_MASK;
3266 #ifndef NO_STRING_ESCAPES
3268 switch (c = *input_line_pointer++)
3296 break; /* As itself. */
3312 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3314 number = number * 8 + c - '0';
3318 --input_line_pointer;
3327 c = *input_line_pointer++;
3328 while (isxdigit (c))
3331 number = number * 16 + c - '0';
3332 else if (isupper (c))
3333 number = number * 16 + c - 'A' + 10;
3335 number = number * 16 + c - 'a' + 10;
3336 c = *input_line_pointer++;
3339 --input_line_pointer;
3344 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3345 as_warn ("Unterminated string: Newline inserted.");
3351 #ifdef ONLY_STANDARD_ESCAPES
3352 as_bad ("Bad escaped character in string, '?' assumed");
3354 #endif /* ONLY_STANDARD_ESCAPES */
3357 } /* switch on escaped char */
3359 #endif /* ! defined (NO_STRING_ESCAPES) */
3363 } /* switch on char */
3365 } /* next_char_of_string() */
3368 get_segmented_expression (expP)
3369 register expressionS *expP;
3371 register segT retval;
3373 retval = expression (expP);
3374 if (expP->X_op == O_illegal
3375 || expP->X_op == O_absent
3376 || expP->X_op == O_big)
3378 as_bad ("expected address expression; zero assumed");
3379 expP->X_op = O_constant;
3380 expP->X_add_number = 0;
3381 retval = absolute_section;
3387 get_known_segmented_expression (expP)
3388 register expressionS *expP;
3390 register segT retval;
3392 if ((retval = get_segmented_expression (expP)) == undefined_section)
3394 /* There is no easy way to extract the undefined symbol from the
3396 if (expP->X_add_symbol != NULL
3397 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3398 as_warn ("symbol \"%s\" undefined; zero assumed",
3399 S_GET_NAME (expP->X_add_symbol));
3401 as_warn ("some symbol undefined; zero assumed");
3402 retval = absolute_section;
3403 expP->X_op = O_constant;
3404 expP->X_add_number = 0;
3406 know (retval == absolute_section || SEG_NORMAL (retval));
3408 } /* get_known_segmented_expression() */
3411 get_absolute_expression ()
3416 if (exp.X_op != O_constant)
3418 if (exp.X_op != O_absent)
3419 as_bad ("bad or irreducible absolute expression; zero assumed");
3420 exp.X_add_number = 0;
3422 return exp.X_add_number;
3425 char /* return terminator */
3426 get_absolute_expression_and_terminator (val_pointer)
3427 long *val_pointer; /* return value of expression */
3429 /* FIXME: val_pointer should probably be offsetT *. */
3430 *val_pointer = (long) get_absolute_expression ();
3431 return (*input_line_pointer++);
3435 * demand_copy_C_string()
3437 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3438 * Give a warning if that happens.
3441 demand_copy_C_string (len_pointer)
3446 if ((s = demand_copy_string (len_pointer)) != 0)
3450 for (len = *len_pointer;
3459 as_bad ("This string may not contain \'\\0\'");
3467 * demand_copy_string()
3469 * Demand string, but return a safe (=private) copy of the string.
3470 * Return NULL if we can't read a string here.
3473 demand_copy_string (lenP)
3476 register unsigned int c;
3482 if (*input_line_pointer == '\"')
3484 input_line_pointer++; /* Skip opening quote. */
3486 while (is_a_char (c = next_char_of_string ()))
3488 obstack_1grow (¬es, c);
3491 /* JF this next line is so demand_copy_C_string will return a null
3492 termanated string. */
3493 obstack_1grow (¬es, '\0');
3494 retval = obstack_finish (¬es);
3498 as_warn ("Missing string");
3500 ignore_rest_of_line ();
3504 } /* demand_copy_string() */
3507 * is_it_end_of_statement()
3509 * In: Input_line_pointer->next character.
3511 * Do: Skip input_line_pointer over all whitespace.
3513 * Out: 1 if input_line_pointer->end-of-line.
3516 is_it_end_of_statement ()
3519 return (is_end_of_line[(unsigned char) *input_line_pointer]);
3520 } /* is_it_end_of_statement() */
3526 register symbolS *symbolP; /* symbol we are working with */
3530 input_line_pointer++;
3531 if (*input_line_pointer == '=')
3532 input_line_pointer++;
3534 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
3535 input_line_pointer++;
3537 /* In MRI mode, the operands end at the first unquoted space. */
3543 for (s = input_line_pointer;
3544 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
3549 inquote = ! inquote;
3556 if (sym_name[0] == '.' && sym_name[1] == '\0')
3558 /* Turn '. = mumble' into a .org mumble */
3559 register segT segment;
3562 segment = get_known_segmented_expression (&exp);
3564 do_org (segment, &exp, 0);
3568 symbolP = symbol_find_or_make (sym_name);
3569 pseudo_set (symbolP);
3574 input_line_pointer = stop;
3576 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3577 ++input_line_pointer;
3581 /* .include -- include a file at this point. */
3595 filename = demand_copy_string (&i);
3600 while (! is_end_of_line[(unsigned char) *input_line_pointer]
3601 && *input_line_pointer != ' '
3602 && *input_line_pointer != '\t')
3604 obstack_1grow (¬es, *input_line_pointer);
3605 ++input_line_pointer;
3608 obstack_1grow (¬es, '\0');
3609 filename = obstack_finish (¬es);
3611 demand_empty_rest_of_line ();
3612 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
3613 for (i = 0; i < include_dir_count; i++)
3615 strcpy (path, include_dirs[i]);
3617 strcat (path, filename);
3618 if (0 != (try = fopen (path, "r")))
3627 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3628 newbuf = input_scrub_include_file (path, input_line_pointer);
3629 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3633 add_include_dir (path)
3638 if (include_dir_count == 0)
3640 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
3641 include_dirs[0] = "."; /* Current dir */
3642 include_dir_count = 2;
3646 include_dir_count++;
3647 include_dirs = (char **) realloc (include_dirs,
3648 include_dir_count * sizeof (*include_dirs));
3651 include_dirs[include_dir_count - 1] = path; /* New one */
3654 if (i > include_dir_maxlen)
3655 include_dir_maxlen = i;
3656 } /* add_include_dir() */
3662 while (!is_end_of_line[(unsigned char) *input_line_pointer])
3664 ++input_line_pointer;
3666 ++input_line_pointer;