Add macro handling extensions and line substitution support.
[binutils.git] / gas / read.c
blob15228426af143f713174b9bb69d4255ab880c86f
1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
3 2000 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)
10 any later version.
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #if 0
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
28 #else
29 #define MASK_CHAR ((int)(unsigned char)-1)
30 #endif
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
41 /* for isdigit() */
42 #include <ctype.h>
44 #include "as.h"
45 #include "subsegs.h"
46 #include "sb.h"
47 #include "macro.h"
48 #include "obstack.h"
49 #include "listing.h"
50 #include "ecoff.h"
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
54 #endif
56 /* Set by the object-format or the target. */
57 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
58 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
59 do { \
60 if ((SIZE) >= 8) \
61 (P2VAR) = 3; \
62 else if ((SIZE) >= 4) \
63 (P2VAR) = 2; \
64 else if ((SIZE) >= 2) \
65 (P2VAR) = 1; \
66 else \
67 (P2VAR) = 0; \
68 } while (0)
69 #endif
71 /* The NOP_OPCODE is for the alignment fill value.
72 * fill it a nop instruction so that the disassembler does not choke
73 * on it
75 #ifndef NOP_OPCODE
76 #define NOP_OPCODE 0x00
77 #endif
79 char *input_line_pointer; /*->next char of source file to parse. */
81 #if BITS_PER_CHAR != 8
82 /* The following table is indexed by[(char)] and will break if
83 a char does not have exactly 256 states (hopefully 0:255!)! */
84 die horribly;
85 #endif
87 #ifndef LEX_AT
88 /* The m88k unfortunately uses @ as a label beginner. */
89 #define LEX_AT 0
90 #endif
92 #ifndef LEX_BR
93 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
94 #define LEX_BR 0
95 #endif
97 #ifndef LEX_PCT
98 /* The Delta 68k assembler permits % inside label names. */
99 #define LEX_PCT 0
100 #endif
102 #ifndef LEX_QM
103 /* The PowerPC Windows NT assemblers permits ? inside label names. */
104 #define LEX_QM 0
105 #endif
107 #ifndef LEX_HASH
108 #define LEX_HASH 0
109 #endif
111 #ifndef LEX_DOLLAR
112 /* The a29k assembler does not permits labels to start with $. */
113 #define LEX_DOLLAR 3
114 #endif
116 #ifndef LEX_TILDE
117 /* The Delta 68k assembler permits ~ at start of label names. */
118 #define LEX_TILDE 0
119 #endif
121 /* used by is_... macros. our ctype[] */
122 char lex_type[256] =
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
126 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
127 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
128 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
129 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
130 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
131 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
132 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
133 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
134 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
135 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
136 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
137 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
138 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
139 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
144 * In: a character.
145 * Out: 1 if this character ends a line.
147 #define Z_ (0)
148 char is_end_of_line[256] =
150 #ifdef CR_EOL
151 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_, /* @abcdefghijklmno */
152 #else
153 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_, /* @abcdefghijklmno */
154 #endif
155 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
156 #ifdef TC_HPPA
157 Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* _!"#$%&'()*+,-./ */
158 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
159 #else
160 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
161 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
162 #endif
163 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
164 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
165 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
166 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
167 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
168 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
169 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
170 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
171 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
173 #undef Z_
175 /* Functions private to this file. */
177 static char *buffer; /* 1st char of each buffer of lines is here. */
178 static char *buffer_limit; /*->1 + last char in buffer. */
180 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
181 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
182 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
184 static char *old_buffer; /* JF a hack */
185 static char *old_input;
186 static char *old_limit;
188 /* Variables for handling include file directory table. */
190 char **include_dirs; /* Table of pointers to directories to
191 search for .include's */
192 int include_dir_count; /* How many are in the table */
193 int include_dir_maxlen = 1;/* Length of longest in table */
195 #ifndef WORKING_DOT_WORD
196 struct broken_word *broken_words;
197 int new_broken_words;
198 #endif
200 /* The current offset into the absolute section. We don't try to
201 build frags in the absolute section, since no data can be stored
202 there. We just keep track of the current offset. */
203 addressT abs_section_offset;
205 /* If this line had an MRI style label, it is stored in this variable.
206 This is used by some of the MRI pseudo-ops. */
207 symbolS *line_label;
209 /* This global variable is used to support MRI common sections. We
210 translate such sections into a common symbol. This variable is
211 non-NULL when we are in an MRI common section. */
212 symbolS *mri_common_symbol;
214 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
215 need to align to an even byte boundary unless the next pseudo-op is
216 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
217 may be needed. */
218 static int mri_pending_align;
220 #ifndef NO_LISTING
221 #ifdef OBJ_ELF
222 /* This variable is set to be non-zero if the next string we see might
223 be the name of the source file in DWARF debugging information. See
224 the comment in emit_expr for the format we look for. */
225 static int dwarf_file_string;
226 #endif
227 #endif
229 static void cons_worker PARAMS ((int, int));
230 static int scrub_from_string PARAMS ((char *, int));
231 static void do_align PARAMS ((int, char *, int, int));
232 static void s_align PARAMS ((int, int));
233 static void s_lcomm_internal PARAMS ((int, int));
234 static int hex_float PARAMS ((int, char *));
235 static inline int sizeof_sleb128 PARAMS ((offsetT));
236 static inline int sizeof_uleb128 PARAMS ((valueT));
237 static inline int output_sleb128 PARAMS ((char *, offsetT));
238 static inline int output_uleb128 PARAMS ((char *, valueT));
239 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
240 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
241 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
242 static void do_org PARAMS ((segT, expressionS *, int));
243 char *demand_copy_string PARAMS ((int *lenP));
244 static segT get_segmented_expression PARAMS ((expressionS *expP));
245 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
246 static void pobegin PARAMS ((void));
247 static int get_line_sb PARAMS ((sb *));
248 static void generate_file_debug PARAMS ((void));
251 void
252 read_begin ()
254 const char *p;
256 pobegin ();
257 obj_read_begin_hook ();
259 /* Something close -- but not too close -- to a multiple of 1024.
260 The debugging malloc I'm using has 24 bytes of overhead. */
261 obstack_begin (&notes, chunksize);
262 obstack_begin (&cond_obstack, chunksize);
264 /* Use machine dependent syntax */
265 for (p = line_separator_chars; *p; p++)
266 is_end_of_line[(unsigned char) *p] = 1;
267 /* Use more. FIXME-SOMEDAY. */
269 if (flag_mri)
270 lex_type['?'] = 3;
273 /* set up pseudo-op tables */
275 static struct hash_control *po_hash;
277 static const pseudo_typeS potable[] =
279 {"abort", s_abort, 0},
280 {"align", s_align_ptwo, 0},
281 {"ascii", stringer, 0},
282 {"asciz", stringer, 1},
283 {"balign", s_align_bytes, 0},
284 {"balignw", s_align_bytes, -2},
285 {"balignl", s_align_bytes, -4},
286 /* block */
287 {"byte", cons, 1},
288 {"comm", s_comm, 0},
289 {"common", s_mri_common, 0},
290 {"common.s", s_mri_common, 1},
291 {"data", s_data, 0},
292 {"dc", cons, 2},
293 {"dc.b", cons, 1},
294 {"dc.d", float_cons, 'd'},
295 {"dc.l", cons, 4},
296 {"dc.s", float_cons, 'f'},
297 {"dc.w", cons, 2},
298 {"dc.x", float_cons, 'x'},
299 {"dcb", s_space, 2},
300 {"dcb.b", s_space, 1},
301 {"dcb.d", s_float_space, 'd'},
302 {"dcb.l", s_space, 4},
303 {"dcb.s", s_float_space, 'f'},
304 {"dcb.w", s_space, 2},
305 {"dcb.x", s_float_space, 'x'},
306 {"ds", s_space, 2},
307 {"ds.b", s_space, 1},
308 {"ds.d", s_space, 8},
309 {"ds.l", s_space, 4},
310 {"ds.p", s_space, 12},
311 {"ds.s", s_space, 4},
312 {"ds.w", s_space, 2},
313 {"ds.x", s_space, 12},
314 {"debug", s_ignore, 0},
315 #ifdef S_SET_DESC
316 {"desc", s_desc, 0},
317 #endif
318 /* dim */
319 {"double", float_cons, 'd'},
320 /* dsect */
321 {"eject", listing_eject, 0}, /* Formfeed listing */
322 {"else", s_else, 0},
323 {"elsec", s_else, 0},
324 {"elseif", s_elseif, (int) O_ne},
325 {"end", s_end, 0},
326 {"endc", s_endif, 0},
327 {"endfunc", s_func, 1},
328 {"endif", s_endif, 0},
329 /* endef */
330 {"equ", s_set, 0},
331 {"equiv", s_set, 1},
332 {"err", s_err, 0},
333 {"exitm", s_mexit, 0},
334 /* extend */
335 {"extern", s_ignore, 0}, /* We treat all undef as ext */
336 {"appfile", s_app_file, 1},
337 {"appline", s_app_line, 0},
338 {"fail", s_fail, 0},
339 {"file", s_app_file, 0},
340 {"fill", s_fill, 0},
341 {"float", float_cons, 'f'},
342 {"format", s_ignore, 0},
343 {"func", s_func, 0},
344 {"global", s_globl, 0},
345 {"globl", s_globl, 0},
346 {"hword", cons, 2},
347 {"if", s_if, (int) O_ne},
348 {"ifc", s_ifc, 0},
349 {"ifdef", s_ifdef, 0},
350 {"ifeq", s_if, (int) O_eq},
351 {"ifeqs", s_ifeqs, 0},
352 {"ifge", s_if, (int) O_ge},
353 {"ifgt", s_if, (int) O_gt},
354 {"ifle", s_if, (int) O_le},
355 {"iflt", s_if, (int) O_lt},
356 {"ifnc", s_ifc, 1},
357 {"ifndef", s_ifdef, 1},
358 {"ifne", s_if, (int) O_ne},
359 {"ifnes", s_ifeqs, 1},
360 {"ifnotdef", s_ifdef, 1},
361 {"include", s_include, 0},
362 {"int", cons, 4},
363 {"irp", s_irp, 0},
364 {"irep", s_irp, 0},
365 {"irpc", s_irp, 1},
366 {"irepc", s_irp, 1},
367 {"lcomm", s_lcomm, 0},
368 {"lflags", listing_flags, 0}, /* Listing flags */
369 {"linkonce", s_linkonce, 0},
370 {"list", listing_list, 1}, /* Turn listing on */
371 {"llen", listing_psize, 1},
372 {"long", cons, 4},
373 {"lsym", s_lsym, 0},
374 {"macro", s_macro, 0},
375 {"mexit", s_mexit, 0},
376 {"mri", s_mri, 0},
377 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
378 {"name", s_ignore, 0},
379 {"noformat", s_ignore, 0},
380 {"nolist", listing_list, 0}, /* Turn listing off */
381 {"nopage", listing_nopage, 0},
382 {"octa", cons, 16},
383 {"offset", s_struct, 0},
384 {"org", s_org, 0},
385 {"p2align", s_align_ptwo, 0},
386 {"p2alignw", s_align_ptwo, -2},
387 {"p2alignl", s_align_ptwo, -4},
388 {"page", listing_eject, 0},
389 {"plen", listing_psize, 0},
390 {"print", s_print, 0},
391 {"psize", listing_psize, 0}, /* set paper size */
392 {"purgem", s_purgem, 0},
393 {"quad", cons, 8},
394 {"rep", s_rept, 0},
395 {"rept", s_rept, 0},
396 {"rva", s_rva, 4},
397 {"sbttl", listing_title, 1}, /* Subtitle of listing */
398 /* scl */
399 /* sect */
400 {"set", s_set, 0},
401 {"short", cons, 2},
402 {"single", float_cons, 'f'},
403 /* size */
404 {"space", s_space, 0},
405 {"skip", s_space, 0},
406 {"sleb128", s_leb128, 1},
407 {"spc", s_ignore, 0},
408 {"stabd", s_stab, 'd'},
409 {"stabn", s_stab, 'n'},
410 {"stabs", s_stab, 's'},
411 {"string", stringer, 1},
412 {"struct", s_struct, 0},
413 /* tag */
414 {"text", s_text, 0},
416 /* This is for gcc to use. It's only just been added (2/94), so gcc
417 won't be able to use it for a while -- probably a year or more.
418 But once this has been released, check with gcc maintainers
419 before deleting it or even changing the spelling. */
420 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
421 /* If we're folding case -- done for some targets, not necessarily
422 all -- the above string in an input file will be converted to
423 this one. Match it either way... */
424 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
426 {"title", listing_title, 0}, /* Listing title */
427 {"ttl", listing_title, 0},
428 /* type */
429 {"uleb128", s_leb128, 0},
430 /* use */
431 /* val */
432 {"xcom", s_comm, 0},
433 {"xdef", s_globl, 0},
434 {"xref", s_ignore, 0},
435 {"xstabs", s_xstab, 's'},
436 {"word", cons, 2},
437 {"zero", s_space, 0},
438 {NULL, NULL, 0} /* end sentinel */
441 static int pop_override_ok = 0;
442 static const char *pop_table_name;
444 void
445 pop_insert (table)
446 const pseudo_typeS *table;
448 const char *errtxt;
449 const pseudo_typeS *pop;
450 for (pop = table; pop->poc_name; pop++)
452 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
453 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
454 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
455 errtxt);
459 #ifndef md_pop_insert
460 #define md_pop_insert() pop_insert(md_pseudo_table)
461 #endif
463 #ifndef obj_pop_insert
464 #define obj_pop_insert() pop_insert(obj_pseudo_table)
465 #endif
467 static void
468 pobegin ()
470 po_hash = hash_new ();
472 /* Do the target-specific pseudo ops. */
473 pop_table_name = "md";
474 md_pop_insert ();
476 /* Now object specific. Skip any that were in the target table. */
477 pop_table_name = "obj";
478 pop_override_ok = 1;
479 obj_pop_insert ();
481 /* Now portable ones. Skip any that we've seen already. */
482 pop_table_name = "standard";
483 pop_insert (potable);
486 #define HANDLE_CONDITIONAL_ASSEMBLY() \
487 if (ignore_input ()) \
489 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
490 if (input_line_pointer == buffer_limit) \
491 break; \
492 continue; \
496 /* This function is used when scrubbing the characters between #APP
497 and #NO_APP. */
499 static char *scrub_string;
500 static char *scrub_string_end;
502 static int
503 scrub_from_string (buf, buflen)
504 char *buf;
505 int buflen;
507 int copy;
509 copy = scrub_string_end - scrub_string;
510 if (copy > buflen)
511 copy = buflen;
512 memcpy (buf, scrub_string, copy);
513 scrub_string += copy;
514 return copy;
517 /* read_a_source_file()
519 * We read the file, putting things into a web that
520 * represents what we have been reading.
522 void
523 read_a_source_file (name)
524 char *name;
526 register char c;
527 register char *s; /* string of symbol, '\0' appended */
528 register int temp;
529 pseudo_typeS *pop;
531 buffer = input_scrub_new_file (name);
533 listing_file (name);
534 listing_newline (NULL);
535 register_dependency (name);
537 /* Generate debugging information before we've read anything in to denote
538 this file as the "main" source file and not a subordinate one
539 (e.g. N_SO vs N_SOL in stabs). */
540 generate_file_debug ();
542 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
543 { /* We have another line to parse. */
544 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
545 contin: /* JF this goto is my fault I admit it.
546 Someone brave please re-write the whole
547 input section here? Pleeze??? */
548 while (input_line_pointer < buffer_limit)
550 /* We have more of this buffer to parse. */
553 * We now have input_line_pointer->1st char of next line.
554 * If input_line_pointer [-1] == '\n' then we just
555 * scanned another line: so bump line counters.
557 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
559 #ifdef md_start_line_hook
560 md_start_line_hook ();
561 #endif
563 if (input_line_pointer[-1] == '\n')
564 bump_line_counters ();
566 line_label = NULL;
568 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
570 /* Text at the start of a line must be a label, we
571 run down and stick a colon in. */
572 if (is_name_beginner (*input_line_pointer))
574 char *line_start = input_line_pointer;
575 char c;
576 int mri_line_macro;
578 LISTING_NEWLINE ();
579 HANDLE_CONDITIONAL_ASSEMBLY ();
581 c = get_symbol_end ();
583 /* In MRI mode, the EQU and MACRO pseudoops must
584 be handled specially. */
585 mri_line_macro = 0;
586 if (flag_m68k_mri)
588 char *rest = input_line_pointer + 1;
590 if (*rest == ':')
591 ++rest;
592 if (*rest == ' ' || *rest == '\t')
593 ++rest;
594 if ((strncasecmp (rest, "EQU", 3) == 0
595 || strncasecmp (rest, "SET", 3) == 0)
596 && (rest[3] == ' ' || rest[3] == '\t'))
598 input_line_pointer = rest + 3;
599 equals (line_start,
600 strncasecmp (rest, "SET", 3) == 0);
601 continue;
603 if (strncasecmp (rest, "MACRO", 5) == 0
604 && (rest[5] == ' '
605 || rest[5] == '\t'
606 || is_end_of_line[(unsigned char) rest[5]]))
607 mri_line_macro = 1;
610 /* In MRI mode, we need to handle the MACRO
611 pseudo-op specially: we don't want to put the
612 symbol in the symbol table. */
613 if (! mri_line_macro
614 #ifdef TC_START_LABEL_WITHOUT_COLON
615 && TC_START_LABEL_WITHOUT_COLON(c,
616 input_line_pointer)
617 #endif
619 line_label = colon (line_start);
620 else
621 line_label = symbol_create (line_start,
622 absolute_section,
623 (valueT) 0,
624 &zero_address_frag);
626 *input_line_pointer = c;
627 if (c == ':')
628 input_line_pointer++;
634 * We are at the begining of a line, or similar place.
635 * We expect a well-formed assembler statement.
636 * A "symbol-name:" is a statement.
638 * Depending on what compiler is used, the order of these tests
639 * may vary to catch most common case 1st.
640 * Each test is independent of all other tests at the (top) level.
641 * PLEASE make a compiler that doesn't use this assembler.
642 * It is crufty to waste a compiler's time encoding things for this
643 * assembler, which then wastes more time decoding it.
644 * (And communicating via (linear) files is silly!
645 * If you must pass stuff, please pass a tree!)
647 if ((c = *input_line_pointer++) == '\t'
648 || c == ' '
649 || c == '\f'
650 || c == 0)
652 c = *input_line_pointer++;
654 know (c != ' '); /* No further leading whitespace. */
656 #ifndef NO_LISTING
657 /* If listing is on, and we are expanding a macro, then give
658 the listing code the contents of the expanded line. */
659 if (listing)
661 if ((listing & LISTING_MACEXP) && macro_nest > 0)
663 char *copy;
664 int len;
666 /* Find the end of the current expanded macro line. */
667 for (s = input_line_pointer-1; *s ; ++s)
668 if (is_end_of_line[(unsigned char) *s])
669 break;
671 /* Copy it for safe keeping. Also give an indication of
672 how much macro nesting is involved at this point. */
673 len = s - (input_line_pointer-1);
674 copy = (char *) xmalloc (len + macro_nest + 2);
675 memset (copy, '>', macro_nest);
676 copy[macro_nest] = ' ';
677 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
678 copy[macro_nest+1+len] = '\0';
680 /* Install the line with the listing facility. */
681 listing_newline (copy);
683 else
684 listing_newline (NULL);
686 #endif
689 * C is the 1st significant character.
690 * Input_line_pointer points after that character.
692 if (is_name_beginner (c))
694 /* want user-defined label or pseudo/opcode */
695 HANDLE_CONDITIONAL_ASSEMBLY ();
697 s = --input_line_pointer;
698 c = get_symbol_end (); /* name's delimiter */
700 * C is character after symbol.
701 * That character's place in the input line is now '\0'.
702 * S points to the beginning of the symbol.
703 * [In case of pseudo-op, s->'.'.]
704 * Input_line_pointer->'\0' where c was.
706 if (TC_START_LABEL(c, input_line_pointer))
708 if (flag_m68k_mri)
710 char *rest = input_line_pointer + 1;
712 /* In MRI mode, \tsym: set 0 is permitted. */
714 if (*rest == ':')
715 ++rest;
716 if (*rest == ' ' || *rest == '\t')
717 ++rest;
718 if ((strncasecmp (rest, "EQU", 3) == 0
719 || strncasecmp (rest, "SET", 3) == 0)
720 && (rest[3] == ' ' || rest[3] == '\t'))
722 input_line_pointer = rest + 3;
723 equals (s, 1);
724 continue;
728 line_label = colon (s); /* user-defined label */
729 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
730 /* Input_line_pointer->after ':'. */
731 SKIP_WHITESPACE ();
735 else if (c == '='
736 || ((c == ' ' || c == '\t')
737 && input_line_pointer[1] == '='
738 #ifdef TC_EQUAL_IN_INSN
739 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
740 #endif
743 equals (s, 1);
744 demand_empty_rest_of_line ();
746 else
747 { /* expect pseudo-op or machine instruction */
748 pop = NULL;
750 #define IGNORE_OPCODE_CASE
751 #ifdef IGNORE_OPCODE_CASE
753 char *s2 = s;
754 while (*s2)
756 if (isupper ((unsigned char) *s2))
757 *s2 = tolower (*s2);
758 s2++;
761 #endif
763 if (NO_PSEUDO_DOT || flag_m68k_mri)
765 /* The MRI assembler and the m88k use pseudo-ops
766 without a period. */
767 pop = (pseudo_typeS *) hash_find (po_hash, s);
768 if (pop != NULL && pop->poc_handler == NULL)
769 pop = NULL;
772 if (pop != NULL
773 || (! flag_m68k_mri && *s == '.'))
776 * PSEUDO - OP.
778 * WARNING: c has next char, which may be end-of-line.
779 * We lookup the pseudo-op table with s+1 because we
780 * already know that the pseudo-op begins with a '.'.
783 if (pop == NULL)
784 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
786 /* In MRI mode, we may need to insert an
787 automatic alignment directive. What a hack
788 this is. */
789 if (mri_pending_align
790 && (pop == NULL
791 || ! ((pop->poc_handler == cons
792 && pop->poc_val == 1)
793 || (pop->poc_handler == s_space
794 && pop->poc_val == 1)
795 #ifdef tc_conditional_pseudoop
796 || tc_conditional_pseudoop (pop)
797 #endif
798 || pop->poc_handler == s_if
799 || pop->poc_handler == s_ifdef
800 || pop->poc_handler == s_ifc
801 || pop->poc_handler == s_ifeqs
802 || pop->poc_handler == s_else
803 || pop->poc_handler == s_endif
804 || pop->poc_handler == s_globl
805 || pop->poc_handler == s_ignore)))
807 do_align (1, (char *) NULL, 0, 0);
808 mri_pending_align = 0;
809 if (line_label != NULL)
811 symbol_set_frag (line_label, frag_now);
812 S_SET_VALUE (line_label, frag_now_fix ());
816 /* Print the error msg now, while we still can */
817 if (pop == NULL)
819 as_bad (_("Unknown pseudo-op: `%s'"), s);
820 *input_line_pointer = c;
821 s_ignore (0);
822 continue;
825 /* Put it back for error messages etc. */
826 *input_line_pointer = c;
827 /* The following skip of whitespace is compulsory.
828 A well shaped space is sometimes all that separates
829 keyword from operands. */
830 if (c == ' ' || c == '\t')
831 input_line_pointer++;
833 * Input_line is restored.
834 * Input_line_pointer->1st non-blank char
835 * after pseudo-operation.
837 (*pop->poc_handler) (pop->poc_val);
839 /* If that was .end, just get out now. */
840 if (pop->poc_handler == s_end)
841 goto quit;
843 else
845 int inquote = 0;
846 #ifdef QUOTES_IN_INSN
847 int inescape = 0;
848 #endif
850 /* WARNING: c has char, which may be end-of-line. */
851 /* Also: input_line_pointer->`\0` where c was. */
852 *input_line_pointer = c;
853 while (!is_end_of_line[(unsigned char) *input_line_pointer]
854 || inquote
855 #ifdef TC_EOL_IN_INSN
856 || TC_EOL_IN_INSN (input_line_pointer)
857 #endif
860 if (flag_m68k_mri && *input_line_pointer == '\'')
861 inquote = ! inquote;
862 #ifdef QUOTES_IN_INSN
863 if (inescape)
864 inescape = 0;
865 else if (*input_line_pointer == '"')
866 inquote = ! inquote;
867 else if (*input_line_pointer == '\\')
868 inescape = 1;
869 #endif
870 input_line_pointer++;
873 c = *input_line_pointer;
874 *input_line_pointer = '\0';
876 generate_lineno_debug ();
878 if (macro_defined)
880 sb out;
881 const char *err;
882 macro_entry *macro;
884 if (check_macro (s, &out, '\0', &err, &macro))
886 if (err != NULL)
887 as_bad ("%s", err);
888 *input_line_pointer++ = c;
889 input_scrub_include_sb (&out,
890 input_line_pointer, 1);
891 sb_kill (&out);
892 buffer_limit =
893 input_scrub_next_buffer (&input_line_pointer);
894 #ifdef md_macro_info
895 md_macro_info (macro);
896 #endif
897 continue;
901 if (mri_pending_align)
903 do_align (1, (char *) NULL, 0, 0);
904 mri_pending_align = 0;
905 if (line_label != NULL)
907 symbol_set_frag (line_label, frag_now);
908 S_SET_VALUE (line_label, frag_now_fix ());
912 md_assemble (s); /* Assemble 1 instruction. */
914 *input_line_pointer++ = c;
916 /* We resume loop AFTER the end-of-line from
917 this instruction. */
918 } /* if (*s=='.') */
919 } /* if c==':' */
920 continue;
921 } /* if (is_name_beginner(c) */
924 /* Empty statement? */
925 if (is_end_of_line[(unsigned char) c])
926 continue;
928 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
929 && isdigit ((unsigned char) c))
931 /* local label ("4:") */
932 char *backup = input_line_pointer;
934 HANDLE_CONDITIONAL_ASSEMBLY ();
936 temp = c - '0';
938 while (isdigit ((unsigned char) *input_line_pointer))
940 temp = (temp * 10) + *input_line_pointer - '0';
941 ++input_line_pointer;
942 } /* read the whole number */
944 if (LOCAL_LABELS_DOLLAR
945 && *input_line_pointer == '$'
946 && *(input_line_pointer + 1) == ':')
948 input_line_pointer += 2;
950 if (dollar_label_defined (temp))
952 as_fatal (_("label \"%d$\" redefined"), temp);
955 define_dollar_label (temp);
956 colon (dollar_label_name (temp, 0));
957 continue;
960 if (LOCAL_LABELS_FB
961 && *input_line_pointer++ == ':')
963 fb_label_instance_inc (temp);
964 colon (fb_label_name (temp, 0));
965 continue;
968 input_line_pointer = backup;
969 } /* local label ("4:") */
971 if (c && strchr (line_comment_chars, c))
972 { /* Its a comment. Better say APP or NO_APP */
973 char *ends;
974 char *new_buf;
975 char *new_tmp;
976 unsigned int new_length;
977 char *tmp_buf = 0;
979 bump_line_counters ();
980 s = input_line_pointer;
981 if (strncmp (s, "APP\n", 4))
982 continue; /* We ignore it */
983 s += 4;
985 ends = strstr (s, "#NO_APP\n");
987 if (!ends)
989 unsigned int tmp_len;
990 unsigned int num;
992 /* The end of the #APP wasn't in this buffer. We
993 keep reading in buffers until we find the #NO_APP
994 that goes with this #APP There is one. The specs
995 guarentee it. . . */
996 tmp_len = buffer_limit - s;
997 tmp_buf = xmalloc (tmp_len + 1);
998 memcpy (tmp_buf, s, tmp_len);
1001 new_tmp = input_scrub_next_buffer (&buffer);
1002 if (!new_tmp)
1003 break;
1004 else
1005 buffer_limit = new_tmp;
1006 input_line_pointer = buffer;
1007 ends = strstr (buffer, "#NO_APP\n");
1008 if (ends)
1009 num = ends - buffer;
1010 else
1011 num = buffer_limit - buffer;
1013 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
1014 memcpy (tmp_buf + tmp_len, buffer, num);
1015 tmp_len += num;
1017 while (!ends);
1019 input_line_pointer = ends ? ends + 8 : NULL;
1021 s = tmp_buf;
1022 ends = s + tmp_len;
1025 else
1027 input_line_pointer = ends + 8;
1030 scrub_string = s;
1031 scrub_string_end = ends;
1033 new_length = ends - s;
1034 new_buf = (char *) xmalloc (new_length);
1035 new_tmp = new_buf;
1036 for (;;)
1038 int space;
1039 int size;
1041 space = (new_buf + new_length) - new_tmp;
1042 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1044 if (size < space)
1046 new_tmp += size;
1047 break;
1050 new_buf = xrealloc (new_buf, new_length + 100);
1051 new_tmp = new_buf + new_length;
1052 new_length += 100;
1055 if (tmp_buf)
1056 free (tmp_buf);
1057 old_buffer = buffer;
1058 old_input = input_line_pointer;
1059 old_limit = buffer_limit;
1060 buffer = new_buf;
1061 input_line_pointer = new_buf;
1062 buffer_limit = new_tmp;
1063 continue;
1066 HANDLE_CONDITIONAL_ASSEMBLY ();
1068 #ifdef tc_unrecognized_line
1069 if (tc_unrecognized_line (c))
1070 continue;
1071 #endif
1073 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1074 input_line_pointer--; /* Report unknown char as ignored. */
1075 ignore_rest_of_line ();
1076 } /* while (input_line_pointer<buffer_limit) */
1078 #ifdef md_after_pass_hook
1079 md_after_pass_hook ();
1080 #endif
1082 if (old_buffer)
1084 free (buffer);
1085 bump_line_counters ();
1086 if (old_input != 0)
1088 buffer = old_buffer;
1089 input_line_pointer = old_input;
1090 buffer_limit = old_limit;
1091 old_buffer = 0;
1092 goto contin;
1095 } /* while (more buffers to scan) */
1097 quit:
1099 #ifdef md_cleanup
1100 md_cleanup();
1101 #endif
1102 input_scrub_close (); /* Close the input file */
1105 /* For most MRI pseudo-ops, the line actually ends at the first
1106 nonquoted space. This function looks for that point, stuffs a null
1107 in, and sets *STOPCP to the character that used to be there, and
1108 returns the location.
1110 Until I hear otherwise, I am going to assume that this is only true
1111 for the m68k MRI assembler. */
1113 char *
1114 mri_comment_field (stopcp)
1115 char *stopcp;
1117 #ifdef TC_M68K
1119 char *s;
1120 int inquote = 0;
1122 know (flag_m68k_mri);
1124 for (s = input_line_pointer;
1125 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1126 || inquote);
1127 s++)
1129 if (*s == '\'')
1130 inquote = ! inquote;
1132 *stopcp = *s;
1133 *s = '\0';
1134 return s;
1136 #else
1138 char *s;
1140 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1142 *stopcp = *s;
1143 *s = '\0';
1144 return s;
1146 #endif
1150 /* Skip to the end of an MRI comment field. */
1152 void
1153 mri_comment_end (stop, stopc)
1154 char *stop;
1155 int stopc;
1157 know (flag_mri);
1159 input_line_pointer = stop;
1160 *stop = stopc;
1161 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1162 ++input_line_pointer;
1165 void
1166 s_abort (ignore)
1167 int ignore ATTRIBUTE_UNUSED;
1169 as_fatal (_(".abort detected. Abandoning ship."));
1172 /* Guts of .align directive. N is the power of two to which to align.
1173 FILL may be NULL, or it may point to the bytes of the fill pattern.
1174 LEN is the length of whatever FILL points to, if anything. MAX is
1175 the maximum number of characters to skip when doing the alignment,
1176 or 0 if there is no maximum. */
1178 static void
1179 do_align (n, fill, len, max)
1180 int n;
1181 char *fill;
1182 int len;
1183 int max;
1185 char default_fill;
1187 #ifdef md_do_align
1188 md_do_align (n, fill, len, max, just_record_alignment);
1189 #endif
1191 if (fill == NULL)
1193 if (subseg_text_p (now_seg))
1194 default_fill = NOP_OPCODE;
1195 else
1196 default_fill = 0;
1197 fill = &default_fill;
1198 len = 1;
1201 /* Only make a frag if we HAVE to. . . */
1202 if (n != 0 && !need_pass_2)
1204 if (len <= 1)
1205 frag_align (n, *fill, max);
1206 else
1207 frag_align_pattern (n, fill, len, max);
1210 #ifdef md_do_align
1211 just_record_alignment:
1212 #endif
1214 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1217 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1218 (in bytes). A negative ARG is the negative of the length of the
1219 fill pattern. BYTES_P is non-zero if the alignment value should be
1220 interpreted as the byte boundary, rather than the power of 2. */
1222 static void
1223 s_align (arg, bytes_p)
1224 int arg;
1225 int bytes_p;
1227 register unsigned int align;
1228 char *stop = NULL;
1229 char stopc;
1230 offsetT fill = 0;
1231 int max;
1232 int fill_p;
1234 if (flag_mri)
1235 stop = mri_comment_field (&stopc);
1237 if (is_end_of_line[(unsigned char) *input_line_pointer])
1239 if (arg < 0)
1240 align = 0;
1241 else
1242 align = arg; /* Default value from pseudo-op table */
1244 else
1246 align = get_absolute_expression ();
1247 SKIP_WHITESPACE ();
1250 if (bytes_p)
1252 /* Convert to a power of 2. */
1253 if (align != 0)
1255 unsigned int i;
1257 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1259 if (align != 1)
1260 as_bad (_("Alignment not a power of 2"));
1261 align = i;
1265 if (align > 15)
1267 align = 15;
1268 as_bad (_("Alignment too large: %u assumed"), align);
1271 if (*input_line_pointer != ',')
1273 fill_p = 0;
1274 max = 0;
1276 else
1278 ++input_line_pointer;
1279 if (*input_line_pointer == ',')
1280 fill_p = 0;
1281 else
1283 fill = get_absolute_expression ();
1284 SKIP_WHITESPACE ();
1285 fill_p = 1;
1288 if (*input_line_pointer != ',')
1289 max = 0;
1290 else
1292 ++input_line_pointer;
1293 max = get_absolute_expression ();
1297 if (! fill_p)
1299 if (arg < 0)
1300 as_warn (_("expected fill pattern missing"));
1301 do_align (align, (char *) NULL, 0, max);
1303 else
1305 int fill_len;
1307 if (arg >= 0)
1308 fill_len = 1;
1309 else
1310 fill_len = - arg;
1311 if (fill_len <= 1)
1313 char fill_char;
1315 fill_char = fill;
1316 do_align (align, &fill_char, fill_len, max);
1318 else
1320 char ab[16];
1322 if ((size_t) fill_len > sizeof ab)
1323 abort ();
1324 md_number_to_chars (ab, fill, fill_len);
1325 do_align (align, ab, fill_len, max);
1329 demand_empty_rest_of_line ();
1331 if (flag_mri)
1332 mri_comment_end (stop, stopc);
1335 /* Handle the .align pseudo-op on machines where ".align 4" means
1336 align to a 4 byte boundary. */
1338 void
1339 s_align_bytes (arg)
1340 int arg;
1342 s_align (arg, 1);
1345 /* Handle the .align pseudo-op on machines where ".align 4" means align
1346 to a 2**4 boundary. */
1348 void
1349 s_align_ptwo (arg)
1350 int arg;
1352 s_align (arg, 0);
1355 void
1356 s_comm (ignore)
1357 int ignore ATTRIBUTE_UNUSED;
1359 register char *name;
1360 register char c;
1361 register char *p;
1362 offsetT temp;
1363 register symbolS *symbolP;
1364 char *stop = NULL;
1365 char stopc;
1367 if (flag_mri)
1368 stop = mri_comment_field (&stopc);
1370 name = input_line_pointer;
1371 c = get_symbol_end ();
1372 /* just after name is now '\0' */
1373 p = input_line_pointer;
1374 *p = c;
1375 SKIP_WHITESPACE ();
1376 if (*input_line_pointer != ',')
1378 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1379 ignore_rest_of_line ();
1380 if (flag_mri)
1381 mri_comment_end (stop, stopc);
1382 return;
1384 input_line_pointer++; /* skip ',' */
1385 if ((temp = get_absolute_expression ()) < 0)
1387 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1388 ignore_rest_of_line ();
1389 if (flag_mri)
1390 mri_comment_end (stop, stopc);
1391 return;
1393 *p = 0;
1394 symbolP = symbol_find_or_make (name);
1395 *p = c;
1396 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1398 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1399 S_GET_NAME (symbolP));
1400 ignore_rest_of_line ();
1401 if (flag_mri)
1402 mri_comment_end (stop, stopc);
1403 return;
1405 if (S_GET_VALUE (symbolP))
1407 if (S_GET_VALUE (symbolP) != (valueT) temp)
1408 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1409 S_GET_NAME (symbolP),
1410 (long) S_GET_VALUE (symbolP),
1411 (long) temp);
1413 else
1415 S_SET_VALUE (symbolP, (valueT) temp);
1416 S_SET_EXTERNAL (symbolP);
1418 #ifdef OBJ_VMS
1420 extern int flag_one;
1421 if ( (!temp) || !flag_one)
1422 S_GET_OTHER(symbolP) = const_flag;
1424 #endif /* not OBJ_VMS */
1425 know (symbolP->sy_frag == &zero_address_frag);
1427 demand_empty_rest_of_line ();
1429 if (flag_mri)
1430 mri_comment_end (stop, stopc);
1431 } /* s_comm() */
1433 /* The MRI COMMON pseudo-op. We handle this by creating a common
1434 symbol with the appropriate name. We make s_space do the right
1435 thing by increasing the size. */
1437 void
1438 s_mri_common (small)
1439 int small ATTRIBUTE_UNUSED;
1441 char *name;
1442 char c;
1443 char *alc = NULL;
1444 symbolS *sym;
1445 offsetT align;
1446 char *stop = NULL;
1447 char stopc;
1449 if (! flag_mri)
1451 s_comm (0);
1452 return;
1455 stop = mri_comment_field (&stopc);
1457 SKIP_WHITESPACE ();
1459 name = input_line_pointer;
1460 if (! isdigit ((unsigned char) *name))
1461 c = get_symbol_end ();
1462 else
1466 ++input_line_pointer;
1468 while (isdigit ((unsigned char) *input_line_pointer));
1469 c = *input_line_pointer;
1470 *input_line_pointer = '\0';
1472 if (line_label != NULL)
1474 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1475 + (input_line_pointer - name)
1476 + 1);
1477 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1478 name = alc;
1482 sym = symbol_find_or_make (name);
1483 *input_line_pointer = c;
1484 if (alc != NULL)
1485 free (alc);
1487 if (*input_line_pointer != ',')
1488 align = 0;
1489 else
1491 ++input_line_pointer;
1492 align = get_absolute_expression ();
1495 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1497 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1498 ignore_rest_of_line ();
1499 mri_comment_end (stop, stopc);
1500 return;
1503 S_SET_EXTERNAL (sym);
1504 mri_common_symbol = sym;
1506 #ifdef S_SET_ALIGN
1507 if (align != 0)
1508 S_SET_ALIGN (sym, align);
1509 #endif
1511 if (line_label != NULL)
1513 expressionS exp;
1514 exp.X_op = O_symbol;
1515 exp.X_add_symbol = sym;
1516 exp.X_add_number = 0;
1517 symbol_set_value_expression (line_label, &exp);
1518 symbol_set_frag (line_label, &zero_address_frag);
1519 S_SET_SEGMENT (line_label, expr_section);
1522 /* FIXME: We just ignore the small argument, which distinguishes
1523 COMMON and COMMON.S. I don't know what we can do about it. */
1525 /* Ignore the type and hptype. */
1526 if (*input_line_pointer == ',')
1527 input_line_pointer += 2;
1528 if (*input_line_pointer == ',')
1529 input_line_pointer += 2;
1531 demand_empty_rest_of_line ();
1533 mri_comment_end (stop, stopc);
1536 void
1537 s_data (ignore)
1538 int ignore ATTRIBUTE_UNUSED;
1540 segT section;
1541 register int temp;
1543 temp = get_absolute_expression ();
1544 if (flag_readonly_data_in_text)
1546 section = text_section;
1547 temp += 1000;
1549 else
1550 section = data_section;
1552 subseg_set (section, (subsegT) temp);
1554 #ifdef OBJ_VMS
1555 const_flag = 0;
1556 #endif
1557 demand_empty_rest_of_line ();
1560 /* Handle the .appfile pseudo-op. This is automatically generated by
1561 do_scrub_chars when a preprocessor # line comment is seen with a
1562 file name. This default definition may be overridden by the object
1563 or CPU specific pseudo-ops. This function is also the default
1564 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1565 .file. */
1567 void
1568 s_app_file (appfile)
1569 int appfile;
1571 register char *s;
1572 int length;
1574 /* Some assemblers tolerate immediately following '"' */
1575 if ((s = demand_copy_string (&length)) != 0)
1577 /* If this is a fake .appfile, a fake newline was inserted into
1578 the buffer. Passing -2 to new_logical_line tells it to
1579 account for it. */
1580 int may_omit
1581 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1583 /* In MRI mode, the preprocessor may have inserted an extraneous
1584 backquote. */
1585 if (flag_m68k_mri
1586 && *input_line_pointer == '\''
1587 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1588 ++input_line_pointer;
1590 demand_empty_rest_of_line ();
1591 if (! may_omit)
1593 #ifdef LISTING
1594 if (listing)
1595 listing_source_file (s);
1596 #endif
1597 register_dependency (s);
1598 #ifdef obj_app_file
1599 obj_app_file (s);
1600 #endif
1605 /* Handle the .appline pseudo-op. This is automatically generated by
1606 do_scrub_chars when a preprocessor # line comment is seen. This
1607 default definition may be overridden by the object or CPU specific
1608 pseudo-ops. */
1610 void
1611 s_app_line (ignore)
1612 int ignore ATTRIBUTE_UNUSED;
1614 int l;
1616 /* The given number is that of the next line. */
1617 l = get_absolute_expression () - 1;
1618 if (l < 0)
1619 /* Some of the back ends can't deal with non-positive line numbers.
1620 Besides, it's silly. */
1621 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1622 else
1624 new_logical_line ((char *) NULL, l);
1625 #ifdef LISTING
1626 if (listing)
1627 listing_source_line (l);
1628 #endif
1630 demand_empty_rest_of_line ();
1633 /* Handle the .end pseudo-op. Actually, the real work is done in
1634 read_a_source_file. */
1636 void
1637 s_end (ignore)
1638 int ignore ATTRIBUTE_UNUSED;
1640 if (flag_mri)
1642 /* The MRI assembler permits the start symbol to follow .end,
1643 but we don't support that. */
1644 SKIP_WHITESPACE ();
1645 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1646 && *input_line_pointer != '*'
1647 && *input_line_pointer != '!')
1648 as_warn (_("start address not supported"));
1652 /* Handle the .err pseudo-op. */
1654 void
1655 s_err (ignore)
1656 int ignore ATTRIBUTE_UNUSED;
1658 as_bad (_(".err encountered"));
1659 demand_empty_rest_of_line ();
1662 /* Handle the MRI fail pseudo-op. */
1664 void
1665 s_fail (ignore)
1666 int ignore ATTRIBUTE_UNUSED;
1668 offsetT temp;
1669 char *stop = NULL;
1670 char stopc;
1672 if (flag_mri)
1673 stop = mri_comment_field (&stopc);
1675 temp = get_absolute_expression ();
1676 if (temp >= 500)
1677 as_warn (_(".fail %ld encountered"), (long) temp);
1678 else
1679 as_bad (_(".fail %ld encountered"), (long) temp);
1681 demand_empty_rest_of_line ();
1683 if (flag_mri)
1684 mri_comment_end (stop, stopc);
1687 void
1688 s_fill (ignore)
1689 int ignore ATTRIBUTE_UNUSED;
1691 expressionS rep_exp;
1692 long size = 1;
1693 register long fill = 0;
1694 char *p;
1696 #ifdef md_flush_pending_output
1697 md_flush_pending_output ();
1698 #endif
1700 get_known_segmented_expression (&rep_exp);
1701 if (*input_line_pointer == ',')
1703 input_line_pointer++;
1704 size = get_absolute_expression ();
1705 if (*input_line_pointer == ',')
1707 input_line_pointer++;
1708 fill = get_absolute_expression ();
1712 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1713 #define BSD_FILL_SIZE_CROCK_8 (8)
1714 if (size > BSD_FILL_SIZE_CROCK_8)
1716 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1717 size = BSD_FILL_SIZE_CROCK_8;
1719 if (size < 0)
1721 as_warn (_("Size negative: .fill ignored."));
1722 size = 0;
1724 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1726 if (rep_exp.X_add_number < 0)
1727 as_warn (_("Repeat < 0, .fill ignored"));
1728 size = 0;
1731 if (size && !need_pass_2)
1733 if (rep_exp.X_op == O_constant)
1735 p = frag_var (rs_fill, (int) size, (int) size,
1736 (relax_substateT) 0, (symbolS *) 0,
1737 (offsetT) rep_exp.X_add_number,
1738 (char *) 0);
1740 else
1742 /* We don't have a constant repeat count, so we can't use
1743 rs_fill. We can get the same results out of rs_space,
1744 but its argument is in bytes, so we must multiply the
1745 repeat count by size. */
1747 symbolS *rep_sym;
1748 rep_sym = make_expr_symbol (&rep_exp);
1749 if (size != 1)
1751 expressionS size_exp;
1752 size_exp.X_op = O_constant;
1753 size_exp.X_add_number = size;
1755 rep_exp.X_op = O_multiply;
1756 rep_exp.X_add_symbol = rep_sym;
1757 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1758 rep_exp.X_add_number = 0;
1759 rep_sym = make_expr_symbol (&rep_exp);
1762 p = frag_var (rs_space, (int) size, (int) size,
1763 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1765 memset (p, 0, (unsigned int) size);
1766 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1767 * flavoured AS. The following bizzare behaviour is to be
1768 * compatible with above. I guess they tried to take up to 8
1769 * bytes from a 4-byte expression and they forgot to sign
1770 * extend. Un*x Sux. */
1771 #define BSD_FILL_SIZE_CROCK_4 (4)
1772 md_number_to_chars (p, (valueT) fill,
1773 (size > BSD_FILL_SIZE_CROCK_4
1774 ? BSD_FILL_SIZE_CROCK_4
1775 : (int) size));
1776 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1777 * but emits no error message because it seems a legal thing to do.
1778 * It is a degenerate case of .fill but could be emitted by a compiler.
1781 demand_empty_rest_of_line ();
1784 void
1785 s_globl (ignore)
1786 int ignore ATTRIBUTE_UNUSED;
1788 char *name;
1789 int c;
1790 symbolS *symbolP;
1791 char *stop = NULL;
1792 char stopc;
1794 if (flag_mri)
1795 stop = mri_comment_field (&stopc);
1799 name = input_line_pointer;
1800 c = get_symbol_end ();
1801 symbolP = symbol_find_or_make (name);
1802 S_SET_EXTERNAL (symbolP);
1804 *input_line_pointer = c;
1805 SKIP_WHITESPACE ();
1806 c = *input_line_pointer;
1807 if (c == ',')
1809 input_line_pointer++;
1810 SKIP_WHITESPACE ();
1811 if (*input_line_pointer == '\n')
1812 c = '\n';
1815 while (c == ',');
1817 demand_empty_rest_of_line ();
1819 if (flag_mri)
1820 mri_comment_end (stop, stopc);
1823 /* Handle the MRI IRP and IRPC pseudo-ops. */
1825 void
1826 s_irp (irpc)
1827 int irpc;
1829 char *file;
1830 unsigned int line;
1831 sb s;
1832 const char *err;
1833 sb out;
1835 as_where (&file, &line);
1837 sb_new (&s);
1838 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1839 sb_add_char (&s, *input_line_pointer++);
1841 sb_new (&out);
1843 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1844 if (err != NULL)
1845 as_bad_where (file, line, "%s", err);
1847 sb_kill (&s);
1849 input_scrub_include_sb (&out, input_line_pointer, 1);
1850 sb_kill (&out);
1851 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1854 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1855 the section to only be linked once. However, this is not supported
1856 by most object file formats. This takes an optional argument,
1857 which is what to do about duplicates. */
1859 void
1860 s_linkonce (ignore)
1861 int ignore ATTRIBUTE_UNUSED;
1863 enum linkonce_type type;
1865 SKIP_WHITESPACE ();
1867 type = LINKONCE_DISCARD;
1869 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1871 char *s;
1872 char c;
1874 s = input_line_pointer;
1875 c = get_symbol_end ();
1876 if (strcasecmp (s, "discard") == 0)
1877 type = LINKONCE_DISCARD;
1878 else if (strcasecmp (s, "one_only") == 0)
1879 type = LINKONCE_ONE_ONLY;
1880 else if (strcasecmp (s, "same_size") == 0)
1881 type = LINKONCE_SAME_SIZE;
1882 else if (strcasecmp (s, "same_contents") == 0)
1883 type = LINKONCE_SAME_CONTENTS;
1884 else
1885 as_warn (_("unrecognized .linkonce type `%s'"), s);
1887 *input_line_pointer = c;
1890 #ifdef obj_handle_link_once
1891 obj_handle_link_once (type);
1892 #else /* ! defined (obj_handle_link_once) */
1893 #ifdef BFD_ASSEMBLER
1895 flagword flags;
1897 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1898 as_warn (_(".linkonce is not supported for this object file format"));
1900 flags = bfd_get_section_flags (stdoutput, now_seg);
1901 flags |= SEC_LINK_ONCE;
1902 switch (type)
1904 default:
1905 abort ();
1906 case LINKONCE_DISCARD:
1907 flags |= SEC_LINK_DUPLICATES_DISCARD;
1908 break;
1909 case LINKONCE_ONE_ONLY:
1910 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1911 break;
1912 case LINKONCE_SAME_SIZE:
1913 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1914 break;
1915 case LINKONCE_SAME_CONTENTS:
1916 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1917 break;
1919 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1920 as_bad (_("bfd_set_section_flags: %s"),
1921 bfd_errmsg (bfd_get_error ()));
1923 #else /* ! defined (BFD_ASSEMBLER) */
1924 as_warn (_(".linkonce is not supported for this object file format"));
1925 #endif /* ! defined (BFD_ASSEMBLER) */
1926 #endif /* ! defined (obj_handle_link_once) */
1928 demand_empty_rest_of_line ();
1931 static void
1932 s_lcomm_internal (needs_align, bytes_p)
1933 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1934 (alignment); 0 if it was an ".lcomm" (2 args only) */
1935 int needs_align;
1936 /* 1 if the alignment value should be interpreted as the byte boundary,
1937 rather than the power of 2. */
1938 int bytes_p;
1940 register char *name;
1941 register char c;
1942 register char *p;
1943 register int temp;
1944 register symbolS *symbolP;
1945 segT current_seg = now_seg;
1946 subsegT current_subseg = now_subseg;
1947 const int max_alignment = 15;
1948 int align = 0;
1949 segT bss_seg = bss_section;
1951 name = input_line_pointer;
1952 c = get_symbol_end ();
1953 p = input_line_pointer;
1954 *p = c;
1955 SKIP_WHITESPACE ();
1957 /* Accept an optional comma after the name. The comma used to be
1958 required, but Irix 5 cc does not generate it. */
1959 if (*input_line_pointer == ',')
1961 ++input_line_pointer;
1962 SKIP_WHITESPACE ();
1965 if (*input_line_pointer == '\n')
1967 as_bad (_("Missing size expression"));
1968 return;
1971 if ((temp = get_absolute_expression ()) < 0)
1973 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1974 ignore_rest_of_line ();
1975 return;
1978 #if defined (TC_MIPS) || defined (TC_ALPHA)
1979 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1980 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1982 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1983 if (temp <= bfd_get_gp_size (stdoutput))
1985 bss_seg = subseg_new (".sbss", 1);
1986 seg_info (bss_seg)->bss = 1;
1987 #ifdef BFD_ASSEMBLER
1988 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1989 as_warn (_("error setting flags for \".sbss\": %s"),
1990 bfd_errmsg (bfd_get_error ()));
1991 #endif
1994 #endif
1996 if (!needs_align)
1998 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
2000 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
2001 if (align)
2002 record_alignment(bss_seg, align);
2005 if (needs_align)
2007 align = 0;
2008 SKIP_WHITESPACE ();
2009 if (*input_line_pointer != ',')
2011 as_bad (_("Expected comma after size"));
2012 ignore_rest_of_line ();
2013 return;
2015 input_line_pointer++;
2016 SKIP_WHITESPACE ();
2017 if (*input_line_pointer == '\n')
2019 as_bad (_("Missing alignment"));
2020 return;
2022 align = get_absolute_expression ();
2023 if (bytes_p)
2025 /* Convert to a power of 2. */
2026 if (align != 0)
2028 unsigned int i;
2030 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2032 if (align != 1)
2033 as_bad (_("Alignment not a power of 2"));
2034 align = i;
2037 if (align > max_alignment)
2039 align = max_alignment;
2040 as_warn (_("Alignment too large: %d. assumed."), align);
2042 else if (align < 0)
2044 align = 0;
2045 as_warn (_("Alignment negative. 0 assumed."));
2047 record_alignment (bss_seg, align);
2048 } /* if needs align */
2049 else
2051 /* Assume some objects may require alignment on some systems. */
2052 #if defined (TC_ALPHA) && ! defined (VMS)
2053 if (temp > 1)
2055 align = ffs (temp) - 1;
2056 if (temp % (1 << align))
2057 abort ();
2059 #endif
2062 *p = 0;
2063 symbolP = symbol_find_or_make (name);
2064 *p = c;
2066 if (
2067 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2068 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2069 #ifdef BFD_ASSEMBLER
2070 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2071 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2072 #else
2073 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2074 #endif
2075 #endif
2076 (S_GET_SEGMENT (symbolP) == bss_seg
2077 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2079 char *pfrag;
2081 subseg_set (bss_seg, 1);
2083 if (align)
2084 frag_align (align, 0, 0);
2085 /* detach from old frag */
2086 if (S_GET_SEGMENT (symbolP) == bss_seg)
2087 symbol_get_frag (symbolP)->fr_symbol = NULL;
2089 symbol_set_frag (symbolP, frag_now);
2090 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2091 (offsetT) temp, (char *) 0);
2092 *pfrag = 0;
2094 S_SET_SEGMENT (symbolP, bss_seg);
2096 #ifdef OBJ_COFF
2097 /* The symbol may already have been created with a preceding
2098 ".globl" directive -- be careful not to step on storage class
2099 in that case. Otherwise, set it to static. */
2100 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2102 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2104 #endif /* OBJ_COFF */
2106 #ifdef S_SET_SIZE
2107 S_SET_SIZE (symbolP, temp);
2108 #endif
2110 else
2111 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2112 S_GET_NAME (symbolP));
2114 subseg_set (current_seg, current_subseg);
2116 demand_empty_rest_of_line ();
2117 } /* s_lcomm_internal() */
2119 void
2120 s_lcomm (needs_align)
2121 int needs_align;
2123 s_lcomm_internal (needs_align, 0);
2126 void s_lcomm_bytes (needs_align)
2127 int needs_align;
2129 s_lcomm_internal (needs_align, 1);
2132 void
2133 s_lsym (ignore)
2134 int ignore ATTRIBUTE_UNUSED;
2136 register char *name;
2137 register char c;
2138 register char *p;
2139 expressionS exp;
2140 register symbolS *symbolP;
2142 /* we permit ANY defined expression: BSD4.2 demands constants */
2143 name = input_line_pointer;
2144 c = get_symbol_end ();
2145 p = input_line_pointer;
2146 *p = c;
2147 SKIP_WHITESPACE ();
2148 if (*input_line_pointer != ',')
2150 *p = 0;
2151 as_bad (_("Expected comma after name \"%s\""), name);
2152 *p = c;
2153 ignore_rest_of_line ();
2154 return;
2156 input_line_pointer++;
2157 expression (&exp);
2158 if (exp.X_op != O_constant
2159 && exp.X_op != O_register)
2161 as_bad (_("bad expression"));
2162 ignore_rest_of_line ();
2163 return;
2165 *p = 0;
2166 symbolP = symbol_find_or_make (name);
2168 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2169 symbolP->sy_desc == 0) out of this test because coff doesn't have
2170 those fields, and I can't see when they'd ever be tripped. I
2171 don't think I understand why they were here so I may have
2172 introduced a bug. As recently as 1.37 didn't have this test
2173 anyway. xoxorich. */
2175 if (S_GET_SEGMENT (symbolP) == undefined_section
2176 && S_GET_VALUE (symbolP) == 0)
2178 /* The name might be an undefined .global symbol; be sure to
2179 keep the "external" bit. */
2180 S_SET_SEGMENT (symbolP,
2181 (exp.X_op == O_constant
2182 ? absolute_section
2183 : reg_section));
2184 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2186 else
2188 as_bad (_("Symbol %s already defined"), name);
2190 *p = c;
2191 demand_empty_rest_of_line ();
2192 } /* s_lsym() */
2194 /* Read a line into an sb. */
2196 static int
2197 get_line_sb (line)
2198 sb *line;
2200 char quote1, quote2, inquote;
2202 if (input_line_pointer[-1] == '\n')
2203 bump_line_counters ();
2205 if (input_line_pointer >= buffer_limit)
2207 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2208 if (buffer_limit == 0)
2209 return 0;
2212 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2213 code needs to be changed. */
2214 if (! flag_m68k_mri)
2215 quote1 = '"';
2216 else
2217 quote1 = '\0';
2219 quote2 = '\0';
2220 if (flag_m68k_mri)
2221 quote2 = '\'';
2222 #ifdef LEX_IS_STRINGQUOTE
2223 quote2 = '\'';
2224 #endif
2226 inquote = '\0';
2227 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2228 || (inquote != '\0' && *input_line_pointer != '\n'))
2230 if (inquote == *input_line_pointer)
2231 inquote = '\0';
2232 else if (inquote == '\0')
2234 if (*input_line_pointer == quote1)
2235 inquote = quote1;
2236 else if (*input_line_pointer == quote2)
2237 inquote = quote2;
2239 sb_add_char (line, *input_line_pointer++);
2241 while (input_line_pointer < buffer_limit
2242 && is_end_of_line[(unsigned char) *input_line_pointer])
2244 if (input_line_pointer[-1] == '\n')
2245 bump_line_counters ();
2246 ++input_line_pointer;
2248 return 1;
2251 /* Define a macro. This is an interface to macro.c, which is shared
2252 between gas and gasp. */
2254 void
2255 s_macro (ignore)
2256 int ignore ATTRIBUTE_UNUSED;
2258 char *file;
2259 unsigned int line;
2260 sb s;
2261 sb label;
2262 const char *err;
2263 const char *name;
2265 as_where (&file, &line);
2267 sb_new (&s);
2268 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2269 sb_add_char (&s, *input_line_pointer++);
2271 sb_new (&label);
2272 if (line_label != NULL)
2273 sb_add_string (&label, S_GET_NAME (line_label));
2275 err = define_macro (0, &s, &label, get_line_sb, &name);
2276 if (err != NULL)
2277 as_bad_where (file, line, "%s", err);
2278 else
2280 if (line_label != NULL)
2282 S_SET_SEGMENT (line_label, undefined_section);
2283 S_SET_VALUE (line_label, 0);
2284 symbol_set_frag (line_label, &zero_address_frag);
2287 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2288 && hash_find (po_hash, name) != NULL)
2289 || (! flag_m68k_mri
2290 && *name == '.'
2291 && hash_find (po_hash, name + 1) != NULL))
2292 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2293 name);
2296 sb_kill (&s);
2299 /* Handle the .mexit pseudo-op, which immediately exits a macro
2300 expansion. */
2302 void
2303 s_mexit (ignore)
2304 int ignore ATTRIBUTE_UNUSED;
2306 cond_exit_macro (macro_nest);
2307 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2310 /* Switch in and out of MRI mode. */
2312 void
2313 s_mri (ignore)
2314 int ignore ATTRIBUTE_UNUSED;
2316 int on, old_flag;
2318 on = get_absolute_expression ();
2319 old_flag = flag_mri;
2320 if (on != 0)
2322 flag_mri = 1;
2323 #ifdef TC_M68K
2324 flag_m68k_mri = 1;
2325 #endif
2326 macro_mri_mode (1);
2328 else
2330 flag_mri = 0;
2331 #ifdef TC_M68K
2332 flag_m68k_mri = 0;
2333 #endif
2334 macro_mri_mode (0);
2337 /* Operator precedence changes in m68k MRI mode, so we need to
2338 update the operator rankings. */
2339 expr_set_precedence ();
2341 #ifdef MRI_MODE_CHANGE
2342 if (on != old_flag)
2343 MRI_MODE_CHANGE (on);
2344 #endif
2346 demand_empty_rest_of_line ();
2349 /* Handle changing the location counter. */
2351 static void
2352 do_org (segment, exp, fill)
2353 segT segment;
2354 expressionS *exp;
2355 int fill;
2357 if (segment != now_seg && segment != absolute_section)
2358 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2359 segment_name (segment), segment_name (now_seg));
2361 if (now_seg == absolute_section)
2363 if (fill != 0)
2364 as_warn (_("ignoring fill value in absolute section"));
2365 if (exp->X_op != O_constant)
2367 as_bad (_("only constant offsets supported in absolute section"));
2368 exp->X_add_number = 0;
2370 abs_section_offset = exp->X_add_number;
2372 else
2374 char *p;
2376 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2377 exp->X_add_number * OCTETS_PER_BYTE, (char *) NULL);
2378 *p = fill;
2382 void
2383 s_org (ignore)
2384 int ignore ATTRIBUTE_UNUSED;
2386 register segT segment;
2387 expressionS exp;
2388 register long temp_fill;
2390 #ifdef md_flush_pending_output
2391 md_flush_pending_output ();
2392 #endif
2394 /* The m68k MRI assembler has a different meaning for .org. It
2395 means to create an absolute section at a given address. We can't
2396 support that--use a linker script instead. */
2397 if (flag_m68k_mri)
2399 as_bad (_("MRI style ORG pseudo-op not supported"));
2400 ignore_rest_of_line ();
2401 return;
2404 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2405 thing as a sub-segment-relative origin. Any absolute origin is
2406 given a warning, then assumed to be segment-relative. Any
2407 segmented origin expression ("foo+42") had better be in the right
2408 segment or the .org is ignored.
2410 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2411 we never know sub-segment sizes when we are reading code. BSD
2412 will crash trying to emit negative numbers of filler bytes in
2413 certain .orgs. We don't crash, but see as-write for that code.
2415 Don't make frag if need_pass_2==1. */
2416 segment = get_known_segmented_expression (&exp);
2417 if (*input_line_pointer == ',')
2419 input_line_pointer++;
2420 temp_fill = get_absolute_expression ();
2422 else
2423 temp_fill = 0;
2425 if (!need_pass_2)
2426 do_org (segment, &exp, temp_fill);
2428 demand_empty_rest_of_line ();
2429 } /* s_org() */
2431 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2432 called by the obj-format routine which handles section changing
2433 when in MRI mode. It will create a new section, and return it. It
2434 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2435 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2436 flags will be set in the section. */
2438 void
2439 s_mri_sect (type)
2440 char *type ATTRIBUTE_UNUSED;
2442 #ifdef TC_M68K
2444 char *name;
2445 char c;
2446 segT seg;
2448 SKIP_WHITESPACE ();
2450 name = input_line_pointer;
2451 if (! isdigit ((unsigned char) *name))
2452 c = get_symbol_end ();
2453 else
2457 ++input_line_pointer;
2459 while (isdigit ((unsigned char) *input_line_pointer));
2460 c = *input_line_pointer;
2461 *input_line_pointer = '\0';
2464 name = xstrdup (name);
2466 *input_line_pointer = c;
2468 seg = subseg_new (name, 0);
2470 if (*input_line_pointer == ',')
2472 int align;
2474 ++input_line_pointer;
2475 align = get_absolute_expression ();
2476 record_alignment (seg, align);
2479 *type = 'C';
2480 if (*input_line_pointer == ',')
2482 c = *++input_line_pointer;
2483 c = toupper ((unsigned char) c);
2484 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2485 *type = c;
2486 else
2487 as_bad (_("unrecognized section type"));
2488 ++input_line_pointer;
2490 #ifdef BFD_ASSEMBLER
2492 flagword flags;
2494 flags = SEC_NO_FLAGS;
2495 if (*type == 'C')
2496 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2497 else if (*type == 'D' || *type == 'M')
2498 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2499 else if (*type == 'R')
2500 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2501 if (flags != SEC_NO_FLAGS)
2503 if (! bfd_set_section_flags (stdoutput, seg, flags))
2504 as_warn (_("error setting flags for \"%s\": %s"),
2505 bfd_section_name (stdoutput, seg),
2506 bfd_errmsg (bfd_get_error ()));
2509 #endif
2512 /* Ignore the HP type. */
2513 if (*input_line_pointer == ',')
2514 input_line_pointer += 2;
2516 demand_empty_rest_of_line ();
2518 #else /* ! TC_M68K */
2519 #ifdef TC_I960
2521 char *name;
2522 char c;
2523 segT seg;
2525 SKIP_WHITESPACE ();
2527 name = input_line_pointer;
2528 c = get_symbol_end ();
2530 name = xstrdup (name);
2532 *input_line_pointer = c;
2534 seg = subseg_new (name, 0);
2536 if (*input_line_pointer != ',')
2537 *type = 'C';
2538 else
2540 char *sectype;
2542 ++input_line_pointer;
2543 SKIP_WHITESPACE ();
2544 sectype = input_line_pointer;
2545 c = get_symbol_end ();
2546 if (*sectype == '\0')
2547 *type = 'C';
2548 else if (strcasecmp (sectype, "text") == 0)
2549 *type = 'C';
2550 else if (strcasecmp (sectype, "data") == 0)
2551 *type = 'D';
2552 else if (strcasecmp (sectype, "romdata") == 0)
2553 *type = 'R';
2554 else
2555 as_warn (_("unrecognized section type `%s'"), sectype);
2556 *input_line_pointer = c;
2559 if (*input_line_pointer == ',')
2561 char *seccmd;
2563 ++input_line_pointer;
2564 SKIP_WHITESPACE ();
2565 seccmd = input_line_pointer;
2566 c = get_symbol_end ();
2567 if (strcasecmp (seccmd, "absolute") == 0)
2569 as_bad (_("absolute sections are not supported"));
2570 *input_line_pointer = c;
2571 ignore_rest_of_line ();
2572 return;
2574 else if (strcasecmp (seccmd, "align") == 0)
2576 int align;
2578 *input_line_pointer = c;
2579 align = get_absolute_expression ();
2580 record_alignment (seg, align);
2582 else
2584 as_warn (_("unrecognized section command `%s'"), seccmd);
2585 *input_line_pointer = c;
2589 demand_empty_rest_of_line ();
2591 #else /* ! TC_I960 */
2592 /* The MRI assembler seems to use different forms of .sect for
2593 different targets. */
2594 as_bad ("MRI mode not supported for this target");
2595 ignore_rest_of_line ();
2596 #endif /* ! TC_I960 */
2597 #endif /* ! TC_M68K */
2600 /* Handle the .print pseudo-op. */
2602 void
2603 s_print (ignore)
2604 int ignore ATTRIBUTE_UNUSED;
2606 char *s;
2607 int len;
2609 s = demand_copy_C_string (&len);
2610 printf ("%s\n", s);
2611 demand_empty_rest_of_line ();
2614 /* Handle the .purgem pseudo-op. */
2616 void
2617 s_purgem (ignore)
2618 int ignore ATTRIBUTE_UNUSED;
2620 if (is_it_end_of_statement ())
2622 demand_empty_rest_of_line ();
2623 return;
2628 char *name;
2629 char c;
2631 SKIP_WHITESPACE ();
2632 name = input_line_pointer;
2633 c = get_symbol_end ();
2634 delete_macro (name);
2635 *input_line_pointer = c;
2636 SKIP_WHITESPACE ();
2638 while (*input_line_pointer++ == ',');
2640 --input_line_pointer;
2641 demand_empty_rest_of_line ();
2644 /* Handle the .rept pseudo-op. */
2646 void
2647 s_rept (ignore)
2648 int ignore ATTRIBUTE_UNUSED;
2650 int count;
2652 count = get_absolute_expression ();
2654 do_repeat(count, "REPT", "ENDR");
2657 /* This function provides a generic repeat block implementation. It allows
2658 different directives to be used as the start/end keys. */
2660 void
2661 do_repeat (count, start, end)
2662 int count;
2663 const char *start;
2664 const char *end;
2666 sb one;
2667 sb many;
2669 sb_new (&one);
2670 if (! buffer_and_nest (start, end, &one, get_line_sb))
2672 as_bad (_("%s without %s"), start, end);
2673 return;
2676 sb_new (&many);
2677 while (count-- > 0)
2678 sb_add_sb (&many, &one);
2680 sb_kill (&one);
2682 input_scrub_include_sb (&many, input_line_pointer, 1);
2683 sb_kill (&many);
2684 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2687 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2688 input buffers to skip. Assumes that conditionals preceding the loop end
2689 are properly nested.
2691 This function makes it easier to implement a premature "break" out of the
2692 loop. The EXTRA arg accounts for other buffers we might have inserted,
2693 such as line substitutions. */
2695 void
2696 end_repeat (extra)
2697 int extra;
2699 cond_exit_macro (macro_nest);
2700 while (extra-- >= 0)
2701 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2704 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2705 this is .equiv, and it is an error if the symbol is already
2706 defined. */
2708 void
2709 s_set (equiv)
2710 int equiv;
2712 register char *name;
2713 register char delim;
2714 register char *end_name;
2715 register symbolS *symbolP;
2718 * Especial apologies for the random logic:
2719 * this just grew, and could be parsed much more simply!
2720 * Dean in haste.
2722 name = input_line_pointer;
2723 delim = get_symbol_end ();
2724 end_name = input_line_pointer;
2725 *end_name = delim;
2726 SKIP_WHITESPACE ();
2728 if (*input_line_pointer != ',')
2730 *end_name = 0;
2731 as_bad (_("Expected comma after name \"%s\""), name);
2732 *end_name = delim;
2733 ignore_rest_of_line ();
2734 return;
2737 input_line_pointer++;
2738 *end_name = 0;
2740 if (name[0] == '.' && name[1] == '\0')
2742 /* Turn '. = mumble' into a .org mumble */
2743 register segT segment;
2744 expressionS exp;
2746 segment = get_known_segmented_expression (&exp);
2748 if (!need_pass_2)
2749 do_org (segment, &exp, 0);
2751 *end_name = delim;
2752 return;
2755 if ((symbolP = symbol_find (name)) == NULL
2756 && (symbolP = md_undefined_symbol (name)) == NULL)
2758 #ifndef NO_LISTING
2759 /* When doing symbol listings, play games with dummy fragments living
2760 outside the normal fragment chain to record the file and line info
2761 for this symbol. */
2762 if (listing & LISTING_SYMBOLS)
2764 extern struct list_info_struct *listing_tail;
2765 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2766 memset (dummy_frag, 0, sizeof(fragS));
2767 dummy_frag->fr_type = rs_fill;
2768 dummy_frag->line = listing_tail;
2769 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2770 dummy_frag->fr_symbol = symbolP;
2772 else
2773 #endif
2774 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2776 #ifdef OBJ_COFF
2777 /* "set" symbols are local unless otherwise specified. */
2778 SF_SET_LOCAL (symbolP);
2779 #endif /* OBJ_COFF */
2781 } /* make a new symbol */
2783 symbol_table_insert (symbolP);
2785 *end_name = delim;
2787 if (equiv
2788 && S_IS_DEFINED (symbolP)
2789 && S_GET_SEGMENT (symbolP) != reg_section)
2790 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2792 pseudo_set (symbolP);
2793 demand_empty_rest_of_line ();
2794 } /* s_set() */
2796 void
2797 s_space (mult)
2798 int mult;
2800 expressionS exp;
2801 expressionS val;
2802 char *p = 0;
2803 char *stop = NULL;
2804 char stopc;
2805 int bytes;
2807 #ifdef md_flush_pending_output
2808 md_flush_pending_output ();
2809 #endif
2811 if (flag_mri)
2812 stop = mri_comment_field (&stopc);
2814 /* In m68k MRI mode, we need to align to a word boundary, unless
2815 this is ds.b. */
2816 if (flag_m68k_mri && mult > 1)
2818 if (now_seg == absolute_section)
2820 abs_section_offset += abs_section_offset & 1;
2821 if (line_label != NULL)
2822 S_SET_VALUE (line_label, abs_section_offset);
2824 else if (mri_common_symbol != NULL)
2826 valueT val;
2828 val = S_GET_VALUE (mri_common_symbol);
2829 if ((val & 1) != 0)
2831 S_SET_VALUE (mri_common_symbol, val + 1);
2832 if (line_label != NULL)
2834 expressionS *symexp;
2836 symexp = symbol_get_value_expression (line_label);
2837 know (symexp->X_op == O_symbol);
2838 know (symexp->X_add_symbol == mri_common_symbol);
2839 symexp->X_add_number += 1;
2843 else
2845 do_align (1, (char *) NULL, 0, 0);
2846 if (line_label != NULL)
2848 symbol_set_frag (line_label, frag_now);
2849 S_SET_VALUE (line_label, frag_now_fix ());
2854 bytes = mult;
2856 expression (&exp);
2858 SKIP_WHITESPACE ();
2859 if (*input_line_pointer == ',')
2861 ++input_line_pointer;
2862 expression (&val);
2864 else
2866 val.X_op = O_constant;
2867 val.X_add_number = 0;
2870 if (val.X_op != O_constant
2871 || val.X_add_number < - 0x80
2872 || val.X_add_number > 0xff
2873 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2875 if (exp.X_op != O_constant)
2876 as_bad (_("Unsupported variable size or fill value"));
2877 else
2879 offsetT i;
2881 if (mult == 0)
2882 mult = 1;
2883 bytes = mult * exp.X_add_number;
2884 for (i = 0; i < exp.X_add_number; i++)
2885 emit_expr (&val, mult);
2888 else
2890 if (exp.X_op == O_constant)
2892 long repeat;
2894 repeat = exp.X_add_number;
2895 if (mult)
2896 repeat *= mult;
2897 bytes = repeat;
2898 if (repeat <= 0)
2900 if (! flag_mri)
2901 as_warn (_(".space repeat count is zero, ignored"));
2902 else if (repeat < 0)
2903 as_warn (_(".space repeat count is negative, ignored"));
2904 goto getout;
2907 /* If we are in the absolute section, just bump the offset. */
2908 if (now_seg == absolute_section)
2910 abs_section_offset += repeat;
2911 goto getout;
2914 /* If we are secretly in an MRI common section, then
2915 creating space just increases the size of the common
2916 symbol. */
2917 if (mri_common_symbol != NULL)
2919 S_SET_VALUE (mri_common_symbol,
2920 S_GET_VALUE (mri_common_symbol) + repeat);
2921 goto getout;
2924 if (!need_pass_2)
2925 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2926 (offsetT) repeat, (char *) 0);
2928 else
2930 if (now_seg == absolute_section)
2932 as_bad (_("space allocation too complex in absolute section"));
2933 subseg_set (text_section, 0);
2935 if (mri_common_symbol != NULL)
2937 as_bad (_("space allocation too complex in common section"));
2938 mri_common_symbol = NULL;
2940 if (!need_pass_2)
2941 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2942 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2945 if (p)
2946 *p = val.X_add_number;
2949 getout:
2951 /* In MRI mode, after an odd number of bytes, we must align to an
2952 even word boundary, unless the next instruction is a dc.b, ds.b
2953 or dcb.b. */
2954 if (flag_mri && (bytes & 1) != 0)
2955 mri_pending_align = 1;
2957 demand_empty_rest_of_line ();
2959 if (flag_mri)
2960 mri_comment_end (stop, stopc);
2963 /* This is like s_space, but the value is a floating point number with
2964 the given precision. This is for the MRI dcb.s pseudo-op and
2965 friends. */
2967 void
2968 s_float_space (float_type)
2969 int float_type;
2971 offsetT count;
2972 int flen;
2973 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2974 char *stop = NULL;
2975 char stopc;
2977 if (flag_mri)
2978 stop = mri_comment_field (&stopc);
2980 count = get_absolute_expression ();
2982 SKIP_WHITESPACE ();
2983 if (*input_line_pointer != ',')
2985 as_bad (_("missing value"));
2986 ignore_rest_of_line ();
2987 if (flag_mri)
2988 mri_comment_end (stop, stopc);
2989 return;
2992 ++input_line_pointer;
2994 SKIP_WHITESPACE ();
2996 /* Skip any 0{letter} that may be present. Don't even check if the
2997 * letter is legal. */
2998 if (input_line_pointer[0] == '0'
2999 && isalpha ((unsigned char) input_line_pointer[1]))
3000 input_line_pointer += 2;
3002 /* Accept :xxxx, where the x's are hex digits, for a floating point
3003 with the exact digits specified. */
3004 if (input_line_pointer[0] == ':')
3006 flen = hex_float (float_type, temp);
3007 if (flen < 0)
3009 ignore_rest_of_line ();
3010 if (flag_mri)
3011 mri_comment_end (stop, stopc);
3012 return;
3015 else
3017 char *err;
3019 err = md_atof (float_type, temp, &flen);
3020 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3021 know (flen > 0);
3022 if (err)
3024 as_bad (_("Bad floating literal: %s"), err);
3025 ignore_rest_of_line ();
3026 if (flag_mri)
3027 mri_comment_end (stop, stopc);
3028 return;
3032 while (--count >= 0)
3034 char *p;
3036 p = frag_more (flen);
3037 memcpy (p, temp, (unsigned int) flen);
3040 demand_empty_rest_of_line ();
3042 if (flag_mri)
3043 mri_comment_end (stop, stopc);
3046 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3048 void
3049 s_struct (ignore)
3050 int ignore ATTRIBUTE_UNUSED;
3052 char *stop = NULL;
3053 char stopc;
3055 if (flag_mri)
3056 stop = mri_comment_field (&stopc);
3057 abs_section_offset = get_absolute_expression ();
3058 subseg_set (absolute_section, 0);
3059 demand_empty_rest_of_line ();
3060 if (flag_mri)
3061 mri_comment_end (stop, stopc);
3064 void
3065 s_text (ignore)
3066 int ignore ATTRIBUTE_UNUSED;
3068 register int temp;
3070 temp = get_absolute_expression ();
3071 subseg_set (text_section, (subsegT) temp);
3072 demand_empty_rest_of_line ();
3073 #ifdef OBJ_VMS
3074 const_flag &= ~IN_DEFAULT_SECTION;
3075 #endif
3076 } /* s_text() */
3079 void
3080 demand_empty_rest_of_line ()
3082 SKIP_WHITESPACE ();
3083 if (is_end_of_line[(unsigned char) *input_line_pointer])
3085 input_line_pointer++;
3087 else
3089 ignore_rest_of_line ();
3091 /* Return having already swallowed end-of-line. */
3092 } /* Return pointing just after end-of-line. */
3094 void
3095 ignore_rest_of_line () /* For suspect lines: gives warning. */
3097 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3099 if (isprint ((unsigned char) *input_line_pointer))
3100 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3101 *input_line_pointer);
3102 else
3103 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3104 *input_line_pointer);
3105 while (input_line_pointer < buffer_limit
3106 && !is_end_of_line[(unsigned char) *input_line_pointer])
3108 input_line_pointer++;
3111 input_line_pointer++; /* Return pointing just after end-of-line. */
3112 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3115 void
3116 discard_rest_of_line ()
3118 while (input_line_pointer < buffer_limit
3119 && !is_end_of_line[(unsigned char) *input_line_pointer])
3121 input_line_pointer++;
3123 input_line_pointer++; /* Return pointing just after end-of-line. */
3124 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3128 * pseudo_set()
3130 * In: Pointer to a symbol.
3131 * Input_line_pointer->expression.
3133 * Out: Input_line_pointer->just after any whitespace after expression.
3134 * Tried to set symbol to value of expression.
3135 * Will change symbols type, value, and frag;
3137 void
3138 pseudo_set (symbolP)
3139 symbolS *symbolP;
3141 expressionS exp;
3142 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3143 int ext;
3144 #endif /* OBJ_AOUT or OBJ_BOUT */
3146 know (symbolP); /* NULL pointer is logic error. */
3147 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3148 ext = S_IS_EXTERNAL (symbolP);
3149 #endif /* OBJ_AOUT or OBJ_BOUT */
3151 (void) expression (&exp);
3153 if (exp.X_op == O_illegal)
3154 as_bad (_("illegal expression; zero assumed"));
3155 else if (exp.X_op == O_absent)
3156 as_bad (_("missing expression; zero assumed"));
3157 else if (exp.X_op == O_big)
3159 if (exp.X_add_number > 0)
3160 as_bad (_("bignum invalid; zero assumed"));
3161 else
3162 as_bad (_("floating point number invalid; zero assumed"));
3164 else if (exp.X_op == O_subtract
3165 && (S_GET_SEGMENT (exp.X_add_symbol)
3166 == S_GET_SEGMENT (exp.X_op_symbol))
3167 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3168 && (symbol_get_frag (exp.X_add_symbol)
3169 == symbol_get_frag (exp.X_op_symbol)))
3171 exp.X_op = O_constant;
3172 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3173 - S_GET_VALUE (exp.X_op_symbol));
3176 switch (exp.X_op)
3178 case O_illegal:
3179 case O_absent:
3180 case O_big:
3181 exp.X_add_number = 0;
3182 /* Fall through. */
3183 case O_constant:
3184 S_SET_SEGMENT (symbolP, absolute_section);
3185 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3186 if (ext)
3187 S_SET_EXTERNAL (symbolP);
3188 else
3189 S_CLEAR_EXTERNAL (symbolP);
3190 #endif /* OBJ_AOUT or OBJ_BOUT */
3191 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3192 if (exp.X_op != O_constant)
3193 symbol_set_frag (symbolP, &zero_address_frag);
3194 break;
3196 case O_register:
3197 S_SET_SEGMENT (symbolP, reg_section);
3198 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3199 symbol_set_frag (symbolP, &zero_address_frag);
3200 break;
3202 case O_symbol:
3203 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3204 || exp.X_add_number != 0)
3205 symbol_set_value_expression (symbolP, &exp);
3206 else if (symbol_section_p (symbolP))
3207 as_bad ("invalid attempt to set value of section symbol");
3208 else
3210 symbolS *s = exp.X_add_symbol;
3212 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3213 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3214 if (ext)
3215 S_SET_EXTERNAL (symbolP);
3216 else
3217 S_CLEAR_EXTERNAL (symbolP);
3218 #endif /* OBJ_AOUT or OBJ_BOUT */
3219 S_SET_VALUE (symbolP,
3220 exp.X_add_number + S_GET_VALUE (s));
3221 symbol_set_frag (symbolP, symbol_get_frag (s));
3222 copy_symbol_attributes (symbolP, s);
3224 break;
3226 default:
3227 /* The value is some complex expression.
3228 FIXME: Should we set the segment to anything? */
3229 symbol_set_value_expression (symbolP, &exp);
3230 break;
3235 * cons()
3237 * CONStruct more frag of .bytes, or .words etc.
3238 * Should need_pass_2 be 1 then emit no frag(s).
3239 * This understands EXPRESSIONS.
3241 * Bug (?)
3243 * This has a split personality. We use expression() to read the
3244 * value. We can detect if the value won't fit in a byte or word.
3245 * But we can't detect if expression() discarded significant digits
3246 * in the case of a long. Not worth the crocks required to fix it.
3249 /* Select a parser for cons expressions. */
3251 /* Some targets need to parse the expression in various fancy ways.
3252 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3253 (for example, the HPPA does this). Otherwise, you can define
3254 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3255 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3256 are defined, which is the normal case, then only simple expressions
3257 are permitted. */
3259 #ifdef TC_M68K
3260 static void
3261 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3262 #endif
3264 #ifndef TC_PARSE_CONS_EXPRESSION
3265 #ifdef BITFIELD_CONS_EXPRESSIONS
3266 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3267 static void
3268 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3269 #endif
3270 #ifdef REPEAT_CONS_EXPRESSIONS
3271 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3272 static void
3273 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3274 #endif
3276 /* If we haven't gotten one yet, just call expression. */
3277 #ifndef TC_PARSE_CONS_EXPRESSION
3278 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3279 #endif
3280 #endif
3282 /* worker to do .byte etc statements */
3283 /* clobbers input_line_pointer, checks */
3284 /* end-of-line. */
3285 static void
3286 cons_worker (nbytes, rva)
3287 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3288 int rva;
3290 int c;
3291 expressionS exp;
3292 char *stop = NULL;
3293 char stopc;
3295 #ifdef md_flush_pending_output
3296 md_flush_pending_output ();
3297 #endif
3299 if (flag_mri)
3300 stop = mri_comment_field (&stopc);
3302 if (is_it_end_of_statement ())
3304 demand_empty_rest_of_line ();
3305 if (flag_mri)
3306 mri_comment_end (stop, stopc);
3307 return;
3310 #ifdef md_cons_align
3311 md_cons_align (nbytes);
3312 #endif
3314 c = 0;
3317 #ifdef TC_M68K
3318 if (flag_m68k_mri)
3319 parse_mri_cons (&exp, (unsigned int) nbytes);
3320 else
3321 #endif
3322 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3324 if (rva)
3326 if (exp.X_op == O_symbol)
3327 exp.X_op = O_symbol_rva;
3328 else
3329 as_fatal (_("rva without symbol"));
3331 emit_expr (&exp, (unsigned int) nbytes);
3332 ++c;
3334 while (*input_line_pointer++ == ',');
3336 /* In MRI mode, after an odd number of bytes, we must align to an
3337 even word boundary, unless the next instruction is a dc.b, ds.b
3338 or dcb.b. */
3339 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3340 mri_pending_align = 1;
3342 input_line_pointer--; /* Put terminator back into stream. */
3344 demand_empty_rest_of_line ();
3346 if (flag_mri)
3347 mri_comment_end (stop, stopc);
3351 void
3352 cons (size)
3353 int size;
3355 cons_worker (size, 0);
3358 void
3359 s_rva (size)
3360 int size;
3362 cons_worker (size, 1);
3365 /* Put the contents of expression EXP into the object file using
3366 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3368 void
3369 emit_expr (exp, nbytes)
3370 expressionS *exp;
3371 unsigned int nbytes;
3373 operatorT op;
3374 register char *p;
3375 valueT extra_digit = 0;
3377 /* Don't do anything if we are going to make another pass. */
3378 if (need_pass_2)
3379 return;
3381 #ifndef NO_LISTING
3382 #ifdef OBJ_ELF
3383 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3384 appear as a four byte positive constant in the .line section,
3385 followed by a 2 byte 0xffff. Look for that case here. */
3387 static int dwarf_line = -1;
3389 if (strcmp (segment_name (now_seg), ".line") != 0)
3390 dwarf_line = -1;
3391 else if (dwarf_line >= 0
3392 && nbytes == 2
3393 && exp->X_op == O_constant
3394 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3395 listing_source_line ((unsigned int) dwarf_line);
3396 else if (nbytes == 4
3397 && exp->X_op == O_constant
3398 && exp->X_add_number >= 0)
3399 dwarf_line = exp->X_add_number;
3400 else
3401 dwarf_line = -1;
3404 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3405 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3406 AT_sibling (0x12) followed by a four byte address of the sibling
3407 followed by a 2 byte AT_name (0x38) followed by the name of the
3408 file. We look for that case here. */
3410 static int dwarf_file = 0;
3412 if (strcmp (segment_name (now_seg), ".debug") != 0)
3413 dwarf_file = 0;
3414 else if (dwarf_file == 0
3415 && nbytes == 2
3416 && exp->X_op == O_constant
3417 && exp->X_add_number == 0x11)
3418 dwarf_file = 1;
3419 else if (dwarf_file == 1
3420 && nbytes == 2
3421 && exp->X_op == O_constant
3422 && exp->X_add_number == 0x12)
3423 dwarf_file = 2;
3424 else if (dwarf_file == 2
3425 && nbytes == 4)
3426 dwarf_file = 3;
3427 else if (dwarf_file == 3
3428 && nbytes == 2
3429 && exp->X_op == O_constant
3430 && exp->X_add_number == 0x38)
3431 dwarf_file = 4;
3432 else
3433 dwarf_file = 0;
3435 /* The variable dwarf_file_string tells stringer that the string
3436 may be the name of the source file. */
3437 if (dwarf_file == 4)
3438 dwarf_file_string = 1;
3439 else
3440 dwarf_file_string = 0;
3442 #endif
3443 #endif
3445 if (check_eh_frame (exp, &nbytes))
3446 return;
3448 op = exp->X_op;
3450 /* Allow `.word 0' in the absolute section. */
3451 if (now_seg == absolute_section)
3453 if (op != O_constant || exp->X_add_number != 0)
3454 as_bad (_("attempt to store value in absolute section"));
3455 abs_section_offset += nbytes;
3456 return;
3459 /* Handle a negative bignum. */
3460 if (op == O_uminus
3461 && exp->X_add_number == 0
3462 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3463 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3465 int i;
3466 unsigned long carry;
3468 exp = symbol_get_value_expression (exp->X_add_symbol);
3470 /* Negate the bignum: one's complement each digit and add 1. */
3471 carry = 1;
3472 for (i = 0; i < exp->X_add_number; i++)
3474 unsigned long next;
3476 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3477 & LITTLENUM_MASK)
3478 + carry);
3479 generic_bignum[i] = next & LITTLENUM_MASK;
3480 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3483 /* We can ignore any carry out, because it will be handled by
3484 extra_digit if it is needed. */
3486 extra_digit = (valueT) -1;
3487 op = O_big;
3490 if (op == O_absent || op == O_illegal)
3492 as_warn (_("zero assumed for missing expression"));
3493 exp->X_add_number = 0;
3494 op = O_constant;
3496 else if (op == O_big && exp->X_add_number <= 0)
3498 as_bad (_("floating point number invalid; zero assumed"));
3499 exp->X_add_number = 0;
3500 op = O_constant;
3502 else if (op == O_register)
3504 as_warn (_("register value used as expression"));
3505 op = O_constant;
3508 p = frag_more ((int) nbytes);
3510 #ifndef WORKING_DOT_WORD
3511 /* If we have the difference of two symbols in a word, save it on
3512 the broken_words list. See the code in write.c. */
3513 if (op == O_subtract && nbytes == 2)
3515 struct broken_word *x;
3517 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3518 x->next_broken_word = broken_words;
3519 broken_words = x;
3520 x->seg = now_seg;
3521 x->subseg = now_subseg;
3522 x->frag = frag_now;
3523 x->word_goes_here = p;
3524 x->dispfrag = 0;
3525 x->add = exp->X_add_symbol;
3526 x->sub = exp->X_op_symbol;
3527 x->addnum = exp->X_add_number;
3528 x->added = 0;
3529 new_broken_words++;
3530 return;
3532 #endif
3534 /* If we have an integer, but the number of bytes is too large to
3535 pass to md_number_to_chars, handle it as a bignum. */
3536 if (op == O_constant && nbytes > sizeof (valueT))
3538 valueT val;
3539 int gencnt;
3541 if (! exp->X_unsigned && exp->X_add_number < 0)
3542 extra_digit = (valueT) -1;
3543 val = (valueT) exp->X_add_number;
3544 gencnt = 0;
3547 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3548 val >>= LITTLENUM_NUMBER_OF_BITS;
3549 ++gencnt;
3551 while (val != 0);
3552 op = exp->X_op = O_big;
3553 exp->X_add_number = gencnt;
3556 if (op == O_constant)
3558 register valueT get;
3559 register valueT use;
3560 register valueT mask;
3561 valueT hibit;
3562 register valueT unmask;
3564 /* JF << of >= number of bits in the object is undefined. In
3565 particular SPARC (Sun 4) has problems */
3566 if (nbytes >= sizeof (valueT))
3568 mask = 0;
3569 if (nbytes > sizeof (valueT))
3570 hibit = 0;
3571 else
3572 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3574 else
3576 /* Don't store these bits. */
3577 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3578 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3581 unmask = ~mask; /* Do store these bits. */
3583 #ifdef NEVER
3584 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3585 mask = ~(unmask >> 1); /* Includes sign bit now. */
3586 #endif
3588 get = exp->X_add_number;
3589 use = get & unmask;
3590 if ((get & mask) != 0
3591 && ((get & mask) != mask
3592 || (get & hibit) == 0))
3593 { /* Leading bits contain both 0s & 1s. */
3594 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3595 (unsigned long) get, (unsigned long) use);
3597 /* put bytes in right order. */
3598 md_number_to_chars (p, use, (int) nbytes);
3600 else if (op == O_big)
3602 unsigned int size;
3603 LITTLENUM_TYPE *nums;
3605 know (nbytes % CHARS_PER_LITTLENUM == 0);
3607 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3608 if (nbytes < size)
3610 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3611 size = nbytes;
3614 if (target_big_endian)
3616 while (nbytes > size)
3618 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3619 nbytes -= CHARS_PER_LITTLENUM;
3620 p += CHARS_PER_LITTLENUM;
3623 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3624 while (size > 0)
3626 --nums;
3627 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3628 size -= CHARS_PER_LITTLENUM;
3629 p += CHARS_PER_LITTLENUM;
3632 else
3634 nums = generic_bignum;
3635 while (size > 0)
3637 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3638 ++nums;
3639 size -= CHARS_PER_LITTLENUM;
3640 p += CHARS_PER_LITTLENUM;
3641 nbytes -= CHARS_PER_LITTLENUM;
3644 while (nbytes > 0)
3646 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3647 nbytes -= CHARS_PER_LITTLENUM;
3648 p += CHARS_PER_LITTLENUM;
3652 else
3654 memset (p, 0, nbytes);
3656 /* Now we need to generate a fixS to record the symbol value.
3657 This is easy for BFD. For other targets it can be more
3658 complex. For very complex cases (currently, the HPPA and
3659 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3660 want. For simpler cases, you can define TC_CONS_RELOC to be
3661 the name of the reloc code that should be stored in the fixS.
3662 If neither is defined, the code uses NO_RELOC if it is
3663 defined, and otherwise uses 0. */
3665 #ifdef BFD_ASSEMBLER
3666 #ifdef TC_CONS_FIX_NEW
3667 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3668 #else
3670 bfd_reloc_code_real_type r;
3672 switch (nbytes)
3674 case 1:
3675 r = BFD_RELOC_8;
3676 break;
3677 case 2:
3678 r = BFD_RELOC_16;
3679 break;
3680 case 4:
3681 r = BFD_RELOC_32;
3682 break;
3683 case 8:
3684 r = BFD_RELOC_64;
3685 break;
3686 default:
3687 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3688 r = BFD_RELOC_32;
3689 break;
3691 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3692 0, r);
3694 #endif
3695 #else
3696 #ifdef TC_CONS_FIX_NEW
3697 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3698 #else
3699 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3700 it is defined, otherwise use NO_RELOC if it is defined,
3701 otherwise use 0. */
3702 #ifndef TC_CONS_RELOC
3703 #ifdef NO_RELOC
3704 #define TC_CONS_RELOC NO_RELOC
3705 #else
3706 #define TC_CONS_RELOC 0
3707 #endif
3708 #endif
3709 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3710 TC_CONS_RELOC);
3711 #endif /* TC_CONS_FIX_NEW */
3712 #endif /* BFD_ASSEMBLER */
3716 #ifdef BITFIELD_CONS_EXPRESSIONS
3718 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3719 w:x,y:z, where w and y are bitwidths and x and y are values. They
3720 then pack them all together. We do a little better in that we allow
3721 them in words, longs, etc. and we'll pack them in target byte order
3722 for you.
3724 The rules are: pack least significat bit first, if a field doesn't
3725 entirely fit, put it in the next unit. Overflowing the bitfield is
3726 explicitly *not* even a warning. The bitwidth should be considered
3727 a "mask".
3729 To use this function the tc-XXX.h file should define
3730 BITFIELD_CONS_EXPRESSIONS. */
3732 static void
3733 parse_bitfield_cons (exp, nbytes)
3734 expressionS *exp;
3735 unsigned int nbytes;
3737 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3738 char *hold = input_line_pointer;
3740 (void) expression (exp);
3742 if (*input_line_pointer == ':')
3743 { /* bitfields */
3744 long value = 0;
3746 for (;;)
3748 unsigned long width;
3750 if (*input_line_pointer != ':')
3752 input_line_pointer = hold;
3753 break;
3754 } /* next piece is not a bitfield */
3756 /* In the general case, we can't allow
3757 full expressions with symbol
3758 differences and such. The relocation
3759 entries for symbols not defined in this
3760 assembly would require arbitrary field
3761 widths, positions, and masks which most
3762 of our current object formats don't
3763 support.
3765 In the specific case where a symbol
3766 *is* defined in this assembly, we
3767 *could* build fixups and track it, but
3768 this could lead to confusion for the
3769 backends. I'm lazy. I'll take any
3770 SEG_ABSOLUTE. I think that means that
3771 you can use a previous .set or
3772 .equ type symbol. xoxorich. */
3774 if (exp->X_op == O_absent)
3776 as_warn (_("using a bit field width of zero"));
3777 exp->X_add_number = 0;
3778 exp->X_op = O_constant;
3779 } /* implied zero width bitfield */
3781 if (exp->X_op != O_constant)
3783 *input_line_pointer = '\0';
3784 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3785 *input_line_pointer = ':';
3786 demand_empty_rest_of_line ();
3787 return;
3788 } /* too complex */
3790 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3792 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3793 width, nbytes, (BITS_PER_CHAR * nbytes));
3794 width = BITS_PER_CHAR * nbytes;
3795 } /* too big */
3797 if (width > bits_available)
3799 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3800 input_line_pointer = hold;
3801 exp->X_add_number = value;
3802 break;
3803 } /* won't fit */
3805 hold = ++input_line_pointer; /* skip ':' */
3807 (void) expression (exp);
3808 if (exp->X_op != O_constant)
3810 char cache = *input_line_pointer;
3812 *input_line_pointer = '\0';
3813 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3814 *input_line_pointer = cache;
3815 demand_empty_rest_of_line ();
3816 return;
3817 } /* too complex */
3819 value |= ((~(-1 << width) & exp->X_add_number)
3820 << ((BITS_PER_CHAR * nbytes) - bits_available));
3822 if ((bits_available -= width) == 0
3823 || is_it_end_of_statement ()
3824 || *input_line_pointer != ',')
3826 break;
3827 } /* all the bitfields we're gonna get */
3829 hold = ++input_line_pointer;
3830 (void) expression (exp);
3831 } /* forever loop */
3833 exp->X_add_number = value;
3834 exp->X_op = O_constant;
3835 exp->X_unsigned = 1;
3836 } /* if looks like a bitfield */
3837 } /* parse_bitfield_cons() */
3839 #endif /* BITFIELD_CONS_EXPRESSIONS */
3841 /* Handle an MRI style string expression. */
3843 #ifdef TC_M68K
3844 static void
3845 parse_mri_cons (exp, nbytes)
3846 expressionS *exp;
3847 unsigned int nbytes;
3849 if (*input_line_pointer != '\''
3850 && (input_line_pointer[1] != '\''
3851 || (*input_line_pointer != 'A'
3852 && *input_line_pointer != 'E')))
3853 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3854 else
3856 unsigned int scan;
3857 unsigned int result = 0;
3859 /* An MRI style string. Cut into as many bytes as will fit into
3860 a nbyte chunk, left justify if necessary, and separate with
3861 commas so we can try again later. */
3862 if (*input_line_pointer == 'A')
3863 ++input_line_pointer;
3864 else if (*input_line_pointer == 'E')
3866 as_bad (_("EBCDIC constants are not supported"));
3867 ++input_line_pointer;
3870 input_line_pointer++;
3871 for (scan = 0; scan < nbytes; scan++)
3873 if (*input_line_pointer == '\'')
3875 if (input_line_pointer[1] == '\'')
3877 input_line_pointer++;
3879 else
3880 break;
3882 result = (result << 8) | (*input_line_pointer++);
3885 /* Left justify */
3886 while (scan < nbytes)
3888 result <<= 8;
3889 scan++;
3891 /* Create correct expression */
3892 exp->X_op = O_constant;
3893 exp->X_add_number = result;
3894 /* Fake it so that we can read the next char too */
3895 if (input_line_pointer[0] != '\'' ||
3896 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3898 input_line_pointer -= 2;
3899 input_line_pointer[0] = ',';
3900 input_line_pointer[1] = '\'';
3902 else
3903 input_line_pointer++;
3906 #endif /* TC_M68K */
3908 #ifdef REPEAT_CONS_EXPRESSIONS
3910 /* Parse a repeat expression for cons. This is used by the MIPS
3911 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3912 object file COUNT times.
3914 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3916 static void
3917 parse_repeat_cons (exp, nbytes)
3918 expressionS *exp;
3919 unsigned int nbytes;
3921 expressionS count;
3922 register int i;
3924 expression (exp);
3926 if (*input_line_pointer != ':')
3928 /* No repeat count. */
3929 return;
3932 ++input_line_pointer;
3933 expression (&count);
3934 if (count.X_op != O_constant
3935 || count.X_add_number <= 0)
3937 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3938 return;
3941 /* The cons function is going to output this expression once. So we
3942 output it count - 1 times. */
3943 for (i = count.X_add_number - 1; i > 0; i--)
3944 emit_expr (exp, nbytes);
3947 #endif /* REPEAT_CONS_EXPRESSIONS */
3949 /* Parse a floating point number represented as a hex constant. This
3950 permits users to specify the exact bits they want in the floating
3951 point number. */
3953 static int
3954 hex_float (float_type, bytes)
3955 int float_type;
3956 char *bytes;
3958 int length;
3959 int i;
3961 switch (float_type)
3963 case 'f':
3964 case 'F':
3965 case 's':
3966 case 'S':
3967 length = 4;
3968 break;
3970 case 'd':
3971 case 'D':
3972 case 'r':
3973 case 'R':
3974 length = 8;
3975 break;
3977 case 'x':
3978 case 'X':
3979 length = 12;
3980 break;
3982 case 'p':
3983 case 'P':
3984 length = 12;
3985 break;
3987 default:
3988 as_bad (_("Unknown floating type type '%c'"), float_type);
3989 return -1;
3992 /* It would be nice if we could go through expression to parse the
3993 hex constant, but if we get a bignum it's a pain to sort it into
3994 the buffer correctly. */
3995 i = 0;
3996 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3998 int d;
4000 /* The MRI assembler accepts arbitrary underscores strewn about
4001 through the hex constant, so we ignore them as well. */
4002 if (*input_line_pointer == '_')
4004 ++input_line_pointer;
4005 continue;
4008 if (i >= length)
4010 as_warn (_("Floating point constant too large"));
4011 return -1;
4013 d = hex_value (*input_line_pointer) << 4;
4014 ++input_line_pointer;
4015 while (*input_line_pointer == '_')
4016 ++input_line_pointer;
4017 if (hex_p (*input_line_pointer))
4019 d += hex_value (*input_line_pointer);
4020 ++input_line_pointer;
4022 if (target_big_endian)
4023 bytes[i] = d;
4024 else
4025 bytes[length - i - 1] = d;
4026 ++i;
4029 if (i < length)
4031 if (target_big_endian)
4032 memset (bytes + i, 0, length - i);
4033 else
4034 memset (bytes, 0, length - i);
4037 return length;
4041 * float_cons()
4043 * CONStruct some more frag chars of .floats .ffloats etc.
4044 * Makes 0 or more new frags.
4045 * If need_pass_2 == 1, no frags are emitted.
4046 * This understands only floating literals, not expressions. Sorry.
4048 * A floating constant is defined by atof_generic(), except it is preceded
4049 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4050 * reading, I decided to be incompatible. This always tries to give you
4051 * rounded bits to the precision of the pseudo-op. Former AS did premature
4052 * truncatation, restored noisy bits instead of trailing 0s AND gave you
4053 * a choice of 2 flavours of noise according to which of 2 floating-point
4054 * scanners you directed AS to use.
4056 * In: input_line_pointer->whitespace before, or '0' of flonum.
4060 void
4061 float_cons (float_type)
4062 /* Clobbers input_line-pointer, checks end-of-line. */
4063 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4065 register char *p;
4066 int length; /* Number of chars in an object. */
4067 register char *err; /* Error from scanning floating literal. */
4068 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4070 if (is_it_end_of_statement ())
4072 demand_empty_rest_of_line ();
4073 return;
4076 #ifdef md_flush_pending_output
4077 md_flush_pending_output ();
4078 #endif
4082 /* input_line_pointer->1st char of a flonum (we hope!). */
4083 SKIP_WHITESPACE ();
4085 /* Skip any 0{letter} that may be present. Don't even check if the
4086 * letter is legal. Someone may invent a "z" format and this routine
4087 * has no use for such information. Lusers beware: you get
4088 * diagnostics if your input is ill-conditioned.
4090 if (input_line_pointer[0] == '0'
4091 && isalpha ((unsigned char) input_line_pointer[1]))
4092 input_line_pointer += 2;
4094 /* Accept :xxxx, where the x's are hex digits, for a floating
4095 point with the exact digits specified. */
4096 if (input_line_pointer[0] == ':')
4098 ++input_line_pointer;
4099 length = hex_float (float_type, temp);
4100 if (length < 0)
4102 ignore_rest_of_line ();
4103 return;
4106 else
4108 err = md_atof (float_type, temp, &length);
4109 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4110 know (length > 0);
4111 if (err)
4113 as_bad (_("Bad floating literal: %s"), err);
4114 ignore_rest_of_line ();
4115 return;
4119 if (!need_pass_2)
4121 int count;
4123 count = 1;
4125 #ifdef REPEAT_CONS_EXPRESSIONS
4126 if (*input_line_pointer == ':')
4128 expressionS count_exp;
4130 ++input_line_pointer;
4131 expression (&count_exp);
4132 if (count_exp.X_op != O_constant
4133 || count_exp.X_add_number <= 0)
4135 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4137 else
4138 count = count_exp.X_add_number;
4140 #endif
4142 while (--count >= 0)
4144 p = frag_more (length);
4145 memcpy (p, temp, (unsigned int) length);
4148 SKIP_WHITESPACE ();
4150 while (*input_line_pointer++ == ',');
4152 --input_line_pointer; /* Put terminator back into stream. */
4153 demand_empty_rest_of_line ();
4154 } /* float_cons() */
4156 /* Return the size of a LEB128 value */
4158 static inline int
4159 sizeof_sleb128 (value)
4160 offsetT value;
4162 register int size = 0;
4163 register unsigned byte;
4167 byte = (value & 0x7f);
4168 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4169 Fortunately, we can structure things so that the extra work reduces
4170 to a noop on systems that do things "properly". */
4171 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4172 size += 1;
4174 while (!(((value == 0) && ((byte & 0x40) == 0))
4175 || ((value == -1) && ((byte & 0x40) != 0))));
4177 return size;
4180 static inline int
4181 sizeof_uleb128 (value)
4182 valueT value;
4184 register int size = 0;
4185 register unsigned byte;
4189 byte = (value & 0x7f);
4190 value >>= 7;
4191 size += 1;
4193 while (value != 0);
4195 return size;
4199 sizeof_leb128 (value, sign)
4200 valueT value;
4201 int sign;
4203 if (sign)
4204 return sizeof_sleb128 ((offsetT) value);
4205 else
4206 return sizeof_uleb128 (value);
4209 /* Output a LEB128 value. */
4211 static inline int
4212 output_sleb128 (p, value)
4213 char *p;
4214 offsetT value;
4216 register char *orig = p;
4217 register int more;
4221 unsigned byte = (value & 0x7f);
4223 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4224 Fortunately, we can structure things so that the extra work reduces
4225 to a noop on systems that do things "properly". */
4226 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4228 more = !((((value == 0) && ((byte & 0x40) == 0))
4229 || ((value == -1) && ((byte & 0x40) != 0))));
4230 if (more)
4231 byte |= 0x80;
4233 *p++ = byte;
4235 while (more);
4237 return p - orig;
4240 static inline int
4241 output_uleb128 (p, value)
4242 char *p;
4243 valueT value;
4245 char *orig = p;
4249 unsigned byte = (value & 0x7f);
4250 value >>= 7;
4251 if (value != 0)
4252 /* More bytes to follow. */
4253 byte |= 0x80;
4255 *p++ = byte;
4257 while (value != 0);
4259 return p - orig;
4263 output_leb128 (p, value, sign)
4264 char *p;
4265 valueT value;
4266 int sign;
4268 if (sign)
4269 return output_sleb128 (p, (offsetT) value);
4270 else
4271 return output_uleb128 (p, value);
4274 /* Do the same for bignums. We combine sizeof with output here in that
4275 we don't output for NULL values of P. It isn't really as critical as
4276 for "normal" values that this be streamlined. */
4278 static inline int
4279 output_big_sleb128 (p, bignum, size)
4280 char *p;
4281 LITTLENUM_TYPE *bignum;
4282 int size;
4284 char *orig = p;
4285 valueT val = 0;
4286 int loaded = 0;
4287 unsigned byte;
4289 /* Strip leading sign extensions off the bignum. */
4290 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4291 size--;
4295 if (loaded < 7 && size > 0)
4297 val |= (*bignum << loaded);
4298 loaded += 8 * CHARS_PER_LITTLENUM;
4299 size--;
4300 bignum++;
4303 byte = val & 0x7f;
4304 loaded -= 7;
4305 val >>= 7;
4307 if (size == 0)
4309 if ((val == 0 && (byte & 0x40) == 0)
4310 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4311 && (byte & 0x40) != 0))
4312 byte |= 0x80;
4315 if (orig)
4316 *p = byte;
4317 p++;
4319 while (byte & 0x80);
4321 return p - orig;
4324 static inline int
4325 output_big_uleb128 (p, bignum, size)
4326 char *p;
4327 LITTLENUM_TYPE *bignum;
4328 int size;
4330 char *orig = p;
4331 valueT val = 0;
4332 int loaded = 0;
4333 unsigned byte;
4335 /* Strip leading zeros off the bignum. */
4336 /* XXX: Is this needed? */
4337 while (size > 0 && bignum[size-1] == 0)
4338 size--;
4342 if (loaded < 7 && size > 0)
4344 val |= (*bignum << loaded);
4345 loaded += 8 * CHARS_PER_LITTLENUM;
4346 size--;
4347 bignum++;
4350 byte = val & 0x7f;
4351 loaded -= 7;
4352 val >>= 7;
4354 if (size > 0 || val)
4355 byte |= 0x80;
4357 if (orig)
4358 *p = byte;
4359 p++;
4361 while (byte & 0x80);
4363 return p - orig;
4366 static int
4367 output_big_leb128 (p, bignum, size, sign)
4368 char *p;
4369 LITTLENUM_TYPE *bignum;
4370 int size, sign;
4372 if (sign)
4373 return output_big_sleb128 (p, bignum, size);
4374 else
4375 return output_big_uleb128 (p, bignum, size);
4378 /* Generate the appropriate fragments for a given expression to emit a
4379 leb128 value. */
4381 void
4382 emit_leb128_expr(exp, sign)
4383 expressionS *exp;
4384 int sign;
4386 operatorT op = exp->X_op;
4388 if (op == O_absent || op == O_illegal)
4390 as_warn (_("zero assumed for missing expression"));
4391 exp->X_add_number = 0;
4392 op = O_constant;
4394 else if (op == O_big && exp->X_add_number <= 0)
4396 as_bad (_("floating point number invalid; zero assumed"));
4397 exp->X_add_number = 0;
4398 op = O_constant;
4400 else if (op == O_register)
4402 as_warn (_("register value used as expression"));
4403 op = O_constant;
4406 if (op == O_constant)
4408 /* If we've got a constant, emit the thing directly right now. */
4410 valueT value = exp->X_add_number;
4411 int size;
4412 char *p;
4414 size = sizeof_leb128 (value, sign);
4415 p = frag_more (size);
4416 output_leb128 (p, value, sign);
4418 else if (op == O_big)
4420 /* O_big is a different sort of constant. */
4422 int size;
4423 char *p;
4425 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4426 p = frag_more (size);
4427 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4429 else
4431 /* Otherwise, we have to create a variable sized fragment and
4432 resolve things later. */
4434 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4435 make_expr_symbol (exp), 0, (char *) NULL);
4439 /* Parse the .sleb128 and .uleb128 pseudos. */
4441 void
4442 s_leb128 (sign)
4443 int sign;
4445 expressionS exp;
4447 do {
4448 expression (&exp);
4449 emit_leb128_expr (&exp, sign);
4450 } while (*input_line_pointer++ == ',');
4452 input_line_pointer--;
4453 demand_empty_rest_of_line ();
4457 * stringer()
4459 * We read 0 or more ',' separated, double-quoted strings.
4461 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4465 void
4466 stringer (append_zero) /* Worker to do .ascii etc statements. */
4467 /* Checks end-of-line. */
4468 register int append_zero; /* 0: don't append '\0', else 1 */
4470 register unsigned int c;
4471 char *start;
4473 #ifdef md_flush_pending_output
4474 md_flush_pending_output ();
4475 #endif
4478 * The following awkward logic is to parse ZERO or more strings,
4479 * comma separated. Recall a string expression includes spaces
4480 * before the opening '\"' and spaces after the closing '\"'.
4481 * We fake a leading ',' if there is (supposed to be)
4482 * a 1st, expression. We keep demanding expressions for each
4483 * ','.
4485 if (is_it_end_of_statement ())
4487 c = 0; /* Skip loop. */
4488 ++input_line_pointer; /* Compensate for end of loop. */
4490 else
4492 c = ','; /* Do loop. */
4494 while (c == ',' || c == '<' || c == '"')
4496 SKIP_WHITESPACE ();
4497 switch (*input_line_pointer)
4499 case '\"':
4500 ++input_line_pointer; /*->1st char of string. */
4501 start = input_line_pointer;
4502 while (is_a_char (c = next_char_of_string ()))
4504 FRAG_APPEND_1_CHAR (c);
4506 if (append_zero)
4508 FRAG_APPEND_1_CHAR (0);
4510 know (input_line_pointer[-1] == '\"');
4512 #ifndef NO_LISTING
4513 #ifdef OBJ_ELF
4514 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4515 will emit .string with a filename in the .debug section
4516 after a sequence of constants. See the comment in
4517 emit_expr for the sequence. emit_expr will set
4518 dwarf_file_string to non-zero if this string might be a
4519 source file name. */
4520 if (strcmp (segment_name (now_seg), ".debug") != 0)
4521 dwarf_file_string = 0;
4522 else if (dwarf_file_string)
4524 c = input_line_pointer[-1];
4525 input_line_pointer[-1] = '\0';
4526 listing_source_file (start);
4527 input_line_pointer[-1] = c;
4529 #endif
4530 #endif
4532 break;
4533 case '<':
4534 input_line_pointer++;
4535 c = get_single_number ();
4536 FRAG_APPEND_1_CHAR (c);
4537 if (*input_line_pointer != '>')
4539 as_bad (_("Expected <nn>"));
4541 input_line_pointer++;
4542 break;
4543 case ',':
4544 input_line_pointer++;
4545 break;
4547 SKIP_WHITESPACE ();
4548 c = *input_line_pointer;
4551 demand_empty_rest_of_line ();
4552 } /* stringer() */
4554 /* FIXME-SOMEDAY: I had trouble here on characters with the
4555 high bits set. We'll probably also have trouble with
4556 multibyte chars, wide chars, etc. Also be careful about
4557 returning values bigger than 1 byte. xoxorich. */
4559 unsigned int
4560 next_char_of_string ()
4562 register unsigned int c;
4564 c = *input_line_pointer++ & CHAR_MASK;
4565 switch (c)
4567 case '\"':
4568 c = NOT_A_CHAR;
4569 break;
4571 case '\n':
4572 as_warn (_("Unterminated string: Newline inserted."));
4573 bump_line_counters ();
4574 break;
4576 #ifndef NO_STRING_ESCAPES
4577 case '\\':
4578 switch (c = *input_line_pointer++)
4580 case 'b':
4581 c = '\b';
4582 break;
4584 case 'f':
4585 c = '\f';
4586 break;
4588 case 'n':
4589 c = '\n';
4590 break;
4592 case 'r':
4593 c = '\r';
4594 break;
4596 case 't':
4597 c = '\t';
4598 break;
4600 case 'v':
4601 c = '\013';
4602 break;
4604 case '\\':
4605 case '"':
4606 break; /* As itself. */
4608 case '0':
4609 case '1':
4610 case '2':
4611 case '3':
4612 case '4':
4613 case '5':
4614 case '6':
4615 case '7':
4616 case '8':
4617 case '9':
4619 long number;
4620 int i;
4622 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4624 number = number * 8 + c - '0';
4626 c = number & 0xff;
4628 --input_line_pointer;
4629 break;
4631 case 'x':
4632 case 'X':
4634 long number;
4636 number = 0;
4637 c = *input_line_pointer++;
4638 while (isxdigit (c))
4640 if (isdigit (c))
4641 number = number * 16 + c - '0';
4642 else if (isupper (c))
4643 number = number * 16 + c - 'A' + 10;
4644 else
4645 number = number * 16 + c - 'a' + 10;
4646 c = *input_line_pointer++;
4648 c = number & 0xff;
4649 --input_line_pointer;
4651 break;
4653 case '\n':
4654 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4655 as_warn (_("Unterminated string: Newline inserted."));
4656 c = '\n';
4657 bump_line_counters ();
4658 break;
4660 default:
4662 #ifdef ONLY_STANDARD_ESCAPES
4663 as_bad (_("Bad escaped character in string, '?' assumed"));
4664 c = '?';
4665 #endif /* ONLY_STANDARD_ESCAPES */
4667 break;
4668 } /* switch on escaped char */
4669 break;
4670 #endif /* ! defined (NO_STRING_ESCAPES) */
4672 default:
4673 break;
4674 } /* switch on char */
4675 return (c);
4676 } /* next_char_of_string() */
4678 static segT
4679 get_segmented_expression (expP)
4680 register expressionS *expP;
4682 register segT retval;
4684 retval = expression (expP);
4685 if (expP->X_op == O_illegal
4686 || expP->X_op == O_absent
4687 || expP->X_op == O_big)
4689 as_bad (_("expected address expression; zero assumed"));
4690 expP->X_op = O_constant;
4691 expP->X_add_number = 0;
4692 retval = absolute_section;
4694 return retval;
4697 static segT
4698 get_known_segmented_expression (expP)
4699 register expressionS *expP;
4701 register segT retval;
4703 if ((retval = get_segmented_expression (expP)) == undefined_section)
4705 /* There is no easy way to extract the undefined symbol from the
4706 expression. */
4707 if (expP->X_add_symbol != NULL
4708 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4709 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4710 S_GET_NAME (expP->X_add_symbol));
4711 else
4712 as_warn (_("some symbol undefined; zero assumed"));
4713 retval = absolute_section;
4714 expP->X_op = O_constant;
4715 expP->X_add_number = 0;
4717 know (retval == absolute_section || SEG_NORMAL (retval));
4718 return (retval);
4719 } /* get_known_segmented_expression() */
4721 offsetT
4722 get_absolute_expression ()
4724 expressionS exp;
4726 expression (&exp);
4727 if (exp.X_op != O_constant)
4729 if (exp.X_op != O_absent)
4730 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4731 exp.X_add_number = 0;
4733 return exp.X_add_number;
4736 char /* return terminator */
4737 get_absolute_expression_and_terminator (val_pointer)
4738 long *val_pointer; /* return value of expression */
4740 /* FIXME: val_pointer should probably be offsetT *. */
4741 *val_pointer = (long) get_absolute_expression ();
4742 return (*input_line_pointer++);
4746 * demand_copy_C_string()
4748 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4749 * Give a warning if that happens.
4751 char *
4752 demand_copy_C_string (len_pointer)
4753 int *len_pointer;
4755 register char *s;
4757 if ((s = demand_copy_string (len_pointer)) != 0)
4759 register int len;
4761 for (len = *len_pointer; len > 0; len--)
4763 if (*s == 0)
4765 s = 0;
4766 len = 1;
4767 *len_pointer = 0;
4768 as_bad (_("This string may not contain \'\\0\'"));
4772 return s;
4776 * demand_copy_string()
4778 * Demand string, but return a safe (=private) copy of the string.
4779 * Return NULL if we can't read a string here.
4781 char *
4782 demand_copy_string (lenP)
4783 int *lenP;
4785 register unsigned int c;
4786 register int len;
4787 char *retval;
4789 len = 0;
4790 SKIP_WHITESPACE ();
4791 if (*input_line_pointer == '\"')
4793 input_line_pointer++; /* Skip opening quote. */
4795 while (is_a_char (c = next_char_of_string ()))
4797 obstack_1grow (&notes, c);
4798 len++;
4800 /* JF this next line is so demand_copy_C_string will return a
4801 null terminated string. */
4802 obstack_1grow (&notes, '\0');
4803 retval = obstack_finish (&notes);
4805 else
4807 as_warn (_("Missing string"));
4808 retval = NULL;
4809 ignore_rest_of_line ();
4811 *lenP = len;
4812 return (retval);
4813 } /* demand_copy_string() */
4816 * is_it_end_of_statement()
4818 * In: Input_line_pointer->next character.
4820 * Do: Skip input_line_pointer over all whitespace.
4822 * Out: 1 if input_line_pointer->end-of-line.
4824 int
4825 is_it_end_of_statement ()
4827 SKIP_WHITESPACE ();
4828 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4829 } /* is_it_end_of_statement() */
4831 void
4832 equals (sym_name, reassign)
4833 char *sym_name;
4834 int reassign;
4836 register symbolS *symbolP; /* symbol we are working with */
4837 char *stop = NULL;
4838 char stopc;
4840 input_line_pointer++;
4841 if (*input_line_pointer == '=')
4842 input_line_pointer++;
4844 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4845 input_line_pointer++;
4847 if (flag_mri)
4848 stop = mri_comment_field (&stopc);
4850 if (sym_name[0] == '.' && sym_name[1] == '\0')
4852 /* Turn '. = mumble' into a .org mumble */
4853 register segT segment;
4854 expressionS exp;
4856 segment = get_known_segmented_expression (&exp);
4857 if (!need_pass_2)
4858 do_org (segment, &exp, 0);
4860 else
4862 symbolP = symbol_find_or_make (sym_name);
4863 /* Permit register names to be redefined. */
4864 if (! reassign
4865 && S_IS_DEFINED (symbolP)
4866 && S_GET_SEGMENT (symbolP) != reg_section)
4867 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4868 pseudo_set (symbolP);
4871 if (flag_mri)
4873 ignore_rest_of_line (); /* check garbage after the expression */
4874 mri_comment_end (stop, stopc);
4876 } /* equals() */
4878 /* .include -- include a file at this point. */
4880 /* ARGSUSED */
4881 void
4882 s_include (arg)
4883 int arg ATTRIBUTE_UNUSED;
4885 char *filename;
4886 int i;
4887 FILE *try;
4888 char *path;
4890 if (! flag_m68k_mri)
4892 filename = demand_copy_string (&i);
4893 if (filename == NULL)
4895 /* demand_copy_string has already printed an error and
4896 called ignore_rest_of_line. */
4897 return;
4900 else
4902 SKIP_WHITESPACE ();
4903 i = 0;
4904 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4905 && *input_line_pointer != ' '
4906 && *input_line_pointer != '\t')
4908 obstack_1grow (&notes, *input_line_pointer);
4909 ++input_line_pointer;
4910 ++i;
4912 obstack_1grow (&notes, '\0');
4913 filename = obstack_finish (&notes);
4914 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4915 ++input_line_pointer;
4917 demand_empty_rest_of_line ();
4918 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4919 for (i = 0; i < include_dir_count; i++)
4921 strcpy (path, include_dirs[i]);
4922 strcat (path, "/");
4923 strcat (path, filename);
4924 if (0 != (try = fopen (path, "r")))
4926 fclose (try);
4927 goto gotit;
4930 free (path);
4931 path = filename;
4932 gotit:
4933 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4934 register_dependency (path);
4935 input_scrub_insert_file (path);
4936 } /* s_include() */
4938 void
4939 add_include_dir (path)
4940 char *path;
4942 int i;
4944 if (include_dir_count == 0)
4946 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4947 include_dirs[0] = "."; /* Current dir */
4948 include_dir_count = 2;
4950 else
4952 include_dir_count++;
4953 include_dirs = (char **) realloc (include_dirs,
4954 include_dir_count * sizeof (*include_dirs));
4957 include_dirs[include_dir_count - 1] = path; /* New one */
4959 i = strlen (path);
4960 if (i > include_dir_maxlen)
4961 include_dir_maxlen = i;
4962 } /* add_include_dir() */
4964 /* Output debugging information to denote the source file. */
4966 static void
4967 generate_file_debug ()
4969 if (debug_type == DEBUG_STABS)
4970 stabs_generate_asm_file ();
4973 /* Output line number debugging information for the current source line. */
4975 void
4976 generate_lineno_debug ()
4978 #ifdef ECOFF_DEBUGGING
4979 /* ECOFF assemblers automatically generate debugging information.
4980 FIXME: This should probably be handled elsewhere. */
4981 if (debug_type == DEBUG_UNSPECIFIED)
4983 if (ECOFF_DEBUGGING && ecoff_no_current_file ())
4984 debug_type = DEBUG_ECOFF;
4985 else
4986 debug_type = DEBUG_NONE;
4988 #endif
4990 switch (debug_type)
4992 case DEBUG_UNSPECIFIED:
4993 case DEBUG_NONE:
4994 break;
4995 case DEBUG_STABS:
4996 stabs_generate_asm_lineno ();
4997 break;
4998 case DEBUG_ECOFF:
4999 ecoff_generate_asm_lineno ();
5000 break;
5001 case DEBUG_DWARF:
5002 case DEBUG_DWARF2:
5003 /* FIXME. */
5004 break;
5008 /* Output debugging information to mark a function entry point or end point.
5009 END_P is zero for .func, and non-zero for .endfunc. */
5011 void
5012 s_func (end_p)
5013 int end_p;
5015 do_s_func (end_p, NULL);
5018 /* Subroutine of s_func so targets can choose a different default prefix.
5019 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5021 void
5022 do_s_func (end_p, default_prefix)
5023 int end_p;
5024 const char *default_prefix;
5026 /* Record the current function so that we can issue an error message for
5027 misplaced .func,.endfunc, and also so that .endfunc needs no
5028 arguments. */
5029 static char *current_name;
5030 static char *current_label;
5032 if (end_p)
5034 if (current_name == NULL)
5036 as_bad (_("missing .func"));
5037 ignore_rest_of_line ();
5038 return;
5041 if (debug_type == DEBUG_STABS)
5042 stabs_generate_asm_endfunc (current_name, current_label);
5044 current_name = current_label = NULL;
5046 else /* ! end_p */
5048 char *name,*label;
5049 char delim1,delim2;
5051 if (current_name != NULL)
5053 as_bad (_(".endfunc missing for previous .func"));
5054 ignore_rest_of_line ();
5055 return;
5058 name = input_line_pointer;
5059 delim1 = get_symbol_end ();
5060 name = xstrdup (name);
5061 *input_line_pointer = delim1;
5062 SKIP_WHITESPACE ();
5063 if (*input_line_pointer != ',')
5065 if (default_prefix)
5066 asprintf (&label, "%s%s", default_prefix, name);
5067 else
5069 char leading_char = 0;
5070 #ifdef BFD_ASSEMBLER
5071 leading_char = bfd_get_symbol_leading_char (stdoutput);
5072 #endif
5073 /* Missing entry point, use function's name with the leading
5074 char prepended. */
5075 if (leading_char)
5076 asprintf (&label, "%c%s", leading_char, name);
5077 else
5078 label = name;
5081 else
5083 ++input_line_pointer;
5084 SKIP_WHITESPACE ();
5085 label = input_line_pointer;
5086 delim2 = get_symbol_end ();
5087 label = xstrdup (label);
5088 *input_line_pointer = delim2;
5091 if (debug_type == DEBUG_STABS)
5092 stabs_generate_asm_func (name, label);
5094 current_name = name;
5095 current_label = label;
5098 demand_empty_rest_of_line ();
5101 void
5102 s_ignore (arg)
5103 int arg ATTRIBUTE_UNUSED;
5105 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5107 ++input_line_pointer;
5109 ++input_line_pointer;
5113 void
5114 read_print_statistics (file)
5115 FILE *file;
5117 hash_print_statistics (file, "pseudo-op table", po_hash);
5120 /* Inserts the given line into the input stream.
5122 This call avoids macro/conditionals nesting checking, since the contents of
5123 the line are assumed to replace the contents of a line already scanned.
5125 An appropriate use of this function would be substition of input lines when
5126 called by md_start_line_hook(). The given line is assumed to already be
5127 properly scrubbed. */
5129 void
5130 input_scrub_insert_line (line)
5131 const char *line;
5133 sb newline;
5134 sb_new (&newline);
5135 sb_add_string (&newline, line);
5136 input_scrub_include_sb (&newline, input_line_pointer, 0);
5137 sb_kill (&newline);
5138 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5141 /* Insert a file into the input stream; the path must resolve to an actual
5142 file; no include path searching or dependency registering is performed. */
5144 void
5145 input_scrub_insert_file (path)
5146 char *path;
5148 input_scrub_include_file (path, input_line_pointer);
5149 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5152 /* end of read.c */