Subversion Repositories Kolibri OS

Rev

Rev 5222 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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