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