* gas/elf/ehopt0.s: New.
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
252b5132 1/* read.c - read a source file -
f7e42eb4
NC
2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000 Free Software Foundation, Inc.
252b5132
RH
4
5This file is part of GAS, the GNU Assembler.
6
7GAS is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GAS is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GAS; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
f0e652b4 2002111-1307, USA. */
252b5132
RH
21
22#if 0
041ff4dd
NC
23/* If your chars aren't 8 bits, you will change this a bit.
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
26#define MASK_CHAR (0xFF)
252b5132 27#else
041ff4dd 28#define MASK_CHAR ((int)(unsigned char) -1)
252b5132
RH
29#endif
30
252b5132 31/* This is the largest known floating point format (for now). It will
041ff4dd 32 grow when we do 4361 style flonums. */
252b5132
RH
33#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
34
35/* Routines that read assembler source text to build spagetti in memory.
36 Another group of these functions is in the expr.c module. */
37
041ff4dd 38/* For isdigit (). */
252b5132
RH
39#include <ctype.h>
40
41#include "as.h"
42#include "subsegs.h"
43#include "sb.h"
44#include "macro.h"
45#include "obstack.h"
46#include "listing.h"
47#include "ecoff.h"
48
49#ifndef TC_START_LABEL
50#define TC_START_LABEL(x,y) (x==':')
51#endif
52
8684e216
HPN
53/* Set by the object-format or the target. */
54#ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
041ff4dd
NC
55#define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 do \
57 { \
58 if ((SIZE) >= 8) \
59 (P2VAR) = 3; \
60 else if ((SIZE) >= 4) \
61 (P2VAR) = 2; \
62 else if ((SIZE) >= 2) \
63 (P2VAR) = 1; \
64 else \
65 (P2VAR) = 0; \
66 } \
67 while (0)
8684e216
HPN
68#endif
69
041ff4dd 70char *input_line_pointer; /*->next char of source file to parse. */
252b5132
RH
71
72#if BITS_PER_CHAR != 8
73/* The following table is indexed by[(char)] and will break if
74 a char does not have exactly 256 states (hopefully 0:255!)! */
75die horribly;
76#endif
77
78#ifndef LEX_AT
79/* The m88k unfortunately uses @ as a label beginner. */
80#define LEX_AT 0
81#endif
82
83#ifndef LEX_BR
84/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85#define LEX_BR 0
86#endif
87
88#ifndef LEX_PCT
89/* The Delta 68k assembler permits % inside label names. */
90#define LEX_PCT 0
91#endif
92
93#ifndef LEX_QM
94/* The PowerPC Windows NT assemblers permits ? inside label names. */
95#define LEX_QM 0
96#endif
97
58b5739a 98#ifndef LEX_HASH
800eeca4
JW
99/* The IA-64 assembler uses # as a suffix designating a symbol. We include
100 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
58b5739a
RH
101#define LEX_HASH 0
102#endif
103
252b5132
RH
104#ifndef LEX_DOLLAR
105/* The a29k assembler does not permits labels to start with $. */
106#define LEX_DOLLAR 3
107#endif
108
109#ifndef LEX_TILDE
110/* The Delta 68k assembler permits ~ at start of label names. */
111#define LEX_TILDE 0
112#endif
113
041ff4dd 114/* Used by is_... macros. our ctype[]. */
ef99799a 115char lex_type[256] = {
252b5132
RH
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
58b5739a 118 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
252b5132
RH
119 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
120 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
122 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
041ff4dd 123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
252b5132
RH
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
127 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
128 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
129 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
130 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
131 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
132};
133
041ff4dd
NC
134/* In: a character.
135 Out: 1 if this character ends a line. */
ef99799a 136char is_end_of_line[256] = {
252b5132 137#ifdef CR_EOL
b75c0c92 138 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
252b5132 139#else
b75c0c92 140 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
252b5132 141#endif
b75c0c92
AM
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
ac743b2c 144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
b75c0c92
AM
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0b545448
AM
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
252b5132 157};
252b5132 158
37d8bb27
NC
159#ifdef IGNORE_OPCODE_CASE
160char original_case_string[128];
161#endif
162
041ff4dd 163/* Functions private to this file. */
252b5132 164
041ff4dd
NC
165static char *buffer; /* 1st char of each buffer of lines is here. */
166static char *buffer_limit; /*->1 + last char in buffer. */
252b5132 167
041ff4dd
NC
168/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
169 in the tc-<CPU>.h file. See the "Porting GAS" section of the
170 internals manual. */
252b5132
RH
171int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
172
041ff4dd 173static char *old_buffer; /* JF a hack. */
252b5132
RH
174static char *old_input;
175static char *old_limit;
176
041ff4dd 177/* Variables for handling include file directory table. */
252b5132 178
041ff4dd
NC
179/* Table of pointers to directories to search for .include's. */
180char **include_dirs;
181
182/* How many are in the table. */
183int include_dir_count;
184
185/* Length of longest in table. */
186int include_dir_maxlen = 1;
252b5132
RH
187
188#ifndef WORKING_DOT_WORD
189struct broken_word *broken_words;
190int new_broken_words;
191#endif
192
193/* The current offset into the absolute section. We don't try to
194 build frags in the absolute section, since no data can be stored
195 there. We just keep track of the current offset. */
196addressT abs_section_offset;
197
198/* If this line had an MRI style label, it is stored in this variable.
199 This is used by some of the MRI pseudo-ops. */
200symbolS *line_label;
201
202/* This global variable is used to support MRI common sections. We
203 translate such sections into a common symbol. This variable is
204 non-NULL when we are in an MRI common section. */
205symbolS *mri_common_symbol;
206
207/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
208 need to align to an even byte boundary unless the next pseudo-op is
209 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
210 may be needed. */
211static int mri_pending_align;
212
213#ifndef NO_LISTING
214#ifdef OBJ_ELF
215/* This variable is set to be non-zero if the next string we see might
216 be the name of the source file in DWARF debugging information. See
217 the comment in emit_expr for the format we look for. */
218static int dwarf_file_string;
219#endif
220#endif
221
222static void cons_worker PARAMS ((int, int));
2b47531b 223static int scrub_from_string PARAMS ((char *, int));
252b5132
RH
224static void do_align PARAMS ((int, char *, int, int));
225static void s_align PARAMS ((int, int));
6d4d30bb 226static void s_lcomm_internal PARAMS ((int, int));
252b5132 227static int hex_float PARAMS ((int, char *));
6d4d30bb
AM
228static inline int sizeof_sleb128 PARAMS ((offsetT));
229static inline int sizeof_uleb128 PARAMS ((valueT));
230static inline int output_sleb128 PARAMS ((char *, offsetT));
231static inline int output_uleb128 PARAMS ((char *, valueT));
232static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
233static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
234static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
252b5132
RH
235static void do_org PARAMS ((segT, expressionS *, int));
236char *demand_copy_string PARAMS ((int *lenP));
237static segT get_segmented_expression PARAMS ((expressionS *expP));
238static segT get_known_segmented_expression PARAMS ((expressionS * expP));
239static void pobegin PARAMS ((void));
240static int get_line_sb PARAMS ((sb *));
241static void generate_file_debug PARAMS ((void));
242\f
252b5132
RH
243void
244read_begin ()
245{
246 const char *p;
247
248 pobegin ();
249 obj_read_begin_hook ();
250
251 /* Something close -- but not too close -- to a multiple of 1024.
252 The debugging malloc I'm using has 24 bytes of overhead. */
253 obstack_begin (&notes, chunksize);
254 obstack_begin (&cond_obstack, chunksize);
255
041ff4dd 256 /* Use machine dependent syntax. */
252b5132
RH
257 for (p = line_separator_chars; *p; p++)
258 is_end_of_line[(unsigned char) *p] = 1;
041ff4dd 259 /* Use more. FIXME-SOMEDAY. */
252b5132
RH
260
261 if (flag_mri)
262 lex_type['?'] = 3;
263}
264\f
041ff4dd 265/* Set up pseudo-op tables. */
252b5132
RH
266
267static struct hash_control *po_hash;
268
ef99799a 269static const pseudo_typeS potable[] = {
252b5132
RH
270 {"abort", s_abort, 0},
271 {"align", s_align_ptwo, 0},
272 {"ascii", stringer, 0},
273 {"asciz", stringer, 1},
274 {"balign", s_align_bytes, 0},
275 {"balignw", s_align_bytes, -2},
276 {"balignl", s_align_bytes, -4},
041ff4dd 277/* block */
252b5132
RH
278 {"byte", cons, 1},
279 {"comm", s_comm, 0},
280 {"common", s_mri_common, 0},
281 {"common.s", s_mri_common, 1},
282 {"data", s_data, 0},
283 {"dc", cons, 2},
284 {"dc.b", cons, 1},
285 {"dc.d", float_cons, 'd'},
286 {"dc.l", cons, 4},
287 {"dc.s", float_cons, 'f'},
288 {"dc.w", cons, 2},
289 {"dc.x", float_cons, 'x'},
290 {"dcb", s_space, 2},
291 {"dcb.b", s_space, 1},
292 {"dcb.d", s_float_space, 'd'},
293 {"dcb.l", s_space, 4},
294 {"dcb.s", s_float_space, 'f'},
295 {"dcb.w", s_space, 2},
296 {"dcb.x", s_float_space, 'x'},
297 {"ds", s_space, 2},
298 {"ds.b", s_space, 1},
299 {"ds.d", s_space, 8},
300 {"ds.l", s_space, 4},
301 {"ds.p", s_space, 12},
302 {"ds.s", s_space, 4},
303 {"ds.w", s_space, 2},
304 {"ds.x", s_space, 12},
305 {"debug", s_ignore, 0},
306#ifdef S_SET_DESC
307 {"desc", s_desc, 0},
308#endif
041ff4dd 309/* dim */
252b5132 310 {"double", float_cons, 'd'},
041ff4dd
NC
311/* dsect */
312 {"eject", listing_eject, 0}, /* Formfeed listing. */
252b5132
RH
313 {"else", s_else, 0},
314 {"elsec", s_else, 0},
3fd9f047 315 {"elseif", s_elseif, (int) O_ne},
252b5132
RH
316 {"end", s_end, 0},
317 {"endc", s_endif, 0},
318 {"endfunc", s_func, 1},
319 {"endif", s_endif, 0},
041ff4dd 320/* endef */
252b5132
RH
321 {"equ", s_set, 0},
322 {"equiv", s_set, 1},
323 {"err", s_err, 0},
324 {"exitm", s_mexit, 0},
041ff4dd
NC
325/* extend */
326 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
252b5132
RH
327 {"appfile", s_app_file, 1},
328 {"appline", s_app_line, 0},
329 {"fail", s_fail, 0},
330 {"file", s_app_file, 0},
331 {"fill", s_fill, 0},
332 {"float", float_cons, 'f'},
333 {"format", s_ignore, 0},
334 {"func", s_func, 0},
335 {"global", s_globl, 0},
336 {"globl", s_globl, 0},
337 {"hword", cons, 2},
338 {"if", s_if, (int) O_ne},
339 {"ifc", s_ifc, 0},
340 {"ifdef", s_ifdef, 0},
341 {"ifeq", s_if, (int) O_eq},
342 {"ifeqs", s_ifeqs, 0},
343 {"ifge", s_if, (int) O_ge},
344 {"ifgt", s_if, (int) O_gt},
345 {"ifle", s_if, (int) O_le},
346 {"iflt", s_if, (int) O_lt},
347 {"ifnc", s_ifc, 1},
348 {"ifndef", s_ifdef, 1},
349 {"ifne", s_if, (int) O_ne},
350 {"ifnes", s_ifeqs, 1},
351 {"ifnotdef", s_ifdef, 1},
352 {"include", s_include, 0},
353 {"int", cons, 4},
354 {"irp", s_irp, 0},
355 {"irep", s_irp, 0},
356 {"irpc", s_irp, 1},
357 {"irepc", s_irp, 1},
358 {"lcomm", s_lcomm, 0},
041ff4dd 359 {"lflags", listing_flags, 0}, /* Listing flags. */
252b5132 360 {"linkonce", s_linkonce, 0},
041ff4dd 361 {"list", listing_list, 1}, /* Turn listing on. */
252b5132
RH
362 {"llen", listing_psize, 1},
363 {"long", cons, 4},
364 {"lsym", s_lsym, 0},
365 {"macro", s_macro, 0},
366 {"mexit", s_mexit, 0},
367 {"mri", s_mri, 0},
368 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
369 {"name", s_ignore, 0},
370 {"noformat", s_ignore, 0},
041ff4dd 371 {"nolist", listing_list, 0}, /* Turn listing off. */
252b5132
RH
372 {"nopage", listing_nopage, 0},
373 {"octa", cons, 16},
374 {"offset", s_struct, 0},
375 {"org", s_org, 0},
376 {"p2align", s_align_ptwo, 0},
377 {"p2alignw", s_align_ptwo, -2},
378 {"p2alignl", s_align_ptwo, -4},
379 {"page", listing_eject, 0},
380 {"plen", listing_psize, 0},
381 {"print", s_print, 0},
041ff4dd 382 {"psize", listing_psize, 0}, /* Set paper size. */
252b5132
RH
383 {"purgem", s_purgem, 0},
384 {"quad", cons, 8},
385 {"rep", s_rept, 0},
386 {"rept", s_rept, 0},
387 {"rva", s_rva, 4},
041ff4dd
NC
388 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
389/* scl */
390/* sect */
252b5132
RH
391 {"set", s_set, 0},
392 {"short", cons, 2},
393 {"single", float_cons, 'f'},
041ff4dd 394/* size */
252b5132
RH
395 {"space", s_space, 0},
396 {"skip", s_space, 0},
397 {"sleb128", s_leb128, 1},
398 {"spc", s_ignore, 0},
399 {"stabd", s_stab, 'd'},
400 {"stabn", s_stab, 'n'},
401 {"stabs", s_stab, 's'},
402 {"string", stringer, 1},
403 {"struct", s_struct, 0},
041ff4dd 404/* tag */
252b5132
RH
405 {"text", s_text, 0},
406
407 /* This is for gcc to use. It's only just been added (2/94), so gcc
408 won't be able to use it for a while -- probably a year or more.
409 But once this has been released, check with gcc maintainers
410 before deleting it or even changing the spelling. */
411 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
412 /* If we're folding case -- done for some targets, not necessarily
413 all -- the above string in an input file will be converted to
414 this one. Match it either way... */
415 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
416
041ff4dd 417 {"title", listing_title, 0}, /* Listing title. */
252b5132 418 {"ttl", listing_title, 0},
041ff4dd 419/* type */
252b5132 420 {"uleb128", s_leb128, 0},
041ff4dd
NC
421/* use */
422/* val */
252b5132
RH
423 {"xcom", s_comm, 0},
424 {"xdef", s_globl, 0},
425 {"xref", s_ignore, 0},
426 {"xstabs", s_xstab, 's'},
427 {"word", cons, 2},
428 {"zero", s_space, 0},
041ff4dd 429 {NULL, NULL, 0} /* End sentinel. */
252b5132
RH
430};
431
432static int pop_override_ok = 0;
433static const char *pop_table_name;
434
435void
436pop_insert (table)
437 const pseudo_typeS *table;
438{
439 const char *errtxt;
440 const pseudo_typeS *pop;
441 for (pop = table; pop->poc_name; pop++)
442 {
443 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
444 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
445 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
446 errtxt);
447 }
448}
449
450#ifndef md_pop_insert
451#define md_pop_insert() pop_insert(md_pseudo_table)
452#endif
453
454#ifndef obj_pop_insert
455#define obj_pop_insert() pop_insert(obj_pseudo_table)
456#endif
457
041ff4dd 458static void
252b5132
RH
459pobegin ()
460{
461 po_hash = hash_new ();
462
041ff4dd 463 /* Do the target-specific pseudo ops. */
252b5132
RH
464 pop_table_name = "md";
465 md_pop_insert ();
466
041ff4dd 467 /* Now object specific. Skip any that were in the target table. */
252b5132
RH
468 pop_table_name = "obj";
469 pop_override_ok = 1;
470 obj_pop_insert ();
471
041ff4dd 472 /* Now portable ones. Skip any that we've seen already. */
252b5132
RH
473 pop_table_name = "standard";
474 pop_insert (potable);
475}
476\f
477#define HANDLE_CONDITIONAL_ASSEMBLY() \
478 if (ignore_input ()) \
479 { \
041ff4dd 480 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
252b5132
RH
481 if (input_line_pointer == buffer_limit) \
482 break; \
483 continue; \
484 }
485
252b5132
RH
486/* This function is used when scrubbing the characters between #APP
487 and #NO_APP. */
488
489static char *scrub_string;
490static char *scrub_string_end;
491
492static int
2b47531b
ILT
493scrub_from_string (buf, buflen)
494 char *buf;
495 int buflen;
252b5132 496{
2b47531b
ILT
497 int copy;
498
499 copy = scrub_string_end - scrub_string;
500 if (copy > buflen)
501 copy = buflen;
502 memcpy (buf, scrub_string, copy);
503 scrub_string += copy;
504 return copy;
252b5132
RH
505}
506
041ff4dd
NC
507/* We read the file, putting things into a web that represents what we
508 have been reading. */
509void
252b5132
RH
510read_a_source_file (name)
511 char *name;
512{
513 register char c;
041ff4dd 514 register char *s; /* String of symbol, '\0' appended. */
252b5132
RH
515 register int temp;
516 pseudo_typeS *pop;
517
4c400d5e
AM
518#ifdef WARN_COMMENTS
519 found_comment = 0;
520#endif
521
252b5132
RH
522 buffer = input_scrub_new_file (name);
523
524 listing_file (name);
525 listing_newline (NULL);
526 register_dependency (name);
527
528 /* Generate debugging information before we've read anything in to denote
529 this file as the "main" source file and not a subordinate one
530 (e.g. N_SO vs N_SOL in stabs). */
531 generate_file_debug ();
532
533 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
041ff4dd
NC
534 { /* We have another line to parse. */
535 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
252b5132
RH
536 contin: /* JF this goto is my fault I admit it.
537 Someone brave please re-write the whole
538 input section here? Pleeze??? */
539 while (input_line_pointer < buffer_limit)
540 {
041ff4dd 541 /* We have more of this buffer to parse. */
252b5132 542
041ff4dd
NC
543 /* We now have input_line_pointer->1st char of next line.
544 If input_line_pointer [-1] == '\n' then we just
545 scanned another line: so bump line counters. */
252b5132
RH
546 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
547 {
548#ifdef md_start_line_hook
549 md_start_line_hook ();
550#endif
252b5132
RH
551 if (input_line_pointer[-1] == '\n')
552 bump_line_counters ();
553
554 line_label = NULL;
555
abd63a32 556 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
252b5132
RH
557 {
558 /* Text at the start of a line must be a label, we
559 run down and stick a colon in. */
560 if (is_name_beginner (*input_line_pointer))
561 {
562 char *line_start = input_line_pointer;
563 char c;
564 int mri_line_macro;
565
566 LISTING_NEWLINE ();
567 HANDLE_CONDITIONAL_ASSEMBLY ();
568
569 c = get_symbol_end ();
570
571 /* In MRI mode, the EQU and MACRO pseudoops must
572 be handled specially. */
573 mri_line_macro = 0;
574 if (flag_m68k_mri)
575 {
576 char *rest = input_line_pointer + 1;
577
578 if (*rest == ':')
579 ++rest;
580 if (*rest == ' ' || *rest == '\t')
581 ++rest;
582 if ((strncasecmp (rest, "EQU", 3) == 0
583 || strncasecmp (rest, "SET", 3) == 0)
584 && (rest[3] == ' ' || rest[3] == '\t'))
585 {
586 input_line_pointer = rest + 3;
587 equals (line_start,
588 strncasecmp (rest, "SET", 3) == 0);
589 continue;
590 }
591 if (strncasecmp (rest, "MACRO", 5) == 0
592 && (rest[5] == ' '
593 || rest[5] == '\t'
594 || is_end_of_line[(unsigned char) rest[5]]))
595 mri_line_macro = 1;
596 }
597
598 /* In MRI mode, we need to handle the MACRO
599 pseudo-op specially: we don't want to put the
600 symbol in the symbol table. */
041ff4dd 601 if (!mri_line_macro
a25c045a 602#ifdef TC_START_LABEL_WITHOUT_COLON
ef99799a
KH
603 && TC_START_LABEL_WITHOUT_COLON(c,
604 input_line_pointer)
a25c045a 605#endif
ef99799a 606 )
252b5132
RH
607 line_label = colon (line_start);
608 else
609 line_label = symbol_create (line_start,
610 absolute_section,
611 (valueT) 0,
612 &zero_address_frag);
613
614 *input_line_pointer = c;
615 if (c == ':')
616 input_line_pointer++;
617 }
618 }
619 }
620
041ff4dd
NC
621 /* We are at the begining of a line, or similar place.
622 We expect a well-formed assembler statement.
623 A "symbol-name:" is a statement.
f0e652b4 624
041ff4dd
NC
625 Depending on what compiler is used, the order of these tests
626 may vary to catch most common case 1st.
627 Each test is independent of all other tests at the (top) level.
628 PLEASE make a compiler that doesn't use this assembler.
629 It is crufty to waste a compiler's time encoding things for this
630 assembler, which then wastes more time decoding it.
631 (And communicating via (linear) files is silly!
632 If you must pass stuff, please pass a tree!) */
252b5132
RH
633 if ((c = *input_line_pointer++) == '\t'
634 || c == ' '
635 || c == '\f'
636 || c == 0)
041ff4dd
NC
637 c = *input_line_pointer++;
638
639 know (c != ' '); /* No further leading whitespace. */
252b5132
RH
640
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)
645 {
646 if ((listing & LISTING_MACEXP) && macro_nest > 0)
647 {
648 char *copy;
649 int len;
650
651 /* Find the end of the current expanded macro line. */
ef99799a 652 for (s = input_line_pointer - 1; *s; ++s)
252b5132
RH
653 if (is_end_of_line[(unsigned char) *s])
654 break;
655
656 /* Copy it for safe keeping. Also give an indication of
657 how much macro nesting is involved at this point. */
ef99799a 658 len = s - (input_line_pointer - 1);
252b5132
RH
659 copy = (char *) xmalloc (len + macro_nest + 2);
660 memset (copy, '>', macro_nest);
661 copy[macro_nest] = ' ';
041ff4dd
NC
662 memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
663 copy[macro_nest + 1 + len] = '\0';
252b5132
RH
664
665 /* Install the line with the listing facility. */
666 listing_newline (copy);
667 }
668 else
669 listing_newline (NULL);
670 }
671#endif
041ff4dd
NC
672 /* C is the 1st significant character.
673 Input_line_pointer points after that character. */
252b5132
RH
674 if (is_name_beginner (c))
675 {
041ff4dd 676 /* Want user-defined label or pseudo/opcode. */
252b5132
RH
677 HANDLE_CONDITIONAL_ASSEMBLY ();
678
679 s = --input_line_pointer;
041ff4dd
NC
680 c = get_symbol_end (); /* name's delimiter. */
681
682 /* C is character after symbol.
683 That character's place in the input line is now '\0'.
684 S points to the beginning of the symbol.
685 [In case of pseudo-op, s->'.'.]
686 Input_line_pointer->'\0' where c was. */
687 if (TC_START_LABEL (c, input_line_pointer))
252b5132
RH
688 {
689 if (flag_m68k_mri)
690 {
691 char *rest = input_line_pointer + 1;
692
693 /* In MRI mode, \tsym: set 0 is permitted. */
252b5132
RH
694 if (*rest == ':')
695 ++rest;
f0e652b4 696
252b5132
RH
697 if (*rest == ' ' || *rest == '\t')
698 ++rest;
f0e652b4 699
252b5132
RH
700 if ((strncasecmp (rest, "EQU", 3) == 0
701 || strncasecmp (rest, "SET", 3) == 0)
702 && (rest[3] == ' ' || rest[3] == '\t'))
703 {
704 input_line_pointer = rest + 3;
705 equals (s, 1);
706 continue;
707 }
708 }
709
041ff4dd
NC
710 line_label = colon (s); /* User-defined label. */
711 /* Put ':' back for error messages' sake. */
712 *input_line_pointer++ = ':';
713 /* Input_line_pointer->after ':'. */
252b5132 714 SKIP_WHITESPACE ();
252b5132
RH
715 }
716 else if (c == '='
717 || ((c == ' ' || c == '\t')
718 && input_line_pointer[1] == '='
719#ifdef TC_EQUAL_IN_INSN
041ff4dd 720 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
252b5132
RH
721#endif
722 ))
723 {
724 equals (s, 1);
725 demand_empty_rest_of_line ();
726 }
727 else
041ff4dd
NC
728 {
729 /* Expect pseudo-op or machine instruction. */
252b5132
RH
730 pop = NULL;
731
252b5132
RH
732#ifdef IGNORE_OPCODE_CASE
733 {
734 char *s2 = s;
37d8bb27
NC
735
736 strncpy (original_case_string, s2, sizeof (original_case_string));
737 original_case_string[sizeof (original_case_string) - 1] = 0;
ef99799a 738
252b5132
RH
739 while (*s2)
740 {
741 if (isupper ((unsigned char) *s2))
742 *s2 = tolower (*s2);
743 s2++;
744 }
745 }
746#endif
abd63a32 747 if (NO_PSEUDO_DOT || flag_m68k_mri)
252b5132
RH
748 {
749 /* The MRI assembler and the m88k use pseudo-ops
750 without a period. */
751 pop = (pseudo_typeS *) hash_find (po_hash, s);
752 if (pop != NULL && pop->poc_handler == NULL)
753 pop = NULL;
754 }
755
756 if (pop != NULL
041ff4dd 757 || (!flag_m68k_mri && *s == '.'))
252b5132 758 {
041ff4dd 759 /* PSEUDO - OP.
f0e652b4 760
041ff4dd
NC
761 WARNING: c has next char, which may be end-of-line.
762 We lookup the pseudo-op table with s+1 because we
763 already know that the pseudo-op begins with a '.'. */
252b5132
RH
764
765 if (pop == NULL)
766 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
767
768 /* In MRI mode, we may need to insert an
769 automatic alignment directive. What a hack
770 this is. */
771 if (mri_pending_align
772 && (pop == NULL
041ff4dd
NC
773 || !((pop->poc_handler == cons
774 && pop->poc_val == 1)
775 || (pop->poc_handler == s_space
776 && pop->poc_val == 1)
252b5132 777#ifdef tc_conditional_pseudoop
041ff4dd 778 || tc_conditional_pseudoop (pop)
252b5132 779#endif
041ff4dd
NC
780 || pop->poc_handler == s_if
781 || pop->poc_handler == s_ifdef
782 || pop->poc_handler == s_ifc
783 || pop->poc_handler == s_ifeqs
784 || pop->poc_handler == s_else
785 || pop->poc_handler == s_endif
786 || pop->poc_handler == s_globl
787 || pop->poc_handler == s_ignore)))
252b5132
RH
788 {
789 do_align (1, (char *) NULL, 0, 0);
790 mri_pending_align = 0;
f0e652b4 791
252b5132
RH
792 if (line_label != NULL)
793 {
2b47531b 794 symbol_set_frag (line_label, frag_now);
252b5132
RH
795 S_SET_VALUE (line_label, frag_now_fix ());
796 }
797 }
798
041ff4dd 799 /* Print the error msg now, while we still can. */
252b5132
RH
800 if (pop == NULL)
801 {
802 as_bad (_("Unknown pseudo-op: `%s'"), s);
803 *input_line_pointer = c;
804 s_ignore (0);
805 continue;
806 }
807
041ff4dd 808 /* Put it back for error messages etc. */
252b5132
RH
809 *input_line_pointer = c;
810 /* The following skip of whitespace is compulsory.
811 A well shaped space is sometimes all that separates
041ff4dd 812 keyword from operands. */
252b5132
RH
813 if (c == ' ' || c == '\t')
814 input_line_pointer++;
041ff4dd
NC
815
816 /* Input_line is restored.
817 Input_line_pointer->1st non-blank char
818 after pseudo-operation. */
252b5132
RH
819 (*pop->poc_handler) (pop->poc_val);
820
821 /* If that was .end, just get out now. */
822 if (pop->poc_handler == s_end)
823 goto quit;
824 }
825 else
826 {
1bf67e0d
ILT
827 int inquote = 0;
828#ifdef QUOTES_IN_INSN
829 int inescape = 0;
830#endif
252b5132 831
041ff4dd
NC
832 /* WARNING: c has char, which may be end-of-line. */
833 /* Also: input_line_pointer->`\0` where c was. */
252b5132
RH
834 *input_line_pointer = c;
835 while (!is_end_of_line[(unsigned char) *input_line_pointer]
836 || inquote
837#ifdef TC_EOL_IN_INSN
838 || TC_EOL_IN_INSN (input_line_pointer)
839#endif
840 )
841 {
842 if (flag_m68k_mri && *input_line_pointer == '\'')
041ff4dd 843 inquote = !inquote;
1c32af22
RH
844#ifdef QUOTES_IN_INSN
845 if (inescape)
846 inescape = 0;
847 else if (*input_line_pointer == '"')
041ff4dd 848 inquote = !inquote;
1c32af22
RH
849 else if (*input_line_pointer == '\\')
850 inescape = 1;
851#endif
252b5132
RH
852 input_line_pointer++;
853 }
854
855 c = *input_line_pointer;
856 *input_line_pointer = '\0';
857
858 generate_lineno_debug ();
859
860 if (macro_defined)
861 {
862 sb out;
863 const char *err;
041ff4dd 864 macro_entry *macro;
252b5132 865
9f10757c 866 if (check_macro (s, &out, '\0', &err, &macro))
252b5132
RH
867 {
868 if (err != NULL)
4c63da97 869 as_bad ("%s", err);
252b5132
RH
870 *input_line_pointer++ = c;
871 input_scrub_include_sb (&out,
9f10757c 872 input_line_pointer, 1);
252b5132
RH
873 sb_kill (&out);
874 buffer_limit =
875 input_scrub_next_buffer (&input_line_pointer);
9f10757c 876#ifdef md_macro_info
041ff4dd 877 md_macro_info (macro);
9f10757c 878#endif
252b5132
RH
879 continue;
880 }
881 }
882
883 if (mri_pending_align)
884 {
885 do_align (1, (char *) NULL, 0, 0);
886 mri_pending_align = 0;
887 if (line_label != NULL)
888 {
2b47531b 889 symbol_set_frag (line_label, frag_now);
252b5132
RH
890 S_SET_VALUE (line_label, frag_now_fix ());
891 }
892 }
893
041ff4dd 894 md_assemble (s); /* Assemble 1 instruction. */
252b5132
RH
895
896 *input_line_pointer++ = c;
897
898 /* We resume loop AFTER the end-of-line from
041ff4dd
NC
899 this instruction. */
900 }
901 }
252b5132 902 continue;
041ff4dd 903 }
252b5132
RH
904
905 /* Empty statement? */
906 if (is_end_of_line[(unsigned char) c])
907 continue;
908
909 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
910 && isdigit ((unsigned char) c))
911 {
041ff4dd 912 /* local label ("4:") */
252b5132
RH
913 char *backup = input_line_pointer;
914
915 HANDLE_CONDITIONAL_ASSEMBLY ();
916
917 temp = c - '0';
918
041ff4dd 919 /* Read the whole number. */
252b5132
RH
920 while (isdigit ((unsigned char) *input_line_pointer))
921 {
922 temp = (temp * 10) + *input_line_pointer - '0';
923 ++input_line_pointer;
041ff4dd 924 }
252b5132
RH
925
926 if (LOCAL_LABELS_DOLLAR
927 && *input_line_pointer == '$'
928 && *(input_line_pointer + 1) == ':')
929 {
930 input_line_pointer += 2;
931
932 if (dollar_label_defined (temp))
933 {
934 as_fatal (_("label \"%d$\" redefined"), temp);
935 }
936
937 define_dollar_label (temp);
938 colon (dollar_label_name (temp, 0));
939 continue;
940 }
941
942 if (LOCAL_LABELS_FB
943 && *input_line_pointer++ == ':')
944 {
945 fb_label_instance_inc (temp);
946 colon (fb_label_name (temp, 0));
947 continue;
948 }
949
950 input_line_pointer = backup;
951 } /* local label ("4:") */
952
953 if (c && strchr (line_comment_chars, c))
041ff4dd 954 { /* Its a comment. Better say APP or NO_APP. */
252b5132
RH
955 char *ends;
956 char *new_buf;
957 char *new_tmp;
958 unsigned int new_length;
959 char *tmp_buf = 0;
960
961 bump_line_counters ();
962 s = input_line_pointer;
963 if (strncmp (s, "APP\n", 4))
964 continue; /* We ignore it */
965 s += 4;
966
967 ends = strstr (s, "#NO_APP\n");
968
969 if (!ends)
970 {
971 unsigned int tmp_len;
972 unsigned int num;
973
974 /* The end of the #APP wasn't in this buffer. We
975 keep reading in buffers until we find the #NO_APP
976 that goes with this #APP There is one. The specs
041ff4dd 977 guarentee it... */
252b5132
RH
978 tmp_len = buffer_limit - s;
979 tmp_buf = xmalloc (tmp_len + 1);
980 memcpy (tmp_buf, s, tmp_len);
981 do
982 {
983 new_tmp = input_scrub_next_buffer (&buffer);
984 if (!new_tmp)
985 break;
986 else
987 buffer_limit = new_tmp;
988 input_line_pointer = buffer;
989 ends = strstr (buffer, "#NO_APP\n");
990 if (ends)
991 num = ends - buffer;
992 else
993 num = buffer_limit - buffer;
994
995 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
996 memcpy (tmp_buf + tmp_len, buffer, num);
997 tmp_len += num;
998 }
999 while (!ends);
1000
1001 input_line_pointer = ends ? ends + 8 : NULL;
1002
1003 s = tmp_buf;
1004 ends = s + tmp_len;
1005
1006 }
1007 else
1008 {
1009 input_line_pointer = ends + 8;
1010 }
1011
1012 scrub_string = s;
1013 scrub_string_end = ends;
1014
1015 new_length = ends - s;
1016 new_buf = (char *) xmalloc (new_length);
1017 new_tmp = new_buf;
1018 for (;;)
1019 {
1020 int space;
1021 int size;
1022
1023 space = (new_buf + new_length) - new_tmp;
1024 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1025
1026 if (size < space)
1027 {
1028 new_tmp += size;
1029 break;
1030 }
1031
1032 new_buf = xrealloc (new_buf, new_length + 100);
1033 new_tmp = new_buf + new_length;
1034 new_length += 100;
1035 }
1036
1037 if (tmp_buf)
1038 free (tmp_buf);
1039 old_buffer = buffer;
1040 old_input = input_line_pointer;
1041 old_limit = buffer_limit;
1042 buffer = new_buf;
1043 input_line_pointer = new_buf;
1044 buffer_limit = new_tmp;
f0e652b4 1045
252b5132
RH
1046 continue;
1047 }
1048
1049 HANDLE_CONDITIONAL_ASSEMBLY ();
1050
1051#ifdef tc_unrecognized_line
1052 if (tc_unrecognized_line (c))
1053 continue;
1054#endif
041ff4dd
NC
1055 /* as_warn (_("Junk character %d."),c); Now done by ignore_rest. */
1056 input_line_pointer--; /* Report unknown char as ignored. */
252b5132 1057 ignore_rest_of_line ();
041ff4dd 1058 }
252b5132
RH
1059
1060#ifdef md_after_pass_hook
1061 md_after_pass_hook ();
1062#endif
1063
1064 if (old_buffer)
1065 {
1066 free (buffer);
1067 bump_line_counters ();
1068 if (old_input != 0)
1069 {
1070 buffer = old_buffer;
1071 input_line_pointer = old_input;
1072 buffer_limit = old_limit;
1073 old_buffer = 0;
1074 goto contin;
1075 }
1076 }
041ff4dd 1077 }
252b5132
RH
1078
1079 quit:
1080
1081#ifdef md_cleanup
041ff4dd 1082 md_cleanup ();
252b5132 1083#endif
041ff4dd
NC
1084 /* Close the input file. */
1085 input_scrub_close ();
4c400d5e
AM
1086#ifdef WARN_COMMENTS
1087 {
1088 if (warn_comment && found_comment)
1089 as_warn_where (found_comment_file, found_comment,
1090 "first comment found here");
1091 }
1092#endif
252b5132
RH
1093}
1094
1095/* For most MRI pseudo-ops, the line actually ends at the first
1096 nonquoted space. This function looks for that point, stuffs a null
1097 in, and sets *STOPCP to the character that used to be there, and
1098 returns the location.
1099
1100 Until I hear otherwise, I am going to assume that this is only true
1101 for the m68k MRI assembler. */
1102
1103char *
1104mri_comment_field (stopcp)
1105 char *stopcp;
1106{
252b5132 1107 char *s;
041ff4dd 1108#ifdef TC_M68K
252b5132
RH
1109 int inquote = 0;
1110
1111 know (flag_m68k_mri);
1112
1113 for (s = input_line_pointer;
041ff4dd 1114 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
252b5132
RH
1115 || inquote);
1116 s++)
1117 {
1118 if (*s == '\'')
041ff4dd 1119 inquote = !inquote;
252b5132 1120 }
252b5132 1121#else
041ff4dd
NC
1122 for (s = input_line_pointer;
1123 !is_end_of_line[(unsigned char) *s];
1124 s++)
252b5132 1125 ;
041ff4dd 1126#endif
252b5132
RH
1127 *stopcp = *s;
1128 *s = '\0';
f0e652b4 1129
252b5132 1130 return s;
252b5132
RH
1131}
1132
1133/* Skip to the end of an MRI comment field. */
1134
1135void
1136mri_comment_end (stop, stopc)
1137 char *stop;
1138 int stopc;
1139{
1140 know (flag_mri);
1141
1142 input_line_pointer = stop;
1143 *stop = stopc;
041ff4dd 1144 while (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
1145 ++input_line_pointer;
1146}
1147
041ff4dd 1148void
252b5132 1149s_abort (ignore)
ab9da554 1150 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1151{
1152 as_fatal (_(".abort detected. Abandoning ship."));
1153}
1154
1155/* Guts of .align directive. N is the power of two to which to align.
1156 FILL may be NULL, or it may point to the bytes of the fill pattern.
1157 LEN is the length of whatever FILL points to, if anything. MAX is
1158 the maximum number of characters to skip when doing the alignment,
1159 or 0 if there is no maximum. */
1160
041ff4dd 1161static void
252b5132
RH
1162do_align (n, fill, len, max)
1163 int n;
1164 char *fill;
1165 int len;
1166 int max;
1167{
252b5132
RH
1168#ifdef md_do_align
1169 md_do_align (n, fill, len, max, just_record_alignment);
1170#endif
1171
041ff4dd 1172 /* Only make a frag if we HAVE to... */
252b5132
RH
1173 if (n != 0 && !need_pass_2)
1174 {
0a9ef439
RH
1175 if (fill == NULL)
1176 {
1177 if (subseg_text_p (now_seg))
1178 frag_align_code (n, max);
1179 else
1180 frag_align (n, 0, max);
1181 }
1182 else if (len <= 1)
252b5132
RH
1183 frag_align (n, *fill, max);
1184 else
1185 frag_align_pattern (n, fill, len, max);
1186 }
1187
1188#ifdef md_do_align
1189 just_record_alignment:
1190#endif
1191
bea9907b 1192 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
252b5132
RH
1193}
1194
1195/* Handle the .align pseudo-op. A positive ARG is a default alignment
1196 (in bytes). A negative ARG is the negative of the length of the
1197 fill pattern. BYTES_P is non-zero if the alignment value should be
1198 interpreted as the byte boundary, rather than the power of 2. */
1199
1200static void
1201s_align (arg, bytes_p)
1202 int arg;
1203 int bytes_p;
1204{
1205 register unsigned int align;
1206 char *stop = NULL;
1207 char stopc;
1208 offsetT fill = 0;
1209 int max;
1210 int fill_p;
1211
1212 if (flag_mri)
1213 stop = mri_comment_field (&stopc);
1214
1215 if (is_end_of_line[(unsigned char) *input_line_pointer])
1216 {
1217 if (arg < 0)
1218 align = 0;
1219 else
041ff4dd 1220 align = arg; /* Default value from pseudo-op table. */
252b5132
RH
1221 }
1222 else
1223 {
1224 align = get_absolute_expression ();
1225 SKIP_WHITESPACE ();
1226 }
1227
1228 if (bytes_p)
1229 {
1230 /* Convert to a power of 2. */
1231 if (align != 0)
1232 {
1233 unsigned int i;
1234
1235 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1236 ;
1237 if (align != 1)
1238 as_bad (_("Alignment not a power of 2"));
f0e652b4 1239
252b5132
RH
1240 align = i;
1241 }
1242 }
1243
1244 if (align > 15)
1245 {
1246 align = 15;
1247 as_bad (_("Alignment too large: %u assumed"), align);
1248 }
1249
1250 if (*input_line_pointer != ',')
1251 {
1252 fill_p = 0;
1253 max = 0;
1254 }
1255 else
1256 {
1257 ++input_line_pointer;
1258 if (*input_line_pointer == ',')
1259 fill_p = 0;
1260 else
1261 {
1262 fill = get_absolute_expression ();
1263 SKIP_WHITESPACE ();
1264 fill_p = 1;
1265 }
1266
1267 if (*input_line_pointer != ',')
1268 max = 0;
1269 else
1270 {
1271 ++input_line_pointer;
1272 max = get_absolute_expression ();
1273 }
1274 }
1275
041ff4dd 1276 if (!fill_p)
252b5132
RH
1277 {
1278 if (arg < 0)
1279 as_warn (_("expected fill pattern missing"));
1280 do_align (align, (char *) NULL, 0, max);
1281 }
1282 else
1283 {
1284 int fill_len;
1285
1286 if (arg >= 0)
1287 fill_len = 1;
1288 else
041ff4dd 1289 fill_len = -arg;
252b5132
RH
1290 if (fill_len <= 1)
1291 {
1292 char fill_char;
1293
1294 fill_char = fill;
1295 do_align (align, &fill_char, fill_len, max);
1296 }
1297 else
1298 {
1299 char ab[16];
1300
1301 if ((size_t) fill_len > sizeof ab)
1302 abort ();
1303 md_number_to_chars (ab, fill, fill_len);
1304 do_align (align, ab, fill_len, max);
1305 }
1306 }
1307
1308 demand_empty_rest_of_line ();
1309
1310 if (flag_mri)
1311 mri_comment_end (stop, stopc);
1312}
1313
1314/* Handle the .align pseudo-op on machines where ".align 4" means
1315 align to a 4 byte boundary. */
1316
041ff4dd 1317void
252b5132
RH
1318s_align_bytes (arg)
1319 int arg;
1320{
1321 s_align (arg, 1);
1322}
1323
1324/* Handle the .align pseudo-op on machines where ".align 4" means align
1325 to a 2**4 boundary. */
1326
041ff4dd 1327void
252b5132
RH
1328s_align_ptwo (arg)
1329 int arg;
1330{
1331 s_align (arg, 0);
1332}
1333
041ff4dd 1334void
252b5132 1335s_comm (ignore)
ab9da554 1336 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1337{
1338 register char *name;
1339 register char c;
1340 register char *p;
1341 offsetT temp;
1342 register symbolS *symbolP;
1343 char *stop = NULL;
1344 char stopc;
1345
1346 if (flag_mri)
1347 stop = mri_comment_field (&stopc);
1348
1349 name = input_line_pointer;
1350 c = get_symbol_end ();
041ff4dd 1351 /* Just after name is now '\0'. */
252b5132
RH
1352 p = input_line_pointer;
1353 *p = c;
1354 SKIP_WHITESPACE ();
f0e652b4 1355
252b5132
RH
1356 if (*input_line_pointer != ',')
1357 {
1358 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1359 ignore_rest_of_line ();
1360 if (flag_mri)
1361 mri_comment_end (stop, stopc);
1362 return;
1363 }
f0e652b4 1364
252b5132 1365 input_line_pointer++; /* skip ',' */
f0e652b4 1366
252b5132
RH
1367 if ((temp = get_absolute_expression ()) < 0)
1368 {
1369 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1370 ignore_rest_of_line ();
1371 if (flag_mri)
1372 mri_comment_end (stop, stopc);
1373 return;
1374 }
f0e652b4 1375
252b5132
RH
1376 *p = 0;
1377 symbolP = symbol_find_or_make (name);
1378 *p = c;
f0e652b4 1379
041ff4dd 1380 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
252b5132
RH
1381 {
1382 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1383 S_GET_NAME (symbolP));
1384 ignore_rest_of_line ();
1385 if (flag_mri)
1386 mri_comment_end (stop, stopc);
1387 return;
1388 }
f0e652b4 1389
252b5132
RH
1390 if (S_GET_VALUE (symbolP))
1391 {
1392 if (S_GET_VALUE (symbolP) != (valueT) temp)
1393 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1394 S_GET_NAME (symbolP),
1395 (long) S_GET_VALUE (symbolP),
1396 (long) temp);
1397 }
1398 else
1399 {
1400 S_SET_VALUE (symbolP, (valueT) temp);
1401 S_SET_EXTERNAL (symbolP);
1402 }
1403#ifdef OBJ_VMS
1404 {
1405 extern int flag_one;
041ff4dd 1406 if (!temp || !flag_one)
252b5132
RH
1407 S_GET_OTHER(symbolP) = const_flag;
1408 }
1409#endif /* not OBJ_VMS */
1410 know (symbolP->sy_frag == &zero_address_frag);
1411
1412 demand_empty_rest_of_line ();
1413
1414 if (flag_mri)
1415 mri_comment_end (stop, stopc);
1416} /* s_comm() */
1417
1418/* The MRI COMMON pseudo-op. We handle this by creating a common
1419 symbol with the appropriate name. We make s_space do the right
1420 thing by increasing the size. */
1421
1422void
1423s_mri_common (small)
ab9da554 1424 int small ATTRIBUTE_UNUSED;
252b5132
RH
1425{
1426 char *name;
1427 char c;
1428 char *alc = NULL;
1429 symbolS *sym;
1430 offsetT align;
1431 char *stop = NULL;
1432 char stopc;
1433
041ff4dd 1434 if (!flag_mri)
252b5132
RH
1435 {
1436 s_comm (0);
1437 return;
1438 }
1439
1440 stop = mri_comment_field (&stopc);
1441
1442 SKIP_WHITESPACE ();
1443
1444 name = input_line_pointer;
041ff4dd 1445 if (!isdigit ((unsigned char) *name))
252b5132
RH
1446 c = get_symbol_end ();
1447 else
1448 {
1449 do
1450 {
1451 ++input_line_pointer;
1452 }
1453 while (isdigit ((unsigned char) *input_line_pointer));
f0e652b4 1454
252b5132
RH
1455 c = *input_line_pointer;
1456 *input_line_pointer = '\0';
1457
1458 if (line_label != NULL)
1459 {
1460 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1461 + (input_line_pointer - name)
1462 + 1);
1463 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1464 name = alc;
1465 }
1466 }
1467
1468 sym = symbol_find_or_make (name);
1469 *input_line_pointer = c;
1470 if (alc != NULL)
1471 free (alc);
1472
1473 if (*input_line_pointer != ',')
1474 align = 0;
1475 else
1476 {
1477 ++input_line_pointer;
1478 align = get_absolute_expression ();
1479 }
1480
041ff4dd 1481 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
252b5132
RH
1482 {
1483 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1484 ignore_rest_of_line ();
1485 mri_comment_end (stop, stopc);
1486 return;
1487 }
1488
1489 S_SET_EXTERNAL (sym);
1490 mri_common_symbol = sym;
1491
1492#ifdef S_SET_ALIGN
1493 if (align != 0)
1494 S_SET_ALIGN (sym, align);
1495#endif
1496
1497 if (line_label != NULL)
1498 {
2b47531b
ILT
1499 expressionS exp;
1500 exp.X_op = O_symbol;
1501 exp.X_add_symbol = sym;
1502 exp.X_add_number = 0;
1503 symbol_set_value_expression (line_label, &exp);
1504 symbol_set_frag (line_label, &zero_address_frag);
252b5132
RH
1505 S_SET_SEGMENT (line_label, expr_section);
1506 }
1507
1508 /* FIXME: We just ignore the small argument, which distinguishes
1509 COMMON and COMMON.S. I don't know what we can do about it. */
1510
1511 /* Ignore the type and hptype. */
1512 if (*input_line_pointer == ',')
1513 input_line_pointer += 2;
1514 if (*input_line_pointer == ',')
1515 input_line_pointer += 2;
1516
1517 demand_empty_rest_of_line ();
1518
1519 mri_comment_end (stop, stopc);
1520}
1521
1522void
1523s_data (ignore)
ab9da554 1524 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1525{
1526 segT section;
1527 register int temp;
1528
1529 temp = get_absolute_expression ();
1530 if (flag_readonly_data_in_text)
1531 {
1532 section = text_section;
1533 temp += 1000;
1534 }
1535 else
1536 section = data_section;
1537
1538 subseg_set (section, (subsegT) temp);
1539
1540#ifdef OBJ_VMS
1541 const_flag = 0;
1542#endif
1543 demand_empty_rest_of_line ();
1544}
1545
1546/* Handle the .appfile pseudo-op. This is automatically generated by
1547 do_scrub_chars when a preprocessor # line comment is seen with a
1548 file name. This default definition may be overridden by the object
1549 or CPU specific pseudo-ops. This function is also the default
1550 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1551 .file. */
1552
041ff4dd 1553void
252b5132
RH
1554s_app_file (appfile)
1555 int appfile;
1556{
1557 register char *s;
1558 int length;
1559
041ff4dd 1560 /* Some assemblers tolerate immediately following '"'. */
252b5132
RH
1561 if ((s = demand_copy_string (&length)) != 0)
1562 {
1563 /* If this is a fake .appfile, a fake newline was inserted into
1564 the buffer. Passing -2 to new_logical_line tells it to
1565 account for it. */
1566 int may_omit
041ff4dd 1567 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
252b5132
RH
1568
1569 /* In MRI mode, the preprocessor may have inserted an extraneous
1570 backquote. */
1571 if (flag_m68k_mri
1572 && *input_line_pointer == '\''
1573 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1574 ++input_line_pointer;
1575
1576 demand_empty_rest_of_line ();
041ff4dd 1577 if (!may_omit)
252b5132
RH
1578 {
1579#ifdef LISTING
1580 if (listing)
1581 listing_source_file (s);
1582#endif
1583 register_dependency (s);
1584#ifdef obj_app_file
1585 obj_app_file (s);
1586#endif
1587 }
1588 }
1589}
1590
1591/* Handle the .appline pseudo-op. This is automatically generated by
1592 do_scrub_chars when a preprocessor # line comment is seen. This
1593 default definition may be overridden by the object or CPU specific
1594 pseudo-ops. */
1595
1596void
1597s_app_line (ignore)
ab9da554 1598 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1599{
1600 int l;
1601
1602 /* The given number is that of the next line. */
1603 l = get_absolute_expression () - 1;
1604 if (l < 0)
1605 /* Some of the back ends can't deal with non-positive line numbers.
1606 Besides, it's silly. */
041ff4dd
NC
1607 as_warn (_("Line numbers must be positive; line number %d rejected."),
1608 l + 1);
252b5132
RH
1609 else
1610 {
1611 new_logical_line ((char *) NULL, l);
1612#ifdef LISTING
1613 if (listing)
1614 listing_source_line (l);
1615#endif
1616 }
1617 demand_empty_rest_of_line ();
1618}
1619
1620/* Handle the .end pseudo-op. Actually, the real work is done in
1621 read_a_source_file. */
1622
1623void
1624s_end (ignore)
ab9da554 1625 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1626{
1627 if (flag_mri)
1628 {
1629 /* The MRI assembler permits the start symbol to follow .end,
1630 but we don't support that. */
1631 SKIP_WHITESPACE ();
041ff4dd 1632 if (!is_end_of_line[(unsigned char) *input_line_pointer]
252b5132
RH
1633 && *input_line_pointer != '*'
1634 && *input_line_pointer != '!')
1635 as_warn (_("start address not supported"));
1636 }
1637}
1638
1639/* Handle the .err pseudo-op. */
1640
1641void
1642s_err (ignore)
ab9da554 1643 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1644{
1645 as_bad (_(".err encountered"));
1646 demand_empty_rest_of_line ();
1647}
1648
1649/* Handle the MRI fail pseudo-op. */
1650
1651void
1652s_fail (ignore)
ab9da554 1653 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1654{
1655 offsetT temp;
1656 char *stop = NULL;
1657 char stopc;
1658
1659 if (flag_mri)
1660 stop = mri_comment_field (&stopc);
1661
1662 temp = get_absolute_expression ();
1663 if (temp >= 500)
1664 as_warn (_(".fail %ld encountered"), (long) temp);
1665 else
1666 as_bad (_(".fail %ld encountered"), (long) temp);
1667
1668 demand_empty_rest_of_line ();
1669
1670 if (flag_mri)
1671 mri_comment_end (stop, stopc);
1672}
1673
041ff4dd 1674void
252b5132 1675s_fill (ignore)
ab9da554 1676 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1677{
1678 expressionS rep_exp;
1679 long size = 1;
1680 register long fill = 0;
1681 char *p;
1682
1683#ifdef md_flush_pending_output
1684 md_flush_pending_output ();
1685#endif
1686
1687 get_known_segmented_expression (&rep_exp);
1688 if (*input_line_pointer == ',')
1689 {
1690 input_line_pointer++;
1691 size = get_absolute_expression ();
1692 if (*input_line_pointer == ',')
1693 {
1694 input_line_pointer++;
1695 fill = get_absolute_expression ();
1696 }
1697 }
1698
1699 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1700#define BSD_FILL_SIZE_CROCK_8 (8)
1701 if (size > BSD_FILL_SIZE_CROCK_8)
1702 {
1703 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1704 size = BSD_FILL_SIZE_CROCK_8;
1705 }
1706 if (size < 0)
1707 {
1708 as_warn (_("Size negative: .fill ignored."));
1709 size = 0;
1710 }
1711 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1712 {
1713 if (rep_exp.X_add_number < 0)
1714 as_warn (_("Repeat < 0, .fill ignored"));
1715 size = 0;
1716 }
1717
1718 if (size && !need_pass_2)
1719 {
1720 if (rep_exp.X_op == O_constant)
1721 {
1722 p = frag_var (rs_fill, (int) size, (int) size,
1723 (relax_substateT) 0, (symbolS *) 0,
1724 (offsetT) rep_exp.X_add_number,
1725 (char *) 0);
1726 }
1727 else
1728 {
1729 /* We don't have a constant repeat count, so we can't use
1730 rs_fill. We can get the same results out of rs_space,
1731 but its argument is in bytes, so we must multiply the
1732 repeat count by size. */
1733
1734 symbolS *rep_sym;
1735 rep_sym = make_expr_symbol (&rep_exp);
1736 if (size != 1)
1737 {
1738 expressionS size_exp;
1739 size_exp.X_op = O_constant;
1740 size_exp.X_add_number = size;
1741
1742 rep_exp.X_op = O_multiply;
1743 rep_exp.X_add_symbol = rep_sym;
1744 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1745 rep_exp.X_add_number = 0;
1746 rep_sym = make_expr_symbol (&rep_exp);
1747 }
1748
1749 p = frag_var (rs_space, (int) size, (int) size,
1750 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1751 }
f0e652b4 1752
252b5132 1753 memset (p, 0, (unsigned int) size);
f0e652b4 1754
252b5132 1755 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
041ff4dd
NC
1756 flavoured AS. The following bizzare behaviour is to be
1757 compatible with above. I guess they tried to take up to 8
1758 bytes from a 4-byte expression and they forgot to sign
1759 extend. Un*x Sux. */
252b5132
RH
1760#define BSD_FILL_SIZE_CROCK_4 (4)
1761 md_number_to_chars (p, (valueT) fill,
1762 (size > BSD_FILL_SIZE_CROCK_4
1763 ? BSD_FILL_SIZE_CROCK_4
1764 : (int) size));
1765 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
041ff4dd
NC
1766 but emits no error message because it seems a legal thing to do.
1767 It is a degenerate case of .fill but could be emitted by a
1768 compiler. */
252b5132
RH
1769 }
1770 demand_empty_rest_of_line ();
1771}
1772
041ff4dd 1773void
252b5132 1774s_globl (ignore)
ab9da554 1775 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1776{
1777 char *name;
1778 int c;
1779 symbolS *symbolP;
1780 char *stop = NULL;
1781 char stopc;
1782
1783 if (flag_mri)
1784 stop = mri_comment_field (&stopc);
1785
1786 do
1787 {
1788 name = input_line_pointer;
1789 c = get_symbol_end ();
1790 symbolP = symbol_find_or_make (name);
58b5739a
RH
1791 S_SET_EXTERNAL (symbolP);
1792
252b5132
RH
1793 *input_line_pointer = c;
1794 SKIP_WHITESPACE ();
58b5739a 1795 c = *input_line_pointer;
252b5132
RH
1796 if (c == ',')
1797 {
1798 input_line_pointer++;
1799 SKIP_WHITESPACE ();
1800 if (*input_line_pointer == '\n')
1801 c = '\n';
1802 }
1803 }
1804 while (c == ',');
1805
1806 demand_empty_rest_of_line ();
1807
1808 if (flag_mri)
1809 mri_comment_end (stop, stopc);
1810}
1811
1812/* Handle the MRI IRP and IRPC pseudo-ops. */
1813
1814void
1815s_irp (irpc)
1816 int irpc;
1817{
1818 char *file;
1819 unsigned int line;
1820 sb s;
1821 const char *err;
1822 sb out;
1823
1824 as_where (&file, &line);
1825
1826 sb_new (&s);
041ff4dd 1827 while (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
1828 sb_add_char (&s, *input_line_pointer++);
1829
1830 sb_new (&out);
1831
1832 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1833 if (err != NULL)
1834 as_bad_where (file, line, "%s", err);
1835
1836 sb_kill (&s);
1837
9f10757c 1838 input_scrub_include_sb (&out, input_line_pointer, 1);
252b5132
RH
1839 sb_kill (&out);
1840 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1841}
1842
1843/* Handle the .linkonce pseudo-op. This tells the assembler to mark
1844 the section to only be linked once. However, this is not supported
1845 by most object file formats. This takes an optional argument,
1846 which is what to do about duplicates. */
1847
1848void
1849s_linkonce (ignore)
ab9da554 1850 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
1851{
1852 enum linkonce_type type;
1853
1854 SKIP_WHITESPACE ();
1855
1856 type = LINKONCE_DISCARD;
1857
041ff4dd 1858 if (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
1859 {
1860 char *s;
1861 char c;
1862
1863 s = input_line_pointer;
1864 c = get_symbol_end ();
1865 if (strcasecmp (s, "discard") == 0)
1866 type = LINKONCE_DISCARD;
1867 else if (strcasecmp (s, "one_only") == 0)
1868 type = LINKONCE_ONE_ONLY;
1869 else if (strcasecmp (s, "same_size") == 0)
1870 type = LINKONCE_SAME_SIZE;
1871 else if (strcasecmp (s, "same_contents") == 0)
1872 type = LINKONCE_SAME_CONTENTS;
1873 else
1874 as_warn (_("unrecognized .linkonce type `%s'"), s);
1875
1876 *input_line_pointer = c;
1877 }
1878
1879#ifdef obj_handle_link_once
1880 obj_handle_link_once (type);
1881#else /* ! defined (obj_handle_link_once) */
1882#ifdef BFD_ASSEMBLER
1883 {
1884 flagword flags;
1885
1886 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1887 as_warn (_(".linkonce is not supported for this object file format"));
1888
1889 flags = bfd_get_section_flags (stdoutput, now_seg);
1890 flags |= SEC_LINK_ONCE;
1891 switch (type)
1892 {
1893 default:
1894 abort ();
1895 case LINKONCE_DISCARD:
1896 flags |= SEC_LINK_DUPLICATES_DISCARD;
1897 break;
1898 case LINKONCE_ONE_ONLY:
1899 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1900 break;
1901 case LINKONCE_SAME_SIZE:
1902 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1903 break;
1904 case LINKONCE_SAME_CONTENTS:
1905 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1906 break;
1907 }
041ff4dd 1908 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
252b5132
RH
1909 as_bad (_("bfd_set_section_flags: %s"),
1910 bfd_errmsg (bfd_get_error ()));
1911 }
1912#else /* ! defined (BFD_ASSEMBLER) */
1913 as_warn (_(".linkonce is not supported for this object file format"));
1914#endif /* ! defined (BFD_ASSEMBLER) */
1915#endif /* ! defined (obj_handle_link_once) */
1916
1917 demand_empty_rest_of_line ();
1918}
1919
041ff4dd 1920static void
252b5132
RH
1921s_lcomm_internal (needs_align, bytes_p)
1922 /* 1 if this was a ".bss" directive, which may require a 3rd argument
041ff4dd 1923 (alignment); 0 if it was an ".lcomm" (2 args only). */
252b5132
RH
1924 int needs_align;
1925 /* 1 if the alignment value should be interpreted as the byte boundary,
041ff4dd 1926 rather than the power of 2. */
252b5132
RH
1927 int bytes_p;
1928{
1929 register char *name;
1930 register char c;
1931 register char *p;
1932 register int temp;
1933 register symbolS *symbolP;
1934 segT current_seg = now_seg;
1935 subsegT current_subseg = now_subseg;
1936 const int max_alignment = 15;
1937 int align = 0;
1938 segT bss_seg = bss_section;
1939
1940 name = input_line_pointer;
1941 c = get_symbol_end ();
1942 p = input_line_pointer;
1943 *p = c;
1944 SKIP_WHITESPACE ();
1945
1946 /* Accept an optional comma after the name. The comma used to be
1947 required, but Irix 5 cc does not generate it. */
1948 if (*input_line_pointer == ',')
1949 {
1950 ++input_line_pointer;
1951 SKIP_WHITESPACE ();
1952 }
1953
1954 if (*input_line_pointer == '\n')
1955 {
1956 as_bad (_("Missing size expression"));
1957 return;
1958 }
1959
1960 if ((temp = get_absolute_expression ()) < 0)
1961 {
1962 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1963 ignore_rest_of_line ();
1964 return;
1965 }
1966
1967#if defined (TC_MIPS) || defined (TC_ALPHA)
1968 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1969 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1970 {
1971 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1972 if (temp <= bfd_get_gp_size (stdoutput))
1973 {
1974 bss_seg = subseg_new (".sbss", 1);
1975 seg_info (bss_seg)->bss = 1;
1976#ifdef BFD_ASSEMBLER
041ff4dd 1977 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
252b5132
RH
1978 as_warn (_("error setting flags for \".sbss\": %s"),
1979 bfd_errmsg (bfd_get_error ()));
1980#endif
1981 }
1982 }
1983#endif
8684e216 1984
041ff4dd
NC
1985 if (!needs_align)
1986 {
1987 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
252b5132 1988
041ff4dd
NC
1989 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
1990 if (align)
1991 record_alignment (bss_seg, align);
1992 }
252b5132
RH
1993
1994 if (needs_align)
1995 {
1996 align = 0;
1997 SKIP_WHITESPACE ();
f0e652b4 1998
252b5132
RH
1999 if (*input_line_pointer != ',')
2000 {
2001 as_bad (_("Expected comma after size"));
2002 ignore_rest_of_line ();
2003 return;
2004 }
f0e652b4 2005
252b5132
RH
2006 input_line_pointer++;
2007 SKIP_WHITESPACE ();
f0e652b4 2008
252b5132
RH
2009 if (*input_line_pointer == '\n')
2010 {
2011 as_bad (_("Missing alignment"));
2012 return;
2013 }
f0e652b4 2014
252b5132 2015 align = get_absolute_expression ();
f0e652b4 2016
252b5132
RH
2017 if (bytes_p)
2018 {
2019 /* Convert to a power of 2. */
2020 if (align != 0)
2021 {
2022 unsigned int i;
2023
2024 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2025 ;
2026 if (align != 1)
2027 as_bad (_("Alignment not a power of 2"));
2028 align = i;
2029 }
2030 }
f0e652b4 2031
252b5132
RH
2032 if (align > max_alignment)
2033 {
2034 align = max_alignment;
2035 as_warn (_("Alignment too large: %d. assumed."), align);
2036 }
2037 else if (align < 0)
2038 {
2039 align = 0;
2040 as_warn (_("Alignment negative. 0 assumed."));
2041 }
f0e652b4 2042
252b5132 2043 record_alignment (bss_seg, align);
041ff4dd 2044 }
252b5132
RH
2045 else
2046 {
2047 /* Assume some objects may require alignment on some systems. */
2048#if defined (TC_ALPHA) && ! defined (VMS)
2049 if (temp > 1)
2050 {
2051 align = ffs (temp) - 1;
2052 if (temp % (1 << align))
2053 abort ();
2054 }
2055#endif
2056 }
2057
2058 *p = 0;
2059 symbolP = symbol_find_or_make (name);
2060 *p = c;
2061
2062 if (
4c63da97
AM
2063#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2064 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2065#ifdef BFD_ASSEMBLER
2066 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2067 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2068#else
2069 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2070#endif
2071#endif
2072 (S_GET_SEGMENT (symbolP) == bss_seg
2073 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
252b5132
RH
2074 {
2075 char *pfrag;
2076
2077 subseg_set (bss_seg, 1);
2078
2079 if (align)
2080 frag_align (align, 0, 0);
f0e652b4 2081
ef99799a 2082 /* Detach from old frag. */
252b5132 2083 if (S_GET_SEGMENT (symbolP) == bss_seg)
2b47531b 2084 symbol_get_frag (symbolP)->fr_symbol = NULL;
252b5132 2085
2b47531b 2086 symbol_set_frag (symbolP, frag_now);
041ff4dd 2087 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
252b5132
RH
2088 (offsetT) temp, (char *) 0);
2089 *pfrag = 0;
2090
2091 S_SET_SEGMENT (symbolP, bss_seg);
2092
2093#ifdef OBJ_COFF
2094 /* The symbol may already have been created with a preceding
2095 ".globl" directive -- be careful not to step on storage class
041ff4dd 2096 in that case. Otherwise, set it to static. */
252b5132
RH
2097 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2098 {
2099 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2100 }
2101#endif /* OBJ_COFF */
2102
2103#ifdef S_SET_SIZE
2104 S_SET_SIZE (symbolP, temp);
2105#endif
2106 }
2107 else
2108 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2109 S_GET_NAME (symbolP));
2110
2111 subseg_set (current_seg, current_subseg);
2112
2113 demand_empty_rest_of_line ();
041ff4dd 2114}
252b5132
RH
2115
2116void
2117s_lcomm (needs_align)
2118 int needs_align;
2119{
2120 s_lcomm_internal (needs_align, 0);
2121}
2122
041ff4dd
NC
2123void
2124s_lcomm_bytes (needs_align)
252b5132
RH
2125 int needs_align;
2126{
2127 s_lcomm_internal (needs_align, 1);
2128}
2129
041ff4dd 2130void
252b5132 2131s_lsym (ignore)
ab9da554 2132 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2133{
2134 register char *name;
2135 register char c;
2136 register char *p;
2137 expressionS exp;
2138 register symbolS *symbolP;
2139
041ff4dd 2140 /* We permit ANY defined expression: BSD4.2 demands constants. */
252b5132
RH
2141 name = input_line_pointer;
2142 c = get_symbol_end ();
2143 p = input_line_pointer;
2144 *p = c;
2145 SKIP_WHITESPACE ();
f0e652b4 2146
252b5132
RH
2147 if (*input_line_pointer != ',')
2148 {
2149 *p = 0;
2150 as_bad (_("Expected comma after name \"%s\""), name);
2151 *p = c;
2152 ignore_rest_of_line ();
2153 return;
2154 }
f0e652b4 2155
252b5132
RH
2156 input_line_pointer++;
2157 expression (&exp);
f0e652b4 2158
252b5132
RH
2159 if (exp.X_op != O_constant
2160 && exp.X_op != O_register)
2161 {
2162 as_bad (_("bad expression"));
2163 ignore_rest_of_line ();
2164 return;
2165 }
f0e652b4 2166
252b5132
RH
2167 *p = 0;
2168 symbolP = symbol_find_or_make (name);
2169
2170 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2171 symbolP->sy_desc == 0) out of this test because coff doesn't have
2172 those fields, and I can't see when they'd ever be tripped. I
2173 don't think I understand why they were here so I may have
2174 introduced a bug. As recently as 1.37 didn't have this test
041ff4dd 2175 anyway. xoxorich. */
252b5132
RH
2176
2177 if (S_GET_SEGMENT (symbolP) == undefined_section
2178 && S_GET_VALUE (symbolP) == 0)
2179 {
2180 /* The name might be an undefined .global symbol; be sure to
041ff4dd 2181 keep the "external" bit. */
252b5132
RH
2182 S_SET_SEGMENT (symbolP,
2183 (exp.X_op == O_constant
2184 ? absolute_section
2185 : reg_section));
2186 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2187 }
2188 else
2189 {
2190 as_bad (_("Symbol %s already defined"), name);
2191 }
f0e652b4 2192
252b5132
RH
2193 *p = c;
2194 demand_empty_rest_of_line ();
041ff4dd 2195}
252b5132
RH
2196
2197/* Read a line into an sb. */
2198
2199static int
2200get_line_sb (line)
2201 sb *line;
2202{
2203 char quote1, quote2, inquote;
2204
2205 if (input_line_pointer[-1] == '\n')
2206 bump_line_counters ();
2207
2208 if (input_line_pointer >= buffer_limit)
2209 {
2210 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2211 if (buffer_limit == 0)
2212 return 0;
2213 }
2214
2215 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2216 code needs to be changed. */
041ff4dd 2217 if (!flag_m68k_mri)
252b5132
RH
2218 quote1 = '"';
2219 else
2220 quote1 = '\0';
2221
2222 quote2 = '\0';
2223 if (flag_m68k_mri)
2224 quote2 = '\'';
2225#ifdef LEX_IS_STRINGQUOTE
2226 quote2 = '\'';
2227#endif
2228
2229 inquote = '\0';
f0e652b4 2230
041ff4dd 2231 while (!is_end_of_line[(unsigned char) *input_line_pointer]
252b5132
RH
2232 || (inquote != '\0' && *input_line_pointer != '\n'))
2233 {
2234 if (inquote == *input_line_pointer)
2235 inquote = '\0';
2236 else if (inquote == '\0')
2237 {
2238 if (*input_line_pointer == quote1)
2239 inquote = quote1;
2240 else if (*input_line_pointer == quote2)
2241 inquote = quote2;
2242 }
f0e652b4 2243
252b5132
RH
2244 sb_add_char (line, *input_line_pointer++);
2245 }
f0e652b4 2246
252b5132
RH
2247 while (input_line_pointer < buffer_limit
2248 && is_end_of_line[(unsigned char) *input_line_pointer])
2249 {
2250 if (input_line_pointer[-1] == '\n')
2251 bump_line_counters ();
2252 ++input_line_pointer;
2253 }
f0e652b4 2254
252b5132
RH
2255 return 1;
2256}
2257
2258/* Define a macro. This is an interface to macro.c, which is shared
2259 between gas and gasp. */
2260
2261void
2262s_macro (ignore)
ab9da554 2263 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2264{
2265 char *file;
2266 unsigned int line;
2267 sb s;
2268 sb label;
2269 const char *err;
2270 const char *name;
2271
2272 as_where (&file, &line);
2273
2274 sb_new (&s);
041ff4dd 2275 while (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
2276 sb_add_char (&s, *input_line_pointer++);
2277
2278 sb_new (&label);
2279 if (line_label != NULL)
2280 sb_add_string (&label, S_GET_NAME (line_label));
2281
2282 err = define_macro (0, &s, &label, get_line_sb, &name);
2283 if (err != NULL)
2284 as_bad_where (file, line, "%s", err);
2285 else
2286 {
2287 if (line_label != NULL)
2288 {
2289 S_SET_SEGMENT (line_label, undefined_section);
2290 S_SET_VALUE (line_label, 0);
2b47531b 2291 symbol_set_frag (line_label, &zero_address_frag);
252b5132
RH
2292 }
2293
abd63a32 2294 if (((NO_PSEUDO_DOT || flag_m68k_mri)
252b5132 2295 && hash_find (po_hash, name) != NULL)
041ff4dd 2296 || (!flag_m68k_mri
252b5132
RH
2297 && *name == '.'
2298 && hash_find (po_hash, name + 1) != NULL))
2299 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2300 name);
2301 }
2302
2303 sb_kill (&s);
2304}
2305
2306/* Handle the .mexit pseudo-op, which immediately exits a macro
2307 expansion. */
2308
2309void
2310s_mexit (ignore)
ab9da554 2311 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2312{
2313 cond_exit_macro (macro_nest);
2314 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2315}
2316
2317/* Switch in and out of MRI mode. */
2318
2319void
2320s_mri (ignore)
ab9da554 2321 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2322{
2323 int on, old_flag;
2324
2325 on = get_absolute_expression ();
2326 old_flag = flag_mri;
2327 if (on != 0)
2328 {
2329 flag_mri = 1;
2330#ifdef TC_M68K
2331 flag_m68k_mri = 1;
2332#endif
2333 macro_mri_mode (1);
2334 }
2335 else
2336 {
2337 flag_mri = 0;
abd63a32 2338#ifdef TC_M68K
252b5132 2339 flag_m68k_mri = 0;
abd63a32 2340#endif
252b5132
RH
2341 macro_mri_mode (0);
2342 }
2343
2344 /* Operator precedence changes in m68k MRI mode, so we need to
2345 update the operator rankings. */
2346 expr_set_precedence ();
2347
2348#ifdef MRI_MODE_CHANGE
2349 if (on != old_flag)
2350 MRI_MODE_CHANGE (on);
2351#endif
2352
2353 demand_empty_rest_of_line ();
2354}
2355
2356/* Handle changing the location counter. */
2357
2358static void
2359do_org (segment, exp, fill)
2360 segT segment;
2361 expressionS *exp;
2362 int fill;
2363{
2364 if (segment != now_seg && segment != absolute_section)
2365 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2366 segment_name (segment), segment_name (now_seg));
2367
2368 if (now_seg == absolute_section)
2369 {
2370 if (fill != 0)
2371 as_warn (_("ignoring fill value in absolute section"));
2372 if (exp->X_op != O_constant)
2373 {
2374 as_bad (_("only constant offsets supported in absolute section"));
2375 exp->X_add_number = 0;
2376 }
2377 abs_section_offset = exp->X_add_number;
2378 }
2379 else
2380 {
2381 char *p;
2289f85d
AM
2382 symbolS *sym = exp->X_add_symbol;
2383 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
252b5132 2384
2289f85d
AM
2385 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2386 {
2387 /* Handle complex expressions. */
2388 sym = make_expr_symbol (exp);
2389 off = 0;
2390 }
2391
2392 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
252b5132
RH
2393 *p = fill;
2394 }
2395}
2396
041ff4dd 2397void
252b5132 2398s_org (ignore)
ab9da554 2399 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2400{
2401 register segT segment;
2402 expressionS exp;
2403 register long temp_fill;
2404
2405#ifdef md_flush_pending_output
2406 md_flush_pending_output ();
2407#endif
2408
2409 /* The m68k MRI assembler has a different meaning for .org. It
2410 means to create an absolute section at a given address. We can't
2411 support that--use a linker script instead. */
2412 if (flag_m68k_mri)
2413 {
2414 as_bad (_("MRI style ORG pseudo-op not supported"));
2415 ignore_rest_of_line ();
2416 return;
2417 }
2418
2419 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2420 thing as a sub-segment-relative origin. Any absolute origin is
2421 given a warning, then assumed to be segment-relative. Any
2422 segmented origin expression ("foo+42") had better be in the right
2423 segment or the .org is ignored.
2424
2425 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2426 we never know sub-segment sizes when we are reading code. BSD
2427 will crash trying to emit negative numbers of filler bytes in
2428 certain .orgs. We don't crash, but see as-write for that code.
2429
2430 Don't make frag if need_pass_2==1. */
2431 segment = get_known_segmented_expression (&exp);
2432 if (*input_line_pointer == ',')
2433 {
2434 input_line_pointer++;
2435 temp_fill = get_absolute_expression ();
2436 }
2437 else
2438 temp_fill = 0;
2439
2440 if (!need_pass_2)
2441 do_org (segment, &exp, temp_fill);
2442
2443 demand_empty_rest_of_line ();
041ff4dd 2444}
252b5132
RH
2445
2446/* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2447 called by the obj-format routine which handles section changing
2448 when in MRI mode. It will create a new section, and return it. It
2449 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2450 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2451 flags will be set in the section. */
2452
2453void
2454s_mri_sect (type)
ab9da554 2455 char *type ATTRIBUTE_UNUSED;
252b5132
RH
2456{
2457#ifdef TC_M68K
2458
2459 char *name;
2460 char c;
2461 segT seg;
2462
2463 SKIP_WHITESPACE ();
041ff4dd 2464
252b5132 2465 name = input_line_pointer;
041ff4dd 2466 if (!isdigit ((unsigned char) *name))
252b5132
RH
2467 c = get_symbol_end ();
2468 else
2469 {
2470 do
2471 {
2472 ++input_line_pointer;
2473 }
2474 while (isdigit ((unsigned char) *input_line_pointer));
f0e652b4 2475
252b5132
RH
2476 c = *input_line_pointer;
2477 *input_line_pointer = '\0';
2478 }
2479
2480 name = xstrdup (name);
2481
2482 *input_line_pointer = c;
2483
2484 seg = subseg_new (name, 0);
2485
2486 if (*input_line_pointer == ',')
2487 {
2488 int align;
2489
2490 ++input_line_pointer;
2491 align = get_absolute_expression ();
2492 record_alignment (seg, align);
2493 }
2494
2495 *type = 'C';
2496 if (*input_line_pointer == ',')
2497 {
2498 c = *++input_line_pointer;
2499 c = toupper ((unsigned char) c);
2500 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2501 *type = c;
2502 else
2503 as_bad (_("unrecognized section type"));
2504 ++input_line_pointer;
2505
2506#ifdef BFD_ASSEMBLER
2507 {
2508 flagword flags;
2509
2510 flags = SEC_NO_FLAGS;
2511 if (*type == 'C')
2512 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2513 else if (*type == 'D' || *type == 'M')
2514 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2515 else if (*type == 'R')
2516 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2517 if (flags != SEC_NO_FLAGS)
2518 {
041ff4dd 2519 if (!bfd_set_section_flags (stdoutput, seg, flags))
252b5132
RH
2520 as_warn (_("error setting flags for \"%s\": %s"),
2521 bfd_section_name (stdoutput, seg),
2522 bfd_errmsg (bfd_get_error ()));
2523 }
2524 }
2525#endif
2526 }
2527
2528 /* Ignore the HP type. */
2529 if (*input_line_pointer == ',')
2530 input_line_pointer += 2;
2531
2532 demand_empty_rest_of_line ();
2533
2534#else /* ! TC_M68K */
2535#ifdef TC_I960
2536
2537 char *name;
2538 char c;
2539 segT seg;
2540
2541 SKIP_WHITESPACE ();
2542
2543 name = input_line_pointer;
2544 c = get_symbol_end ();
2545
2546 name = xstrdup (name);
2547
2548 *input_line_pointer = c;
2549
2550 seg = subseg_new (name, 0);
2551
2552 if (*input_line_pointer != ',')
2553 *type = 'C';
2554 else
2555 {
2556 char *sectype;
2557
2558 ++input_line_pointer;
2559 SKIP_WHITESPACE ();
2560 sectype = input_line_pointer;
2561 c = get_symbol_end ();
2562 if (*sectype == '\0')
2563 *type = 'C';
2564 else if (strcasecmp (sectype, "text") == 0)
2565 *type = 'C';
2566 else if (strcasecmp (sectype, "data") == 0)
2567 *type = 'D';
2568 else if (strcasecmp (sectype, "romdata") == 0)
2569 *type = 'R';
2570 else
2571 as_warn (_("unrecognized section type `%s'"), sectype);
2572 *input_line_pointer = c;
2573 }
2574
2575 if (*input_line_pointer == ',')
2576 {
2577 char *seccmd;
2578
2579 ++input_line_pointer;
2580 SKIP_WHITESPACE ();
2581 seccmd = input_line_pointer;
2582 c = get_symbol_end ();
2583 if (strcasecmp (seccmd, "absolute") == 0)
2584 {
2585 as_bad (_("absolute sections are not supported"));
2586 *input_line_pointer = c;
2587 ignore_rest_of_line ();
2588 return;
2589 }
2590 else if (strcasecmp (seccmd, "align") == 0)
2591 {
2592 int align;
2593
2594 *input_line_pointer = c;
2595 align = get_absolute_expression ();
2596 record_alignment (seg, align);
2597 }
2598 else
2599 {
2600 as_warn (_("unrecognized section command `%s'"), seccmd);
2601 *input_line_pointer = c;
2602 }
2603 }
2604
041ff4dd 2605 demand_empty_rest_of_line ();
252b5132
RH
2606
2607#else /* ! TC_I960 */
2608 /* The MRI assembler seems to use different forms of .sect for
2609 different targets. */
2610 as_bad ("MRI mode not supported for this target");
2611 ignore_rest_of_line ();
2612#endif /* ! TC_I960 */
2613#endif /* ! TC_M68K */
2614}
2615
2616/* Handle the .print pseudo-op. */
2617
2618void
2619s_print (ignore)
ab9da554 2620 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2621{
2622 char *s;
2623 int len;
2624
2625 s = demand_copy_C_string (&len);
2626 printf ("%s\n", s);
2627 demand_empty_rest_of_line ();
2628}
2629
2630/* Handle the .purgem pseudo-op. */
2631
2632void
2633s_purgem (ignore)
ab9da554 2634 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2635{
2636 if (is_it_end_of_statement ())
2637 {
2638 demand_empty_rest_of_line ();
2639 return;
2640 }
2641
2642 do
2643 {
2644 char *name;
2645 char c;
2646
2647 SKIP_WHITESPACE ();
2648 name = input_line_pointer;
2649 c = get_symbol_end ();
2650 delete_macro (name);
2651 *input_line_pointer = c;
2652 SKIP_WHITESPACE ();
2653 }
2654 while (*input_line_pointer++ == ',');
2655
2656 --input_line_pointer;
2657 demand_empty_rest_of_line ();
2658}
2659
2660/* Handle the .rept pseudo-op. */
2661
2662void
2663s_rept (ignore)
ab9da554 2664 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
2665{
2666 int count;
252b5132
RH
2667
2668 count = get_absolute_expression ();
2669
041ff4dd 2670 do_repeat (count, "REPT", "ENDR");
6dc19fc4
TW
2671}
2672
2673/* This function provides a generic repeat block implementation. It allows
041ff4dd 2674 different directives to be used as the start/end keys. */
6dc19fc4
TW
2675
2676void
2677do_repeat (count, start, end)
041ff4dd
NC
2678 int count;
2679 const char *start;
2680 const char *end;
6dc19fc4
TW
2681{
2682 sb one;
2683 sb many;
2684
252b5132 2685 sb_new (&one);
041ff4dd 2686 if (!buffer_and_nest (start, end, &one, get_line_sb))
252b5132 2687 {
6dc19fc4 2688 as_bad (_("%s without %s"), start, end);
252b5132
RH
2689 return;
2690 }
2691
2692 sb_new (&many);
2693 while (count-- > 0)
2694 sb_add_sb (&many, &one);
2695
2696 sb_kill (&one);
2697
9f10757c 2698 input_scrub_include_sb (&many, input_line_pointer, 1);
252b5132
RH
2699 sb_kill (&many);
2700 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2701}
2702
6dc19fc4
TW
2703/* Skip to end of current repeat loop; EXTRA indicates how many additional
2704 input buffers to skip. Assumes that conditionals preceding the loop end
041ff4dd 2705 are properly nested.
6dc19fc4
TW
2706
2707 This function makes it easier to implement a premature "break" out of the
2708 loop. The EXTRA arg accounts for other buffers we might have inserted,
041ff4dd 2709 such as line substitutions. */
6dc19fc4
TW
2710
2711void
2712end_repeat (extra)
041ff4dd 2713 int extra;
6dc19fc4
TW
2714{
2715 cond_exit_macro (macro_nest);
2716 while (extra-- >= 0)
2717 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2718}
2719
252b5132
RH
2720/* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2721 this is .equiv, and it is an error if the symbol is already
2722 defined. */
2723
041ff4dd 2724void
252b5132
RH
2725s_set (equiv)
2726 int equiv;
2727{
2728 register char *name;
2729 register char delim;
2730 register char *end_name;
2731 register symbolS *symbolP;
2732
041ff4dd
NC
2733 /* Especial apologies for the random logic:
2734 this just grew, and could be parsed much more simply!
2735 Dean in haste. */
252b5132
RH
2736 name = input_line_pointer;
2737 delim = get_symbol_end ();
2738 end_name = input_line_pointer;
2739 *end_name = delim;
2740 SKIP_WHITESPACE ();
2741
2742 if (*input_line_pointer != ',')
2743 {
2744 *end_name = 0;
2745 as_bad (_("Expected comma after name \"%s\""), name);
2746 *end_name = delim;
2747 ignore_rest_of_line ();
2748 return;
2749 }
2750
2751 input_line_pointer++;
2752 *end_name = 0;
2753
2754 if (name[0] == '.' && name[1] == '\0')
2755 {
041ff4dd 2756 /* Turn '. = mumble' into a .org mumble. */
252b5132
RH
2757 register segT segment;
2758 expressionS exp;
2759
2760 segment = get_known_segmented_expression (&exp);
2761
2762 if (!need_pass_2)
2763 do_org (segment, &exp, 0);
2764
2765 *end_name = delim;
2766 return;
2767 }
2768
2769 if ((symbolP = symbol_find (name)) == NULL
2770 && (symbolP = md_undefined_symbol (name)) == NULL)
2771 {
2772#ifndef NO_LISTING
2773 /* When doing symbol listings, play games with dummy fragments living
2774 outside the normal fragment chain to record the file and line info
2775 for this symbol. */
2776 if (listing & LISTING_SYMBOLS)
2777 {
2778 extern struct list_info_struct *listing_tail;
041ff4dd
NC
2779 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2780 memset (dummy_frag, 0, sizeof (fragS));
252b5132
RH
2781 dummy_frag->fr_type = rs_fill;
2782 dummy_frag->line = listing_tail;
2783 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2784 dummy_frag->fr_symbol = symbolP;
2785 }
2786 else
2787#endif
041ff4dd
NC
2788 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2789
252b5132 2790#ifdef OBJ_COFF
041ff4dd 2791 /* "set" symbols are local unless otherwise specified. */
252b5132
RH
2792 SF_SET_LOCAL (symbolP);
2793#endif /* OBJ_COFF */
041ff4dd 2794 }
252b5132
RH
2795
2796 symbol_table_insert (symbolP);
2797
2798 *end_name = delim;
2799
2800 if (equiv
2801 && S_IS_DEFINED (symbolP)
2802 && S_GET_SEGMENT (symbolP) != reg_section)
2803 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2804
2805 pseudo_set (symbolP);
2806 demand_empty_rest_of_line ();
041ff4dd 2807}
252b5132 2808
041ff4dd 2809void
252b5132
RH
2810s_space (mult)
2811 int mult;
2812{
2813 expressionS exp;
2814 expressionS val;
2815 char *p = 0;
2816 char *stop = NULL;
2817 char stopc;
2818 int bytes;
2819
2820#ifdef md_flush_pending_output
2821 md_flush_pending_output ();
2822#endif
2823
2824 if (flag_mri)
2825 stop = mri_comment_field (&stopc);
2826
2827 /* In m68k MRI mode, we need to align to a word boundary, unless
2828 this is ds.b. */
2829 if (flag_m68k_mri && mult > 1)
2830 {
2831 if (now_seg == absolute_section)
2832 {
2833 abs_section_offset += abs_section_offset & 1;
2834 if (line_label != NULL)
2835 S_SET_VALUE (line_label, abs_section_offset);
2836 }
2837 else if (mri_common_symbol != NULL)
2838 {
2839 valueT val;
2840
2841 val = S_GET_VALUE (mri_common_symbol);
2842 if ((val & 1) != 0)
2843 {
2844 S_SET_VALUE (mri_common_symbol, val + 1);
2845 if (line_label != NULL)
2846 {
2b47531b
ILT
2847 expressionS *symexp;
2848
2849 symexp = symbol_get_value_expression (line_label);
2850 know (symexp->X_op == O_symbol);
2851 know (symexp->X_add_symbol == mri_common_symbol);
2852 symexp->X_add_number += 1;
252b5132
RH
2853 }
2854 }
2855 }
2856 else
2857 {
2858 do_align (1, (char *) NULL, 0, 0);
2859 if (line_label != NULL)
2860 {
2b47531b 2861 symbol_set_frag (line_label, frag_now);
252b5132
RH
2862 S_SET_VALUE (line_label, frag_now_fix ());
2863 }
2864 }
2865 }
2866
2867 bytes = mult;
2868
2869 expression (&exp);
2870
2871 SKIP_WHITESPACE ();
2872 if (*input_line_pointer == ',')
2873 {
2874 ++input_line_pointer;
2875 expression (&val);
2876 }
2877 else
2878 {
2879 val.X_op = O_constant;
2880 val.X_add_number = 0;
2881 }
2882
2883 if (val.X_op != O_constant
2884 || val.X_add_number < - 0x80
2885 || val.X_add_number > 0xff
2886 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2887 {
2888 if (exp.X_op != O_constant)
2889 as_bad (_("Unsupported variable size or fill value"));
2890 else
2891 {
2892 offsetT i;
2893
2894 if (mult == 0)
2895 mult = 1;
2896 bytes = mult * exp.X_add_number;
2897 for (i = 0; i < exp.X_add_number; i++)
2898 emit_expr (&val, mult);
2899 }
2900 }
2901 else
2902 {
2903 if (exp.X_op == O_constant)
2904 {
2905 long repeat;
2906
2907 repeat = exp.X_add_number;
2908 if (mult)
2909 repeat *= mult;
2910 bytes = repeat;
2911 if (repeat <= 0)
2912 {
041ff4dd 2913 if (!flag_mri)
252b5132
RH
2914 as_warn (_(".space repeat count is zero, ignored"));
2915 else if (repeat < 0)
2916 as_warn (_(".space repeat count is negative, ignored"));
2917 goto getout;
2918 }
2919
2920 /* If we are in the absolute section, just bump the offset. */
2921 if (now_seg == absolute_section)
2922 {
2923 abs_section_offset += repeat;
2924 goto getout;
2925 }
2926
2927 /* If we are secretly in an MRI common section, then
2928 creating space just increases the size of the common
2929 symbol. */
2930 if (mri_common_symbol != NULL)
2931 {
2932 S_SET_VALUE (mri_common_symbol,
2933 S_GET_VALUE (mri_common_symbol) + repeat);
2934 goto getout;
2935 }
2936
2937 if (!need_pass_2)
2938 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2939 (offsetT) repeat, (char *) 0);
2940 }
2941 else
2942 {
2943 if (now_seg == absolute_section)
2944 {
2945 as_bad (_("space allocation too complex in absolute section"));
2946 subseg_set (text_section, 0);
2947 }
f0e652b4 2948
252b5132
RH
2949 if (mri_common_symbol != NULL)
2950 {
2951 as_bad (_("space allocation too complex in common section"));
2952 mri_common_symbol = NULL;
2953 }
f0e652b4 2954
252b5132
RH
2955 if (!need_pass_2)
2956 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2957 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2958 }
2959
2960 if (p)
2961 *p = val.X_add_number;
2962 }
2963
2964 getout:
2965
2966 /* In MRI mode, after an odd number of bytes, we must align to an
2967 even word boundary, unless the next instruction is a dc.b, ds.b
2968 or dcb.b. */
2969 if (flag_mri && (bytes & 1) != 0)
2970 mri_pending_align = 1;
2971
2972 demand_empty_rest_of_line ();
2973
2974 if (flag_mri)
2975 mri_comment_end (stop, stopc);
2976}
2977
2978/* This is like s_space, but the value is a floating point number with
2979 the given precision. This is for the MRI dcb.s pseudo-op and
2980 friends. */
2981
2982void
2983s_float_space (float_type)
2984 int float_type;
2985{
2986 offsetT count;
2987 int flen;
2988 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2989 char *stop = NULL;
2990 char stopc;
2991
2992 if (flag_mri)
2993 stop = mri_comment_field (&stopc);
2994
2995 count = get_absolute_expression ();
2996
2997 SKIP_WHITESPACE ();
2998 if (*input_line_pointer != ',')
2999 {
3000 as_bad (_("missing value"));
3001 ignore_rest_of_line ();
3002 if (flag_mri)
3003 mri_comment_end (stop, stopc);
3004 return;
3005 }
3006
3007 ++input_line_pointer;
3008
3009 SKIP_WHITESPACE ();
3010
3011 /* Skip any 0{letter} that may be present. Don't even check if the
3012 * letter is legal. */
3013 if (input_line_pointer[0] == '0'
3014 && isalpha ((unsigned char) input_line_pointer[1]))
3015 input_line_pointer += 2;
3016
3017 /* Accept :xxxx, where the x's are hex digits, for a floating point
3018 with the exact digits specified. */
3019 if (input_line_pointer[0] == ':')
3020 {
3021 flen = hex_float (float_type, temp);
3022 if (flen < 0)
3023 {
3024 ignore_rest_of_line ();
3025 if (flag_mri)
3026 mri_comment_end (stop, stopc);
3027 return;
3028 }
3029 }
3030 else
3031 {
3032 char *err;
3033
3034 err = md_atof (float_type, temp, &flen);
3035 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3036 know (flen > 0);
3037 if (err)
3038 {
3039 as_bad (_("Bad floating literal: %s"), err);
3040 ignore_rest_of_line ();
3041 if (flag_mri)
3042 mri_comment_end (stop, stopc);
3043 return;
3044 }
3045 }
3046
3047 while (--count >= 0)
3048 {
3049 char *p;
3050
3051 p = frag_more (flen);
3052 memcpy (p, temp, (unsigned int) flen);
3053 }
3054
3055 demand_empty_rest_of_line ();
3056
3057 if (flag_mri)
3058 mri_comment_end (stop, stopc);
3059}
3060
3061/* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3062
3063void
3064s_struct (ignore)
ab9da554 3065 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
3066{
3067 char *stop = NULL;
3068 char stopc;
3069
3070 if (flag_mri)
3071 stop = mri_comment_field (&stopc);
3072 abs_section_offset = get_absolute_expression ();
3073 subseg_set (absolute_section, 0);
3074 demand_empty_rest_of_line ();
3075 if (flag_mri)
3076 mri_comment_end (stop, stopc);
3077}
3078
3079void
3080s_text (ignore)
ab9da554 3081 int ignore ATTRIBUTE_UNUSED;
252b5132
RH
3082{
3083 register int temp;
3084
3085 temp = get_absolute_expression ();
3086 subseg_set (text_section, (subsegT) temp);
3087 demand_empty_rest_of_line ();
3088#ifdef OBJ_VMS
3089 const_flag &= ~IN_DEFAULT_SECTION;
3090#endif
041ff4dd 3091}
252b5132 3092\f
041ff4dd 3093void
252b5132
RH
3094demand_empty_rest_of_line ()
3095{
3096 SKIP_WHITESPACE ();
3097 if (is_end_of_line[(unsigned char) *input_line_pointer])
041ff4dd 3098 input_line_pointer++;
252b5132 3099 else
041ff4dd
NC
3100 ignore_rest_of_line ();
3101
3102 /* Return having already swallowed end-of-line. */
3103}
252b5132
RH
3104
3105void
041ff4dd 3106ignore_rest_of_line ()
252b5132 3107{
041ff4dd 3108 /* For suspect lines: gives warning. */
252b5132
RH
3109 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3110 {
3111 if (isprint ((unsigned char) *input_line_pointer))
3112 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3113 *input_line_pointer);
3114 else
3115 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3116 *input_line_pointer);
f0e652b4 3117
252b5132
RH
3118 while (input_line_pointer < buffer_limit
3119 && !is_end_of_line[(unsigned char) *input_line_pointer])
041ff4dd 3120 input_line_pointer++;
252b5132 3121 }
f0e652b4 3122
041ff4dd
NC
3123 input_line_pointer++;
3124
3125 /* Return pointing just after end-of-line. */
252b5132
RH
3126 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3127}
3128
3129void
3130discard_rest_of_line ()
3131{
3132 while (input_line_pointer < buffer_limit
041ff4dd
NC
3133 && !is_end_of_line[(unsigned char) *input_line_pointer])
3134 input_line_pointer++;
3135
3136 input_line_pointer++;
f0e652b4 3137
041ff4dd 3138 /* Return pointing just after end-of-line. */
252b5132
RH
3139 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3140}
3141
041ff4dd
NC
3142/* In: Pointer to a symbol.
3143 Input_line_pointer->expression.
f0e652b4 3144
041ff4dd
NC
3145 Out: Input_line_pointer->just after any whitespace after expression.
3146 Tried to set symbol to value of expression.
3147 Will change symbols type, value, and frag; */
3148
252b5132
RH
3149void
3150pseudo_set (symbolP)
3151 symbolS *symbolP;
3152{
3153 expressionS exp;
3154#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3155 int ext;
3156#endif /* OBJ_AOUT or OBJ_BOUT */
3157
041ff4dd 3158 know (symbolP); /* NULL pointer is logic error. */
252b5132
RH
3159#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3160 ext = S_IS_EXTERNAL (symbolP);
3161#endif /* OBJ_AOUT or OBJ_BOUT */
3162
3163 (void) expression (&exp);
3164
3165 if (exp.X_op == O_illegal)
3166 as_bad (_("illegal expression; zero assumed"));
3167 else if (exp.X_op == O_absent)
3168 as_bad (_("missing expression; zero assumed"));
3169 else if (exp.X_op == O_big)
3170 {
3171 if (exp.X_add_number > 0)
3172 as_bad (_("bignum invalid; zero assumed"));
3173 else
3174 as_bad (_("floating point number invalid; zero assumed"));
3175 }
3176 else if (exp.X_op == O_subtract
3177 && (S_GET_SEGMENT (exp.X_add_symbol)
3178 == S_GET_SEGMENT (exp.X_op_symbol))
3179 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2b47531b
ILT
3180 && (symbol_get_frag (exp.X_add_symbol)
3181 == symbol_get_frag (exp.X_op_symbol)))
252b5132
RH
3182 {
3183 exp.X_op = O_constant;
3184 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3185 - S_GET_VALUE (exp.X_op_symbol));
3186 }
3187
3188 switch (exp.X_op)
3189 {
3190 case O_illegal:
3191 case O_absent:
3192 case O_big:
3193 exp.X_add_number = 0;
3194 /* Fall through. */
3195 case O_constant:
3196 S_SET_SEGMENT (symbolP, absolute_section);
3197#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3198 if (ext)
3199 S_SET_EXTERNAL (symbolP);
3200 else
3201 S_CLEAR_EXTERNAL (symbolP);
3202#endif /* OBJ_AOUT or OBJ_BOUT */
3203 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3204 if (exp.X_op != O_constant)
041ff4dd 3205 symbol_set_frag (symbolP, &zero_address_frag);
252b5132
RH
3206 break;
3207
3208 case O_register:
3209 S_SET_SEGMENT (symbolP, reg_section);
3210 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2b47531b 3211 symbol_set_frag (symbolP, &zero_address_frag);
252b5132
RH
3212 break;
3213
3214 case O_symbol:
3215 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3216 || exp.X_add_number != 0)
2b47531b 3217 symbol_set_value_expression (symbolP, &exp);
53b0d397
ILT
3218 else if (symbol_section_p (symbolP))
3219 as_bad ("invalid attempt to set value of section symbol");
252b5132
RH
3220 else
3221 {
3222 symbolS *s = exp.X_add_symbol;
3223
3224 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3225#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3226 if (ext)
3227 S_SET_EXTERNAL (symbolP);
3228 else
3229 S_CLEAR_EXTERNAL (symbolP);
3230#endif /* OBJ_AOUT or OBJ_BOUT */
3231 S_SET_VALUE (symbolP,
3232 exp.X_add_number + S_GET_VALUE (s));
2b47531b 3233 symbol_set_frag (symbolP, symbol_get_frag (s));
252b5132
RH
3234 copy_symbol_attributes (symbolP, s);
3235 }
3236 break;
3237
3238 default:
3239 /* The value is some complex expression.
3240 FIXME: Should we set the segment to anything? */
2b47531b 3241 symbol_set_value_expression (symbolP, &exp);
252b5132
RH
3242 break;
3243 }
3244}
3245\f
041ff4dd 3246/* cons()
f0e652b4 3247
041ff4dd
NC
3248 CONStruct more frag of .bytes, or .words etc.
3249 Should need_pass_2 be 1 then emit no frag(s).
3250 This understands EXPRESSIONS.
f0e652b4 3251
041ff4dd 3252 Bug (?)
f0e652b4 3253
041ff4dd
NC
3254 This has a split personality. We use expression() to read the
3255 value. We can detect if the value won't fit in a byte or word.
3256 But we can't detect if expression() discarded significant digits
3257 in the case of a long. Not worth the crocks required to fix it. */
252b5132
RH
3258
3259/* Select a parser for cons expressions. */
3260
3261/* Some targets need to parse the expression in various fancy ways.
3262 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3263 (for example, the HPPA does this). Otherwise, you can define
3264 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3265 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3266 are defined, which is the normal case, then only simple expressions
3267 are permitted. */
3268
abd63a32 3269#ifdef TC_M68K
252b5132
RH
3270static void
3271parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
abd63a32 3272#endif
252b5132
RH
3273
3274#ifndef TC_PARSE_CONS_EXPRESSION
3275#ifdef BITFIELD_CONS_EXPRESSIONS
3276#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
041ff4dd 3277static void
252b5132
RH
3278parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3279#endif
3280#ifdef REPEAT_CONS_EXPRESSIONS
3281#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3282static void
3283parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3284#endif
3285
3286/* If we haven't gotten one yet, just call expression. */
3287#ifndef TC_PARSE_CONS_EXPRESSION
3288#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3289#endif
3290#endif
3291
041ff4dd
NC
3292/* Worker to do .byte etc statements.
3293 Clobbers input_line_pointer and checks end-of-line. */
3294
3295static void
252b5132 3296cons_worker (nbytes, rva)
041ff4dd 3297 register int nbytes; /* 1=.byte, 2=.word, 4=.long. */
252b5132
RH
3298 int rva;
3299{
3300 int c;
3301 expressionS exp;
3302 char *stop = NULL;
3303 char stopc;
3304
3305#ifdef md_flush_pending_output
3306 md_flush_pending_output ();
3307#endif
3308
3309 if (flag_mri)
3310 stop = mri_comment_field (&stopc);
3311
3312 if (is_it_end_of_statement ())
3313 {
3314 demand_empty_rest_of_line ();
3315 if (flag_mri)
3316 mri_comment_end (stop, stopc);
3317 return;
3318 }
3319
3320#ifdef md_cons_align
3321 md_cons_align (nbytes);
3322#endif
3323
3324 c = 0;
3325 do
3326 {
abd63a32 3327#ifdef TC_M68K
252b5132
RH
3328 if (flag_m68k_mri)
3329 parse_mri_cons (&exp, (unsigned int) nbytes);
3330 else
abd63a32 3331#endif
252b5132
RH
3332 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3333
3334 if (rva)
3335 {
3336 if (exp.X_op == O_symbol)
3337 exp.X_op = O_symbol_rva;
3338 else
3339 as_fatal (_("rva without symbol"));
3340 }
3341 emit_expr (&exp, (unsigned int) nbytes);
3342 ++c;
3343 }
3344 while (*input_line_pointer++ == ',');
3345
3346 /* In MRI mode, after an odd number of bytes, we must align to an
3347 even word boundary, unless the next instruction is a dc.b, ds.b
3348 or dcb.b. */
3349 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3350 mri_pending_align = 1;
3351
041ff4dd 3352 input_line_pointer--; /* Put terminator back into stream. */
252b5132
RH
3353
3354 demand_empty_rest_of_line ();
3355
3356 if (flag_mri)
3357 mri_comment_end (stop, stopc);
3358}
3359
252b5132
RH
3360void
3361cons (size)
3362 int size;
3363{
3364 cons_worker (size, 0);
3365}
3366
041ff4dd 3367void
252b5132
RH
3368s_rva (size)
3369 int size;
3370{
3371 cons_worker (size, 1);
3372}
3373
3374/* Put the contents of expression EXP into the object file using
3375 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3376
3377void
3378emit_expr (exp, nbytes)
3379 expressionS *exp;
3380 unsigned int nbytes;
3381{
3382 operatorT op;
3383 register char *p;
3384 valueT extra_digit = 0;
3385
3386 /* Don't do anything if we are going to make another pass. */
3387 if (need_pass_2)
3388 return;
3389
3390#ifndef NO_LISTING
3391#ifdef OBJ_ELF
3392 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3393 appear as a four byte positive constant in the .line section,
3394 followed by a 2 byte 0xffff. Look for that case here. */
3395 {
3396 static int dwarf_line = -1;
3397
3398 if (strcmp (segment_name (now_seg), ".line") != 0)
3399 dwarf_line = -1;
3400 else if (dwarf_line >= 0
3401 && nbytes == 2
3402 && exp->X_op == O_constant
3403 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3404 listing_source_line ((unsigned int) dwarf_line);
3405 else if (nbytes == 4
3406 && exp->X_op == O_constant
3407 && exp->X_add_number >= 0)
3408 dwarf_line = exp->X_add_number;
3409 else
3410 dwarf_line = -1;
3411 }
3412
3413 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3414 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3415 AT_sibling (0x12) followed by a four byte address of the sibling
3416 followed by a 2 byte AT_name (0x38) followed by the name of the
3417 file. We look for that case here. */
3418 {
3419 static int dwarf_file = 0;
3420
3421 if (strcmp (segment_name (now_seg), ".debug") != 0)
3422 dwarf_file = 0;
3423 else if (dwarf_file == 0
3424 && nbytes == 2
3425 && exp->X_op == O_constant
3426 && exp->X_add_number == 0x11)
3427 dwarf_file = 1;
3428 else if (dwarf_file == 1
3429 && nbytes == 2
3430 && exp->X_op == O_constant
3431 && exp->X_add_number == 0x12)
3432 dwarf_file = 2;
3433 else if (dwarf_file == 2
3434 && nbytes == 4)
3435 dwarf_file = 3;
3436 else if (dwarf_file == 3
3437 && nbytes == 2
3438 && exp->X_op == O_constant
3439 && exp->X_add_number == 0x38)
3440 dwarf_file = 4;
3441 else
3442 dwarf_file = 0;
3443
3444 /* The variable dwarf_file_string tells stringer that the string
3445 may be the name of the source file. */
3446 if (dwarf_file == 4)
3447 dwarf_file_string = 1;
3448 else
3449 dwarf_file_string = 0;
3450 }
3451#endif
3452#endif
3453
3454 if (check_eh_frame (exp, &nbytes))
3455 return;
3456
3457 op = exp->X_op;
3458
3459 /* Allow `.word 0' in the absolute section. */
3460 if (now_seg == absolute_section)
3461 {
3462 if (op != O_constant || exp->X_add_number != 0)
3463 as_bad (_("attempt to store value in absolute section"));
3464 abs_section_offset += nbytes;
3465 return;
3466 }
3467
3468 /* Handle a negative bignum. */
3469 if (op == O_uminus
3470 && exp->X_add_number == 0
2b47531b
ILT
3471 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3472 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
252b5132
RH
3473 {
3474 int i;
3475 unsigned long carry;
3476
2b47531b 3477 exp = symbol_get_value_expression (exp->X_add_symbol);
252b5132
RH
3478
3479 /* Negate the bignum: one's complement each digit and add 1. */
3480 carry = 1;
3481 for (i = 0; i < exp->X_add_number; i++)
3482 {
3483 unsigned long next;
3484
041ff4dd 3485 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
252b5132
RH
3486 & LITTLENUM_MASK)
3487 + carry);
3488 generic_bignum[i] = next & LITTLENUM_MASK;
3489 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3490 }
3491
3492 /* We can ignore any carry out, because it will be handled by
3493 extra_digit if it is needed. */
3494
3495 extra_digit = (valueT) -1;
3496 op = O_big;
3497 }
3498
3499 if (op == O_absent || op == O_illegal)
3500 {
3501 as_warn (_("zero assumed for missing expression"));
3502 exp->X_add_number = 0;
3503 op = O_constant;
3504 }
3505 else if (op == O_big && exp->X_add_number <= 0)
3506 {
3507 as_bad (_("floating point number invalid; zero assumed"));
3508 exp->X_add_number = 0;
3509 op = O_constant;
3510 }
3511 else if (op == O_register)
3512 {
3513 as_warn (_("register value used as expression"));
3514 op = O_constant;
3515 }
3516
3517 p = frag_more ((int) nbytes);
3518
3519#ifndef WORKING_DOT_WORD
3520 /* If we have the difference of two symbols in a word, save it on
3521 the broken_words list. See the code in write.c. */
3522 if (op == O_subtract && nbytes == 2)
3523 {
3524 struct broken_word *x;
3525
3526 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3527 x->next_broken_word = broken_words;
3528 broken_words = x;
3529 x->seg = now_seg;
3530 x->subseg = now_subseg;
3531 x->frag = frag_now;
3532 x->word_goes_here = p;
3533 x->dispfrag = 0;
3534 x->add = exp->X_add_symbol;
3535 x->sub = exp->X_op_symbol;
3536 x->addnum = exp->X_add_number;
3537 x->added = 0;
3538 new_broken_words++;
3539 return;
3540 }
3541#endif
3542
3543 /* If we have an integer, but the number of bytes is too large to
3544 pass to md_number_to_chars, handle it as a bignum. */
3545 if (op == O_constant && nbytes > sizeof (valueT))
3546 {
3547 valueT val;
3548 int gencnt;
3549
041ff4dd 3550 if (!exp->X_unsigned && exp->X_add_number < 0)
252b5132
RH
3551 extra_digit = (valueT) -1;
3552 val = (valueT) exp->X_add_number;
3553 gencnt = 0;
3554 do
3555 {
3556 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3557 val >>= LITTLENUM_NUMBER_OF_BITS;
3558 ++gencnt;
3559 }
3560 while (val != 0);
3561 op = exp->X_op = O_big;
3562 exp->X_add_number = gencnt;
3563 }
3564
3565 if (op == O_constant)
3566 {
3567 register valueT get;
3568 register valueT use;
3569 register valueT mask;
3570 valueT hibit;
3571 register valueT unmask;
3572
3573 /* JF << of >= number of bits in the object is undefined. In
041ff4dd 3574 particular SPARC (Sun 4) has problems. */
252b5132
RH
3575 if (nbytes >= sizeof (valueT))
3576 {
3577 mask = 0;
3578 if (nbytes > sizeof (valueT))
3579 hibit = 0;
3580 else
3581 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3582 }
3583 else
3584 {
041ff4dd 3585 /* Don't store these bits. */
252b5132
RH
3586 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3587 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3588 }
3589
041ff4dd 3590 unmask = ~mask; /* Do store these bits. */
252b5132
RH
3591
3592#ifdef NEVER
3593 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
041ff4dd 3594 mask = ~(unmask >> 1); /* Includes sign bit now. */
252b5132
RH
3595#endif
3596
3597 get = exp->X_add_number;
3598 use = get & unmask;
3599 if ((get & mask) != 0
3600 && ((get & mask) != mask
3601 || (get & hibit) == 0))
041ff4dd 3602 { /* Leading bits contain both 0s & 1s. */
252b5132
RH
3603 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3604 (unsigned long) get, (unsigned long) use);
3605 }
041ff4dd 3606 /* Put bytes in right order. */
252b5132
RH
3607 md_number_to_chars (p, use, (int) nbytes);
3608 }
3609 else if (op == O_big)
3610 {
3611 unsigned int size;
3612 LITTLENUM_TYPE *nums;
3613
3614 know (nbytes % CHARS_PER_LITTLENUM == 0);
3615
3616 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3617 if (nbytes < size)
3618 {
3619 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3620 size = nbytes;
3621 }
3622
3623 if (target_big_endian)
3624 {
3625 while (nbytes > size)
3626 {
3627 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3628 nbytes -= CHARS_PER_LITTLENUM;
3629 p += CHARS_PER_LITTLENUM;
3630 }
3631
3632 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3633 while (size > 0)
3634 {
3635 --nums;
3636 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3637 size -= CHARS_PER_LITTLENUM;
3638 p += CHARS_PER_LITTLENUM;
3639 }
3640 }
3641 else
3642 {
3643 nums = generic_bignum;
3644 while (size > 0)
3645 {
3646 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3647 ++nums;
3648 size -= CHARS_PER_LITTLENUM;
3649 p += CHARS_PER_LITTLENUM;
3650 nbytes -= CHARS_PER_LITTLENUM;
3651 }
3652
3653 while (nbytes > 0)
3654 {
3655 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3656 nbytes -= CHARS_PER_LITTLENUM;
3657 p += CHARS_PER_LITTLENUM;
3658 }
3659 }
3660 }
3661 else
3662 {
3663 memset (p, 0, nbytes);
3664
3665 /* Now we need to generate a fixS to record the symbol value.
3666 This is easy for BFD. For other targets it can be more
3667 complex. For very complex cases (currently, the HPPA and
3668 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3669 want. For simpler cases, you can define TC_CONS_RELOC to be
3670 the name of the reloc code that should be stored in the fixS.
3671 If neither is defined, the code uses NO_RELOC if it is
3672 defined, and otherwise uses 0. */
3673
3674#ifdef BFD_ASSEMBLER
3675#ifdef TC_CONS_FIX_NEW
3676 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3677#else
3678 {
3679 bfd_reloc_code_real_type r;
3680
3681 switch (nbytes)
3682 {
3683 case 1:
3684 r = BFD_RELOC_8;
3685 break;
3686 case 2:
3687 r = BFD_RELOC_16;
3688 break;
3689 case 4:
3690 r = BFD_RELOC_32;
3691 break;
3692 case 8:
3693 r = BFD_RELOC_64;
3694 break;
3695 default:
3696 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3697 r = BFD_RELOC_32;
3698 break;
3699 }
3700 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3701 0, r);
3702 }
3703#endif
3704#else
3705#ifdef TC_CONS_FIX_NEW
3706 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3707#else
3708 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3709 it is defined, otherwise use NO_RELOC if it is defined,
3710 otherwise use 0. */
3711#ifndef TC_CONS_RELOC
3712#ifdef NO_RELOC
3713#define TC_CONS_RELOC NO_RELOC
3714#else
3715#define TC_CONS_RELOC 0
3716#endif
3717#endif
3718 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3719 TC_CONS_RELOC);
3720#endif /* TC_CONS_FIX_NEW */
3721#endif /* BFD_ASSEMBLER */
3722 }
3723}
3724\f
3725#ifdef BITFIELD_CONS_EXPRESSIONS
3726
3727/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3728 w:x,y:z, where w and y are bitwidths and x and y are values. They
3729 then pack them all together. We do a little better in that we allow
3730 them in words, longs, etc. and we'll pack them in target byte order
3731 for you.
3732
3733 The rules are: pack least significat bit first, if a field doesn't
3734 entirely fit, put it in the next unit. Overflowing the bitfield is
3735 explicitly *not* even a warning. The bitwidth should be considered
3736 a "mask".
3737
3738 To use this function the tc-XXX.h file should define
3739 BITFIELD_CONS_EXPRESSIONS. */
3740
041ff4dd 3741static void
252b5132
RH
3742parse_bitfield_cons (exp, nbytes)
3743 expressionS *exp;
3744 unsigned int nbytes;
3745{
3746 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3747 char *hold = input_line_pointer;
3748
3749 (void) expression (exp);
3750
3751 if (*input_line_pointer == ':')
041ff4dd
NC
3752 {
3753 /* Bitfields. */
252b5132
RH
3754 long value = 0;
3755
3756 for (;;)
3757 {
3758 unsigned long width;
3759
3760 if (*input_line_pointer != ':')
3761 {
3762 input_line_pointer = hold;
3763 break;
041ff4dd 3764 } /* Next piece is not a bitfield. */
252b5132
RH
3765
3766 /* In the general case, we can't allow
3767 full expressions with symbol
3768 differences and such. The relocation
3769 entries for symbols not defined in this
3770 assembly would require arbitrary field
3771 widths, positions, and masks which most
3772 of our current object formats don't
3773 support.
3774
3775 In the specific case where a symbol
3776 *is* defined in this assembly, we
3777 *could* build fixups and track it, but
3778 this could lead to confusion for the
3779 backends. I'm lazy. I'll take any
3780 SEG_ABSOLUTE. I think that means that
3781 you can use a previous .set or
041ff4dd 3782 .equ type symbol. xoxorich. */
252b5132
RH
3783
3784 if (exp->X_op == O_absent)
3785 {
3786 as_warn (_("using a bit field width of zero"));
3787 exp->X_add_number = 0;
3788 exp->X_op = O_constant;
041ff4dd 3789 } /* Implied zero width bitfield. */
252b5132
RH
3790
3791 if (exp->X_op != O_constant)
3792 {
3793 *input_line_pointer = '\0';
3794 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3795 *input_line_pointer = ':';
3796 demand_empty_rest_of_line ();
3797 return;
041ff4dd 3798 } /* Too complex. */
252b5132
RH
3799
3800 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3801 {
3802 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3803 width, nbytes, (BITS_PER_CHAR * nbytes));
3804 width = BITS_PER_CHAR * nbytes;
041ff4dd 3805 } /* Too big. */
252b5132
RH
3806
3807 if (width > bits_available)
3808 {
3809 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3810 input_line_pointer = hold;
3811 exp->X_add_number = value;
3812 break;
041ff4dd 3813 } /* Won't fit. */
252b5132 3814
ef99799a
KH
3815 /* Skip ':'. */
3816 hold = ++input_line_pointer;
252b5132
RH
3817
3818 (void) expression (exp);
3819 if (exp->X_op != O_constant)
3820 {
3821 char cache = *input_line_pointer;
3822
3823 *input_line_pointer = '\0';
3824 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3825 *input_line_pointer = cache;
3826 demand_empty_rest_of_line ();
3827 return;
041ff4dd 3828 } /* Too complex. */
252b5132
RH
3829
3830 value |= ((~(-1 << width) & exp->X_add_number)
3831 << ((BITS_PER_CHAR * nbytes) - bits_available));
3832
3833 if ((bits_available -= width) == 0
3834 || is_it_end_of_statement ()
3835 || *input_line_pointer != ',')
3836 {
3837 break;
041ff4dd 3838 } /* All the bitfields we're gonna get. */
252b5132
RH
3839
3840 hold = ++input_line_pointer;
3841 (void) expression (exp);
041ff4dd 3842 }
252b5132
RH
3843
3844 exp->X_add_number = value;
3845 exp->X_op = O_constant;
3846 exp->X_unsigned = 1;
041ff4dd
NC
3847 }
3848}
252b5132
RH
3849
3850#endif /* BITFIELD_CONS_EXPRESSIONS */
3851\f
3852/* Handle an MRI style string expression. */
3853
abd63a32 3854#ifdef TC_M68K
252b5132
RH
3855static void
3856parse_mri_cons (exp, nbytes)
3857 expressionS *exp;
3858 unsigned int nbytes;
3859{
3860 if (*input_line_pointer != '\''
3861 && (input_line_pointer[1] != '\''
3862 || (*input_line_pointer != 'A'
3863 && *input_line_pointer != 'E')))
3864 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3865 else
3866 {
3867 unsigned int scan;
3868 unsigned int result = 0;
3869
3870 /* An MRI style string. Cut into as many bytes as will fit into
3871 a nbyte chunk, left justify if necessary, and separate with
3872 commas so we can try again later. */
3873 if (*input_line_pointer == 'A')
3874 ++input_line_pointer;
3875 else if (*input_line_pointer == 'E')
3876 {
3877 as_bad (_("EBCDIC constants are not supported"));
3878 ++input_line_pointer;
3879 }
3880
3881 input_line_pointer++;
3882 for (scan = 0; scan < nbytes; scan++)
3883 {
3884 if (*input_line_pointer == '\'')
3885 {
3886 if (input_line_pointer[1] == '\'')
3887 {
3888 input_line_pointer++;
3889 }
3890 else
3891 break;
3892 }
3893 result = (result << 8) | (*input_line_pointer++);
3894 }
3895
041ff4dd 3896 /* Left justify. */
252b5132
RH
3897 while (scan < nbytes)
3898 {
3899 result <<= 8;
3900 scan++;
3901 }
f0e652b4 3902
041ff4dd 3903 /* Create correct expression. */
252b5132
RH
3904 exp->X_op = O_constant;
3905 exp->X_add_number = result;
f0e652b4 3906
041ff4dd 3907 /* Fake it so that we can read the next char too. */
252b5132
RH
3908 if (input_line_pointer[0] != '\'' ||
3909 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3910 {
3911 input_line_pointer -= 2;
3912 input_line_pointer[0] = ',';
3913 input_line_pointer[1] = '\'';
3914 }
3915 else
3916 input_line_pointer++;
3917 }
3918}
abd63a32 3919#endif /* TC_M68K */
252b5132
RH
3920\f
3921#ifdef REPEAT_CONS_EXPRESSIONS
3922
3923/* Parse a repeat expression for cons. This is used by the MIPS
3924 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3925 object file COUNT times.
3926
3927 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3928
3929static void
3930parse_repeat_cons (exp, nbytes)
3931 expressionS *exp;
3932 unsigned int nbytes;
3933{
3934 expressionS count;
3935 register int i;
3936
3937 expression (exp);
3938
3939 if (*input_line_pointer != ':')
3940 {
3941 /* No repeat count. */
3942 return;
3943 }
3944
3945 ++input_line_pointer;
3946 expression (&count);
3947 if (count.X_op != O_constant
3948 || count.X_add_number <= 0)
3949 {
3950 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3951 return;
3952 }
3953
3954 /* The cons function is going to output this expression once. So we
3955 output it count - 1 times. */
3956 for (i = count.X_add_number - 1; i > 0; i--)
3957 emit_expr (exp, nbytes);
3958}
3959
3960#endif /* REPEAT_CONS_EXPRESSIONS */
3961\f
3962/* Parse a floating point number represented as a hex constant. This
3963 permits users to specify the exact bits they want in the floating
3964 point number. */
3965
3966static int
3967hex_float (float_type, bytes)
3968 int float_type;
3969 char *bytes;
3970{
3971 int length;
3972 int i;
3973
3974 switch (float_type)
3975 {
3976 case 'f':
3977 case 'F':
3978 case 's':
3979 case 'S':
3980 length = 4;
3981 break;
3982
3983 case 'd':
3984 case 'D':
3985 case 'r':
3986 case 'R':
3987 length = 8;
3988 break;
3989
3990 case 'x':
3991 case 'X':
3992 length = 12;
3993 break;
3994
3995 case 'p':
3996 case 'P':
3997 length = 12;
3998 break;
3999
4000 default:
4001 as_bad (_("Unknown floating type type '%c'"), float_type);
4002 return -1;
4003 }
4004
4005 /* It would be nice if we could go through expression to parse the
4006 hex constant, but if we get a bignum it's a pain to sort it into
4007 the buffer correctly. */
4008 i = 0;
4009 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4010 {
4011 int d;
4012
4013 /* The MRI assembler accepts arbitrary underscores strewn about
041ff4dd 4014 through the hex constant, so we ignore them as well. */
252b5132
RH
4015 if (*input_line_pointer == '_')
4016 {
4017 ++input_line_pointer;
4018 continue;
4019 }
4020
4021 if (i >= length)
4022 {
4023 as_warn (_("Floating point constant too large"));
4024 return -1;
4025 }
4026 d = hex_value (*input_line_pointer) << 4;
4027 ++input_line_pointer;
4028 while (*input_line_pointer == '_')
4029 ++input_line_pointer;
4030 if (hex_p (*input_line_pointer))
4031 {
4032 d += hex_value (*input_line_pointer);
4033 ++input_line_pointer;
4034 }
4035 if (target_big_endian)
4036 bytes[i] = d;
4037 else
4038 bytes[length - i - 1] = d;
4039 ++i;
4040 }
4041
4042 if (i < length)
4043 {
4044 if (target_big_endian)
4045 memset (bytes + i, 0, length - i);
4046 else
4047 memset (bytes, 0, length - i);
4048 }
4049
4050 return length;
4051}
4052
041ff4dd 4053/* float_cons()
f0e652b4 4054
041ff4dd
NC
4055 CONStruct some more frag chars of .floats .ffloats etc.
4056 Makes 0 or more new frags.
4057 If need_pass_2 == 1, no frags are emitted.
4058 This understands only floating literals, not expressions. Sorry.
f0e652b4 4059
041ff4dd
NC
4060 A floating constant is defined by atof_generic(), except it is preceded
4061 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4062 reading, I decided to be incompatible. This always tries to give you
4063 rounded bits to the precision of the pseudo-op. Former AS did premature
4064 truncatation, restored noisy bits instead of trailing 0s AND gave you
4065 a choice of 2 flavours of noise according to which of 2 floating-point
4066 scanners you directed AS to use.
f0e652b4 4067
041ff4dd 4068 In: input_line_pointer->whitespace before, or '0' of flonum. */
252b5132
RH
4069
4070void
4071float_cons (float_type)
041ff4dd
NC
4072 /* Clobbers input_line-pointer, checks end-of-line. */
4073 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
252b5132
RH
4074{
4075 register char *p;
041ff4dd
NC
4076 int length; /* Number of chars in an object. */
4077 register char *err; /* Error from scanning floating literal. */
252b5132
RH
4078 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4079
4080 if (is_it_end_of_statement ())
4081 {
4082 demand_empty_rest_of_line ();
4083 return;
4084 }
4085
4086#ifdef md_flush_pending_output
4087 md_flush_pending_output ();
4088#endif
4089
4090 do
4091 {
041ff4dd 4092 /* input_line_pointer->1st char of a flonum (we hope!). */
252b5132
RH
4093 SKIP_WHITESPACE ();
4094
4095 /* Skip any 0{letter} that may be present. Don't even check if the
041ff4dd
NC
4096 letter is legal. Someone may invent a "z" format and this routine
4097 has no use for such information. Lusers beware: you get
4098 diagnostics if your input is ill-conditioned. */
252b5132
RH
4099 if (input_line_pointer[0] == '0'
4100 && isalpha ((unsigned char) input_line_pointer[1]))
4101 input_line_pointer += 2;
4102
4103 /* Accept :xxxx, where the x's are hex digits, for a floating
4104 point with the exact digits specified. */
4105 if (input_line_pointer[0] == ':')
4106 {
4107 ++input_line_pointer;
4108 length = hex_float (float_type, temp);
4109 if (length < 0)
4110 {
4111 ignore_rest_of_line ();
4112 return;
4113 }
4114 }
4115 else
4116 {
4117 err = md_atof (float_type, temp, &length);
4118 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4119 know (length > 0);
4120 if (err)
4121 {
4122 as_bad (_("Bad floating literal: %s"), err);
4123 ignore_rest_of_line ();
4124 return;
4125 }
4126 }
4127
4128 if (!need_pass_2)
4129 {
4130 int count;
4131
4132 count = 1;
4133
4134#ifdef REPEAT_CONS_EXPRESSIONS
4135 if (*input_line_pointer == ':')
4136 {
4137 expressionS count_exp;
4138
4139 ++input_line_pointer;
4140 expression (&count_exp);
f0e652b4 4141
252b5132
RH
4142 if (count_exp.X_op != O_constant
4143 || count_exp.X_add_number <= 0)
041ff4dd 4144 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
252b5132
RH
4145 else
4146 count = count_exp.X_add_number;
4147 }
4148#endif
4149
4150 while (--count >= 0)
4151 {
4152 p = frag_more (length);
4153 memcpy (p, temp, (unsigned int) length);
4154 }
4155 }
4156 SKIP_WHITESPACE ();
4157 }
4158 while (*input_line_pointer++ == ',');
4159
041ff4dd
NC
4160 /* Put terminator back into stream. */
4161 --input_line_pointer;
252b5132 4162 demand_empty_rest_of_line ();
041ff4dd 4163}
252b5132 4164\f
041ff4dd 4165/* Return the size of a LEB128 value. */
252b5132
RH
4166
4167static inline int
4168sizeof_sleb128 (value)
4169 offsetT value;
4170{
4171 register int size = 0;
4172 register unsigned byte;
4173
4174 do
4175 {
4176 byte = (value & 0x7f);
4177 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4178 Fortunately, we can structure things so that the extra work reduces
4179 to a noop on systems that do things "properly". */
4180 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4181 size += 1;
4182 }
4183 while (!(((value == 0) && ((byte & 0x40) == 0))
4184 || ((value == -1) && ((byte & 0x40) != 0))));
4185
4186 return size;
4187}
4188
4189static inline int
4190sizeof_uleb128 (value)
4191 valueT value;
4192{
4193 register int size = 0;
4194 register unsigned byte;
4195
4196 do
4197 {
4198 byte = (value & 0x7f);
4199 value >>= 7;
4200 size += 1;
4201 }
4202 while (value != 0);
4203
4204 return size;
4205}
4206
4207int
4208sizeof_leb128 (value, sign)
4209 valueT value;
4210 int sign;
4211{
4212 if (sign)
4213 return sizeof_sleb128 ((offsetT) value);
4214 else
4215 return sizeof_uleb128 (value);
4216}
4217
4218/* Output a LEB128 value. */
4219
4220static inline int
4221output_sleb128 (p, value)
4222 char *p;
4223 offsetT value;
4224{
4225 register char *orig = p;
4226 register int more;
4227
4228 do
4229 {
4230 unsigned byte = (value & 0x7f);
4231
4232 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4233 Fortunately, we can structure things so that the extra work reduces
4234 to a noop on systems that do things "properly". */
4235 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4236
4237 more = !((((value == 0) && ((byte & 0x40) == 0))
4238 || ((value == -1) && ((byte & 0x40) != 0))));
4239 if (more)
4240 byte |= 0x80;
4241
4242 *p++ = byte;
4243 }
4244 while (more);
4245
4246 return p - orig;
4247}
4248
4249static inline int
4250output_uleb128 (p, value)
4251 char *p;
4252 valueT value;
4253{
4254 char *orig = p;
4255
4256 do
4257 {
4258 unsigned byte = (value & 0x7f);
4259 value >>= 7;
4260 if (value != 0)
4261 /* More bytes to follow. */
4262 byte |= 0x80;
4263
4264 *p++ = byte;
4265 }
4266 while (value != 0);
4267
4268 return p - orig;
4269}
4270
4271int
4272output_leb128 (p, value, sign)
4273 char *p;
4274 valueT value;
4275 int sign;
4276{
4277 if (sign)
4278 return output_sleb128 (p, (offsetT) value);
4279 else
4280 return output_uleb128 (p, value);
4281}
4282
4283/* Do the same for bignums. We combine sizeof with output here in that
4284 we don't output for NULL values of P. It isn't really as critical as
4285 for "normal" values that this be streamlined. */
4286
6d4d30bb 4287static inline int
252b5132
RH
4288output_big_sleb128 (p, bignum, size)
4289 char *p;
4290 LITTLENUM_TYPE *bignum;
4291 int size;
4292{
4293 char *orig = p;
4294 valueT val = 0;
4295 int loaded = 0;
4296 unsigned byte;
4297
4298 /* Strip leading sign extensions off the bignum. */
041ff4dd 4299 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
252b5132
RH
4300 size--;
4301
4302 do
4303 {
4304 if (loaded < 7 && size > 0)
4305 {
4306 val |= (*bignum << loaded);
4307 loaded += 8 * CHARS_PER_LITTLENUM;
4308 size--;
4309 bignum++;
4310 }
4311
4312 byte = val & 0x7f;
4313 loaded -= 7;
4314 val >>= 7;
4315
4316 if (size == 0)
4317 {
4318 if ((val == 0 && (byte & 0x40) == 0)
041ff4dd 4319 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
252b5132
RH
4320 && (byte & 0x40) != 0))
4321 byte |= 0x80;
4322 }
4323
4324 if (orig)
4325 *p = byte;
4326 p++;
4327 }
4328 while (byte & 0x80);
4329
4330 return p - orig;
4331}
4332
6d4d30bb 4333static inline int
252b5132
RH
4334output_big_uleb128 (p, bignum, size)
4335 char *p;
4336 LITTLENUM_TYPE *bignum;
4337 int size;
4338{
4339 char *orig = p;
4340 valueT val = 0;
4341 int loaded = 0;
4342 unsigned byte;
4343
4344 /* Strip leading zeros off the bignum. */
4345 /* XXX: Is this needed? */
041ff4dd 4346 while (size > 0 && bignum[size - 1] == 0)
252b5132
RH
4347 size--;
4348
4349 do
4350 {
4351 if (loaded < 7 && size > 0)
4352 {
4353 val |= (*bignum << loaded);
4354 loaded += 8 * CHARS_PER_LITTLENUM;
4355 size--;
4356 bignum++;
4357 }
4358
4359 byte = val & 0x7f;
4360 loaded -= 7;
4361 val >>= 7;
4362
4363 if (size > 0 || val)
4364 byte |= 0x80;
4365
4366 if (orig)
4367 *p = byte;
4368 p++;
4369 }
4370 while (byte & 0x80);
4371
4372 return p - orig;
4373}
4374
6d4d30bb 4375static int
252b5132
RH
4376output_big_leb128 (p, bignum, size, sign)
4377 char *p;
4378 LITTLENUM_TYPE *bignum;
4379 int size, sign;
4380{
4381 if (sign)
4382 return output_big_sleb128 (p, bignum, size);
4383 else
4384 return output_big_uleb128 (p, bignum, size);
4385}
4386
4387/* Generate the appropriate fragments for a given expression to emit a
4388 leb128 value. */
4389
4390void
041ff4dd 4391emit_leb128_expr (exp, sign)
252b5132
RH
4392 expressionS *exp;
4393 int sign;
4394{
4395 operatorT op = exp->X_op;
4396
4397 if (op == O_absent || op == O_illegal)
4398 {
4399 as_warn (_("zero assumed for missing expression"));
4400 exp->X_add_number = 0;
4401 op = O_constant;
4402 }
4403 else if (op == O_big && exp->X_add_number <= 0)
4404 {
4405 as_bad (_("floating point number invalid; zero assumed"));
4406 exp->X_add_number = 0;
4407 op = O_constant;
4408 }
4409 else if (op == O_register)
4410 {
4411 as_warn (_("register value used as expression"));
4412 op = O_constant;
4413 }
4414
4415 if (op == O_constant)
4416 {
4417 /* If we've got a constant, emit the thing directly right now. */
4418
4419 valueT value = exp->X_add_number;
4420 int size;
4421 char *p;
4422
4423 size = sizeof_leb128 (value, sign);
4424 p = frag_more (size);
4425 output_leb128 (p, value, sign);
4426 }
4427 else if (op == O_big)
4428 {
4429 /* O_big is a different sort of constant. */
4430
4431 int size;
4432 char *p;
4433
4434 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4435 p = frag_more (size);
4436 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4437 }
4438 else
4439 {
041ff4dd 4440 /* Otherwise, we have to create a variable sized fragment and
252b5132
RH
4441 resolve things later. */
4442
041ff4dd 4443 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
252b5132
RH
4444 make_expr_symbol (exp), 0, (char *) NULL);
4445 }
4446}
4447
4448/* Parse the .sleb128 and .uleb128 pseudos. */
4449
4450void
4451s_leb128 (sign)
4452 int sign;
4453{
4454 expressionS exp;
4455
041ff4dd
NC
4456 do
4457 {
4458 expression (&exp);
4459 emit_leb128_expr (&exp, sign);
4460 }
4461 while (*input_line_pointer++ == ',');
252b5132
RH
4462
4463 input_line_pointer--;
4464 demand_empty_rest_of_line ();
4465}
4466\f
041ff4dd
NC
4467/* We read 0 or more ',' separated, double-quoted strings.
4468 Caller should have checked need_pass_2 is FALSE because we don't
4469 check it. */
4470
4471void
4472stringer (append_zero) /* Worker to do .ascii etc statements. */
4473 /* Checks end-of-line. */
4474 register int append_zero; /* 0: don't append '\0', else 1. */
252b5132
RH
4475{
4476 register unsigned int c;
4477 char *start;
4478
4479#ifdef md_flush_pending_output
4480 md_flush_pending_output ();
4481#endif
4482
041ff4dd
NC
4483 /* The following awkward logic is to parse ZERO or more strings,
4484 comma separated. Recall a string expression includes spaces
4485 before the opening '\"' and spaces after the closing '\"'.
4486 We fake a leading ',' if there is (supposed to be)
4487 a 1st, expression. We keep demanding expressions for each ','. */
252b5132
RH
4488 if (is_it_end_of_statement ())
4489 {
041ff4dd
NC
4490 c = 0; /* Skip loop. */
4491 ++input_line_pointer; /* Compensate for end of loop. */
252b5132
RH
4492 }
4493 else
4494 {
041ff4dd 4495 c = ','; /* Do loop. */
252b5132
RH
4496 }
4497 while (c == ',' || c == '<' || c == '"')
4498 {
4499 SKIP_WHITESPACE ();
4500 switch (*input_line_pointer)
4501 {
4502 case '\"':
041ff4dd 4503 ++input_line_pointer; /*->1st char of string. */
252b5132
RH
4504 start = input_line_pointer;
4505 while (is_a_char (c = next_char_of_string ()))
4506 {
4507 FRAG_APPEND_1_CHAR (c);
4508 }
4509 if (append_zero)
4510 {
4511 FRAG_APPEND_1_CHAR (0);
4512 }
4513 know (input_line_pointer[-1] == '\"');
4514
4515#ifndef NO_LISTING
4516#ifdef OBJ_ELF
4517 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4518 will emit .string with a filename in the .debug section
4519 after a sequence of constants. See the comment in
4520 emit_expr for the sequence. emit_expr will set
4521 dwarf_file_string to non-zero if this string might be a
4522 source file name. */
4523 if (strcmp (segment_name (now_seg), ".debug") != 0)
4524 dwarf_file_string = 0;
4525 else if (dwarf_file_string)
4526 {
4527 c = input_line_pointer[-1];
4528 input_line_pointer[-1] = '\0';
4529 listing_source_file (start);
4530 input_line_pointer[-1] = c;
4531 }
4532#endif
4533#endif
4534
4535 break;
4536 case '<':
4537 input_line_pointer++;
4538 c = get_single_number ();
4539 FRAG_APPEND_1_CHAR (c);
4540 if (*input_line_pointer != '>')
4541 {
4542 as_bad (_("Expected <nn>"));
4543 }
4544 input_line_pointer++;
4545 break;
4546 case ',':
4547 input_line_pointer++;
4548 break;
4549 }
4550 SKIP_WHITESPACE ();
4551 c = *input_line_pointer;
4552 }
4553
4554 demand_empty_rest_of_line ();
4555} /* stringer() */
4556\f
4557/* FIXME-SOMEDAY: I had trouble here on characters with the
4558 high bits set. We'll probably also have trouble with
4559 multibyte chars, wide chars, etc. Also be careful about
041ff4dd 4560 returning values bigger than 1 byte. xoxorich. */
252b5132 4561
041ff4dd 4562unsigned int
252b5132
RH
4563next_char_of_string ()
4564{
4565 register unsigned int c;
4566
4567 c = *input_line_pointer++ & CHAR_MASK;
4568 switch (c)
4569 {
4570 case '\"':
4571 c = NOT_A_CHAR;
4572 break;
4573
4574 case '\n':
4575 as_warn (_("Unterminated string: Newline inserted."));
4576 bump_line_counters ();
4577 break;
4578
4579#ifndef NO_STRING_ESCAPES
4580 case '\\':
4581 switch (c = *input_line_pointer++)
4582 {
4583 case 'b':
4584 c = '\b';
4585 break;
4586
4587 case 'f':
4588 c = '\f';
4589 break;
4590
4591 case 'n':
4592 c = '\n';
4593 break;
4594
4595 case 'r':
4596 c = '\r';
4597 break;
4598
4599 case 't':
4600 c = '\t';
4601 break;
4602
4603 case 'v':
4604 c = '\013';
4605 break;
4606
4607 case '\\':
4608 case '"':
041ff4dd 4609 break; /* As itself. */
252b5132
RH
4610
4611 case '0':
4612 case '1':
4613 case '2':
4614 case '3':
4615 case '4':
4616 case '5':
4617 case '6':
4618 case '7':
4619 case '8':
4620 case '9':
4621 {
4622 long number;
4623 int i;
4624
041ff4dd
NC
4625 for (i = 0, number = 0;
4626 isdigit (c) && i < 3;
4627 c = *input_line_pointer++, i++)
252b5132
RH
4628 {
4629 number = number * 8 + c - '0';
4630 }
f0e652b4 4631
252b5132
RH
4632 c = number & 0xff;
4633 }
4634 --input_line_pointer;
4635 break;
4636
4637 case 'x':
4638 case 'X':
4639 {
4640 long number;
4641
4642 number = 0;
4643 c = *input_line_pointer++;
4644 while (isxdigit (c))
4645 {
4646 if (isdigit (c))
4647 number = number * 16 + c - '0';
4648 else if (isupper (c))
4649 number = number * 16 + c - 'A' + 10;
4650 else
4651 number = number * 16 + c - 'a' + 10;
4652 c = *input_line_pointer++;
4653 }
4654 c = number & 0xff;
4655 --input_line_pointer;
4656 }
4657 break;
4658
4659 case '\n':
041ff4dd 4660 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
252b5132
RH
4661 as_warn (_("Unterminated string: Newline inserted."));
4662 c = '\n';
4663 bump_line_counters ();
4664 break;
4665
4666 default:
4667
4668#ifdef ONLY_STANDARD_ESCAPES
4669 as_bad (_("Bad escaped character in string, '?' assumed"));
4670 c = '?';
4671#endif /* ONLY_STANDARD_ESCAPES */
4672
4673 break;
041ff4dd 4674 }
252b5132
RH
4675 break;
4676#endif /* ! defined (NO_STRING_ESCAPES) */
4677
4678 default:
4679 break;
041ff4dd 4680 }
252b5132 4681 return (c);
041ff4dd 4682}
252b5132
RH
4683\f
4684static segT
4685get_segmented_expression (expP)
4686 register expressionS *expP;
4687{
4688 register segT retval;
4689
4690 retval = expression (expP);
4691 if (expP->X_op == O_illegal
4692 || expP->X_op == O_absent
4693 || expP->X_op == O_big)
4694 {
4695 as_bad (_("expected address expression; zero assumed"));
4696 expP->X_op = O_constant;
4697 expP->X_add_number = 0;
4698 retval = absolute_section;
4699 }
4700 return retval;
4701}
4702
041ff4dd 4703static segT
252b5132
RH
4704get_known_segmented_expression (expP)
4705 register expressionS *expP;
4706{
4707 register segT retval;
4708
4709 if ((retval = get_segmented_expression (expP)) == undefined_section)
4710 {
4711 /* There is no easy way to extract the undefined symbol from the
4712 expression. */
4713 if (expP->X_add_symbol != NULL
4714 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4715 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4716 S_GET_NAME (expP->X_add_symbol));
4717 else
4718 as_warn (_("some symbol undefined; zero assumed"));
4719 retval = absolute_section;
4720 expP->X_op = O_constant;
4721 expP->X_add_number = 0;
4722 }
4723 know (retval == absolute_section || SEG_NORMAL (retval));
4724 return (retval);
041ff4dd 4725}
252b5132
RH
4726
4727offsetT
4728get_absolute_expression ()
4729{
4730 expressionS exp;
4731
4732 expression (&exp);
4733 if (exp.X_op != O_constant)
4734 {
4735 if (exp.X_op != O_absent)
4736 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4737 exp.X_add_number = 0;
4738 }
4739 return exp.X_add_number;
4740}
4741
041ff4dd 4742char /* Return terminator. */
252b5132 4743get_absolute_expression_and_terminator (val_pointer)
041ff4dd 4744 long *val_pointer; /* Return value of expression. */
252b5132
RH
4745{
4746 /* FIXME: val_pointer should probably be offsetT *. */
4747 *val_pointer = (long) get_absolute_expression ();
4748 return (*input_line_pointer++);
4749}
4750\f
041ff4dd
NC
4751/* Like demand_copy_string, but return NULL if the string contains any '\0's.
4752 Give a warning if that happens. */
4753
252b5132
RH
4754char *
4755demand_copy_C_string (len_pointer)
4756 int *len_pointer;
4757{
4758 register char *s;
4759
4760 if ((s = demand_copy_string (len_pointer)) != 0)
4761 {
4762 register int len;
4763
4764 for (len = *len_pointer; len > 0; len--)
4765 {
4766 if (*s == 0)
4767 {
4768 s = 0;
4769 len = 1;
4770 *len_pointer = 0;
4771 as_bad (_("This string may not contain \'\\0\'"));
4772 }
4773 }
4774 }
f0e652b4 4775
252b5132
RH
4776 return s;
4777}
4778\f
041ff4dd
NC
4779/* Demand string, but return a safe (=private) copy of the string.
4780 Return NULL if we can't read a string here. */
4781
252b5132
RH
4782char *
4783demand_copy_string (lenP)
4784 int *lenP;
4785{
4786 register unsigned int c;
4787 register int len;
4788 char *retval;
4789
4790 len = 0;
4791 SKIP_WHITESPACE ();
4792 if (*input_line_pointer == '\"')
4793 {
041ff4dd 4794 input_line_pointer++; /* Skip opening quote. */
252b5132
RH
4795
4796 while (is_a_char (c = next_char_of_string ()))
4797 {
4798 obstack_1grow (&notes, c);
4799 len++;
4800 }
4801 /* JF this next line is so demand_copy_C_string will return a
041ff4dd 4802 null terminated string. */
252b5132
RH
4803 obstack_1grow (&notes, '\0');
4804 retval = obstack_finish (&notes);
4805 }
4806 else
4807 {
4808 as_warn (_("Missing string"));
4809 retval = NULL;
4810 ignore_rest_of_line ();
4811 }
4812 *lenP = len;
4813 return (retval);
041ff4dd 4814}
252b5132 4815\f
041ff4dd 4816/* In: Input_line_pointer->next character.
f0e652b4 4817
041ff4dd 4818 Do: Skip input_line_pointer over all whitespace.
f0e652b4 4819
041ff4dd
NC
4820 Out: 1 if input_line_pointer->end-of-line. */
4821
4822int
252b5132
RH
4823is_it_end_of_statement ()
4824{
4825 SKIP_WHITESPACE ();
4826 return (is_end_of_line[(unsigned char) *input_line_pointer]);
041ff4dd 4827}
252b5132 4828
041ff4dd 4829void
252b5132
RH
4830equals (sym_name, reassign)
4831 char *sym_name;
4832 int reassign;
4833{
041ff4dd 4834 register symbolS *symbolP; /* Symbol we are working with. */
252b5132
RH
4835 char *stop = NULL;
4836 char stopc;
4837
4838 input_line_pointer++;
4839 if (*input_line_pointer == '=')
4840 input_line_pointer++;
4841
4842 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4843 input_line_pointer++;
4844
4845 if (flag_mri)
4846 stop = mri_comment_field (&stopc);
4847
4848 if (sym_name[0] == '.' && sym_name[1] == '\0')
4849 {
041ff4dd 4850 /* Turn '. = mumble' into a .org mumble. */
252b5132
RH
4851 register segT segment;
4852 expressionS exp;
4853
4854 segment = get_known_segmented_expression (&exp);
4855 if (!need_pass_2)
4856 do_org (segment, &exp, 0);
4857 }
4858 else
4859 {
440ecb38
L
4860#ifdef OBJ_COFF
4861 int local;
4862
4863 symbolP = symbol_find (sym_name);
4864 local = symbolP == NULL;
4865 if (local)
4866#endif /* OBJ_COFF */
252b5132
RH
4867 symbolP = symbol_find_or_make (sym_name);
4868 /* Permit register names to be redefined. */
041ff4dd 4869 if (!reassign
252b5132
RH
4870 && S_IS_DEFINED (symbolP)
4871 && S_GET_SEGMENT (symbolP) != reg_section)
4872 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
775cf891
NC
4873
4874#ifdef OBJ_COFF
4875 /* "set" symbols are local unless otherwise specified. */
440ecb38
L
4876 if (local)
4877 SF_SET_LOCAL (symbolP);
775cf891
NC
4878#endif /* OBJ_COFF */
4879
252b5132
RH
4880 pseudo_set (symbolP);
4881 }
4882
4883 if (flag_mri)
041ff4dd
NC
4884 {
4885 /* Check garbage after the expression. */
4886 ignore_rest_of_line ();
4887 mri_comment_end (stop, stopc);
4888 }
4889}
252b5132 4890
041ff4dd 4891/* .include -- include a file at this point. */
252b5132 4892
041ff4dd 4893void
252b5132 4894s_include (arg)
ab9da554 4895 int arg ATTRIBUTE_UNUSED;
252b5132 4896{
252b5132
RH
4897 char *filename;
4898 int i;
4899 FILE *try;
4900 char *path;
4901
041ff4dd 4902 if (!flag_m68k_mri)
252b5132
RH
4903 {
4904 filename = demand_copy_string (&i);
4905 if (filename == NULL)
4906 {
4907 /* demand_copy_string has already printed an error and
4908 called ignore_rest_of_line. */
4909 return;
4910 }
4911 }
4912 else
4913 {
4914 SKIP_WHITESPACE ();
4915 i = 0;
041ff4dd 4916 while (!is_end_of_line[(unsigned char) *input_line_pointer]
252b5132
RH
4917 && *input_line_pointer != ' '
4918 && *input_line_pointer != '\t')
4919 {
4920 obstack_1grow (&notes, *input_line_pointer);
4921 ++input_line_pointer;
4922 ++i;
4923 }
f0e652b4 4924
252b5132
RH
4925 obstack_1grow (&notes, '\0');
4926 filename = obstack_finish (&notes);
041ff4dd 4927 while (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
4928 ++input_line_pointer;
4929 }
f0e652b4 4930
252b5132
RH
4931 demand_empty_rest_of_line ();
4932 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
f0e652b4 4933
252b5132
RH
4934 for (i = 0; i < include_dir_count; i++)
4935 {
4936 strcpy (path, include_dirs[i]);
4937 strcat (path, "/");
4938 strcat (path, filename);
4939 if (0 != (try = fopen (path, "r")))
4940 {
4941 fclose (try);
4942 goto gotit;
4943 }
4944 }
f0e652b4 4945
252b5132
RH
4946 free (path);
4947 path = filename;
4948gotit:
041ff4dd 4949 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
252b5132 4950 register_dependency (path);
9f10757c 4951 input_scrub_insert_file (path);
041ff4dd 4952}
252b5132 4953
041ff4dd 4954void
252b5132
RH
4955add_include_dir (path)
4956 char *path;
4957{
4958 int i;
4959
4960 if (include_dir_count == 0)
4961 {
4962 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
041ff4dd 4963 include_dirs[0] = "."; /* Current dir. */
252b5132
RH
4964 include_dir_count = 2;
4965 }
4966 else
4967 {
4968 include_dir_count++;
041ff4dd
NC
4969 include_dirs =
4970 (char **) realloc (include_dirs,
4971 include_dir_count * sizeof (*include_dirs));
252b5132
RH
4972 }
4973
041ff4dd 4974 include_dirs[include_dir_count - 1] = path; /* New one. */
252b5132
RH
4975
4976 i = strlen (path);
4977 if (i > include_dir_maxlen)
4978 include_dir_maxlen = i;
041ff4dd 4979}
252b5132
RH
4980\f
4981/* Output debugging information to denote the source file. */
4982
4983static void
4984generate_file_debug ()
4985{
4986 if (debug_type == DEBUG_STABS)
4987 stabs_generate_asm_file ();
4988}
4989
4990/* Output line number debugging information for the current source line. */
4991
4992void
4993generate_lineno_debug ()
4994{
252b5132
RH
4995 switch (debug_type)
4996 {
4997 case DEBUG_UNSPECIFIED:
4998 case DEBUG_NONE:
4dc7ead9 4999 case DEBUG_DWARF:
252b5132
RH
5000 break;
5001 case DEBUG_STABS:
5002 stabs_generate_asm_lineno ();
5003 break;
5004 case DEBUG_ECOFF:
5005 ecoff_generate_asm_lineno ();
5006 break;
252b5132 5007 case DEBUG_DWARF2:
4dc7ead9
RH
5008 /* ??? We could here indicate to dwarf2dbg.c that something
5009 has changed. However, since there is additional backend
5010 support that is required (calling dwarf2_emit_insn), we
5011 let dwarf2dbg.c call as_where on its own. */
252b5132
RH
5012 break;
5013 }
5014}
5015
5016/* Output debugging information to mark a function entry point or end point.
5017 END_P is zero for .func, and non-zero for .endfunc. */
5018
5019void
5020s_func (end_p)
5021 int end_p;
5022{
5023 do_s_func (end_p, NULL);
5024}
5025
5026/* Subroutine of s_func so targets can choose a different default prefix.
5027 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5028
5029void
5030do_s_func (end_p, default_prefix)
5031 int end_p;
5032 const char *default_prefix;
5033{
5034 /* Record the current function so that we can issue an error message for
5035 misplaced .func,.endfunc, and also so that .endfunc needs no
5036 arguments. */
5037 static char *current_name;
5038 static char *current_label;
5039
5040 if (end_p)
5041 {
5042 if (current_name == NULL)
5043 {
5044 as_bad (_("missing .func"));
5045 ignore_rest_of_line ();
5046 return;
5047 }
5048
5049 if (debug_type == DEBUG_STABS)
5050 stabs_generate_asm_endfunc (current_name, current_label);
5051
5052 current_name = current_label = NULL;
5053 }
5054 else /* ! end_p */
5055 {
041ff4dd
NC
5056 char *name, *label;
5057 char delim1, delim2;
252b5132
RH
5058
5059 if (current_name != NULL)
5060 {
5061 as_bad (_(".endfunc missing for previous .func"));
5062 ignore_rest_of_line ();
5063 return;
5064 }
5065
5066 name = input_line_pointer;
5067 delim1 = get_symbol_end ();
5068 name = xstrdup (name);
5069 *input_line_pointer = delim1;
5070 SKIP_WHITESPACE ();
5071 if (*input_line_pointer != ',')
5072 {
5073 if (default_prefix)
5074 asprintf (&label, "%s%s", default_prefix, name);
5075 else
5076 {
5077 char leading_char = 0;
5078#ifdef BFD_ASSEMBLER
5079 leading_char = bfd_get_symbol_leading_char (stdoutput);
5080#endif
5081 /* Missing entry point, use function's name with the leading
5082 char prepended. */
5083 if (leading_char)
5084 asprintf (&label, "%c%s", leading_char, name);
5085 else
5086 label = name;
5087 }
5088 }
5089 else
5090 {
5091 ++input_line_pointer;
5092 SKIP_WHITESPACE ();
5093 label = input_line_pointer;
5094 delim2 = get_symbol_end ();
5095 label = xstrdup (label);
5096 *input_line_pointer = delim2;
5097 }
5098
5099 if (debug_type == DEBUG_STABS)
5100 stabs_generate_asm_func (name, label);
5101
5102 current_name = name;
5103 current_label = label;
5104 }
5105
5106 demand_empty_rest_of_line ();
5107}
5108\f
041ff4dd 5109void
252b5132 5110s_ignore (arg)
ab9da554 5111 int arg ATTRIBUTE_UNUSED;
252b5132
RH
5112{
5113 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5114 {
5115 ++input_line_pointer;
5116 }
5117 ++input_line_pointer;
5118}
5119
252b5132
RH
5120void
5121read_print_statistics (file)
5122 FILE *file;
5123{
5124 hash_print_statistics (file, "pseudo-op table", po_hash);
5125}
5126
041ff4dd
NC
5127/* Inserts the given line into the input stream.
5128
9f10757c
TW
5129 This call avoids macro/conditionals nesting checking, since the contents of
5130 the line are assumed to replace the contents of a line already scanned.
5131
5132 An appropriate use of this function would be substition of input lines when
5133 called by md_start_line_hook(). The given line is assumed to already be
5134 properly scrubbed. */
5135
5136void
5137input_scrub_insert_line (line)
041ff4dd 5138 const char *line;
9f10757c
TW
5139{
5140 sb newline;
5141 sb_new (&newline);
5142 sb_add_string (&newline, line);
5143 input_scrub_include_sb (&newline, input_line_pointer, 0);
5144 sb_kill (&newline);
5145 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5146}
5147
5148/* Insert a file into the input stream; the path must resolve to an actual
041ff4dd 5149 file; no include path searching or dependency registering is performed. */
9f10757c
TW
5150
5151void
5152input_scrub_insert_file (path)
041ff4dd 5153 char *path;
9f10757c
TW
5154{
5155 input_scrub_include_file (path, input_line_pointer);
5156 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5157}
This page took 0.315415 seconds and 4 git commands to generate.