* tc-i386.c (md_assemble): Refuse 's' and 'l' suffixes in the intel
[binutils.git] / gas / read.c
blob0db8697fdbbd9b950991d9b1b867d05d45b618a5
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 /* If your chars aren't 8 bits, you will change this a bit.
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
26 #define MASK_CHAR (0xFF)
27 #else
28 #define MASK_CHAR ((int)(unsigned char) -1)
29 #endif
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
33 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
35 /* Routines that read assembler source text to build spagetti in memory.
36 Another group of these functions is in the expr.c module. */
38 /* For isdigit (). */
39 #include <ctype.h>
41 #include "as.h"
42 #include "subsegs.h"
43 #include "sb.h"
44 #include "macro.h"
45 #include "obstack.h"
46 #include "listing.h"
47 #include "ecoff.h"
49 #ifndef TC_START_LABEL
50 #define TC_START_LABEL(x,y) (x==':')
51 #endif
53 /* Set by the object-format or the target. */
54 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
55 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 do \
57 { \
58 if ((SIZE) >= 8) \
59 (P2VAR) = 3; \
60 else if ((SIZE) >= 4) \
61 (P2VAR) = 2; \
62 else if ((SIZE) >= 2) \
63 (P2VAR) = 1; \
64 else \
65 (P2VAR) = 0; \
66 } \
67 while (0)
68 #endif
70 /* The NOP_OPCODE is for the alignment fill value.
71 Fill it a nop instruction so that the disassembler does not choke
72 on it. */
73 #ifndef NOP_OPCODE
74 #define NOP_OPCODE 0x00
75 #endif
77 char *input_line_pointer; /*->next char of source file to parse. */
79 #if BITS_PER_CHAR != 8
80 /* The following table is indexed by[(char)] and will break if
81 a char does not have exactly 256 states (hopefully 0:255!)! */
82 die horribly;
83 #endif
85 #ifndef LEX_AT
86 /* The m88k unfortunately uses @ as a label beginner. */
87 #define LEX_AT 0
88 #endif
90 #ifndef LEX_BR
91 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
92 #define LEX_BR 0
93 #endif
95 #ifndef LEX_PCT
96 /* The Delta 68k assembler permits % inside label names. */
97 #define LEX_PCT 0
98 #endif
100 #ifndef LEX_QM
101 /* The PowerPC Windows NT assemblers permits ? inside label names. */
102 #define LEX_QM 0
103 #endif
105 #ifndef LEX_HASH
106 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
107 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
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] = {
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
125 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
126 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
127 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
128 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
129 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
130 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
131 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
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
141 /* In: a character.
142 Out: 1 if this character ends a line. */
143 char is_end_of_line[256] = {
144 #ifdef CR_EOL
145 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
146 #else
147 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
148 #endif
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
163 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
166 #ifdef IGNORE_OPCODE_CASE
167 char original_case_string[128];
168 #endif
170 /* Functions private to this file. */
172 static char *buffer; /* 1st char of each buffer of lines is here. */
173 static char *buffer_limit; /*->1 + last char in buffer. */
175 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
176 in the tc-<CPU>.h file. See the "Porting GAS" section of the
177 internals manual. */
178 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
180 static char *old_buffer; /* JF a hack. */
181 static char *old_input;
182 static char *old_limit;
184 /* Variables for handling include file directory table. */
186 /* Table of pointers to directories to search for .include's. */
187 char **include_dirs;
189 /* How many are in the table. */
190 int include_dir_count;
192 /* Length of longest in table. */
193 int include_dir_maxlen = 1;
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));
250 void
251 read_begin ()
253 const char *p;
255 pobegin ();
256 obj_read_begin_hook ();
258 /* Something close -- but not too close -- to a multiple of 1024.
259 The debugging malloc I'm using has 24 bytes of overhead. */
260 obstack_begin (&notes, chunksize);
261 obstack_begin (&cond_obstack, chunksize);
263 /* Use machine dependent syntax. */
264 for (p = line_separator_chars; *p; p++)
265 is_end_of_line[(unsigned char) *p] = 1;
266 /* Use more. FIXME-SOMEDAY. */
268 if (flag_mri)
269 lex_type['?'] = 3;
272 /* Set up pseudo-op tables. */
274 static struct hash_control *po_hash;
276 static const pseudo_typeS potable[] = {
277 {"abort", s_abort, 0},
278 {"align", s_align_ptwo, 0},
279 {"ascii", stringer, 0},
280 {"asciz", stringer, 1},
281 {"balign", s_align_bytes, 0},
282 {"balignw", s_align_bytes, -2},
283 {"balignl", s_align_bytes, -4},
284 /* block */
285 {"byte", cons, 1},
286 {"comm", s_comm, 0},
287 {"common", s_mri_common, 0},
288 {"common.s", s_mri_common, 1},
289 {"data", s_data, 0},
290 {"dc", cons, 2},
291 {"dc.b", cons, 1},
292 {"dc.d", float_cons, 'd'},
293 {"dc.l", cons, 4},
294 {"dc.s", float_cons, 'f'},
295 {"dc.w", cons, 2},
296 {"dc.x", float_cons, 'x'},
297 {"dcb", s_space, 2},
298 {"dcb.b", s_space, 1},
299 {"dcb.d", s_float_space, 'd'},
300 {"dcb.l", s_space, 4},
301 {"dcb.s", s_float_space, 'f'},
302 {"dcb.w", s_space, 2},
303 {"dcb.x", s_float_space, 'x'},
304 {"ds", s_space, 2},
305 {"ds.b", s_space, 1},
306 {"ds.d", s_space, 8},
307 {"ds.l", s_space, 4},
308 {"ds.p", s_space, 12},
309 {"ds.s", s_space, 4},
310 {"ds.w", s_space, 2},
311 {"ds.x", s_space, 12},
312 {"debug", s_ignore, 0},
313 #ifdef S_SET_DESC
314 {"desc", s_desc, 0},
315 #endif
316 /* dim */
317 {"double", float_cons, 'd'},
318 /* dsect */
319 {"eject", listing_eject, 0}, /* Formfeed listing. */
320 {"else", s_else, 0},
321 {"elsec", s_else, 0},
322 {"elseif", s_elseif, (int) O_ne},
323 {"end", s_end, 0},
324 {"endc", s_endif, 0},
325 {"endfunc", s_func, 1},
326 {"endif", s_endif, 0},
327 /* endef */
328 {"equ", s_set, 0},
329 {"equiv", s_set, 1},
330 {"err", s_err, 0},
331 {"exitm", s_mexit, 0},
332 /* extend */
333 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
334 {"appfile", s_app_file, 1},
335 {"appline", s_app_line, 0},
336 {"fail", s_fail, 0},
337 {"file", s_app_file, 0},
338 {"fill", s_fill, 0},
339 {"float", float_cons, 'f'},
340 {"format", s_ignore, 0},
341 {"func", s_func, 0},
342 {"global", s_globl, 0},
343 {"globl", s_globl, 0},
344 {"hword", cons, 2},
345 {"if", s_if, (int) O_ne},
346 {"ifc", s_ifc, 0},
347 {"ifdef", s_ifdef, 0},
348 {"ifeq", s_if, (int) O_eq},
349 {"ifeqs", s_ifeqs, 0},
350 {"ifge", s_if, (int) O_ge},
351 {"ifgt", s_if, (int) O_gt},
352 {"ifle", s_if, (int) O_le},
353 {"iflt", s_if, (int) O_lt},
354 {"ifnc", s_ifc, 1},
355 {"ifndef", s_ifdef, 1},
356 {"ifne", s_if, (int) O_ne},
357 {"ifnes", s_ifeqs, 1},
358 {"ifnotdef", s_ifdef, 1},
359 {"include", s_include, 0},
360 {"int", cons, 4},
361 {"irp", s_irp, 0},
362 {"irep", s_irp, 0},
363 {"irpc", s_irp, 1},
364 {"irepc", s_irp, 1},
365 {"lcomm", s_lcomm, 0},
366 {"lflags", listing_flags, 0}, /* Listing flags. */
367 {"linkonce", s_linkonce, 0},
368 {"list", listing_list, 1}, /* Turn listing on. */
369 {"llen", listing_psize, 1},
370 {"long", cons, 4},
371 {"lsym", s_lsym, 0},
372 {"macro", s_macro, 0},
373 {"mexit", s_mexit, 0},
374 {"mri", s_mri, 0},
375 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
376 {"name", s_ignore, 0},
377 {"noformat", s_ignore, 0},
378 {"nolist", listing_list, 0}, /* Turn listing off. */
379 {"nopage", listing_nopage, 0},
380 {"octa", cons, 16},
381 {"offset", s_struct, 0},
382 {"org", s_org, 0},
383 {"p2align", s_align_ptwo, 0},
384 {"p2alignw", s_align_ptwo, -2},
385 {"p2alignl", s_align_ptwo, -4},
386 {"page", listing_eject, 0},
387 {"plen", listing_psize, 0},
388 {"print", s_print, 0},
389 {"psize", listing_psize, 0}, /* Set paper size. */
390 {"purgem", s_purgem, 0},
391 {"quad", cons, 8},
392 {"rep", s_rept, 0},
393 {"rept", s_rept, 0},
394 {"rva", s_rva, 4},
395 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
396 /* scl */
397 /* sect */
398 {"set", s_set, 0},
399 {"short", cons, 2},
400 {"single", float_cons, 'f'},
401 /* size */
402 {"space", s_space, 0},
403 {"skip", s_space, 0},
404 {"sleb128", s_leb128, 1},
405 {"spc", s_ignore, 0},
406 {"stabd", s_stab, 'd'},
407 {"stabn", s_stab, 'n'},
408 {"stabs", s_stab, 's'},
409 {"string", stringer, 1},
410 {"struct", s_struct, 0},
411 /* tag */
412 {"text", s_text, 0},
414 /* This is for gcc to use. It's only just been added (2/94), so gcc
415 won't be able to use it for a while -- probably a year or more.
416 But once this has been released, check with gcc maintainers
417 before deleting it or even changing the spelling. */
418 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
419 /* If we're folding case -- done for some targets, not necessarily
420 all -- the above string in an input file will be converted to
421 this one. Match it either way... */
422 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
424 {"title", listing_title, 0}, /* Listing title. */
425 {"ttl", listing_title, 0},
426 /* type */
427 {"uleb128", s_leb128, 0},
428 /* use */
429 /* val */
430 {"xcom", s_comm, 0},
431 {"xdef", s_globl, 0},
432 {"xref", s_ignore, 0},
433 {"xstabs", s_xstab, 's'},
434 {"word", cons, 2},
435 {"zero", s_space, 0},
436 {NULL, NULL, 0} /* End sentinel. */
439 static int pop_override_ok = 0;
440 static const char *pop_table_name;
442 void
443 pop_insert (table)
444 const pseudo_typeS *table;
446 const char *errtxt;
447 const pseudo_typeS *pop;
448 for (pop = table; pop->poc_name; pop++)
450 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
451 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
452 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
453 errtxt);
457 #ifndef md_pop_insert
458 #define md_pop_insert() pop_insert(md_pseudo_table)
459 #endif
461 #ifndef obj_pop_insert
462 #define obj_pop_insert() pop_insert(obj_pseudo_table)
463 #endif
465 static void
466 pobegin ()
468 po_hash = hash_new ();
470 /* Do the target-specific pseudo ops. */
471 pop_table_name = "md";
472 md_pop_insert ();
474 /* Now object specific. Skip any that were in the target table. */
475 pop_table_name = "obj";
476 pop_override_ok = 1;
477 obj_pop_insert ();
479 /* Now portable ones. Skip any that we've seen already. */
480 pop_table_name = "standard";
481 pop_insert (potable);
484 #define HANDLE_CONDITIONAL_ASSEMBLY() \
485 if (ignore_input ()) \
487 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
488 if (input_line_pointer == buffer_limit) \
489 break; \
490 continue; \
493 /* This function is used when scrubbing the characters between #APP
494 and #NO_APP. */
496 static char *scrub_string;
497 static char *scrub_string_end;
499 static int
500 scrub_from_string (buf, buflen)
501 char *buf;
502 int buflen;
504 int copy;
506 copy = scrub_string_end - scrub_string;
507 if (copy > buflen)
508 copy = buflen;
509 memcpy (buf, scrub_string, copy);
510 scrub_string += copy;
511 return copy;
514 /* We read the file, putting things into a web that represents what we
515 have been reading. */
516 void
517 read_a_source_file (name)
518 char *name;
520 register char c;
521 register char *s; /* String of symbol, '\0' appended. */
522 register int temp;
523 pseudo_typeS *pop;
525 #ifdef WARN_COMMENTS
526 found_comment = 0;
527 #endif
529 buffer = input_scrub_new_file (name);
531 listing_file (name);
532 listing_newline (NULL);
533 register_dependency (name);
535 /* Generate debugging information before we've read anything in to denote
536 this file as the "main" source file and not a subordinate one
537 (e.g. N_SO vs N_SOL in stabs). */
538 generate_file_debug ();
540 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
541 { /* We have another line to parse. */
542 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
543 contin: /* JF this goto is my fault I admit it.
544 Someone brave please re-write the whole
545 input section here? Pleeze??? */
546 while (input_line_pointer < buffer_limit)
548 /* We have more of this buffer to parse. */
550 /* We now have input_line_pointer->1st char of next line.
551 If input_line_pointer [-1] == '\n' then we just
552 scanned another line: so bump line counters. */
553 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
555 #ifdef md_start_line_hook
556 md_start_line_hook ();
557 #endif
558 if (input_line_pointer[-1] == '\n')
559 bump_line_counters ();
561 line_label = NULL;
563 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
565 /* Text at the start of a line must be a label, we
566 run down and stick a colon in. */
567 if (is_name_beginner (*input_line_pointer))
569 char *line_start = input_line_pointer;
570 char c;
571 int mri_line_macro;
573 LISTING_NEWLINE ();
574 HANDLE_CONDITIONAL_ASSEMBLY ();
576 c = get_symbol_end ();
578 /* In MRI mode, the EQU and MACRO pseudoops must
579 be handled specially. */
580 mri_line_macro = 0;
581 if (flag_m68k_mri)
583 char *rest = input_line_pointer + 1;
585 if (*rest == ':')
586 ++rest;
587 if (*rest == ' ' || *rest == '\t')
588 ++rest;
589 if ((strncasecmp (rest, "EQU", 3) == 0
590 || strncasecmp (rest, "SET", 3) == 0)
591 && (rest[3] == ' ' || rest[3] == '\t'))
593 input_line_pointer = rest + 3;
594 equals (line_start,
595 strncasecmp (rest, "SET", 3) == 0);
596 continue;
598 if (strncasecmp (rest, "MACRO", 5) == 0
599 && (rest[5] == ' '
600 || rest[5] == '\t'
601 || is_end_of_line[(unsigned char) rest[5]]))
602 mri_line_macro = 1;
605 /* In MRI mode, we need to handle the MACRO
606 pseudo-op specially: we don't want to put the
607 symbol in the symbol table. */
608 if (!mri_line_macro
609 #ifdef TC_START_LABEL_WITHOUT_COLON
610 && TC_START_LABEL_WITHOUT_COLON(c,
611 input_line_pointer)
612 #endif
614 line_label = colon (line_start);
615 else
616 line_label = symbol_create (line_start,
617 absolute_section,
618 (valueT) 0,
619 &zero_address_frag);
621 *input_line_pointer = c;
622 if (c == ':')
623 input_line_pointer++;
628 /* We are at the begining of a line, or similar place.
629 We expect a well-formed assembler statement.
630 A "symbol-name:" is a statement.
632 Depending on what compiler is used, the order of these tests
633 may vary to catch most common case 1st.
634 Each test is independent of all other tests at the (top) level.
635 PLEASE make a compiler that doesn't use this assembler.
636 It is crufty to waste a compiler's time encoding things for this
637 assembler, which then wastes more time decoding it.
638 (And communicating via (linear) files is silly!
639 If you must pass stuff, please pass a tree!) */
640 if ((c = *input_line_pointer++) == '\t'
641 || c == ' '
642 || c == '\f'
643 || c == 0)
644 c = *input_line_pointer++;
646 know (c != ' '); /* No further leading whitespace. */
648 #ifndef NO_LISTING
649 /* If listing is on, and we are expanding a macro, then give
650 the listing code the contents of the expanded line. */
651 if (listing)
653 if ((listing & LISTING_MACEXP) && macro_nest > 0)
655 char *copy;
656 int len;
658 /* Find the end of the current expanded macro line. */
659 for (s = input_line_pointer - 1; *s; ++s)
660 if (is_end_of_line[(unsigned char) *s])
661 break;
663 /* Copy it for safe keeping. Also give an indication of
664 how much macro nesting is involved at this point. */
665 len = s - (input_line_pointer - 1);
666 copy = (char *) xmalloc (len + macro_nest + 2);
667 memset (copy, '>', macro_nest);
668 copy[macro_nest] = ' ';
669 memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
670 copy[macro_nest + 1 + len] = '\0';
672 /* Install the line with the listing facility. */
673 listing_newline (copy);
675 else
676 listing_newline (NULL);
678 #endif
679 /* C is the 1st significant character.
680 Input_line_pointer points after that character. */
681 if (is_name_beginner (c))
683 /* Want user-defined label or pseudo/opcode. */
684 HANDLE_CONDITIONAL_ASSEMBLY ();
686 s = --input_line_pointer;
687 c = get_symbol_end (); /* name's delimiter. */
689 /* C is character after symbol.
690 That character's place in the input line is now '\0'.
691 S points to the beginning of the symbol.
692 [In case of pseudo-op, s->'.'.]
693 Input_line_pointer->'\0' where c was. */
694 if (TC_START_LABEL (c, input_line_pointer))
696 if (flag_m68k_mri)
698 char *rest = input_line_pointer + 1;
700 /* In MRI mode, \tsym: set 0 is permitted. */
701 if (*rest == ':')
702 ++rest;
704 if (*rest == ' ' || *rest == '\t')
705 ++rest;
707 if ((strncasecmp (rest, "EQU", 3) == 0
708 || strncasecmp (rest, "SET", 3) == 0)
709 && (rest[3] == ' ' || rest[3] == '\t'))
711 input_line_pointer = rest + 3;
712 equals (s, 1);
713 continue;
717 line_label = colon (s); /* User-defined label. */
718 /* Put ':' back for error messages' sake. */
719 *input_line_pointer++ = ':';
720 /* Input_line_pointer->after ':'. */
721 SKIP_WHITESPACE ();
723 else if (c == '='
724 || ((c == ' ' || c == '\t')
725 && input_line_pointer[1] == '='
726 #ifdef TC_EQUAL_IN_INSN
727 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
728 #endif
731 equals (s, 1);
732 demand_empty_rest_of_line ();
734 else
736 /* Expect pseudo-op or machine instruction. */
737 pop = NULL;
739 #ifdef IGNORE_OPCODE_CASE
741 char *s2 = s;
743 strncpy (original_case_string, s2, sizeof (original_case_string));
744 original_case_string[sizeof (original_case_string) - 1] = 0;
746 while (*s2)
748 if (isupper ((unsigned char) *s2))
749 *s2 = tolower (*s2);
750 s2++;
753 #endif
754 if (NO_PSEUDO_DOT || flag_m68k_mri)
756 /* The MRI assembler and the m88k use pseudo-ops
757 without a period. */
758 pop = (pseudo_typeS *) hash_find (po_hash, s);
759 if (pop != NULL && pop->poc_handler == NULL)
760 pop = NULL;
763 if (pop != NULL
764 || (!flag_m68k_mri && *s == '.'))
766 /* PSEUDO - OP.
768 WARNING: c has next char, which may be end-of-line.
769 We lookup the pseudo-op table with s+1 because we
770 already know that the pseudo-op begins with a '.'. */
772 if (pop == NULL)
773 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
775 /* In MRI mode, we may need to insert an
776 automatic alignment directive. What a hack
777 this is. */
778 if (mri_pending_align
779 && (pop == NULL
780 || !((pop->poc_handler == cons
781 && pop->poc_val == 1)
782 || (pop->poc_handler == s_space
783 && pop->poc_val == 1)
784 #ifdef tc_conditional_pseudoop
785 || tc_conditional_pseudoop (pop)
786 #endif
787 || pop->poc_handler == s_if
788 || pop->poc_handler == s_ifdef
789 || pop->poc_handler == s_ifc
790 || pop->poc_handler == s_ifeqs
791 || pop->poc_handler == s_else
792 || pop->poc_handler == s_endif
793 || pop->poc_handler == s_globl
794 || pop->poc_handler == s_ignore)))
796 do_align (1, (char *) NULL, 0, 0);
797 mri_pending_align = 0;
799 if (line_label != NULL)
801 symbol_set_frag (line_label, frag_now);
802 S_SET_VALUE (line_label, frag_now_fix ());
806 /* Print the error msg now, while we still can. */
807 if (pop == NULL)
809 as_bad (_("Unknown pseudo-op: `%s'"), s);
810 *input_line_pointer = c;
811 s_ignore (0);
812 continue;
815 /* Put it back for error messages etc. */
816 *input_line_pointer = c;
817 /* The following skip of whitespace is compulsory.
818 A well shaped space is sometimes all that separates
819 keyword from operands. */
820 if (c == ' ' || c == '\t')
821 input_line_pointer++;
823 /* Input_line is restored.
824 Input_line_pointer->1st non-blank char
825 after pseudo-operation. */
826 (*pop->poc_handler) (pop->poc_val);
828 /* If that was .end, just get out now. */
829 if (pop->poc_handler == s_end)
830 goto quit;
832 else
834 int inquote = 0;
835 #ifdef QUOTES_IN_INSN
836 int inescape = 0;
837 #endif
839 /* WARNING: c has char, which may be end-of-line. */
840 /* Also: input_line_pointer->`\0` where c was. */
841 *input_line_pointer = c;
842 while (!is_end_of_line[(unsigned char) *input_line_pointer]
843 || inquote
844 #ifdef TC_EOL_IN_INSN
845 || TC_EOL_IN_INSN (input_line_pointer)
846 #endif
849 if (flag_m68k_mri && *input_line_pointer == '\'')
850 inquote = !inquote;
851 #ifdef QUOTES_IN_INSN
852 if (inescape)
853 inescape = 0;
854 else if (*input_line_pointer == '"')
855 inquote = !inquote;
856 else if (*input_line_pointer == '\\')
857 inescape = 1;
858 #endif
859 input_line_pointer++;
862 c = *input_line_pointer;
863 *input_line_pointer = '\0';
865 generate_lineno_debug ();
867 if (macro_defined)
869 sb out;
870 const char *err;
871 macro_entry *macro;
873 if (check_macro (s, &out, '\0', &err, &macro))
875 if (err != NULL)
876 as_bad ("%s", err);
877 *input_line_pointer++ = c;
878 input_scrub_include_sb (&out,
879 input_line_pointer, 1);
880 sb_kill (&out);
881 buffer_limit =
882 input_scrub_next_buffer (&input_line_pointer);
883 #ifdef md_macro_info
884 md_macro_info (macro);
885 #endif
886 continue;
890 if (mri_pending_align)
892 do_align (1, (char *) NULL, 0, 0);
893 mri_pending_align = 0;
894 if (line_label != NULL)
896 symbol_set_frag (line_label, frag_now);
897 S_SET_VALUE (line_label, frag_now_fix ());
901 md_assemble (s); /* Assemble 1 instruction. */
903 *input_line_pointer++ = c;
905 /* We resume loop AFTER the end-of-line from
906 this instruction. */
909 continue;
912 /* Empty statement? */
913 if (is_end_of_line[(unsigned char) c])
914 continue;
916 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
917 && isdigit ((unsigned char) c))
919 /* local label ("4:") */
920 char *backup = input_line_pointer;
922 HANDLE_CONDITIONAL_ASSEMBLY ();
924 temp = c - '0';
926 /* Read the whole number. */
927 while (isdigit ((unsigned char) *input_line_pointer))
929 temp = (temp * 10) + *input_line_pointer - '0';
930 ++input_line_pointer;
933 if (LOCAL_LABELS_DOLLAR
934 && *input_line_pointer == '$'
935 && *(input_line_pointer + 1) == ':')
937 input_line_pointer += 2;
939 if (dollar_label_defined (temp))
941 as_fatal (_("label \"%d$\" redefined"), temp);
944 define_dollar_label (temp);
945 colon (dollar_label_name (temp, 0));
946 continue;
949 if (LOCAL_LABELS_FB
950 && *input_line_pointer++ == ':')
952 fb_label_instance_inc (temp);
953 colon (fb_label_name (temp, 0));
954 continue;
957 input_line_pointer = backup;
958 } /* local label ("4:") */
960 if (c && strchr (line_comment_chars, c))
961 { /* Its a comment. Better say APP or NO_APP. */
962 char *ends;
963 char *new_buf;
964 char *new_tmp;
965 unsigned int new_length;
966 char *tmp_buf = 0;
968 bump_line_counters ();
969 s = input_line_pointer;
970 if (strncmp (s, "APP\n", 4))
971 continue; /* We ignore it */
972 s += 4;
974 ends = strstr (s, "#NO_APP\n");
976 if (!ends)
978 unsigned int tmp_len;
979 unsigned int num;
981 /* The end of the #APP wasn't in this buffer. We
982 keep reading in buffers until we find the #NO_APP
983 that goes with this #APP There is one. The specs
984 guarentee it... */
985 tmp_len = buffer_limit - s;
986 tmp_buf = xmalloc (tmp_len + 1);
987 memcpy (tmp_buf, s, tmp_len);
990 new_tmp = input_scrub_next_buffer (&buffer);
991 if (!new_tmp)
992 break;
993 else
994 buffer_limit = new_tmp;
995 input_line_pointer = buffer;
996 ends = strstr (buffer, "#NO_APP\n");
997 if (ends)
998 num = ends - buffer;
999 else
1000 num = buffer_limit - buffer;
1002 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
1003 memcpy (tmp_buf + tmp_len, buffer, num);
1004 tmp_len += num;
1006 while (!ends);
1008 input_line_pointer = ends ? ends + 8 : NULL;
1010 s = tmp_buf;
1011 ends = s + tmp_len;
1014 else
1016 input_line_pointer = ends + 8;
1019 scrub_string = s;
1020 scrub_string_end = ends;
1022 new_length = ends - s;
1023 new_buf = (char *) xmalloc (new_length);
1024 new_tmp = new_buf;
1025 for (;;)
1027 int space;
1028 int size;
1030 space = (new_buf + new_length) - new_tmp;
1031 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1033 if (size < space)
1035 new_tmp += size;
1036 break;
1039 new_buf = xrealloc (new_buf, new_length + 100);
1040 new_tmp = new_buf + new_length;
1041 new_length += 100;
1044 if (tmp_buf)
1045 free (tmp_buf);
1046 old_buffer = buffer;
1047 old_input = input_line_pointer;
1048 old_limit = buffer_limit;
1049 buffer = new_buf;
1050 input_line_pointer = new_buf;
1051 buffer_limit = new_tmp;
1053 continue;
1056 HANDLE_CONDITIONAL_ASSEMBLY ();
1058 #ifdef tc_unrecognized_line
1059 if (tc_unrecognized_line (c))
1060 continue;
1061 #endif
1062 /* as_warn (_("Junk character %d."),c); Now done by ignore_rest. */
1063 input_line_pointer--; /* Report unknown char as ignored. */
1064 ignore_rest_of_line ();
1067 #ifdef md_after_pass_hook
1068 md_after_pass_hook ();
1069 #endif
1071 if (old_buffer)
1073 free (buffer);
1074 bump_line_counters ();
1075 if (old_input != 0)
1077 buffer = old_buffer;
1078 input_line_pointer = old_input;
1079 buffer_limit = old_limit;
1080 old_buffer = 0;
1081 goto contin;
1086 quit:
1088 #ifdef md_cleanup
1089 md_cleanup ();
1090 #endif
1091 /* Close the input file. */
1092 input_scrub_close ();
1093 #ifdef WARN_COMMENTS
1095 if (warn_comment && found_comment)
1096 as_warn_where (found_comment_file, found_comment,
1097 "first comment found here");
1099 #endif
1102 /* For most MRI pseudo-ops, the line actually ends at the first
1103 nonquoted space. This function looks for that point, stuffs a null
1104 in, and sets *STOPCP to the character that used to be there, and
1105 returns the location.
1107 Until I hear otherwise, I am going to assume that this is only true
1108 for the m68k MRI assembler. */
1110 char *
1111 mri_comment_field (stopcp)
1112 char *stopcp;
1114 char *s;
1115 #ifdef TC_M68K
1116 int inquote = 0;
1118 know (flag_m68k_mri);
1120 for (s = input_line_pointer;
1121 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1122 || inquote);
1123 s++)
1125 if (*s == '\'')
1126 inquote = !inquote;
1128 #else
1129 for (s = input_line_pointer;
1130 !is_end_of_line[(unsigned char) *s];
1131 s++)
1133 #endif
1134 *stopcp = *s;
1135 *s = '\0';
1137 return s;
1140 /* Skip to the end of an MRI comment field. */
1142 void
1143 mri_comment_end (stop, stopc)
1144 char *stop;
1145 int stopc;
1147 know (flag_mri);
1149 input_line_pointer = stop;
1150 *stop = stopc;
1151 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1152 ++input_line_pointer;
1155 void
1156 s_abort (ignore)
1157 int ignore ATTRIBUTE_UNUSED;
1159 as_fatal (_(".abort detected. Abandoning ship."));
1162 /* Guts of .align directive. N is the power of two to which to align.
1163 FILL may be NULL, or it may point to the bytes of the fill pattern.
1164 LEN is the length of whatever FILL points to, if anything. MAX is
1165 the maximum number of characters to skip when doing the alignment,
1166 or 0 if there is no maximum. */
1168 static void
1169 do_align (n, fill, len, max)
1170 int n;
1171 char *fill;
1172 int len;
1173 int max;
1175 char default_fill;
1177 #ifdef md_do_align
1178 md_do_align (n, fill, len, max, just_record_alignment);
1179 #endif
1181 if (fill == NULL)
1183 if (subseg_text_p (now_seg))
1184 default_fill = NOP_OPCODE;
1185 else
1186 default_fill = 0;
1187 fill = &default_fill;
1188 len = 1;
1191 /* Only make a frag if we HAVE to... */
1192 if (n != 0 && !need_pass_2)
1194 if (len <= 1)
1195 frag_align (n, *fill, max);
1196 else
1197 frag_align_pattern (n, fill, len, max);
1200 #ifdef md_do_align
1201 just_record_alignment:
1202 #endif
1204 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1207 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1208 (in bytes). A negative ARG is the negative of the length of the
1209 fill pattern. BYTES_P is non-zero if the alignment value should be
1210 interpreted as the byte boundary, rather than the power of 2. */
1212 static void
1213 s_align (arg, bytes_p)
1214 int arg;
1215 int bytes_p;
1217 register unsigned int align;
1218 char *stop = NULL;
1219 char stopc;
1220 offsetT fill = 0;
1221 int max;
1222 int fill_p;
1224 if (flag_mri)
1225 stop = mri_comment_field (&stopc);
1227 if (is_end_of_line[(unsigned char) *input_line_pointer])
1229 if (arg < 0)
1230 align = 0;
1231 else
1232 align = arg; /* Default value from pseudo-op table. */
1234 else
1236 align = get_absolute_expression ();
1237 SKIP_WHITESPACE ();
1240 if (bytes_p)
1242 /* Convert to a power of 2. */
1243 if (align != 0)
1245 unsigned int i;
1247 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1249 if (align != 1)
1250 as_bad (_("Alignment not a power of 2"));
1252 align = i;
1256 if (align > 15)
1258 align = 15;
1259 as_bad (_("Alignment too large: %u assumed"), align);
1262 if (*input_line_pointer != ',')
1264 fill_p = 0;
1265 max = 0;
1267 else
1269 ++input_line_pointer;
1270 if (*input_line_pointer == ',')
1271 fill_p = 0;
1272 else
1274 fill = get_absolute_expression ();
1275 SKIP_WHITESPACE ();
1276 fill_p = 1;
1279 if (*input_line_pointer != ',')
1280 max = 0;
1281 else
1283 ++input_line_pointer;
1284 max = get_absolute_expression ();
1288 if (!fill_p)
1290 if (arg < 0)
1291 as_warn (_("expected fill pattern missing"));
1292 do_align (align, (char *) NULL, 0, max);
1294 else
1296 int fill_len;
1298 if (arg >= 0)
1299 fill_len = 1;
1300 else
1301 fill_len = -arg;
1302 if (fill_len <= 1)
1304 char fill_char;
1306 fill_char = fill;
1307 do_align (align, &fill_char, fill_len, max);
1309 else
1311 char ab[16];
1313 if ((size_t) fill_len > sizeof ab)
1314 abort ();
1315 md_number_to_chars (ab, fill, fill_len);
1316 do_align (align, ab, fill_len, max);
1320 demand_empty_rest_of_line ();
1322 if (flag_mri)
1323 mri_comment_end (stop, stopc);
1326 /* Handle the .align pseudo-op on machines where ".align 4" means
1327 align to a 4 byte boundary. */
1329 void
1330 s_align_bytes (arg)
1331 int arg;
1333 s_align (arg, 1);
1336 /* Handle the .align pseudo-op on machines where ".align 4" means align
1337 to a 2**4 boundary. */
1339 void
1340 s_align_ptwo (arg)
1341 int arg;
1343 s_align (arg, 0);
1346 void
1347 s_comm (ignore)
1348 int ignore ATTRIBUTE_UNUSED;
1350 register char *name;
1351 register char c;
1352 register char *p;
1353 offsetT temp;
1354 register symbolS *symbolP;
1355 char *stop = NULL;
1356 char stopc;
1358 if (flag_mri)
1359 stop = mri_comment_field (&stopc);
1361 name = input_line_pointer;
1362 c = get_symbol_end ();
1363 /* Just after name is now '\0'. */
1364 p = input_line_pointer;
1365 *p = c;
1366 SKIP_WHITESPACE ();
1368 if (*input_line_pointer != ',')
1370 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1371 ignore_rest_of_line ();
1372 if (flag_mri)
1373 mri_comment_end (stop, stopc);
1374 return;
1377 input_line_pointer++; /* skip ',' */
1379 if ((temp = get_absolute_expression ()) < 0)
1381 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1382 ignore_rest_of_line ();
1383 if (flag_mri)
1384 mri_comment_end (stop, stopc);
1385 return;
1388 *p = 0;
1389 symbolP = symbol_find_or_make (name);
1390 *p = c;
1392 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
1394 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1395 S_GET_NAME (symbolP));
1396 ignore_rest_of_line ();
1397 if (flag_mri)
1398 mri_comment_end (stop, stopc);
1399 return;
1402 if (S_GET_VALUE (symbolP))
1404 if (S_GET_VALUE (symbolP) != (valueT) temp)
1405 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1406 S_GET_NAME (symbolP),
1407 (long) S_GET_VALUE (symbolP),
1408 (long) temp);
1410 else
1412 S_SET_VALUE (symbolP, (valueT) temp);
1413 S_SET_EXTERNAL (symbolP);
1415 #ifdef OBJ_VMS
1417 extern int flag_one;
1418 if (!temp || !flag_one)
1419 S_GET_OTHER(symbolP) = const_flag;
1421 #endif /* not OBJ_VMS */
1422 know (symbolP->sy_frag == &zero_address_frag);
1424 demand_empty_rest_of_line ();
1426 if (flag_mri)
1427 mri_comment_end (stop, stopc);
1428 } /* s_comm() */
1430 /* The MRI COMMON pseudo-op. We handle this by creating a common
1431 symbol with the appropriate name. We make s_space do the right
1432 thing by increasing the size. */
1434 void
1435 s_mri_common (small)
1436 int small ATTRIBUTE_UNUSED;
1438 char *name;
1439 char c;
1440 char *alc = NULL;
1441 symbolS *sym;
1442 offsetT align;
1443 char *stop = NULL;
1444 char stopc;
1446 if (!flag_mri)
1448 s_comm (0);
1449 return;
1452 stop = mri_comment_field (&stopc);
1454 SKIP_WHITESPACE ();
1456 name = input_line_pointer;
1457 if (!isdigit ((unsigned char) *name))
1458 c = get_symbol_end ();
1459 else
1463 ++input_line_pointer;
1465 while (isdigit ((unsigned char) *input_line_pointer));
1467 c = *input_line_pointer;
1468 *input_line_pointer = '\0';
1470 if (line_label != NULL)
1472 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1473 + (input_line_pointer - name)
1474 + 1);
1475 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1476 name = alc;
1480 sym = symbol_find_or_make (name);
1481 *input_line_pointer = c;
1482 if (alc != NULL)
1483 free (alc);
1485 if (*input_line_pointer != ',')
1486 align = 0;
1487 else
1489 ++input_line_pointer;
1490 align = get_absolute_expression ();
1493 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1495 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1496 ignore_rest_of_line ();
1497 mri_comment_end (stop, stopc);
1498 return;
1501 S_SET_EXTERNAL (sym);
1502 mri_common_symbol = sym;
1504 #ifdef S_SET_ALIGN
1505 if (align != 0)
1506 S_SET_ALIGN (sym, align);
1507 #endif
1509 if (line_label != NULL)
1511 expressionS exp;
1512 exp.X_op = O_symbol;
1513 exp.X_add_symbol = sym;
1514 exp.X_add_number = 0;
1515 symbol_set_value_expression (line_label, &exp);
1516 symbol_set_frag (line_label, &zero_address_frag);
1517 S_SET_SEGMENT (line_label, expr_section);
1520 /* FIXME: We just ignore the small argument, which distinguishes
1521 COMMON and COMMON.S. I don't know what we can do about it. */
1523 /* Ignore the type and hptype. */
1524 if (*input_line_pointer == ',')
1525 input_line_pointer += 2;
1526 if (*input_line_pointer == ',')
1527 input_line_pointer += 2;
1529 demand_empty_rest_of_line ();
1531 mri_comment_end (stop, stopc);
1534 void
1535 s_data (ignore)
1536 int ignore ATTRIBUTE_UNUSED;
1538 segT section;
1539 register int temp;
1541 temp = get_absolute_expression ();
1542 if (flag_readonly_data_in_text)
1544 section = text_section;
1545 temp += 1000;
1547 else
1548 section = data_section;
1550 subseg_set (section, (subsegT) temp);
1552 #ifdef OBJ_VMS
1553 const_flag = 0;
1554 #endif
1555 demand_empty_rest_of_line ();
1558 /* Handle the .appfile pseudo-op. This is automatically generated by
1559 do_scrub_chars when a preprocessor # line comment is seen with a
1560 file name. This default definition may be overridden by the object
1561 or CPU specific pseudo-ops. This function is also the default
1562 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1563 .file. */
1565 void
1566 s_app_file (appfile)
1567 int appfile;
1569 register char *s;
1570 int length;
1572 /* Some assemblers tolerate immediately following '"'. */
1573 if ((s = demand_copy_string (&length)) != 0)
1575 /* If this is a fake .appfile, a fake newline was inserted into
1576 the buffer. Passing -2 to new_logical_line tells it to
1577 account for it. */
1578 int may_omit
1579 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
1581 /* In MRI mode, the preprocessor may have inserted an extraneous
1582 backquote. */
1583 if (flag_m68k_mri
1584 && *input_line_pointer == '\''
1585 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1586 ++input_line_pointer;
1588 demand_empty_rest_of_line ();
1589 if (!may_omit)
1591 #ifdef LISTING
1592 if (listing)
1593 listing_source_file (s);
1594 #endif
1595 register_dependency (s);
1596 #ifdef obj_app_file
1597 obj_app_file (s);
1598 #endif
1603 /* Handle the .appline pseudo-op. This is automatically generated by
1604 do_scrub_chars when a preprocessor # line comment is seen. This
1605 default definition may be overridden by the object or CPU specific
1606 pseudo-ops. */
1608 void
1609 s_app_line (ignore)
1610 int ignore ATTRIBUTE_UNUSED;
1612 int l;
1614 /* The given number is that of the next line. */
1615 l = get_absolute_expression () - 1;
1616 if (l < 0)
1617 /* Some of the back ends can't deal with non-positive line numbers.
1618 Besides, it's silly. */
1619 as_warn (_("Line numbers must be positive; line number %d rejected."),
1620 l + 1);
1621 else
1623 new_logical_line ((char *) NULL, l);
1624 #ifdef LISTING
1625 if (listing)
1626 listing_source_line (l);
1627 #endif
1629 demand_empty_rest_of_line ();
1632 /* Handle the .end pseudo-op. Actually, the real work is done in
1633 read_a_source_file. */
1635 void
1636 s_end (ignore)
1637 int ignore ATTRIBUTE_UNUSED;
1639 if (flag_mri)
1641 /* The MRI assembler permits the start symbol to follow .end,
1642 but we don't support that. */
1643 SKIP_WHITESPACE ();
1644 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1645 && *input_line_pointer != '*'
1646 && *input_line_pointer != '!')
1647 as_warn (_("start address not supported"));
1651 /* Handle the .err pseudo-op. */
1653 void
1654 s_err (ignore)
1655 int ignore ATTRIBUTE_UNUSED;
1657 as_bad (_(".err encountered"));
1658 demand_empty_rest_of_line ();
1661 /* Handle the MRI fail pseudo-op. */
1663 void
1664 s_fail (ignore)
1665 int ignore ATTRIBUTE_UNUSED;
1667 offsetT temp;
1668 char *stop = NULL;
1669 char stopc;
1671 if (flag_mri)
1672 stop = mri_comment_field (&stopc);
1674 temp = get_absolute_expression ();
1675 if (temp >= 500)
1676 as_warn (_(".fail %ld encountered"), (long) temp);
1677 else
1678 as_bad (_(".fail %ld encountered"), (long) temp);
1680 demand_empty_rest_of_line ();
1682 if (flag_mri)
1683 mri_comment_end (stop, stopc);
1686 void
1687 s_fill (ignore)
1688 int ignore ATTRIBUTE_UNUSED;
1690 expressionS rep_exp;
1691 long size = 1;
1692 register long fill = 0;
1693 char *p;
1695 #ifdef md_flush_pending_output
1696 md_flush_pending_output ();
1697 #endif
1699 get_known_segmented_expression (&rep_exp);
1700 if (*input_line_pointer == ',')
1702 input_line_pointer++;
1703 size = get_absolute_expression ();
1704 if (*input_line_pointer == ',')
1706 input_line_pointer++;
1707 fill = get_absolute_expression ();
1711 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1712 #define BSD_FILL_SIZE_CROCK_8 (8)
1713 if (size > BSD_FILL_SIZE_CROCK_8)
1715 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1716 size = BSD_FILL_SIZE_CROCK_8;
1718 if (size < 0)
1720 as_warn (_("Size negative: .fill ignored."));
1721 size = 0;
1723 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1725 if (rep_exp.X_add_number < 0)
1726 as_warn (_("Repeat < 0, .fill ignored"));
1727 size = 0;
1730 if (size && !need_pass_2)
1732 if (rep_exp.X_op == O_constant)
1734 p = frag_var (rs_fill, (int) size, (int) size,
1735 (relax_substateT) 0, (symbolS *) 0,
1736 (offsetT) rep_exp.X_add_number,
1737 (char *) 0);
1739 else
1741 /* We don't have a constant repeat count, so we can't use
1742 rs_fill. We can get the same results out of rs_space,
1743 but its argument is in bytes, so we must multiply the
1744 repeat count by size. */
1746 symbolS *rep_sym;
1747 rep_sym = make_expr_symbol (&rep_exp);
1748 if (size != 1)
1750 expressionS size_exp;
1751 size_exp.X_op = O_constant;
1752 size_exp.X_add_number = size;
1754 rep_exp.X_op = O_multiply;
1755 rep_exp.X_add_symbol = rep_sym;
1756 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1757 rep_exp.X_add_number = 0;
1758 rep_sym = make_expr_symbol (&rep_exp);
1761 p = frag_var (rs_space, (int) size, (int) size,
1762 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1765 memset (p, 0, (unsigned int) size);
1767 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1768 flavoured AS. The following bizzare behaviour is to be
1769 compatible with above. I guess they tried to take up to 8
1770 bytes from a 4-byte expression and they forgot to sign
1771 extend. Un*x Sux. */
1772 #define BSD_FILL_SIZE_CROCK_4 (4)
1773 md_number_to_chars (p, (valueT) fill,
1774 (size > BSD_FILL_SIZE_CROCK_4
1775 ? BSD_FILL_SIZE_CROCK_4
1776 : (int) size));
1777 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1778 but emits no error message because it seems a legal thing to do.
1779 It is a degenerate case of .fill but could be emitted by a
1780 compiler. */
1782 demand_empty_rest_of_line ();
1785 void
1786 s_globl (ignore)
1787 int ignore ATTRIBUTE_UNUSED;
1789 char *name;
1790 int c;
1791 symbolS *symbolP;
1792 char *stop = NULL;
1793 char stopc;
1795 if (flag_mri)
1796 stop = mri_comment_field (&stopc);
1800 name = input_line_pointer;
1801 c = get_symbol_end ();
1802 symbolP = symbol_find_or_make (name);
1803 S_SET_EXTERNAL (symbolP);
1805 *input_line_pointer = c;
1806 SKIP_WHITESPACE ();
1807 c = *input_line_pointer;
1808 if (c == ',')
1810 input_line_pointer++;
1811 SKIP_WHITESPACE ();
1812 if (*input_line_pointer == '\n')
1813 c = '\n';
1816 while (c == ',');
1818 demand_empty_rest_of_line ();
1820 if (flag_mri)
1821 mri_comment_end (stop, stopc);
1824 /* Handle the MRI IRP and IRPC pseudo-ops. */
1826 void
1827 s_irp (irpc)
1828 int irpc;
1830 char *file;
1831 unsigned int line;
1832 sb s;
1833 const char *err;
1834 sb out;
1836 as_where (&file, &line);
1838 sb_new (&s);
1839 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1840 sb_add_char (&s, *input_line_pointer++);
1842 sb_new (&out);
1844 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1845 if (err != NULL)
1846 as_bad_where (file, line, "%s", err);
1848 sb_kill (&s);
1850 input_scrub_include_sb (&out, input_line_pointer, 1);
1851 sb_kill (&out);
1852 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1855 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1856 the section to only be linked once. However, this is not supported
1857 by most object file formats. This takes an optional argument,
1858 which is what to do about duplicates. */
1860 void
1861 s_linkonce (ignore)
1862 int ignore ATTRIBUTE_UNUSED;
1864 enum linkonce_type type;
1866 SKIP_WHITESPACE ();
1868 type = LINKONCE_DISCARD;
1870 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1872 char *s;
1873 char c;
1875 s = input_line_pointer;
1876 c = get_symbol_end ();
1877 if (strcasecmp (s, "discard") == 0)
1878 type = LINKONCE_DISCARD;
1879 else if (strcasecmp (s, "one_only") == 0)
1880 type = LINKONCE_ONE_ONLY;
1881 else if (strcasecmp (s, "same_size") == 0)
1882 type = LINKONCE_SAME_SIZE;
1883 else if (strcasecmp (s, "same_contents") == 0)
1884 type = LINKONCE_SAME_CONTENTS;
1885 else
1886 as_warn (_("unrecognized .linkonce type `%s'"), s);
1888 *input_line_pointer = c;
1891 #ifdef obj_handle_link_once
1892 obj_handle_link_once (type);
1893 #else /* ! defined (obj_handle_link_once) */
1894 #ifdef BFD_ASSEMBLER
1896 flagword flags;
1898 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1899 as_warn (_(".linkonce is not supported for this object file format"));
1901 flags = bfd_get_section_flags (stdoutput, now_seg);
1902 flags |= SEC_LINK_ONCE;
1903 switch (type)
1905 default:
1906 abort ();
1907 case LINKONCE_DISCARD:
1908 flags |= SEC_LINK_DUPLICATES_DISCARD;
1909 break;
1910 case LINKONCE_ONE_ONLY:
1911 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1912 break;
1913 case LINKONCE_SAME_SIZE:
1914 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1915 break;
1916 case LINKONCE_SAME_CONTENTS:
1917 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1918 break;
1920 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
1921 as_bad (_("bfd_set_section_flags: %s"),
1922 bfd_errmsg (bfd_get_error ()));
1924 #else /* ! defined (BFD_ASSEMBLER) */
1925 as_warn (_(".linkonce is not supported for this object file format"));
1926 #endif /* ! defined (BFD_ASSEMBLER) */
1927 #endif /* ! defined (obj_handle_link_once) */
1929 demand_empty_rest_of_line ();
1932 static void
1933 s_lcomm_internal (needs_align, bytes_p)
1934 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1935 (alignment); 0 if it was an ".lcomm" (2 args only). */
1936 int needs_align;
1937 /* 1 if the alignment value should be interpreted as the byte boundary,
1938 rather than the power of 2. */
1939 int bytes_p;
1941 register char *name;
1942 register char c;
1943 register char *p;
1944 register int temp;
1945 register symbolS *symbolP;
1946 segT current_seg = now_seg;
1947 subsegT current_subseg = now_subseg;
1948 const int max_alignment = 15;
1949 int align = 0;
1950 segT bss_seg = bss_section;
1952 name = input_line_pointer;
1953 c = get_symbol_end ();
1954 p = input_line_pointer;
1955 *p = c;
1956 SKIP_WHITESPACE ();
1958 /* Accept an optional comma after the name. The comma used to be
1959 required, but Irix 5 cc does not generate it. */
1960 if (*input_line_pointer == ',')
1962 ++input_line_pointer;
1963 SKIP_WHITESPACE ();
1966 if (*input_line_pointer == '\n')
1968 as_bad (_("Missing size expression"));
1969 return;
1972 if ((temp = get_absolute_expression ()) < 0)
1974 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1975 ignore_rest_of_line ();
1976 return;
1979 #if defined (TC_MIPS) || defined (TC_ALPHA)
1980 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1981 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1983 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1984 if (temp <= bfd_get_gp_size (stdoutput))
1986 bss_seg = subseg_new (".sbss", 1);
1987 seg_info (bss_seg)->bss = 1;
1988 #ifdef BFD_ASSEMBLER
1989 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1990 as_warn (_("error setting flags for \".sbss\": %s"),
1991 bfd_errmsg (bfd_get_error ()));
1992 #endif
1995 #endif
1997 if (!needs_align)
1999 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
2001 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
2002 if (align)
2003 record_alignment (bss_seg, align);
2006 if (needs_align)
2008 align = 0;
2009 SKIP_WHITESPACE ();
2011 if (*input_line_pointer != ',')
2013 as_bad (_("Expected comma after size"));
2014 ignore_rest_of_line ();
2015 return;
2018 input_line_pointer++;
2019 SKIP_WHITESPACE ();
2021 if (*input_line_pointer == '\n')
2023 as_bad (_("Missing alignment"));
2024 return;
2027 align = get_absolute_expression ();
2029 if (bytes_p)
2031 /* Convert to a power of 2. */
2032 if (align != 0)
2034 unsigned int i;
2036 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2038 if (align != 1)
2039 as_bad (_("Alignment not a power of 2"));
2040 align = i;
2044 if (align > max_alignment)
2046 align = max_alignment;
2047 as_warn (_("Alignment too large: %d. assumed."), align);
2049 else if (align < 0)
2051 align = 0;
2052 as_warn (_("Alignment negative. 0 assumed."));
2055 record_alignment (bss_seg, align);
2057 else
2059 /* Assume some objects may require alignment on some systems. */
2060 #if defined (TC_ALPHA) && ! defined (VMS)
2061 if (temp > 1)
2063 align = ffs (temp) - 1;
2064 if (temp % (1 << align))
2065 abort ();
2067 #endif
2070 *p = 0;
2071 symbolP = symbol_find_or_make (name);
2072 *p = c;
2074 if (
2075 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2076 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2077 #ifdef BFD_ASSEMBLER
2078 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2079 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2080 #else
2081 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2082 #endif
2083 #endif
2084 (S_GET_SEGMENT (symbolP) == bss_seg
2085 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2087 char *pfrag;
2089 subseg_set (bss_seg, 1);
2091 if (align)
2092 frag_align (align, 0, 0);
2094 /* Detach from old frag. */
2095 if (S_GET_SEGMENT (symbolP) == bss_seg)
2096 symbol_get_frag (symbolP)->fr_symbol = NULL;
2098 symbol_set_frag (symbolP, frag_now);
2099 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
2100 (offsetT) temp, (char *) 0);
2101 *pfrag = 0;
2103 S_SET_SEGMENT (symbolP, bss_seg);
2105 #ifdef OBJ_COFF
2106 /* The symbol may already have been created with a preceding
2107 ".globl" directive -- be careful not to step on storage class
2108 in that case. Otherwise, set it to static. */
2109 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2111 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2113 #endif /* OBJ_COFF */
2115 #ifdef S_SET_SIZE
2116 S_SET_SIZE (symbolP, temp);
2117 #endif
2119 else
2120 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2121 S_GET_NAME (symbolP));
2123 subseg_set (current_seg, current_subseg);
2125 demand_empty_rest_of_line ();
2128 void
2129 s_lcomm (needs_align)
2130 int needs_align;
2132 s_lcomm_internal (needs_align, 0);
2135 void
2136 s_lcomm_bytes (needs_align)
2137 int needs_align;
2139 s_lcomm_internal (needs_align, 1);
2142 void
2143 s_lsym (ignore)
2144 int ignore ATTRIBUTE_UNUSED;
2146 register char *name;
2147 register char c;
2148 register char *p;
2149 expressionS exp;
2150 register symbolS *symbolP;
2152 /* We permit ANY defined expression: BSD4.2 demands constants. */
2153 name = input_line_pointer;
2154 c = get_symbol_end ();
2155 p = input_line_pointer;
2156 *p = c;
2157 SKIP_WHITESPACE ();
2159 if (*input_line_pointer != ',')
2161 *p = 0;
2162 as_bad (_("Expected comma after name \"%s\""), name);
2163 *p = c;
2164 ignore_rest_of_line ();
2165 return;
2168 input_line_pointer++;
2169 expression (&exp);
2171 if (exp.X_op != O_constant
2172 && exp.X_op != O_register)
2174 as_bad (_("bad expression"));
2175 ignore_rest_of_line ();
2176 return;
2179 *p = 0;
2180 symbolP = symbol_find_or_make (name);
2182 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2183 symbolP->sy_desc == 0) out of this test because coff doesn't have
2184 those fields, and I can't see when they'd ever be tripped. I
2185 don't think I understand why they were here so I may have
2186 introduced a bug. As recently as 1.37 didn't have this test
2187 anyway. xoxorich. */
2189 if (S_GET_SEGMENT (symbolP) == undefined_section
2190 && S_GET_VALUE (symbolP) == 0)
2192 /* The name might be an undefined .global symbol; be sure to
2193 keep the "external" bit. */
2194 S_SET_SEGMENT (symbolP,
2195 (exp.X_op == O_constant
2196 ? absolute_section
2197 : reg_section));
2198 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2200 else
2202 as_bad (_("Symbol %s already defined"), name);
2205 *p = c;
2206 demand_empty_rest_of_line ();
2209 /* Read a line into an sb. */
2211 static int
2212 get_line_sb (line)
2213 sb *line;
2215 char quote1, quote2, inquote;
2217 if (input_line_pointer[-1] == '\n')
2218 bump_line_counters ();
2220 if (input_line_pointer >= buffer_limit)
2222 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2223 if (buffer_limit == 0)
2224 return 0;
2227 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2228 code needs to be changed. */
2229 if (!flag_m68k_mri)
2230 quote1 = '"';
2231 else
2232 quote1 = '\0';
2234 quote2 = '\0';
2235 if (flag_m68k_mri)
2236 quote2 = '\'';
2237 #ifdef LEX_IS_STRINGQUOTE
2238 quote2 = '\'';
2239 #endif
2241 inquote = '\0';
2243 while (!is_end_of_line[(unsigned char) *input_line_pointer]
2244 || (inquote != '\0' && *input_line_pointer != '\n'))
2246 if (inquote == *input_line_pointer)
2247 inquote = '\0';
2248 else if (inquote == '\0')
2250 if (*input_line_pointer == quote1)
2251 inquote = quote1;
2252 else if (*input_line_pointer == quote2)
2253 inquote = quote2;
2256 sb_add_char (line, *input_line_pointer++);
2259 while (input_line_pointer < buffer_limit
2260 && is_end_of_line[(unsigned char) *input_line_pointer])
2262 if (input_line_pointer[-1] == '\n')
2263 bump_line_counters ();
2264 ++input_line_pointer;
2267 return 1;
2270 /* Define a macro. This is an interface to macro.c, which is shared
2271 between gas and gasp. */
2273 void
2274 s_macro (ignore)
2275 int ignore ATTRIBUTE_UNUSED;
2277 char *file;
2278 unsigned int line;
2279 sb s;
2280 sb label;
2281 const char *err;
2282 const char *name;
2284 as_where (&file, &line);
2286 sb_new (&s);
2287 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2288 sb_add_char (&s, *input_line_pointer++);
2290 sb_new (&label);
2291 if (line_label != NULL)
2292 sb_add_string (&label, S_GET_NAME (line_label));
2294 err = define_macro (0, &s, &label, get_line_sb, &name);
2295 if (err != NULL)
2296 as_bad_where (file, line, "%s", err);
2297 else
2299 if (line_label != NULL)
2301 S_SET_SEGMENT (line_label, undefined_section);
2302 S_SET_VALUE (line_label, 0);
2303 symbol_set_frag (line_label, &zero_address_frag);
2306 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2307 && hash_find (po_hash, name) != NULL)
2308 || (!flag_m68k_mri
2309 && *name == '.'
2310 && hash_find (po_hash, name + 1) != NULL))
2311 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2312 name);
2315 sb_kill (&s);
2318 /* Handle the .mexit pseudo-op, which immediately exits a macro
2319 expansion. */
2321 void
2322 s_mexit (ignore)
2323 int ignore ATTRIBUTE_UNUSED;
2325 cond_exit_macro (macro_nest);
2326 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2329 /* Switch in and out of MRI mode. */
2331 void
2332 s_mri (ignore)
2333 int ignore ATTRIBUTE_UNUSED;
2335 int on, old_flag;
2337 on = get_absolute_expression ();
2338 old_flag = flag_mri;
2339 if (on != 0)
2341 flag_mri = 1;
2342 #ifdef TC_M68K
2343 flag_m68k_mri = 1;
2344 #endif
2345 macro_mri_mode (1);
2347 else
2349 flag_mri = 0;
2350 #ifdef TC_M68K
2351 flag_m68k_mri = 0;
2352 #endif
2353 macro_mri_mode (0);
2356 /* Operator precedence changes in m68k MRI mode, so we need to
2357 update the operator rankings. */
2358 expr_set_precedence ();
2360 #ifdef MRI_MODE_CHANGE
2361 if (on != old_flag)
2362 MRI_MODE_CHANGE (on);
2363 #endif
2365 demand_empty_rest_of_line ();
2368 /* Handle changing the location counter. */
2370 static void
2371 do_org (segment, exp, fill)
2372 segT segment;
2373 expressionS *exp;
2374 int fill;
2376 if (segment != now_seg && segment != absolute_section)
2377 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2378 segment_name (segment), segment_name (now_seg));
2380 if (now_seg == absolute_section)
2382 if (fill != 0)
2383 as_warn (_("ignoring fill value in absolute section"));
2384 if (exp->X_op != O_constant)
2386 as_bad (_("only constant offsets supported in absolute section"));
2387 exp->X_add_number = 0;
2389 abs_section_offset = exp->X_add_number;
2391 else
2393 char *p;
2395 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2396 exp->X_add_number * OCTETS_PER_BYTE, (char *) NULL);
2397 *p = fill;
2401 void
2402 s_org (ignore)
2403 int ignore ATTRIBUTE_UNUSED;
2405 register segT segment;
2406 expressionS exp;
2407 register long temp_fill;
2409 #ifdef md_flush_pending_output
2410 md_flush_pending_output ();
2411 #endif
2413 /* The m68k MRI assembler has a different meaning for .org. It
2414 means to create an absolute section at a given address. We can't
2415 support that--use a linker script instead. */
2416 if (flag_m68k_mri)
2418 as_bad (_("MRI style ORG pseudo-op not supported"));
2419 ignore_rest_of_line ();
2420 return;
2423 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2424 thing as a sub-segment-relative origin. Any absolute origin is
2425 given a warning, then assumed to be segment-relative. Any
2426 segmented origin expression ("foo+42") had better be in the right
2427 segment or the .org is ignored.
2429 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2430 we never know sub-segment sizes when we are reading code. BSD
2431 will crash trying to emit negative numbers of filler bytes in
2432 certain .orgs. We don't crash, but see as-write for that code.
2434 Don't make frag if need_pass_2==1. */
2435 segment = get_known_segmented_expression (&exp);
2436 if (*input_line_pointer == ',')
2438 input_line_pointer++;
2439 temp_fill = get_absolute_expression ();
2441 else
2442 temp_fill = 0;
2444 if (!need_pass_2)
2445 do_org (segment, &exp, temp_fill);
2447 demand_empty_rest_of_line ();
2450 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2451 called by the obj-format routine which handles section changing
2452 when in MRI mode. It will create a new section, and return it. It
2453 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2454 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2455 flags will be set in the section. */
2457 void
2458 s_mri_sect (type)
2459 char *type ATTRIBUTE_UNUSED;
2461 #ifdef TC_M68K
2463 char *name;
2464 char c;
2465 segT seg;
2467 SKIP_WHITESPACE ();
2469 name = input_line_pointer;
2470 if (!isdigit ((unsigned char) *name))
2471 c = get_symbol_end ();
2472 else
2476 ++input_line_pointer;
2478 while (isdigit ((unsigned char) *input_line_pointer));
2480 c = *input_line_pointer;
2481 *input_line_pointer = '\0';
2484 name = xstrdup (name);
2486 *input_line_pointer = c;
2488 seg = subseg_new (name, 0);
2490 if (*input_line_pointer == ',')
2492 int align;
2494 ++input_line_pointer;
2495 align = get_absolute_expression ();
2496 record_alignment (seg, align);
2499 *type = 'C';
2500 if (*input_line_pointer == ',')
2502 c = *++input_line_pointer;
2503 c = toupper ((unsigned char) c);
2504 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2505 *type = c;
2506 else
2507 as_bad (_("unrecognized section type"));
2508 ++input_line_pointer;
2510 #ifdef BFD_ASSEMBLER
2512 flagword flags;
2514 flags = SEC_NO_FLAGS;
2515 if (*type == 'C')
2516 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2517 else if (*type == 'D' || *type == 'M')
2518 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2519 else if (*type == 'R')
2520 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2521 if (flags != SEC_NO_FLAGS)
2523 if (!bfd_set_section_flags (stdoutput, seg, flags))
2524 as_warn (_("error setting flags for \"%s\": %s"),
2525 bfd_section_name (stdoutput, seg),
2526 bfd_errmsg (bfd_get_error ()));
2529 #endif
2532 /* Ignore the HP type. */
2533 if (*input_line_pointer == ',')
2534 input_line_pointer += 2;
2536 demand_empty_rest_of_line ();
2538 #else /* ! TC_M68K */
2539 #ifdef TC_I960
2541 char *name;
2542 char c;
2543 segT seg;
2545 SKIP_WHITESPACE ();
2547 name = input_line_pointer;
2548 c = get_symbol_end ();
2550 name = xstrdup (name);
2552 *input_line_pointer = c;
2554 seg = subseg_new (name, 0);
2556 if (*input_line_pointer != ',')
2557 *type = 'C';
2558 else
2560 char *sectype;
2562 ++input_line_pointer;
2563 SKIP_WHITESPACE ();
2564 sectype = input_line_pointer;
2565 c = get_symbol_end ();
2566 if (*sectype == '\0')
2567 *type = 'C';
2568 else if (strcasecmp (sectype, "text") == 0)
2569 *type = 'C';
2570 else if (strcasecmp (sectype, "data") == 0)
2571 *type = 'D';
2572 else if (strcasecmp (sectype, "romdata") == 0)
2573 *type = 'R';
2574 else
2575 as_warn (_("unrecognized section type `%s'"), sectype);
2576 *input_line_pointer = c;
2579 if (*input_line_pointer == ',')
2581 char *seccmd;
2583 ++input_line_pointer;
2584 SKIP_WHITESPACE ();
2585 seccmd = input_line_pointer;
2586 c = get_symbol_end ();
2587 if (strcasecmp (seccmd, "absolute") == 0)
2589 as_bad (_("absolute sections are not supported"));
2590 *input_line_pointer = c;
2591 ignore_rest_of_line ();
2592 return;
2594 else if (strcasecmp (seccmd, "align") == 0)
2596 int align;
2598 *input_line_pointer = c;
2599 align = get_absolute_expression ();
2600 record_alignment (seg, align);
2602 else
2604 as_warn (_("unrecognized section command `%s'"), seccmd);
2605 *input_line_pointer = c;
2609 demand_empty_rest_of_line ();
2611 #else /* ! TC_I960 */
2612 /* The MRI assembler seems to use different forms of .sect for
2613 different targets. */
2614 as_bad ("MRI mode not supported for this target");
2615 ignore_rest_of_line ();
2616 #endif /* ! TC_I960 */
2617 #endif /* ! TC_M68K */
2620 /* Handle the .print pseudo-op. */
2622 void
2623 s_print (ignore)
2624 int ignore ATTRIBUTE_UNUSED;
2626 char *s;
2627 int len;
2629 s = demand_copy_C_string (&len);
2630 printf ("%s\n", s);
2631 demand_empty_rest_of_line ();
2634 /* Handle the .purgem pseudo-op. */
2636 void
2637 s_purgem (ignore)
2638 int ignore ATTRIBUTE_UNUSED;
2640 if (is_it_end_of_statement ())
2642 demand_empty_rest_of_line ();
2643 return;
2648 char *name;
2649 char c;
2651 SKIP_WHITESPACE ();
2652 name = input_line_pointer;
2653 c = get_symbol_end ();
2654 delete_macro (name);
2655 *input_line_pointer = c;
2656 SKIP_WHITESPACE ();
2658 while (*input_line_pointer++ == ',');
2660 --input_line_pointer;
2661 demand_empty_rest_of_line ();
2664 /* Handle the .rept pseudo-op. */
2666 void
2667 s_rept (ignore)
2668 int ignore ATTRIBUTE_UNUSED;
2670 int count;
2672 count = get_absolute_expression ();
2674 do_repeat (count, "REPT", "ENDR");
2677 /* This function provides a generic repeat block implementation. It allows
2678 different directives to be used as the start/end keys. */
2680 void
2681 do_repeat (count, start, end)
2682 int count;
2683 const char *start;
2684 const char *end;
2686 sb one;
2687 sb many;
2689 sb_new (&one);
2690 if (!buffer_and_nest (start, end, &one, get_line_sb))
2692 as_bad (_("%s without %s"), start, end);
2693 return;
2696 sb_new (&many);
2697 while (count-- > 0)
2698 sb_add_sb (&many, &one);
2700 sb_kill (&one);
2702 input_scrub_include_sb (&many, input_line_pointer, 1);
2703 sb_kill (&many);
2704 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2707 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2708 input buffers to skip. Assumes that conditionals preceding the loop end
2709 are properly nested.
2711 This function makes it easier to implement a premature "break" out of the
2712 loop. The EXTRA arg accounts for other buffers we might have inserted,
2713 such as line substitutions. */
2715 void
2716 end_repeat (extra)
2717 int extra;
2719 cond_exit_macro (macro_nest);
2720 while (extra-- >= 0)
2721 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2724 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2725 this is .equiv, and it is an error if the symbol is already
2726 defined. */
2728 void
2729 s_set (equiv)
2730 int equiv;
2732 register char *name;
2733 register char delim;
2734 register char *end_name;
2735 register symbolS *symbolP;
2737 /* Especial apologies for the random logic:
2738 this just grew, and could be parsed much more simply!
2739 Dean in haste. */
2740 name = input_line_pointer;
2741 delim = get_symbol_end ();
2742 end_name = input_line_pointer;
2743 *end_name = delim;
2744 SKIP_WHITESPACE ();
2746 if (*input_line_pointer != ',')
2748 *end_name = 0;
2749 as_bad (_("Expected comma after name \"%s\""), name);
2750 *end_name = delim;
2751 ignore_rest_of_line ();
2752 return;
2755 input_line_pointer++;
2756 *end_name = 0;
2758 if (name[0] == '.' && name[1] == '\0')
2760 /* Turn '. = mumble' into a .org mumble. */
2761 register segT segment;
2762 expressionS exp;
2764 segment = get_known_segmented_expression (&exp);
2766 if (!need_pass_2)
2767 do_org (segment, &exp, 0);
2769 *end_name = delim;
2770 return;
2773 if ((symbolP = symbol_find (name)) == NULL
2774 && (symbolP = md_undefined_symbol (name)) == NULL)
2776 #ifndef NO_LISTING
2777 /* When doing symbol listings, play games with dummy fragments living
2778 outside the normal fragment chain to record the file and line info
2779 for this symbol. */
2780 if (listing & LISTING_SYMBOLS)
2782 extern struct list_info_struct *listing_tail;
2783 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2784 memset (dummy_frag, 0, sizeof (fragS));
2785 dummy_frag->fr_type = rs_fill;
2786 dummy_frag->line = listing_tail;
2787 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2788 dummy_frag->fr_symbol = symbolP;
2790 else
2791 #endif
2792 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2794 #ifdef OBJ_COFF
2795 /* "set" symbols are local unless otherwise specified. */
2796 SF_SET_LOCAL (symbolP);
2797 #endif /* OBJ_COFF */
2800 symbol_table_insert (symbolP);
2802 *end_name = delim;
2804 if (equiv
2805 && S_IS_DEFINED (symbolP)
2806 && S_GET_SEGMENT (symbolP) != reg_section)
2807 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2809 pseudo_set (symbolP);
2810 demand_empty_rest_of_line ();
2813 void
2814 s_space (mult)
2815 int mult;
2817 expressionS exp;
2818 expressionS val;
2819 char *p = 0;
2820 char *stop = NULL;
2821 char stopc;
2822 int bytes;
2824 #ifdef md_flush_pending_output
2825 md_flush_pending_output ();
2826 #endif
2828 if (flag_mri)
2829 stop = mri_comment_field (&stopc);
2831 /* In m68k MRI mode, we need to align to a word boundary, unless
2832 this is ds.b. */
2833 if (flag_m68k_mri && mult > 1)
2835 if (now_seg == absolute_section)
2837 abs_section_offset += abs_section_offset & 1;
2838 if (line_label != NULL)
2839 S_SET_VALUE (line_label, abs_section_offset);
2841 else if (mri_common_symbol != NULL)
2843 valueT val;
2845 val = S_GET_VALUE (mri_common_symbol);
2846 if ((val & 1) != 0)
2848 S_SET_VALUE (mri_common_symbol, val + 1);
2849 if (line_label != NULL)
2851 expressionS *symexp;
2853 symexp = symbol_get_value_expression (line_label);
2854 know (symexp->X_op == O_symbol);
2855 know (symexp->X_add_symbol == mri_common_symbol);
2856 symexp->X_add_number += 1;
2860 else
2862 do_align (1, (char *) NULL, 0, 0);
2863 if (line_label != NULL)
2865 symbol_set_frag (line_label, frag_now);
2866 S_SET_VALUE (line_label, frag_now_fix ());
2871 bytes = mult;
2873 expression (&exp);
2875 SKIP_WHITESPACE ();
2876 if (*input_line_pointer == ',')
2878 ++input_line_pointer;
2879 expression (&val);
2881 else
2883 val.X_op = O_constant;
2884 val.X_add_number = 0;
2887 if (val.X_op != O_constant
2888 || val.X_add_number < - 0x80
2889 || val.X_add_number > 0xff
2890 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2892 if (exp.X_op != O_constant)
2893 as_bad (_("Unsupported variable size or fill value"));
2894 else
2896 offsetT i;
2898 if (mult == 0)
2899 mult = 1;
2900 bytes = mult * exp.X_add_number;
2901 for (i = 0; i < exp.X_add_number; i++)
2902 emit_expr (&val, mult);
2905 else
2907 if (exp.X_op == O_constant)
2909 long repeat;
2911 repeat = exp.X_add_number;
2912 if (mult)
2913 repeat *= mult;
2914 bytes = repeat;
2915 if (repeat <= 0)
2917 if (!flag_mri)
2918 as_warn (_(".space repeat count is zero, ignored"));
2919 else if (repeat < 0)
2920 as_warn (_(".space repeat count is negative, ignored"));
2921 goto getout;
2924 /* If we are in the absolute section, just bump the offset. */
2925 if (now_seg == absolute_section)
2927 abs_section_offset += repeat;
2928 goto getout;
2931 /* If we are secretly in an MRI common section, then
2932 creating space just increases the size of the common
2933 symbol. */
2934 if (mri_common_symbol != NULL)
2936 S_SET_VALUE (mri_common_symbol,
2937 S_GET_VALUE (mri_common_symbol) + repeat);
2938 goto getout;
2941 if (!need_pass_2)
2942 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2943 (offsetT) repeat, (char *) 0);
2945 else
2947 if (now_seg == absolute_section)
2949 as_bad (_("space allocation too complex in absolute section"));
2950 subseg_set (text_section, 0);
2953 if (mri_common_symbol != NULL)
2955 as_bad (_("space allocation too complex in common section"));
2956 mri_common_symbol = NULL;
2959 if (!need_pass_2)
2960 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2961 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2964 if (p)
2965 *p = val.X_add_number;
2968 getout:
2970 /* In MRI mode, after an odd number of bytes, we must align to an
2971 even word boundary, unless the next instruction is a dc.b, ds.b
2972 or dcb.b. */
2973 if (flag_mri && (bytes & 1) != 0)
2974 mri_pending_align = 1;
2976 demand_empty_rest_of_line ();
2978 if (flag_mri)
2979 mri_comment_end (stop, stopc);
2982 /* This is like s_space, but the value is a floating point number with
2983 the given precision. This is for the MRI dcb.s pseudo-op and
2984 friends. */
2986 void
2987 s_float_space (float_type)
2988 int float_type;
2990 offsetT count;
2991 int flen;
2992 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2993 char *stop = NULL;
2994 char stopc;
2996 if (flag_mri)
2997 stop = mri_comment_field (&stopc);
2999 count = get_absolute_expression ();
3001 SKIP_WHITESPACE ();
3002 if (*input_line_pointer != ',')
3004 as_bad (_("missing value"));
3005 ignore_rest_of_line ();
3006 if (flag_mri)
3007 mri_comment_end (stop, stopc);
3008 return;
3011 ++input_line_pointer;
3013 SKIP_WHITESPACE ();
3015 /* Skip any 0{letter} that may be present. Don't even check if the
3016 * letter is legal. */
3017 if (input_line_pointer[0] == '0'
3018 && isalpha ((unsigned char) input_line_pointer[1]))
3019 input_line_pointer += 2;
3021 /* Accept :xxxx, where the x's are hex digits, for a floating point
3022 with the exact digits specified. */
3023 if (input_line_pointer[0] == ':')
3025 flen = hex_float (float_type, temp);
3026 if (flen < 0)
3028 ignore_rest_of_line ();
3029 if (flag_mri)
3030 mri_comment_end (stop, stopc);
3031 return;
3034 else
3036 char *err;
3038 err = md_atof (float_type, temp, &flen);
3039 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3040 know (flen > 0);
3041 if (err)
3043 as_bad (_("Bad floating literal: %s"), err);
3044 ignore_rest_of_line ();
3045 if (flag_mri)
3046 mri_comment_end (stop, stopc);
3047 return;
3051 while (--count >= 0)
3053 char *p;
3055 p = frag_more (flen);
3056 memcpy (p, temp, (unsigned int) flen);
3059 demand_empty_rest_of_line ();
3061 if (flag_mri)
3062 mri_comment_end (stop, stopc);
3065 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3067 void
3068 s_struct (ignore)
3069 int ignore ATTRIBUTE_UNUSED;
3071 char *stop = NULL;
3072 char stopc;
3074 if (flag_mri)
3075 stop = mri_comment_field (&stopc);
3076 abs_section_offset = get_absolute_expression ();
3077 subseg_set (absolute_section, 0);
3078 demand_empty_rest_of_line ();
3079 if (flag_mri)
3080 mri_comment_end (stop, stopc);
3083 void
3084 s_text (ignore)
3085 int ignore ATTRIBUTE_UNUSED;
3087 register int temp;
3089 temp = get_absolute_expression ();
3090 subseg_set (text_section, (subsegT) temp);
3091 demand_empty_rest_of_line ();
3092 #ifdef OBJ_VMS
3093 const_flag &= ~IN_DEFAULT_SECTION;
3094 #endif
3097 void
3098 demand_empty_rest_of_line ()
3100 SKIP_WHITESPACE ();
3101 if (is_end_of_line[(unsigned char) *input_line_pointer])
3102 input_line_pointer++;
3103 else
3104 ignore_rest_of_line ();
3106 /* Return having already swallowed end-of-line. */
3109 void
3110 ignore_rest_of_line ()
3112 /* For suspect lines: gives warning. */
3113 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3115 if (isprint ((unsigned char) *input_line_pointer))
3116 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3117 *input_line_pointer);
3118 else
3119 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3120 *input_line_pointer);
3122 while (input_line_pointer < buffer_limit
3123 && !is_end_of_line[(unsigned char) *input_line_pointer])
3124 input_line_pointer++;
3127 input_line_pointer++;
3129 /* Return pointing just after end-of-line. */
3130 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3133 void
3134 discard_rest_of_line ()
3136 while (input_line_pointer < buffer_limit
3137 && !is_end_of_line[(unsigned char) *input_line_pointer])
3138 input_line_pointer++;
3140 input_line_pointer++;
3142 /* Return pointing just after end-of-line. */
3143 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3146 /* In: Pointer to a symbol.
3147 Input_line_pointer->expression.
3149 Out: Input_line_pointer->just after any whitespace after expression.
3150 Tried to set symbol to value of expression.
3151 Will change symbols type, value, and frag; */
3153 void
3154 pseudo_set (symbolP)
3155 symbolS *symbolP;
3157 expressionS exp;
3158 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3159 int ext;
3160 #endif /* OBJ_AOUT or OBJ_BOUT */
3162 know (symbolP); /* NULL pointer is logic error. */
3163 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3164 ext = S_IS_EXTERNAL (symbolP);
3165 #endif /* OBJ_AOUT or OBJ_BOUT */
3167 (void) expression (&exp);
3169 if (exp.X_op == O_illegal)
3170 as_bad (_("illegal expression; zero assumed"));
3171 else if (exp.X_op == O_absent)
3172 as_bad (_("missing expression; zero assumed"));
3173 else if (exp.X_op == O_big)
3175 if (exp.X_add_number > 0)
3176 as_bad (_("bignum invalid; zero assumed"));
3177 else
3178 as_bad (_("floating point number invalid; zero assumed"));
3180 else if (exp.X_op == O_subtract
3181 && (S_GET_SEGMENT (exp.X_add_symbol)
3182 == S_GET_SEGMENT (exp.X_op_symbol))
3183 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3184 && (symbol_get_frag (exp.X_add_symbol)
3185 == symbol_get_frag (exp.X_op_symbol)))
3187 exp.X_op = O_constant;
3188 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3189 - S_GET_VALUE (exp.X_op_symbol));
3192 switch (exp.X_op)
3194 case O_illegal:
3195 case O_absent:
3196 case O_big:
3197 exp.X_add_number = 0;
3198 /* Fall through. */
3199 case O_constant:
3200 S_SET_SEGMENT (symbolP, absolute_section);
3201 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3202 if (ext)
3203 S_SET_EXTERNAL (symbolP);
3204 else
3205 S_CLEAR_EXTERNAL (symbolP);
3206 #endif /* OBJ_AOUT or OBJ_BOUT */
3207 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3208 if (exp.X_op != O_constant)
3209 symbol_set_frag (symbolP, &zero_address_frag);
3210 break;
3212 case O_register:
3213 S_SET_SEGMENT (symbolP, reg_section);
3214 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3215 symbol_set_frag (symbolP, &zero_address_frag);
3216 break;
3218 case O_symbol:
3219 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3220 || exp.X_add_number != 0)
3221 symbol_set_value_expression (symbolP, &exp);
3222 else if (symbol_section_p (symbolP))
3223 as_bad ("invalid attempt to set value of section symbol");
3224 else
3226 symbolS *s = exp.X_add_symbol;
3228 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3229 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3230 if (ext)
3231 S_SET_EXTERNAL (symbolP);
3232 else
3233 S_CLEAR_EXTERNAL (symbolP);
3234 #endif /* OBJ_AOUT or OBJ_BOUT */
3235 S_SET_VALUE (symbolP,
3236 exp.X_add_number + S_GET_VALUE (s));
3237 symbol_set_frag (symbolP, symbol_get_frag (s));
3238 copy_symbol_attributes (symbolP, s);
3240 break;
3242 default:
3243 /* The value is some complex expression.
3244 FIXME: Should we set the segment to anything? */
3245 symbol_set_value_expression (symbolP, &exp);
3246 break;
3250 /* cons()
3252 CONStruct more frag of .bytes, or .words etc.
3253 Should need_pass_2 be 1 then emit no frag(s).
3254 This understands EXPRESSIONS.
3256 Bug (?)
3258 This has a split personality. We use expression() to read the
3259 value. We can detect if the value won't fit in a byte or word.
3260 But we can't detect if expression() discarded significant digits
3261 in the case of a long. Not worth the crocks required to fix it. */
3263 /* Select a parser for cons expressions. */
3265 /* Some targets need to parse the expression in various fancy ways.
3266 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3267 (for example, the HPPA does this). Otherwise, you can define
3268 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3269 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3270 are defined, which is the normal case, then only simple expressions
3271 are permitted. */
3273 #ifdef TC_M68K
3274 static void
3275 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3276 #endif
3278 #ifndef TC_PARSE_CONS_EXPRESSION
3279 #ifdef BITFIELD_CONS_EXPRESSIONS
3280 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3281 static void
3282 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3283 #endif
3284 #ifdef REPEAT_CONS_EXPRESSIONS
3285 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3286 static void
3287 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3288 #endif
3290 /* If we haven't gotten one yet, just call expression. */
3291 #ifndef TC_PARSE_CONS_EXPRESSION
3292 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3293 #endif
3294 #endif
3296 /* Worker to do .byte etc statements.
3297 Clobbers input_line_pointer and checks end-of-line. */
3299 static void
3300 cons_worker (nbytes, rva)
3301 register int nbytes; /* 1=.byte, 2=.word, 4=.long. */
3302 int rva;
3304 int c;
3305 expressionS exp;
3306 char *stop = NULL;
3307 char stopc;
3309 #ifdef md_flush_pending_output
3310 md_flush_pending_output ();
3311 #endif
3313 if (flag_mri)
3314 stop = mri_comment_field (&stopc);
3316 if (is_it_end_of_statement ())
3318 demand_empty_rest_of_line ();
3319 if (flag_mri)
3320 mri_comment_end (stop, stopc);
3321 return;
3324 #ifdef md_cons_align
3325 md_cons_align (nbytes);
3326 #endif
3328 c = 0;
3331 #ifdef TC_M68K
3332 if (flag_m68k_mri)
3333 parse_mri_cons (&exp, (unsigned int) nbytes);
3334 else
3335 #endif
3336 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3338 if (rva)
3340 if (exp.X_op == O_symbol)
3341 exp.X_op = O_symbol_rva;
3342 else
3343 as_fatal (_("rva without symbol"));
3345 emit_expr (&exp, (unsigned int) nbytes);
3346 ++c;
3348 while (*input_line_pointer++ == ',');
3350 /* In MRI mode, after an odd number of bytes, we must align to an
3351 even word boundary, unless the next instruction is a dc.b, ds.b
3352 or dcb.b. */
3353 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3354 mri_pending_align = 1;
3356 input_line_pointer--; /* Put terminator back into stream. */
3358 demand_empty_rest_of_line ();
3360 if (flag_mri)
3361 mri_comment_end (stop, stopc);
3364 void
3365 cons (size)
3366 int size;
3368 cons_worker (size, 0);
3371 void
3372 s_rva (size)
3373 int size;
3375 cons_worker (size, 1);
3378 /* Put the contents of expression EXP into the object file using
3379 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3381 void
3382 emit_expr (exp, nbytes)
3383 expressionS *exp;
3384 unsigned int nbytes;
3386 operatorT op;
3387 register char *p;
3388 valueT extra_digit = 0;
3390 /* Don't do anything if we are going to make another pass. */
3391 if (need_pass_2)
3392 return;
3394 #ifndef NO_LISTING
3395 #ifdef OBJ_ELF
3396 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3397 appear as a four byte positive constant in the .line section,
3398 followed by a 2 byte 0xffff. Look for that case here. */
3400 static int dwarf_line = -1;
3402 if (strcmp (segment_name (now_seg), ".line") != 0)
3403 dwarf_line = -1;
3404 else if (dwarf_line >= 0
3405 && nbytes == 2
3406 && exp->X_op == O_constant
3407 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3408 listing_source_line ((unsigned int) dwarf_line);
3409 else if (nbytes == 4
3410 && exp->X_op == O_constant
3411 && exp->X_add_number >= 0)
3412 dwarf_line = exp->X_add_number;
3413 else
3414 dwarf_line = -1;
3417 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3418 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3419 AT_sibling (0x12) followed by a four byte address of the sibling
3420 followed by a 2 byte AT_name (0x38) followed by the name of the
3421 file. We look for that case here. */
3423 static int dwarf_file = 0;
3425 if (strcmp (segment_name (now_seg), ".debug") != 0)
3426 dwarf_file = 0;
3427 else if (dwarf_file == 0
3428 && nbytes == 2
3429 && exp->X_op == O_constant
3430 && exp->X_add_number == 0x11)
3431 dwarf_file = 1;
3432 else if (dwarf_file == 1
3433 && nbytes == 2
3434 && exp->X_op == O_constant
3435 && exp->X_add_number == 0x12)
3436 dwarf_file = 2;
3437 else if (dwarf_file == 2
3438 && nbytes == 4)
3439 dwarf_file = 3;
3440 else if (dwarf_file == 3
3441 && nbytes == 2
3442 && exp->X_op == O_constant
3443 && exp->X_add_number == 0x38)
3444 dwarf_file = 4;
3445 else
3446 dwarf_file = 0;
3448 /* The variable dwarf_file_string tells stringer that the string
3449 may be the name of the source file. */
3450 if (dwarf_file == 4)
3451 dwarf_file_string = 1;
3452 else
3453 dwarf_file_string = 0;
3455 #endif
3456 #endif
3458 if (check_eh_frame (exp, &nbytes))
3459 return;
3461 op = exp->X_op;
3463 /* Allow `.word 0' in the absolute section. */
3464 if (now_seg == absolute_section)
3466 if (op != O_constant || exp->X_add_number != 0)
3467 as_bad (_("attempt to store value in absolute section"));
3468 abs_section_offset += nbytes;
3469 return;
3472 /* Handle a negative bignum. */
3473 if (op == O_uminus
3474 && exp->X_add_number == 0
3475 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3476 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3478 int i;
3479 unsigned long carry;
3481 exp = symbol_get_value_expression (exp->X_add_symbol);
3483 /* Negate the bignum: one's complement each digit and add 1. */
3484 carry = 1;
3485 for (i = 0; i < exp->X_add_number; i++)
3487 unsigned long next;
3489 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
3490 & LITTLENUM_MASK)
3491 + carry);
3492 generic_bignum[i] = next & LITTLENUM_MASK;
3493 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3496 /* We can ignore any carry out, because it will be handled by
3497 extra_digit if it is needed. */
3499 extra_digit = (valueT) -1;
3500 op = O_big;
3503 if (op == O_absent || op == O_illegal)
3505 as_warn (_("zero assumed for missing expression"));
3506 exp->X_add_number = 0;
3507 op = O_constant;
3509 else if (op == O_big && exp->X_add_number <= 0)
3511 as_bad (_("floating point number invalid; zero assumed"));
3512 exp->X_add_number = 0;
3513 op = O_constant;
3515 else if (op == O_register)
3517 as_warn (_("register value used as expression"));
3518 op = O_constant;
3521 p = frag_more ((int) nbytes);
3523 #ifndef WORKING_DOT_WORD
3524 /* If we have the difference of two symbols in a word, save it on
3525 the broken_words list. See the code in write.c. */
3526 if (op == O_subtract && nbytes == 2)
3528 struct broken_word *x;
3530 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3531 x->next_broken_word = broken_words;
3532 broken_words = x;
3533 x->seg = now_seg;
3534 x->subseg = now_subseg;
3535 x->frag = frag_now;
3536 x->word_goes_here = p;
3537 x->dispfrag = 0;
3538 x->add = exp->X_add_symbol;
3539 x->sub = exp->X_op_symbol;
3540 x->addnum = exp->X_add_number;
3541 x->added = 0;
3542 new_broken_words++;
3543 return;
3545 #endif
3547 /* If we have an integer, but the number of bytes is too large to
3548 pass to md_number_to_chars, handle it as a bignum. */
3549 if (op == O_constant && nbytes > sizeof (valueT))
3551 valueT val;
3552 int gencnt;
3554 if (!exp->X_unsigned && exp->X_add_number < 0)
3555 extra_digit = (valueT) -1;
3556 val = (valueT) exp->X_add_number;
3557 gencnt = 0;
3560 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3561 val >>= LITTLENUM_NUMBER_OF_BITS;
3562 ++gencnt;
3564 while (val != 0);
3565 op = exp->X_op = O_big;
3566 exp->X_add_number = gencnt;
3569 if (op == O_constant)
3571 register valueT get;
3572 register valueT use;
3573 register valueT mask;
3574 valueT hibit;
3575 register valueT unmask;
3577 /* JF << of >= number of bits in the object is undefined. In
3578 particular SPARC (Sun 4) has problems. */
3579 if (nbytes >= sizeof (valueT))
3581 mask = 0;
3582 if (nbytes > sizeof (valueT))
3583 hibit = 0;
3584 else
3585 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3587 else
3589 /* Don't store these bits. */
3590 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3591 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3594 unmask = ~mask; /* Do store these bits. */
3596 #ifdef NEVER
3597 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3598 mask = ~(unmask >> 1); /* Includes sign bit now. */
3599 #endif
3601 get = exp->X_add_number;
3602 use = get & unmask;
3603 if ((get & mask) != 0
3604 && ((get & mask) != mask
3605 || (get & hibit) == 0))
3606 { /* Leading bits contain both 0s & 1s. */
3607 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3608 (unsigned long) get, (unsigned long) use);
3610 /* Put bytes in right order. */
3611 md_number_to_chars (p, use, (int) nbytes);
3613 else if (op == O_big)
3615 unsigned int size;
3616 LITTLENUM_TYPE *nums;
3618 know (nbytes % CHARS_PER_LITTLENUM == 0);
3620 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3621 if (nbytes < size)
3623 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3624 size = nbytes;
3627 if (target_big_endian)
3629 while (nbytes > size)
3631 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3632 nbytes -= CHARS_PER_LITTLENUM;
3633 p += CHARS_PER_LITTLENUM;
3636 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3637 while (size > 0)
3639 --nums;
3640 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3641 size -= CHARS_PER_LITTLENUM;
3642 p += CHARS_PER_LITTLENUM;
3645 else
3647 nums = generic_bignum;
3648 while (size > 0)
3650 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3651 ++nums;
3652 size -= CHARS_PER_LITTLENUM;
3653 p += CHARS_PER_LITTLENUM;
3654 nbytes -= CHARS_PER_LITTLENUM;
3657 while (nbytes > 0)
3659 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3660 nbytes -= CHARS_PER_LITTLENUM;
3661 p += CHARS_PER_LITTLENUM;
3665 else
3667 memset (p, 0, nbytes);
3669 /* Now we need to generate a fixS to record the symbol value.
3670 This is easy for BFD. For other targets it can be more
3671 complex. For very complex cases (currently, the HPPA and
3672 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3673 want. For simpler cases, you can define TC_CONS_RELOC to be
3674 the name of the reloc code that should be stored in the fixS.
3675 If neither is defined, the code uses NO_RELOC if it is
3676 defined, and otherwise uses 0. */
3678 #ifdef BFD_ASSEMBLER
3679 #ifdef TC_CONS_FIX_NEW
3680 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3681 #else
3683 bfd_reloc_code_real_type r;
3685 switch (nbytes)
3687 case 1:
3688 r = BFD_RELOC_8;
3689 break;
3690 case 2:
3691 r = BFD_RELOC_16;
3692 break;
3693 case 4:
3694 r = BFD_RELOC_32;
3695 break;
3696 case 8:
3697 r = BFD_RELOC_64;
3698 break;
3699 default:
3700 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3701 r = BFD_RELOC_32;
3702 break;
3704 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3705 0, r);
3707 #endif
3708 #else
3709 #ifdef TC_CONS_FIX_NEW
3710 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3711 #else
3712 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3713 it is defined, otherwise use NO_RELOC if it is defined,
3714 otherwise use 0. */
3715 #ifndef TC_CONS_RELOC
3716 #ifdef NO_RELOC
3717 #define TC_CONS_RELOC NO_RELOC
3718 #else
3719 #define TC_CONS_RELOC 0
3720 #endif
3721 #endif
3722 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3723 TC_CONS_RELOC);
3724 #endif /* TC_CONS_FIX_NEW */
3725 #endif /* BFD_ASSEMBLER */
3729 #ifdef BITFIELD_CONS_EXPRESSIONS
3731 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3732 w:x,y:z, where w and y are bitwidths and x and y are values. They
3733 then pack them all together. We do a little better in that we allow
3734 them in words, longs, etc. and we'll pack them in target byte order
3735 for you.
3737 The rules are: pack least significat bit first, if a field doesn't
3738 entirely fit, put it in the next unit. Overflowing the bitfield is
3739 explicitly *not* even a warning. The bitwidth should be considered
3740 a "mask".
3742 To use this function the tc-XXX.h file should define
3743 BITFIELD_CONS_EXPRESSIONS. */
3745 static void
3746 parse_bitfield_cons (exp, nbytes)
3747 expressionS *exp;
3748 unsigned int nbytes;
3750 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3751 char *hold = input_line_pointer;
3753 (void) expression (exp);
3755 if (*input_line_pointer == ':')
3757 /* Bitfields. */
3758 long value = 0;
3760 for (;;)
3762 unsigned long width;
3764 if (*input_line_pointer != ':')
3766 input_line_pointer = hold;
3767 break;
3768 } /* Next piece is not a bitfield. */
3770 /* In the general case, we can't allow
3771 full expressions with symbol
3772 differences and such. The relocation
3773 entries for symbols not defined in this
3774 assembly would require arbitrary field
3775 widths, positions, and masks which most
3776 of our current object formats don't
3777 support.
3779 In the specific case where a symbol
3780 *is* defined in this assembly, we
3781 *could* build fixups and track it, but
3782 this could lead to confusion for the
3783 backends. I'm lazy. I'll take any
3784 SEG_ABSOLUTE. I think that means that
3785 you can use a previous .set or
3786 .equ type symbol. xoxorich. */
3788 if (exp->X_op == O_absent)
3790 as_warn (_("using a bit field width of zero"));
3791 exp->X_add_number = 0;
3792 exp->X_op = O_constant;
3793 } /* Implied zero width bitfield. */
3795 if (exp->X_op != O_constant)
3797 *input_line_pointer = '\0';
3798 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3799 *input_line_pointer = ':';
3800 demand_empty_rest_of_line ();
3801 return;
3802 } /* Too complex. */
3804 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3806 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3807 width, nbytes, (BITS_PER_CHAR * nbytes));
3808 width = BITS_PER_CHAR * nbytes;
3809 } /* Too big. */
3811 if (width > bits_available)
3813 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3814 input_line_pointer = hold;
3815 exp->X_add_number = value;
3816 break;
3817 } /* Won't fit. */
3819 /* Skip ':'. */
3820 hold = ++input_line_pointer;
3822 (void) expression (exp);
3823 if (exp->X_op != O_constant)
3825 char cache = *input_line_pointer;
3827 *input_line_pointer = '\0';
3828 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3829 *input_line_pointer = cache;
3830 demand_empty_rest_of_line ();
3831 return;
3832 } /* Too complex. */
3834 value |= ((~(-1 << width) & exp->X_add_number)
3835 << ((BITS_PER_CHAR * nbytes) - bits_available));
3837 if ((bits_available -= width) == 0
3838 || is_it_end_of_statement ()
3839 || *input_line_pointer != ',')
3841 break;
3842 } /* All the bitfields we're gonna get. */
3844 hold = ++input_line_pointer;
3845 (void) expression (exp);
3848 exp->X_add_number = value;
3849 exp->X_op = O_constant;
3850 exp->X_unsigned = 1;
3854 #endif /* BITFIELD_CONS_EXPRESSIONS */
3856 /* Handle an MRI style string expression. */
3858 #ifdef TC_M68K
3859 static void
3860 parse_mri_cons (exp, nbytes)
3861 expressionS *exp;
3862 unsigned int nbytes;
3864 if (*input_line_pointer != '\''
3865 && (input_line_pointer[1] != '\''
3866 || (*input_line_pointer != 'A'
3867 && *input_line_pointer != 'E')))
3868 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3869 else
3871 unsigned int scan;
3872 unsigned int result = 0;
3874 /* An MRI style string. Cut into as many bytes as will fit into
3875 a nbyte chunk, left justify if necessary, and separate with
3876 commas so we can try again later. */
3877 if (*input_line_pointer == 'A')
3878 ++input_line_pointer;
3879 else if (*input_line_pointer == 'E')
3881 as_bad (_("EBCDIC constants are not supported"));
3882 ++input_line_pointer;
3885 input_line_pointer++;
3886 for (scan = 0; scan < nbytes; scan++)
3888 if (*input_line_pointer == '\'')
3890 if (input_line_pointer[1] == '\'')
3892 input_line_pointer++;
3894 else
3895 break;
3897 result = (result << 8) | (*input_line_pointer++);
3900 /* Left justify. */
3901 while (scan < nbytes)
3903 result <<= 8;
3904 scan++;
3907 /* Create correct expression. */
3908 exp->X_op = O_constant;
3909 exp->X_add_number = result;
3911 /* Fake it so that we can read the next char too. */
3912 if (input_line_pointer[0] != '\'' ||
3913 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3915 input_line_pointer -= 2;
3916 input_line_pointer[0] = ',';
3917 input_line_pointer[1] = '\'';
3919 else
3920 input_line_pointer++;
3923 #endif /* TC_M68K */
3925 #ifdef REPEAT_CONS_EXPRESSIONS
3927 /* Parse a repeat expression for cons. This is used by the MIPS
3928 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3929 object file COUNT times.
3931 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3933 static void
3934 parse_repeat_cons (exp, nbytes)
3935 expressionS *exp;
3936 unsigned int nbytes;
3938 expressionS count;
3939 register int i;
3941 expression (exp);
3943 if (*input_line_pointer != ':')
3945 /* No repeat count. */
3946 return;
3949 ++input_line_pointer;
3950 expression (&count);
3951 if (count.X_op != O_constant
3952 || count.X_add_number <= 0)
3954 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3955 return;
3958 /* The cons function is going to output this expression once. So we
3959 output it count - 1 times. */
3960 for (i = count.X_add_number - 1; i > 0; i--)
3961 emit_expr (exp, nbytes);
3964 #endif /* REPEAT_CONS_EXPRESSIONS */
3966 /* Parse a floating point number represented as a hex constant. This
3967 permits users to specify the exact bits they want in the floating
3968 point number. */
3970 static int
3971 hex_float (float_type, bytes)
3972 int float_type;
3973 char *bytes;
3975 int length;
3976 int i;
3978 switch (float_type)
3980 case 'f':
3981 case 'F':
3982 case 's':
3983 case 'S':
3984 length = 4;
3985 break;
3987 case 'd':
3988 case 'D':
3989 case 'r':
3990 case 'R':
3991 length = 8;
3992 break;
3994 case 'x':
3995 case 'X':
3996 length = 12;
3997 break;
3999 case 'p':
4000 case 'P':
4001 length = 12;
4002 break;
4004 default:
4005 as_bad (_("Unknown floating type type '%c'"), float_type);
4006 return -1;
4009 /* It would be nice if we could go through expression to parse the
4010 hex constant, but if we get a bignum it's a pain to sort it into
4011 the buffer correctly. */
4012 i = 0;
4013 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4015 int d;
4017 /* The MRI assembler accepts arbitrary underscores strewn about
4018 through the hex constant, so we ignore them as well. */
4019 if (*input_line_pointer == '_')
4021 ++input_line_pointer;
4022 continue;
4025 if (i >= length)
4027 as_warn (_("Floating point constant too large"));
4028 return -1;
4030 d = hex_value (*input_line_pointer) << 4;
4031 ++input_line_pointer;
4032 while (*input_line_pointer == '_')
4033 ++input_line_pointer;
4034 if (hex_p (*input_line_pointer))
4036 d += hex_value (*input_line_pointer);
4037 ++input_line_pointer;
4039 if (target_big_endian)
4040 bytes[i] = d;
4041 else
4042 bytes[length - i - 1] = d;
4043 ++i;
4046 if (i < length)
4048 if (target_big_endian)
4049 memset (bytes + i, 0, length - i);
4050 else
4051 memset (bytes, 0, length - i);
4054 return length;
4057 /* float_cons()
4059 CONStruct some more frag chars of .floats .ffloats etc.
4060 Makes 0 or more new frags.
4061 If need_pass_2 == 1, no frags are emitted.
4062 This understands only floating literals, not expressions. Sorry.
4064 A floating constant is defined by atof_generic(), except it is preceded
4065 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4066 reading, I decided to be incompatible. This always tries to give you
4067 rounded bits to the precision of the pseudo-op. Former AS did premature
4068 truncatation, restored noisy bits instead of trailing 0s AND gave you
4069 a choice of 2 flavours of noise according to which of 2 floating-point
4070 scanners you directed AS to use.
4072 In: input_line_pointer->whitespace before, or '0' of flonum. */
4074 void
4075 float_cons (float_type)
4076 /* Clobbers input_line-pointer, checks end-of-line. */
4077 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4079 register char *p;
4080 int length; /* Number of chars in an object. */
4081 register char *err; /* Error from scanning floating literal. */
4082 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4084 if (is_it_end_of_statement ())
4086 demand_empty_rest_of_line ();
4087 return;
4090 #ifdef md_flush_pending_output
4091 md_flush_pending_output ();
4092 #endif
4096 /* input_line_pointer->1st char of a flonum (we hope!). */
4097 SKIP_WHITESPACE ();
4099 /* Skip any 0{letter} that may be present. Don't even check if the
4100 letter is legal. Someone may invent a "z" format and this routine
4101 has no use for such information. Lusers beware: you get
4102 diagnostics if your input is ill-conditioned. */
4103 if (input_line_pointer[0] == '0'
4104 && isalpha ((unsigned char) input_line_pointer[1]))
4105 input_line_pointer += 2;
4107 /* Accept :xxxx, where the x's are hex digits, for a floating
4108 point with the exact digits specified. */
4109 if (input_line_pointer[0] == ':')
4111 ++input_line_pointer;
4112 length = hex_float (float_type, temp);
4113 if (length < 0)
4115 ignore_rest_of_line ();
4116 return;
4119 else
4121 err = md_atof (float_type, temp, &length);
4122 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4123 know (length > 0);
4124 if (err)
4126 as_bad (_("Bad floating literal: %s"), err);
4127 ignore_rest_of_line ();
4128 return;
4132 if (!need_pass_2)
4134 int count;
4136 count = 1;
4138 #ifdef REPEAT_CONS_EXPRESSIONS
4139 if (*input_line_pointer == ':')
4141 expressionS count_exp;
4143 ++input_line_pointer;
4144 expression (&count_exp);
4146 if (count_exp.X_op != O_constant
4147 || count_exp.X_add_number <= 0)
4148 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4149 else
4150 count = count_exp.X_add_number;
4152 #endif
4154 while (--count >= 0)
4156 p = frag_more (length);
4157 memcpy (p, temp, (unsigned int) length);
4160 SKIP_WHITESPACE ();
4162 while (*input_line_pointer++ == ',');
4164 /* Put terminator back into stream. */
4165 --input_line_pointer;
4166 demand_empty_rest_of_line ();
4169 /* Return the size of a LEB128 value. */
4171 static inline int
4172 sizeof_sleb128 (value)
4173 offsetT value;
4175 register int size = 0;
4176 register unsigned byte;
4180 byte = (value & 0x7f);
4181 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4182 Fortunately, we can structure things so that the extra work reduces
4183 to a noop on systems that do things "properly". */
4184 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4185 size += 1;
4187 while (!(((value == 0) && ((byte & 0x40) == 0))
4188 || ((value == -1) && ((byte & 0x40) != 0))));
4190 return size;
4193 static inline int
4194 sizeof_uleb128 (value)
4195 valueT value;
4197 register int size = 0;
4198 register unsigned byte;
4202 byte = (value & 0x7f);
4203 value >>= 7;
4204 size += 1;
4206 while (value != 0);
4208 return size;
4212 sizeof_leb128 (value, sign)
4213 valueT value;
4214 int sign;
4216 if (sign)
4217 return sizeof_sleb128 ((offsetT) value);
4218 else
4219 return sizeof_uleb128 (value);
4222 /* Output a LEB128 value. */
4224 static inline int
4225 output_sleb128 (p, value)
4226 char *p;
4227 offsetT value;
4229 register char *orig = p;
4230 register int more;
4234 unsigned byte = (value & 0x7f);
4236 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4237 Fortunately, we can structure things so that the extra work reduces
4238 to a noop on systems that do things "properly". */
4239 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4241 more = !((((value == 0) && ((byte & 0x40) == 0))
4242 || ((value == -1) && ((byte & 0x40) != 0))));
4243 if (more)
4244 byte |= 0x80;
4246 *p++ = byte;
4248 while (more);
4250 return p - orig;
4253 static inline int
4254 output_uleb128 (p, value)
4255 char *p;
4256 valueT value;
4258 char *orig = p;
4262 unsigned byte = (value & 0x7f);
4263 value >>= 7;
4264 if (value != 0)
4265 /* More bytes to follow. */
4266 byte |= 0x80;
4268 *p++ = byte;
4270 while (value != 0);
4272 return p - orig;
4276 output_leb128 (p, value, sign)
4277 char *p;
4278 valueT value;
4279 int sign;
4281 if (sign)
4282 return output_sleb128 (p, (offsetT) value);
4283 else
4284 return output_uleb128 (p, value);
4287 /* Do the same for bignums. We combine sizeof with output here in that
4288 we don't output for NULL values of P. It isn't really as critical as
4289 for "normal" values that this be streamlined. */
4291 static inline int
4292 output_big_sleb128 (p, bignum, size)
4293 char *p;
4294 LITTLENUM_TYPE *bignum;
4295 int size;
4297 char *orig = p;
4298 valueT val = 0;
4299 int loaded = 0;
4300 unsigned byte;
4302 /* Strip leading sign extensions off the bignum. */
4303 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
4304 size--;
4308 if (loaded < 7 && size > 0)
4310 val |= (*bignum << loaded);
4311 loaded += 8 * CHARS_PER_LITTLENUM;
4312 size--;
4313 bignum++;
4316 byte = val & 0x7f;
4317 loaded -= 7;
4318 val >>= 7;
4320 if (size == 0)
4322 if ((val == 0 && (byte & 0x40) == 0)
4323 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
4324 && (byte & 0x40) != 0))
4325 byte |= 0x80;
4328 if (orig)
4329 *p = byte;
4330 p++;
4332 while (byte & 0x80);
4334 return p - orig;
4337 static inline int
4338 output_big_uleb128 (p, bignum, size)
4339 char *p;
4340 LITTLENUM_TYPE *bignum;
4341 int size;
4343 char *orig = p;
4344 valueT val = 0;
4345 int loaded = 0;
4346 unsigned byte;
4348 /* Strip leading zeros off the bignum. */
4349 /* XXX: Is this needed? */
4350 while (size > 0 && bignum[size - 1] == 0)
4351 size--;
4355 if (loaded < 7 && size > 0)
4357 val |= (*bignum << loaded);
4358 loaded += 8 * CHARS_PER_LITTLENUM;
4359 size--;
4360 bignum++;
4363 byte = val & 0x7f;
4364 loaded -= 7;
4365 val >>= 7;
4367 if (size > 0 || val)
4368 byte |= 0x80;
4370 if (orig)
4371 *p = byte;
4372 p++;
4374 while (byte & 0x80);
4376 return p - orig;
4379 static int
4380 output_big_leb128 (p, bignum, size, sign)
4381 char *p;
4382 LITTLENUM_TYPE *bignum;
4383 int size, sign;
4385 if (sign)
4386 return output_big_sleb128 (p, bignum, size);
4387 else
4388 return output_big_uleb128 (p, bignum, size);
4391 /* Generate the appropriate fragments for a given expression to emit a
4392 leb128 value. */
4394 void
4395 emit_leb128_expr (exp, sign)
4396 expressionS *exp;
4397 int sign;
4399 operatorT op = exp->X_op;
4401 if (op == O_absent || op == O_illegal)
4403 as_warn (_("zero assumed for missing expression"));
4404 exp->X_add_number = 0;
4405 op = O_constant;
4407 else if (op == O_big && exp->X_add_number <= 0)
4409 as_bad (_("floating point number invalid; zero assumed"));
4410 exp->X_add_number = 0;
4411 op = O_constant;
4413 else if (op == O_register)
4415 as_warn (_("register value used as expression"));
4416 op = O_constant;
4419 if (op == O_constant)
4421 /* If we've got a constant, emit the thing directly right now. */
4423 valueT value = exp->X_add_number;
4424 int size;
4425 char *p;
4427 size = sizeof_leb128 (value, sign);
4428 p = frag_more (size);
4429 output_leb128 (p, value, sign);
4431 else if (op == O_big)
4433 /* O_big is a different sort of constant. */
4435 int size;
4436 char *p;
4438 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4439 p = frag_more (size);
4440 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4442 else
4444 /* Otherwise, we have to create a variable sized fragment and
4445 resolve things later. */
4447 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4448 make_expr_symbol (exp), 0, (char *) NULL);
4452 /* Parse the .sleb128 and .uleb128 pseudos. */
4454 void
4455 s_leb128 (sign)
4456 int sign;
4458 expressionS exp;
4462 expression (&exp);
4463 emit_leb128_expr (&exp, sign);
4465 while (*input_line_pointer++ == ',');
4467 input_line_pointer--;
4468 demand_empty_rest_of_line ();
4471 /* We read 0 or more ',' separated, double-quoted strings.
4472 Caller should have checked need_pass_2 is FALSE because we don't
4473 check it. */
4475 void
4476 stringer (append_zero) /* Worker to do .ascii etc statements. */
4477 /* Checks end-of-line. */
4478 register int append_zero; /* 0: don't append '\0', else 1. */
4480 register unsigned int c;
4481 char *start;
4483 #ifdef md_flush_pending_output
4484 md_flush_pending_output ();
4485 #endif
4487 /* The following awkward logic is to parse ZERO or more strings,
4488 comma separated. Recall a string expression includes spaces
4489 before the opening '\"' and spaces after the closing '\"'.
4490 We fake a leading ',' if there is (supposed to be)
4491 a 1st, expression. We keep demanding expressions for each ','. */
4492 if (is_it_end_of_statement ())
4494 c = 0; /* Skip loop. */
4495 ++input_line_pointer; /* Compensate for end of loop. */
4497 else
4499 c = ','; /* Do loop. */
4501 while (c == ',' || c == '<' || c == '"')
4503 SKIP_WHITESPACE ();
4504 switch (*input_line_pointer)
4506 case '\"':
4507 ++input_line_pointer; /*->1st char of string. */
4508 start = input_line_pointer;
4509 while (is_a_char (c = next_char_of_string ()))
4511 FRAG_APPEND_1_CHAR (c);
4513 if (append_zero)
4515 FRAG_APPEND_1_CHAR (0);
4517 know (input_line_pointer[-1] == '\"');
4519 #ifndef NO_LISTING
4520 #ifdef OBJ_ELF
4521 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4522 will emit .string with a filename in the .debug section
4523 after a sequence of constants. See the comment in
4524 emit_expr for the sequence. emit_expr will set
4525 dwarf_file_string to non-zero if this string might be a
4526 source file name. */
4527 if (strcmp (segment_name (now_seg), ".debug") != 0)
4528 dwarf_file_string = 0;
4529 else if (dwarf_file_string)
4531 c = input_line_pointer[-1];
4532 input_line_pointer[-1] = '\0';
4533 listing_source_file (start);
4534 input_line_pointer[-1] = c;
4536 #endif
4537 #endif
4539 break;
4540 case '<':
4541 input_line_pointer++;
4542 c = get_single_number ();
4543 FRAG_APPEND_1_CHAR (c);
4544 if (*input_line_pointer != '>')
4546 as_bad (_("Expected <nn>"));
4548 input_line_pointer++;
4549 break;
4550 case ',':
4551 input_line_pointer++;
4552 break;
4554 SKIP_WHITESPACE ();
4555 c = *input_line_pointer;
4558 demand_empty_rest_of_line ();
4559 } /* stringer() */
4561 /* FIXME-SOMEDAY: I had trouble here on characters with the
4562 high bits set. We'll probably also have trouble with
4563 multibyte chars, wide chars, etc. Also be careful about
4564 returning values bigger than 1 byte. xoxorich. */
4566 unsigned int
4567 next_char_of_string ()
4569 register unsigned int c;
4571 c = *input_line_pointer++ & CHAR_MASK;
4572 switch (c)
4574 case '\"':
4575 c = NOT_A_CHAR;
4576 break;
4578 case '\n':
4579 as_warn (_("Unterminated string: Newline inserted."));
4580 bump_line_counters ();
4581 break;
4583 #ifndef NO_STRING_ESCAPES
4584 case '\\':
4585 switch (c = *input_line_pointer++)
4587 case 'b':
4588 c = '\b';
4589 break;
4591 case 'f':
4592 c = '\f';
4593 break;
4595 case 'n':
4596 c = '\n';
4597 break;
4599 case 'r':
4600 c = '\r';
4601 break;
4603 case 't':
4604 c = '\t';
4605 break;
4607 case 'v':
4608 c = '\013';
4609 break;
4611 case '\\':
4612 case '"':
4613 break; /* As itself. */
4615 case '0':
4616 case '1':
4617 case '2':
4618 case '3':
4619 case '4':
4620 case '5':
4621 case '6':
4622 case '7':
4623 case '8':
4624 case '9':
4626 long number;
4627 int i;
4629 for (i = 0, number = 0;
4630 isdigit (c) && i < 3;
4631 c = *input_line_pointer++, i++)
4633 number = number * 8 + c - '0';
4636 c = number & 0xff;
4638 --input_line_pointer;
4639 break;
4641 case 'x':
4642 case 'X':
4644 long number;
4646 number = 0;
4647 c = *input_line_pointer++;
4648 while (isxdigit (c))
4650 if (isdigit (c))
4651 number = number * 16 + c - '0';
4652 else if (isupper (c))
4653 number = number * 16 + c - 'A' + 10;
4654 else
4655 number = number * 16 + c - 'a' + 10;
4656 c = *input_line_pointer++;
4658 c = number & 0xff;
4659 --input_line_pointer;
4661 break;
4663 case '\n':
4664 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4665 as_warn (_("Unterminated string: Newline inserted."));
4666 c = '\n';
4667 bump_line_counters ();
4668 break;
4670 default:
4672 #ifdef ONLY_STANDARD_ESCAPES
4673 as_bad (_("Bad escaped character in string, '?' assumed"));
4674 c = '?';
4675 #endif /* ONLY_STANDARD_ESCAPES */
4677 break;
4679 break;
4680 #endif /* ! defined (NO_STRING_ESCAPES) */
4682 default:
4683 break;
4685 return (c);
4688 static segT
4689 get_segmented_expression (expP)
4690 register expressionS *expP;
4692 register segT retval;
4694 retval = expression (expP);
4695 if (expP->X_op == O_illegal
4696 || expP->X_op == O_absent
4697 || expP->X_op == O_big)
4699 as_bad (_("expected address expression; zero assumed"));
4700 expP->X_op = O_constant;
4701 expP->X_add_number = 0;
4702 retval = absolute_section;
4704 return retval;
4707 static segT
4708 get_known_segmented_expression (expP)
4709 register expressionS *expP;
4711 register segT retval;
4713 if ((retval = get_segmented_expression (expP)) == undefined_section)
4715 /* There is no easy way to extract the undefined symbol from the
4716 expression. */
4717 if (expP->X_add_symbol != NULL
4718 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4719 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4720 S_GET_NAME (expP->X_add_symbol));
4721 else
4722 as_warn (_("some symbol undefined; zero assumed"));
4723 retval = absolute_section;
4724 expP->X_op = O_constant;
4725 expP->X_add_number = 0;
4727 know (retval == absolute_section || SEG_NORMAL (retval));
4728 return (retval);
4731 offsetT
4732 get_absolute_expression ()
4734 expressionS exp;
4736 expression (&exp);
4737 if (exp.X_op != O_constant)
4739 if (exp.X_op != O_absent)
4740 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4741 exp.X_add_number = 0;
4743 return exp.X_add_number;
4746 char /* Return terminator. */
4747 get_absolute_expression_and_terminator (val_pointer)
4748 long *val_pointer; /* Return value of expression. */
4750 /* FIXME: val_pointer should probably be offsetT *. */
4751 *val_pointer = (long) get_absolute_expression ();
4752 return (*input_line_pointer++);
4755 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4756 Give a warning if that happens. */
4758 char *
4759 demand_copy_C_string (len_pointer)
4760 int *len_pointer;
4762 register char *s;
4764 if ((s = demand_copy_string (len_pointer)) != 0)
4766 register int len;
4768 for (len = *len_pointer; len > 0; len--)
4770 if (*s == 0)
4772 s = 0;
4773 len = 1;
4774 *len_pointer = 0;
4775 as_bad (_("This string may not contain \'\\0\'"));
4780 return s;
4783 /* Demand string, but return a safe (=private) copy of the string.
4784 Return NULL if we can't read a string here. */
4786 char *
4787 demand_copy_string (lenP)
4788 int *lenP;
4790 register unsigned int c;
4791 register int len;
4792 char *retval;
4794 len = 0;
4795 SKIP_WHITESPACE ();
4796 if (*input_line_pointer == '\"')
4798 input_line_pointer++; /* Skip opening quote. */
4800 while (is_a_char (c = next_char_of_string ()))
4802 obstack_1grow (&notes, c);
4803 len++;
4805 /* JF this next line is so demand_copy_C_string will return a
4806 null terminated string. */
4807 obstack_1grow (&notes, '\0');
4808 retval = obstack_finish (&notes);
4810 else
4812 as_warn (_("Missing string"));
4813 retval = NULL;
4814 ignore_rest_of_line ();
4816 *lenP = len;
4817 return (retval);
4820 /* In: Input_line_pointer->next character.
4822 Do: Skip input_line_pointer over all whitespace.
4824 Out: 1 if input_line_pointer->end-of-line. */
4827 is_it_end_of_statement ()
4829 SKIP_WHITESPACE ();
4830 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4833 void
4834 equals (sym_name, reassign)
4835 char *sym_name;
4836 int reassign;
4838 register symbolS *symbolP; /* Symbol we are working with. */
4839 char *stop = NULL;
4840 char stopc;
4842 input_line_pointer++;
4843 if (*input_line_pointer == '=')
4844 input_line_pointer++;
4846 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4847 input_line_pointer++;
4849 if (flag_mri)
4850 stop = mri_comment_field (&stopc);
4852 if (sym_name[0] == '.' && sym_name[1] == '\0')
4854 /* Turn '. = mumble' into a .org mumble. */
4855 register segT segment;
4856 expressionS exp;
4858 segment = get_known_segmented_expression (&exp);
4859 if (!need_pass_2)
4860 do_org (segment, &exp, 0);
4862 else
4864 symbolP = symbol_find_or_make (sym_name);
4865 /* Permit register names to be redefined. */
4866 if (!reassign
4867 && S_IS_DEFINED (symbolP)
4868 && S_GET_SEGMENT (symbolP) != reg_section)
4869 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4870 pseudo_set (symbolP);
4873 if (flag_mri)
4875 /* Check garbage after the expression. */
4876 ignore_rest_of_line ();
4877 mri_comment_end (stop, stopc);
4881 /* .include -- include a file at this point. */
4883 void
4884 s_include (arg)
4885 int arg ATTRIBUTE_UNUSED;
4887 char *filename;
4888 int i;
4889 FILE *try;
4890 char *path;
4892 if (!flag_m68k_mri)
4894 filename = demand_copy_string (&i);
4895 if (filename == NULL)
4897 /* demand_copy_string has already printed an error and
4898 called ignore_rest_of_line. */
4899 return;
4902 else
4904 SKIP_WHITESPACE ();
4905 i = 0;
4906 while (!is_end_of_line[(unsigned char) *input_line_pointer]
4907 && *input_line_pointer != ' '
4908 && *input_line_pointer != '\t')
4910 obstack_1grow (&notes, *input_line_pointer);
4911 ++input_line_pointer;
4912 ++i;
4915 obstack_1grow (&notes, '\0');
4916 filename = obstack_finish (&notes);
4917 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4918 ++input_line_pointer;
4921 demand_empty_rest_of_line ();
4922 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4924 for (i = 0; i < include_dir_count; i++)
4926 strcpy (path, include_dirs[i]);
4927 strcat (path, "/");
4928 strcat (path, filename);
4929 if (0 != (try = fopen (path, "r")))
4931 fclose (try);
4932 goto gotit;
4936 free (path);
4937 path = filename;
4938 gotit:
4939 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4940 register_dependency (path);
4941 input_scrub_insert_file (path);
4944 void
4945 add_include_dir (path)
4946 char *path;
4948 int i;
4950 if (include_dir_count == 0)
4952 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4953 include_dirs[0] = "."; /* Current dir. */
4954 include_dir_count = 2;
4956 else
4958 include_dir_count++;
4959 include_dirs =
4960 (char **) realloc (include_dirs,
4961 include_dir_count * sizeof (*include_dirs));
4964 include_dirs[include_dir_count - 1] = path; /* New one. */
4966 i = strlen (path);
4967 if (i > include_dir_maxlen)
4968 include_dir_maxlen = i;
4971 /* Output debugging information to denote the source file. */
4973 static void
4974 generate_file_debug ()
4976 if (debug_type == DEBUG_STABS)
4977 stabs_generate_asm_file ();
4980 /* Output line number debugging information for the current source line. */
4982 void
4983 generate_lineno_debug ()
4985 switch (debug_type)
4987 case DEBUG_UNSPECIFIED:
4988 case DEBUG_NONE:
4989 case DEBUG_DWARF:
4990 break;
4991 case DEBUG_STABS:
4992 stabs_generate_asm_lineno ();
4993 break;
4994 case DEBUG_ECOFF:
4995 ecoff_generate_asm_lineno ();
4996 break;
4997 case DEBUG_DWARF2:
4998 /* ??? We could here indicate to dwarf2dbg.c that something
4999 has changed. However, since there is additional backend
5000 support that is required (calling dwarf2_emit_insn), we
5001 let dwarf2dbg.c call as_where on its own. */
5002 break;
5006 /* Output debugging information to mark a function entry point or end point.
5007 END_P is zero for .func, and non-zero for .endfunc. */
5009 void
5010 s_func (end_p)
5011 int end_p;
5013 do_s_func (end_p, NULL);
5016 /* Subroutine of s_func so targets can choose a different default prefix.
5017 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5019 void
5020 do_s_func (end_p, default_prefix)
5021 int end_p;
5022 const char *default_prefix;
5024 /* Record the current function so that we can issue an error message for
5025 misplaced .func,.endfunc, and also so that .endfunc needs no
5026 arguments. */
5027 static char *current_name;
5028 static char *current_label;
5030 if (end_p)
5032 if (current_name == NULL)
5034 as_bad (_("missing .func"));
5035 ignore_rest_of_line ();
5036 return;
5039 if (debug_type == DEBUG_STABS)
5040 stabs_generate_asm_endfunc (current_name, current_label);
5042 current_name = current_label = NULL;
5044 else /* ! end_p */
5046 char *name, *label;
5047 char delim1, delim2;
5049 if (current_name != NULL)
5051 as_bad (_(".endfunc missing for previous .func"));
5052 ignore_rest_of_line ();
5053 return;
5056 name = input_line_pointer;
5057 delim1 = get_symbol_end ();
5058 name = xstrdup (name);
5059 *input_line_pointer = delim1;
5060 SKIP_WHITESPACE ();
5061 if (*input_line_pointer != ',')
5063 if (default_prefix)
5064 asprintf (&label, "%s%s", default_prefix, name);
5065 else
5067 char leading_char = 0;
5068 #ifdef BFD_ASSEMBLER
5069 leading_char = bfd_get_symbol_leading_char (stdoutput);
5070 #endif
5071 /* Missing entry point, use function's name with the leading
5072 char prepended. */
5073 if (leading_char)
5074 asprintf (&label, "%c%s", leading_char, name);
5075 else
5076 label = name;
5079 else
5081 ++input_line_pointer;
5082 SKIP_WHITESPACE ();
5083 label = input_line_pointer;
5084 delim2 = get_symbol_end ();
5085 label = xstrdup (label);
5086 *input_line_pointer = delim2;
5089 if (debug_type == DEBUG_STABS)
5090 stabs_generate_asm_func (name, label);
5092 current_name = name;
5093 current_label = label;
5096 demand_empty_rest_of_line ();
5099 void
5100 s_ignore (arg)
5101 int arg ATTRIBUTE_UNUSED;
5103 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5105 ++input_line_pointer;
5107 ++input_line_pointer;
5110 void
5111 read_print_statistics (file)
5112 FILE *file;
5114 hash_print_statistics (file, "pseudo-op table", po_hash);
5117 /* Inserts the given line into the input stream.
5119 This call avoids macro/conditionals nesting checking, since the contents of
5120 the line are assumed to replace the contents of a line already scanned.
5122 An appropriate use of this function would be substition of input lines when
5123 called by md_start_line_hook(). The given line is assumed to already be
5124 properly scrubbed. */
5126 void
5127 input_scrub_insert_line (line)
5128 const char *line;
5130 sb newline;
5131 sb_new (&newline);
5132 sb_add_string (&newline, line);
5133 input_scrub_include_sb (&newline, input_line_pointer, 0);
5134 sb_kill (&newline);
5135 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5138 /* Insert a file into the input stream; the path must resolve to an actual
5139 file; no include path searching or dependency registering is performed. */
5141 void
5142 input_scrub_insert_file (path)
5143 char *path;
5145 input_scrub_include_file (path, input_line_pointer);
5146 buffer_limit = input_scrub_next_buffer (&input_line_pointer);