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. */
45 #include "libiberty.h"
49 #ifndef TC_START_LABEL
50 #define TC_START_LABEL(x,y) (x==':')
53 /* The NOP_OPCODE is for the alignment fill value.
54 * fill it a nop instruction so that the disassembler does not choke
58 #define NOP_OPCODE 0x00
61 char *input_line_pointer
; /*->next char of source file to parse. */
63 int generate_asm_lineno
= 0; /* flag to generate line stab for .s file */
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. */
77 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
82 /* The Delta 68k assembler permits % inside label names. */
86 /* used by is_... macros. our ctype[] */
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
91 0, 0, 0, 0, 3, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
92 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
93 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
94 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
95 0, 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, 0, /* pqrstuvwxyz{|}~. */
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
109 * Out: 1 if this character ends a line.
112 char is_end_of_line
[256] =
115 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
117 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
119 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
121 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
122 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
124 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
125 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
127 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
128 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
129 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
130 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
131 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
132 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
133 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
134 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
135 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
139 /* Functions private to this file. */
141 static char *buffer
; /* 1st char of each buffer of lines is here. */
142 static char *buffer_limit
; /*->1 + last char in buffer. */
144 #ifdef TARGET_BYTES_BIG_ENDIAN
145 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
146 instead of to 0 or 1. */
147 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
148 #undef TARGET_BYTES_BIG_ENDIAN
149 #define TARGET_BYTES_BIG_ENDIAN 1
151 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
153 int target_big_endian
/* = 0 */;
156 static char *old_buffer
; /* JF a hack */
157 static char *old_input
;
158 static char *old_limit
;
160 /* Variables for handling include file directory list. */
162 char **include_dirs
; /* List of pointers to directories to
163 search for .include's */
164 int include_dir_count
; /* How many are in the list */
165 int include_dir_maxlen
= 1;/* Length of longest in list */
167 #ifndef WORKING_DOT_WORD
168 struct broken_word
*broken_words
;
169 int new_broken_words
;
172 /* The current offset into the absolute section. We don't try to
173 build frags in the absolute section, since no data can be stored
174 there. We just keep track of the current offset. */
175 addressT abs_section_offset
;
177 /* If this line had an MRI style label, it is stored in this variable.
178 This is used by some of the MRI pseudo-ops. */
179 symbolS
*mri_line_label
;
181 /* This global variable is used to support MRI common sections. We
182 translate such sections into a common symbol. This variable is
183 non-NULL when we are in an MRI common section. */
184 symbolS
*mri_common_symbol
;
186 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
187 need to align to an even byte boundary unless the next pseudo-op is
188 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
190 static int mri_pending_align
;
192 static void do_align
PARAMS ((int, char *));
193 static int hex_float
PARAMS ((int, char *));
194 static void do_org
PARAMS ((segT
, expressionS
*, int));
195 char *demand_copy_string
PARAMS ((int *lenP
));
196 int is_it_end_of_statement
PARAMS ((void));
197 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
198 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
199 static void pobegin
PARAMS ((void));
208 obj_read_begin_hook ();
210 /* Something close -- but not too close -- to a multiple of 1024.
211 The debugging malloc I'm using has 24 bytes of overhead. */
212 obstack_begin (¬es
, 5090);
213 obstack_begin (&cond_obstack
, 990);
215 /* Use machine dependent syntax */
216 for (p
= line_separator_chars
; *p
; p
++)
217 is_end_of_line
[(unsigned char) *p
] = 1;
218 /* Use more. FIXME-SOMEDAY. */
224 /* set up pseudo-op tables */
226 static struct hash_control
*po_hash
;
228 static const pseudo_typeS potable
[] =
230 {"abort", s_abort
, 0},
231 {"align", s_align_ptwo
, 0},
232 {"ascii", stringer
, 0},
233 {"asciz", stringer
, 1},
234 {"balign", s_align_bytes
, 0},
238 {"common", s_mri_common
, 0},
239 {"common.s", s_mri_common
, 1},
243 {"dc.d", float_cons
, 'd'},
245 {"dc.s", float_cons
, 'f'},
247 {"dc.x", float_cons
, 'x'},
249 {"dcb.b", s_space
, 1},
250 {"dcb.d", s_float_space
, 'd'},
251 {"dcb.l", s_space
, 4},
252 {"dcb.s", s_float_space
, 'f'},
253 {"dcb.w", s_space
, 2},
254 {"dcb.x", s_float_space
, 'x'},
256 {"ds.b", s_space
, 1},
257 {"ds.d", s_space
, 8},
258 {"ds.l", s_space
, 4},
259 {"ds.p", s_space
, 12},
260 {"ds.s", s_space
, 4},
261 {"ds.w", s_space
, 2},
262 {"ds.x", s_space
, 12},
267 {"double", float_cons
, 'd'},
269 {"eject", listing_eject
, 0}, /* Formfeed listing */
271 {"elsec", s_else
, 0},
273 {"endc", s_endif
, 0},
274 {"endif", s_endif
, 0},
279 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
280 {"appfile", s_app_file
, 1},
281 {"appline", s_app_line
, 0},
283 {"file", s_app_file
, 0},
285 {"float", float_cons
, 'f'},
286 {"format", s_ignore
, 0},
287 {"global", s_globl
, 0},
288 {"globl", s_globl
, 0},
290 {"if", s_if
, (int) O_ne
},
291 {"ifdef", s_ifdef
, 0},
292 {"ifeq", s_if
, (int) O_eq
},
293 {"ifeqs", s_ifeqs
, 0},
294 {"ifge", s_if
, (int) O_ge
},
295 {"ifgt", s_if
, (int) O_gt
},
296 {"ifle", s_if
, (int) O_le
},
297 {"iflt", s_if
, (int) O_lt
},
298 {"ifndef", s_ifdef
, 1},
299 {"ifne", s_if
, (int) O_ne
},
300 {"ifnes", s_ifeqs
, 1},
301 {"ifnotdef", s_ifdef
, 1},
302 {"include", s_include
, 0},
304 {"lcomm", s_lcomm
, 0},
305 {"lflags", listing_flags
, 0}, /* Listing flags */
306 {"list", listing_list
, 1}, /* Turn listing on */
307 {"llen", listing_psize
, 1},
310 {"noformat", s_ignore
, 0},
311 {"nolist", listing_list
, 0}, /* Turn listing off */
312 {"nopage", listing_nopage
, 0},
314 {"offset", s_struct
, 0},
316 {"p2align", s_align_ptwo
, 0},
317 {"page", listing_eject
, 0},
318 {"plen", listing_psize
, 0},
319 {"psize", listing_psize
, 0}, /* set paper size */
322 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
327 {"single", float_cons
, 'f'},
329 {"space", s_space
, 0},
330 {"stabd", s_stab
, 'd'},
331 {"stabn", s_stab
, 'n'},
332 {"stabs", s_stab
, 's'},
333 {"string", stringer
, 1},
334 {"struct", s_struct
, 0},
338 /* This is for gcc to use. It's only just been added (2/94), so gcc
339 won't be able to use it for a while -- probably a year or more.
340 But once this has been released, check with gcc maintainers
341 before deleting it or even changing the spelling. */
342 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
343 /* If we're folding case -- done for some targets, not necessarily
344 all -- the above string in an input file will be converted to
345 this one. Match it either way... */
346 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
348 {"title", listing_title
, 0}, /* Listing title */
352 {"xdef", s_globl
, 0},
353 {"xstabs", s_xstab
, 's'},
355 {"zero", s_space
, 0},
356 {NULL
} /* end sentinel */
359 static int pop_override_ok
= 0;
360 static const char *pop_table_name
;
364 const pseudo_typeS
*table
;
367 const pseudo_typeS
*pop
;
368 for (pop
= table
; pop
->poc_name
; pop
++)
370 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
371 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
372 as_fatal ("error constructing %s pseudo-op table", pop_table_name
);
376 #ifndef md_pop_insert
377 #define md_pop_insert() pop_insert(md_pseudo_table)
380 #ifndef obj_pop_insert
381 #define obj_pop_insert() pop_insert(obj_pseudo_table)
387 po_hash
= hash_new ();
389 /* Do the target-specific pseudo ops. */
390 pop_table_name
= "md";
393 /* Now object specific. Skip any that were in the target table. */
394 pop_table_name
= "obj";
398 /* Now portable ones. Skip any that we've seen already. */
399 pop_table_name
= "standard";
400 pop_insert (potable
);
403 #define HANDLE_CONDITIONAL_ASSEMBLY() \
404 if (ignore_input ()) \
406 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
407 if (input_line_pointer == buffer_limit) \
413 /* read_a_source_file()
415 * We read the file, putting things into a web that
416 * represents what we have been reading.
419 read_a_source_file (name
)
423 register char *s
; /* string of symbol, '\0' appended */
427 buffer
= input_scrub_new_file (name
);
430 listing_newline ("");
432 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
433 { /* We have another line to parse. */
434 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
435 contin
: /* JF this goto is my fault I admit it.
436 Someone brave please re-write the whole
437 input section here? Pleeze??? */
438 while (input_line_pointer
< buffer_limit
)
440 /* We have more of this buffer to parse. */
443 * We now have input_line_pointer->1st char of next line.
444 * If input_line_pointer [-1] == '\n' then we just
445 * scanned another line: so bump line counters.
447 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
449 #ifdef md_start_line_hook
450 md_start_line_hook ();
453 if (input_line_pointer
[-1] == '\n')
454 bump_line_counters ();
457 #ifdef LABELS_WITHOUT_COLONS
462 mri_line_label
= NULL
;
464 /* Text at the start of a line must be a label, we
465 run down and stick a colon in. */
466 if (is_name_beginner (*input_line_pointer
))
468 char *line_start
= input_line_pointer
;
469 char c
= get_symbol_end ();
471 if (! ignore_input ())
473 /* In MRI mode, the EQU pseudoop must be
474 handled specially. */
477 if (((strncasecmp (input_line_pointer
+ 1,
479 || (strncasecmp (input_line_pointer
+ 1,
481 && (input_line_pointer
[4] == ' '
482 || input_line_pointer
[4] == '\t'))
484 input_line_pointer
+= 4;
490 mri_line_label
= colon (line_start
);
493 *input_line_pointer
= c
;
495 input_line_pointer
++;
501 * We are at the begining of a line, or similar place.
502 * We expect a well-formed assembler statement.
503 * A "symbol-name:" is a statement.
505 * Depending on what compiler is used, the order of these tests
506 * may vary to catch most common case 1st.
507 * Each test is independent of all other tests at the (top) level.
508 * PLEASE make a compiler that doesn't use this assembler.
509 * It is crufty to waste a compiler's time encoding things for this
510 * assembler, which then wastes more time decoding it.
511 * (And communicating via (linear) files is silly!
512 * If you must pass stuff, please pass a tree!)
514 if ((c
= *input_line_pointer
++) == '\t'
519 c
= *input_line_pointer
++;
521 know (c
!= ' '); /* No further leading whitespace. */
524 * C is the 1st significant character.
525 * Input_line_pointer points after that character.
527 if (is_name_beginner (c
))
529 /* want user-defined label or pseudo/opcode */
530 HANDLE_CONDITIONAL_ASSEMBLY ();
532 s
= --input_line_pointer
;
533 c
= get_symbol_end (); /* name's delimiter */
535 * C is character after symbol.
536 * That character's place in the input line is now '\0'.
537 * S points to the beginning of the symbol.
538 * [In case of pseudo-op, s->'.'.]
539 * Input_line_pointer->'\0' where c was.
541 if (TC_START_LABEL(c
, input_line_pointer
))
543 colon (s
); /* user-defined label */
544 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
545 /* Input_line_pointer->after ':'. */
551 || (input_line_pointer
[1] == '='
552 #ifdef TC_EQUAL_IN_INSN
553 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
558 demand_empty_rest_of_line ();
561 { /* expect pseudo-op or machine instruction */
564 #define IGNORE_OPCODE_CASE
565 #ifdef IGNORE_OPCODE_CASE
583 /* The MRI assembler and the m88k use pseudo-ops
585 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
586 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
590 if (pop
!= NULL
|| *s
== '.')
595 * WARNING: c has next char, which may be end-of-line.
596 * We lookup the pseudo-op table with s+1 because we
597 * already know that the pseudo-op begins with a '.'.
601 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
603 /* In MRI mode, we may need to insert an
604 automatic alignment directive. What a hack
606 if (mri_pending_align
608 || ! ((pop
->poc_handler
== cons
609 && pop
->poc_val
== 1)
610 || (pop
->poc_handler
== s_space
611 && pop
->poc_val
== 1))))
613 do_align (1, (char *) NULL
);
614 mri_pending_align
= 0;
617 /* Print the error msg now, while we still can */
620 as_bad ("Unknown pseudo-op: `%s'", s
);
621 *input_line_pointer
= c
;
626 /* Put it back for error messages etc. */
627 *input_line_pointer
= c
;
628 /* The following skip of whitespace is compulsory.
629 A well shaped space is sometimes all that separates
630 keyword from operands. */
631 if (c
== ' ' || c
== '\t')
632 input_line_pointer
++;
634 * Input_line is restored.
635 * Input_line_pointer->1st non-blank char
636 * after pseudo-operation.
638 (*pop
->poc_handler
) (pop
->poc_val
);
640 /* If that was .end, just get out now. */
641 if (pop
->poc_handler
== s_end
)
645 { /* machine instruction */
646 if (mri_pending_align
)
648 do_align (1, (char *) NULL
);
649 mri_pending_align
= 0;
652 /* WARNING: c has char, which may be end-of-line. */
653 /* Also: input_line_pointer->`\0` where c was. */
654 *input_line_pointer
= c
;
655 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
656 #ifdef TC_EOL_IN_INSN
657 || TC_EOL_IN_INSN (input_line_pointer
)
661 input_line_pointer
++;
664 c
= *input_line_pointer
;
665 *input_line_pointer
= '\0';
667 #ifdef OBJ_GENERATE_ASM_LINENO
668 if (generate_asm_lineno
== 0)
670 if (ecoff_no_current_file ())
671 generate_asm_lineno
= 1;
673 if (generate_asm_lineno
== 1)
678 as_where (&s
, &lineno
);
679 OBJ_GENERATE_ASM_LINENO (s
, lineno
);
683 md_assemble (s
); /* Assemble 1 instruction. */
685 *input_line_pointer
++ = c
;
687 /* We resume loop AFTER the end-of-line from
692 } /* if (is_name_beginner(c) */
695 /* Empty statement? */
696 if (is_end_of_line
[(unsigned char) c
])
699 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
)
702 /* local label ("4:") */
703 char *backup
= input_line_pointer
;
705 HANDLE_CONDITIONAL_ASSEMBLY ();
709 while (isdigit (*input_line_pointer
))
711 temp
= (temp
* 10) + *input_line_pointer
- '0';
712 ++input_line_pointer
;
713 } /* read the whole number */
715 if (LOCAL_LABELS_DOLLAR
716 && *input_line_pointer
== '$'
717 && *(input_line_pointer
+ 1) == ':')
719 input_line_pointer
+= 2;
721 if (dollar_label_defined (temp
))
723 as_fatal ("label \"%d$\" redefined", temp
);
726 define_dollar_label (temp
);
727 colon (dollar_label_name (temp
, 0));
732 && *input_line_pointer
++ == ':')
734 fb_label_instance_inc (temp
);
735 colon (fb_label_name (temp
, 0));
739 input_line_pointer
= backup
;
740 } /* local label ("4:") */
742 if (c
&& strchr (line_comment_chars
, c
))
743 { /* Its a comment. Better say APP or NO_APP */
747 unsigned int new_length
;
749 extern char *scrub_string
, *scrub_last_string
;
751 bump_line_counters ();
752 s
= input_line_pointer
;
753 if (strncmp (s
, "APP\n", 4))
754 continue; /* We ignore it */
757 ends
= strstr (s
, "#NO_APP\n");
761 unsigned int tmp_len
;
764 /* The end of the #APP wasn't in this buffer. We
765 keep reading in buffers until we find the #NO_APP
766 that goes with this #APP There is one. The specs
768 tmp_len
= buffer_limit
- s
;
769 tmp_buf
= xmalloc (tmp_len
+ 1);
770 memcpy (tmp_buf
, s
, tmp_len
);
773 new_tmp
= input_scrub_next_buffer (&buffer
);
777 buffer_limit
= new_tmp
;
778 input_line_pointer
= buffer
;
779 ends
= strstr (buffer
, "#NO_APP\n");
783 num
= buffer_limit
- buffer
;
785 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
786 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
791 input_line_pointer
= ends
? ends
+ 8 : NULL
;
799 input_line_pointer
= ends
+ 8;
801 new_buf
= xmalloc (100);
806 scrub_last_string
= ends
;
811 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
815 if (new_tmp
== new_buf
+ new_length
)
817 new_buf
= xrealloc (new_buf
, new_length
+ 100);
818 new_tmp
= new_buf
+ new_length
;
826 old_input
= input_line_pointer
;
827 old_limit
= buffer_limit
;
829 input_line_pointer
= new_buf
;
830 buffer_limit
= new_tmp
;
834 HANDLE_CONDITIONAL_ASSEMBLY ();
836 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
837 input_line_pointer
--; /* Report unknown char as ignored. */
838 ignore_rest_of_line ();
839 } /* while (input_line_pointer<buffer_limit) */
841 #ifdef md_after_pass_hook
842 md_after_pass_hook ();
847 bump_line_counters ();
851 input_line_pointer
= old_input
;
852 buffer_limit
= old_limit
;
857 } /* while (more buffers to scan) */
860 input_scrub_close (); /* Close the input file */
867 as_fatal (".abort detected. Abandoning ship.");
870 /* Guts of .align directive. */
877 md_do_align (n
, fill
, just_record_alignment
);
881 /* @@ Fix this right for BFD! */
883 static char nop_opcode
= NOP_OPCODE
;
885 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
894 /* Only make a frag if we HAVE to. . . */
895 if (n
&& !need_pass_2
)
896 frag_align (n
, *fill
);
899 just_record_alignment
:
902 record_alignment (now_seg
, n
);
905 /* For machines where ".align 4" means align to a 4 byte boundary. */
910 register unsigned int temp
;
913 unsigned long max_alignment
= 1 << 15;
915 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
916 temp
= arg
; /* Default value from pseudo-op table */
918 temp
= get_absolute_expression ();
920 if (temp
> max_alignment
)
922 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
925 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
926 have to convert it. */
929 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
933 as_bad ("Alignment not a power of 2");
936 if (*input_line_pointer
== ',')
938 input_line_pointer
++;
939 temp_fill
= get_absolute_expression ();
940 do_align (temp
, &temp_fill
);
943 do_align (temp
, (char *) 0);
945 demand_empty_rest_of_line ();
948 /* For machines where ".align 4" means align to 2**4 boundary. */
950 s_align_ptwo (ignore
)
955 long max_alignment
= 15;
957 temp
= get_absolute_expression ();
958 if (temp
> max_alignment
)
959 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
962 as_bad ("Alignment negative. 0 assumed.");
965 if (*input_line_pointer
== ',')
967 input_line_pointer
++;
968 temp_fill
= get_absolute_expression ();
969 do_align (temp
, &temp_fill
);
972 do_align (temp
, (char *) 0);
974 demand_empty_rest_of_line ();
985 register symbolS
*symbolP
;
987 name
= input_line_pointer
;
988 c
= get_symbol_end ();
989 /* just after name is now '\0' */
990 p
= input_line_pointer
;
993 if (*input_line_pointer
!= ',')
995 as_bad ("Expected comma after symbol-name: rest of line ignored.");
996 ignore_rest_of_line ();
999 input_line_pointer
++; /* skip ',' */
1000 if ((temp
= get_absolute_expression ()) < 0)
1002 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
1003 ignore_rest_of_line ();
1007 symbolP
= symbol_find_or_make (name
);
1009 if (S_IS_DEFINED (symbolP
))
1011 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1012 S_GET_NAME (symbolP
));
1013 ignore_rest_of_line ();
1016 if (S_GET_VALUE (symbolP
))
1018 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
1019 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1020 S_GET_NAME (symbolP
),
1021 (long) S_GET_VALUE (symbolP
),
1026 S_SET_VALUE (symbolP
, (valueT
) temp
);
1027 S_SET_EXTERNAL (symbolP
);
1031 extern int flag_one
;
1032 if ( (!temp
) || !flag_one
)
1033 S_GET_OTHER(symbolP
) = const_flag
;
1035 #endif /* not OBJ_VMS */
1036 know (symbolP
->sy_frag
== &zero_address_frag
);
1037 demand_empty_rest_of_line ();
1040 /* The MRI COMMON pseudo-op. We handle this by creating a common
1041 symbol with the appropriate name. We make s_space do the right
1042 thing by increasing the size. */
1045 s_mri_common (small
)
1062 name
= input_line_pointer
;
1063 if (! isdigit ((unsigned char) *name
))
1064 c
= get_symbol_end ();
1069 ++input_line_pointer
;
1071 while (isdigit ((unsigned char) *input_line_pointer
));
1072 c
= *input_line_pointer
;
1073 *input_line_pointer
= '\0';
1075 if (mri_line_label
!= NULL
)
1077 alc
= (char *) xmalloc (strlen (S_GET_NAME (mri_line_label
))
1078 + (input_line_pointer
- name
)
1080 sprintf (alc
, "%s%s", name
, S_GET_NAME (mri_line_label
));
1085 sym
= symbol_find_or_make (name
);
1086 *input_line_pointer
= c
;
1090 if (*input_line_pointer
!= ',')
1094 ++input_line_pointer
;
1095 align
= get_absolute_expression ();
1098 if (S_IS_DEFINED (sym
))
1100 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1101 if (! S_IS_COMMON (sym
))
1104 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym
));
1105 ignore_rest_of_line ();
1110 S_SET_EXTERNAL (sym
);
1111 mri_common_symbol
= sym
;
1115 S_SET_ALIGN (sym
, align
);
1118 if (mri_line_label
!= NULL
)
1120 mri_line_label
->sy_value
.X_op
= O_symbol
;
1121 mri_line_label
->sy_value
.X_add_symbol
= sym
;
1122 mri_line_label
->sy_value
.X_add_number
= S_GET_VALUE (sym
);
1123 mri_line_label
->sy_frag
= &zero_address_frag
;
1124 S_SET_SEGMENT (mri_line_label
, expr_section
);
1127 /* FIXME: We just ignore the small argument, which distinguishes
1128 COMMON and COMMON.S. I don't know what we can do about it. */
1130 /* Ignore the type and hptype. */
1131 if (*input_line_pointer
== ',')
1132 input_line_pointer
+= 2;
1133 if (*input_line_pointer
== ',')
1134 input_line_pointer
+= 2;
1135 demand_empty_rest_of_line ();
1145 temp
= get_absolute_expression ();
1146 if (flag_readonly_data_in_text
)
1148 section
= text_section
;
1152 section
= data_section
;
1154 subseg_set (section
, (subsegT
) temp
);
1159 demand_empty_rest_of_line ();
1162 /* Handle the .appfile pseudo-op. This is automatically generated by
1163 do_scrub_next_char when a preprocessor # line comment is seen with
1164 a file name. This default definition may be overridden by the
1165 object or CPU specific pseudo-ops. This function is also the
1166 default definition for .file; the APPFILE argument is 1 for
1167 .appfile, 0 for .file. */
1170 s_app_file (appfile
)
1176 /* Some assemblers tolerate immediately following '"' */
1177 if ((s
= demand_copy_string (&length
)) != 0)
1179 /* If this is a fake .appfile, a fake newline was inserted into
1180 the buffer. Passing -2 to new_logical_line tells it to
1182 new_logical_line (s
, appfile
? -2 : -1);
1183 demand_empty_rest_of_line ();
1186 listing_source_file (s
);
1194 /* Handle the .appline pseudo-op. This is automatically generated by
1195 do_scrub_next_char when a preprocessor # line comment is seen.
1196 This default definition may be overridden by the object or CPU
1197 specific pseudo-ops. */
1205 /* The given number is that of the next line. */
1206 l
= get_absolute_expression () - 1;
1208 /* Some of the back ends can't deal with non-positive line numbers.
1209 Besides, it's silly. */
1210 as_warn ("Line numbers must be positive; line number %d rejected.", l
+1);
1213 new_logical_line ((char *) NULL
, l
);
1216 listing_source_line (l
);
1219 demand_empty_rest_of_line ();
1222 /* Handle the .end pseudo-op. Actually, the real work is done in
1223 read_a_source_file. */
1231 /* The MRI assembler permits the start symbol to follow .end,
1232 but we don't support that. */
1234 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1235 as_warn ("start address not supported");
1239 /* Handle the MRI fail pseudo-op. */
1247 temp
= get_absolute_expression ();
1249 as_warn (".fail %ld encountered", (long) temp
);
1251 as_bad (".fail %ld encountered", (long) temp
);
1252 demand_empty_rest_of_line ();
1259 long temp_repeat
= 0;
1261 register long temp_fill
= 0;
1265 temp_repeat
= get_absolute_expression ();
1266 if (*input_line_pointer
== ',')
1268 input_line_pointer
++;
1269 temp_size
= get_absolute_expression ();
1270 if (*input_line_pointer
== ',')
1272 input_line_pointer
++;
1273 temp_fill
= get_absolute_expression ();
1276 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1277 #define BSD_FILL_SIZE_CROCK_8 (8)
1278 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
1280 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
1281 temp_size
= BSD_FILL_SIZE_CROCK_8
;
1285 as_warn ("Size negative: .fill ignored.");
1288 else if (temp_repeat
<= 0)
1290 as_warn ("Repeat < 0, .fill ignored");
1294 if (temp_size
&& !need_pass_2
)
1296 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
1297 memset (p
, 0, (unsigned int) temp_size
);
1298 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1299 * flavoured AS. The following bizzare behaviour is to be
1300 * compatible with above. I guess they tried to take up to 8
1301 * bytes from a 4-byte expression and they forgot to sign
1302 * extend. Un*x Sux. */
1303 #define BSD_FILL_SIZE_CROCK_4 (4)
1304 md_number_to_chars (p
, (valueT
) temp_fill
,
1305 (temp_size
> BSD_FILL_SIZE_CROCK_4
1306 ? BSD_FILL_SIZE_CROCK_4
1307 : (int) temp_size
));
1308 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1309 * but emits no error message because it seems a legal thing to do.
1310 * It is a degenerate case of .fill but could be emitted by a compiler.
1313 demand_empty_rest_of_line ();
1326 name
= input_line_pointer
;
1327 c
= get_symbol_end ();
1328 symbolP
= symbol_find_or_make (name
);
1329 *input_line_pointer
= c
;
1331 S_SET_EXTERNAL (symbolP
);
1334 input_line_pointer
++;
1336 if (*input_line_pointer
== '\n')
1341 demand_empty_rest_of_line ();
1345 s_lcomm (needs_align
)
1346 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1347 (alignment); 0 if it was an ".lcomm" (2 args only) */
1350 register char *name
;
1354 register symbolS
*symbolP
;
1355 segT current_seg
= now_seg
;
1356 subsegT current_subseg
= now_subseg
;
1357 const int max_alignment
= 15;
1359 segT bss_seg
= bss_section
;
1361 name
= input_line_pointer
;
1362 c
= get_symbol_end ();
1363 p
= input_line_pointer
;
1367 /* Accept an optional comma after the name. The comma used to be
1368 required, but Irix 5 cc does not generate it. */
1369 if (*input_line_pointer
== ',')
1371 ++input_line_pointer
;
1375 if (*input_line_pointer
== '\n')
1377 as_bad ("Missing size expression");
1381 if ((temp
= get_absolute_expression ()) < 0)
1383 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1384 ignore_rest_of_line ();
1388 #if defined (TC_MIPS) || defined (TC_ALPHA)
1389 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
1390 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1392 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1393 if (temp
<= bfd_get_gp_size (stdoutput
))
1395 bss_seg
= subseg_new (".sbss", 1);
1396 seg_info (bss_seg
)->bss
= 1;
1402 /* FIXME. This needs to be machine independent. */
1412 record_alignment(bss_seg
, align
);
1419 if (*input_line_pointer
!= ',')
1421 as_bad ("Expected comma after size");
1422 ignore_rest_of_line ();
1425 input_line_pointer
++;
1427 if (*input_line_pointer
== '\n')
1429 as_bad ("Missing alignment");
1432 align
= get_absolute_expression ();
1433 if (align
> max_alignment
)
1435 align
= max_alignment
;
1436 as_warn ("Alignment too large: %d. assumed.", align
);
1441 as_warn ("Alignment negative. 0 assumed.");
1443 record_alignment (bss_seg
, align
);
1444 } /* if needs align */
1447 /* Assume some objects may require alignment on some systems. */
1451 align
= ffs (temp
) - 1;
1452 if (temp
% (1 << align
))
1459 symbolP
= symbol_find_or_make (name
);
1463 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1464 S_GET_OTHER (symbolP
) == 0 &&
1465 S_GET_DESC (symbolP
) == 0 &&
1466 #endif /* OBJ_AOUT or OBJ_BOUT */
1467 (S_GET_SEGMENT (symbolP
) == bss_seg
1468 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1472 subseg_set (bss_seg
, 1);
1475 frag_align (align
, 0);
1476 /* detach from old frag */
1477 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1478 symbolP
->sy_frag
->fr_symbol
= NULL
;
1480 symbolP
->sy_frag
= frag_now
;
1481 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1485 S_SET_SEGMENT (symbolP
, bss_seg
);
1488 /* The symbol may already have been created with a preceding
1489 ".globl" directive -- be careful not to step on storage class
1490 in that case. Otherwise, set it to static. */
1491 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1493 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1495 #endif /* OBJ_COFF */
1498 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1499 S_GET_NAME (symbolP
));
1501 subseg_set (current_seg
, current_subseg
);
1503 demand_empty_rest_of_line ();
1510 register char *name
;
1514 register symbolS
*symbolP
;
1516 /* we permit ANY defined expression: BSD4.2 demands constants */
1517 name
= input_line_pointer
;
1518 c
= get_symbol_end ();
1519 p
= input_line_pointer
;
1522 if (*input_line_pointer
!= ',')
1525 as_bad ("Expected comma after name \"%s\"", name
);
1527 ignore_rest_of_line ();
1530 input_line_pointer
++;
1532 if (exp
.X_op
!= O_constant
1533 && exp
.X_op
!= O_register
)
1535 as_bad ("bad expression");
1536 ignore_rest_of_line ();
1540 symbolP
= symbol_find_or_make (name
);
1542 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1543 symbolP->sy_desc == 0) out of this test because coff doesn't have
1544 those fields, and I can't see when they'd ever be tripped. I
1545 don't think I understand why they were here so I may have
1546 introduced a bug. As recently as 1.37 didn't have this test
1547 anyway. xoxorich. */
1549 if (S_GET_SEGMENT (symbolP
) == undefined_section
1550 && S_GET_VALUE (symbolP
) == 0)
1552 /* The name might be an undefined .global symbol; be sure to
1553 keep the "external" bit. */
1554 S_SET_SEGMENT (symbolP
,
1555 (exp
.X_op
== O_constant
1558 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1562 as_bad ("Symbol %s already defined", name
);
1565 demand_empty_rest_of_line ();
1568 /* Handle changing the location counter. */
1571 do_org (segment
, exp
, fill
)
1576 if (segment
!= now_seg
&& segment
!= absolute_section
)
1577 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1578 segment_name (segment
), segment_name (now_seg
));
1580 if (now_seg
== absolute_section
)
1583 as_warn ("ignoring fill value in absolute section");
1584 if (exp
->X_op
!= O_constant
)
1586 as_bad ("only constant offsets supported in absolute section");
1587 exp
->X_add_number
= 0;
1589 abs_section_offset
= exp
->X_add_number
;
1595 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
->X_add_symbol
,
1596 exp
->X_add_number
, (char *) NULL
);
1605 register segT segment
;
1607 register long temp_fill
;
1609 /* The MRI assembler has a different meaning for .org. It means to
1610 create an absolute section at a given address. We can't support
1611 that--use a linker script instead. */
1614 as_bad ("MRI style ORG pseudo-op not supported");
1615 ignore_rest_of_line ();
1619 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1620 thing as a sub-segment-relative origin. Any absolute origin is
1621 given a warning, then assumed to be segment-relative. Any
1622 segmented origin expression ("foo+42") had better be in the right
1623 segment or the .org is ignored.
1625 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1626 we never know sub-segment sizes when we are reading code. BSD
1627 will crash trying to emit negative numbers of filler bytes in
1628 certain .orgs. We don't crash, but see as-write for that code.
1630 Don't make frag if need_pass_2==1. */
1631 segment
= get_known_segmented_expression (&exp
);
1632 if (*input_line_pointer
== ',')
1634 input_line_pointer
++;
1635 temp_fill
= get_absolute_expression ();
1641 do_org (segment
, &exp
, temp_fill
);
1643 demand_empty_rest_of_line ();
1650 register char *name
;
1651 register char delim
;
1652 register char *end_name
;
1653 register symbolS
*symbolP
;
1656 * Especial apologies for the random logic:
1657 * this just grew, and could be parsed much more simply!
1660 name
= input_line_pointer
;
1661 delim
= get_symbol_end ();
1662 end_name
= input_line_pointer
;
1666 if (*input_line_pointer
!= ',')
1669 as_bad ("Expected comma after name \"%s\"", name
);
1671 ignore_rest_of_line ();
1675 input_line_pointer
++;
1678 if (name
[0] == '.' && name
[1] == '\0')
1680 /* Turn '. = mumble' into a .org mumble */
1681 register segT segment
;
1684 segment
= get_known_segmented_expression (&exp
);
1687 do_org (segment
, &exp
, 0);
1693 if ((symbolP
= symbol_find (name
)) == NULL
1694 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1696 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1698 /* "set" symbols are local unless otherwise specified. */
1699 SF_SET_LOCAL (symbolP
);
1700 #endif /* OBJ_COFF */
1702 } /* make a new symbol */
1704 symbol_table_insert (symbolP
);
1707 pseudo_set (symbolP
);
1708 demand_empty_rest_of_line ();
1719 #ifdef md_flush_pending_output
1720 md_flush_pending_output ();
1723 /* Just like .fill, but temp_size = 1 */
1725 if (exp
.X_op
== O_constant
)
1729 repeat
= exp
.X_add_number
;
1734 as_warn (".space repeat count is %s, ignored",
1735 repeat
? "negative" : "zero");
1736 ignore_rest_of_line ();
1740 /* If we are in the absolute section, just bump the offset. */
1741 if (now_seg
== absolute_section
)
1743 abs_section_offset
+= repeat
;
1744 demand_empty_rest_of_line ();
1748 /* If we are secretly in an MRI common section, then creating
1749 space just increases the size of the common symbol. */
1750 if (mri_common_symbol
!= NULL
)
1752 S_SET_VALUE (mri_common_symbol
,
1753 S_GET_VALUE (mri_common_symbol
) + repeat
);
1754 demand_empty_rest_of_line ();
1759 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1760 repeat
, (char *) 0);
1764 if (now_seg
== absolute_section
)
1766 as_bad ("space allocation too complex in absolute section");
1767 subseg_set (text_section
, 0);
1769 if (mri_common_symbol
!= NULL
)
1771 as_bad ("space allocation too complex in common section");
1772 mri_common_symbol
= NULL
;
1775 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
1776 make_expr_symbol (&exp
), 0L, (char *) 0);
1779 if (*input_line_pointer
== ',')
1781 input_line_pointer
++;
1782 temp_fill
= get_absolute_expression ();
1792 demand_empty_rest_of_line ();
1795 /* This is like s_space, but the value is a floating point number with
1796 the given precision. This is for the MRI dcb.s pseudo-op and
1800 s_float_space (float_type
)
1805 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
1807 count
= get_absolute_expression ();
1810 if (*input_line_pointer
!= ',')
1812 as_bad ("missing value");
1813 ignore_rest_of_line ();
1817 ++input_line_pointer
;
1821 /* Skip any 0{letter} that may be present. Don't even check if the
1822 * letter is legal. */
1823 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
1824 input_line_pointer
+= 2;
1826 /* Accept :xxxx, where the x's are hex digits, for a floating point
1827 with the exact digits specified. */
1828 if (input_line_pointer
[0] == ':')
1830 flen
= hex_float (float_type
, temp
);
1833 ignore_rest_of_line ();
1841 err
= md_atof (float_type
, temp
, &flen
);
1842 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
1846 as_bad ("Bad floating literal: %s", err
);
1847 ignore_rest_of_line ();
1852 while (--count
>= 0)
1856 p
= frag_more (flen
);
1857 memcpy (p
, temp
, (unsigned int) flen
);
1860 demand_empty_rest_of_line ();
1863 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
1869 abs_section_offset
= get_absolute_expression ();
1870 subseg_set (absolute_section
, 0);
1871 demand_empty_rest_of_line ();
1880 temp
= get_absolute_expression ();
1881 subseg_set (text_section
, (subsegT
) temp
);
1882 demand_empty_rest_of_line ();
1884 const_flag
&= ~IN_DEFAULT_SECTION
;
1890 demand_empty_rest_of_line ()
1893 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1895 input_line_pointer
++;
1899 ignore_rest_of_line ();
1901 /* Return having already swallowed end-of-line. */
1902 } /* Return pointing just after end-of-line. */
1905 ignore_rest_of_line () /* For suspect lines: gives warning. */
1907 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1909 if (isprint (*input_line_pointer
))
1910 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1911 *input_line_pointer
);
1913 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1914 *input_line_pointer
);
1915 while (input_line_pointer
< buffer_limit
1916 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
1918 input_line_pointer
++;
1921 input_line_pointer
++; /* Return pointing just after end-of-line. */
1922 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
1928 * In: Pointer to a symbol.
1929 * Input_line_pointer->expression.
1931 * Out: Input_line_pointer->just after any whitespace after expression.
1932 * Tried to set symbol to value of expression.
1933 * Will change symbols type, value, and frag;
1936 pseudo_set (symbolP
)
1940 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1942 #endif /* OBJ_AOUT or OBJ_BOUT */
1944 know (symbolP
); /* NULL pointer is logic error. */
1945 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1946 ext
= S_IS_EXTERNAL (symbolP
);
1947 #endif /* OBJ_AOUT or OBJ_BOUT */
1949 (void) expression (&exp
);
1951 if (exp
.X_op
== O_illegal
)
1952 as_bad ("illegal expression; zero assumed");
1953 else if (exp
.X_op
== O_absent
)
1954 as_bad ("missing expression; zero assumed");
1955 else if (exp
.X_op
== O_big
)
1956 as_bad ("%s number invalid; zero assumed",
1957 exp
.X_add_number
> 0 ? "bignum" : "floating point");
1958 else if (exp
.X_op
== O_subtract
1959 && (S_GET_SEGMENT (exp
.X_add_symbol
)
1960 == S_GET_SEGMENT (exp
.X_op_symbol
))
1961 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
1962 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
1964 exp
.X_op
= O_constant
;
1965 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
1966 - S_GET_VALUE (exp
.X_op_symbol
));
1974 exp
.X_add_number
= 0;
1977 S_SET_SEGMENT (symbolP
, absolute_section
);
1978 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1980 S_SET_EXTERNAL (symbolP
);
1982 S_CLEAR_EXTERNAL (symbolP
);
1983 #endif /* OBJ_AOUT or OBJ_BOUT */
1984 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1985 symbolP
->sy_frag
= &zero_address_frag
;
1989 S_SET_SEGMENT (symbolP
, reg_section
);
1990 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1991 symbolP
->sy_frag
= &zero_address_frag
;
1995 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
1996 || exp
.X_add_number
!= 0)
1997 symbolP
->sy_value
= exp
;
2000 symbolS
*s
= exp
.X_add_symbol
;
2002 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
2003 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2005 S_SET_EXTERNAL (symbolP
);
2007 S_CLEAR_EXTERNAL (symbolP
);
2008 #endif /* OBJ_AOUT or OBJ_BOUT */
2009 S_SET_VALUE (symbolP
,
2010 exp
.X_add_number
+ S_GET_VALUE (s
));
2011 symbolP
->sy_frag
= s
->sy_frag
;
2012 copy_symbol_attributes (symbolP
, s
);
2017 /* The value is some complex expression.
2018 FIXME: Should we set the segment to anything? */
2019 symbolP
->sy_value
= exp
;
2027 * CONStruct more frag of .bytes, or .words etc.
2028 * Should need_pass_2 be 1 then emit no frag(s).
2029 * This understands EXPRESSIONS.
2033 * This has a split personality. We use expression() to read the
2034 * value. We can detect if the value won't fit in a byte or word.
2035 * But we can't detect if expression() discarded significant digits
2036 * in the case of a long. Not worth the crocks required to fix it.
2039 /* Select a parser for cons expressions. */
2041 /* Some targets need to parse the expression in various fancy ways.
2042 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2043 (for example, the HPPA does this). Otherwise, you can define
2044 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2045 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2046 are defined, which is the normal case, then only simple expressions
2050 parse_mri_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2052 #ifndef TC_PARSE_CONS_EXPRESSION
2053 #ifdef BITFIELD_CONS_EXPRESSIONS
2054 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2056 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2058 #ifdef REPEAT_CONS_EXPRESSIONS
2059 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2061 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2064 /* If we haven't gotten one yet, just call expression. */
2065 #ifndef TC_PARSE_CONS_EXPRESSION
2066 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2070 /* worker to do .byte etc statements */
2071 /* clobbers input_line_pointer, checks */
2075 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
2080 #ifdef md_flush_pending_output
2081 md_flush_pending_output ();
2084 if (is_it_end_of_statement ())
2086 demand_empty_rest_of_line ();
2094 parse_mri_cons (&exp
, (unsigned int) nbytes
);
2096 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
2097 emit_expr (&exp
, (unsigned int) nbytes
);
2100 while (*input_line_pointer
++ == ',');
2102 /* In MRI mode, after an odd number of bytes, we must align to an
2103 even word boundary, unless the next instruction is a dc.b, ds.b
2105 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
2106 mri_pending_align
= 1;
2108 input_line_pointer
--; /* Put terminator back into stream. */
2109 demand_empty_rest_of_line ();
2112 /* Put the contents of expression EXP into the object file using
2113 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2116 emit_expr (exp
, nbytes
)
2118 unsigned int nbytes
;
2122 valueT extra_digit
= 0;
2124 /* Don't do anything if we are going to make another pass. */
2130 /* Allow `.word 0' in the absolute section. */
2131 if (now_seg
== absolute_section
)
2133 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
2134 as_bad ("attempt to store value in absolute section");
2135 abs_section_offset
+= nbytes
;
2139 /* Handle a negative bignum. */
2141 && exp
->X_add_number
== 0
2142 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
2143 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
2146 unsigned long carry
;
2148 exp
= &exp
->X_add_symbol
->sy_value
;
2150 /* Negate the bignum: one's complement each digit and add 1. */
2152 for (i
= 0; i
< exp
->X_add_number
; i
++)
2156 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
2159 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
2160 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
2163 /* We can ignore any carry out, because it will be handled by
2164 extra_digit if it is needed. */
2166 extra_digit
= (valueT
) -1;
2170 if (op
== O_absent
|| op
== O_illegal
)
2172 as_warn ("zero assumed for missing expression");
2173 exp
->X_add_number
= 0;
2176 else if (op
== O_big
&& exp
->X_add_number
<= 0)
2178 as_bad ("floating point number invalid; zero assumed");
2179 exp
->X_add_number
= 0;
2182 else if (op
== O_register
)
2184 as_warn ("register value used as expression");
2188 p
= frag_more ((int) nbytes
);
2190 #ifndef WORKING_DOT_WORD
2191 /* If we have the difference of two symbols in a word, save it on
2192 the broken_words list. See the code in write.c. */
2193 if (op
== O_subtract
&& nbytes
== 2)
2195 struct broken_word
*x
;
2197 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
2198 x
->next_broken_word
= broken_words
;
2201 x
->word_goes_here
= p
;
2203 x
->add
= exp
->X_add_symbol
;
2204 x
->sub
= exp
->X_op_symbol
;
2205 x
->addnum
= exp
->X_add_number
;
2212 /* If we have an integer, but the number of bytes is too large to
2213 pass to md_number_to_chars, handle it as a bignum. */
2214 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
2219 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
2220 extra_digit
= (valueT
) -1;
2221 val
= (valueT
) exp
->X_add_number
;
2225 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
2226 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2230 op
= exp
->X_op
= O_big
;
2231 exp
->X_add_number
= gencnt
;
2234 if (op
== O_constant
)
2236 register valueT get
;
2237 register valueT use
;
2238 register valueT mask
;
2239 register valueT unmask
;
2241 /* JF << of >= number of bits in the object is undefined. In
2242 particular SPARC (Sun 4) has problems */
2243 if (nbytes
>= sizeof (valueT
))
2246 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
2248 unmask
= ~mask
; /* Do store these bits. */
2251 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2252 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
2255 get
= exp
->X_add_number
;
2257 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
2258 { /* Leading bits contain both 0s & 1s. */
2259 as_warn ("Value 0x%lx truncated to 0x%lx.", get
, use
);
2261 /* put bytes in right order. */
2262 md_number_to_chars (p
, use
, (int) nbytes
);
2264 else if (op
== O_big
)
2267 LITTLENUM_TYPE
*nums
;
2269 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
2271 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
2274 as_warn ("Bignum truncated to %d bytes", nbytes
);
2278 if (target_big_endian
)
2280 while (nbytes
> size
)
2282 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
2283 nbytes
-= CHARS_PER_LITTLENUM
;
2284 p
+= CHARS_PER_LITTLENUM
;
2287 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
2291 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
2292 size
-= CHARS_PER_LITTLENUM
;
2293 p
+= CHARS_PER_LITTLENUM
;
2298 nums
= generic_bignum
;
2301 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
2303 size
-= CHARS_PER_LITTLENUM
;
2304 p
+= CHARS_PER_LITTLENUM
;
2305 nbytes
-= CHARS_PER_LITTLENUM
;
2310 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
2311 nbytes
-= CHARS_PER_LITTLENUM
;
2312 p
+= CHARS_PER_LITTLENUM
;
2318 memset (p
, 0, nbytes
);
2320 /* Now we need to generate a fixS to record the symbol value.
2321 This is easy for BFD. For other targets it can be more
2322 complex. For very complex cases (currently, the HPPA and
2323 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2324 want. For simpler cases, you can define TC_CONS_RELOC to be
2325 the name of the reloc code that should be stored in the fixS.
2326 If neither is defined, the code uses NO_RELOC if it is
2327 defined, and otherwise uses 0. */
2329 #ifdef BFD_ASSEMBLER
2330 #ifdef TC_CONS_FIX_NEW
2331 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
2333 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
2334 /* @@ Should look at CPU word size. */
2335 nbytes
== 2 ? BFD_RELOC_16
2336 : nbytes
== 8 ? BFD_RELOC_64
2340 #ifdef TC_CONS_FIX_NEW
2341 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
2343 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
2344 it is defined, otherwise use NO_RELOC if it is defined,
2346 #ifndef TC_CONS_RELOC
2348 #define TC_CONS_RELOC NO_RELOC
2350 #define TC_CONS_RELOC 0
2353 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
2355 #endif /* TC_CONS_FIX_NEW */
2356 #endif /* BFD_ASSEMBLER */
2360 #ifdef BITFIELD_CONS_EXPRESSIONS
2362 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
2363 w:x,y:z, where w and y are bitwidths and x and y are values. They
2364 then pack them all together. We do a little better in that we allow
2365 them in words, longs, etc. and we'll pack them in target byte order
2368 The rules are: pack least significat bit first, if a field doesn't
2369 entirely fit, put it in the next unit. Overflowing the bitfield is
2370 explicitly *not* even a warning. The bitwidth should be considered
2373 To use this function the tc-XXX.h file should define
2374 BITFIELD_CONS_EXPRESSIONS. */
2377 parse_bitfield_cons (exp
, nbytes
)
2379 unsigned int nbytes
;
2381 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
2382 char *hold
= input_line_pointer
;
2384 (void) expression (exp
);
2386 if (*input_line_pointer
== ':')
2392 unsigned long width
;
2394 if (*input_line_pointer
!= ':')
2396 input_line_pointer
= hold
;
2398 } /* next piece is not a bitfield */
2400 /* In the general case, we can't allow
2401 full expressions with symbol
2402 differences and such. The relocation
2403 entries for symbols not defined in this
2404 assembly would require arbitrary field
2405 widths, positions, and masks which most
2406 of our current object formats don't
2409 In the specific case where a symbol
2410 *is* defined in this assembly, we
2411 *could* build fixups and track it, but
2412 this could lead to confusion for the
2413 backends. I'm lazy. I'll take any
2414 SEG_ABSOLUTE. I think that means that
2415 you can use a previous .set or
2416 .equ type symbol. xoxorich. */
2418 if (exp
->X_op
== O_absent
)
2420 as_warn ("using a bit field width of zero");
2421 exp
->X_add_number
= 0;
2422 exp
->X_op
= O_constant
;
2423 } /* implied zero width bitfield */
2425 if (exp
->X_op
!= O_constant
)
2427 *input_line_pointer
= '\0';
2428 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
2429 *input_line_pointer
= ':';
2430 demand_empty_rest_of_line ();
2434 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
2436 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2437 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
2438 width
= BITS_PER_CHAR
* nbytes
;
2441 if (width
> bits_available
)
2443 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2444 input_line_pointer
= hold
;
2445 exp
->X_add_number
= value
;
2449 hold
= ++input_line_pointer
; /* skip ':' */
2451 (void) expression (exp
);
2452 if (exp
->X_op
!= O_constant
)
2454 char cache
= *input_line_pointer
;
2456 *input_line_pointer
= '\0';
2457 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
2458 *input_line_pointer
= cache
;
2459 demand_empty_rest_of_line ();
2463 value
|= ((~(-1 << width
) & exp
->X_add_number
)
2464 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
2466 if ((bits_available
-= width
) == 0
2467 || is_it_end_of_statement ()
2468 || *input_line_pointer
!= ',')
2471 } /* all the bitfields we're gonna get */
2473 hold
= ++input_line_pointer
;
2474 (void) expression (exp
);
2475 } /* forever loop */
2477 exp
->X_add_number
= value
;
2478 exp
->X_op
= O_constant
;
2479 exp
->X_unsigned
= 1;
2480 } /* if looks like a bitfield */
2481 } /* parse_bitfield_cons() */
2483 #endif /* BITFIELD_CONS_EXPRESSIONS */
2485 /* Handle an MRI style string expression. */
2488 parse_mri_cons (exp
, nbytes
)
2490 unsigned int nbytes
;
2492 if (*input_line_pointer
!= '\''
2493 && (input_line_pointer
[1] != '\''
2494 || (*input_line_pointer
!= 'A'
2495 && *input_line_pointer
!= 'E')))
2496 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
2500 unsigned int result
= 0;
2502 /* An MRI style string. Cut into as many bytes as will fit into
2503 a nbyte chunk, left justify if necessary, and separate with
2504 commas so we can try again later. */
2505 if (*input_line_pointer
== 'A')
2506 ++input_line_pointer
;
2507 else if (*input_line_pointer
== 'E')
2509 as_bad ("EBCDIC constants are not supported");
2510 ++input_line_pointer
;
2513 input_line_pointer
++;
2514 for (scan
= 0; scan
< nbytes
; scan
++)
2516 if (*input_line_pointer
== '\'')
2518 if (input_line_pointer
[1] == '\'')
2520 input_line_pointer
++;
2525 result
= (result
<< 8) | (*input_line_pointer
++);
2529 while (scan
< nbytes
)
2534 /* Create correct expression */
2535 exp
->X_op
= O_constant
;
2536 exp
->X_add_number
= result
;
2537 /* Fake it so that we can read the next char too */
2538 if (input_line_pointer
[0] != '\'' ||
2539 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
2541 input_line_pointer
-= 2;
2542 input_line_pointer
[0] = ',';
2543 input_line_pointer
[1] = '\'';
2546 input_line_pointer
++;
2550 #ifdef REPEAT_CONS_EXPRESSIONS
2552 /* Parse a repeat expression for cons. This is used by the MIPS
2553 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2554 object file COUNT times.
2556 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2559 parse_repeat_cons (exp
, nbytes
)
2561 unsigned int nbytes
;
2568 if (*input_line_pointer
!= ':')
2570 /* No repeat count. */
2574 ++input_line_pointer
;
2575 expression (&count
);
2576 if (count
.X_op
!= O_constant
2577 || count
.X_add_number
<= 0)
2579 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2583 /* The cons function is going to output this expression once. So we
2584 output it count - 1 times. */
2585 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
2586 emit_expr (exp
, nbytes
);
2589 #endif /* REPEAT_CONS_EXPRESSIONS */
2591 /* Parse a floating point number represented as a hex constant. This
2592 permits users to specify the exact bits they want in the floating
2596 hex_float (float_type
, bytes
)
2630 as_bad ("Unknown floating type type '%c'", float_type
);
2634 /* It would be nice if we could go through expression to parse the
2635 hex constant, but if we get a bignum it's a pain to sort it into
2636 the buffer correctly. */
2638 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
2642 /* The MRI assembler accepts arbitrary underscores strewn about
2643 through the hex constant, so we ignore them as well. */
2644 if (*input_line_pointer
== '_')
2646 ++input_line_pointer
;
2652 as_warn ("Floating point constant too large");
2655 d
= hex_value (*input_line_pointer
) << 4;
2656 ++input_line_pointer
;
2657 while (*input_line_pointer
== '_')
2658 ++input_line_pointer
;
2659 if (hex_p (*input_line_pointer
))
2661 d
+= hex_value (*input_line_pointer
);
2662 ++input_line_pointer
;
2664 if (target_big_endian
)
2667 bytes
[length
- i
- 1] = d
;
2673 if (target_big_endian
)
2674 memset (bytes
+ i
, 0, length
- i
);
2676 memset (bytes
, 0, length
- i
);
2685 * CONStruct some more frag chars of .floats .ffloats etc.
2686 * Makes 0 or more new frags.
2687 * If need_pass_2 == 1, no frags are emitted.
2688 * This understands only floating literals, not expressions. Sorry.
2690 * A floating constant is defined by atof_generic(), except it is preceded
2691 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2692 * reading, I decided to be incompatible. This always tries to give you
2693 * rounded bits to the precision of the pseudo-op. Former AS did premature
2694 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2695 * a choice of 2 flavours of noise according to which of 2 floating-point
2696 * scanners you directed AS to use.
2698 * In: input_line_pointer->whitespace before, or '0' of flonum.
2703 float_cons (float_type
)
2704 /* Clobbers input_line-pointer, checks end-of-line. */
2705 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2708 int length
; /* Number of chars in an object. */
2709 register char *err
; /* Error from scanning floating literal. */
2710 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2712 if (is_it_end_of_statement ())
2714 demand_empty_rest_of_line ();
2720 /* input_line_pointer->1st char of a flonum (we hope!). */
2723 /* Skip any 0{letter} that may be present. Don't even check if the
2724 * letter is legal. Someone may invent a "z" format and this routine
2725 * has no use for such information. Lusers beware: you get
2726 * diagnostics if your input is ill-conditioned.
2728 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2729 input_line_pointer
+= 2;
2731 /* Accept :xxxx, where the x's are hex digits, for a floating
2732 point with the exact digits specified. */
2733 if (input_line_pointer
[0] == ':')
2735 ++input_line_pointer
;
2736 length
= hex_float (float_type
, temp
);
2739 ignore_rest_of_line ();
2745 err
= md_atof (float_type
, temp
, &length
);
2746 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2750 as_bad ("Bad floating literal: %s", err
);
2751 ignore_rest_of_line ();
2762 #ifdef REPEAT_CONS_EXPRESSIONS
2763 if (*input_line_pointer
== ':')
2765 expressionS count_exp
;
2767 ++input_line_pointer
;
2768 expression (&count_exp
);
2769 if (count_exp
.X_op
!= O_constant
2770 || count_exp
.X_add_number
<= 0)
2772 as_warn ("unresolvable or nonpositive repeat count; using 1");
2775 count
= count_exp
.X_add_number
;
2779 while (--count
>= 0)
2781 p
= frag_more (length
);
2782 memcpy (p
, temp
, (unsigned int) length
);
2787 while (*input_line_pointer
++ == ',');
2789 --input_line_pointer
; /* Put terminator back into stream. */
2790 demand_empty_rest_of_line ();
2791 } /* float_cons() */
2796 * We read 0 or more ',' seperated, double-quoted strings.
2798 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2803 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2804 /* Checks end-of-line. */
2805 register int append_zero
; /* 0: don't append '\0', else 1 */
2807 register unsigned int c
;
2809 #ifdef md_flush_pending_output
2810 md_flush_pending_output ();
2814 * The following awkward logic is to parse ZERO or more strings,
2815 * comma seperated. Recall a string expression includes spaces
2816 * before the opening '\"' and spaces after the closing '\"'.
2817 * We fake a leading ',' if there is (supposed to be)
2818 * a 1st, expression. We keep demanding expressions for each
2821 if (is_it_end_of_statement ())
2823 c
= 0; /* Skip loop. */
2824 ++input_line_pointer
; /* Compensate for end of loop. */
2828 c
= ','; /* Do loop. */
2830 while (c
== ',' || c
== '<' || c
== '"')
2833 switch (*input_line_pointer
)
2836 ++input_line_pointer
; /*->1st char of string. */
2837 while (is_a_char (c
= next_char_of_string ()))
2839 FRAG_APPEND_1_CHAR (c
);
2843 FRAG_APPEND_1_CHAR (0);
2845 know (input_line_pointer
[-1] == '\"');
2848 input_line_pointer
++;
2849 c
= get_single_number ();
2850 FRAG_APPEND_1_CHAR (c
);
2851 if (*input_line_pointer
!= '>')
2853 as_bad ("Expected <nn>");
2855 input_line_pointer
++;
2858 input_line_pointer
++;
2862 c
= *input_line_pointer
;
2865 demand_empty_rest_of_line ();
2868 /* FIXME-SOMEDAY: I had trouble here on characters with the
2869 high bits set. We'll probably also have trouble with
2870 multibyte chars, wide chars, etc. Also be careful about
2871 returning values bigger than 1 byte. xoxorich. */
2874 next_char_of_string ()
2876 register unsigned int c
;
2878 c
= *input_line_pointer
++ & CHAR_MASK
;
2885 #ifndef NO_STRING_ESCAPES
2887 switch (c
= *input_line_pointer
++)
2915 break; /* As itself. */
2931 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
2933 number
= number
* 8 + c
- '0';
2937 --input_line_pointer
;
2946 c
= *input_line_pointer
++;
2947 while (isxdigit (c
))
2950 number
= number
* 16 + c
- '0';
2951 else if (isupper (c
))
2952 number
= number
* 16 + c
- 'A' + 10;
2954 number
= number
* 16 + c
- 'a' + 10;
2955 c
= *input_line_pointer
++;
2958 --input_line_pointer
;
2963 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2964 as_warn ("Unterminated string: Newline inserted.");
2970 #ifdef ONLY_STANDARD_ESCAPES
2971 as_bad ("Bad escaped character in string, '?' assumed");
2973 #endif /* ONLY_STANDARD_ESCAPES */
2976 } /* switch on escaped char */
2978 #endif /* ! defined (NO_STRING_ESCAPES) */
2982 } /* switch on char */
2984 } /* next_char_of_string() */
2987 get_segmented_expression (expP
)
2988 register expressionS
*expP
;
2990 register segT retval
;
2992 retval
= expression (expP
);
2993 if (expP
->X_op
== O_illegal
2994 || expP
->X_op
== O_absent
2995 || expP
->X_op
== O_big
)
2997 as_bad ("expected address expression; zero assumed");
2998 expP
->X_op
= O_constant
;
2999 expP
->X_add_number
= 0;
3000 retval
= absolute_section
;
3006 get_known_segmented_expression (expP
)
3007 register expressionS
*expP
;
3009 register segT retval
;
3011 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
3013 /* There is no easy way to extract the undefined symbol from the
3015 if (expP
->X_add_symbol
!= NULL
3016 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
3017 as_warn ("symbol \"%s\" undefined; zero assumed",
3018 S_GET_NAME (expP
->X_add_symbol
));
3020 as_warn ("some symbol undefined; zero assumed");
3021 retval
= absolute_section
;
3022 expP
->X_op
= O_constant
;
3023 expP
->X_add_number
= 0;
3025 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
3027 } /* get_known_segmented_expression() */
3030 get_absolute_expression ()
3035 if (exp
.X_op
!= O_constant
)
3037 if (exp
.X_op
!= O_absent
)
3038 as_bad ("bad or irreducible absolute expression; zero assumed");
3039 exp
.X_add_number
= 0;
3041 return exp
.X_add_number
;
3044 char /* return terminator */
3045 get_absolute_expression_and_terminator (val_pointer
)
3046 long *val_pointer
; /* return value of expression */
3048 /* FIXME: val_pointer should probably be offsetT *. */
3049 *val_pointer
= (long) get_absolute_expression ();
3050 return (*input_line_pointer
++);
3054 * demand_copy_C_string()
3056 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3057 * Give a warning if that happens.
3060 demand_copy_C_string (len_pointer
)
3065 if ((s
= demand_copy_string (len_pointer
)) != 0)
3069 for (len
= *len_pointer
;
3078 as_bad ("This string may not contain \'\\0\'");
3086 * demand_copy_string()
3088 * Demand string, but return a safe (=private) copy of the string.
3089 * Return NULL if we can't read a string here.
3092 demand_copy_string (lenP
)
3095 register unsigned int c
;
3101 if (*input_line_pointer
== '\"')
3103 input_line_pointer
++; /* Skip opening quote. */
3105 while (is_a_char (c
= next_char_of_string ()))
3107 obstack_1grow (¬es
, c
);
3110 /* JF this next line is so demand_copy_C_string will return a null
3111 termanated string. */
3112 obstack_1grow (¬es
, '\0');
3113 retval
= obstack_finish (¬es
);
3117 as_warn ("Missing string");
3119 ignore_rest_of_line ();
3123 } /* demand_copy_string() */
3126 * is_it_end_of_statement()
3128 * In: Input_line_pointer->next character.
3130 * Do: Skip input_line_pointer over all whitespace.
3132 * Out: 1 if input_line_pointer->end-of-line.
3135 is_it_end_of_statement ()
3138 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
3139 } /* is_it_end_of_statement() */
3145 register symbolS
*symbolP
; /* symbol we are working with */
3147 input_line_pointer
++;
3148 if (*input_line_pointer
== '=')
3149 input_line_pointer
++;
3151 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
3152 input_line_pointer
++;
3154 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
3156 /* Turn '. = mumble' into a .org mumble */
3157 register segT segment
;
3160 segment
= get_known_segmented_expression (&exp
);
3162 do_org (segment
, &exp
, 0);
3166 symbolP
= symbol_find_or_make (sym_name
);
3167 pseudo_set (symbolP
);
3171 /* .include -- include a file at this point. */
3184 filename
= demand_copy_string (&i
);
3185 demand_empty_rest_of_line ();
3186 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
3187 for (i
= 0; i
< include_dir_count
; i
++)
3189 strcpy (path
, include_dirs
[i
]);
3191 strcat (path
, filename
);
3192 if (0 != (try = fopen (path
, "r")))
3201 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3202 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
3203 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3207 add_include_dir (path
)
3212 if (include_dir_count
== 0)
3214 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
3215 include_dirs
[0] = "."; /* Current dir */
3216 include_dir_count
= 2;
3220 include_dir_count
++;
3221 include_dirs
= (char **) realloc (include_dirs
,
3222 include_dir_count
* sizeof (*include_dirs
));
3225 include_dirs
[include_dir_count
- 1] = path
; /* New one */
3228 if (i
> include_dir_maxlen
)
3229 include_dir_maxlen
= i
;
3230 } /* add_include_dir() */
3236 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
3238 ++input_line_pointer
;
3240 ++input_line_pointer
;