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