* ltconfig, ltmain.sh: Update to libtool 1.3.4.
[binutils.git] / gas / read.c
blob71dae8e42e8b72d92b560be9f5f151d81d160fe4
1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
3 2000 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #if 0
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
28 #else
29 #define MASK_CHAR ((int)(unsigned char)-1)
30 #endif
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
41 /* for isdigit() */
42 #include <ctype.h>
44 #include "as.h"
45 #include "subsegs.h"
46 #include "sb.h"
47 #include "macro.h"
48 #include "obstack.h"
49 #include "listing.h"
50 #include "ecoff.h"
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
54 #endif
56 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
58 * on it
60 #ifndef NOP_OPCODE
61 #define NOP_OPCODE 0x00
62 #endif
64 char *input_line_pointer; /*->next char of source file to parse. */
66 #if BITS_PER_CHAR != 8
67 /* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
69 die horribly;
70 #endif
72 #ifndef LEX_AT
73 /* The m88k unfortunately uses @ as a label beginner. */
74 #define LEX_AT 0
75 #endif
77 #ifndef LEX_BR
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
79 #define LEX_BR 0
80 #endif
82 #ifndef LEX_PCT
83 /* The Delta 68k assembler permits % inside label names. */
84 #define LEX_PCT 0
85 #endif
87 #ifndef LEX_QM
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
89 #define LEX_QM 0
90 #endif
92 #ifndef LEX_HASH
93 #define LEX_HASH 0
94 #endif
96 #ifndef LEX_DOLLAR
97 /* The a29k assembler does not permits labels to start with $. */
98 #define LEX_DOLLAR 3
99 #endif
101 #ifndef LEX_TILDE
102 /* The Delta 68k assembler permits ~ at start of label names. */
103 #define LEX_TILDE 0
104 #endif
106 /* used by is_... macros. our ctype[] */
107 char lex_type[256] =
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
111 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
112 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
113 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
115 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
129 * In: a character.
130 * Out: 1 if this character ends a line.
132 #define Z_ (0)
133 char is_end_of_line[256] =
135 #ifdef CR_EOL
136 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_, /* @abcdefghijklmno */
137 #else
138 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_, /* @abcdefghijklmno */
139 #endif
140 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
141 #ifdef TC_HPPA
142 Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* _!"#$%&'()*+,-./ */
143 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
144 #else
145 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
146 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
147 #endif
148 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
149 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
150 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
151 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
152 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
153 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
154 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
155 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
156 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
158 #undef Z_
160 /* Functions private to this file. */
162 static char *buffer; /* 1st char of each buffer of lines is here. */
163 static char *buffer_limit; /*->1 + last char in buffer. */
165 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
166 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
167 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
169 static char *old_buffer; /* JF a hack */
170 static char *old_input;
171 static char *old_limit;
173 /* Variables for handling include file directory table. */
175 char **include_dirs; /* Table of pointers to directories to
176 search for .include's */
177 int include_dir_count; /* How many are in the table */
178 int include_dir_maxlen = 1;/* Length of longest in table */
180 #ifndef WORKING_DOT_WORD
181 struct broken_word *broken_words;
182 int new_broken_words;
183 #endif
185 /* The current offset into the absolute section. We don't try to
186 build frags in the absolute section, since no data can be stored
187 there. We just keep track of the current offset. */
188 addressT abs_section_offset;
190 /* If this line had an MRI style label, it is stored in this variable.
191 This is used by some of the MRI pseudo-ops. */
192 symbolS *line_label;
194 /* This global variable is used to support MRI common sections. We
195 translate such sections into a common symbol. This variable is
196 non-NULL when we are in an MRI common section. */
197 symbolS *mri_common_symbol;
199 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
200 need to align to an even byte boundary unless the next pseudo-op is
201 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
202 may be needed. */
203 static int mri_pending_align;
205 #ifndef NO_LISTING
206 #ifdef OBJ_ELF
207 /* This variable is set to be non-zero if the next string we see might
208 be the name of the source file in DWARF debugging information. See
209 the comment in emit_expr for the format we look for. */
210 static int dwarf_file_string;
211 #endif
212 #endif
214 static void cons_worker PARAMS ((int, int));
215 static int scrub_from_string PARAMS ((char *, int));
216 static void do_align PARAMS ((int, char *, int, int));
217 static void s_align PARAMS ((int, int));
218 static void s_lcomm_internal PARAMS ((int, int));
219 static int hex_float PARAMS ((int, char *));
220 static inline int sizeof_sleb128 PARAMS ((offsetT));
221 static inline int sizeof_uleb128 PARAMS ((valueT));
222 static inline int output_sleb128 PARAMS ((char *, offsetT));
223 static inline int output_uleb128 PARAMS ((char *, valueT));
224 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
225 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
226 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
227 static void do_org PARAMS ((segT, expressionS *, int));
228 char *demand_copy_string PARAMS ((int *lenP));
229 static segT get_segmented_expression PARAMS ((expressionS *expP));
230 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
231 static void pobegin PARAMS ((void));
232 static int get_line_sb PARAMS ((sb *));
233 static void generate_file_debug PARAMS ((void));
236 void
237 read_begin ()
239 const char *p;
241 pobegin ();
242 obj_read_begin_hook ();
244 /* Something close -- but not too close -- to a multiple of 1024.
245 The debugging malloc I'm using has 24 bytes of overhead. */
246 obstack_begin (&notes, chunksize);
247 obstack_begin (&cond_obstack, chunksize);
249 /* Use machine dependent syntax */
250 for (p = line_separator_chars; *p; p++)
251 is_end_of_line[(unsigned char) *p] = 1;
252 /* Use more. FIXME-SOMEDAY. */
254 if (flag_mri)
255 lex_type['?'] = 3;
258 /* set up pseudo-op tables */
260 static struct hash_control *po_hash;
262 static const pseudo_typeS potable[] =
264 {"abort", s_abort, 0},
265 {"align", s_align_ptwo, 0},
266 {"ascii", stringer, 0},
267 {"asciz", stringer, 1},
268 {"balign", s_align_bytes, 0},
269 {"balignw", s_align_bytes, -2},
270 {"balignl", s_align_bytes, -4},
271 /* block */
272 {"byte", cons, 1},
273 {"comm", s_comm, 0},
274 {"common", s_mri_common, 0},
275 {"common.s", s_mri_common, 1},
276 {"data", s_data, 0},
277 {"dc", cons, 2},
278 {"dc.b", cons, 1},
279 {"dc.d", float_cons, 'd'},
280 {"dc.l", cons, 4},
281 {"dc.s", float_cons, 'f'},
282 {"dc.w", cons, 2},
283 {"dc.x", float_cons, 'x'},
284 {"dcb", s_space, 2},
285 {"dcb.b", s_space, 1},
286 {"dcb.d", s_float_space, 'd'},
287 {"dcb.l", s_space, 4},
288 {"dcb.s", s_float_space, 'f'},
289 {"dcb.w", s_space, 2},
290 {"dcb.x", s_float_space, 'x'},
291 {"ds", s_space, 2},
292 {"ds.b", s_space, 1},
293 {"ds.d", s_space, 8},
294 {"ds.l", s_space, 4},
295 {"ds.p", s_space, 12},
296 {"ds.s", s_space, 4},
297 {"ds.w", s_space, 2},
298 {"ds.x", s_space, 12},
299 {"debug", s_ignore, 0},
300 #ifdef S_SET_DESC
301 {"desc", s_desc, 0},
302 #endif
303 /* dim */
304 {"double", float_cons, 'd'},
305 /* dsect */
306 {"eject", listing_eject, 0}, /* Formfeed listing */
307 {"else", s_else, 0},
308 {"elsec", s_else, 0},
309 {"elseif", s_elseif, (int) O_ne},
310 {"end", s_end, 0},
311 {"endc", s_endif, 0},
312 {"endfunc", s_func, 1},
313 {"endif", s_endif, 0},
314 /* endef */
315 {"equ", s_set, 0},
316 {"equiv", s_set, 1},
317 {"err", s_err, 0},
318 {"exitm", s_mexit, 0},
319 /* extend */
320 {"extern", s_ignore, 0}, /* We treat all undef as ext */
321 {"appfile", s_app_file, 1},
322 {"appline", s_app_line, 0},
323 {"fail", s_fail, 0},
324 {"file", s_app_file, 0},
325 {"fill", s_fill, 0},
326 {"float", float_cons, 'f'},
327 {"format", s_ignore, 0},
328 {"func", s_func, 0},
329 {"global", s_globl, 0},
330 {"globl", s_globl, 0},
331 {"hword", cons, 2},
332 {"if", s_if, (int) O_ne},
333 {"ifc", s_ifc, 0},
334 {"ifdef", s_ifdef, 0},
335 {"ifeq", s_if, (int) O_eq},
336 {"ifeqs", s_ifeqs, 0},
337 {"ifge", s_if, (int) O_ge},
338 {"ifgt", s_if, (int) O_gt},
339 {"ifle", s_if, (int) O_le},
340 {"iflt", s_if, (int) O_lt},
341 {"ifnc", s_ifc, 1},
342 {"ifndef", s_ifdef, 1},
343 {"ifne", s_if, (int) O_ne},
344 {"ifnes", s_ifeqs, 1},
345 {"ifnotdef", s_ifdef, 1},
346 {"include", s_include, 0},
347 {"int", cons, 4},
348 {"irp", s_irp, 0},
349 {"irep", s_irp, 0},
350 {"irpc", s_irp, 1},
351 {"irepc", s_irp, 1},
352 {"lcomm", s_lcomm, 0},
353 {"lflags", listing_flags, 0}, /* Listing flags */
354 {"linkonce", s_linkonce, 0},
355 {"list", listing_list, 1}, /* Turn listing on */
356 {"llen", listing_psize, 1},
357 {"long", cons, 4},
358 {"lsym", s_lsym, 0},
359 {"macro", s_macro, 0},
360 {"mexit", s_mexit, 0},
361 {"mri", s_mri, 0},
362 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
363 {"name", s_ignore, 0},
364 {"noformat", s_ignore, 0},
365 {"nolist", listing_list, 0}, /* Turn listing off */
366 {"nopage", listing_nopage, 0},
367 {"octa", cons, 16},
368 {"offset", s_struct, 0},
369 {"org", s_org, 0},
370 {"p2align", s_align_ptwo, 0},
371 {"p2alignw", s_align_ptwo, -2},
372 {"p2alignl", s_align_ptwo, -4},
373 {"page", listing_eject, 0},
374 {"plen", listing_psize, 0},
375 {"print", s_print, 0},
376 {"psize", listing_psize, 0}, /* set paper size */
377 {"purgem", s_purgem, 0},
378 {"quad", cons, 8},
379 {"rep", s_rept, 0},
380 {"rept", s_rept, 0},
381 {"rva", s_rva, 4},
382 {"sbttl", listing_title, 1}, /* Subtitle of listing */
383 /* scl */
384 /* sect */
385 {"set", s_set, 0},
386 {"short", cons, 2},
387 {"single", float_cons, 'f'},
388 /* size */
389 {"space", s_space, 0},
390 {"skip", s_space, 0},
391 {"sleb128", s_leb128, 1},
392 {"spc", s_ignore, 0},
393 {"stabd", s_stab, 'd'},
394 {"stabn", s_stab, 'n'},
395 {"stabs", s_stab, 's'},
396 {"string", stringer, 1},
397 {"struct", s_struct, 0},
398 /* tag */
399 {"text", s_text, 0},
401 /* This is for gcc to use. It's only just been added (2/94), so gcc
402 won't be able to use it for a while -- probably a year or more.
403 But once this has been released, check with gcc maintainers
404 before deleting it or even changing the spelling. */
405 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
406 /* If we're folding case -- done for some targets, not necessarily
407 all -- the above string in an input file will be converted to
408 this one. Match it either way... */
409 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
411 {"title", listing_title, 0}, /* Listing title */
412 {"ttl", listing_title, 0},
413 /* type */
414 {"uleb128", s_leb128, 0},
415 /* use */
416 /* val */
417 {"xcom", s_comm, 0},
418 {"xdef", s_globl, 0},
419 {"xref", s_ignore, 0},
420 {"xstabs", s_xstab, 's'},
421 {"word", cons, 2},
422 {"zero", s_space, 0},
423 {NULL, NULL, 0} /* end sentinel */
426 static int pop_override_ok = 0;
427 static const char *pop_table_name;
429 void
430 pop_insert (table)
431 const pseudo_typeS *table;
433 const char *errtxt;
434 const pseudo_typeS *pop;
435 for (pop = table; pop->poc_name; pop++)
437 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
438 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
439 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
440 errtxt);
444 #ifndef md_pop_insert
445 #define md_pop_insert() pop_insert(md_pseudo_table)
446 #endif
448 #ifndef obj_pop_insert
449 #define obj_pop_insert() pop_insert(obj_pseudo_table)
450 #endif
452 static void
453 pobegin ()
455 po_hash = hash_new ();
457 /* Do the target-specific pseudo ops. */
458 pop_table_name = "md";
459 md_pop_insert ();
461 /* Now object specific. Skip any that were in the target table. */
462 pop_table_name = "obj";
463 pop_override_ok = 1;
464 obj_pop_insert ();
466 /* Now portable ones. Skip any that we've seen already. */
467 pop_table_name = "standard";
468 pop_insert (potable);
471 #define HANDLE_CONDITIONAL_ASSEMBLY() \
472 if (ignore_input ()) \
474 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
475 if (input_line_pointer == buffer_limit) \
476 break; \
477 continue; \
481 /* This function is used when scrubbing the characters between #APP
482 and #NO_APP. */
484 static char *scrub_string;
485 static char *scrub_string_end;
487 static int
488 scrub_from_string (buf, buflen)
489 char *buf;
490 int buflen;
492 int copy;
494 copy = scrub_string_end - scrub_string;
495 if (copy > buflen)
496 copy = buflen;
497 memcpy (buf, scrub_string, copy);
498 scrub_string += copy;
499 return copy;
502 /* read_a_source_file()
504 * We read the file, putting things into a web that
505 * represents what we have been reading.
507 void
508 read_a_source_file (name)
509 char *name;
511 register char c;
512 register char *s; /* string of symbol, '\0' appended */
513 register int temp;
514 pseudo_typeS *pop;
516 buffer = input_scrub_new_file (name);
518 listing_file (name);
519 listing_newline (NULL);
520 register_dependency (name);
522 /* Generate debugging information before we've read anything in to denote
523 this file as the "main" source file and not a subordinate one
524 (e.g. N_SO vs N_SOL in stabs). */
525 generate_file_debug ();
527 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
528 { /* We have another line to parse. */
529 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
530 contin: /* JF this goto is my fault I admit it.
531 Someone brave please re-write the whole
532 input section here? Pleeze??? */
533 while (input_line_pointer < buffer_limit)
535 /* We have more of this buffer to parse. */
538 * We now have input_line_pointer->1st char of next line.
539 * If input_line_pointer [-1] == '\n' then we just
540 * scanned another line: so bump line counters.
542 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
544 #ifdef md_start_line_hook
545 md_start_line_hook ();
546 #endif
548 if (input_line_pointer[-1] == '\n')
549 bump_line_counters ();
551 line_label = NULL;
553 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
555 /* Text at the start of a line must be a label, we
556 run down and stick a colon in. */
557 if (is_name_beginner (*input_line_pointer))
559 char *line_start = input_line_pointer;
560 char c;
561 int mri_line_macro;
563 LISTING_NEWLINE ();
564 HANDLE_CONDITIONAL_ASSEMBLY ();
566 c = get_symbol_end ();
568 /* In MRI mode, the EQU and MACRO pseudoops must
569 be handled specially. */
570 mri_line_macro = 0;
571 if (flag_m68k_mri)
573 char *rest = input_line_pointer + 1;
575 if (*rest == ':')
576 ++rest;
577 if (*rest == ' ' || *rest == '\t')
578 ++rest;
579 if ((strncasecmp (rest, "EQU", 3) == 0
580 || strncasecmp (rest, "SET", 3) == 0)
581 && (rest[3] == ' ' || rest[3] == '\t'))
583 input_line_pointer = rest + 3;
584 equals (line_start,
585 strncasecmp (rest, "SET", 3) == 0);
586 continue;
588 if (strncasecmp (rest, "MACRO", 5) == 0
589 && (rest[5] == ' '
590 || rest[5] == '\t'
591 || is_end_of_line[(unsigned char) rest[5]]))
592 mri_line_macro = 1;
595 /* In MRI mode, we need to handle the MACRO
596 pseudo-op specially: we don't want to put the
597 symbol in the symbol table. */
598 if (! mri_line_macro
599 #ifdef TC_START_LABEL_WITHOUT_COLON
600 && TC_START_LABEL_WITHOUT_COLON(c,
601 input_line_pointer)
602 #endif
604 line_label = colon (line_start);
605 else
606 line_label = symbol_create (line_start,
607 absolute_section,
608 (valueT) 0,
609 &zero_address_frag);
611 *input_line_pointer = c;
612 if (c == ':')
613 input_line_pointer++;
619 * We are at the begining of a line, or similar place.
620 * We expect a well-formed assembler statement.
621 * A "symbol-name:" is a statement.
623 * Depending on what compiler is used, the order of these tests
624 * may vary to catch most common case 1st.
625 * Each test is independent of all other tests at the (top) level.
626 * PLEASE make a compiler that doesn't use this assembler.
627 * It is crufty to waste a compiler's time encoding things for this
628 * assembler, which then wastes more time decoding it.
629 * (And communicating via (linear) files is silly!
630 * If you must pass stuff, please pass a tree!)
632 if ((c = *input_line_pointer++) == '\t'
633 || c == ' '
634 || c == '\f'
635 || c == 0)
637 c = *input_line_pointer++;
639 know (c != ' '); /* No further leading whitespace. */
641 #ifndef NO_LISTING
642 /* If listing is on, and we are expanding a macro, then give
643 the listing code the contents of the expanded line. */
644 if (listing)
646 if ((listing & LISTING_MACEXP) && macro_nest > 0)
648 char *copy;
649 int len;
651 /* Find the end of the current expanded macro line. */
652 for (s = input_line_pointer-1; *s ; ++s)
653 if (is_end_of_line[(unsigned char) *s])
654 break;
656 /* Copy it for safe keeping. Also give an indication of
657 how much macro nesting is involved at this point. */
658 len = s - (input_line_pointer-1);
659 copy = (char *) xmalloc (len + macro_nest + 2);
660 memset (copy, '>', macro_nest);
661 copy[macro_nest] = ' ';
662 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
663 copy[macro_nest+1+len] = '\0';
665 /* Install the line with the listing facility. */
666 listing_newline (copy);
668 else
669 listing_newline (NULL);
671 #endif
674 * C is the 1st significant character.
675 * Input_line_pointer points after that character.
677 if (is_name_beginner (c))
679 /* want user-defined label or pseudo/opcode */
680 HANDLE_CONDITIONAL_ASSEMBLY ();
682 s = --input_line_pointer;
683 c = get_symbol_end (); /* name's delimiter */
685 * C is character after symbol.
686 * That character's place in the input line is now '\0'.
687 * S points to the beginning of the symbol.
688 * [In case of pseudo-op, s->'.'.]
689 * Input_line_pointer->'\0' where c was.
691 if (TC_START_LABEL(c, input_line_pointer))
693 if (flag_m68k_mri)
695 char *rest = input_line_pointer + 1;
697 /* In MRI mode, \tsym: set 0 is permitted. */
699 if (*rest == ':')
700 ++rest;
701 if (*rest == ' ' || *rest == '\t')
702 ++rest;
703 if ((strncasecmp (rest, "EQU", 3) == 0
704 || strncasecmp (rest, "SET", 3) == 0)
705 && (rest[3] == ' ' || rest[3] == '\t'))
707 input_line_pointer = rest + 3;
708 equals (s, 1);
709 continue;
713 line_label = colon (s); /* user-defined label */
714 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
715 /* Input_line_pointer->after ':'. */
716 SKIP_WHITESPACE ();
720 else if (c == '='
721 || ((c == ' ' || c == '\t')
722 && input_line_pointer[1] == '='
723 #ifdef TC_EQUAL_IN_INSN
724 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
725 #endif
728 equals (s, 1);
729 demand_empty_rest_of_line ();
731 else
732 { /* expect pseudo-op or machine instruction */
733 pop = NULL;
735 #define IGNORE_OPCODE_CASE
736 #ifdef IGNORE_OPCODE_CASE
738 char *s2 = s;
739 while (*s2)
741 if (isupper ((unsigned char) *s2))
742 *s2 = tolower (*s2);
743 s2++;
746 #endif
748 if (NO_PSEUDO_DOT || flag_m68k_mri)
750 /* The MRI assembler and the m88k use pseudo-ops
751 without a period. */
752 pop = (pseudo_typeS *) hash_find (po_hash, s);
753 if (pop != NULL && pop->poc_handler == NULL)
754 pop = NULL;
757 if (pop != NULL
758 || (! flag_m68k_mri && *s == '.'))
761 * PSEUDO - OP.
763 * WARNING: c has next char, which may be end-of-line.
764 * We lookup the pseudo-op table with s+1 because we
765 * already know that the pseudo-op begins with a '.'.
768 if (pop == NULL)
769 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
771 /* In MRI mode, we may need to insert an
772 automatic alignment directive. What a hack
773 this is. */
774 if (mri_pending_align
775 && (pop == NULL
776 || ! ((pop->poc_handler == cons
777 && pop->poc_val == 1)
778 || (pop->poc_handler == s_space
779 && pop->poc_val == 1)
780 #ifdef tc_conditional_pseudoop
781 || tc_conditional_pseudoop (pop)
782 #endif
783 || pop->poc_handler == s_if
784 || pop->poc_handler == s_ifdef
785 || pop->poc_handler == s_ifc
786 || pop->poc_handler == s_ifeqs
787 || pop->poc_handler == s_else
788 || pop->poc_handler == s_endif
789 || pop->poc_handler == s_globl
790 || pop->poc_handler == s_ignore)))
792 do_align (1, (char *) NULL, 0, 0);
793 mri_pending_align = 0;
794 if (line_label != NULL)
796 symbol_set_frag (line_label, frag_now);
797 S_SET_VALUE (line_label, frag_now_fix ());
801 /* Print the error msg now, while we still can */
802 if (pop == NULL)
804 as_bad (_("Unknown pseudo-op: `%s'"), s);
805 *input_line_pointer = c;
806 s_ignore (0);
807 continue;
810 /* Put it back for error messages etc. */
811 *input_line_pointer = c;
812 /* The following skip of whitespace is compulsory.
813 A well shaped space is sometimes all that separates
814 keyword from operands. */
815 if (c == ' ' || c == '\t')
816 input_line_pointer++;
818 * Input_line is restored.
819 * Input_line_pointer->1st non-blank char
820 * after pseudo-operation.
822 (*pop->poc_handler) (pop->poc_val);
824 /* If that was .end, just get out now. */
825 if (pop->poc_handler == s_end)
826 goto quit;
828 else
830 int inquote = 0;
831 #ifdef QUOTES_IN_INSN
832 int inescape = 0;
833 #endif
835 /* WARNING: c has char, which may be end-of-line. */
836 /* Also: input_line_pointer->`\0` where c was. */
837 *input_line_pointer = c;
838 while (!is_end_of_line[(unsigned char) *input_line_pointer]
839 || inquote
840 #ifdef TC_EOL_IN_INSN
841 || TC_EOL_IN_INSN (input_line_pointer)
842 #endif
845 if (flag_m68k_mri && *input_line_pointer == '\'')
846 inquote = ! inquote;
847 #ifdef QUOTES_IN_INSN
848 if (inescape)
849 inescape = 0;
850 else if (*input_line_pointer == '"')
851 inquote = ! inquote;
852 else if (*input_line_pointer == '\\')
853 inescape = 1;
854 #endif
855 input_line_pointer++;
858 c = *input_line_pointer;
859 *input_line_pointer = '\0';
861 generate_lineno_debug ();
863 if (macro_defined)
865 sb out;
866 const char *err;
868 if (check_macro (s, &out, '\0', &err))
870 if (err != NULL)
871 as_bad ("%s", err);
872 *input_line_pointer++ = c;
873 input_scrub_include_sb (&out,
874 input_line_pointer);
875 sb_kill (&out);
876 buffer_limit =
877 input_scrub_next_buffer (&input_line_pointer);
878 continue;
882 if (mri_pending_align)
884 do_align (1, (char *) NULL, 0, 0);
885 mri_pending_align = 0;
886 if (line_label != NULL)
888 symbol_set_frag (line_label, frag_now);
889 S_SET_VALUE (line_label, frag_now_fix ());
893 md_assemble (s); /* Assemble 1 instruction. */
895 *input_line_pointer++ = c;
897 /* We resume loop AFTER the end-of-line from
898 this instruction. */
899 } /* if (*s=='.') */
900 } /* if c==':' */
901 continue;
902 } /* if (is_name_beginner(c) */
905 /* Empty statement? */
906 if (is_end_of_line[(unsigned char) c])
907 continue;
909 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
910 && isdigit ((unsigned char) c))
912 /* local label ("4:") */
913 char *backup = input_line_pointer;
915 HANDLE_CONDITIONAL_ASSEMBLY ();
917 temp = c - '0';
919 while (isdigit ((unsigned char) *input_line_pointer))
921 temp = (temp * 10) + *input_line_pointer - '0';
922 ++input_line_pointer;
923 } /* read the whole number */
925 if (LOCAL_LABELS_DOLLAR
926 && *input_line_pointer == '$'
927 && *(input_line_pointer + 1) == ':')
929 input_line_pointer += 2;
931 if (dollar_label_defined (temp))
933 as_fatal (_("label \"%d$\" redefined"), temp);
936 define_dollar_label (temp);
937 colon (dollar_label_name (temp, 0));
938 continue;
941 if (LOCAL_LABELS_FB
942 && *input_line_pointer++ == ':')
944 fb_label_instance_inc (temp);
945 colon (fb_label_name (temp, 0));
946 continue;
949 input_line_pointer = backup;
950 } /* local label ("4:") */
952 if (c && strchr (line_comment_chars, c))
953 { /* Its a comment. Better say APP or NO_APP */
954 char *ends;
955 char *new_buf;
956 char *new_tmp;
957 unsigned int new_length;
958 char *tmp_buf = 0;
960 bump_line_counters ();
961 s = input_line_pointer;
962 if (strncmp (s, "APP\n", 4))
963 continue; /* We ignore it */
964 s += 4;
966 ends = strstr (s, "#NO_APP\n");
968 if (!ends)
970 unsigned int tmp_len;
971 unsigned int num;
973 /* The end of the #APP wasn't in this buffer. We
974 keep reading in buffers until we find the #NO_APP
975 that goes with this #APP There is one. The specs
976 guarentee it. . . */
977 tmp_len = buffer_limit - s;
978 tmp_buf = xmalloc (tmp_len + 1);
979 memcpy (tmp_buf, s, tmp_len);
982 new_tmp = input_scrub_next_buffer (&buffer);
983 if (!new_tmp)
984 break;
985 else
986 buffer_limit = new_tmp;
987 input_line_pointer = buffer;
988 ends = strstr (buffer, "#NO_APP\n");
989 if (ends)
990 num = ends - buffer;
991 else
992 num = buffer_limit - buffer;
994 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
995 memcpy (tmp_buf + tmp_len, buffer, num);
996 tmp_len += num;
998 while (!ends);
1000 input_line_pointer = ends ? ends + 8 : NULL;
1002 s = tmp_buf;
1003 ends = s + tmp_len;
1006 else
1008 input_line_pointer = ends + 8;
1011 scrub_string = s;
1012 scrub_string_end = ends;
1014 new_length = ends - s;
1015 new_buf = (char *) xmalloc (new_length);
1016 new_tmp = new_buf;
1017 for (;;)
1019 int space;
1020 int size;
1022 space = (new_buf + new_length) - new_tmp;
1023 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1025 if (size < space)
1027 new_tmp += size;
1028 break;
1031 new_buf = xrealloc (new_buf, new_length + 100);
1032 new_tmp = new_buf + new_length;
1033 new_length += 100;
1036 if (tmp_buf)
1037 free (tmp_buf);
1038 old_buffer = buffer;
1039 old_input = input_line_pointer;
1040 old_limit = buffer_limit;
1041 buffer = new_buf;
1042 input_line_pointer = new_buf;
1043 buffer_limit = new_tmp;
1044 continue;
1047 HANDLE_CONDITIONAL_ASSEMBLY ();
1049 #ifdef tc_unrecognized_line
1050 if (tc_unrecognized_line (c))
1051 continue;
1052 #endif
1054 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1055 input_line_pointer--; /* Report unknown char as ignored. */
1056 ignore_rest_of_line ();
1057 } /* while (input_line_pointer<buffer_limit) */
1059 #ifdef md_after_pass_hook
1060 md_after_pass_hook ();
1061 #endif
1063 if (old_buffer)
1065 free (buffer);
1066 bump_line_counters ();
1067 if (old_input != 0)
1069 buffer = old_buffer;
1070 input_line_pointer = old_input;
1071 buffer_limit = old_limit;
1072 old_buffer = 0;
1073 goto contin;
1076 } /* while (more buffers to scan) */
1078 quit:
1080 #ifdef md_cleanup
1081 md_cleanup();
1082 #endif
1083 input_scrub_close (); /* Close the input file */
1086 /* For most MRI pseudo-ops, the line actually ends at the first
1087 nonquoted space. This function looks for that point, stuffs a null
1088 in, and sets *STOPCP to the character that used to be there, and
1089 returns the location.
1091 Until I hear otherwise, I am going to assume that this is only true
1092 for the m68k MRI assembler. */
1094 char *
1095 mri_comment_field (stopcp)
1096 char *stopcp;
1098 #ifdef TC_M68K
1100 char *s;
1101 int inquote = 0;
1103 know (flag_m68k_mri);
1105 for (s = input_line_pointer;
1106 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1107 || inquote);
1108 s++)
1110 if (*s == '\'')
1111 inquote = ! inquote;
1113 *stopcp = *s;
1114 *s = '\0';
1115 return s;
1117 #else
1119 char *s;
1121 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1123 *stopcp = *s;
1124 *s = '\0';
1125 return s;
1127 #endif
1131 /* Skip to the end of an MRI comment field. */
1133 void
1134 mri_comment_end (stop, stopc)
1135 char *stop;
1136 int stopc;
1138 know (flag_mri);
1140 input_line_pointer = stop;
1141 *stop = stopc;
1142 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1143 ++input_line_pointer;
1146 void
1147 s_abort (ignore)
1148 int ignore ATTRIBUTE_UNUSED;
1150 as_fatal (_(".abort detected. Abandoning ship."));
1153 /* Guts of .align directive. N is the power of two to which to align.
1154 FILL may be NULL, or it may point to the bytes of the fill pattern.
1155 LEN is the length of whatever FILL points to, if anything. MAX is
1156 the maximum number of characters to skip when doing the alignment,
1157 or 0 if there is no maximum. */
1159 static void
1160 do_align (n, fill, len, max)
1161 int n;
1162 char *fill;
1163 int len;
1164 int max;
1166 char default_fill;
1168 #ifdef md_do_align
1169 md_do_align (n, fill, len, max, just_record_alignment);
1170 #endif
1172 if (fill == NULL)
1174 if (subseg_text_p (now_seg))
1175 default_fill = NOP_OPCODE;
1176 else
1177 default_fill = 0;
1178 fill = &default_fill;
1179 len = 1;
1182 /* Only make a frag if we HAVE to. . . */
1183 if (n != 0 && !need_pass_2)
1185 if (len <= 1)
1186 frag_align (n, *fill, max);
1187 else
1188 frag_align_pattern (n, fill, len, max);
1191 #ifdef md_do_align
1192 just_record_alignment:
1193 #endif
1195 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1198 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1199 (in bytes). A negative ARG is the negative of the length of the
1200 fill pattern. BYTES_P is non-zero if the alignment value should be
1201 interpreted as the byte boundary, rather than the power of 2. */
1203 static void
1204 s_align (arg, bytes_p)
1205 int arg;
1206 int bytes_p;
1208 register unsigned int align;
1209 char *stop = NULL;
1210 char stopc;
1211 offsetT fill = 0;
1212 int max;
1213 int fill_p;
1215 if (flag_mri)
1216 stop = mri_comment_field (&stopc);
1218 if (is_end_of_line[(unsigned char) *input_line_pointer])
1220 if (arg < 0)
1221 align = 0;
1222 else
1223 align = arg; /* Default value from pseudo-op table */
1225 else
1227 align = get_absolute_expression ();
1228 SKIP_WHITESPACE ();
1231 if (bytes_p)
1233 /* Convert to a power of 2. */
1234 if (align != 0)
1236 unsigned int i;
1238 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1240 if (align != 1)
1241 as_bad (_("Alignment not a power of 2"));
1242 align = i;
1246 if (align > 15)
1248 align = 15;
1249 as_bad (_("Alignment too large: %u assumed"), align);
1252 if (*input_line_pointer != ',')
1254 fill_p = 0;
1255 max = 0;
1257 else
1259 ++input_line_pointer;
1260 if (*input_line_pointer == ',')
1261 fill_p = 0;
1262 else
1264 fill = get_absolute_expression ();
1265 SKIP_WHITESPACE ();
1266 fill_p = 1;
1269 if (*input_line_pointer != ',')
1270 max = 0;
1271 else
1273 ++input_line_pointer;
1274 max = get_absolute_expression ();
1278 if (! fill_p)
1280 if (arg < 0)
1281 as_warn (_("expected fill pattern missing"));
1282 do_align (align, (char *) NULL, 0, max);
1284 else
1286 int fill_len;
1288 if (arg >= 0)
1289 fill_len = 1;
1290 else
1291 fill_len = - arg;
1292 if (fill_len <= 1)
1294 char fill_char;
1296 fill_char = fill;
1297 do_align (align, &fill_char, fill_len, max);
1299 else
1301 char ab[16];
1303 if ((size_t) fill_len > sizeof ab)
1304 abort ();
1305 md_number_to_chars (ab, fill, fill_len);
1306 do_align (align, ab, fill_len, max);
1310 demand_empty_rest_of_line ();
1312 if (flag_mri)
1313 mri_comment_end (stop, stopc);
1316 /* Handle the .align pseudo-op on machines where ".align 4" means
1317 align to a 4 byte boundary. */
1319 void
1320 s_align_bytes (arg)
1321 int arg;
1323 s_align (arg, 1);
1326 /* Handle the .align pseudo-op on machines where ".align 4" means align
1327 to a 2**4 boundary. */
1329 void
1330 s_align_ptwo (arg)
1331 int arg;
1333 s_align (arg, 0);
1336 void
1337 s_comm (ignore)
1338 int ignore ATTRIBUTE_UNUSED;
1340 register char *name;
1341 register char c;
1342 register char *p;
1343 offsetT temp;
1344 register symbolS *symbolP;
1345 char *stop = NULL;
1346 char stopc;
1348 if (flag_mri)
1349 stop = mri_comment_field (&stopc);
1351 name = input_line_pointer;
1352 c = get_symbol_end ();
1353 /* just after name is now '\0' */
1354 p = input_line_pointer;
1355 *p = c;
1356 SKIP_WHITESPACE ();
1357 if (*input_line_pointer != ',')
1359 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1360 ignore_rest_of_line ();
1361 if (flag_mri)
1362 mri_comment_end (stop, stopc);
1363 return;
1365 input_line_pointer++; /* skip ',' */
1366 if ((temp = get_absolute_expression ()) < 0)
1368 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1369 ignore_rest_of_line ();
1370 if (flag_mri)
1371 mri_comment_end (stop, stopc);
1372 return;
1374 *p = 0;
1375 symbolP = symbol_find_or_make (name);
1376 *p = c;
1377 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1379 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1380 S_GET_NAME (symbolP));
1381 ignore_rest_of_line ();
1382 if (flag_mri)
1383 mri_comment_end (stop, stopc);
1384 return;
1386 if (S_GET_VALUE (symbolP))
1388 if (S_GET_VALUE (symbolP) != (valueT) temp)
1389 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1390 S_GET_NAME (symbolP),
1391 (long) S_GET_VALUE (symbolP),
1392 (long) temp);
1394 else
1396 S_SET_VALUE (symbolP, (valueT) temp);
1397 S_SET_EXTERNAL (symbolP);
1399 #ifdef OBJ_VMS
1401 extern int flag_one;
1402 if ( (!temp) || !flag_one)
1403 S_GET_OTHER(symbolP) = const_flag;
1405 #endif /* not OBJ_VMS */
1406 know (symbolP->sy_frag == &zero_address_frag);
1408 demand_empty_rest_of_line ();
1410 if (flag_mri)
1411 mri_comment_end (stop, stopc);
1412 } /* s_comm() */
1414 /* The MRI COMMON pseudo-op. We handle this by creating a common
1415 symbol with the appropriate name. We make s_space do the right
1416 thing by increasing the size. */
1418 void
1419 s_mri_common (small)
1420 int small ATTRIBUTE_UNUSED;
1422 char *name;
1423 char c;
1424 char *alc = NULL;
1425 symbolS *sym;
1426 offsetT align;
1427 char *stop = NULL;
1428 char stopc;
1430 if (! flag_mri)
1432 s_comm (0);
1433 return;
1436 stop = mri_comment_field (&stopc);
1438 SKIP_WHITESPACE ();
1440 name = input_line_pointer;
1441 if (! isdigit ((unsigned char) *name))
1442 c = get_symbol_end ();
1443 else
1447 ++input_line_pointer;
1449 while (isdigit ((unsigned char) *input_line_pointer));
1450 c = *input_line_pointer;
1451 *input_line_pointer = '\0';
1453 if (line_label != NULL)
1455 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1456 + (input_line_pointer - name)
1457 + 1);
1458 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1459 name = alc;
1463 sym = symbol_find_or_make (name);
1464 *input_line_pointer = c;
1465 if (alc != NULL)
1466 free (alc);
1468 if (*input_line_pointer != ',')
1469 align = 0;
1470 else
1472 ++input_line_pointer;
1473 align = get_absolute_expression ();
1476 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1478 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1479 ignore_rest_of_line ();
1480 mri_comment_end (stop, stopc);
1481 return;
1484 S_SET_EXTERNAL (sym);
1485 mri_common_symbol = sym;
1487 #ifdef S_SET_ALIGN
1488 if (align != 0)
1489 S_SET_ALIGN (sym, align);
1490 #endif
1492 if (line_label != NULL)
1494 expressionS exp;
1495 exp.X_op = O_symbol;
1496 exp.X_add_symbol = sym;
1497 exp.X_add_number = 0;
1498 symbol_set_value_expression (line_label, &exp);
1499 symbol_set_frag (line_label, &zero_address_frag);
1500 S_SET_SEGMENT (line_label, expr_section);
1503 /* FIXME: We just ignore the small argument, which distinguishes
1504 COMMON and COMMON.S. I don't know what we can do about it. */
1506 /* Ignore the type and hptype. */
1507 if (*input_line_pointer == ',')
1508 input_line_pointer += 2;
1509 if (*input_line_pointer == ',')
1510 input_line_pointer += 2;
1512 demand_empty_rest_of_line ();
1514 mri_comment_end (stop, stopc);
1517 void
1518 s_data (ignore)
1519 int ignore ATTRIBUTE_UNUSED;
1521 segT section;
1522 register int temp;
1524 temp = get_absolute_expression ();
1525 if (flag_readonly_data_in_text)
1527 section = text_section;
1528 temp += 1000;
1530 else
1531 section = data_section;
1533 subseg_set (section, (subsegT) temp);
1535 #ifdef OBJ_VMS
1536 const_flag = 0;
1537 #endif
1538 demand_empty_rest_of_line ();
1541 /* Handle the .appfile pseudo-op. This is automatically generated by
1542 do_scrub_chars when a preprocessor # line comment is seen with a
1543 file name. This default definition may be overridden by the object
1544 or CPU specific pseudo-ops. This function is also the default
1545 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1546 .file. */
1548 void
1549 s_app_file (appfile)
1550 int appfile;
1552 register char *s;
1553 int length;
1555 /* Some assemblers tolerate immediately following '"' */
1556 if ((s = demand_copy_string (&length)) != 0)
1558 /* If this is a fake .appfile, a fake newline was inserted into
1559 the buffer. Passing -2 to new_logical_line tells it to
1560 account for it. */
1561 int may_omit
1562 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1564 /* In MRI mode, the preprocessor may have inserted an extraneous
1565 backquote. */
1566 if (flag_m68k_mri
1567 && *input_line_pointer == '\''
1568 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1569 ++input_line_pointer;
1571 demand_empty_rest_of_line ();
1572 if (! may_omit)
1574 #ifdef LISTING
1575 if (listing)
1576 listing_source_file (s);
1577 #endif
1578 register_dependency (s);
1579 #ifdef obj_app_file
1580 obj_app_file (s);
1581 #endif
1586 /* Handle the .appline pseudo-op. This is automatically generated by
1587 do_scrub_chars when a preprocessor # line comment is seen. This
1588 default definition may be overridden by the object or CPU specific
1589 pseudo-ops. */
1591 void
1592 s_app_line (ignore)
1593 int ignore ATTRIBUTE_UNUSED;
1595 int l;
1597 /* The given number is that of the next line. */
1598 l = get_absolute_expression () - 1;
1599 if (l < 0)
1600 /* Some of the back ends can't deal with non-positive line numbers.
1601 Besides, it's silly. */
1602 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1603 else
1605 new_logical_line ((char *) NULL, l);
1606 #ifdef LISTING
1607 if (listing)
1608 listing_source_line (l);
1609 #endif
1611 demand_empty_rest_of_line ();
1614 /* Handle the .end pseudo-op. Actually, the real work is done in
1615 read_a_source_file. */
1617 void
1618 s_end (ignore)
1619 int ignore ATTRIBUTE_UNUSED;
1621 if (flag_mri)
1623 /* The MRI assembler permits the start symbol to follow .end,
1624 but we don't support that. */
1625 SKIP_WHITESPACE ();
1626 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1627 && *input_line_pointer != '*'
1628 && *input_line_pointer != '!')
1629 as_warn (_("start address not supported"));
1633 /* Handle the .err pseudo-op. */
1635 void
1636 s_err (ignore)
1637 int ignore ATTRIBUTE_UNUSED;
1639 as_bad (_(".err encountered"));
1640 demand_empty_rest_of_line ();
1643 /* Handle the MRI fail pseudo-op. */
1645 void
1646 s_fail (ignore)
1647 int ignore ATTRIBUTE_UNUSED;
1649 offsetT temp;
1650 char *stop = NULL;
1651 char stopc;
1653 if (flag_mri)
1654 stop = mri_comment_field (&stopc);
1656 temp = get_absolute_expression ();
1657 if (temp >= 500)
1658 as_warn (_(".fail %ld encountered"), (long) temp);
1659 else
1660 as_bad (_(".fail %ld encountered"), (long) temp);
1662 demand_empty_rest_of_line ();
1664 if (flag_mri)
1665 mri_comment_end (stop, stopc);
1668 void
1669 s_fill (ignore)
1670 int ignore ATTRIBUTE_UNUSED;
1672 expressionS rep_exp;
1673 long size = 1;
1674 register long fill = 0;
1675 char *p;
1677 #ifdef md_flush_pending_output
1678 md_flush_pending_output ();
1679 #endif
1681 get_known_segmented_expression (&rep_exp);
1682 if (*input_line_pointer == ',')
1684 input_line_pointer++;
1685 size = get_absolute_expression ();
1686 if (*input_line_pointer == ',')
1688 input_line_pointer++;
1689 fill = get_absolute_expression ();
1693 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1694 #define BSD_FILL_SIZE_CROCK_8 (8)
1695 if (size > BSD_FILL_SIZE_CROCK_8)
1697 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1698 size = BSD_FILL_SIZE_CROCK_8;
1700 if (size < 0)
1702 as_warn (_("Size negative: .fill ignored."));
1703 size = 0;
1705 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1707 if (rep_exp.X_add_number < 0)
1708 as_warn (_("Repeat < 0, .fill ignored"));
1709 size = 0;
1712 if (size && !need_pass_2)
1714 if (rep_exp.X_op == O_constant)
1716 p = frag_var (rs_fill, (int) size, (int) size,
1717 (relax_substateT) 0, (symbolS *) 0,
1718 (offsetT) rep_exp.X_add_number,
1719 (char *) 0);
1721 else
1723 /* We don't have a constant repeat count, so we can't use
1724 rs_fill. We can get the same results out of rs_space,
1725 but its argument is in bytes, so we must multiply the
1726 repeat count by size. */
1728 symbolS *rep_sym;
1729 rep_sym = make_expr_symbol (&rep_exp);
1730 if (size != 1)
1732 expressionS size_exp;
1733 size_exp.X_op = O_constant;
1734 size_exp.X_add_number = size;
1736 rep_exp.X_op = O_multiply;
1737 rep_exp.X_add_symbol = rep_sym;
1738 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1739 rep_exp.X_add_number = 0;
1740 rep_sym = make_expr_symbol (&rep_exp);
1743 p = frag_var (rs_space, (int) size, (int) size,
1744 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1746 memset (p, 0, (unsigned int) size);
1747 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1748 * flavoured AS. The following bizzare behaviour is to be
1749 * compatible with above. I guess they tried to take up to 8
1750 * bytes from a 4-byte expression and they forgot to sign
1751 * extend. Un*x Sux. */
1752 #define BSD_FILL_SIZE_CROCK_4 (4)
1753 md_number_to_chars (p, (valueT) fill,
1754 (size > BSD_FILL_SIZE_CROCK_4
1755 ? BSD_FILL_SIZE_CROCK_4
1756 : (int) size));
1757 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1758 * but emits no error message because it seems a legal thing to do.
1759 * It is a degenerate case of .fill but could be emitted by a compiler.
1762 demand_empty_rest_of_line ();
1765 void
1766 s_globl (ignore)
1767 int ignore ATTRIBUTE_UNUSED;
1769 char *name;
1770 int c;
1771 symbolS *symbolP;
1772 char *stop = NULL;
1773 char stopc;
1775 if (flag_mri)
1776 stop = mri_comment_field (&stopc);
1780 name = input_line_pointer;
1781 c = get_symbol_end ();
1782 symbolP = symbol_find_or_make (name);
1783 S_SET_EXTERNAL (symbolP);
1785 *input_line_pointer = c;
1786 SKIP_WHITESPACE ();
1787 c = *input_line_pointer;
1788 if (c == ',')
1790 input_line_pointer++;
1791 SKIP_WHITESPACE ();
1792 if (*input_line_pointer == '\n')
1793 c = '\n';
1796 while (c == ',');
1798 demand_empty_rest_of_line ();
1800 if (flag_mri)
1801 mri_comment_end (stop, stopc);
1804 /* Handle the MRI IRP and IRPC pseudo-ops. */
1806 void
1807 s_irp (irpc)
1808 int irpc;
1810 char *file;
1811 unsigned int line;
1812 sb s;
1813 const char *err;
1814 sb out;
1816 as_where (&file, &line);
1818 sb_new (&s);
1819 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1820 sb_add_char (&s, *input_line_pointer++);
1822 sb_new (&out);
1824 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1825 if (err != NULL)
1826 as_bad_where (file, line, "%s", err);
1828 sb_kill (&s);
1830 input_scrub_include_sb (&out, input_line_pointer);
1831 sb_kill (&out);
1832 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1835 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1836 the section to only be linked once. However, this is not supported
1837 by most object file formats. This takes an optional argument,
1838 which is what to do about duplicates. */
1840 void
1841 s_linkonce (ignore)
1842 int ignore ATTRIBUTE_UNUSED;
1844 enum linkonce_type type;
1846 SKIP_WHITESPACE ();
1848 type = LINKONCE_DISCARD;
1850 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1852 char *s;
1853 char c;
1855 s = input_line_pointer;
1856 c = get_symbol_end ();
1857 if (strcasecmp (s, "discard") == 0)
1858 type = LINKONCE_DISCARD;
1859 else if (strcasecmp (s, "one_only") == 0)
1860 type = LINKONCE_ONE_ONLY;
1861 else if (strcasecmp (s, "same_size") == 0)
1862 type = LINKONCE_SAME_SIZE;
1863 else if (strcasecmp (s, "same_contents") == 0)
1864 type = LINKONCE_SAME_CONTENTS;
1865 else
1866 as_warn (_("unrecognized .linkonce type `%s'"), s);
1868 *input_line_pointer = c;
1871 #ifdef obj_handle_link_once
1872 obj_handle_link_once (type);
1873 #else /* ! defined (obj_handle_link_once) */
1874 #ifdef BFD_ASSEMBLER
1876 flagword flags;
1878 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1879 as_warn (_(".linkonce is not supported for this object file format"));
1881 flags = bfd_get_section_flags (stdoutput, now_seg);
1882 flags |= SEC_LINK_ONCE;
1883 switch (type)
1885 default:
1886 abort ();
1887 case LINKONCE_DISCARD:
1888 flags |= SEC_LINK_DUPLICATES_DISCARD;
1889 break;
1890 case LINKONCE_ONE_ONLY:
1891 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1892 break;
1893 case LINKONCE_SAME_SIZE:
1894 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1895 break;
1896 case LINKONCE_SAME_CONTENTS:
1897 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1898 break;
1900 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1901 as_bad (_("bfd_set_section_flags: %s"),
1902 bfd_errmsg (bfd_get_error ()));
1904 #else /* ! defined (BFD_ASSEMBLER) */
1905 as_warn (_(".linkonce is not supported for this object file format"));
1906 #endif /* ! defined (BFD_ASSEMBLER) */
1907 #endif /* ! defined (obj_handle_link_once) */
1909 demand_empty_rest_of_line ();
1912 static void
1913 s_lcomm_internal (needs_align, bytes_p)
1914 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1915 (alignment); 0 if it was an ".lcomm" (2 args only) */
1916 int needs_align;
1917 /* 1 if the alignment value should be interpreted as the byte boundary,
1918 rather than the power of 2. */
1919 int bytes_p;
1921 register char *name;
1922 register char c;
1923 register char *p;
1924 register int temp;
1925 register symbolS *symbolP;
1926 segT current_seg = now_seg;
1927 subsegT current_subseg = now_subseg;
1928 const int max_alignment = 15;
1929 int align = 0;
1930 segT bss_seg = bss_section;
1932 name = input_line_pointer;
1933 c = get_symbol_end ();
1934 p = input_line_pointer;
1935 *p = c;
1936 SKIP_WHITESPACE ();
1938 /* Accept an optional comma after the name. The comma used to be
1939 required, but Irix 5 cc does not generate it. */
1940 if (*input_line_pointer == ',')
1942 ++input_line_pointer;
1943 SKIP_WHITESPACE ();
1946 if (*input_line_pointer == '\n')
1948 as_bad (_("Missing size expression"));
1949 return;
1952 if ((temp = get_absolute_expression ()) < 0)
1954 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1955 ignore_rest_of_line ();
1956 return;
1959 #if defined (TC_MIPS) || defined (TC_ALPHA)
1960 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1961 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1963 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1964 if (temp <= bfd_get_gp_size (stdoutput))
1966 bss_seg = subseg_new (".sbss", 1);
1967 seg_info (bss_seg)->bss = 1;
1968 #ifdef BFD_ASSEMBLER
1969 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1970 as_warn (_("error setting flags for \".sbss\": %s"),
1971 bfd_errmsg (bfd_get_error ()));
1972 #endif
1975 #endif
1976 if (!needs_align)
1978 /* FIXME. This needs to be machine independent. */
1979 if (temp >= 8)
1980 align = 3;
1981 else if (temp >= 4)
1982 align = 2;
1983 else if (temp >= 2)
1984 align = 1;
1985 else
1986 align = 0;
1988 #ifdef OBJ_EVAX
1989 /* FIXME: This needs to be done in a more general fashion. */
1990 align = 3;
1991 #endif
1993 record_alignment(bss_seg, align);
1996 if (needs_align)
1998 align = 0;
1999 SKIP_WHITESPACE ();
2000 if (*input_line_pointer != ',')
2002 as_bad (_("Expected comma after size"));
2003 ignore_rest_of_line ();
2004 return;
2006 input_line_pointer++;
2007 SKIP_WHITESPACE ();
2008 if (*input_line_pointer == '\n')
2010 as_bad (_("Missing alignment"));
2011 return;
2013 align = get_absolute_expression ();
2014 if (bytes_p)
2016 /* Convert to a power of 2. */
2017 if (align != 0)
2019 unsigned int i;
2021 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2023 if (align != 1)
2024 as_bad (_("Alignment not a power of 2"));
2025 align = i;
2028 if (align > max_alignment)
2030 align = max_alignment;
2031 as_warn (_("Alignment too large: %d. assumed."), align);
2033 else if (align < 0)
2035 align = 0;
2036 as_warn (_("Alignment negative. 0 assumed."));
2038 record_alignment (bss_seg, align);
2039 } /* if needs align */
2040 else
2042 /* Assume some objects may require alignment on some systems. */
2043 #if defined (TC_ALPHA) && ! defined (VMS)
2044 if (temp > 1)
2046 align = ffs (temp) - 1;
2047 if (temp % (1 << align))
2048 abort ();
2050 #endif
2053 *p = 0;
2054 symbolP = symbol_find_or_make (name);
2055 *p = c;
2057 if (
2058 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2059 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2060 #ifdef BFD_ASSEMBLER
2061 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2062 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2063 #else
2064 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2065 #endif
2066 #endif
2067 (S_GET_SEGMENT (symbolP) == bss_seg
2068 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2070 char *pfrag;
2072 subseg_set (bss_seg, 1);
2074 if (align)
2075 frag_align (align, 0, 0);
2076 /* detach from old frag */
2077 if (S_GET_SEGMENT (symbolP) == bss_seg)
2078 symbol_get_frag (symbolP)->fr_symbol = NULL;
2080 symbol_set_frag (symbolP, frag_now);
2081 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2082 (offsetT) temp, (char *) 0);
2083 *pfrag = 0;
2085 S_SET_SEGMENT (symbolP, bss_seg);
2087 #ifdef OBJ_COFF
2088 /* The symbol may already have been created with a preceding
2089 ".globl" directive -- be careful not to step on storage class
2090 in that case. Otherwise, set it to static. */
2091 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2093 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2095 #endif /* OBJ_COFF */
2097 #ifdef S_SET_SIZE
2098 S_SET_SIZE (symbolP, temp);
2099 #endif
2101 else
2102 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2103 S_GET_NAME (symbolP));
2105 subseg_set (current_seg, current_subseg);
2107 demand_empty_rest_of_line ();
2108 } /* s_lcomm_internal() */
2110 void
2111 s_lcomm (needs_align)
2112 int needs_align;
2114 s_lcomm_internal (needs_align, 0);
2117 void s_lcomm_bytes (needs_align)
2118 int needs_align;
2120 s_lcomm_internal (needs_align, 1);
2123 void
2124 s_lsym (ignore)
2125 int ignore ATTRIBUTE_UNUSED;
2127 register char *name;
2128 register char c;
2129 register char *p;
2130 expressionS exp;
2131 register symbolS *symbolP;
2133 /* we permit ANY defined expression: BSD4.2 demands constants */
2134 name = input_line_pointer;
2135 c = get_symbol_end ();
2136 p = input_line_pointer;
2137 *p = c;
2138 SKIP_WHITESPACE ();
2139 if (*input_line_pointer != ',')
2141 *p = 0;
2142 as_bad (_("Expected comma after name \"%s\""), name);
2143 *p = c;
2144 ignore_rest_of_line ();
2145 return;
2147 input_line_pointer++;
2148 expression (&exp);
2149 if (exp.X_op != O_constant
2150 && exp.X_op != O_register)
2152 as_bad (_("bad expression"));
2153 ignore_rest_of_line ();
2154 return;
2156 *p = 0;
2157 symbolP = symbol_find_or_make (name);
2159 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2160 symbolP->sy_desc == 0) out of this test because coff doesn't have
2161 those fields, and I can't see when they'd ever be tripped. I
2162 don't think I understand why they were here so I may have
2163 introduced a bug. As recently as 1.37 didn't have this test
2164 anyway. xoxorich. */
2166 if (S_GET_SEGMENT (symbolP) == undefined_section
2167 && S_GET_VALUE (symbolP) == 0)
2169 /* The name might be an undefined .global symbol; be sure to
2170 keep the "external" bit. */
2171 S_SET_SEGMENT (symbolP,
2172 (exp.X_op == O_constant
2173 ? absolute_section
2174 : reg_section));
2175 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2177 else
2179 as_bad (_("Symbol %s already defined"), name);
2181 *p = c;
2182 demand_empty_rest_of_line ();
2183 } /* s_lsym() */
2185 /* Read a line into an sb. */
2187 static int
2188 get_line_sb (line)
2189 sb *line;
2191 char quote1, quote2, inquote;
2193 if (input_line_pointer[-1] == '\n')
2194 bump_line_counters ();
2196 if (input_line_pointer >= buffer_limit)
2198 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2199 if (buffer_limit == 0)
2200 return 0;
2203 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2204 code needs to be changed. */
2205 if (! flag_m68k_mri)
2206 quote1 = '"';
2207 else
2208 quote1 = '\0';
2210 quote2 = '\0';
2211 if (flag_m68k_mri)
2212 quote2 = '\'';
2213 #ifdef LEX_IS_STRINGQUOTE
2214 quote2 = '\'';
2215 #endif
2217 inquote = '\0';
2218 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2219 || (inquote != '\0' && *input_line_pointer != '\n'))
2221 if (inquote == *input_line_pointer)
2222 inquote = '\0';
2223 else if (inquote == '\0')
2225 if (*input_line_pointer == quote1)
2226 inquote = quote1;
2227 else if (*input_line_pointer == quote2)
2228 inquote = quote2;
2230 sb_add_char (line, *input_line_pointer++);
2232 while (input_line_pointer < buffer_limit
2233 && is_end_of_line[(unsigned char) *input_line_pointer])
2235 if (input_line_pointer[-1] == '\n')
2236 bump_line_counters ();
2237 ++input_line_pointer;
2239 return 1;
2242 /* Define a macro. This is an interface to macro.c, which is shared
2243 between gas and gasp. */
2245 void
2246 s_macro (ignore)
2247 int ignore ATTRIBUTE_UNUSED;
2249 char *file;
2250 unsigned int line;
2251 sb s;
2252 sb label;
2253 const char *err;
2254 const char *name;
2256 as_where (&file, &line);
2258 sb_new (&s);
2259 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2260 sb_add_char (&s, *input_line_pointer++);
2262 sb_new (&label);
2263 if (line_label != NULL)
2264 sb_add_string (&label, S_GET_NAME (line_label));
2266 err = define_macro (0, &s, &label, get_line_sb, &name);
2267 if (err != NULL)
2268 as_bad_where (file, line, "%s", err);
2269 else
2271 if (line_label != NULL)
2273 S_SET_SEGMENT (line_label, undefined_section);
2274 S_SET_VALUE (line_label, 0);
2275 symbol_set_frag (line_label, &zero_address_frag);
2278 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2279 && hash_find (po_hash, name) != NULL)
2280 || (! flag_m68k_mri
2281 && *name == '.'
2282 && hash_find (po_hash, name + 1) != NULL))
2283 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2284 name);
2287 sb_kill (&s);
2290 /* Handle the .mexit pseudo-op, which immediately exits a macro
2291 expansion. */
2293 void
2294 s_mexit (ignore)
2295 int ignore ATTRIBUTE_UNUSED;
2297 cond_exit_macro (macro_nest);
2298 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2301 /* Switch in and out of MRI mode. */
2303 void
2304 s_mri (ignore)
2305 int ignore ATTRIBUTE_UNUSED;
2307 int on, old_flag;
2309 on = get_absolute_expression ();
2310 old_flag = flag_mri;
2311 if (on != 0)
2313 flag_mri = 1;
2314 #ifdef TC_M68K
2315 flag_m68k_mri = 1;
2316 #endif
2317 macro_mri_mode (1);
2319 else
2321 flag_mri = 0;
2322 #ifdef TC_M68K
2323 flag_m68k_mri = 0;
2324 #endif
2325 macro_mri_mode (0);
2328 /* Operator precedence changes in m68k MRI mode, so we need to
2329 update the operator rankings. */
2330 expr_set_precedence ();
2332 #ifdef MRI_MODE_CHANGE
2333 if (on != old_flag)
2334 MRI_MODE_CHANGE (on);
2335 #endif
2337 demand_empty_rest_of_line ();
2340 /* Handle changing the location counter. */
2342 static void
2343 do_org (segment, exp, fill)
2344 segT segment;
2345 expressionS *exp;
2346 int fill;
2348 if (segment != now_seg && segment != absolute_section)
2349 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2350 segment_name (segment), segment_name (now_seg));
2352 if (now_seg == absolute_section)
2354 if (fill != 0)
2355 as_warn (_("ignoring fill value in absolute section"));
2356 if (exp->X_op != O_constant)
2358 as_bad (_("only constant offsets supported in absolute section"));
2359 exp->X_add_number = 0;
2361 abs_section_offset = exp->X_add_number;
2363 else
2365 char *p;
2367 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2368 exp->X_add_number * OCTETS_PER_BYTE, (char *) NULL);
2369 *p = fill;
2373 void
2374 s_org (ignore)
2375 int ignore ATTRIBUTE_UNUSED;
2377 register segT segment;
2378 expressionS exp;
2379 register long temp_fill;
2381 #ifdef md_flush_pending_output
2382 md_flush_pending_output ();
2383 #endif
2385 /* The m68k MRI assembler has a different meaning for .org. It
2386 means to create an absolute section at a given address. We can't
2387 support that--use a linker script instead. */
2388 if (flag_m68k_mri)
2390 as_bad (_("MRI style ORG pseudo-op not supported"));
2391 ignore_rest_of_line ();
2392 return;
2395 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2396 thing as a sub-segment-relative origin. Any absolute origin is
2397 given a warning, then assumed to be segment-relative. Any
2398 segmented origin expression ("foo+42") had better be in the right
2399 segment or the .org is ignored.
2401 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2402 we never know sub-segment sizes when we are reading code. BSD
2403 will crash trying to emit negative numbers of filler bytes in
2404 certain .orgs. We don't crash, but see as-write for that code.
2406 Don't make frag if need_pass_2==1. */
2407 segment = get_known_segmented_expression (&exp);
2408 if (*input_line_pointer == ',')
2410 input_line_pointer++;
2411 temp_fill = get_absolute_expression ();
2413 else
2414 temp_fill = 0;
2416 if (!need_pass_2)
2417 do_org (segment, &exp, temp_fill);
2419 demand_empty_rest_of_line ();
2420 } /* s_org() */
2422 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2423 called by the obj-format routine which handles section changing
2424 when in MRI mode. It will create a new section, and return it. It
2425 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2426 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2427 flags will be set in the section. */
2429 void
2430 s_mri_sect (type)
2431 char *type ATTRIBUTE_UNUSED;
2433 #ifdef TC_M68K
2435 char *name;
2436 char c;
2437 segT seg;
2439 SKIP_WHITESPACE ();
2441 name = input_line_pointer;
2442 if (! isdigit ((unsigned char) *name))
2443 c = get_symbol_end ();
2444 else
2448 ++input_line_pointer;
2450 while (isdigit ((unsigned char) *input_line_pointer));
2451 c = *input_line_pointer;
2452 *input_line_pointer = '\0';
2455 name = xstrdup (name);
2457 *input_line_pointer = c;
2459 seg = subseg_new (name, 0);
2461 if (*input_line_pointer == ',')
2463 int align;
2465 ++input_line_pointer;
2466 align = get_absolute_expression ();
2467 record_alignment (seg, align);
2470 *type = 'C';
2471 if (*input_line_pointer == ',')
2473 c = *++input_line_pointer;
2474 c = toupper ((unsigned char) c);
2475 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2476 *type = c;
2477 else
2478 as_bad (_("unrecognized section type"));
2479 ++input_line_pointer;
2481 #ifdef BFD_ASSEMBLER
2483 flagword flags;
2485 flags = SEC_NO_FLAGS;
2486 if (*type == 'C')
2487 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2488 else if (*type == 'D' || *type == 'M')
2489 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2490 else if (*type == 'R')
2491 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2492 if (flags != SEC_NO_FLAGS)
2494 if (! bfd_set_section_flags (stdoutput, seg, flags))
2495 as_warn (_("error setting flags for \"%s\": %s"),
2496 bfd_section_name (stdoutput, seg),
2497 bfd_errmsg (bfd_get_error ()));
2500 #endif
2503 /* Ignore the HP type. */
2504 if (*input_line_pointer == ',')
2505 input_line_pointer += 2;
2507 demand_empty_rest_of_line ();
2509 #else /* ! TC_M68K */
2510 #ifdef TC_I960
2512 char *name;
2513 char c;
2514 segT seg;
2516 SKIP_WHITESPACE ();
2518 name = input_line_pointer;
2519 c = get_symbol_end ();
2521 name = xstrdup (name);
2523 *input_line_pointer = c;
2525 seg = subseg_new (name, 0);
2527 if (*input_line_pointer != ',')
2528 *type = 'C';
2529 else
2531 char *sectype;
2533 ++input_line_pointer;
2534 SKIP_WHITESPACE ();
2535 sectype = input_line_pointer;
2536 c = get_symbol_end ();
2537 if (*sectype == '\0')
2538 *type = 'C';
2539 else if (strcasecmp (sectype, "text") == 0)
2540 *type = 'C';
2541 else if (strcasecmp (sectype, "data") == 0)
2542 *type = 'D';
2543 else if (strcasecmp (sectype, "romdata") == 0)
2544 *type = 'R';
2545 else
2546 as_warn (_("unrecognized section type `%s'"), sectype);
2547 *input_line_pointer = c;
2550 if (*input_line_pointer == ',')
2552 char *seccmd;
2554 ++input_line_pointer;
2555 SKIP_WHITESPACE ();
2556 seccmd = input_line_pointer;
2557 c = get_symbol_end ();
2558 if (strcasecmp (seccmd, "absolute") == 0)
2560 as_bad (_("absolute sections are not supported"));
2561 *input_line_pointer = c;
2562 ignore_rest_of_line ();
2563 return;
2565 else if (strcasecmp (seccmd, "align") == 0)
2567 int align;
2569 *input_line_pointer = c;
2570 align = get_absolute_expression ();
2571 record_alignment (seg, align);
2573 else
2575 as_warn (_("unrecognized section command `%s'"), seccmd);
2576 *input_line_pointer = c;
2580 demand_empty_rest_of_line ();
2582 #else /* ! TC_I960 */
2583 /* The MRI assembler seems to use different forms of .sect for
2584 different targets. */
2585 as_bad ("MRI mode not supported for this target");
2586 ignore_rest_of_line ();
2587 #endif /* ! TC_I960 */
2588 #endif /* ! TC_M68K */
2591 /* Handle the .print pseudo-op. */
2593 void
2594 s_print (ignore)
2595 int ignore ATTRIBUTE_UNUSED;
2597 char *s;
2598 int len;
2600 s = demand_copy_C_string (&len);
2601 printf ("%s\n", s);
2602 demand_empty_rest_of_line ();
2605 /* Handle the .purgem pseudo-op. */
2607 void
2608 s_purgem (ignore)
2609 int ignore ATTRIBUTE_UNUSED;
2611 if (is_it_end_of_statement ())
2613 demand_empty_rest_of_line ();
2614 return;
2619 char *name;
2620 char c;
2622 SKIP_WHITESPACE ();
2623 name = input_line_pointer;
2624 c = get_symbol_end ();
2625 delete_macro (name);
2626 *input_line_pointer = c;
2627 SKIP_WHITESPACE ();
2629 while (*input_line_pointer++ == ',');
2631 --input_line_pointer;
2632 demand_empty_rest_of_line ();
2635 /* Handle the .rept pseudo-op. */
2637 void
2638 s_rept (ignore)
2639 int ignore ATTRIBUTE_UNUSED;
2641 int count;
2643 count = get_absolute_expression ();
2645 do_repeat(count, "REPT", "ENDR");
2648 /* This function provides a generic repeat block implementation. It allows
2649 different directives to be used as the start/end keys. */
2651 void
2652 do_repeat (count, start, end)
2653 int count;
2654 const char *start;
2655 const char *end;
2657 sb one;
2658 sb many;
2660 sb_new (&one);
2661 if (! buffer_and_nest (start, end, &one, get_line_sb))
2663 as_bad (_("%s without %s"), start, end);
2664 return;
2667 sb_new (&many);
2668 while (count-- > 0)
2669 sb_add_sb (&many, &one);
2671 sb_kill (&one);
2673 input_scrub_include_sb (&many, input_line_pointer);
2674 sb_kill (&many);
2675 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2678 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2679 input buffers to skip. Assumes that conditionals preceding the loop end
2680 are properly nested.
2682 This function makes it easier to implement a premature "break" out of the
2683 loop. The EXTRA arg accounts for other buffers we might have inserted,
2684 such as line substitutions. */
2686 void
2687 end_repeat (extra)
2688 int extra;
2690 cond_exit_macro (macro_nest);
2691 while (extra-- >= 0)
2692 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2695 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2696 this is .equiv, and it is an error if the symbol is already
2697 defined. */
2699 void
2700 s_set (equiv)
2701 int equiv;
2703 register char *name;
2704 register char delim;
2705 register char *end_name;
2706 register symbolS *symbolP;
2709 * Especial apologies for the random logic:
2710 * this just grew, and could be parsed much more simply!
2711 * Dean in haste.
2713 name = input_line_pointer;
2714 delim = get_symbol_end ();
2715 end_name = input_line_pointer;
2716 *end_name = delim;
2717 SKIP_WHITESPACE ();
2719 if (*input_line_pointer != ',')
2721 *end_name = 0;
2722 as_bad (_("Expected comma after name \"%s\""), name);
2723 *end_name = delim;
2724 ignore_rest_of_line ();
2725 return;
2728 input_line_pointer++;
2729 *end_name = 0;
2731 if (name[0] == '.' && name[1] == '\0')
2733 /* Turn '. = mumble' into a .org mumble */
2734 register segT segment;
2735 expressionS exp;
2737 segment = get_known_segmented_expression (&exp);
2739 if (!need_pass_2)
2740 do_org (segment, &exp, 0);
2742 *end_name = delim;
2743 return;
2746 if ((symbolP = symbol_find (name)) == NULL
2747 && (symbolP = md_undefined_symbol (name)) == NULL)
2749 #ifndef NO_LISTING
2750 /* When doing symbol listings, play games with dummy fragments living
2751 outside the normal fragment chain to record the file and line info
2752 for this symbol. */
2753 if (listing & LISTING_SYMBOLS)
2755 extern struct list_info_struct *listing_tail;
2756 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2757 memset (dummy_frag, 0, sizeof(fragS));
2758 dummy_frag->fr_type = rs_fill;
2759 dummy_frag->line = listing_tail;
2760 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2761 dummy_frag->fr_symbol = symbolP;
2763 else
2764 #endif
2765 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2767 #ifdef OBJ_COFF
2768 /* "set" symbols are local unless otherwise specified. */
2769 SF_SET_LOCAL (symbolP);
2770 #endif /* OBJ_COFF */
2772 } /* make a new symbol */
2774 symbol_table_insert (symbolP);
2776 *end_name = delim;
2778 if (equiv
2779 && S_IS_DEFINED (symbolP)
2780 && S_GET_SEGMENT (symbolP) != reg_section)
2781 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2783 pseudo_set (symbolP);
2784 demand_empty_rest_of_line ();
2785 } /* s_set() */
2787 void
2788 s_space (mult)
2789 int mult;
2791 expressionS exp;
2792 expressionS val;
2793 char *p = 0;
2794 char *stop = NULL;
2795 char stopc;
2796 int bytes;
2798 #ifdef md_flush_pending_output
2799 md_flush_pending_output ();
2800 #endif
2802 if (flag_mri)
2803 stop = mri_comment_field (&stopc);
2805 /* In m68k MRI mode, we need to align to a word boundary, unless
2806 this is ds.b. */
2807 if (flag_m68k_mri && mult > 1)
2809 if (now_seg == absolute_section)
2811 abs_section_offset += abs_section_offset & 1;
2812 if (line_label != NULL)
2813 S_SET_VALUE (line_label, abs_section_offset);
2815 else if (mri_common_symbol != NULL)
2817 valueT val;
2819 val = S_GET_VALUE (mri_common_symbol);
2820 if ((val & 1) != 0)
2822 S_SET_VALUE (mri_common_symbol, val + 1);
2823 if (line_label != NULL)
2825 expressionS *symexp;
2827 symexp = symbol_get_value_expression (line_label);
2828 know (symexp->X_op == O_symbol);
2829 know (symexp->X_add_symbol == mri_common_symbol);
2830 symexp->X_add_number += 1;
2834 else
2836 do_align (1, (char *) NULL, 0, 0);
2837 if (line_label != NULL)
2839 symbol_set_frag (line_label, frag_now);
2840 S_SET_VALUE (line_label, frag_now_fix ());
2845 bytes = mult;
2847 expression (&exp);
2849 SKIP_WHITESPACE ();
2850 if (*input_line_pointer == ',')
2852 ++input_line_pointer;
2853 expression (&val);
2855 else
2857 val.X_op = O_constant;
2858 val.X_add_number = 0;
2861 if (val.X_op != O_constant
2862 || val.X_add_number < - 0x80
2863 || val.X_add_number > 0xff
2864 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2866 if (exp.X_op != O_constant)
2867 as_bad (_("Unsupported variable size or fill value"));
2868 else
2870 offsetT i;
2872 if (mult == 0)
2873 mult = 1;
2874 bytes = mult * exp.X_add_number;
2875 for (i = 0; i < exp.X_add_number; i++)
2876 emit_expr (&val, mult);
2879 else
2881 if (exp.X_op == O_constant)
2883 long repeat;
2885 repeat = exp.X_add_number;
2886 if (mult)
2887 repeat *= mult;
2888 bytes = repeat;
2889 if (repeat <= 0)
2891 if (! flag_mri)
2892 as_warn (_(".space repeat count is zero, ignored"));
2893 else if (repeat < 0)
2894 as_warn (_(".space repeat count is negative, ignored"));
2895 goto getout;
2898 /* If we are in the absolute section, just bump the offset. */
2899 if (now_seg == absolute_section)
2901 abs_section_offset += repeat;
2902 goto getout;
2905 /* If we are secretly in an MRI common section, then
2906 creating space just increases the size of the common
2907 symbol. */
2908 if (mri_common_symbol != NULL)
2910 S_SET_VALUE (mri_common_symbol,
2911 S_GET_VALUE (mri_common_symbol) + repeat);
2912 goto getout;
2915 if (!need_pass_2)
2916 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2917 (offsetT) repeat, (char *) 0);
2919 else
2921 if (now_seg == absolute_section)
2923 as_bad (_("space allocation too complex in absolute section"));
2924 subseg_set (text_section, 0);
2926 if (mri_common_symbol != NULL)
2928 as_bad (_("space allocation too complex in common section"));
2929 mri_common_symbol = NULL;
2931 if (!need_pass_2)
2932 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2933 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2936 if (p)
2937 *p = val.X_add_number;
2940 getout:
2942 /* In MRI mode, after an odd number of bytes, we must align to an
2943 even word boundary, unless the next instruction is a dc.b, ds.b
2944 or dcb.b. */
2945 if (flag_mri && (bytes & 1) != 0)
2946 mri_pending_align = 1;
2948 demand_empty_rest_of_line ();
2950 if (flag_mri)
2951 mri_comment_end (stop, stopc);
2954 /* This is like s_space, but the value is a floating point number with
2955 the given precision. This is for the MRI dcb.s pseudo-op and
2956 friends. */
2958 void
2959 s_float_space (float_type)
2960 int float_type;
2962 offsetT count;
2963 int flen;
2964 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2965 char *stop = NULL;
2966 char stopc;
2968 if (flag_mri)
2969 stop = mri_comment_field (&stopc);
2971 count = get_absolute_expression ();
2973 SKIP_WHITESPACE ();
2974 if (*input_line_pointer != ',')
2976 as_bad (_("missing value"));
2977 ignore_rest_of_line ();
2978 if (flag_mri)
2979 mri_comment_end (stop, stopc);
2980 return;
2983 ++input_line_pointer;
2985 SKIP_WHITESPACE ();
2987 /* Skip any 0{letter} that may be present. Don't even check if the
2988 * letter is legal. */
2989 if (input_line_pointer[0] == '0'
2990 && isalpha ((unsigned char) input_line_pointer[1]))
2991 input_line_pointer += 2;
2993 /* Accept :xxxx, where the x's are hex digits, for a floating point
2994 with the exact digits specified. */
2995 if (input_line_pointer[0] == ':')
2997 flen = hex_float (float_type, temp);
2998 if (flen < 0)
3000 ignore_rest_of_line ();
3001 if (flag_mri)
3002 mri_comment_end (stop, stopc);
3003 return;
3006 else
3008 char *err;
3010 err = md_atof (float_type, temp, &flen);
3011 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3012 know (flen > 0);
3013 if (err)
3015 as_bad (_("Bad floating literal: %s"), err);
3016 ignore_rest_of_line ();
3017 if (flag_mri)
3018 mri_comment_end (stop, stopc);
3019 return;
3023 while (--count >= 0)
3025 char *p;
3027 p = frag_more (flen);
3028 memcpy (p, temp, (unsigned int) flen);
3031 demand_empty_rest_of_line ();
3033 if (flag_mri)
3034 mri_comment_end (stop, stopc);
3037 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3039 void
3040 s_struct (ignore)
3041 int ignore ATTRIBUTE_UNUSED;
3043 char *stop = NULL;
3044 char stopc;
3046 if (flag_mri)
3047 stop = mri_comment_field (&stopc);
3048 abs_section_offset = get_absolute_expression ();
3049 subseg_set (absolute_section, 0);
3050 demand_empty_rest_of_line ();
3051 if (flag_mri)
3052 mri_comment_end (stop, stopc);
3055 void
3056 s_text (ignore)
3057 int ignore ATTRIBUTE_UNUSED;
3059 register int temp;
3061 temp = get_absolute_expression ();
3062 subseg_set (text_section, (subsegT) temp);
3063 demand_empty_rest_of_line ();
3064 #ifdef OBJ_VMS
3065 const_flag &= ~IN_DEFAULT_SECTION;
3066 #endif
3067 } /* s_text() */
3070 void
3071 demand_empty_rest_of_line ()
3073 SKIP_WHITESPACE ();
3074 if (is_end_of_line[(unsigned char) *input_line_pointer])
3076 input_line_pointer++;
3078 else
3080 ignore_rest_of_line ();
3082 /* Return having already swallowed end-of-line. */
3083 } /* Return pointing just after end-of-line. */
3085 void
3086 ignore_rest_of_line () /* For suspect lines: gives warning. */
3088 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3090 if (isprint ((unsigned char) *input_line_pointer))
3091 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3092 *input_line_pointer);
3093 else
3094 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3095 *input_line_pointer);
3096 while (input_line_pointer < buffer_limit
3097 && !is_end_of_line[(unsigned char) *input_line_pointer])
3099 input_line_pointer++;
3102 input_line_pointer++; /* Return pointing just after end-of-line. */
3103 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3106 void
3107 discard_rest_of_line ()
3109 while (input_line_pointer < buffer_limit
3110 && !is_end_of_line[(unsigned char) *input_line_pointer])
3112 input_line_pointer++;
3114 input_line_pointer++; /* Return pointing just after end-of-line. */
3115 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3119 * pseudo_set()
3121 * In: Pointer to a symbol.
3122 * Input_line_pointer->expression.
3124 * Out: Input_line_pointer->just after any whitespace after expression.
3125 * Tried to set symbol to value of expression.
3126 * Will change symbols type, value, and frag;
3128 void
3129 pseudo_set (symbolP)
3130 symbolS *symbolP;
3132 expressionS exp;
3133 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3134 int ext;
3135 #endif /* OBJ_AOUT or OBJ_BOUT */
3137 know (symbolP); /* NULL pointer is logic error. */
3138 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3139 ext = S_IS_EXTERNAL (symbolP);
3140 #endif /* OBJ_AOUT or OBJ_BOUT */
3142 (void) expression (&exp);
3144 if (exp.X_op == O_illegal)
3145 as_bad (_("illegal expression; zero assumed"));
3146 else if (exp.X_op == O_absent)
3147 as_bad (_("missing expression; zero assumed"));
3148 else if (exp.X_op == O_big)
3150 if (exp.X_add_number > 0)
3151 as_bad (_("bignum invalid; zero assumed"));
3152 else
3153 as_bad (_("floating point number invalid; zero assumed"));
3155 else if (exp.X_op == O_subtract
3156 && (S_GET_SEGMENT (exp.X_add_symbol)
3157 == S_GET_SEGMENT (exp.X_op_symbol))
3158 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3159 && (symbol_get_frag (exp.X_add_symbol)
3160 == symbol_get_frag (exp.X_op_symbol)))
3162 exp.X_op = O_constant;
3163 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3164 - S_GET_VALUE (exp.X_op_symbol));
3167 switch (exp.X_op)
3169 case O_illegal:
3170 case O_absent:
3171 case O_big:
3172 exp.X_add_number = 0;
3173 /* Fall through. */
3174 case O_constant:
3175 S_SET_SEGMENT (symbolP, absolute_section);
3176 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3177 if (ext)
3178 S_SET_EXTERNAL (symbolP);
3179 else
3180 S_CLEAR_EXTERNAL (symbolP);
3181 #endif /* OBJ_AOUT or OBJ_BOUT */
3182 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3183 if (exp.X_op != O_constant)
3184 symbol_set_frag (symbolP, &zero_address_frag);
3185 break;
3187 case O_register:
3188 S_SET_SEGMENT (symbolP, reg_section);
3189 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3190 symbol_set_frag (symbolP, &zero_address_frag);
3191 break;
3193 case O_symbol:
3194 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3195 || exp.X_add_number != 0)
3196 symbol_set_value_expression (symbolP, &exp);
3197 else if (symbol_section_p (symbolP))
3198 as_bad ("invalid attempt to set value of section symbol");
3199 else
3201 symbolS *s = exp.X_add_symbol;
3203 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3204 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3205 if (ext)
3206 S_SET_EXTERNAL (symbolP);
3207 else
3208 S_CLEAR_EXTERNAL (symbolP);
3209 #endif /* OBJ_AOUT or OBJ_BOUT */
3210 S_SET_VALUE (symbolP,
3211 exp.X_add_number + S_GET_VALUE (s));
3212 symbol_set_frag (symbolP, symbol_get_frag (s));
3213 copy_symbol_attributes (symbolP, s);
3215 break;
3217 default:
3218 /* The value is some complex expression.
3219 FIXME: Should we set the segment to anything? */
3220 symbol_set_value_expression (symbolP, &exp);
3221 break;
3226 * cons()
3228 * CONStruct more frag of .bytes, or .words etc.
3229 * Should need_pass_2 be 1 then emit no frag(s).
3230 * This understands EXPRESSIONS.
3232 * Bug (?)
3234 * This has a split personality. We use expression() to read the
3235 * value. We can detect if the value won't fit in a byte or word.
3236 * But we can't detect if expression() discarded significant digits
3237 * in the case of a long. Not worth the crocks required to fix it.
3240 /* Select a parser for cons expressions. */
3242 /* Some targets need to parse the expression in various fancy ways.
3243 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3244 (for example, the HPPA does this). Otherwise, you can define
3245 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3246 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3247 are defined, which is the normal case, then only simple expressions
3248 are permitted. */
3250 #ifdef TC_M68K
3251 static void
3252 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3253 #endif
3255 #ifndef TC_PARSE_CONS_EXPRESSION
3256 #ifdef BITFIELD_CONS_EXPRESSIONS
3257 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3258 static void
3259 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3260 #endif
3261 #ifdef REPEAT_CONS_EXPRESSIONS
3262 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3263 static void
3264 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3265 #endif
3267 /* If we haven't gotten one yet, just call expression. */
3268 #ifndef TC_PARSE_CONS_EXPRESSION
3269 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3270 #endif
3271 #endif
3273 /* worker to do .byte etc statements */
3274 /* clobbers input_line_pointer, checks */
3275 /* end-of-line. */
3276 static void
3277 cons_worker (nbytes, rva)
3278 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3279 int rva;
3281 int c;
3282 expressionS exp;
3283 char *stop = NULL;
3284 char stopc;
3286 #ifdef md_flush_pending_output
3287 md_flush_pending_output ();
3288 #endif
3290 if (flag_mri)
3291 stop = mri_comment_field (&stopc);
3293 if (is_it_end_of_statement ())
3295 demand_empty_rest_of_line ();
3296 if (flag_mri)
3297 mri_comment_end (stop, stopc);
3298 return;
3301 #ifdef md_cons_align
3302 md_cons_align (nbytes);
3303 #endif
3305 c = 0;
3308 #ifdef TC_M68K
3309 if (flag_m68k_mri)
3310 parse_mri_cons (&exp, (unsigned int) nbytes);
3311 else
3312 #endif
3313 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3315 if (rva)
3317 if (exp.X_op == O_symbol)
3318 exp.X_op = O_symbol_rva;
3319 else
3320 as_fatal (_("rva without symbol"));
3322 emit_expr (&exp, (unsigned int) nbytes);
3323 ++c;
3325 while (*input_line_pointer++ == ',');
3327 /* In MRI mode, after an odd number of bytes, we must align to an
3328 even word boundary, unless the next instruction is a dc.b, ds.b
3329 or dcb.b. */
3330 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3331 mri_pending_align = 1;
3333 input_line_pointer--; /* Put terminator back into stream. */
3335 demand_empty_rest_of_line ();
3337 if (flag_mri)
3338 mri_comment_end (stop, stopc);
3342 void
3343 cons (size)
3344 int size;
3346 cons_worker (size, 0);
3349 void
3350 s_rva (size)
3351 int size;
3353 cons_worker (size, 1);
3356 /* Put the contents of expression EXP into the object file using
3357 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3359 void
3360 emit_expr (exp, nbytes)
3361 expressionS *exp;
3362 unsigned int nbytes;
3364 operatorT op;
3365 register char *p;
3366 valueT extra_digit = 0;
3368 /* Don't do anything if we are going to make another pass. */
3369 if (need_pass_2)
3370 return;
3372 #ifndef NO_LISTING
3373 #ifdef OBJ_ELF
3374 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3375 appear as a four byte positive constant in the .line section,
3376 followed by a 2 byte 0xffff. Look for that case here. */
3378 static int dwarf_line = -1;
3380 if (strcmp (segment_name (now_seg), ".line") != 0)
3381 dwarf_line = -1;
3382 else if (dwarf_line >= 0
3383 && nbytes == 2
3384 && exp->X_op == O_constant
3385 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3386 listing_source_line ((unsigned int) dwarf_line);
3387 else if (nbytes == 4
3388 && exp->X_op == O_constant
3389 && exp->X_add_number >= 0)
3390 dwarf_line = exp->X_add_number;
3391 else
3392 dwarf_line = -1;
3395 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3396 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3397 AT_sibling (0x12) followed by a four byte address of the sibling
3398 followed by a 2 byte AT_name (0x38) followed by the name of the
3399 file. We look for that case here. */
3401 static int dwarf_file = 0;
3403 if (strcmp (segment_name (now_seg), ".debug") != 0)
3404 dwarf_file = 0;
3405 else if (dwarf_file == 0
3406 && nbytes == 2
3407 && exp->X_op == O_constant
3408 && exp->X_add_number == 0x11)
3409 dwarf_file = 1;
3410 else if (dwarf_file == 1
3411 && nbytes == 2
3412 && exp->X_op == O_constant
3413 && exp->X_add_number == 0x12)
3414 dwarf_file = 2;
3415 else if (dwarf_file == 2
3416 && nbytes == 4)
3417 dwarf_file = 3;
3418 else if (dwarf_file == 3
3419 && nbytes == 2
3420 && exp->X_op == O_constant
3421 && exp->X_add_number == 0x38)
3422 dwarf_file = 4;
3423 else
3424 dwarf_file = 0;
3426 /* The variable dwarf_file_string tells stringer that the string
3427 may be the name of the source file. */
3428 if (dwarf_file == 4)
3429 dwarf_file_string = 1;
3430 else
3431 dwarf_file_string = 0;
3433 #endif
3434 #endif
3436 if (check_eh_frame (exp, &nbytes))
3437 return;
3439 op = exp->X_op;
3441 /* Allow `.word 0' in the absolute section. */
3442 if (now_seg == absolute_section)
3444 if (op != O_constant || exp->X_add_number != 0)
3445 as_bad (_("attempt to store value in absolute section"));
3446 abs_section_offset += nbytes;
3447 return;
3450 /* Handle a negative bignum. */
3451 if (op == O_uminus
3452 && exp->X_add_number == 0
3453 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3454 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3456 int i;
3457 unsigned long carry;
3459 exp = symbol_get_value_expression (exp->X_add_symbol);
3461 /* Negate the bignum: one's complement each digit and add 1. */
3462 carry = 1;
3463 for (i = 0; i < exp->X_add_number; i++)
3465 unsigned long next;
3467 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3468 & LITTLENUM_MASK)
3469 + carry);
3470 generic_bignum[i] = next & LITTLENUM_MASK;
3471 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3474 /* We can ignore any carry out, because it will be handled by
3475 extra_digit if it is needed. */
3477 extra_digit = (valueT) -1;
3478 op = O_big;
3481 if (op == O_absent || op == O_illegal)
3483 as_warn (_("zero assumed for missing expression"));
3484 exp->X_add_number = 0;
3485 op = O_constant;
3487 else if (op == O_big && exp->X_add_number <= 0)
3489 as_bad (_("floating point number invalid; zero assumed"));
3490 exp->X_add_number = 0;
3491 op = O_constant;
3493 else if (op == O_register)
3495 as_warn (_("register value used as expression"));
3496 op = O_constant;
3499 p = frag_more ((int) nbytes);
3501 #ifndef WORKING_DOT_WORD
3502 /* If we have the difference of two symbols in a word, save it on
3503 the broken_words list. See the code in write.c. */
3504 if (op == O_subtract && nbytes == 2)
3506 struct broken_word *x;
3508 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3509 x->next_broken_word = broken_words;
3510 broken_words = x;
3511 x->seg = now_seg;
3512 x->subseg = now_subseg;
3513 x->frag = frag_now;
3514 x->word_goes_here = p;
3515 x->dispfrag = 0;
3516 x->add = exp->X_add_symbol;
3517 x->sub = exp->X_op_symbol;
3518 x->addnum = exp->X_add_number;
3519 x->added = 0;
3520 new_broken_words++;
3521 return;
3523 #endif
3525 /* If we have an integer, but the number of bytes is too large to
3526 pass to md_number_to_chars, handle it as a bignum. */
3527 if (op == O_constant && nbytes > sizeof (valueT))
3529 valueT val;
3530 int gencnt;
3532 if (! exp->X_unsigned && exp->X_add_number < 0)
3533 extra_digit = (valueT) -1;
3534 val = (valueT) exp->X_add_number;
3535 gencnt = 0;
3538 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3539 val >>= LITTLENUM_NUMBER_OF_BITS;
3540 ++gencnt;
3542 while (val != 0);
3543 op = exp->X_op = O_big;
3544 exp->X_add_number = gencnt;
3547 if (op == O_constant)
3549 register valueT get;
3550 register valueT use;
3551 register valueT mask;
3552 valueT hibit;
3553 register valueT unmask;
3555 /* JF << of >= number of bits in the object is undefined. In
3556 particular SPARC (Sun 4) has problems */
3557 if (nbytes >= sizeof (valueT))
3559 mask = 0;
3560 if (nbytes > sizeof (valueT))
3561 hibit = 0;
3562 else
3563 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3565 else
3567 /* Don't store these bits. */
3568 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3569 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3572 unmask = ~mask; /* Do store these bits. */
3574 #ifdef NEVER
3575 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3576 mask = ~(unmask >> 1); /* Includes sign bit now. */
3577 #endif
3579 get = exp->X_add_number;
3580 use = get & unmask;
3581 if ((get & mask) != 0
3582 && ((get & mask) != mask
3583 || (get & hibit) == 0))
3584 { /* Leading bits contain both 0s & 1s. */
3585 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3586 (unsigned long) get, (unsigned long) use);
3588 /* put bytes in right order. */
3589 md_number_to_chars (p, use, (int) nbytes);
3591 else if (op == O_big)
3593 unsigned int size;
3594 LITTLENUM_TYPE *nums;
3596 know (nbytes % CHARS_PER_LITTLENUM == 0);
3598 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3599 if (nbytes < size)
3601 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3602 size = nbytes;
3605 if (target_big_endian)
3607 while (nbytes > size)
3609 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3610 nbytes -= CHARS_PER_LITTLENUM;
3611 p += CHARS_PER_LITTLENUM;
3614 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3615 while (size > 0)
3617 --nums;
3618 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3619 size -= CHARS_PER_LITTLENUM;
3620 p += CHARS_PER_LITTLENUM;
3623 else
3625 nums = generic_bignum;
3626 while (size > 0)
3628 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3629 ++nums;
3630 size -= CHARS_PER_LITTLENUM;
3631 p += CHARS_PER_LITTLENUM;
3632 nbytes -= CHARS_PER_LITTLENUM;
3635 while (nbytes > 0)
3637 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3638 nbytes -= CHARS_PER_LITTLENUM;
3639 p += CHARS_PER_LITTLENUM;
3643 else
3645 memset (p, 0, nbytes);
3647 /* Now we need to generate a fixS to record the symbol value.
3648 This is easy for BFD. For other targets it can be more
3649 complex. For very complex cases (currently, the HPPA and
3650 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3651 want. For simpler cases, you can define TC_CONS_RELOC to be
3652 the name of the reloc code that should be stored in the fixS.
3653 If neither is defined, the code uses NO_RELOC if it is
3654 defined, and otherwise uses 0. */
3656 #ifdef BFD_ASSEMBLER
3657 #ifdef TC_CONS_FIX_NEW
3658 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3659 #else
3661 bfd_reloc_code_real_type r;
3663 switch (nbytes)
3665 case 1:
3666 r = BFD_RELOC_8;
3667 break;
3668 case 2:
3669 r = BFD_RELOC_16;
3670 break;
3671 case 4:
3672 r = BFD_RELOC_32;
3673 break;
3674 case 8:
3675 r = BFD_RELOC_64;
3676 break;
3677 default:
3678 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3679 r = BFD_RELOC_32;
3680 break;
3682 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3683 0, r);
3685 #endif
3686 #else
3687 #ifdef TC_CONS_FIX_NEW
3688 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3689 #else
3690 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3691 it is defined, otherwise use NO_RELOC if it is defined,
3692 otherwise use 0. */
3693 #ifndef TC_CONS_RELOC
3694 #ifdef NO_RELOC
3695 #define TC_CONS_RELOC NO_RELOC
3696 #else
3697 #define TC_CONS_RELOC 0
3698 #endif
3699 #endif
3700 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3701 TC_CONS_RELOC);
3702 #endif /* TC_CONS_FIX_NEW */
3703 #endif /* BFD_ASSEMBLER */
3707 #ifdef BITFIELD_CONS_EXPRESSIONS
3709 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3710 w:x,y:z, where w and y are bitwidths and x and y are values. They
3711 then pack them all together. We do a little better in that we allow
3712 them in words, longs, etc. and we'll pack them in target byte order
3713 for you.
3715 The rules are: pack least significat bit first, if a field doesn't
3716 entirely fit, put it in the next unit. Overflowing the bitfield is
3717 explicitly *not* even a warning. The bitwidth should be considered
3718 a "mask".
3720 To use this function the tc-XXX.h file should define
3721 BITFIELD_CONS_EXPRESSIONS. */
3723 static void
3724 parse_bitfield_cons (exp, nbytes)
3725 expressionS *exp;
3726 unsigned int nbytes;
3728 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3729 char *hold = input_line_pointer;
3731 (void) expression (exp);
3733 if (*input_line_pointer == ':')
3734 { /* bitfields */
3735 long value = 0;
3737 for (;;)
3739 unsigned long width;
3741 if (*input_line_pointer != ':')
3743 input_line_pointer = hold;
3744 break;
3745 } /* next piece is not a bitfield */
3747 /* In the general case, we can't allow
3748 full expressions with symbol
3749 differences and such. The relocation
3750 entries for symbols not defined in this
3751 assembly would require arbitrary field
3752 widths, positions, and masks which most
3753 of our current object formats don't
3754 support.
3756 In the specific case where a symbol
3757 *is* defined in this assembly, we
3758 *could* build fixups and track it, but
3759 this could lead to confusion for the
3760 backends. I'm lazy. I'll take any
3761 SEG_ABSOLUTE. I think that means that
3762 you can use a previous .set or
3763 .equ type symbol. xoxorich. */
3765 if (exp->X_op == O_absent)
3767 as_warn (_("using a bit field width of zero"));
3768 exp->X_add_number = 0;
3769 exp->X_op = O_constant;
3770 } /* implied zero width bitfield */
3772 if (exp->X_op != O_constant)
3774 *input_line_pointer = '\0';
3775 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3776 *input_line_pointer = ':';
3777 demand_empty_rest_of_line ();
3778 return;
3779 } /* too complex */
3781 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3783 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3784 width, nbytes, (BITS_PER_CHAR * nbytes));
3785 width = BITS_PER_CHAR * nbytes;
3786 } /* too big */
3788 if (width > bits_available)
3790 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3791 input_line_pointer = hold;
3792 exp->X_add_number = value;
3793 break;
3794 } /* won't fit */
3796 hold = ++input_line_pointer; /* skip ':' */
3798 (void) expression (exp);
3799 if (exp->X_op != O_constant)
3801 char cache = *input_line_pointer;
3803 *input_line_pointer = '\0';
3804 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3805 *input_line_pointer = cache;
3806 demand_empty_rest_of_line ();
3807 return;
3808 } /* too complex */
3810 value |= ((~(-1 << width) & exp->X_add_number)
3811 << ((BITS_PER_CHAR * nbytes) - bits_available));
3813 if ((bits_available -= width) == 0
3814 || is_it_end_of_statement ()
3815 || *input_line_pointer != ',')
3817 break;
3818 } /* all the bitfields we're gonna get */
3820 hold = ++input_line_pointer;
3821 (void) expression (exp);
3822 } /* forever loop */
3824 exp->X_add_number = value;
3825 exp->X_op = O_constant;
3826 exp->X_unsigned = 1;
3827 } /* if looks like a bitfield */
3828 } /* parse_bitfield_cons() */
3830 #endif /* BITFIELD_CONS_EXPRESSIONS */
3832 /* Handle an MRI style string expression. */
3834 #ifdef TC_M68K
3835 static void
3836 parse_mri_cons (exp, nbytes)
3837 expressionS *exp;
3838 unsigned int nbytes;
3840 if (*input_line_pointer != '\''
3841 && (input_line_pointer[1] != '\''
3842 || (*input_line_pointer != 'A'
3843 && *input_line_pointer != 'E')))
3844 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3845 else
3847 unsigned int scan;
3848 unsigned int result = 0;
3850 /* An MRI style string. Cut into as many bytes as will fit into
3851 a nbyte chunk, left justify if necessary, and separate with
3852 commas so we can try again later. */
3853 if (*input_line_pointer == 'A')
3854 ++input_line_pointer;
3855 else if (*input_line_pointer == 'E')
3857 as_bad (_("EBCDIC constants are not supported"));
3858 ++input_line_pointer;
3861 input_line_pointer++;
3862 for (scan = 0; scan < nbytes; scan++)
3864 if (*input_line_pointer == '\'')
3866 if (input_line_pointer[1] == '\'')
3868 input_line_pointer++;
3870 else
3871 break;
3873 result = (result << 8) | (*input_line_pointer++);
3876 /* Left justify */
3877 while (scan < nbytes)
3879 result <<= 8;
3880 scan++;
3882 /* Create correct expression */
3883 exp->X_op = O_constant;
3884 exp->X_add_number = result;
3885 /* Fake it so that we can read the next char too */
3886 if (input_line_pointer[0] != '\'' ||
3887 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3889 input_line_pointer -= 2;
3890 input_line_pointer[0] = ',';
3891 input_line_pointer[1] = '\'';
3893 else
3894 input_line_pointer++;
3897 #endif /* TC_M68K */
3899 #ifdef REPEAT_CONS_EXPRESSIONS
3901 /* Parse a repeat expression for cons. This is used by the MIPS
3902 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3903 object file COUNT times.
3905 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3907 static void
3908 parse_repeat_cons (exp, nbytes)
3909 expressionS *exp;
3910 unsigned int nbytes;
3912 expressionS count;
3913 register int i;
3915 expression (exp);
3917 if (*input_line_pointer != ':')
3919 /* No repeat count. */
3920 return;
3923 ++input_line_pointer;
3924 expression (&count);
3925 if (count.X_op != O_constant
3926 || count.X_add_number <= 0)
3928 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3929 return;
3932 /* The cons function is going to output this expression once. So we
3933 output it count - 1 times. */
3934 for (i = count.X_add_number - 1; i > 0; i--)
3935 emit_expr (exp, nbytes);
3938 #endif /* REPEAT_CONS_EXPRESSIONS */
3940 /* Parse a floating point number represented as a hex constant. This
3941 permits users to specify the exact bits they want in the floating
3942 point number. */
3944 static int
3945 hex_float (float_type, bytes)
3946 int float_type;
3947 char *bytes;
3949 int length;
3950 int i;
3952 switch (float_type)
3954 case 'f':
3955 case 'F':
3956 case 's':
3957 case 'S':
3958 length = 4;
3959 break;
3961 case 'd':
3962 case 'D':
3963 case 'r':
3964 case 'R':
3965 length = 8;
3966 break;
3968 case 'x':
3969 case 'X':
3970 length = 12;
3971 break;
3973 case 'p':
3974 case 'P':
3975 length = 12;
3976 break;
3978 default:
3979 as_bad (_("Unknown floating type type '%c'"), float_type);
3980 return -1;
3983 /* It would be nice if we could go through expression to parse the
3984 hex constant, but if we get a bignum it's a pain to sort it into
3985 the buffer correctly. */
3986 i = 0;
3987 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3989 int d;
3991 /* The MRI assembler accepts arbitrary underscores strewn about
3992 through the hex constant, so we ignore them as well. */
3993 if (*input_line_pointer == '_')
3995 ++input_line_pointer;
3996 continue;
3999 if (i >= length)
4001 as_warn (_("Floating point constant too large"));
4002 return -1;
4004 d = hex_value (*input_line_pointer) << 4;
4005 ++input_line_pointer;
4006 while (*input_line_pointer == '_')
4007 ++input_line_pointer;
4008 if (hex_p (*input_line_pointer))
4010 d += hex_value (*input_line_pointer);
4011 ++input_line_pointer;
4013 if (target_big_endian)
4014 bytes[i] = d;
4015 else
4016 bytes[length - i - 1] = d;
4017 ++i;
4020 if (i < length)
4022 if (target_big_endian)
4023 memset (bytes + i, 0, length - i);
4024 else
4025 memset (bytes, 0, length - i);
4028 return length;
4032 * float_cons()
4034 * CONStruct some more frag chars of .floats .ffloats etc.
4035 * Makes 0 or more new frags.
4036 * If need_pass_2 == 1, no frags are emitted.
4037 * This understands only floating literals, not expressions. Sorry.
4039 * A floating constant is defined by atof_generic(), except it is preceded
4040 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4041 * reading, I decided to be incompatible. This always tries to give you
4042 * rounded bits to the precision of the pseudo-op. Former AS did premature
4043 * truncatation, restored noisy bits instead of trailing 0s AND gave you
4044 * a choice of 2 flavours of noise according to which of 2 floating-point
4045 * scanners you directed AS to use.
4047 * In: input_line_pointer->whitespace before, or '0' of flonum.
4051 void
4052 float_cons (float_type)
4053 /* Clobbers input_line-pointer, checks end-of-line. */
4054 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4056 register char *p;
4057 int length; /* Number of chars in an object. */
4058 register char *err; /* Error from scanning floating literal. */
4059 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4061 if (is_it_end_of_statement ())
4063 demand_empty_rest_of_line ();
4064 return;
4067 #ifdef md_flush_pending_output
4068 md_flush_pending_output ();
4069 #endif
4073 /* input_line_pointer->1st char of a flonum (we hope!). */
4074 SKIP_WHITESPACE ();
4076 /* Skip any 0{letter} that may be present. Don't even check if the
4077 * letter is legal. Someone may invent a "z" format and this routine
4078 * has no use for such information. Lusers beware: you get
4079 * diagnostics if your input is ill-conditioned.
4081 if (input_line_pointer[0] == '0'
4082 && isalpha ((unsigned char) input_line_pointer[1]))
4083 input_line_pointer += 2;
4085 /* Accept :xxxx, where the x's are hex digits, for a floating
4086 point with the exact digits specified. */
4087 if (input_line_pointer[0] == ':')
4089 ++input_line_pointer;
4090 length = hex_float (float_type, temp);
4091 if (length < 0)
4093 ignore_rest_of_line ();
4094 return;
4097 else
4099 err = md_atof (float_type, temp, &length);
4100 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4101 know (length > 0);
4102 if (err)
4104 as_bad (_("Bad floating literal: %s"), err);
4105 ignore_rest_of_line ();
4106 return;
4110 if (!need_pass_2)
4112 int count;
4114 count = 1;
4116 #ifdef REPEAT_CONS_EXPRESSIONS
4117 if (*input_line_pointer == ':')
4119 expressionS count_exp;
4121 ++input_line_pointer;
4122 expression (&count_exp);
4123 if (count_exp.X_op != O_constant
4124 || count_exp.X_add_number <= 0)
4126 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4128 else
4129 count = count_exp.X_add_number;
4131 #endif
4133 while (--count >= 0)
4135 p = frag_more (length);
4136 memcpy (p, temp, (unsigned int) length);
4139 SKIP_WHITESPACE ();
4141 while (*input_line_pointer++ == ',');
4143 --input_line_pointer; /* Put terminator back into stream. */
4144 demand_empty_rest_of_line ();
4145 } /* float_cons() */
4147 /* Return the size of a LEB128 value */
4149 static inline int
4150 sizeof_sleb128 (value)
4151 offsetT value;
4153 register int size = 0;
4154 register unsigned byte;
4158 byte = (value & 0x7f);
4159 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4160 Fortunately, we can structure things so that the extra work reduces
4161 to a noop on systems that do things "properly". */
4162 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4163 size += 1;
4165 while (!(((value == 0) && ((byte & 0x40) == 0))
4166 || ((value == -1) && ((byte & 0x40) != 0))));
4168 return size;
4171 static inline int
4172 sizeof_uleb128 (value)
4173 valueT value;
4175 register int size = 0;
4176 register unsigned byte;
4180 byte = (value & 0x7f);
4181 value >>= 7;
4182 size += 1;
4184 while (value != 0);
4186 return size;
4190 sizeof_leb128 (value, sign)
4191 valueT value;
4192 int sign;
4194 if (sign)
4195 return sizeof_sleb128 ((offsetT) value);
4196 else
4197 return sizeof_uleb128 (value);
4200 /* Output a LEB128 value. */
4202 static inline int
4203 output_sleb128 (p, value)
4204 char *p;
4205 offsetT value;
4207 register char *orig = p;
4208 register int more;
4212 unsigned byte = (value & 0x7f);
4214 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4215 Fortunately, we can structure things so that the extra work reduces
4216 to a noop on systems that do things "properly". */
4217 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4219 more = !((((value == 0) && ((byte & 0x40) == 0))
4220 || ((value == -1) && ((byte & 0x40) != 0))));
4221 if (more)
4222 byte |= 0x80;
4224 *p++ = byte;
4226 while (more);
4228 return p - orig;
4231 static inline int
4232 output_uleb128 (p, value)
4233 char *p;
4234 valueT value;
4236 char *orig = p;
4240 unsigned byte = (value & 0x7f);
4241 value >>= 7;
4242 if (value != 0)
4243 /* More bytes to follow. */
4244 byte |= 0x80;
4246 *p++ = byte;
4248 while (value != 0);
4250 return p - orig;
4254 output_leb128 (p, value, sign)
4255 char *p;
4256 valueT value;
4257 int sign;
4259 if (sign)
4260 return output_sleb128 (p, (offsetT) value);
4261 else
4262 return output_uleb128 (p, value);
4265 /* Do the same for bignums. We combine sizeof with output here in that
4266 we don't output for NULL values of P. It isn't really as critical as
4267 for "normal" values that this be streamlined. */
4269 static inline int
4270 output_big_sleb128 (p, bignum, size)
4271 char *p;
4272 LITTLENUM_TYPE *bignum;
4273 int size;
4275 char *orig = p;
4276 valueT val = 0;
4277 int loaded = 0;
4278 unsigned byte;
4280 /* Strip leading sign extensions off the bignum. */
4281 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4282 size--;
4286 if (loaded < 7 && size > 0)
4288 val |= (*bignum << loaded);
4289 loaded += 8 * CHARS_PER_LITTLENUM;
4290 size--;
4291 bignum++;
4294 byte = val & 0x7f;
4295 loaded -= 7;
4296 val >>= 7;
4298 if (size == 0)
4300 if ((val == 0 && (byte & 0x40) == 0)
4301 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4302 && (byte & 0x40) != 0))
4303 byte |= 0x80;
4306 if (orig)
4307 *p = byte;
4308 p++;
4310 while (byte & 0x80);
4312 return p - orig;
4315 static inline int
4316 output_big_uleb128 (p, bignum, size)
4317 char *p;
4318 LITTLENUM_TYPE *bignum;
4319 int size;
4321 char *orig = p;
4322 valueT val = 0;
4323 int loaded = 0;
4324 unsigned byte;
4326 /* Strip leading zeros off the bignum. */
4327 /* XXX: Is this needed? */
4328 while (size > 0 && bignum[size-1] == 0)
4329 size--;
4333 if (loaded < 7 && size > 0)
4335 val |= (*bignum << loaded);
4336 loaded += 8 * CHARS_PER_LITTLENUM;
4337 size--;
4338 bignum++;
4341 byte = val & 0x7f;
4342 loaded -= 7;
4343 val >>= 7;
4345 if (size > 0 || val)
4346 byte |= 0x80;
4348 if (orig)
4349 *p = byte;
4350 p++;
4352 while (byte & 0x80);
4354 return p - orig;
4357 static int
4358 output_big_leb128 (p, bignum, size, sign)
4359 char *p;
4360 LITTLENUM_TYPE *bignum;
4361 int size, sign;
4363 if (sign)
4364 return output_big_sleb128 (p, bignum, size);
4365 else
4366 return output_big_uleb128 (p, bignum, size);
4369 /* Generate the appropriate fragments for a given expression to emit a
4370 leb128 value. */
4372 void
4373 emit_leb128_expr(exp, sign)
4374 expressionS *exp;
4375 int sign;
4377 operatorT op = exp->X_op;
4379 if (op == O_absent || op == O_illegal)
4381 as_warn (_("zero assumed for missing expression"));
4382 exp->X_add_number = 0;
4383 op = O_constant;
4385 else if (op == O_big && exp->X_add_number <= 0)
4387 as_bad (_("floating point number invalid; zero assumed"));
4388 exp->X_add_number = 0;
4389 op = O_constant;
4391 else if (op == O_register)
4393 as_warn (_("register value used as expression"));
4394 op = O_constant;
4397 if (op == O_constant)
4399 /* If we've got a constant, emit the thing directly right now. */
4401 valueT value = exp->X_add_number;
4402 int size;
4403 char *p;
4405 size = sizeof_leb128 (value, sign);
4406 p = frag_more (size);
4407 output_leb128 (p, value, sign);
4409 else if (op == O_big)
4411 /* O_big is a different sort of constant. */
4413 int size;
4414 char *p;
4416 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4417 p = frag_more (size);
4418 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4420 else
4422 /* Otherwise, we have to create a variable sized fragment and
4423 resolve things later. */
4425 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4426 make_expr_symbol (exp), 0, (char *) NULL);
4430 /* Parse the .sleb128 and .uleb128 pseudos. */
4432 void
4433 s_leb128 (sign)
4434 int sign;
4436 expressionS exp;
4438 do {
4439 expression (&exp);
4440 emit_leb128_expr (&exp, sign);
4441 } while (*input_line_pointer++ == ',');
4443 input_line_pointer--;
4444 demand_empty_rest_of_line ();
4448 * stringer()
4450 * We read 0 or more ',' separated, double-quoted strings.
4452 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4456 void
4457 stringer (append_zero) /* Worker to do .ascii etc statements. */
4458 /* Checks end-of-line. */
4459 register int append_zero; /* 0: don't append '\0', else 1 */
4461 register unsigned int c;
4462 char *start;
4464 #ifdef md_flush_pending_output
4465 md_flush_pending_output ();
4466 #endif
4469 * The following awkward logic is to parse ZERO or more strings,
4470 * comma separated. Recall a string expression includes spaces
4471 * before the opening '\"' and spaces after the closing '\"'.
4472 * We fake a leading ',' if there is (supposed to be)
4473 * a 1st, expression. We keep demanding expressions for each
4474 * ','.
4476 if (is_it_end_of_statement ())
4478 c = 0; /* Skip loop. */
4479 ++input_line_pointer; /* Compensate for end of loop. */
4481 else
4483 c = ','; /* Do loop. */
4485 while (c == ',' || c == '<' || c == '"')
4487 SKIP_WHITESPACE ();
4488 switch (*input_line_pointer)
4490 case '\"':
4491 ++input_line_pointer; /*->1st char of string. */
4492 start = input_line_pointer;
4493 while (is_a_char (c = next_char_of_string ()))
4495 FRAG_APPEND_1_CHAR (c);
4497 if (append_zero)
4499 FRAG_APPEND_1_CHAR (0);
4501 know (input_line_pointer[-1] == '\"');
4503 #ifndef NO_LISTING
4504 #ifdef OBJ_ELF
4505 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4506 will emit .string with a filename in the .debug section
4507 after a sequence of constants. See the comment in
4508 emit_expr for the sequence. emit_expr will set
4509 dwarf_file_string to non-zero if this string might be a
4510 source file name. */
4511 if (strcmp (segment_name (now_seg), ".debug") != 0)
4512 dwarf_file_string = 0;
4513 else if (dwarf_file_string)
4515 c = input_line_pointer[-1];
4516 input_line_pointer[-1] = '\0';
4517 listing_source_file (start);
4518 input_line_pointer[-1] = c;
4520 #endif
4521 #endif
4523 break;
4524 case '<':
4525 input_line_pointer++;
4526 c = get_single_number ();
4527 FRAG_APPEND_1_CHAR (c);
4528 if (*input_line_pointer != '>')
4530 as_bad (_("Expected <nn>"));
4532 input_line_pointer++;
4533 break;
4534 case ',':
4535 input_line_pointer++;
4536 break;
4538 SKIP_WHITESPACE ();
4539 c = *input_line_pointer;
4542 demand_empty_rest_of_line ();
4543 } /* stringer() */
4545 /* FIXME-SOMEDAY: I had trouble here on characters with the
4546 high bits set. We'll probably also have trouble with
4547 multibyte chars, wide chars, etc. Also be careful about
4548 returning values bigger than 1 byte. xoxorich. */
4550 unsigned int
4551 next_char_of_string ()
4553 register unsigned int c;
4555 c = *input_line_pointer++ & CHAR_MASK;
4556 switch (c)
4558 case '\"':
4559 c = NOT_A_CHAR;
4560 break;
4562 case '\n':
4563 as_warn (_("Unterminated string: Newline inserted."));
4564 bump_line_counters ();
4565 break;
4567 #ifndef NO_STRING_ESCAPES
4568 case '\\':
4569 switch (c = *input_line_pointer++)
4571 case 'b':
4572 c = '\b';
4573 break;
4575 case 'f':
4576 c = '\f';
4577 break;
4579 case 'n':
4580 c = '\n';
4581 break;
4583 case 'r':
4584 c = '\r';
4585 break;
4587 case 't':
4588 c = '\t';
4589 break;
4591 case 'v':
4592 c = '\013';
4593 break;
4595 case '\\':
4596 case '"':
4597 break; /* As itself. */
4599 case '0':
4600 case '1':
4601 case '2':
4602 case '3':
4603 case '4':
4604 case '5':
4605 case '6':
4606 case '7':
4607 case '8':
4608 case '9':
4610 long number;
4611 int i;
4613 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4615 number = number * 8 + c - '0';
4617 c = number & 0xff;
4619 --input_line_pointer;
4620 break;
4622 case 'x':
4623 case 'X':
4625 long number;
4627 number = 0;
4628 c = *input_line_pointer++;
4629 while (isxdigit (c))
4631 if (isdigit (c))
4632 number = number * 16 + c - '0';
4633 else if (isupper (c))
4634 number = number * 16 + c - 'A' + 10;
4635 else
4636 number = number * 16 + c - 'a' + 10;
4637 c = *input_line_pointer++;
4639 c = number & 0xff;
4640 --input_line_pointer;
4642 break;
4644 case '\n':
4645 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4646 as_warn (_("Unterminated string: Newline inserted."));
4647 c = '\n';
4648 bump_line_counters ();
4649 break;
4651 default:
4653 #ifdef ONLY_STANDARD_ESCAPES
4654 as_bad (_("Bad escaped character in string, '?' assumed"));
4655 c = '?';
4656 #endif /* ONLY_STANDARD_ESCAPES */
4658 break;
4659 } /* switch on escaped char */
4660 break;
4661 #endif /* ! defined (NO_STRING_ESCAPES) */
4663 default:
4664 break;
4665 } /* switch on char */
4666 return (c);
4667 } /* next_char_of_string() */
4669 static segT
4670 get_segmented_expression (expP)
4671 register expressionS *expP;
4673 register segT retval;
4675 retval = expression (expP);
4676 if (expP->X_op == O_illegal
4677 || expP->X_op == O_absent
4678 || expP->X_op == O_big)
4680 as_bad (_("expected address expression; zero assumed"));
4681 expP->X_op = O_constant;
4682 expP->X_add_number = 0;
4683 retval = absolute_section;
4685 return retval;
4688 static segT
4689 get_known_segmented_expression (expP)
4690 register expressionS *expP;
4692 register segT retval;
4694 if ((retval = get_segmented_expression (expP)) == undefined_section)
4696 /* There is no easy way to extract the undefined symbol from the
4697 expression. */
4698 if (expP->X_add_symbol != NULL
4699 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4700 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4701 S_GET_NAME (expP->X_add_symbol));
4702 else
4703 as_warn (_("some symbol undefined; zero assumed"));
4704 retval = absolute_section;
4705 expP->X_op = O_constant;
4706 expP->X_add_number = 0;
4708 know (retval == absolute_section || SEG_NORMAL (retval));
4709 return (retval);
4710 } /* get_known_segmented_expression() */
4712 offsetT
4713 get_absolute_expression ()
4715 expressionS exp;
4717 expression (&exp);
4718 if (exp.X_op != O_constant)
4720 if (exp.X_op != O_absent)
4721 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4722 exp.X_add_number = 0;
4724 return exp.X_add_number;
4727 char /* return terminator */
4728 get_absolute_expression_and_terminator (val_pointer)
4729 long *val_pointer; /* return value of expression */
4731 /* FIXME: val_pointer should probably be offsetT *. */
4732 *val_pointer = (long) get_absolute_expression ();
4733 return (*input_line_pointer++);
4737 * demand_copy_C_string()
4739 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4740 * Give a warning if that happens.
4742 char *
4743 demand_copy_C_string (len_pointer)
4744 int *len_pointer;
4746 register char *s;
4748 if ((s = demand_copy_string (len_pointer)) != 0)
4750 register int len;
4752 for (len = *len_pointer; len > 0; len--)
4754 if (*s == 0)
4756 s = 0;
4757 len = 1;
4758 *len_pointer = 0;
4759 as_bad (_("This string may not contain \'\\0\'"));
4763 return s;
4767 * demand_copy_string()
4769 * Demand string, but return a safe (=private) copy of the string.
4770 * Return NULL if we can't read a string here.
4772 char *
4773 demand_copy_string (lenP)
4774 int *lenP;
4776 register unsigned int c;
4777 register int len;
4778 char *retval;
4780 len = 0;
4781 SKIP_WHITESPACE ();
4782 if (*input_line_pointer == '\"')
4784 input_line_pointer++; /* Skip opening quote. */
4786 while (is_a_char (c = next_char_of_string ()))
4788 obstack_1grow (&notes, c);
4789 len++;
4791 /* JF this next line is so demand_copy_C_string will return a
4792 null terminated string. */
4793 obstack_1grow (&notes, '\0');
4794 retval = obstack_finish (&notes);
4796 else
4798 as_warn (_("Missing string"));
4799 retval = NULL;
4800 ignore_rest_of_line ();
4802 *lenP = len;
4803 return (retval);
4804 } /* demand_copy_string() */
4807 * is_it_end_of_statement()
4809 * In: Input_line_pointer->next character.
4811 * Do: Skip input_line_pointer over all whitespace.
4813 * Out: 1 if input_line_pointer->end-of-line.
4815 int
4816 is_it_end_of_statement ()
4818 SKIP_WHITESPACE ();
4819 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4820 } /* is_it_end_of_statement() */
4822 void
4823 equals (sym_name, reassign)
4824 char *sym_name;
4825 int reassign;
4827 register symbolS *symbolP; /* symbol we are working with */
4828 char *stop = NULL;
4829 char stopc;
4831 input_line_pointer++;
4832 if (*input_line_pointer == '=')
4833 input_line_pointer++;
4835 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4836 input_line_pointer++;
4838 if (flag_mri)
4839 stop = mri_comment_field (&stopc);
4841 if (sym_name[0] == '.' && sym_name[1] == '\0')
4843 /* Turn '. = mumble' into a .org mumble */
4844 register segT segment;
4845 expressionS exp;
4847 segment = get_known_segmented_expression (&exp);
4848 if (!need_pass_2)
4849 do_org (segment, &exp, 0);
4851 else
4853 symbolP = symbol_find_or_make (sym_name);
4854 /* Permit register names to be redefined. */
4855 if (! reassign
4856 && S_IS_DEFINED (symbolP)
4857 && S_GET_SEGMENT (symbolP) != reg_section)
4858 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4859 pseudo_set (symbolP);
4862 if (flag_mri)
4864 ignore_rest_of_line (); /* check garbage after the expression */
4865 mri_comment_end (stop, stopc);
4867 } /* equals() */
4869 /* .include -- include a file at this point. */
4871 /* ARGSUSED */
4872 void
4873 s_include (arg)
4874 int arg ATTRIBUTE_UNUSED;
4876 char *newbuf;
4877 char *filename;
4878 int i;
4879 FILE *try;
4880 char *path;
4882 if (! flag_m68k_mri)
4884 filename = demand_copy_string (&i);
4885 if (filename == NULL)
4887 /* demand_copy_string has already printed an error and
4888 called ignore_rest_of_line. */
4889 return;
4892 else
4894 SKIP_WHITESPACE ();
4895 i = 0;
4896 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4897 && *input_line_pointer != ' '
4898 && *input_line_pointer != '\t')
4900 obstack_1grow (&notes, *input_line_pointer);
4901 ++input_line_pointer;
4902 ++i;
4904 obstack_1grow (&notes, '\0');
4905 filename = obstack_finish (&notes);
4906 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4907 ++input_line_pointer;
4909 demand_empty_rest_of_line ();
4910 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4911 for (i = 0; i < include_dir_count; i++)
4913 strcpy (path, include_dirs[i]);
4914 strcat (path, "/");
4915 strcat (path, filename);
4916 if (0 != (try = fopen (path, "r")))
4918 fclose (try);
4919 goto gotit;
4922 free (path);
4923 path = filename;
4924 gotit:
4925 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4926 register_dependency (path);
4927 newbuf = input_scrub_include_file (path, input_line_pointer);
4928 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4929 } /* s_include() */
4931 void
4932 add_include_dir (path)
4933 char *path;
4935 int i;
4937 if (include_dir_count == 0)
4939 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4940 include_dirs[0] = "."; /* Current dir */
4941 include_dir_count = 2;
4943 else
4945 include_dir_count++;
4946 include_dirs = (char **) realloc (include_dirs,
4947 include_dir_count * sizeof (*include_dirs));
4950 include_dirs[include_dir_count - 1] = path; /* New one */
4952 i = strlen (path);
4953 if (i > include_dir_maxlen)
4954 include_dir_maxlen = i;
4955 } /* add_include_dir() */
4957 /* Output debugging information to denote the source file. */
4959 static void
4960 generate_file_debug ()
4962 if (debug_type == DEBUG_STABS)
4963 stabs_generate_asm_file ();
4966 /* Output line number debugging information for the current source line. */
4968 void
4969 generate_lineno_debug ()
4971 #ifdef ECOFF_DEBUGGING
4972 /* ECOFF assemblers automatically generate debugging information.
4973 FIXME: This should probably be handled elsewhere. */
4974 if (debug_type == DEBUG_UNSPECIFIED)
4976 if (ECOFF_DEBUGGING && ecoff_no_current_file ())
4977 debug_type = DEBUG_ECOFF;
4978 else
4979 debug_type = DEBUG_NONE;
4981 #endif
4983 switch (debug_type)
4985 case DEBUG_UNSPECIFIED:
4986 case DEBUG_NONE:
4987 break;
4988 case DEBUG_STABS:
4989 stabs_generate_asm_lineno ();
4990 break;
4991 case DEBUG_ECOFF:
4992 ecoff_generate_asm_lineno ();
4993 break;
4994 case DEBUG_DWARF:
4995 case DEBUG_DWARF2:
4996 /* FIXME. */
4997 break;
5001 /* Output debugging information to mark a function entry point or end point.
5002 END_P is zero for .func, and non-zero for .endfunc. */
5004 void
5005 s_func (end_p)
5006 int end_p;
5008 do_s_func (end_p, NULL);
5011 /* Subroutine of s_func so targets can choose a different default prefix.
5012 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5014 void
5015 do_s_func (end_p, default_prefix)
5016 int end_p;
5017 const char *default_prefix;
5019 /* Record the current function so that we can issue an error message for
5020 misplaced .func,.endfunc, and also so that .endfunc needs no
5021 arguments. */
5022 static char *current_name;
5023 static char *current_label;
5025 if (end_p)
5027 if (current_name == NULL)
5029 as_bad (_("missing .func"));
5030 ignore_rest_of_line ();
5031 return;
5034 if (debug_type == DEBUG_STABS)
5035 stabs_generate_asm_endfunc (current_name, current_label);
5037 current_name = current_label = NULL;
5039 else /* ! end_p */
5041 char *name,*label;
5042 char delim1,delim2;
5044 if (current_name != NULL)
5046 as_bad (_(".endfunc missing for previous .func"));
5047 ignore_rest_of_line ();
5048 return;
5051 name = input_line_pointer;
5052 delim1 = get_symbol_end ();
5053 name = xstrdup (name);
5054 *input_line_pointer = delim1;
5055 SKIP_WHITESPACE ();
5056 if (*input_line_pointer != ',')
5058 if (default_prefix)
5059 asprintf (&label, "%s%s", default_prefix, name);
5060 else
5062 char leading_char = 0;
5063 #ifdef BFD_ASSEMBLER
5064 leading_char = bfd_get_symbol_leading_char (stdoutput);
5065 #endif
5066 /* Missing entry point, use function's name with the leading
5067 char prepended. */
5068 if (leading_char)
5069 asprintf (&label, "%c%s", leading_char, name);
5070 else
5071 label = name;
5074 else
5076 ++input_line_pointer;
5077 SKIP_WHITESPACE ();
5078 label = input_line_pointer;
5079 delim2 = get_symbol_end ();
5080 label = xstrdup (label);
5081 *input_line_pointer = delim2;
5084 if (debug_type == DEBUG_STABS)
5085 stabs_generate_asm_func (name, label);
5087 current_name = name;
5088 current_label = label;
5091 demand_empty_rest_of_line ();
5094 void
5095 s_ignore (arg)
5096 int arg ATTRIBUTE_UNUSED;
5098 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5100 ++input_line_pointer;
5102 ++input_line_pointer;
5106 void
5107 read_print_statistics (file)
5108 FILE *file;
5110 hash_print_statistics (file, "pseudo-op table", po_hash);
5113 /* end of read.c */