Back to index

cell-binutils  2.17cvs20070401
read.c
Go to the documentation of this file.
00001 /* read.c - read a source file -
00002    Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
00003    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00004    Free Software Foundation, Inc.
00005 
00006 This file is part of GAS, the GNU Assembler.
00007 
00008 GAS is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2, or (at your option)
00011 any later version.
00012 
00013 GAS is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with GAS; see the file COPYING.  If not, write to the Free
00020 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00021 02110-1301, USA.  */
00022 
00023 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
00024    But then, GNU isn't spozed to run on your machine anyway.
00025    (RMS is so shortsighted sometimes.)  */
00026 #define MASK_CHAR ((int)(unsigned char) -1)
00027 
00028 /* This is the largest known floating point format (for now). It will
00029    grow when we do 4361 style flonums.  */
00030 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
00031 
00032 /* Routines that read assembler source text to build spaghetti in memory.
00033    Another group of these functions is in the expr.c module.  */
00034 
00035 #include "as.h"
00036 #include "safe-ctype.h"
00037 #include "subsegs.h"
00038 #include "sb.h"
00039 #include "macro.h"
00040 #include "obstack.h"
00041 #include "ecoff.h"
00042 #include "dw2gencfi.h"
00043 
00044 #ifndef TC_START_LABEL
00045 #define TC_START_LABEL(x,y) (x == ':')
00046 #endif
00047 
00048 /* Set by the object-format or the target.  */
00049 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
00050 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR)        \
00051   do                                                    \
00052     {                                                   \
00053       if ((SIZE) >= 8)                                         \
00054        (P2VAR) = 3;                                     \
00055       else if ((SIZE) >= 4)                             \
00056        (P2VAR) = 2;                                     \
00057       else if ((SIZE) >= 2)                             \
00058        (P2VAR) = 1;                                     \
00059       else                                              \
00060        (P2VAR) = 0;                                     \
00061     }                                                   \
00062   while (0)
00063 #endif
00064 
00065 char *input_line_pointer;   /*->next char of source file to parse.  */
00066 
00067 #if BITS_PER_CHAR != 8
00068 /*  The following table is indexed by[(char)] and will break if
00069     a char does not have exactly 256 states (hopefully 0:255!)!  */
00070 die horribly;
00071 #endif
00072 
00073 #ifndef LEX_AT
00074 #define LEX_AT 0
00075 #endif
00076 
00077 #ifndef LEX_BR
00078 /* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
00079 #define LEX_BR 0
00080 #endif
00081 
00082 #ifndef LEX_PCT
00083 /* The Delta 68k assembler permits % inside label names.  */
00084 #define LEX_PCT 0
00085 #endif
00086 
00087 #ifndef LEX_QM
00088 /* The PowerPC Windows NT assemblers permits ? inside label names.  */
00089 #define LEX_QM 0
00090 #endif
00091 
00092 #ifndef LEX_HASH
00093 /* The IA-64 assembler uses # as a suffix designating a symbol.  We include
00094    it in the symbol and strip it out in tc_canonicalize_symbol_name.  */
00095 #define LEX_HASH 0
00096 #endif
00097 
00098 #ifndef LEX_DOLLAR
00099 #define LEX_DOLLAR 3
00100 #endif
00101 
00102 #ifndef LEX_TILDE
00103 /* The Delta 68k assembler permits ~ at start of label names.  */
00104 #define LEX_TILDE 0
00105 #endif
00106 
00107 /* Used by is_... macros. our ctype[].  */
00108 char lex_type[256] = {
00109   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* @ABCDEFGHIJKLMNO */
00110   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* PQRSTUVWXYZ[\]^_ */
00111   0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
00112   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM,  /* 0123456789:;<=>? */
00113   LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  /* @ABCDEFGHIJKLMNO */
00114   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
00115   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,       /* `abcdefghijklmno */
00116   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~.  */
00117   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00118   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00119   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00120   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00121   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00122   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00123   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00124   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
00125 };
00126 
00127 /* In: a character.
00128    Out: 1 if this character ends a line.  */
00129 char is_end_of_line[256] = {
00130 #ifdef CR_EOL
00131   1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,       /* @abcdefghijklmno */
00132 #else
00133   1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,       /* @abcdefghijklmno */
00134 #endif
00135   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00136   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* _!"#$%&'()*+,-./ */
00137   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* 0123456789:;<=>? */
00138   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00139   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00140   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00141   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00142   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00143   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00144   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00145   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00146   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00147   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00148   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
00149   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
00150 };
00151 
00152 #ifndef TC_CASE_SENSITIVE
00153 char original_case_string[128];
00154 #endif
00155 
00156 /* Functions private to this file.  */
00157 
00158 static char *buffer; /* 1st char of each buffer of lines is here.  */
00159 static char *buffer_limit;  /*->1 + last char in buffer.  */
00160 
00161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
00162    in the tc-<CPU>.h file.  See the "Porting GAS" section of the
00163    internals manual.  */
00164 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
00165 
00166 /* Variables for handling include file directory table.  */
00167 
00168 /* Table of pointers to directories to search for .include's.  */
00169 char **include_dirs;
00170 
00171 /* How many are in the table.  */
00172 int include_dir_count;
00173 
00174 /* Length of longest in table.  */
00175 int include_dir_maxlen = 1;
00176 
00177 #ifndef WORKING_DOT_WORD
00178 struct broken_word *broken_words;
00179 int new_broken_words;
00180 #endif
00181 
00182 /* The current offset into the absolute section.  We don't try to
00183    build frags in the absolute section, since no data can be stored
00184    there.  We just keep track of the current offset.  */
00185 addressT abs_section_offset;
00186 
00187 /* If this line had an MRI style label, it is stored in this variable.
00188    This is used by some of the MRI pseudo-ops.  */
00189 symbolS *line_label;
00190 
00191 /* This global variable is used to support MRI common sections.  We
00192    translate such sections into a common symbol.  This variable is
00193    non-NULL when we are in an MRI common section.  */
00194 symbolS *mri_common_symbol;
00195 
00196 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
00197    need to align to an even byte boundary unless the next pseudo-op is
00198    dc.b, ds.b, or dcb.b.  This variable is set to 1 if an alignment
00199    may be needed.  */
00200 static int mri_pending_align;
00201 
00202 #ifndef NO_LISTING
00203 #ifdef OBJ_ELF
00204 /* This variable is set to be non-zero if the next string we see might
00205    be the name of the source file in DWARF debugging information.  See
00206    the comment in emit_expr for the format we look for.  */
00207 static int dwarf_file_string;
00208 #endif
00209 #endif
00210 
00211 static void do_s_func (int end_p, const char *default_prefix);
00212 static void do_align (int, char *, int, int);
00213 static void s_align (int, int);
00214 static void s_altmacro (int);
00215 static void s_bad_end (int);
00216 static void s_reloc (int);
00217 static int hex_float (int, char *);
00218 static segT get_known_segmented_expression (expressionS * expP);
00219 static void pobegin (void);
00220 static int get_line_sb (sb *);
00221 static void generate_file_debug (void);
00222 static char *_find_end_of_line (char *, int, int);
00223 
00224 void
00225 read_begin (void)
00226 {
00227   const char *p;
00228 
00229   pobegin ();
00230   obj_read_begin_hook ();
00231 
00232   /* Something close -- but not too close -- to a multiple of 1024.
00233      The debugging malloc I'm using has 24 bytes of overhead.  */
00234   obstack_begin (&notes, chunksize);
00235   obstack_begin (&cond_obstack, chunksize);
00236 
00237   /* Use machine dependent syntax.  */
00238   for (p = line_separator_chars; *p; p++)
00239     is_end_of_line[(unsigned char) *p] = 1;
00240   /* Use more.  FIXME-SOMEDAY.  */
00241 
00242   if (flag_mri)
00243     lex_type['?'] = 3;
00244 }
00245 
00246 #ifndef TC_ADDRESS_BYTES
00247 #define TC_ADDRESS_BYTES address_bytes
00248 
00249 static inline int
00250 address_bytes (void)
00251 {
00252   /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
00253      contain an address.  */
00254   int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
00255   n |= n >> 1;
00256   n |= n >> 2;
00257   n += 1;
00258   return n;
00259 }
00260 #endif
00261 
00262 /* Set up pseudo-op tables.  */
00263 
00264 static struct hash_control *po_hash;
00265 
00266 static const pseudo_typeS potable[] = {
00267   {"abort", s_abort, 0},
00268   {"align", s_align_ptwo, 0},
00269   {"altmacro", s_altmacro, 1},
00270   {"ascii", stringer, 0},
00271   {"asciz", stringer, 1},
00272   {"balign", s_align_bytes, 0},
00273   {"balignw", s_align_bytes, -2},
00274   {"balignl", s_align_bytes, -4},
00275 /* block  */
00276   {"byte", cons, 1},
00277   {"comm", s_comm, 0},
00278   {"common", s_mri_common, 0},
00279   {"common.s", s_mri_common, 1},
00280   {"data", s_data, 0},
00281   {"dc", cons, 2},
00282 #ifdef TC_ADDRESS_BYTES
00283   {"dc.a", cons, 0},
00284 #endif
00285   {"dc.b", cons, 1},
00286   {"dc.d", float_cons, 'd'},
00287   {"dc.l", cons, 4},
00288   {"dc.s", float_cons, 'f'},
00289   {"dc.w", cons, 2},
00290   {"dc.x", float_cons, 'x'},
00291   {"dcb", s_space, 2},
00292   {"dcb.b", s_space, 1},
00293   {"dcb.d", s_float_space, 'd'},
00294   {"dcb.l", s_space, 4},
00295   {"dcb.s", s_float_space, 'f'},
00296   {"dcb.w", s_space, 2},
00297   {"dcb.x", s_float_space, 'x'},
00298   {"ds", s_space, 2},
00299   {"ds.b", s_space, 1},
00300   {"ds.d", s_space, 8},
00301   {"ds.l", s_space, 4},
00302   {"ds.p", s_space, 12},
00303   {"ds.s", s_space, 4},
00304   {"ds.w", s_space, 2},
00305   {"ds.x", s_space, 12},
00306   {"debug", s_ignore, 0},
00307 #ifdef S_SET_DESC
00308   {"desc", s_desc, 0},
00309 #endif
00310 /* dim  */
00311   {"double", float_cons, 'd'},
00312 /* dsect  */
00313   {"eject", listing_eject, 0},     /* Formfeed listing.  */
00314   {"else", s_else, 0},
00315   {"elsec", s_else, 0},
00316   {"elseif", s_elseif, (int) O_ne},
00317   {"end", s_end, 0},
00318   {"endc", s_endif, 0},
00319   {"endfunc", s_func, 1},
00320   {"endif", s_endif, 0},
00321   {"endm", s_bad_end, 0},
00322   {"endr", s_bad_end, 1},
00323 /* endef  */
00324   {"equ", s_set, 0},
00325   {"equiv", s_set, 1},
00326   {"eqv", s_set, -1},
00327   {"err", s_err, 0},
00328   {"error", s_errwarn, 1},
00329   {"exitm", s_mexit, 0},
00330 /* extend  */
00331   {"extern", s_ignore, 0},  /* We treat all undef as ext.  */
00332   {"appfile", s_app_file, 1},
00333   {"appline", s_app_line, 1},
00334   {"fail", s_fail, 0},
00335   {"file", s_app_file, 0},
00336   {"fill", s_fill, 0},
00337   {"float", float_cons, 'f'},
00338   {"format", s_ignore, 0},
00339   {"func", s_func, 0},
00340   {"global", s_globl, 0},
00341   {"globl", s_globl, 0},
00342   {"hword", cons, 2},
00343   {"if", s_if, (int) O_ne},
00344   {"ifb", s_ifb, 1},
00345   {"ifc", s_ifc, 0},
00346   {"ifdef", s_ifdef, 0},
00347   {"ifeq", s_if, (int) O_eq},
00348   {"ifeqs", s_ifeqs, 0},
00349   {"ifge", s_if, (int) O_ge},
00350   {"ifgt", s_if, (int) O_gt},
00351   {"ifle", s_if, (int) O_le},
00352   {"iflt", s_if, (int) O_lt},
00353   {"ifnb", s_ifb, 0},
00354   {"ifnc", s_ifc, 1},
00355   {"ifndef", s_ifdef, 1},
00356   {"ifne", s_if, (int) O_ne},
00357   {"ifnes", s_ifeqs, 1},
00358   {"ifnotdef", s_ifdef, 1},
00359   {"incbin", s_incbin, 0},
00360   {"include", s_include, 0},
00361   {"int", cons, 4},
00362   {"irp", s_irp, 0},
00363   {"irep", s_irp, 0},
00364   {"irpc", s_irp, 1},
00365   {"irepc", s_irp, 1},
00366   {"lcomm", s_lcomm, 0},
00367   {"lflags", listing_flags, 0},    /* Listing flags.  */
00368   {"linefile", s_app_line, 0},
00369   {"linkonce", s_linkonce, 0},
00370   {"list", listing_list, 1},       /* Turn listing on.  */
00371   {"llen", listing_psize, 1},
00372   {"long", cons, 4},
00373   {"lsym", s_lsym, 0},
00374   {"macro", s_macro, 0},
00375   {"mexit", s_mexit, 0},
00376   {"mri", s_mri, 0},
00377   {".mri", s_mri, 0},       /* Special case so .mri works in MRI mode.  */
00378   {"name", s_ignore, 0},
00379   {"noaltmacro", s_altmacro, 0},
00380   {"noformat", s_ignore, 0},
00381   {"nolist", listing_list, 0},     /* Turn listing off.  */
00382   {"nopage", listing_nopage, 0},
00383   {"octa", cons, 16},
00384   {"offset", s_struct, 0},
00385   {"org", s_org, 0},
00386   {"p2align", s_align_ptwo, 0},
00387   {"p2alignw", s_align_ptwo, -2},
00388   {"p2alignl", s_align_ptwo, -4},
00389   {"page", listing_eject, 0},
00390   {"plen", listing_psize, 0},
00391   {"print", s_print, 0},
00392   {"psize", listing_psize, 0},     /* Set paper size.  */
00393   {"purgem", s_purgem, 0},
00394   {"quad", cons, 8},
00395   {"reloc", s_reloc, 0},
00396   {"rep", s_rept, 0},
00397   {"rept", s_rept, 0},
00398   {"rva", s_rva, 4},
00399   {"sbttl", listing_title, 1},     /* Subtitle of listing.  */
00400 /* scl  */
00401 /* sect  */
00402   {"set", s_set, 0},
00403   {"short", cons, 2},
00404   {"single", float_cons, 'f'},
00405 /* size  */
00406   {"space", s_space, 0},
00407   {"skip", s_space, 0},
00408   {"sleb128", s_leb128, 1},
00409   {"spc", s_ignore, 0},
00410   {"stabd", s_stab, 'd'},
00411   {"stabn", s_stab, 'n'},
00412   {"stabs", s_stab, 's'},
00413   {"string", stringer, 1},
00414   {"struct", s_struct, 0},
00415 /* tag  */
00416   {"text", s_text, 0},
00417 
00418   /* This is for gcc to use.  It's only just been added (2/94), so gcc
00419      won't be able to use it for a while -- probably a year or more.
00420      But once this has been released, check with gcc maintainers
00421      before deleting it or even changing the spelling.  */
00422   {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
00423   /* If we're folding case -- done for some targets, not necessarily
00424      all -- the above string in an input file will be converted to
00425      this one.  Match it either way...  */
00426   {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
00427 
00428   {"title", listing_title, 0},     /* Listing title.  */
00429   {"ttl", listing_title, 0},
00430 /* type  */
00431   {"uleb128", s_leb128, 0},
00432 /* use  */
00433 /* val  */
00434   {"xcom", s_comm, 0},
00435   {"xdef", s_globl, 0},
00436   {"xref", s_ignore, 0},
00437   {"xstabs", s_xstab, 's'},
00438   {"warning", s_errwarn, 0},
00439   {"weakref", s_weakref, 0},
00440   {"word", cons, 2},
00441   {"zero", s_space, 0},
00442   {NULL, NULL, 0}                  /* End sentinel.  */
00443 };
00444 
00445 static offsetT
00446 get_absolute_expr (expressionS *exp)
00447 {
00448   expression_and_evaluate (exp);
00449   if (exp->X_op != O_constant)
00450     {
00451       if (exp->X_op != O_absent)
00452        as_bad (_("bad or irreducible absolute expression"));
00453       exp->X_add_number = 0;
00454     }
00455   return exp->X_add_number;
00456 }
00457 
00458 offsetT
00459 get_absolute_expression (void)
00460 {
00461   expressionS exp;
00462 
00463   return get_absolute_expr (&exp);
00464 }
00465 
00466 static int pop_override_ok = 0;
00467 static const char *pop_table_name;
00468 
00469 void
00470 pop_insert (const pseudo_typeS *table)
00471 {
00472   const char *errtxt;
00473   const pseudo_typeS *pop;
00474   for (pop = table; pop->poc_name; pop++)
00475     {
00476       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
00477       if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
00478        as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
00479                 errtxt);
00480     }
00481 }
00482 
00483 #ifndef md_pop_insert
00484 #define md_pop_insert()            pop_insert(md_pseudo_table)
00485 #endif
00486 
00487 #ifndef obj_pop_insert
00488 #define obj_pop_insert()    pop_insert(obj_pseudo_table)
00489 #endif
00490 
00491 #ifndef cfi_pop_insert
00492 #define cfi_pop_insert()    pop_insert(cfi_pseudo_table)
00493 #endif
00494 
00495 static void
00496 pobegin (void)
00497 {
00498   po_hash = hash_new ();
00499 
00500   /* Do the target-specific pseudo ops.  */
00501   pop_table_name = "md";
00502   md_pop_insert ();
00503 
00504   /* Now object specific.  Skip any that were in the target table.  */
00505   pop_table_name = "obj";
00506   pop_override_ok = 1;
00507   obj_pop_insert ();
00508 
00509   /* Now portable ones.  Skip any that we've seen already.  */
00510   pop_table_name = "standard";
00511   pop_insert (potable);
00512 
00513 #ifdef TARGET_USE_CFIPOP
00514   pop_table_name = "cfi";
00515   pop_override_ok = 1;
00516   cfi_pop_insert ();
00517 #endif
00518 }
00519 
00520 #define HANDLE_CONDITIONAL_ASSEMBLY()                                 \
00521   if (ignore_input ())                                                \
00522     {                                                          \
00523       char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri);      \
00524       input_line_pointer = (input_line_pointer <= buffer_limit        \
00525                          && eol >= buffer_limit)               \
00526                         ? buffer_limit                         \
00527                         : eol + 1;                             \
00528       continue;                                                       \
00529     }
00530 
00531 /* This function is used when scrubbing the characters between #APP
00532    and #NO_APP.  */
00533 
00534 static char *scrub_string;
00535 static char *scrub_string_end;
00536 
00537 static int
00538 scrub_from_string (char *buf, int buflen)
00539 {
00540   int copy;
00541 
00542   copy = scrub_string_end - scrub_string;
00543   if (copy > buflen)
00544     copy = buflen;
00545   memcpy (buf, scrub_string, copy);
00546   scrub_string += copy;
00547   return copy;
00548 }
00549 
00550 /* Helper function of read_a_source_file, which tries to expand a macro.  */
00551 static int
00552 try_macro (char term, const char *line)
00553 {
00554   sb out;
00555   const char *err;
00556   macro_entry *macro;
00557 
00558   if (check_macro (line, &out, &err, &macro))
00559     {
00560       if (err != NULL)
00561        as_bad ("%s", err);
00562       *input_line_pointer++ = term;
00563       input_scrub_include_sb (&out,
00564                            input_line_pointer, 1);
00565       sb_kill (&out);
00566       buffer_limit =
00567        input_scrub_next_buffer (&input_line_pointer);
00568 #ifdef md_macro_info
00569       md_macro_info (macro);
00570 #endif
00571       return 1;
00572     }
00573   return 0;
00574 }
00575 
00576 /* We read the file, putting things into a web that represents what we
00577    have been reading.  */
00578 void
00579 read_a_source_file (char *name)
00580 {
00581   register char c;
00582   register char *s;         /* String of symbol, '\0' appended.  */
00583   register int temp;
00584   pseudo_typeS *pop;
00585 
00586 #ifdef WARN_COMMENTS
00587   found_comment = 0;
00588 #endif
00589 
00590   buffer = input_scrub_new_file (name);
00591 
00592   listing_file (name);
00593   listing_newline (NULL);
00594   register_dependency (name);
00595 
00596   /* Generate debugging information before we've read anything in to denote
00597      this file as the "main" source file and not a subordinate one
00598      (e.g. N_SO vs N_SOL in stabs).  */
00599   generate_file_debug ();
00600 
00601   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
00602     {                       /* We have another line to parse.  */
00603 #ifndef NO_LISTING
00604       /* In order to avoid listing macro expansion lines with labels
00605         multiple times, keep track of which line was last issued.  */
00606       static char *last_eol;
00607 
00608       last_eol = NULL;
00609 #endif
00610       know (buffer_limit[-1] == '\n');    /* Must have a sentinel.  */
00611 
00612       while (input_line_pointer < buffer_limit)
00613        {
00614          /* We have more of this buffer to parse.  */
00615 
00616          /* We now have input_line_pointer->1st char of next line.
00617             If input_line_pointer [-1] == '\n' then we just
00618             scanned another line: so bump line counters.  */
00619          if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
00620            {
00621 #ifdef md_start_line_hook
00622              md_start_line_hook ();
00623 #endif
00624              if (input_line_pointer[-1] == '\n')
00625               bump_line_counters ();
00626 
00627              line_label = NULL;
00628 
00629              if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
00630               {
00631                 /* Text at the start of a line must be a label, we
00632                    run down and stick a colon in.  */
00633                 if (is_name_beginner (*input_line_pointer))
00634                   {
00635                     char *line_start = input_line_pointer;
00636                     char c;
00637                     int mri_line_macro;
00638 
00639                     LISTING_NEWLINE ();
00640                     HANDLE_CONDITIONAL_ASSEMBLY ();
00641 
00642                     c = get_symbol_end ();
00643 
00644                     /* In MRI mode, the EQU and MACRO pseudoops must
00645                       be handled specially.  */
00646                     mri_line_macro = 0;
00647                     if (flag_m68k_mri)
00648                      {
00649                        char *rest = input_line_pointer + 1;
00650 
00651                        if (*rest == ':')
00652                          ++rest;
00653                        if (*rest == ' ' || *rest == '\t')
00654                          ++rest;
00655                        if ((strncasecmp (rest, "EQU", 3) == 0
00656                             || strncasecmp (rest, "SET", 3) == 0)
00657                            && (rest[3] == ' ' || rest[3] == '\t'))
00658                          {
00659                            input_line_pointer = rest + 3;
00660                            equals (line_start,
00661                                   strncasecmp (rest, "SET", 3) == 0);
00662                            continue;
00663                          }
00664                        if (strncasecmp (rest, "MACRO", 5) == 0
00665                            && (rest[5] == ' '
00666                               || rest[5] == '\t'
00667                               || is_end_of_line[(unsigned char) rest[5]]))
00668                          mri_line_macro = 1;
00669                      }
00670 
00671                     /* In MRI mode, we need to handle the MACRO
00672                       pseudo-op specially: we don't want to put the
00673                       symbol in the symbol table.  */
00674                     if (!mri_line_macro
00675 #ifdef TC_START_LABEL_WITHOUT_COLON
00676                        && TC_START_LABEL_WITHOUT_COLON(c,
00677                                                    input_line_pointer)
00678 #endif
00679                        )
00680                      line_label = colon (line_start);
00681                     else
00682                      line_label = symbol_create (line_start,
00683                                               absolute_section,
00684                                               (valueT) 0,
00685                                               &zero_address_frag);
00686 
00687                     *input_line_pointer = c;
00688                     if (c == ':')
00689                      input_line_pointer++;
00690                   }
00691               }
00692            }
00693 
00694          /* We are at the beginning of a line, or similar place.
00695             We expect a well-formed assembler statement.
00696             A "symbol-name:" is a statement.
00697 
00698             Depending on what compiler is used, the order of these tests
00699             may vary to catch most common case 1st.
00700             Each test is independent of all other tests at the (top) level.
00701             PLEASE make a compiler that doesn't use this assembler.
00702             It is crufty to waste a compiler's time encoding things for this
00703             assembler, which then wastes more time decoding it.
00704             (And communicating via (linear) files is silly!
00705             If you must pass stuff, please pass a tree!)  */
00706          if ((c = *input_line_pointer++) == '\t'
00707              || c == ' '
00708              || c == '\f'
00709              || c == 0)
00710            c = *input_line_pointer++;
00711 
00712          know (c != ' ');   /* No further leading whitespace.  */
00713 
00714 #ifndef NO_LISTING
00715          /* If listing is on, and we are expanding a macro, then give
00716             the listing code the contents of the expanded line.  */
00717          if (listing)
00718            {
00719              if ((listing & LISTING_MACEXP) && macro_nest > 0)
00720               {
00721                 char *copy;
00722                 int len;
00723 
00724                 /* Find the end of the current expanded macro line.  */
00725                 s = find_end_of_line (input_line_pointer - 1, flag_m68k_mri);
00726 
00727                 if (s != last_eol)
00728                   {
00729                     last_eol = s;
00730                     /* Copy it for safe keeping.  Also give an indication of
00731                       how much macro nesting is involved at this point.  */
00732                     len = s - (input_line_pointer - 1);
00733                     copy = (char *) xmalloc (len + macro_nest + 2);
00734                     memset (copy, '>', macro_nest);
00735                     copy[macro_nest] = ' ';
00736                     memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
00737                     copy[macro_nest + 1 + len] = '\0';
00738 
00739                     /* Install the line with the listing facility.  */
00740                     listing_newline (copy);
00741                   }
00742               }
00743              else
00744               listing_newline (NULL);
00745            }
00746 #endif
00747          /* C is the 1st significant character.
00748             Input_line_pointer points after that character.  */
00749          if (is_name_beginner (c))
00750            {
00751              /* Want user-defined label or pseudo/opcode.  */
00752              HANDLE_CONDITIONAL_ASSEMBLY ();
00753 
00754              s = --input_line_pointer;
00755              c = get_symbol_end ();       /* name's delimiter.  */
00756 
00757              /* C is character after symbol.
00758                That character's place in the input line is now '\0'.
00759                S points to the beginning of the symbol.
00760                  [In case of pseudo-op, s->'.'.]
00761                Input_line_pointer->'\0' where c was.  */
00762              if (TC_START_LABEL (c, input_line_pointer))
00763               {
00764                 if (flag_m68k_mri)
00765                   {
00766                     char *rest = input_line_pointer + 1;
00767 
00768                     /* In MRI mode, \tsym: set 0 is permitted.  */
00769                     if (*rest == ':')
00770                      ++rest;
00771 
00772                     if (*rest == ' ' || *rest == '\t')
00773                      ++rest;
00774 
00775                     if ((strncasecmp (rest, "EQU", 3) == 0
00776                         || strncasecmp (rest, "SET", 3) == 0)
00777                        && (rest[3] == ' ' || rest[3] == '\t'))
00778                      {
00779                        input_line_pointer = rest + 3;
00780                        equals (s, 1);
00781                        continue;
00782                      }
00783                   }
00784 
00785                 line_label = colon (s);   /* User-defined label.  */
00786                 /* Put ':' back for error messages' sake.  */
00787                 *input_line_pointer++ = ':';
00788 #ifdef tc_check_label
00789                 tc_check_label (line_label);
00790 #endif
00791                 /* Input_line_pointer->after ':'.  */
00792                 SKIP_WHITESPACE ();
00793               }
00794               else if (input_line_pointer[1] == '='
00795                      && (c == '='
00796                         || ((c == ' ' || c == '\t')
00797                             && input_line_pointer[2] == '=')))
00798               {
00799                 equals (s, -1);
00800                 demand_empty_rest_of_line ();
00801               }
00802               else if ((c == '='
00803                        || ((c == ' ' || c == '\t')
00804                             && input_line_pointer[1] == '='))
00805 #ifdef TC_EQUAL_IN_INSN
00806                            && !TC_EQUAL_IN_INSN (c, s)
00807 #endif
00808                            )
00809               {
00810                 equals (s, 1);
00811                 demand_empty_rest_of_line ();
00812               }
00813              else
00814               {
00815                 /* Expect pseudo-op or machine instruction.  */
00816                 pop = NULL;
00817 
00818 #ifndef TC_CASE_SENSITIVE
00819                 {
00820                   char *s2 = s;
00821 
00822                   strncpy (original_case_string, s2, sizeof (original_case_string));
00823                   original_case_string[sizeof (original_case_string) - 1] = 0;
00824 
00825                   while (*s2)
00826                     {
00827                      *s2 = TOLOWER (*s2);
00828                      s2++;
00829                     }
00830                 }
00831 #endif
00832                 if (NO_PSEUDO_DOT || flag_m68k_mri)
00833                   {
00834                     /* The MRI assembler uses pseudo-ops without
00835                       a period.  */
00836                     pop = (pseudo_typeS *) hash_find (po_hash, s);
00837                     if (pop != NULL && pop->poc_handler == NULL)
00838                      pop = NULL;
00839                   }
00840 
00841                 if (pop != NULL
00842                     || (!flag_m68k_mri && *s == '.'))
00843                   {
00844                     /* PSEUDO - OP.
00845 
00846                       WARNING: c has next char, which may be end-of-line.
00847                       We lookup the pseudo-op table with s+1 because we
00848                       already know that the pseudo-op begins with a '.'.  */
00849 
00850                     if (pop == NULL)
00851                      pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
00852                     if (pop && !pop->poc_handler)
00853                      pop = NULL;
00854 
00855                     /* In MRI mode, we may need to insert an
00856                       automatic alignment directive.  What a hack
00857                       this is.  */
00858                     if (mri_pending_align
00859                        && (pop == NULL
00860                            || !((pop->poc_handler == cons
00861                                 && pop->poc_val == 1)
00862                                || (pop->poc_handler == s_space
00863                                    && pop->poc_val == 1)
00864 #ifdef tc_conditional_pseudoop
00865                                || tc_conditional_pseudoop (pop)
00866 #endif
00867                                || pop->poc_handler == s_if
00868                                || pop->poc_handler == s_ifdef
00869                                || pop->poc_handler == s_ifc
00870                                || pop->poc_handler == s_ifeqs
00871                                || pop->poc_handler == s_else
00872                                || pop->poc_handler == s_endif
00873                                || pop->poc_handler == s_globl
00874                                || pop->poc_handler == s_ignore)))
00875                      {
00876                        do_align (1, (char *) NULL, 0, 0);
00877                        mri_pending_align = 0;
00878 
00879                        if (line_label != NULL)
00880                          {
00881                            symbol_set_frag (line_label, frag_now);
00882                            S_SET_VALUE (line_label, frag_now_fix ());
00883                          }
00884                      }
00885 
00886                     /* Print the error msg now, while we still can.  */
00887                     if (pop == NULL)
00888                      {
00889                        char *end = input_line_pointer;
00890 
00891                        *input_line_pointer = c;
00892                        s_ignore (0);
00893                        c = *--input_line_pointer;
00894                        *input_line_pointer = '\0';
00895                        if (! macro_defined || ! try_macro (c, s))
00896                          {
00897                            *end = '\0';
00898                            as_bad (_("unknown pseudo-op: `%s'"), s);
00899                            *input_line_pointer++ = c;
00900                          }
00901                        continue;
00902                      }
00903 
00904                     /* Put it back for error messages etc.  */
00905                     *input_line_pointer = c;
00906                     /* The following skip of whitespace is compulsory.
00907                       A well shaped space is sometimes all that separates
00908                       keyword from operands.  */
00909                     if (c == ' ' || c == '\t')
00910                      input_line_pointer++;
00911 
00912                     /* Input_line is restored.
00913                       Input_line_pointer->1st non-blank char
00914                       after pseudo-operation.  */
00915                     (*pop->poc_handler) (pop->poc_val);
00916 
00917                     /* If that was .end, just get out now.  */
00918                     if (pop->poc_handler == s_end)
00919                      goto quit;
00920                   }
00921                 else
00922                   {
00923                     /* WARNING: c has char, which may be end-of-line.  */
00924                     /* Also: input_line_pointer->`\0` where c was.  */
00925                     *input_line_pointer = c;
00926                     input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1);
00927                     c = *input_line_pointer;
00928                     *input_line_pointer = '\0';
00929 
00930                     generate_lineno_debug ();
00931 
00932                     if (macro_defined && try_macro (c, s))
00933                      continue;
00934 
00935                     if (mri_pending_align)
00936                      {
00937                        do_align (1, (char *) NULL, 0, 0);
00938                        mri_pending_align = 0;
00939                        if (line_label != NULL)
00940                          {
00941                            symbol_set_frag (line_label, frag_now);
00942                            S_SET_VALUE (line_label, frag_now_fix ());
00943                          }
00944                      }
00945 
00946                     md_assemble (s);      /* Assemble 1 instruction.  */
00947 
00948                     *input_line_pointer++ = c;
00949 
00950                     /* We resume loop AFTER the end-of-line from
00951                       this instruction.  */
00952                   }
00953               }
00954              continue;
00955            }
00956 
00957          /* Empty statement?  */
00958          if (is_end_of_line[(unsigned char) c])
00959            continue;
00960 
00961          if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
00962            {
00963              /* local label  ("4:")  */
00964              char *backup = input_line_pointer;
00965 
00966              HANDLE_CONDITIONAL_ASSEMBLY ();
00967 
00968              temp = c - '0';
00969 
00970              /* Read the whole number.  */
00971              while (ISDIGIT (*input_line_pointer))
00972               {
00973                 temp = (temp * 10) + *input_line_pointer - '0';
00974                 ++input_line_pointer;
00975               }
00976 
00977              if (LOCAL_LABELS_DOLLAR
00978                 && *input_line_pointer == '$'
00979                 && *(input_line_pointer + 1) == ':')
00980               {
00981                 input_line_pointer += 2;
00982 
00983                 if (dollar_label_defined (temp))
00984                   {
00985                     as_fatal (_("label \"%d$\" redefined"), temp);
00986                   }
00987 
00988                 define_dollar_label (temp);
00989                 colon (dollar_label_name (temp, 0));
00990                 continue;
00991               }
00992 
00993              if (LOCAL_LABELS_FB
00994                 && *input_line_pointer++ == ':')
00995               {
00996                 fb_label_instance_inc (temp);
00997                 colon (fb_label_name (temp, 0));
00998                 continue;
00999               }
01000 
01001              input_line_pointer = backup;
01002            }                /* local label  ("4:") */
01003 
01004          if (c && strchr (line_comment_chars, c))
01005            {                /* Its a comment.  Better say APP or NO_APP.  */
01006              sb sbuf;
01007              char *ends;
01008              char *new_buf;
01009              char *new_tmp;
01010              unsigned int new_length;
01011              char *tmp_buf = 0;
01012 
01013              s = input_line_pointer;
01014              if (strncmp (s, "APP\n", 4))
01015               {
01016                 /* We ignore it.  */
01017                 ignore_rest_of_line ();
01018                 continue;
01019               }
01020              bump_line_counters ();
01021              s += 4;
01022 
01023              sb_new (&sbuf);
01024              ends = strstr (s, "#NO_APP\n");
01025 
01026              if (!ends)
01027               {
01028                 unsigned int tmp_len;
01029                 unsigned int num;
01030 
01031                 /* The end of the #APP wasn't in this buffer.  We
01032                    keep reading in buffers until we find the #NO_APP
01033                    that goes with this #APP  There is one.  The specs
01034                    guarantee it...  */
01035                 tmp_len = buffer_limit - s;
01036                 tmp_buf = xmalloc (tmp_len + 1);
01037                 memcpy (tmp_buf, s, tmp_len);
01038                 do
01039                   {
01040                     new_tmp = input_scrub_next_buffer (&buffer);
01041                     if (!new_tmp)
01042                      break;
01043                     else
01044                      buffer_limit = new_tmp;
01045                     input_line_pointer = buffer;
01046                     ends = strstr (buffer, "#NO_APP\n");
01047                     if (ends)
01048                      num = ends - buffer;
01049                     else
01050                      num = buffer_limit - buffer;
01051 
01052                     tmp_buf = xrealloc (tmp_buf, tmp_len + num);
01053                     memcpy (tmp_buf + tmp_len, buffer, num);
01054                     tmp_len += num;
01055                   }
01056                 while (!ends);
01057 
01058                 input_line_pointer = ends ? ends + 8 : NULL;
01059 
01060                 s = tmp_buf;
01061                 ends = s + tmp_len;
01062 
01063               }
01064              else
01065               {
01066                 input_line_pointer = ends + 8;
01067               }
01068 
01069              scrub_string = s;
01070              scrub_string_end = ends;
01071 
01072              new_length = ends - s;
01073              new_buf = (char *) xmalloc (new_length);
01074              new_tmp = new_buf;
01075              for (;;)
01076               {
01077                 int space;
01078                 int size;
01079 
01080                 space = (new_buf + new_length) - new_tmp;
01081                 size = do_scrub_chars (scrub_from_string, new_tmp, space);
01082 
01083                 if (size < space)
01084                   {
01085                     new_tmp[size] = 0;
01086                     break;
01087                   }
01088 
01089                 new_buf = xrealloc (new_buf, new_length + 100);
01090                 new_tmp = new_buf + new_length;
01091                 new_length += 100;
01092               }
01093 
01094              if (tmp_buf)
01095               free (tmp_buf);
01096 
01097              /* We've "scrubbed" input to the preferred format.  In the
01098                process we may have consumed the whole of the remaining
01099                file (and included files).  We handle this formatted
01100                input similar to that of macro expansion, letting
01101                actual macro expansion (possibly nested) and other
01102                input expansion work.  Beware that in messages, line
01103                numbers and possibly file names will be incorrect.  */
01104              sb_add_string (&sbuf, new_buf);
01105              input_scrub_include_sb (&sbuf, input_line_pointer, 0);
01106              sb_kill (&sbuf);
01107              buffer_limit = input_scrub_next_buffer (&input_line_pointer);
01108              free (new_buf);
01109              continue;
01110            }
01111 
01112          HANDLE_CONDITIONAL_ASSEMBLY ();
01113 
01114 #ifdef tc_unrecognized_line
01115          if (tc_unrecognized_line (c))
01116            continue;
01117 #endif
01118          input_line_pointer--;
01119          /* Report unknown char as error.  */
01120          demand_empty_rest_of_line ();
01121        }
01122 
01123 #ifdef md_after_pass_hook
01124       md_after_pass_hook ();
01125 #endif
01126     }
01127 
01128  quit:
01129 
01130 #ifdef md_cleanup
01131   md_cleanup ();
01132 #endif
01133   /* Close the input file.  */
01134   input_scrub_close ();
01135 #ifdef WARN_COMMENTS
01136   {
01137     if (warn_comment && found_comment)
01138       as_warn_where (found_comment_file, found_comment,
01139                    "first comment found here");
01140   }
01141 #endif
01142 }
01143 
01144 /* Convert O_constant expression EXP into the equivalent O_big representation.
01145    Take the sign of the number from X_unsigned rather than X_add_number.  */
01146 
01147 static void
01148 convert_to_bignum (expressionS *exp)
01149 {
01150   valueT value;
01151   unsigned int i;
01152 
01153   value = exp->X_add_number;
01154   for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
01155     {
01156       generic_bignum[i] = value & LITTLENUM_MASK;
01157       value >>= LITTLENUM_NUMBER_OF_BITS;
01158     }
01159   /* Add a sequence of sign bits if the top bit of X_add_number is not
01160      the sign of the original value.  */
01161   if ((exp->X_add_number < 0) != !exp->X_unsigned)
01162     generic_bignum[i++] = exp->X_unsigned ? 0 : LITTLENUM_MASK;
01163   exp->X_op = O_big;
01164   exp->X_add_number = i;
01165 }
01166 
01167 /* For most MRI pseudo-ops, the line actually ends at the first
01168    nonquoted space.  This function looks for that point, stuffs a null
01169    in, and sets *STOPCP to the character that used to be there, and
01170    returns the location.
01171 
01172    Until I hear otherwise, I am going to assume that this is only true
01173    for the m68k MRI assembler.  */
01174 
01175 char *
01176 mri_comment_field (char *stopcp)
01177 {
01178   char *s;
01179 #ifdef TC_M68K
01180   int inquote = 0;
01181 
01182   know (flag_m68k_mri);
01183 
01184   for (s = input_line_pointer;
01185        ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
01186        || inquote);
01187        s++)
01188     {
01189       if (*s == '\'')
01190        inquote = !inquote;
01191     }
01192 #else
01193   for (s = input_line_pointer;
01194        !is_end_of_line[(unsigned char) *s];
01195        s++)
01196     ;
01197 #endif
01198   *stopcp = *s;
01199   *s = '\0';
01200 
01201   return s;
01202 }
01203 
01204 /* Skip to the end of an MRI comment field.  */
01205 
01206 void
01207 mri_comment_end (char *stop, int stopc)
01208 {
01209   know (flag_mri);
01210 
01211   input_line_pointer = stop;
01212   *stop = stopc;
01213   while (!is_end_of_line[(unsigned char) *input_line_pointer])
01214     ++input_line_pointer;
01215 }
01216 
01217 void
01218 s_abort (int ignore ATTRIBUTE_UNUSED)
01219 {
01220   as_fatal (_(".abort detected.  Abandoning ship."));
01221 }
01222 
01223 /* Guts of .align directive.  N is the power of two to which to align.
01224    FILL may be NULL, or it may point to the bytes of the fill pattern.
01225    LEN is the length of whatever FILL points to, if anything.  MAX is
01226    the maximum number of characters to skip when doing the alignment,
01227    or 0 if there is no maximum.  */
01228 
01229 static void
01230 do_align (int n, char *fill, int len, int max)
01231 {
01232   if (now_seg == absolute_section)
01233     {
01234       if (fill != NULL)
01235        while (len-- > 0)
01236          if (*fill++ != '\0')
01237            {
01238              as_warn (_("ignoring fill value in absolute section"));
01239              break;
01240            }
01241       fill = NULL;
01242       len = 0;
01243     }
01244 
01245 #ifdef md_flush_pending_output
01246   md_flush_pending_output ();
01247 #endif
01248 #ifdef md_do_align
01249   md_do_align (n, fill, len, max, just_record_alignment);
01250 #endif
01251 
01252   /* Only make a frag if we HAVE to...  */
01253   if (n != 0 && !need_pass_2)
01254     {
01255       if (fill == NULL)
01256        {
01257          if (subseg_text_p (now_seg))
01258            frag_align_code (n, max);
01259          else
01260            frag_align (n, 0, max);
01261        }
01262       else if (len <= 1)
01263        frag_align (n, *fill, max);
01264       else
01265        frag_align_pattern (n, fill, len, max);
01266     }
01267 
01268 #ifdef md_do_align
01269  just_record_alignment: ATTRIBUTE_UNUSED_LABEL
01270 #endif
01271 
01272   record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
01273 }
01274 
01275 /* Handle the .align pseudo-op.  A positive ARG is a default alignment
01276    (in bytes).  A negative ARG is the negative of the length of the
01277    fill pattern.  BYTES_P is non-zero if the alignment value should be
01278    interpreted as the byte boundary, rather than the power of 2.  */
01279 
01280 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
01281 
01282 static void
01283 s_align (int arg, int bytes_p)
01284 {
01285   unsigned int align_limit = ALIGN_LIMIT;
01286   unsigned int align;
01287   char *stop = NULL;
01288   char stopc = 0;
01289   offsetT fill = 0;
01290   int max;
01291   int fill_p;
01292 
01293   if (flag_mri)
01294     stop = mri_comment_field (&stopc);
01295 
01296   if (is_end_of_line[(unsigned char) *input_line_pointer])
01297     {
01298       if (arg < 0)
01299        align = 0;
01300       else
01301        align = arg;  /* Default value from pseudo-op table.  */
01302     }
01303   else
01304     {
01305       align = get_absolute_expression ();
01306       SKIP_WHITESPACE ();
01307     }
01308 
01309   if (bytes_p)
01310     {
01311       /* Convert to a power of 2.  */
01312       if (align != 0)
01313        {
01314          unsigned int i;
01315 
01316          for (i = 0; (align & 1) == 0; align >>= 1, ++i)
01317            ;
01318          if (align != 1)
01319            as_bad (_("alignment not a power of 2"));
01320 
01321          align = i;
01322        }
01323     }
01324 
01325   if (align > align_limit)
01326     {
01327       align = align_limit;
01328       as_warn (_("alignment too large: %u assumed"), align);
01329     }
01330 
01331   if (*input_line_pointer != ',')
01332     {
01333       fill_p = 0;
01334       max = 0;
01335     }
01336   else
01337     {
01338       ++input_line_pointer;
01339       if (*input_line_pointer == ',')
01340        fill_p = 0;
01341       else
01342        {
01343          fill = get_absolute_expression ();
01344          SKIP_WHITESPACE ();
01345          fill_p = 1;
01346        }
01347 
01348       if (*input_line_pointer != ',')
01349        max = 0;
01350       else
01351        {
01352          ++input_line_pointer;
01353          max = get_absolute_expression ();
01354        }
01355     }
01356 
01357   if (!fill_p)
01358     {
01359       if (arg < 0)
01360        as_warn (_("expected fill pattern missing"));
01361       do_align (align, (char *) NULL, 0, max);
01362     }
01363   else
01364     {
01365       int fill_len;
01366 
01367       if (arg >= 0)
01368        fill_len = 1;
01369       else
01370        fill_len = -arg;
01371       if (fill_len <= 1)
01372        {
01373          char fill_char;
01374 
01375          fill_char = fill;
01376          do_align (align, &fill_char, fill_len, max);
01377        }
01378       else
01379        {
01380          char ab[16];
01381 
01382          if ((size_t) fill_len > sizeof ab)
01383            abort ();
01384          md_number_to_chars (ab, fill, fill_len);
01385          do_align (align, ab, fill_len, max);
01386        }
01387     }
01388 
01389   demand_empty_rest_of_line ();
01390 
01391   if (flag_mri)
01392     mri_comment_end (stop, stopc);
01393 }
01394 
01395 /* Handle the .align pseudo-op on machines where ".align 4" means
01396    align to a 4 byte boundary.  */
01397 
01398 void
01399 s_align_bytes (int arg)
01400 {
01401   s_align (arg, 1);
01402 }
01403 
01404 /* Handle the .align pseudo-op on machines where ".align 4" means align
01405    to a 2**4 boundary.  */
01406 
01407 void
01408 s_align_ptwo (int arg)
01409 {
01410   s_align (arg, 0);
01411 }
01412 
01413 /* Switch in and out of alternate macro mode.  */
01414 
01415 void
01416 s_altmacro (int on)
01417 {
01418   demand_empty_rest_of_line ();
01419   macro_set_alternate (on);
01420 }
01421 
01422 symbolS *
01423 s_comm_internal (int param,
01424                symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
01425 {
01426   char *name;
01427   char c;
01428   char *p;
01429   offsetT temp, size;
01430   symbolS *symbolP = NULL;
01431   char *stop = NULL;
01432   char stopc = 0;
01433   expressionS exp;
01434 
01435   if (flag_mri)
01436     stop = mri_comment_field (&stopc);
01437 
01438   name = input_line_pointer;
01439   c = get_symbol_end ();
01440   /* Just after name is now '\0'.  */
01441   p = input_line_pointer;
01442   *p = c;
01443 
01444   if (name == p)
01445     {
01446       as_bad (_("expected symbol name"));
01447       ignore_rest_of_line ();
01448       goto out;
01449     }
01450 
01451   SKIP_WHITESPACE ();
01452 
01453   /* Accept an optional comma after the name.  The comma used to be
01454      required, but Irix 5 cc does not generate it for .lcomm.  */
01455   if (*input_line_pointer == ',')
01456     input_line_pointer++;
01457 
01458   temp = get_absolute_expr (&exp);
01459   size = temp;
01460   size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
01461   if (exp.X_op == O_absent)
01462     {
01463       as_bad (_("missing size expression"));
01464       ignore_rest_of_line ();
01465       goto out;
01466     }
01467   else if (temp != size || !exp.X_unsigned)
01468     {
01469       as_warn (_("size (%ld) out of range, ignored"), (long) temp);
01470       ignore_rest_of_line ();
01471       goto out;
01472     }
01473 
01474   *p = 0;
01475   symbolP = symbol_find_or_make (name);
01476   if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
01477       && !S_IS_COMMON (symbolP))
01478     {
01479       if (!S_IS_VOLATILE (symbolP))
01480        {
01481          symbolP = NULL;
01482          as_bad (_("symbol `%s' is already defined"), name);
01483          *p = c;
01484          ignore_rest_of_line ();
01485          goto out;
01486        }
01487       symbolP = symbol_clone (symbolP, 1);
01488       S_SET_SEGMENT (symbolP, undefined_section);
01489       S_SET_VALUE (symbolP, 0);
01490       symbol_set_frag (symbolP, &zero_address_frag);
01491       S_CLEAR_VOLATILE (symbolP);
01492     }
01493 
01494   size = S_GET_VALUE (symbolP);
01495   if (size == 0)
01496     size = temp;
01497   else if (size != temp)
01498     as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
01499             name, (long) size, (long) temp);
01500 
01501   *p = c;
01502   if (comm_parse_extra != NULL)
01503     symbolP = (*comm_parse_extra) (param, symbolP, size);
01504   else
01505     {
01506       S_SET_VALUE (symbolP, (valueT) size);
01507       S_SET_EXTERNAL (symbolP);
01508       S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
01509 #ifdef OBJ_VMS
01510       {
01511        extern int flag_one;
01512        if (size == 0 || !flag_one)
01513          S_GET_OTHER (symbolP) = const_flag;
01514       }
01515 #endif
01516     }
01517 
01518   demand_empty_rest_of_line ();
01519  out:
01520   if (flag_mri)
01521     mri_comment_end (stop, stopc);
01522   return symbolP;
01523 }
01524 
01525 void
01526 s_comm (int ignore)
01527 {
01528   s_comm_internal (ignore, NULL);
01529 }
01530 
01531 /* The MRI COMMON pseudo-op.  We handle this by creating a common
01532    symbol with the appropriate name.  We make s_space do the right
01533    thing by increasing the size.  */
01534 
01535 void
01536 s_mri_common (int small ATTRIBUTE_UNUSED)
01537 {
01538   char *name;
01539   char c;
01540   char *alc = NULL;
01541   symbolS *sym;
01542   offsetT align;
01543   char *stop = NULL;
01544   char stopc = 0;
01545 
01546   if (!flag_mri)
01547     {
01548       s_comm (0);
01549       return;
01550     }
01551 
01552   stop = mri_comment_field (&stopc);
01553 
01554   SKIP_WHITESPACE ();
01555 
01556   name = input_line_pointer;
01557   if (!ISDIGIT (*name))
01558     c = get_symbol_end ();
01559   else
01560     {
01561       do
01562        {
01563          ++input_line_pointer;
01564        }
01565       while (ISDIGIT (*input_line_pointer));
01566 
01567       c = *input_line_pointer;
01568       *input_line_pointer = '\0';
01569 
01570       if (line_label != NULL)
01571        {
01572          alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
01573                               + (input_line_pointer - name)
01574                               + 1);
01575          sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
01576          name = alc;
01577        }
01578     }
01579 
01580   sym = symbol_find_or_make (name);
01581   *input_line_pointer = c;
01582   if (alc != NULL)
01583     free (alc);
01584 
01585   if (*input_line_pointer != ',')
01586     align = 0;
01587   else
01588     {
01589       ++input_line_pointer;
01590       align = get_absolute_expression ();
01591     }
01592 
01593   if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
01594     {
01595       as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
01596       ignore_rest_of_line ();
01597       mri_comment_end (stop, stopc);
01598       return;
01599     }
01600 
01601   S_SET_EXTERNAL (sym);
01602   S_SET_SEGMENT (sym, bfd_com_section_ptr);
01603   mri_common_symbol = sym;
01604 
01605 #ifdef S_SET_ALIGN
01606   if (align != 0)
01607     S_SET_ALIGN (sym, align);
01608 #endif
01609 
01610   if (line_label != NULL)
01611     {
01612       expressionS exp;
01613       exp.X_op = O_symbol;
01614       exp.X_add_symbol = sym;
01615       exp.X_add_number = 0;
01616       symbol_set_value_expression (line_label, &exp);
01617       symbol_set_frag (line_label, &zero_address_frag);
01618       S_SET_SEGMENT (line_label, expr_section);
01619     }
01620 
01621   /* FIXME: We just ignore the small argument, which distinguishes
01622      COMMON and COMMON.S.  I don't know what we can do about it.  */
01623 
01624   /* Ignore the type and hptype.  */
01625   if (*input_line_pointer == ',')
01626     input_line_pointer += 2;
01627   if (*input_line_pointer == ',')
01628     input_line_pointer += 2;
01629 
01630   demand_empty_rest_of_line ();
01631 
01632   mri_comment_end (stop, stopc);
01633 }
01634 
01635 void
01636 s_data (int ignore ATTRIBUTE_UNUSED)
01637 {
01638   segT section;
01639   register int temp;
01640 
01641   temp = get_absolute_expression ();
01642   if (flag_readonly_data_in_text)
01643     {
01644       section = text_section;
01645       temp += 1000;
01646     }
01647   else
01648     section = data_section;
01649 
01650   subseg_set (section, (subsegT) temp);
01651 
01652 #ifdef OBJ_VMS
01653   const_flag = 0;
01654 #endif
01655   demand_empty_rest_of_line ();
01656 }
01657 
01658 /* Handle the .appfile pseudo-op.  This is automatically generated by
01659    do_scrub_chars when a preprocessor # line comment is seen with a
01660    file name.  This default definition may be overridden by the object
01661    or CPU specific pseudo-ops.  This function is also the default
01662    definition for .file; the APPFILE argument is 1 for .appfile, 0 for
01663    .file.  */
01664 
01665 void
01666 s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
01667 {
01668 #ifdef LISTING
01669   if (listing)
01670     listing_source_file (file);
01671 #endif
01672   register_dependency (file);
01673 #ifdef obj_app_file
01674   obj_app_file (file, appfile);
01675 #endif
01676 }
01677 
01678 void
01679 s_app_file (int appfile)
01680 {
01681   register char *s;
01682   int length;
01683 
01684   /* Some assemblers tolerate immediately following '"'.  */
01685   if ((s = demand_copy_string (&length)) != 0)
01686     {
01687       int may_omit
01688        = (!new_logical_line_flags (s, -1, 1) && appfile);
01689 
01690       /* In MRI mode, the preprocessor may have inserted an extraneous
01691         backquote.  */
01692       if (flag_m68k_mri
01693          && *input_line_pointer == '\''
01694          && is_end_of_line[(unsigned char) input_line_pointer[1]])
01695        ++input_line_pointer;
01696 
01697       demand_empty_rest_of_line ();
01698       if (!may_omit)
01699        s_app_file_string (s, appfile);
01700     }
01701 }
01702 
01703 static int
01704 get_linefile_number (int *flag)
01705 {
01706   SKIP_WHITESPACE ();
01707 
01708   if (*input_line_pointer < '0' || *input_line_pointer > '9')
01709     return 0;
01710 
01711   *flag = get_absolute_expression ();
01712 
01713   return 1;
01714 }
01715 
01716 /* Handle the .appline pseudo-op.  This is automatically generated by
01717    do_scrub_chars when a preprocessor # line comment is seen.  This
01718    default definition may be overridden by the object or CPU specific
01719    pseudo-ops.  */
01720 
01721 void
01722 s_app_line (int appline)
01723 {
01724   char *file = NULL;
01725   int l;
01726 
01727   /* The given number is that of the next line.  */
01728   if (appline)
01729     l = get_absolute_expression ();
01730   else if (!get_linefile_number (&l))
01731     {
01732       ignore_rest_of_line ();
01733       return;
01734     }
01735 
01736   l--;
01737 
01738   if (l < -1)
01739     /* Some of the back ends can't deal with non-positive line numbers.
01740        Besides, it's silly.  GCC however will generate a line number of
01741        zero when it is pre-processing builtins for assembler-with-cpp files:
01742 
01743           # 0 "<built-in>"
01744 
01745        We do not want to barf on this, especially since such files are used
01746        in the GCC and GDB testsuites.  So we check for negative line numbers
01747        rather than non-positive line numbers.  */
01748     as_warn (_("line numbers must be positive; line number %d rejected"),
01749             l + 1);
01750   else
01751     {
01752       int flags = 0;
01753       int length = 0;
01754 
01755       if (!appline)
01756        {
01757          SKIP_WHITESPACE ();
01758 
01759          if (*input_line_pointer == '"')
01760            file = demand_copy_string (&length);
01761 
01762          if (file)
01763            {
01764              int this_flag;
01765 
01766              while (get_linefile_number (&this_flag))
01767               switch (this_flag)
01768                 {
01769                   /* From GCC's cpp documentation:
01770                      1: start of a new file.
01771                      2: returning to a file after having included
01772                         another file.
01773                      3: following text comes from a system header file.
01774                      4: following text should be treated as extern "C".
01775 
01776                      4 is nonsensical for the assembler; 3, we don't
01777                      care about, so we ignore it just in case a
01778                      system header file is included while
01779                      preprocessing assembly.  So 1 and 2 are all we
01780                      care about, and they are mutually incompatible.
01781                      new_logical_line_flags() demands this.  */
01782                 case 1:
01783                 case 2:
01784                   if (flags && flags != (1 << this_flag))
01785                     as_warn (_("incompatible flag %i in line directive"),
01786                             this_flag);
01787                   else
01788                     flags |= 1 << this_flag;
01789                   break;
01790 
01791                 case 3:
01792                 case 4:
01793                   /* We ignore these.  */
01794                   break;
01795 
01796                 default:
01797                   as_warn (_("unsupported flag %i in line directive"),
01798                           this_flag);
01799                   break;
01800                 }
01801 
01802              if (!is_end_of_line[(unsigned char)*input_line_pointer])
01803               file = 0;
01804            }
01805        }
01806 
01807       if (appline || file)
01808        {
01809          new_logical_line_flags (file, l, flags);
01810 #ifdef LISTING
01811          if (listing)
01812            listing_source_line (l);
01813 #endif
01814        }
01815     }
01816   if (appline || file)
01817     demand_empty_rest_of_line ();
01818   else
01819     ignore_rest_of_line ();
01820 }
01821 
01822 /* Handle the .end pseudo-op.  Actually, the real work is done in
01823    read_a_source_file.  */
01824 
01825 void
01826 s_end (int ignore ATTRIBUTE_UNUSED)
01827 {
01828   if (flag_mri)
01829     {
01830       /* The MRI assembler permits the start symbol to follow .end,
01831         but we don't support that.  */
01832       SKIP_WHITESPACE ();
01833       if (!is_end_of_line[(unsigned char) *input_line_pointer]
01834          && *input_line_pointer != '*'
01835          && *input_line_pointer != '!')
01836        as_warn (_("start address not supported"));
01837     }
01838 }
01839 
01840 /* Handle the .err pseudo-op.  */
01841 
01842 void
01843 s_err (int ignore ATTRIBUTE_UNUSED)
01844 {
01845   as_bad (_(".err encountered"));
01846   demand_empty_rest_of_line ();
01847 }
01848 
01849 /* Handle the .error and .warning pseudo-ops.  */
01850 
01851 void
01852 s_errwarn (int err)
01853 {
01854   int len;
01855   /* The purpose for the conditional assignment is not to
01856      internationalize the directive itself, but that we need a
01857      self-contained message, one that can be passed like the
01858      demand_copy_C_string return value, and with no assumption on the
01859      location of the name of the directive within the message.  */
01860   char *msg
01861     = (err ? _(".error directive invoked in source file")
01862        : _(".warning directive invoked in source file"));
01863 
01864   if (!is_it_end_of_statement ())
01865     {
01866       if (*input_line_pointer != '\"')
01867        {
01868          as_bad (_("%s argument must be a string"),
01869                 err ? ".error" : ".warning");
01870          ignore_rest_of_line ();
01871          return;
01872        }
01873 
01874       msg = demand_copy_C_string (&len);
01875       if (msg == NULL)
01876        return;
01877     }
01878 
01879   if (err)
01880     as_bad ("%s", msg);
01881   else
01882     as_warn ("%s", msg);
01883   demand_empty_rest_of_line ();
01884 }
01885 
01886 /* Handle the MRI fail pseudo-op.  */
01887 
01888 void
01889 s_fail (int ignore ATTRIBUTE_UNUSED)
01890 {
01891   offsetT temp;
01892   char *stop = NULL;
01893   char stopc = 0;
01894 
01895   if (flag_mri)
01896     stop = mri_comment_field (&stopc);
01897 
01898   temp = get_absolute_expression ();
01899   if (temp >= 500)
01900     as_warn (_(".fail %ld encountered"), (long) temp);
01901   else
01902     as_bad (_(".fail %ld encountered"), (long) temp);
01903 
01904   demand_empty_rest_of_line ();
01905 
01906   if (flag_mri)
01907     mri_comment_end (stop, stopc);
01908 }
01909 
01910 void
01911 s_fill (int ignore ATTRIBUTE_UNUSED)
01912 {
01913   expressionS rep_exp;
01914   long size = 1;
01915   register long fill = 0;
01916   char *p;
01917 
01918 #ifdef md_flush_pending_output
01919   md_flush_pending_output ();
01920 #endif
01921 
01922   get_known_segmented_expression (&rep_exp);
01923   if (*input_line_pointer == ',')
01924     {
01925       input_line_pointer++;
01926       size = get_absolute_expression ();
01927       if (*input_line_pointer == ',')
01928        {
01929          input_line_pointer++;
01930          fill = get_absolute_expression ();
01931        }
01932     }
01933 
01934   /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
01935 #define BSD_FILL_SIZE_CROCK_8 (8)
01936   if (size > BSD_FILL_SIZE_CROCK_8)
01937     {
01938       as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
01939       size = BSD_FILL_SIZE_CROCK_8;
01940     }
01941   if (size < 0)
01942     {
01943       as_warn (_("size negative; .fill ignored"));
01944       size = 0;
01945     }
01946   else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
01947     {
01948       if (rep_exp.X_add_number < 0)
01949        as_warn (_("repeat < 0; .fill ignored"));
01950       size = 0;
01951     }
01952 
01953   if (size && !need_pass_2)
01954     {
01955       if (rep_exp.X_op == O_constant)
01956        {
01957          p = frag_var (rs_fill, (int) size, (int) size,
01958                      (relax_substateT) 0, (symbolS *) 0,
01959                      (offsetT) rep_exp.X_add_number,
01960                      (char *) 0);
01961        }
01962       else
01963        {
01964          /* We don't have a constant repeat count, so we can't use
01965             rs_fill.  We can get the same results out of rs_space,
01966             but its argument is in bytes, so we must multiply the
01967             repeat count by size.  */
01968 
01969          symbolS *rep_sym;
01970          rep_sym = make_expr_symbol (&rep_exp);
01971          if (size != 1)
01972            {
01973              expressionS size_exp;
01974              size_exp.X_op = O_constant;
01975              size_exp.X_add_number = size;
01976 
01977              rep_exp.X_op = O_multiply;
01978              rep_exp.X_add_symbol = rep_sym;
01979              rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
01980              rep_exp.X_add_number = 0;
01981              rep_sym = make_expr_symbol (&rep_exp);
01982            }
01983 
01984          p = frag_var (rs_space, (int) size, (int) size,
01985                      (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
01986        }
01987 
01988       memset (p, 0, (unsigned int) size);
01989 
01990       /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
01991         flavoured AS.  The following bizarre behaviour is to be
01992         compatible with above.  I guess they tried to take up to 8
01993         bytes from a 4-byte expression and they forgot to sign
01994         extend.  */
01995 #define BSD_FILL_SIZE_CROCK_4 (4)
01996       md_number_to_chars (p, (valueT) fill,
01997                        (size > BSD_FILL_SIZE_CROCK_4
01998                         ? BSD_FILL_SIZE_CROCK_4
01999                         : (int) size));
02000       /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
02001         but emits no error message because it seems a legal thing to do.
02002         It is a degenerate case of .fill but could be emitted by a
02003         compiler.  */
02004     }
02005   demand_empty_rest_of_line ();
02006 }
02007 
02008 void
02009 s_globl (int ignore ATTRIBUTE_UNUSED)
02010 {
02011   char *name;
02012   int c;
02013   symbolS *symbolP;
02014   char *stop = NULL;
02015   char stopc = 0;
02016 
02017   if (flag_mri)
02018     stop = mri_comment_field (&stopc);
02019 
02020   do
02021     {
02022       name = input_line_pointer;
02023       c = get_symbol_end ();
02024       symbolP = symbol_find_or_make (name);
02025       S_SET_EXTERNAL (symbolP);
02026 
02027       *input_line_pointer = c;
02028       SKIP_WHITESPACE ();
02029       c = *input_line_pointer;
02030       if (c == ',')
02031        {
02032          input_line_pointer++;
02033          SKIP_WHITESPACE ();
02034          if (is_end_of_line[(unsigned char) *input_line_pointer])
02035            c = '\n';
02036        }
02037     }
02038   while (c == ',');
02039 
02040   demand_empty_rest_of_line ();
02041 
02042   if (flag_mri)
02043     mri_comment_end (stop, stopc);
02044 }
02045 
02046 /* Handle the MRI IRP and IRPC pseudo-ops.  */
02047 
02048 void
02049 s_irp (int irpc)
02050 {
02051   char *file, *eol;
02052   unsigned int line;
02053   sb s;
02054   const char *err;
02055   sb out;
02056 
02057   as_where (&file, &line);
02058 
02059   sb_new (&s);
02060   eol = find_end_of_line (input_line_pointer, 0);
02061   sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
02062   input_line_pointer = eol;
02063 
02064   sb_new (&out);
02065 
02066   err = expand_irp (irpc, 0, &s, &out, get_line_sb);
02067   if (err != NULL)
02068     as_bad_where (file, line, "%s", err);
02069 
02070   sb_kill (&s);
02071 
02072   input_scrub_include_sb (&out, input_line_pointer, 1);
02073   sb_kill (&out);
02074   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
02075 }
02076 
02077 /* Handle the .linkonce pseudo-op.  This tells the assembler to mark
02078    the section to only be linked once.  However, this is not supported
02079    by most object file formats.  This takes an optional argument,
02080    which is what to do about duplicates.  */
02081 
02082 void
02083 s_linkonce (int ignore ATTRIBUTE_UNUSED)
02084 {
02085   enum linkonce_type type;
02086 
02087   SKIP_WHITESPACE ();
02088 
02089   type = LINKONCE_DISCARD;
02090 
02091   if (!is_end_of_line[(unsigned char) *input_line_pointer])
02092     {
02093       char *s;
02094       char c;
02095 
02096       s = input_line_pointer;
02097       c = get_symbol_end ();
02098       if (strcasecmp (s, "discard") == 0)
02099        type = LINKONCE_DISCARD;
02100       else if (strcasecmp (s, "one_only") == 0)
02101        type = LINKONCE_ONE_ONLY;
02102       else if (strcasecmp (s, "same_size") == 0)
02103        type = LINKONCE_SAME_SIZE;
02104       else if (strcasecmp (s, "same_contents") == 0)
02105        type = LINKONCE_SAME_CONTENTS;
02106       else
02107        as_warn (_("unrecognized .linkonce type `%s'"), s);
02108 
02109       *input_line_pointer = c;
02110     }
02111 
02112 #ifdef obj_handle_link_once
02113   obj_handle_link_once (type);
02114 #else /* ! defined (obj_handle_link_once) */
02115   {
02116     flagword flags;
02117 
02118     if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
02119       as_warn (_(".linkonce is not supported for this object file format"));
02120 
02121     flags = bfd_get_section_flags (stdoutput, now_seg);
02122     flags |= SEC_LINK_ONCE;
02123     switch (type)
02124       {
02125       default:
02126        abort ();
02127       case LINKONCE_DISCARD:
02128        flags |= SEC_LINK_DUPLICATES_DISCARD;
02129        break;
02130       case LINKONCE_ONE_ONLY:
02131        flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
02132        break;
02133       case LINKONCE_SAME_SIZE:
02134        flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
02135        break;
02136       case LINKONCE_SAME_CONTENTS:
02137        flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
02138        break;
02139       }
02140     if (!bfd_set_section_flags (stdoutput, now_seg, flags))
02141       as_bad (_("bfd_set_section_flags: %s"),
02142              bfd_errmsg (bfd_get_error ()));
02143   }
02144 #endif /* ! defined (obj_handle_link_once) */
02145 
02146   demand_empty_rest_of_line ();
02147 }
02148 
02149 void
02150 bss_alloc (symbolS *symbolP, addressT size, int align)
02151 {
02152   char *pfrag;
02153   segT current_seg = now_seg;
02154   subsegT current_subseg = now_subseg;
02155   segT bss_seg = bss_section;
02156 
02157 #if defined (TC_MIPS) || defined (TC_ALPHA)
02158   if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
02159       || OUTPUT_FLAVOR == bfd_target_elf_flavour)
02160     {
02161       /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
02162       if (size <= bfd_get_gp_size (stdoutput))
02163        {
02164          bss_seg = subseg_new (".sbss", 1);
02165          seg_info (bss_seg)->bss = 1;
02166          if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
02167            as_warn (_("error setting flags for \".sbss\": %s"),
02168                    bfd_errmsg (bfd_get_error ()));
02169        }
02170     }
02171 #endif
02172   subseg_set (bss_seg, 1);
02173 
02174   if (align)
02175     {
02176       record_alignment (bss_seg, align);
02177       frag_align (align, 0, 0);
02178     }
02179 
02180   /* Detach from old frag.  */
02181   if (S_GET_SEGMENT (symbolP) == bss_seg)
02182     symbol_get_frag (symbolP)->fr_symbol = NULL;
02183 
02184   symbol_set_frag (symbolP, frag_now);
02185   pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
02186   *pfrag = 0;
02187 
02188 #ifdef S_SET_SIZE
02189   S_SET_SIZE (symbolP, size);
02190 #endif
02191   S_SET_SEGMENT (symbolP, bss_seg);
02192 
02193 #ifdef OBJ_COFF
02194   /* The symbol may already have been created with a preceding
02195      ".globl" directive -- be careful not to step on storage class
02196      in that case.  Otherwise, set it to static.  */
02197   if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
02198     S_SET_STORAGE_CLASS (symbolP, C_STAT);
02199 #endif /* OBJ_COFF */
02200 
02201   subseg_set (current_seg, current_subseg);
02202 }
02203 
02204 offsetT
02205 parse_align (int align_bytes)
02206 {
02207   expressionS exp;
02208   addressT align;
02209 
02210   SKIP_WHITESPACE ();
02211   if (*input_line_pointer != ',')
02212     {
02213     no_align:
02214       as_bad (_("expected alignment after size"));
02215       ignore_rest_of_line ();
02216       return -1;
02217     }
02218 
02219   input_line_pointer++;
02220   SKIP_WHITESPACE ();
02221 
02222   align = get_absolute_expr (&exp);
02223   if (exp.X_op == O_absent)
02224     goto no_align;
02225 
02226   if (!exp.X_unsigned)
02227     {
02228       as_warn (_("alignment negative; 0 assumed"));
02229       align = 0;
02230     }
02231 
02232   if (align_bytes && align != 0)
02233     {
02234       /* convert to a power of 2 alignment */
02235       unsigned int alignp2 = 0;
02236       while ((align & 1) == 0)
02237        align >>= 1, ++alignp2;
02238       if (align != 1)
02239        {
02240          as_bad (_("alignment not a power of 2"));
02241          ignore_rest_of_line ();
02242          return -1;
02243        }
02244       align = alignp2;
02245     }
02246   return align;
02247 }
02248 
02249 /* Called from s_comm_internal after symbol name and size have been
02250    parsed.  NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
02251    1 if this was a ".bss" directive which has a 3rd argument
02252    (alignment as a power of 2), or 2 if this was a ".bss" directive
02253    with alignment in bytes.  */
02254 
02255 symbolS *
02256 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
02257 {
02258   addressT align = 0;
02259 
02260   if (needs_align)
02261     {
02262       align = parse_align (needs_align - 1);
02263       if (align == (addressT) -1)
02264        return NULL;
02265     }
02266   else
02267     /* Assume some objects may require alignment on some systems.  */
02268     TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
02269 
02270   bss_alloc (symbolP, size, align);
02271   return symbolP;
02272 }
02273 
02274 void
02275 s_lcomm (int needs_align)
02276 {
02277   s_comm_internal (needs_align, s_lcomm_internal);
02278 }
02279 
02280 void
02281 s_lcomm_bytes (int needs_align)
02282 {
02283   s_comm_internal (needs_align * 2, s_lcomm_internal);
02284 }
02285 
02286 void
02287 s_lsym (int ignore ATTRIBUTE_UNUSED)
02288 {
02289   register char *name;
02290   register char c;
02291   register char *p;
02292   expressionS exp;
02293   register symbolS *symbolP;
02294 
02295   /* We permit ANY defined expression: BSD4.2 demands constants.  */
02296   name = input_line_pointer;
02297   c = get_symbol_end ();
02298   p = input_line_pointer;
02299   *p = c;
02300 
02301   if (name == p)
02302     {
02303       as_bad (_("expected symbol name"));
02304       ignore_rest_of_line ();
02305       return;
02306     }
02307 
02308   SKIP_WHITESPACE ();
02309 
02310   if (*input_line_pointer != ',')
02311     {
02312       *p = 0;
02313       as_bad (_("expected comma after \"%s\""), name);
02314       *p = c;
02315       ignore_rest_of_line ();
02316       return;
02317     }
02318 
02319   input_line_pointer++;
02320   expression_and_evaluate (&exp);
02321 
02322   if (exp.X_op != O_constant
02323       && exp.X_op != O_register)
02324     {
02325       as_bad (_("bad expression"));
02326       ignore_rest_of_line ();
02327       return;
02328     }
02329 
02330   *p = 0;
02331   symbolP = symbol_find_or_make (name);
02332 
02333   if (S_GET_SEGMENT (symbolP) == undefined_section)
02334     {
02335       /* The name might be an undefined .global symbol; be sure to
02336         keep the "external" bit.  */
02337       S_SET_SEGMENT (symbolP,
02338                    (exp.X_op == O_constant
02339                     ? absolute_section
02340                     : reg_section));
02341       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
02342     }
02343   else
02344     {
02345       as_bad (_("symbol `%s' is already defined"), name);
02346     }
02347 
02348   *p = c;
02349   demand_empty_rest_of_line ();
02350 }
02351 
02352 /* Read a line into an sb.  Returns the character that ended the line
02353    or zero if there are no more lines.  */
02354 
02355 static int
02356 get_line_sb (sb *line)
02357 {
02358   char *eol;
02359 
02360   if (input_line_pointer[-1] == '\n')
02361     bump_line_counters ();
02362 
02363   if (input_line_pointer >= buffer_limit)
02364     {
02365       buffer_limit = input_scrub_next_buffer (&input_line_pointer);
02366       if (buffer_limit == 0)
02367        return 0;
02368     }
02369 
02370   eol = find_end_of_line (input_line_pointer, flag_m68k_mri);
02371   sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
02372   input_line_pointer = eol;
02373 
02374   /* Don't skip multiple end-of-line characters, because that breaks support
02375      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
02376      characters but isn't.  Instead just skip one end of line character and
02377      return the character skipped so that the caller can re-insert it if
02378      necessary.   */
02379   return *input_line_pointer++;
02380 }
02381 
02382 /* Define a macro.  This is an interface to macro.c.  */
02383 
02384 void
02385 s_macro (int ignore ATTRIBUTE_UNUSED)
02386 {
02387   char *file, *eol;
02388   unsigned int line;
02389   sb s;
02390   const char *err;
02391   const char *name;
02392 
02393   as_where (&file, &line);
02394 
02395   sb_new (&s);
02396   eol = find_end_of_line (input_line_pointer, 0);
02397   sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
02398   input_line_pointer = eol;
02399 
02400   if (line_label != NULL)
02401     {
02402       sb label;
02403 
02404       sb_new (&label);
02405       sb_add_string (&label, S_GET_NAME (line_label));
02406       err = define_macro (0, &s, &label, get_line_sb, file, line, &name);
02407       sb_kill (&label);
02408     }
02409   else
02410     err = define_macro (0, &s, NULL, get_line_sb, file, line, &name);
02411   if (err != NULL)
02412     as_bad_where (file, line, err, name);
02413   else
02414     {
02415       if (line_label != NULL)
02416        {
02417          S_SET_SEGMENT (line_label, absolute_section);
02418          S_SET_VALUE (line_label, 0);
02419          symbol_set_frag (line_label, &zero_address_frag);
02420        }
02421 
02422       if (((NO_PSEUDO_DOT || flag_m68k_mri)
02423           && hash_find (po_hash, name) != NULL)
02424          || (!flag_m68k_mri
02425              && *name == '.'
02426              && hash_find (po_hash, name + 1) != NULL))
02427        as_warn_where (file,
02428                line,
02429                _("attempt to redefine pseudo-op `%s' ignored"),
02430                name);
02431     }
02432 
02433   sb_kill (&s);
02434 }
02435 
02436 /* Handle the .mexit pseudo-op, which immediately exits a macro
02437    expansion.  */
02438 
02439 void
02440 s_mexit (int ignore ATTRIBUTE_UNUSED)
02441 {
02442   cond_exit_macro (macro_nest);
02443   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
02444 }
02445 
02446 /* Switch in and out of MRI mode.  */
02447 
02448 void
02449 s_mri (int ignore ATTRIBUTE_UNUSED)
02450 {
02451   int on, old_flag;
02452 
02453   on = get_absolute_expression ();
02454   old_flag = flag_mri;
02455   if (on != 0)
02456     {
02457       flag_mri = 1;
02458 #ifdef TC_M68K
02459       flag_m68k_mri = 1;
02460 #endif
02461       macro_mri_mode (1);
02462     }
02463   else
02464     {
02465       flag_mri = 0;
02466 #ifdef TC_M68K
02467       flag_m68k_mri = 0;
02468 #endif
02469       macro_mri_mode (0);
02470     }
02471 
02472   /* Operator precedence changes in m68k MRI mode, so we need to
02473      update the operator rankings.  */
02474   expr_set_precedence ();
02475 
02476 #ifdef MRI_MODE_CHANGE
02477   if (on != old_flag)
02478     MRI_MODE_CHANGE (on);
02479 #endif
02480 
02481   demand_empty_rest_of_line ();
02482 }
02483 
02484 /* Handle changing the location counter.  */
02485 
02486 static void
02487 do_org (segT segment, expressionS *exp, int fill)
02488 {
02489   if (segment != now_seg && segment != absolute_section)
02490     as_bad (_("invalid segment \"%s\""), segment_name (segment));
02491 
02492   if (now_seg == absolute_section)
02493     {
02494       if (fill != 0)
02495        as_warn (_("ignoring fill value in absolute section"));
02496       if (exp->X_op != O_constant)
02497        {
02498          as_bad (_("only constant offsets supported in absolute section"));
02499          exp->X_add_number = 0;
02500        }
02501       abs_section_offset = exp->X_add_number;
02502     }
02503   else
02504     {
02505       char *p;
02506       symbolS *sym = exp->X_add_symbol;
02507       offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
02508 
02509       if (exp->X_op != O_constant && exp->X_op != O_symbol)
02510        {
02511          /* Handle complex expressions.  */
02512          sym = make_expr_symbol (exp);
02513          off = 0;
02514        }
02515 
02516       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
02517       *p = fill;
02518     }
02519 }
02520 
02521 void
02522 s_org (int ignore ATTRIBUTE_UNUSED)
02523 {
02524   register segT segment;
02525   expressionS exp;
02526   register long temp_fill;
02527 
02528 #ifdef md_flush_pending_output
02529   md_flush_pending_output ();
02530 #endif
02531 
02532   /* The m68k MRI assembler has a different meaning for .org.  It
02533      means to create an absolute section at a given address.  We can't
02534      support that--use a linker script instead.  */
02535   if (flag_m68k_mri)
02536     {
02537       as_bad (_("MRI style ORG pseudo-op not supported"));
02538       ignore_rest_of_line ();
02539       return;
02540     }
02541 
02542   /* Don't believe the documentation of BSD 4.2 AS.  There is no such
02543      thing as a sub-segment-relative origin.  Any absolute origin is
02544      given a warning, then assumed to be segment-relative.  Any
02545      segmented origin expression ("foo+42") had better be in the right
02546      segment or the .org is ignored.
02547 
02548      BSD 4.2 AS warns if you try to .org backwards. We cannot because
02549      we never know sub-segment sizes when we are reading code.  BSD
02550      will crash trying to emit negative numbers of filler bytes in
02551      certain .orgs. We don't crash, but see as-write for that code.
02552 
02553      Don't make frag if need_pass_2==1.  */
02554   segment = get_known_segmented_expression (&exp);
02555   if (*input_line_pointer == ',')
02556     {
02557       input_line_pointer++;
02558       temp_fill = get_absolute_expression ();
02559     }
02560   else
02561     temp_fill = 0;
02562 
02563   if (!need_pass_2)
02564     do_org (segment, &exp, temp_fill);
02565 
02566   demand_empty_rest_of_line ();
02567 }
02568 
02569 /* Handle parsing for the MRI SECT/SECTION pseudo-op.  This should be
02570    called by the obj-format routine which handles section changing
02571    when in MRI mode.  It will create a new section, and return it.  It
02572    will set *TYPE to the section type: one of 'C' (code), 'D' (data),
02573    'M' (mixed), or 'R' (romable).  The flags will be set in the section.  */
02574 
02575 void
02576 s_mri_sect (char *type ATTRIBUTE_UNUSED)
02577 {
02578 #ifdef TC_M68K
02579 
02580   char *name;
02581   char c;
02582   segT seg;
02583 
02584   SKIP_WHITESPACE ();
02585 
02586   name = input_line_pointer;
02587   if (!ISDIGIT (*name))
02588     c = get_symbol_end ();
02589   else
02590     {
02591       do
02592        {
02593          ++input_line_pointer;
02594        }
02595       while (ISDIGIT (*input_line_pointer));
02596 
02597       c = *input_line_pointer;
02598       *input_line_pointer = '\0';
02599     }
02600 
02601   name = xstrdup (name);
02602 
02603   *input_line_pointer = c;
02604 
02605   seg = subseg_new (name, 0);
02606 
02607   if (*input_line_pointer == ',')
02608     {
02609       int align;
02610 
02611       ++input_line_pointer;
02612       align = get_absolute_expression ();
02613       record_alignment (seg, align);
02614     }
02615 
02616   *type = 'C';
02617   if (*input_line_pointer == ',')
02618     {
02619       c = *++input_line_pointer;
02620       c = TOUPPER (c);
02621       if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
02622        *type = c;
02623       else
02624        as_bad (_("unrecognized section type"));
02625       ++input_line_pointer;
02626 
02627       {
02628        flagword flags;
02629 
02630        flags = SEC_NO_FLAGS;
02631        if (*type == 'C')
02632          flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
02633        else if (*type == 'D' || *type == 'M')
02634          flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
02635        else if (*type == 'R')
02636          flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
02637        if (flags != SEC_NO_FLAGS)
02638          {
02639            if (!bfd_set_section_flags (stdoutput, seg, flags))
02640              as_warn (_("error setting flags for \"%s\": %s"),
02641                      bfd_section_name (stdoutput, seg),
02642                      bfd_errmsg (bfd_get_error ()));
02643          }
02644       }
02645     }
02646 
02647   /* Ignore the HP type.  */
02648   if (*input_line_pointer == ',')
02649     input_line_pointer += 2;
02650 
02651   demand_empty_rest_of_line ();
02652 
02653 #else /* ! TC_M68K */
02654 #ifdef TC_I960
02655 
02656   char *name;
02657   char c;
02658   segT seg;
02659 
02660   SKIP_WHITESPACE ();
02661 
02662   name = input_line_pointer;
02663   c = get_symbol_end ();
02664 
02665   name = xstrdup (name);
02666 
02667   *input_line_pointer = c;
02668 
02669   seg = subseg_new (name, 0);
02670 
02671   if (*input_line_pointer != ',')
02672     *type = 'C';
02673   else
02674     {
02675       char *sectype;
02676 
02677       ++input_line_pointer;
02678       SKIP_WHITESPACE ();
02679       sectype = input_line_pointer;
02680       c = get_symbol_end ();
02681       if (*sectype == '\0')
02682        *type = 'C';
02683       else if (strcasecmp (sectype, "text") == 0)
02684        *type = 'C';
02685       else if (strcasecmp (sectype, "data") == 0)
02686        *type = 'D';
02687       else if (strcasecmp (sectype, "romdata") == 0)
02688        *type = 'R';
02689       else
02690        as_warn (_("unrecognized section type `%s'"), sectype);
02691       *input_line_pointer = c;
02692     }
02693 
02694   if (*input_line_pointer == ',')
02695     {
02696       char *seccmd;
02697 
02698       ++input_line_pointer;
02699       SKIP_WHITESPACE ();
02700       seccmd = input_line_pointer;
02701       c = get_symbol_end ();
02702       if (strcasecmp (seccmd, "absolute") == 0)
02703        {
02704          as_bad (_("absolute sections are not supported"));
02705          *input_line_pointer = c;
02706          ignore_rest_of_line ();
02707          return;
02708        }
02709       else if (strcasecmp (seccmd, "align") == 0)
02710        {
02711          int align;
02712 
02713          *input_line_pointer = c;
02714          align = get_absolute_expression ();
02715          record_alignment (seg, align);
02716        }
02717       else
02718        {
02719          as_warn (_("unrecognized section command `%s'"), seccmd);
02720          *input_line_pointer = c;
02721        }
02722     }
02723 
02724   demand_empty_rest_of_line ();
02725 
02726 #else /* ! TC_I960 */
02727   /* The MRI assembler seems to use different forms of .sect for
02728      different targets.  */
02729   as_bad ("MRI mode not supported for this target");
02730   ignore_rest_of_line ();
02731 #endif /* ! TC_I960 */
02732 #endif /* ! TC_M68K */
02733 }
02734 
02735 /* Handle the .print pseudo-op.  */
02736 
02737 void
02738 s_print (int ignore ATTRIBUTE_UNUSED)
02739 {
02740   char *s;
02741   int len;
02742 
02743   s = demand_copy_C_string (&len);
02744   if (s != NULL)
02745     printf ("%s\n", s);
02746   demand_empty_rest_of_line ();
02747 }
02748 
02749 /* Handle the .purgem pseudo-op.  */
02750 
02751 void
02752 s_purgem (int ignore ATTRIBUTE_UNUSED)
02753 {
02754   if (is_it_end_of_statement ())
02755     {
02756       demand_empty_rest_of_line ();
02757       return;
02758     }
02759 
02760   do
02761     {
02762       char *name;
02763       char c;
02764 
02765       SKIP_WHITESPACE ();
02766       name = input_line_pointer;
02767       c = get_symbol_end ();
02768       delete_macro (name);
02769       *input_line_pointer = c;
02770       SKIP_WHITESPACE ();
02771     }
02772   while (*input_line_pointer++ == ',');
02773 
02774   --input_line_pointer;
02775   demand_empty_rest_of_line ();
02776 }
02777 
02778 /* Handle the .endm/.endr pseudo-ops.  */
02779 
02780 static void
02781 s_bad_end (int endr)
02782 {
02783   as_warn (_(".end%c encountered without preceeding %s"),
02784           endr ? 'r' : 'm',
02785           endr ? ".rept, .irp, or .irpc" : ".macro");
02786   demand_empty_rest_of_line ();
02787 }
02788 
02789 /* Handle the .rept pseudo-op.  */
02790 
02791 void
02792 s_rept (int ignore ATTRIBUTE_UNUSED)
02793 {
02794   int count;
02795 
02796   count = get_absolute_expression ();
02797 
02798   do_repeat (count, "REPT", "ENDR");
02799 }
02800 
02801 /* This function provides a generic repeat block implementation.   It allows
02802    different directives to be used as the start/end keys.  */
02803 
02804 void
02805 do_repeat (int count, const char *start, const char *end)
02806 {
02807   sb one;
02808   sb many;
02809 
02810   sb_new (&one);
02811   if (!buffer_and_nest (start, end, &one, get_line_sb))
02812     {
02813       as_bad (_("%s without %s"), start, end);
02814       return;
02815     }
02816 
02817   sb_new (&many);
02818   while (count-- > 0)
02819     sb_add_sb (&many, &one);
02820 
02821   sb_kill (&one);
02822 
02823   input_scrub_include_sb (&many, input_line_pointer, 1);
02824   sb_kill (&many);
02825   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
02826 }
02827 
02828 /* Skip to end of current repeat loop; EXTRA indicates how many additional
02829    input buffers to skip.  Assumes that conditionals preceding the loop end
02830    are properly nested.
02831 
02832    This function makes it easier to implement a premature "break" out of the
02833    loop.  The EXTRA arg accounts for other buffers we might have inserted,
02834    such as line substitutions.  */
02835 
02836 void
02837 end_repeat (int extra)
02838 {
02839   cond_exit_macro (macro_nest);
02840   while (extra-- >= 0)
02841     buffer_limit = input_scrub_next_buffer (&input_line_pointer);
02842 }
02843 
02844 static void
02845 assign_symbol (char *name, int mode)
02846 {
02847   symbolS *symbolP;
02848 
02849   if (name[0] == '.' && name[1] == '\0')
02850     {
02851       /* Turn '. = mumble' into a .org mumble.  */
02852       segT segment;
02853       expressionS exp;
02854 
02855       segment = get_known_segmented_expression (&exp);
02856 
02857       if (!need_pass_2)
02858        do_org (segment, &exp, 0);
02859 
02860       return;
02861     }
02862 
02863   if ((symbolP = symbol_find (name)) == NULL
02864       && (symbolP = md_undefined_symbol (name)) == NULL)
02865     {
02866       symbolP = symbol_find_or_make (name);
02867 #ifndef NO_LISTING
02868       /* When doing symbol listings, play games with dummy fragments living
02869         outside the normal fragment chain to record the file and line info
02870         for this symbol.  */
02871       if (listing & LISTING_SYMBOLS)
02872        {
02873          extern struct list_info_struct *listing_tail;
02874          fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
02875          dummy_frag->line = listing_tail;
02876          dummy_frag->fr_symbol = symbolP;
02877          symbol_set_frag (symbolP, dummy_frag);
02878        }
02879 #endif
02880 #ifdef OBJ_COFF
02881       /* "set" symbols are local unless otherwise specified.  */
02882       SF_SET_LOCAL (symbolP);
02883 #endif
02884     }
02885 
02886   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
02887     {
02888       /* Permit register names to be redefined.  */
02889       if ((mode != 0 || !S_IS_VOLATILE (symbolP))
02890          && S_GET_SEGMENT (symbolP) != reg_section)
02891        {
02892          as_bad (_("symbol `%s' is already defined"), name);
02893          symbolP = symbol_clone (symbolP, 0);
02894        }
02895       /* If the symbol is volatile, copy the symbol and replace the
02896         original with the copy, so that previous uses of the symbol will
02897         retain the value of the symbol at the point of use.  */
02898       else if (S_IS_VOLATILE (symbolP))
02899        symbolP = symbol_clone (symbolP, 1);
02900     }
02901 
02902   if (mode == 0)
02903     S_SET_VOLATILE (symbolP);
02904   else if (mode < 0)
02905     S_SET_FORWARD_REF (symbolP);
02906 
02907   pseudo_set (symbolP);
02908 }
02909 
02910 /* Handle the .equ, .equiv, .eqv, and .set directives.  If EQUIV is 1,
02911    then this is .equiv, and it is an error if the symbol is already
02912    defined.  If EQUIV is -1, the symbol additionally is a forward
02913    reference.  */
02914 
02915 void
02916 s_set (int equiv)
02917 {
02918   char *name;
02919   char delim;
02920   char *end_name;
02921 
02922   /* Especial apologies for the random logic:
02923      this just grew, and could be parsed much more simply!
02924      Dean in haste.  */
02925   name = input_line_pointer;
02926   delim = get_symbol_end ();
02927   end_name = input_line_pointer;
02928   *end_name = delim;
02929 
02930   if (name == end_name)
02931     {
02932       as_bad (_("expected symbol name"));
02933       ignore_rest_of_line ();
02934       return;
02935     }
02936 
02937   SKIP_WHITESPACE ();
02938 
02939   if (*input_line_pointer != ',')
02940     {
02941       *end_name = 0;
02942       as_bad (_("expected comma after \"%s\""), name);
02943       *end_name = delim;
02944       ignore_rest_of_line ();
02945       return;
02946     }
02947 
02948   input_line_pointer++;
02949   *end_name = 0;
02950 
02951   assign_symbol (name, equiv);
02952   *end_name = delim;
02953 
02954   demand_empty_rest_of_line ();
02955 }
02956 
02957 void
02958 s_space (int mult)
02959 {
02960   expressionS exp;
02961   expressionS val;
02962   char *p = 0;
02963   char *stop = NULL;
02964   char stopc = 0;
02965   int bytes;
02966 
02967 #ifdef md_flush_pending_output
02968   md_flush_pending_output ();
02969 #endif
02970 
02971   if (flag_mri)
02972     stop = mri_comment_field (&stopc);
02973 
02974   /* In m68k MRI mode, we need to align to a word boundary, unless
02975      this is ds.b.  */
02976   if (flag_m68k_mri && mult > 1)
02977     {
02978       if (now_seg == absolute_section)
02979        {
02980          abs_section_offset += abs_section_offset & 1;
02981          if (line_label != NULL)
02982            S_SET_VALUE (line_label, abs_section_offset);
02983        }
02984       else if (mri_common_symbol != NULL)
02985        {
02986          valueT val;
02987 
02988          val = S_GET_VALUE (mri_common_symbol);
02989          if ((val & 1) != 0)
02990            {
02991              S_SET_VALUE (mri_common_symbol, val + 1);
02992              if (line_label != NULL)
02993               {
02994                 expressionS *symexp;
02995 
02996                 symexp = symbol_get_value_expression (line_label);
02997                 know (symexp->X_op == O_symbol);
02998                 know (symexp->X_add_symbol == mri_common_symbol);
02999                 symexp->X_add_number += 1;
03000               }
03001            }
03002        }
03003       else
03004        {
03005          do_align (1, (char *) NULL, 0, 0);
03006          if (line_label != NULL)
03007            {
03008              symbol_set_frag (line_label, frag_now);
03009              S_SET_VALUE (line_label, frag_now_fix ());
03010            }
03011        }
03012     }
03013 
03014   bytes = mult;
03015 
03016   expression (&exp);
03017 
03018   SKIP_WHITESPACE ();
03019   if (*input_line_pointer == ',')
03020     {
03021       ++input_line_pointer;
03022       expression (&val);
03023     }
03024   else
03025     {
03026       val.X_op = O_constant;
03027       val.X_add_number = 0;
03028     }
03029 
03030   if (val.X_op != O_constant
03031       || val.X_add_number < - 0x80
03032       || val.X_add_number > 0xff
03033       || (mult != 0 && mult != 1 && val.X_add_number != 0))
03034     {
03035       resolve_expression (&exp);
03036       if (exp.X_op != O_constant)
03037        as_bad (_("unsupported variable size or fill value"));
03038       else
03039        {
03040          offsetT i;
03041 
03042          if (mult == 0)
03043            mult = 1;
03044          bytes = mult * exp.X_add_number;
03045          for (i = 0; i < exp.X_add_number; i++)
03046            emit_expr (&val, mult);
03047        }
03048     }
03049   else
03050     {
03051       if (now_seg == absolute_section || mri_common_symbol != NULL)
03052        resolve_expression (&exp);
03053 
03054       if (exp.X_op == O_constant)
03055        {
03056          long repeat;
03057 
03058          repeat = exp.X_add_number;
03059          if (mult)
03060            repeat *= mult;
03061          bytes = repeat;
03062          if (repeat <= 0)
03063            {
03064              if (!flag_mri)
03065               as_warn (_(".space repeat count is zero, ignored"));
03066              else if (repeat < 0)
03067               as_warn (_(".space repeat count is negative, ignored"));
03068              goto getout;
03069            }
03070 
03071          /* If we are in the absolute section, just bump the offset.  */
03072          if (now_seg == absolute_section)
03073            {
03074              abs_section_offset += repeat;
03075              goto getout;
03076            }
03077 
03078          /* If we are secretly in an MRI common section, then
03079             creating space just increases the size of the common
03080             symbol.  */
03081          if (mri_common_symbol != NULL)
03082            {
03083              S_SET_VALUE (mri_common_symbol,
03084                         S_GET_VALUE (mri_common_symbol) + repeat);
03085              goto getout;
03086            }
03087 
03088          if (!need_pass_2)
03089            p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
03090                        (offsetT) repeat, (char *) 0);
03091        }
03092       else
03093        {
03094          if (now_seg == absolute_section)
03095            {
03096              as_bad (_("space allocation too complex in absolute section"));
03097              subseg_set (text_section, 0);
03098            }
03099 
03100          if (mri_common_symbol != NULL)
03101            {
03102              as_bad (_("space allocation too complex in common section"));
03103              mri_common_symbol = NULL;
03104            }
03105 
03106          if (!need_pass_2)
03107            p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
03108                        make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
03109        }
03110 
03111       if (p)
03112        *p = val.X_add_number;
03113     }
03114 
03115  getout:
03116 
03117   /* In MRI mode, after an odd number of bytes, we must align to an
03118      even word boundary, unless the next instruction is a dc.b, ds.b
03119      or dcb.b.  */
03120   if (flag_mri && (bytes & 1) != 0)
03121     mri_pending_align = 1;
03122 
03123   demand_empty_rest_of_line ();
03124 
03125   if (flag_mri)
03126     mri_comment_end (stop, stopc);
03127 }
03128 
03129 /* This is like s_space, but the value is a floating point number with
03130    the given precision.  This is for the MRI dcb.s pseudo-op and
03131    friends.  */
03132 
03133 void
03134 s_float_space (int float_type)
03135 {
03136   offsetT count;
03137   int flen;
03138   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
03139   char *stop = NULL;
03140   char stopc = 0;
03141 
03142   if (flag_mri)
03143     stop = mri_comment_field (&stopc);
03144 
03145   count = get_absolute_expression ();
03146 
03147   SKIP_WHITESPACE ();
03148   if (*input_line_pointer != ',')
03149     {
03150       as_bad (_("missing value"));
03151       ignore_rest_of_line ();
03152       if (flag_mri)
03153        mri_comment_end (stop, stopc);
03154       return;
03155     }
03156 
03157   ++input_line_pointer;
03158 
03159   SKIP_WHITESPACE ();
03160 
03161   /* Skip any 0{letter} that may be present.  Don't even check if the
03162    * letter is legal.  */
03163   if (input_line_pointer[0] == '0'
03164       && ISALPHA (input_line_pointer[1]))
03165     input_line_pointer += 2;
03166 
03167   /* Accept :xxxx, where the x's are hex digits, for a floating point
03168      with the exact digits specified.  */
03169   if (input_line_pointer[0] == ':')
03170     {
03171       flen = hex_float (float_type, temp);
03172       if (flen < 0)
03173        {
03174          ignore_rest_of_line ();
03175          if (flag_mri)
03176            mri_comment_end (stop, stopc);
03177          return;
03178        }
03179     }
03180   else
03181     {
03182       char *err;
03183 
03184       err = md_atof (float_type, temp, &flen);
03185       know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
03186       know (flen > 0);
03187       if (err)
03188        {
03189          as_bad (_("bad floating literal: %s"), err);
03190          ignore_rest_of_line ();
03191          if (flag_mri)
03192            mri_comment_end (stop, stopc);
03193          return;
03194        }
03195     }
03196 
03197   while (--count >= 0)
03198     {
03199       char *p;
03200 
03201       p = frag_more (flen);
03202       memcpy (p, temp, (unsigned int) flen);
03203     }
03204 
03205   demand_empty_rest_of_line ();
03206 
03207   if (flag_mri)
03208     mri_comment_end (stop, stopc);
03209 }
03210 
03211 /* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
03212 
03213 void
03214 s_struct (int ignore ATTRIBUTE_UNUSED)
03215 {
03216   char *stop = NULL;
03217   char stopc = 0;
03218 
03219   if (flag_mri)
03220     stop = mri_comment_field (&stopc);
03221   abs_section_offset = get_absolute_expression ();
03222 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
03223   /* The ELF backend needs to know that we are changing sections, so
03224      that .previous works correctly. */
03225   if (IS_ELF)
03226     obj_elf_section_change_hook ();
03227 #endif
03228   subseg_set (absolute_section, 0);
03229   demand_empty_rest_of_line ();
03230   if (flag_mri)
03231     mri_comment_end (stop, stopc);
03232 }
03233 
03234 void
03235 s_text (int ignore ATTRIBUTE_UNUSED)
03236 {
03237   register int temp;
03238 
03239   temp = get_absolute_expression ();
03240   subseg_set (text_section, (subsegT) temp);
03241   demand_empty_rest_of_line ();
03242 #ifdef OBJ_VMS
03243   const_flag &= ~IN_DEFAULT_SECTION;
03244 #endif
03245 }
03246 
03247 /* .weakref x, y sets x as an alias to y that, as long as y is not
03248    referenced directly, will cause y to become a weak symbol.  */
03249 void
03250 s_weakref (int ignore ATTRIBUTE_UNUSED)
03251 {
03252   char *name;
03253   char delim;
03254   char *end_name;
03255   symbolS *symbolP;
03256   symbolS *symbolP2;
03257   expressionS exp;
03258 
03259   name = input_line_pointer;
03260   delim = get_symbol_end ();
03261   end_name = input_line_pointer;
03262 
03263   if (name == end_name)
03264     {
03265       as_bad (_("expected symbol name"));
03266       *end_name = delim;
03267       ignore_rest_of_line ();
03268       return;
03269     }
03270 
03271   symbolP = symbol_find_or_make (name);
03272 
03273   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
03274     {
03275       if (!S_IS_VOLATILE (symbolP))
03276        {
03277          as_bad (_("symbol `%s' is already defined"), name);
03278          *end_name = delim;
03279          ignore_rest_of_line ();
03280          return;
03281        }
03282       symbolP = symbol_clone (symbolP, 1);
03283       S_CLEAR_VOLATILE (symbolP);
03284     }
03285 
03286   *end_name = delim;
03287 
03288   SKIP_WHITESPACE ();
03289 
03290   if (*input_line_pointer != ',')
03291     {
03292       *end_name = 0;
03293       as_bad (_("expected comma after \"%s\""), name);
03294       *end_name = delim;
03295       ignore_rest_of_line ();
03296       return;
03297     }
03298 
03299   input_line_pointer++;
03300 
03301   SKIP_WHITESPACE ();
03302 
03303   name = input_line_pointer;
03304   delim = get_symbol_end ();
03305   end_name = input_line_pointer;
03306 
03307   if (name == end_name)
03308     {
03309       as_bad (_("expected symbol name"));
03310       ignore_rest_of_line ();
03311       return;
03312     }
03313 
03314   if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
03315       && (symbolP2 = md_undefined_symbol (name)) == NULL)
03316     {
03317       symbolP2 = symbol_find_or_make (name);
03318       S_SET_WEAKREFD (symbolP2);
03319     }
03320   else
03321     {
03322       symbolS *symp = symbolP2;
03323 
03324       while (S_IS_WEAKREFR (symp) && symp != symbolP)
03325        {
03326          expressionS *expP = symbol_get_value_expression (symp);
03327 
03328          assert (expP->X_op == O_symbol
03329                 && expP->X_add_number == 0);
03330          symp = expP->X_add_symbol;
03331        }
03332       if (symp == symbolP)
03333        {
03334          char *loop;
03335 
03336          loop = concat (S_GET_NAME (symbolP),
03337                       " => ", S_GET_NAME (symbolP2), NULL);
03338 
03339          symp = symbolP2;
03340          while (symp != symbolP)
03341            {
03342              char *old_loop = loop;
03343              symp = symbol_get_value_expression (symp)->X_add_symbol;
03344              loop = concat (loop, " => ", S_GET_NAME (symp), NULL);
03345              free (old_loop);
03346            }
03347 
03348          as_bad (_("%s: would close weakref loop: %s"),
03349                 S_GET_NAME (symbolP), loop);
03350 
03351          free (loop);
03352 
03353          *end_name = delim;
03354          ignore_rest_of_line ();
03355          return;
03356        }
03357 
03358       /* Short-circuiting instead of just checking here might speed
03359         things up a tiny little bit, but loop error messages would
03360         miss intermediate links.  */
03361       /* symbolP2 = symp; */
03362     }
03363 
03364   *end_name = delim;
03365 
03366   memset (&exp, 0, sizeof (exp));
03367   exp.X_op = O_symbol;
03368   exp.X_add_symbol = symbolP2;
03369 
03370   S_SET_SEGMENT (symbolP, undefined_section);
03371   symbol_set_value_expression (symbolP, &exp);
03372   symbol_set_frag (symbolP, &zero_address_frag);
03373   S_SET_WEAKREFR (symbolP);
03374 
03375   demand_empty_rest_of_line ();
03376 }
03377 
03378 
03379 /* Verify that we are at the end of a line.  If not, issue an error and
03380    skip to EOL.  */
03381 
03382 void
03383 demand_empty_rest_of_line (void)
03384 {
03385   SKIP_WHITESPACE ();
03386   if (is_end_of_line[(unsigned char) *input_line_pointer])
03387     input_line_pointer++;
03388   else
03389     {
03390       if (ISPRINT (*input_line_pointer))
03391        as_bad (_("junk at end of line, first unrecognized character is `%c'"),
03392                *input_line_pointer);
03393       else
03394        as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
03395                *input_line_pointer);
03396       ignore_rest_of_line ();
03397     }
03398   
03399   /* Return pointing just after end-of-line.  */
03400   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
03401 }
03402 
03403 /* Silently advance to the end of line.  Use this after already having
03404    issued an error about something bad.  */
03405 
03406 void
03407 ignore_rest_of_line (void)
03408 {
03409   while (input_line_pointer < buffer_limit
03410         && !is_end_of_line[(unsigned char) *input_line_pointer])
03411     input_line_pointer++;
03412 
03413   input_line_pointer++;
03414 
03415   /* Return pointing just after end-of-line.  */
03416   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
03417 }
03418 
03419 /* Sets frag for given symbol to zero_address_frag, except when the
03420    symbol frag is already set to a dummy listing frag.  */
03421 
03422 static void
03423 set_zero_frag (symbolS *symbolP)
03424 {
03425   if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
03426     symbol_set_frag (symbolP, &zero_address_frag);
03427 }
03428 
03429 /* In: Pointer to a symbol.
03430        Input_line_pointer->expression.
03431 
03432    Out:       Input_line_pointer->just after any whitespace after expression.
03433        Tried to set symbol to value of expression.
03434        Will change symbols type, value, and frag;  */
03435 
03436 void
03437 pseudo_set (symbolS *symbolP)
03438 {
03439   expressionS exp;
03440   segT seg;
03441 
03442   know (symbolP);           /* NULL pointer is logic error.  */
03443 
03444   if (!S_IS_FORWARD_REF (symbolP))
03445     (void) expression (&exp);
03446   else
03447     (void) deferred_expression (&exp);
03448 
03449   if (exp.X_op == O_illegal)
03450     as_bad (_("illegal expression"));
03451   else if (exp.X_op == O_absent)
03452     as_bad (_("missing expression"));
03453   else if (exp.X_op == O_big)
03454     {
03455       if (exp.X_add_number > 0)
03456        as_bad (_("bignum invalid"));
03457       else
03458        as_bad (_("floating point number invalid"));
03459     }
03460   else if (exp.X_op == O_subtract
03461           && !S_IS_FORWARD_REF (symbolP)
03462           && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
03463           && (symbol_get_frag (exp.X_add_symbol)
03464               == symbol_get_frag (exp.X_op_symbol)))
03465     {
03466       exp.X_op = O_constant;
03467       exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
03468                        - S_GET_VALUE (exp.X_op_symbol));
03469     }
03470 
03471   if (symbol_section_p (symbolP))
03472     {
03473       as_bad ("attempt to set value of section symbol");
03474       return;
03475     }
03476 
03477   switch (exp.X_op)
03478     {
03479     case O_illegal:
03480     case O_absent:
03481     case O_big:
03482       exp.X_add_number = 0;
03483       /* Fall through.  */
03484     case O_constant:
03485       S_SET_SEGMENT (symbolP, absolute_section);
03486       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
03487       set_zero_frag (symbolP);
03488       break;
03489 
03490     case O_register:
03491       S_SET_SEGMENT (symbolP, reg_section);
03492       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
03493       set_zero_frag (symbolP);
03494       break;
03495 
03496     case O_symbol:
03497       seg = S_GET_SEGMENT (exp.X_add_symbol);
03498       /* For x=undef+const, create an expression symbol.
03499         For x=x+const, just update x except when x is an undefined symbol
03500         For x=defined+const, evaluate x.  */
03501       if (symbolP == exp.X_add_symbol
03502          && (seg != undefined_section
03503              || !symbol_constant_p (symbolP)))
03504        {
03505          *symbol_X_add_number (symbolP) += exp.X_add_number;
03506          break;
03507        }
03508       else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
03509        {
03510          symbolS *s = exp.X_add_symbol;
03511 
03512          if (S_IS_COMMON (s))
03513            as_bad (_("`%s' can't be equated to common symbol '%s'"),
03514                   S_GET_NAME (symbolP), S_GET_NAME (s));
03515 
03516          S_SET_SEGMENT (symbolP, seg);
03517          S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
03518          symbol_set_frag (symbolP, symbol_get_frag (s));
03519          copy_symbol_attributes (symbolP, s);
03520          break;
03521        }
03522       S_SET_SEGMENT (symbolP, undefined_section);
03523       symbol_set_value_expression (symbolP, &exp);
03524       set_zero_frag (symbolP);
03525       break;
03526 
03527     default:
03528       /* The value is some complex expression.  */
03529       S_SET_SEGMENT (symbolP, expr_section);
03530       symbol_set_value_expression (symbolP, &exp);
03531       set_zero_frag (symbolP);
03532       break;
03533     }
03534 }
03535 
03536 /*                   cons()
03537 
03538    CONStruct more frag of .bytes, or .words etc.
03539    Should need_pass_2 be 1 then emit no frag(s).
03540    This understands EXPRESSIONS.
03541 
03542    Bug (?)
03543 
03544    This has a split personality. We use expression() to read the
03545    value. We can detect if the value won't fit in a byte or word.
03546    But we can't detect if expression() discarded significant digits
03547    in the case of a long. Not worth the crocks required to fix it.  */
03548 
03549 /* Select a parser for cons expressions.  */
03550 
03551 /* Some targets need to parse the expression in various fancy ways.
03552    You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
03553    (for example, the HPPA does this).  Otherwise, you can define
03554    BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
03555    REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
03556    are defined, which is the normal case, then only simple expressions
03557    are permitted.  */
03558 
03559 #ifdef TC_M68K
03560 static void
03561 parse_mri_cons (expressionS *exp, unsigned int nbytes);
03562 #endif
03563 
03564 #ifndef TC_PARSE_CONS_EXPRESSION
03565 #ifdef BITFIELD_CONS_EXPRESSIONS
03566 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
03567 static void
03568 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
03569 #endif
03570 #ifdef REPEAT_CONS_EXPRESSIONS
03571 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
03572 static void
03573 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
03574 #endif
03575 
03576 /* If we haven't gotten one yet, just call expression.  */
03577 #ifndef TC_PARSE_CONS_EXPRESSION
03578 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
03579 #endif
03580 #endif
03581 
03582 void
03583 do_parse_cons_expression (expressionS *exp,
03584                        int nbytes ATTRIBUTE_UNUSED)
03585 {
03586   TC_PARSE_CONS_EXPRESSION (exp, nbytes);
03587 }
03588 
03589 
03590 /* Worker to do .byte etc statements.
03591    Clobbers input_line_pointer and checks end-of-line.  */
03592 
03593 static void
03594 cons_worker (register int nbytes,  /* 1=.byte, 2=.word, 4=.long.  */
03595             int rva)
03596 {
03597   int c;
03598   expressionS exp;
03599   char *stop = NULL;
03600   char stopc = 0;
03601 
03602 #ifdef md_flush_pending_output
03603   md_flush_pending_output ();
03604 #endif
03605 
03606   if (flag_mri)
03607     stop = mri_comment_field (&stopc);
03608 
03609   if (is_it_end_of_statement ())
03610     {
03611       demand_empty_rest_of_line ();
03612       if (flag_mri)
03613        mri_comment_end (stop, stopc);
03614       return;
03615     }
03616 
03617 #ifdef TC_ADDRESS_BYTES
03618   if (nbytes == 0)
03619     nbytes = TC_ADDRESS_BYTES ();
03620 #endif
03621 
03622 #ifdef md_cons_align
03623   md_cons_align (nbytes);
03624 #endif
03625 
03626   c = 0;
03627   do
03628     {
03629 #ifdef TC_M68K
03630       if (flag_m68k_mri)
03631        parse_mri_cons (&exp, (unsigned int) nbytes);
03632       else
03633 #endif
03634        TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
03635 
03636       if (rva)
03637        {
03638          if (exp.X_op == O_symbol)
03639            exp.X_op = O_symbol_rva;
03640          else
03641            as_fatal (_("rva without symbol"));
03642        }
03643       emit_expr (&exp, (unsigned int) nbytes);
03644       ++c;
03645     }
03646   while (*input_line_pointer++ == ',');
03647 
03648   /* In MRI mode, after an odd number of bytes, we must align to an
03649      even word boundary, unless the next instruction is a dc.b, ds.b
03650      or dcb.b.  */
03651   if (flag_mri && nbytes == 1 && (c & 1) != 0)
03652     mri_pending_align = 1;
03653 
03654   input_line_pointer--;            /* Put terminator back into stream.  */
03655 
03656   demand_empty_rest_of_line ();
03657 
03658   if (flag_mri)
03659     mri_comment_end (stop, stopc);
03660 }
03661 
03662 void
03663 cons (int size)
03664 {
03665   cons_worker (size, 0);
03666 }
03667 
03668 void
03669 s_rva (int size)
03670 {
03671   cons_worker (size, 1);
03672 }
03673 
03674 /* .reloc offset, reloc_name, symbol+addend.  */
03675 
03676 void
03677 s_reloc (int ignore ATTRIBUTE_UNUSED)
03678 {
03679   char *stop = NULL;
03680   char stopc = 0;
03681   expressionS exp;
03682   char *r_name;
03683   int c;
03684   struct reloc_list *reloc;
03685 
03686   reloc = xmalloc (sizeof (*reloc));
03687 
03688   if (flag_mri)
03689     stop = mri_comment_field (&stopc);
03690 
03691   expression (&exp);
03692   switch (exp.X_op)
03693     {
03694     case O_illegal:
03695     case O_absent:
03696     case O_big:
03697     case O_register:
03698       as_bad (_("missing or bad offset expression"));
03699       goto err_out;
03700     case O_constant:
03701       exp.X_add_symbol = section_symbol (now_seg);
03702       exp.X_op = O_symbol;
03703       /* Fall thru */
03704     case O_symbol:
03705       if (exp.X_add_number == 0)
03706        {
03707          reloc->u.a.offset_sym = exp.X_add_symbol;
03708          break;
03709        }
03710       /* Fall thru */
03711     default:
03712       reloc->u.a.offset_sym = make_expr_symbol (&exp);
03713       break;
03714     }
03715 
03716   SKIP_WHITESPACE ();
03717   if (*input_line_pointer != ',')
03718     {
03719       as_bad (_("missing reloc type"));
03720       goto err_out;
03721     }
03722 
03723   ++input_line_pointer;
03724   SKIP_WHITESPACE ();
03725   r_name = input_line_pointer;
03726   c = get_symbol_end ();
03727   reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
03728   *input_line_pointer = c;
03729   if (reloc->u.a.howto == NULL)
03730     {
03731       as_bad (_("unrecognized reloc type"));
03732       goto err_out;
03733     }
03734 
03735   exp.X_op = O_absent;
03736   SKIP_WHITESPACE ();
03737   if (*input_line_pointer == ',')
03738     {
03739       ++input_line_pointer;
03740       expression_and_evaluate (&exp);
03741     }
03742   switch (exp.X_op)
03743     {
03744     case O_illegal:
03745     case O_big:
03746     case O_register:
03747       as_bad (_("bad reloc expression"));
03748     err_out:
03749       ignore_rest_of_line ();
03750       free (reloc);
03751       if (flag_mri)
03752        mri_comment_end (stop, stopc);
03753       return;
03754     case O_absent:
03755       reloc->u.a.sym = NULL;
03756       reloc->u.a.addend = 0;
03757       break;
03758     case O_constant:
03759       reloc->u.a.sym = NULL;
03760       reloc->u.a.addend = exp.X_add_number;
03761       break;
03762     case O_symbol:
03763       reloc->u.a.sym = exp.X_add_symbol;
03764       reloc->u.a.addend = exp.X_add_number;
03765       break;
03766     default:
03767       reloc->u.a.sym = make_expr_symbol (&exp);
03768       reloc->u.a.addend = 0;
03769       break;
03770     }
03771 
03772   as_where (&reloc->file, &reloc->line);
03773   reloc->next = reloc_list;
03774   reloc_list = reloc;
03775 
03776   demand_empty_rest_of_line ();
03777   if (flag_mri)
03778     mri_comment_end (stop, stopc);
03779 }
03780 
03781 /* Put the contents of expression EXP into the object file using
03782    NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
03783 
03784 void
03785 emit_expr (expressionS *exp, unsigned int nbytes)
03786 {
03787   operatorT op;
03788   register char *p;
03789   valueT extra_digit = 0;
03790 
03791   /* Don't do anything if we are going to make another pass.  */
03792   if (need_pass_2)
03793     return;
03794 
03795   dot_value = frag_now_fix ();
03796 
03797 #ifndef NO_LISTING
03798 #ifdef OBJ_ELF
03799   /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
03800      appear as a four byte positive constant in the .line section,
03801      followed by a 2 byte 0xffff.  Look for that case here.  */
03802   {
03803     static int dwarf_line = -1;
03804 
03805     if (strcmp (segment_name (now_seg), ".line") != 0)
03806       dwarf_line = -1;
03807     else if (dwarf_line >= 0
03808             && nbytes == 2
03809             && exp->X_op == O_constant
03810             && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
03811       listing_source_line ((unsigned int) dwarf_line);
03812     else if (nbytes == 4
03813             && exp->X_op == O_constant
03814             && exp->X_add_number >= 0)
03815       dwarf_line = exp->X_add_number;
03816     else
03817       dwarf_line = -1;
03818   }
03819 
03820   /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
03821      appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
03822      AT_sibling (0x12) followed by a four byte address of the sibling
03823      followed by a 2 byte AT_name (0x38) followed by the name of the
03824      file.  We look for that case here.  */
03825   {
03826     static int dwarf_file = 0;
03827 
03828     if (strcmp (segment_name (now_seg), ".debug") != 0)
03829       dwarf_file = 0;
03830     else if (dwarf_file == 0
03831             && nbytes == 2
03832             && exp->X_op == O_constant
03833             && exp->X_add_number == 0x11)
03834       dwarf_file = 1;
03835     else if (dwarf_file == 1
03836             && nbytes == 2
03837             && exp->X_op == O_constant
03838             && exp->X_add_number == 0x12)
03839       dwarf_file = 2;
03840     else if (dwarf_file == 2
03841             && nbytes == 4)
03842       dwarf_file = 3;
03843     else if (dwarf_file == 3
03844             && nbytes == 2
03845             && exp->X_op == O_constant
03846             && exp->X_add_number == 0x38)
03847       dwarf_file = 4;
03848     else
03849       dwarf_file = 0;
03850 
03851     /* The variable dwarf_file_string tells stringer that the string
03852        may be the name of the source file.  */
03853     if (dwarf_file == 4)
03854       dwarf_file_string = 1;
03855     else
03856       dwarf_file_string = 0;
03857   }
03858 #endif
03859 #endif
03860 
03861   if (check_eh_frame (exp, &nbytes))
03862     return;
03863 
03864   op = exp->X_op;
03865 
03866   /* Allow `.word 0' in the absolute section.  */
03867   if (now_seg == absolute_section)
03868     {
03869       if (op != O_constant || exp->X_add_number != 0)
03870        as_bad (_("attempt to store value in absolute section"));
03871       abs_section_offset += nbytes;
03872       return;
03873     }
03874 
03875   /* Handle a negative bignum.  */
03876   if (op == O_uminus
03877       && exp->X_add_number == 0
03878       && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
03879       && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
03880     {
03881       int i;
03882       unsigned long carry;
03883 
03884       exp = symbol_get_value_expression (exp->X_add_symbol);
03885 
03886       /* Negate the bignum: one's complement each digit and add 1.  */
03887       carry = 1;
03888       for (i = 0; i < exp->X_add_number; i++)
03889        {
03890          unsigned long next;
03891 
03892          next = (((~(generic_bignum[i] & LITTLENUM_MASK))
03893                  & LITTLENUM_MASK)
03894                 + carry);
03895          generic_bignum[i] = next & LITTLENUM_MASK;
03896          carry = next >> LITTLENUM_NUMBER_OF_BITS;
03897        }
03898 
03899       /* We can ignore any carry out, because it will be handled by
03900         extra_digit if it is needed.  */
03901 
03902       extra_digit = (valueT) -1;
03903       op = O_big;
03904     }
03905 
03906   if (op == O_absent || op == O_illegal)
03907     {
03908       as_warn (_("zero assumed for missing expression"));
03909       exp->X_add_number = 0;
03910       op = O_constant;
03911     }
03912   else if (op == O_big && exp->X_add_number <= 0)
03913     {
03914       as_bad (_("floating point number invalid"));
03915       exp->X_add_number = 0;
03916       op = O_constant;
03917     }
03918   else if (op == O_register)
03919     {
03920       as_warn (_("register value used as expression"));
03921       op = O_constant;
03922     }
03923 
03924   p = frag_more ((int) nbytes);
03925 
03926 #ifndef WORKING_DOT_WORD
03927   /* If we have the difference of two symbols in a word, save it on
03928      the broken_words list.  See the code in write.c.  */
03929   if (op == O_subtract && nbytes == 2)
03930     {
03931       struct broken_word *x;
03932 
03933       x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
03934       x->next_broken_word = broken_words;
03935       broken_words = x;
03936       x->seg = now_seg;
03937       x->subseg = now_subseg;
03938       x->frag = frag_now;
03939       x->word_goes_here = p;
03940       x->dispfrag = 0;
03941       x->add = exp->X_add_symbol;
03942       x->sub = exp->X_op_symbol;
03943       x->addnum = exp->X_add_number;
03944       x->added = 0;
03945       x->use_jump = 0;
03946       new_broken_words++;
03947       return;
03948     }
03949 #endif
03950 
03951   /* If we have an integer, but the number of bytes is too large to
03952      pass to md_number_to_chars, handle it as a bignum.  */
03953   if (op == O_constant && nbytes > sizeof (valueT))
03954     {
03955       extra_digit = exp->X_unsigned ? 0 : -1;
03956       convert_to_bignum (exp);
03957       op = O_big;
03958     }
03959 
03960   if (op == O_constant)
03961     {
03962       register valueT get;
03963       register valueT use;
03964       register valueT mask;
03965       valueT hibit;
03966       register valueT unmask;
03967 
03968       /* JF << of >= number of bits in the object is undefined.  In
03969         particular SPARC (Sun 4) has problems.  */
03970       if (nbytes >= sizeof (valueT))
03971        {
03972          mask = 0;
03973          if (nbytes > sizeof (valueT))
03974            hibit = 0;
03975          else
03976            hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
03977        }
03978       else
03979        {
03980          /* Don't store these bits.  */
03981          mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
03982          hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
03983        }
03984 
03985       unmask = ~mask;              /* Do store these bits.  */
03986 
03987 #ifdef NEVER
03988       "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
03989       mask = ~(unmask >> 1);       /* Includes sign bit now.  */
03990 #endif
03991 
03992       get = exp->X_add_number;
03993       use = get & unmask;
03994       if ((get & mask) != 0
03995          && ((get & mask) != mask
03996              || (get & hibit) == 0))
03997        {             /* Leading bits contain both 0s & 1s.  */
03998          as_warn (_("value 0x%lx truncated to 0x%lx"),
03999                  (unsigned long) get, (unsigned long) use);
04000        }
04001       /* Put bytes in right order.  */
04002       md_number_to_chars (p, use, (int) nbytes);
04003     }
04004   else if (op == O_big)
04005     {
04006       unsigned int size;
04007       LITTLENUM_TYPE *nums;
04008 
04009       know (nbytes % CHARS_PER_LITTLENUM == 0);
04010 
04011       size = exp->X_add_number * CHARS_PER_LITTLENUM;
04012       if (nbytes < size)
04013        {
04014          as_warn (_("bignum truncated to %d bytes"), nbytes);
04015          size = nbytes;
04016        }
04017 
04018       if (target_big_endian)
04019        {
04020          while (nbytes > size)
04021            {
04022              md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
04023              nbytes -= CHARS_PER_LITTLENUM;
04024              p += CHARS_PER_LITTLENUM;
04025            }
04026 
04027          nums = generic_bignum + size / CHARS_PER_LITTLENUM;
04028          while (size >= CHARS_PER_LITTLENUM)
04029            {
04030              --nums;
04031              md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
04032              size -= CHARS_PER_LITTLENUM;
04033              p += CHARS_PER_LITTLENUM;
04034            }
04035        }
04036       else
04037        {
04038          nums = generic_bignum;
04039          while (size >= CHARS_PER_LITTLENUM)
04040            {
04041              md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
04042              ++nums;
04043              size -= CHARS_PER_LITTLENUM;
04044              p += CHARS_PER_LITTLENUM;
04045              nbytes -= CHARS_PER_LITTLENUM;
04046            }
04047 
04048          while (nbytes >= CHARS_PER_LITTLENUM)
04049            {
04050              md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
04051              nbytes -= CHARS_PER_LITTLENUM;
04052              p += CHARS_PER_LITTLENUM;
04053            }
04054        }
04055     }
04056   else
04057     {
04058       memset (p, 0, nbytes);
04059 
04060       /* Now we need to generate a fixS to record the symbol value.  */
04061 
04062 #ifdef TC_CONS_FIX_NEW
04063       TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
04064 #else
04065       {
04066        bfd_reloc_code_real_type r;
04067 
04068        switch (nbytes)
04069          {
04070          case 1:
04071            r = BFD_RELOC_8;
04072            break;
04073          case 2:
04074            r = BFD_RELOC_16;
04075            break;
04076          case 4:
04077            r = BFD_RELOC_32;
04078            break;
04079          case 8:
04080            r = BFD_RELOC_64;
04081            break;
04082          default:
04083            as_bad (_("unsupported BFD relocation size %u"), nbytes);
04084            r = BFD_RELOC_32;
04085            break;
04086          }
04087        fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
04088                    0, r);
04089       }
04090 #endif
04091     }
04092 }
04093 
04094 #ifdef BITFIELD_CONS_EXPRESSIONS
04095 
04096 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
04097    w:x,y:z, where w and y are bitwidths and x and y are values.  They
04098    then pack them all together. We do a little better in that we allow
04099    them in words, longs, etc. and we'll pack them in target byte order
04100    for you.
04101 
04102    The rules are: pack least significant bit first, if a field doesn't
04103    entirely fit, put it in the next unit.  Overflowing the bitfield is
04104    explicitly *not* even a warning.  The bitwidth should be considered
04105    a "mask".
04106 
04107    To use this function the tc-XXX.h file should define
04108    BITFIELD_CONS_EXPRESSIONS.  */
04109 
04110 static void
04111 parse_bitfield_cons (exp, nbytes)
04112      expressionS *exp;
04113      unsigned int nbytes;
04114 {
04115   unsigned int bits_available = BITS_PER_CHAR * nbytes;
04116   char *hold = input_line_pointer;
04117 
04118   (void) expression (exp);
04119 
04120   if (*input_line_pointer == ':')
04121     {
04122       /* Bitfields.  */
04123       long value = 0;
04124 
04125       for (;;)
04126        {
04127          unsigned long width;
04128 
04129          if (*input_line_pointer != ':')
04130            {
04131              input_line_pointer = hold;
04132              break;
04133            }                /* Next piece is not a bitfield.  */
04134 
04135          /* In the general case, we can't allow
04136             full expressions with symbol
04137             differences and such.  The relocation
04138             entries for symbols not defined in this
04139             assembly would require arbitrary field
04140             widths, positions, and masks which most
04141             of our current object formats don't
04142             support.
04143 
04144             In the specific case where a symbol
04145             *is* defined in this assembly, we
04146             *could* build fixups and track it, but
04147             this could lead to confusion for the
04148             backends.  I'm lazy. I'll take any
04149             SEG_ABSOLUTE. I think that means that
04150             you can use a previous .set or
04151             .equ type symbol.  xoxorich.  */
04152 
04153          if (exp->X_op == O_absent)
04154            {
04155              as_warn (_("using a bit field width of zero"));
04156              exp->X_add_number = 0;
04157              exp->X_op = O_constant;
04158            }                /* Implied zero width bitfield.  */
04159 
04160          if (exp->X_op != O_constant)
04161            {
04162              *input_line_pointer = '\0';
04163              as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
04164              *input_line_pointer = ':';
04165              demand_empty_rest_of_line ();
04166              return;
04167            }                /* Too complex.  */
04168 
04169          if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
04170            {
04171              as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
04172                      width, nbytes, (BITS_PER_CHAR * nbytes));
04173              width = BITS_PER_CHAR * nbytes;
04174            }                /* Too big.  */
04175 
04176          if (width > bits_available)
04177            {
04178              /* FIXME-SOMEDAY: backing up and reparsing is wasteful.  */
04179              input_line_pointer = hold;
04180              exp->X_add_number = value;
04181              break;
04182            }                /* Won't fit.  */
04183 
04184          /* Skip ':'.  */
04185          hold = ++input_line_pointer;
04186 
04187          (void) expression (exp);
04188          if (exp->X_op != O_constant)
04189            {
04190              char cache = *input_line_pointer;
04191 
04192              *input_line_pointer = '\0';
04193              as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
04194              *input_line_pointer = cache;
04195              demand_empty_rest_of_line ();
04196              return;
04197            }                /* Too complex.  */
04198 
04199          value |= ((~(-1 << width) & exp->X_add_number)
04200                   << ((BITS_PER_CHAR * nbytes) - bits_available));
04201 
04202          if ((bits_available -= width) == 0
04203              || is_it_end_of_statement ()
04204              || *input_line_pointer != ',')
04205            {
04206              break;
04207            }                /* All the bitfields we're gonna get.  */
04208 
04209          hold = ++input_line_pointer;
04210          (void) expression (exp);
04211        }
04212 
04213       exp->X_add_number = value;
04214       exp->X_op = O_constant;
04215       exp->X_unsigned = 1;
04216     }
04217 }
04218 
04219 #endif /* BITFIELD_CONS_EXPRESSIONS */
04220 
04221 /* Handle an MRI style string expression.  */
04222 
04223 #ifdef TC_M68K
04224 static void
04225 parse_mri_cons (exp, nbytes)
04226      expressionS *exp;
04227      unsigned int nbytes;
04228 {
04229   if (*input_line_pointer != '\''
04230       && (input_line_pointer[1] != '\''
04231          || (*input_line_pointer != 'A'
04232              && *input_line_pointer != 'E')))
04233     TC_PARSE_CONS_EXPRESSION (exp, nbytes);
04234   else
04235     {
04236       unsigned int scan;
04237       unsigned int result = 0;
04238 
04239       /* An MRI style string.  Cut into as many bytes as will fit into
04240         a nbyte chunk, left justify if necessary, and separate with
04241         commas so we can try again later.  */
04242       if (*input_line_pointer == 'A')
04243        ++input_line_pointer;
04244       else if (*input_line_pointer == 'E')
04245        {
04246          as_bad (_("EBCDIC constants are not supported"));
04247          ++input_line_pointer;
04248        }
04249 
04250       input_line_pointer++;
04251       for (scan = 0; scan < nbytes; scan++)
04252        {
04253          if (*input_line_pointer == '\'')
04254            {
04255              if (input_line_pointer[1] == '\'')
04256               {
04257                 input_line_pointer++;
04258               }
04259              else
04260               break;
04261            }
04262          result = (result << 8) | (*input_line_pointer++);
04263        }
04264 
04265       /* Left justify.  */
04266       while (scan < nbytes)
04267        {
04268          result <<= 8;
04269          scan++;
04270        }
04271 
04272       /* Create correct expression.  */
04273       exp->X_op = O_constant;
04274       exp->X_add_number = result;
04275 
04276       /* Fake it so that we can read the next char too.  */
04277       if (input_line_pointer[0] != '\'' ||
04278          (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
04279        {
04280          input_line_pointer -= 2;
04281          input_line_pointer[0] = ',';
04282          input_line_pointer[1] = '\'';
04283        }
04284       else
04285        input_line_pointer++;
04286     }
04287 }
04288 #endif /* TC_M68K */
04289 
04290 #ifdef REPEAT_CONS_EXPRESSIONS
04291 
04292 /* Parse a repeat expression for cons.  This is used by the MIPS
04293    assembler.  The format is NUMBER:COUNT; NUMBER appears in the
04294    object file COUNT times.
04295 
04296    To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
04297 
04298 static void
04299 parse_repeat_cons (exp, nbytes)
04300      expressionS *exp;
04301      unsigned int nbytes;
04302 {
04303   expressionS count;
04304   register int i;
04305 
04306   expression (exp);
04307 
04308   if (*input_line_pointer != ':')
04309     {
04310       /* No repeat count.  */
04311       return;
04312     }
04313 
04314   ++input_line_pointer;
04315   expression (&count);
04316   if (count.X_op != O_constant
04317       || count.X_add_number <= 0)
04318     {
04319       as_warn (_("unresolvable or nonpositive repeat count; using 1"));
04320       return;
04321     }
04322 
04323   /* The cons function is going to output this expression once.  So we
04324      output it count - 1 times.  */
04325   for (i = count.X_add_number - 1; i > 0; i--)
04326     emit_expr (exp, nbytes);
04327 }
04328 
04329 #endif /* REPEAT_CONS_EXPRESSIONS */
04330 
04331 /* Parse a floating point number represented as a hex constant.  This
04332    permits users to specify the exact bits they want in the floating
04333    point number.  */
04334 
04335 static int
04336 hex_float (int float_type, char *bytes)
04337 {
04338   int length;
04339   int i;
04340 
04341   switch (float_type)
04342     {
04343     case 'f':
04344     case 'F':
04345     case 's':
04346     case 'S':
04347       length = 4;
04348       break;
04349 
04350     case 'd':
04351     case 'D':
04352     case 'r':
04353     case 'R':
04354       length = 8;
04355       break;
04356 
04357     case 'x':
04358     case 'X':
04359       length = 12;
04360       break;
04361 
04362     case 'p':
04363     case 'P':
04364       length = 12;
04365       break;
04366 
04367     default:
04368       as_bad (_("unknown floating type type '%c'"), float_type);
04369       return -1;
04370     }
04371 
04372   /* It would be nice if we could go through expression to parse the
04373      hex constant, but if we get a bignum it's a pain to sort it into
04374      the buffer correctly.  */
04375   i = 0;
04376   while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
04377     {
04378       int d;
04379 
04380       /* The MRI assembler accepts arbitrary underscores strewn about
04381         through the hex constant, so we ignore them as well.  */
04382       if (*input_line_pointer == '_')
04383        {
04384          ++input_line_pointer;
04385          continue;
04386        }
04387 
04388       if (i >= length)
04389        {
04390          as_warn (_("floating point constant too large"));
04391          return -1;
04392        }
04393       d = hex_value (*input_line_pointer) << 4;
04394       ++input_line_pointer;
04395       while (*input_line_pointer == '_')
04396        ++input_line_pointer;
04397       if (hex_p (*input_line_pointer))
04398        {
04399          d += hex_value (*input_line_pointer);
04400          ++input_line_pointer;
04401        }
04402       if (target_big_endian)
04403        bytes[i] = d;
04404       else
04405        bytes[length - i - 1] = d;
04406       ++i;
04407     }
04408 
04409   if (i < length)
04410     {
04411       if (target_big_endian)
04412        memset (bytes + i, 0, length - i);
04413       else
04414        memset (bytes, 0, length - i);
04415     }
04416 
04417   return length;
04418 }
04419 
04420 /*                   float_cons()
04421 
04422    CONStruct some more frag chars of .floats .ffloats etc.
04423    Makes 0 or more new frags.
04424    If need_pass_2 == 1, no frags are emitted.
04425    This understands only floating literals, not expressions. Sorry.
04426 
04427    A floating constant is defined by atof_generic(), except it is preceded
04428    by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
04429    reading, I decided to be incompatible. This always tries to give you
04430    rounded bits to the precision of the pseudo-op. Former AS did premature
04431    truncation, restored noisy bits instead of trailing 0s AND gave you
04432    a choice of 2 flavours of noise according to which of 2 floating-point
04433    scanners you directed AS to use.
04434 
04435    In: input_line_pointer->whitespace before, or '0' of flonum.  */
04436 
04437 void
04438 float_cons (/* Clobbers input_line-pointer, checks end-of-line.  */
04439            register int float_type /* 'f':.ffloat ... 'F':.float ...  */)
04440 {
04441   register char *p;
04442   int length;               /* Number of chars in an object.  */
04443   register char *err;              /* Error from scanning floating literal.  */
04444   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
04445 
04446   if (is_it_end_of_statement ())
04447     {
04448       demand_empty_rest_of_line ();
04449       return;
04450     }
04451 
04452 #ifdef md_flush_pending_output
04453   md_flush_pending_output ();
04454 #endif
04455 
04456   do
04457     {
04458       /* input_line_pointer->1st char of a flonum (we hope!).  */
04459       SKIP_WHITESPACE ();
04460 
04461       /* Skip any 0{letter} that may be present. Don't even check if the
04462         letter is legal. Someone may invent a "z" format and this routine
04463         has no use for such information. Lusers beware: you get
04464         diagnostics if your input is ill-conditioned.  */
04465       if (input_line_pointer[0] == '0'
04466          && ISALPHA (input_line_pointer[1]))
04467        input_line_pointer += 2;
04468 
04469       /* Accept :xxxx, where the x's are hex digits, for a floating
04470         point with the exact digits specified.  */
04471       if (input_line_pointer[0] == ':')
04472        {
04473          ++input_line_pointer;
04474          length = hex_float (float_type, temp);
04475          if (length < 0)
04476            {
04477              ignore_rest_of_line ();
04478              return;
04479            }
04480        }
04481       else
04482        {
04483          err = md_atof (float_type, temp, &length);
04484          know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
04485          know (length > 0);
04486          if (err)
04487            {
04488              as_bad (_("bad floating literal: %s"), err);
04489              ignore_rest_of_line ();
04490              return;
04491            }
04492        }
04493 
04494       if (!need_pass_2)
04495        {
04496          int count;
04497 
04498          count = 1;
04499 
04500 #ifdef REPEAT_CONS_EXPRESSIONS
04501          if (*input_line_pointer == ':')
04502            {
04503              expressionS count_exp;
04504 
04505              ++input_line_pointer;
04506              expression (&count_exp);
04507 
04508              if (count_exp.X_op != O_constant
04509                 || count_exp.X_add_number <= 0)
04510               as_warn (_("unresolvable or nonpositive repeat count; using 1"));
04511              else
04512               count = count_exp.X_add_number;
04513            }
04514 #endif
04515 
04516          while (--count >= 0)
04517            {
04518              p = frag_more (length);
04519              memcpy (p, temp, (unsigned int) length);
04520            }
04521        }
04522       SKIP_WHITESPACE ();
04523     }
04524   while (*input_line_pointer++ == ',');
04525 
04526   /* Put terminator back into stream.  */
04527   --input_line_pointer;
04528   demand_empty_rest_of_line ();
04529 }
04530 
04531 /* Return the size of a LEB128 value.  */
04532 
04533 static inline int
04534 sizeof_sleb128 (offsetT value)
04535 {
04536   register int size = 0;
04537   register unsigned byte;
04538 
04539   do
04540     {
04541       byte = (value & 0x7f);
04542       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
04543         Fortunately, we can structure things so that the extra work reduces
04544         to a noop on systems that do things "properly".  */
04545       value = (value >> 7) | ~(-(offsetT)1 >> 7);
04546       size += 1;
04547     }
04548   while (!(((value == 0) && ((byte & 0x40) == 0))
04549           || ((value == -1) && ((byte & 0x40) != 0))));
04550 
04551   return size;
04552 }
04553 
04554 static inline int
04555 sizeof_uleb128 (valueT value)
04556 {
04557   register int size = 0;
04558   register unsigned byte;
04559 
04560   do
04561     {
04562       byte = (value & 0x7f);
04563       value >>= 7;
04564       size += 1;
04565     }
04566   while (value != 0);
04567 
04568   return size;
04569 }
04570 
04571 int
04572 sizeof_leb128 (valueT value, int sign)
04573 {
04574   if (sign)
04575     return sizeof_sleb128 ((offsetT) value);
04576   else
04577     return sizeof_uleb128 (value);
04578 }
04579 
04580 /* Output a LEB128 value.  */
04581 
04582 static inline int
04583 output_sleb128 (char *p, offsetT value)
04584 {
04585   register char *orig = p;
04586   register int more;
04587 
04588   do
04589     {
04590       unsigned byte = (value & 0x7f);
04591 
04592       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
04593         Fortunately, we can structure things so that the extra work reduces
04594         to a noop on systems that do things "properly".  */
04595       value = (value >> 7) | ~(-(offsetT)1 >> 7);
04596 
04597       more = !((((value == 0) && ((byte & 0x40) == 0))
04598               || ((value == -1) && ((byte & 0x40) != 0))));
04599       if (more)
04600        byte |= 0x80;
04601 
04602       *p++ = byte;
04603     }
04604   while (more);
04605 
04606   return p - orig;
04607 }
04608 
04609 static inline int
04610 output_uleb128 (char *p, valueT value)
04611 {
04612   char *orig = p;
04613 
04614   do
04615     {
04616       unsigned byte = (value & 0x7f);
04617       value >>= 7;
04618       if (value != 0)
04619        /* More bytes to follow.  */
04620        byte |= 0x80;
04621 
04622       *p++ = byte;
04623     }
04624   while (value != 0);
04625 
04626   return p - orig;
04627 }
04628 
04629 int
04630 output_leb128 (char *p, valueT value, int sign)
04631 {
04632   if (sign)
04633     return output_sleb128 (p, (offsetT) value);
04634   else
04635     return output_uleb128 (p, value);
04636 }
04637 
04638 /* Do the same for bignums.  We combine sizeof with output here in that
04639    we don't output for NULL values of P.  It isn't really as critical as
04640    for "normal" values that this be streamlined.  */
04641 
04642 static inline int
04643 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
04644 {
04645   char *orig = p;
04646   valueT val = 0;
04647   int loaded = 0;
04648   unsigned byte;
04649 
04650   /* Strip leading sign extensions off the bignum.  */
04651   while (size > 1
04652         && bignum[size - 1] == LITTLENUM_MASK
04653         && bignum[size - 2] > LITTLENUM_MASK / 2)
04654     size--;
04655 
04656   do
04657     {
04658       /* OR in the next part of the littlenum.  */
04659       val |= (*bignum << loaded);
04660       loaded += LITTLENUM_NUMBER_OF_BITS;
04661       size--;
04662       bignum++;
04663 
04664       /* Add bytes until there are less than 7 bits left in VAL
04665         or until every non-sign bit has been written.  */
04666       do
04667        {
04668          byte = val & 0x7f;
04669          loaded -= 7;
04670          val >>= 7;
04671          if (size > 0
04672              || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
04673            byte |= 0x80;
04674 
04675          if (orig)
04676            *p = byte;
04677          p++;
04678        }
04679       while ((byte & 0x80) != 0 && loaded >= 7);
04680     }
04681   while (size > 0);
04682 
04683   /* Mop up any left-over bits (of which there will be less than 7).  */
04684   if ((byte & 0x80) != 0)
04685     {
04686       /* Sign-extend VAL.  */
04687       if (val & (1 << (loaded - 1)))
04688        val |= ~0 << loaded;
04689       if (orig)
04690        *p = val & 0x7f;
04691       p++;
04692     }
04693 
04694   return p - orig;
04695 }
04696 
04697 static inline int
04698 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
04699 {
04700   char *orig = p;
04701   valueT val = 0;
04702   int loaded = 0;
04703   unsigned byte;
04704 
04705   /* Strip leading zeros off the bignum.  */
04706   /* XXX: Is this needed?  */
04707   while (size > 0 && bignum[size - 1] == 0)
04708     size--;
04709 
04710   do
04711     {
04712       if (loaded < 7 && size > 0)
04713        {
04714          val |= (*bignum << loaded);
04715          loaded += 8 * CHARS_PER_LITTLENUM;
04716          size--;
04717          bignum++;
04718        }
04719 
04720       byte = val & 0x7f;
04721       loaded -= 7;
04722       val >>= 7;
04723 
04724       if (size > 0 || val)
04725        byte |= 0x80;
04726 
04727       if (orig)
04728        *p = byte;
04729       p++;
04730     }
04731   while (byte & 0x80);
04732 
04733   return p - orig;
04734 }
04735 
04736 static int
04737 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
04738 {
04739   if (sign)
04740     return output_big_sleb128 (p, bignum, size);
04741   else
04742     return output_big_uleb128 (p, bignum, size);
04743 }
04744 
04745 /* Generate the appropriate fragments for a given expression to emit a
04746    leb128 value.  */
04747 
04748 static void
04749 emit_leb128_expr (expressionS *exp, int sign)
04750 {
04751   operatorT op = exp->X_op;
04752   unsigned int nbytes;
04753 
04754   if (op == O_absent || op == O_illegal)
04755     {
04756       as_warn (_("zero assumed for missing expression"));
04757       exp->X_add_number = 0;
04758       op = O_constant;
04759     }
04760   else if (op == O_big && exp->X_add_number <= 0)
04761     {
04762       as_bad (_("floating point number invalid"));
04763       exp->X_add_number = 0;
04764       op = O_constant;
04765     }
04766   else if (op == O_register)
04767     {
04768       as_warn (_("register value used as expression"));
04769       op = O_constant;
04770     }
04771   else if (op == O_constant
04772           && sign
04773           && (exp->X_add_number < 0) != !exp->X_unsigned)
04774     {
04775       /* We're outputting a signed leb128 and the sign of X_add_number
04776         doesn't reflect the sign of the original value.  Convert EXP
04777         to a correctly-extended bignum instead.  */
04778       convert_to_bignum (exp);
04779       op = O_big;
04780     }
04781 
04782   /* Let check_eh_frame know that data is being emitted.  nbytes == -1 is
04783      a signal that this is leb128 data.  It shouldn't optimize this away.  */
04784   nbytes = (unsigned int) -1;
04785   if (check_eh_frame (exp, &nbytes))
04786     abort ();
04787 
04788   /* Let the backend know that subsequent data may be byte aligned.  */
04789 #ifdef md_cons_align
04790   md_cons_align (1);
04791 #endif
04792 
04793   if (op == O_constant)
04794     {
04795       /* If we've got a constant, emit the thing directly right now.  */
04796 
04797       valueT value = exp->X_add_number;
04798       int size;
04799       char *p;
04800 
04801       size = sizeof_leb128 (value, sign);
04802       p = frag_more (size);
04803       output_leb128 (p, value, sign);
04804     }
04805   else if (op == O_big)
04806     {
04807       /* O_big is a different sort of constant.  */
04808 
04809       int size;
04810       char *p;
04811 
04812       size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
04813       p = frag_more (size);
04814       output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
04815     }
04816   else
04817     {
04818       /* Otherwise, we have to create a variable sized fragment and
04819         resolve things later.  */
04820 
04821       frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
04822               make_expr_symbol (exp), 0, (char *) NULL);
04823     }
04824 }
04825 
04826 /* Parse the .sleb128 and .uleb128 pseudos.  */
04827 
04828 void
04829 s_leb128 (int sign)
04830 {
04831   expressionS exp;
04832 
04833 #ifdef md_flush_pending_output
04834   md_flush_pending_output ();
04835 #endif
04836 
04837   do
04838     {
04839       expression (&exp);
04840       emit_leb128_expr (&exp, sign);
04841     }
04842   while (*input_line_pointer++ == ',');
04843 
04844   input_line_pointer--;
04845   demand_empty_rest_of_line ();
04846 }
04847 
04848 /* We read 0 or more ',' separated, double-quoted strings.
04849    Caller should have checked need_pass_2 is FALSE because we don't
04850    check it.  */
04851 
04852 void
04853 stringer (/* Worker to do .ascii etc statements.  */
04854          /* Checks end-of-line.  */
04855          register int append_zero  /* 0: don't append '\0', else 1.  */)
04856 {
04857   register unsigned int c;
04858   char *start;
04859 
04860 #ifdef md_flush_pending_output
04861   md_flush_pending_output ();
04862 #endif
04863 
04864   /* The following awkward logic is to parse ZERO or more strings,
04865      comma separated. Recall a string expression includes spaces
04866      before the opening '\"' and spaces after the closing '\"'.
04867      We fake a leading ',' if there is (supposed to be)
04868      a 1st, expression. We keep demanding expressions for each ','.  */
04869   if (is_it_end_of_statement ())
04870     {
04871       c = 0;                /* Skip loop.  */
04872       ++input_line_pointer; /* Compensate for end of loop.  */
04873     }
04874   else
04875     {
04876       c = ',';                     /* Do loop.  */
04877     }
04878   /* If we have been switched into the abs_section then we
04879      will not have an obstack onto which we can hang strings.  */
04880   if (now_seg == absolute_section)
04881     {
04882       as_bad (_("strings must be placed into a section"));
04883       c = 0;
04884       ignore_rest_of_line ();
04885     }
04886 
04887   while (c == ',' || c == '<' || c == '"')
04888     {
04889       SKIP_WHITESPACE ();
04890       switch (*input_line_pointer)
04891        {
04892        case '\"':
04893          ++input_line_pointer;     /*->1st char of string.  */
04894          start = input_line_pointer;
04895          while (is_a_char (c = next_char_of_string ()))
04896            {
04897              FRAG_APPEND_1_CHAR (c);
04898            }
04899          if (append_zero)
04900            {
04901              FRAG_APPEND_1_CHAR (0);
04902            }
04903          know (input_line_pointer[-1] == '\"');
04904 
04905 #ifndef NO_LISTING
04906 #ifdef OBJ_ELF
04907          /* In ELF, when gcc is emitting DWARF 1 debugging output, it
04908             will emit .string with a filename in the .debug section
04909             after a sequence of constants.  See the comment in
04910             emit_expr for the sequence.  emit_expr will set
04911             dwarf_file_string to non-zero if this string might be a
04912             source file name.  */
04913          if (strcmp (segment_name (now_seg), ".debug") != 0)
04914            dwarf_file_string = 0;
04915          else if (dwarf_file_string)
04916            {
04917              c = input_line_pointer[-1];
04918              input_line_pointer[-1] = '\0';
04919              listing_source_file (start);
04920              input_line_pointer[-1] = c;
04921            }
04922 #endif
04923 #endif
04924 
04925          break;
04926        case '<':
04927          input_line_pointer++;
04928          c = get_single_number ();
04929          FRAG_APPEND_1_CHAR (c);
04930          if (*input_line_pointer != '>')
04931            {
04932              as_bad (_("expected <nn>"));
04933            }
04934          input_line_pointer++;
04935          break;
04936        case ',':
04937          input_line_pointer++;
04938          break;
04939        }
04940       SKIP_WHITESPACE ();
04941       c = *input_line_pointer;
04942     }
04943 
04944   demand_empty_rest_of_line ();
04945 }                           /* stringer() */
04946 
04947 /* FIXME-SOMEDAY: I had trouble here on characters with the
04948     high bits set.  We'll probably also have trouble with
04949     multibyte chars, wide chars, etc.  Also be careful about
04950     returning values bigger than 1 byte.  xoxorich.  */
04951 
04952 unsigned int
04953 next_char_of_string (void)
04954 {
04955   register unsigned int c;
04956 
04957   c = *input_line_pointer++ & CHAR_MASK;
04958   switch (c)
04959     {
04960     case '\"':
04961       c = NOT_A_CHAR;
04962       break;
04963 
04964     case '\n':
04965       as_warn (_("unterminated string; newline inserted"));
04966       bump_line_counters ();
04967       break;
04968 
04969 #ifndef NO_STRING_ESCAPES
04970     case '\\':
04971       switch (c = *input_line_pointer++)
04972        {
04973        case 'b':
04974          c = '\b';
04975          break;
04976 
04977        case 'f':
04978          c = '\f';
04979          break;
04980 
04981        case 'n':
04982          c = '\n';
04983          break;
04984 
04985        case 'r':
04986          c = '\r';
04987          break;
04988 
04989        case 't':
04990          c = '\t';
04991          break;
04992 
04993        case 'v':
04994          c = '\013';
04995          break;
04996 
04997        case '\\':
04998        case '"':
04999          break;             /* As itself.  */
05000 
05001        case '0':
05002        case '1':
05003        case '2':
05004        case '3':
05005        case '4':
05006        case '5':
05007        case '6':
05008        case '7':
05009        case '8':
05010        case '9':
05011          {
05012            long number;
05013            int i;
05014 
05015            for (i = 0, number = 0;
05016                ISDIGIT (c) && i < 3;
05017                c = *input_line_pointer++, i++)
05018              {
05019               number = number * 8 + c - '0';
05020              }
05021 
05022            c = number & 0xff;
05023          }
05024          --input_line_pointer;
05025          break;
05026 
05027        case 'x':
05028        case 'X':
05029          {
05030            long number;
05031 
05032            number = 0;
05033            c = *input_line_pointer++;
05034            while (ISXDIGIT (c))
05035              {
05036               if (ISDIGIT (c))
05037                 number = number * 16 + c - '0';
05038               else if (ISUPPER (c))
05039                 number = number * 16 + c - 'A' + 10;
05040               else
05041                 number = number * 16 + c - 'a' + 10;
05042               c = *input_line_pointer++;
05043              }
05044            c = number & 0xff;
05045            --input_line_pointer;
05046          }
05047          break;
05048 
05049        case '\n':
05050          /* To be compatible with BSD 4.2 as: give the luser a linefeed!!  */
05051          as_warn (_("unterminated string; newline inserted"));
05052          c = '\n';
05053          bump_line_counters ();
05054          break;
05055 
05056        default:
05057 
05058 #ifdef ONLY_STANDARD_ESCAPES
05059          as_bad (_("bad escaped character in string"));
05060          c = '?';
05061 #endif /* ONLY_STANDARD_ESCAPES */
05062 
05063          break;
05064        }
05065       break;
05066 #endif /* ! defined (NO_STRING_ESCAPES) */
05067 
05068     default:
05069       break;
05070     }
05071   return (c);
05072 }
05073 
05074 static segT
05075 get_segmented_expression (register expressionS *expP)
05076 {
05077   register segT retval;
05078 
05079   retval = expression (expP);
05080   if (expP->X_op == O_illegal
05081       || expP->X_op == O_absent
05082       || expP->X_op == O_big)
05083     {
05084       as_bad (_("expected address expression"));
05085       expP->X_op = O_constant;
05086       expP->X_add_number = 0;
05087       retval = absolute_section;
05088     }
05089   return retval;
05090 }
05091 
05092 static segT
05093 get_known_segmented_expression (register expressionS *expP)
05094 {
05095   register segT retval;
05096 
05097   if ((retval = get_segmented_expression (expP)) == undefined_section)
05098     {
05099       /* There is no easy way to extract the undefined symbol from the
05100         expression.  */
05101       if (expP->X_add_symbol != NULL
05102          && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
05103        as_warn (_("symbol \"%s\" undefined; zero assumed"),
05104                S_GET_NAME (expP->X_add_symbol));
05105       else
05106        as_warn (_("some symbol undefined; zero assumed"));
05107       retval = absolute_section;
05108       expP->X_op = O_constant;
05109       expP->X_add_number = 0;
05110     }
05111   know (retval == absolute_section || SEG_NORMAL (retval));
05112   return (retval);
05113 }
05114 
05115 char                        /* Return terminator.  */
05116 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression.  */)
05117 {
05118   /* FIXME: val_pointer should probably be offsetT *.  */
05119   *val_pointer = (long) get_absolute_expression ();
05120   return (*input_line_pointer++);
05121 }
05122 
05123 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
05124    Give a warning if that happens.  */
05125 
05126 char *
05127 demand_copy_C_string (int *len_pointer)
05128 {
05129   register char *s;
05130 
05131   if ((s = demand_copy_string (len_pointer)) != 0)
05132     {
05133       register int len;
05134 
05135       for (len = *len_pointer; len > 0; len--)
05136        {
05137          if (*s == 0)
05138            {
05139              s = 0;
05140              len = 1;
05141              *len_pointer = 0;
05142              as_bad (_("this string may not contain \'\\0\'"));
05143            }
05144        }
05145     }
05146 
05147   return s;
05148 }
05149 
05150 /* Demand string, but return a safe (=private) copy of the string.
05151    Return NULL if we can't read a string here.  */
05152 
05153 char *
05154 demand_copy_string (int *lenP)
05155 {
05156   register unsigned int c;
05157   register int len;
05158   char *retval;
05159 
05160   len = 0;
05161   SKIP_WHITESPACE ();
05162   if (*input_line_pointer == '\"')
05163     {
05164       input_line_pointer++; /* Skip opening quote.  */
05165 
05166       while (is_a_char (c = next_char_of_string ()))
05167        {
05168          obstack_1grow (&notes, c);
05169          len++;
05170        }
05171       /* JF this next line is so demand_copy_C_string will return a
05172         null terminated string.  */
05173       obstack_1grow (&notes, '\0');
05174       retval = obstack_finish (&notes);
05175     }
05176   else
05177     {
05178       as_bad (_("missing string"));
05179       retval = NULL;
05180       ignore_rest_of_line ();
05181     }
05182   *lenP = len;
05183   return (retval);
05184 }
05185 
05186 /* In: Input_line_pointer->next character.
05187 
05188    Do: Skip input_line_pointer over all whitespace.
05189 
05190    Out:       1 if input_line_pointer->end-of-line.  */
05191 
05192 int
05193 is_it_end_of_statement (void)
05194 {
05195   SKIP_WHITESPACE ();
05196   return (is_end_of_line[(unsigned char) *input_line_pointer]);
05197 }
05198 
05199 void
05200 equals (char *sym_name, int reassign)
05201 {
05202   char *stop = NULL;
05203   char stopc = 0;
05204 
05205   input_line_pointer++;
05206   if (*input_line_pointer == '=')
05207     input_line_pointer++;
05208   if (reassign < 0 && *input_line_pointer == '=')
05209     input_line_pointer++;
05210 
05211   while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
05212     input_line_pointer++;
05213 
05214   if (flag_mri)
05215     stop = mri_comment_field (&stopc);
05216 
05217   assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
05218 
05219   if (flag_mri)
05220     {
05221       demand_empty_rest_of_line ();
05222       mri_comment_end (stop, stopc);
05223     }
05224 }
05225 
05226 /* .incbin -- include a file verbatim at the current location.  */
05227 
05228 void
05229 s_incbin (int x ATTRIBUTE_UNUSED)
05230 {
05231   FILE * binfile;
05232   char * path;
05233   char * filename;
05234   char * binfrag;
05235   long   skip = 0;
05236   long   count = 0;
05237   long   bytes;
05238   int    len;
05239 
05240 #ifdef md_flush_pending_output
05241   md_flush_pending_output ();
05242 #endif
05243 
05244   SKIP_WHITESPACE ();
05245   filename = demand_copy_string (& len);
05246   if (filename == NULL)
05247     return;
05248 
05249   SKIP_WHITESPACE ();
05250 
05251   /* Look for optional skip and count.  */
05252   if (* input_line_pointer == ',')
05253     {
05254       ++ input_line_pointer;
05255       skip = get_absolute_expression ();
05256 
05257       SKIP_WHITESPACE ();
05258 
05259       if (* input_line_pointer == ',')
05260        {
05261          ++ input_line_pointer;
05262 
05263          count = get_absolute_expression ();
05264          if (count == 0)
05265            as_warn (_(".incbin count zero, ignoring `%s'"), filename);
05266 
05267          SKIP_WHITESPACE ();
05268        }
05269     }
05270 
05271   demand_empty_rest_of_line ();
05272 
05273   /* Try opening absolute path first, then try include dirs.  */
05274   binfile = fopen (filename, FOPEN_RB);
05275   if (binfile == NULL)
05276     {
05277       int i;
05278 
05279       path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
05280 
05281       for (i = 0; i < include_dir_count; i++)
05282        {
05283          sprintf (path, "%s/%s", include_dirs[i], filename);
05284 
05285          binfile = fopen (path, FOPEN_RB);
05286          if (binfile != NULL)
05287            break;
05288        }
05289 
05290       if (binfile == NULL)
05291        as_bad (_("file not found: %s"), filename);
05292     }
05293   else
05294     path = xstrdup (filename);
05295 
05296   if (binfile)
05297     {
05298       long   file_len;
05299 
05300       register_dependency (path);
05301 
05302       /* Compute the length of the file.  */
05303       if (fseek (binfile, 0, SEEK_END) != 0)
05304        {
05305          as_bad (_("seek to end of .incbin file failed `%s'"), path);
05306          goto done;
05307        }
05308       file_len = ftell (binfile);
05309 
05310       /* If a count was not specified use the remainder of the file.  */
05311       if (count == 0)
05312        count = file_len - skip;
05313 
05314       if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
05315        {
05316          as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
05317                 skip, count, file_len);
05318          goto done;
05319        }
05320 
05321       if (fseek (binfile, skip, SEEK_SET) != 0)
05322        {
05323          as_bad (_("could not skip to %ld in file `%s'"), skip, path);
05324          goto done;
05325        }
05326 
05327       /* Allocate frag space and store file contents in it.  */
05328       binfrag = frag_more (count);
05329 
05330       bytes = fread (binfrag, 1, count, binfile);
05331       if (bytes < count)
05332        as_warn (_("truncated file `%s', %ld of %ld bytes read"),
05333                path, bytes, count);
05334     }
05335 done:
05336   if (binfile != NULL)
05337     fclose (binfile);
05338   if (path)
05339     free (path);
05340 }
05341 
05342 /* .include -- include a file at this point.  */
05343 
05344 void
05345 s_include (int arg ATTRIBUTE_UNUSED)
05346 {
05347   char *filename;
05348   int i;
05349   FILE *try;
05350   char *path;
05351 
05352   if (!flag_m68k_mri)
05353     {
05354       filename = demand_copy_string (&i);
05355       if (filename == NULL)
05356        {
05357          /* demand_copy_string has already printed an error and
05358             called ignore_rest_of_line.  */
05359          return;
05360        }
05361     }
05362   else
05363     {
05364       SKIP_WHITESPACE ();
05365       i = 0;
05366       while (!is_end_of_line[(unsigned char) *input_line_pointer]
05367             && *input_line_pointer != ' '
05368             && *input_line_pointer != '\t')
05369        {
05370          obstack_1grow (&notes, *input_line_pointer);
05371          ++input_line_pointer;
05372          ++i;
05373        }
05374 
05375       obstack_1grow (&notes, '\0');
05376       filename = obstack_finish (&notes);
05377       while (!is_end_of_line[(unsigned char) *input_line_pointer])
05378        ++input_line_pointer;
05379     }
05380 
05381   demand_empty_rest_of_line ();
05382   path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
05383 
05384   for (i = 0; i < include_dir_count; i++)
05385     {
05386       strcpy (path, include_dirs[i]);
05387       strcat (path, "/");
05388       strcat (path, filename);
05389       if (0 != (try = fopen (path, FOPEN_RT)))
05390        {
05391          fclose (try);
05392          goto gotit;
05393        }
05394     }
05395 
05396   free (path);
05397   path = filename;
05398 gotit:
05399   /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY.  */
05400   register_dependency (path);
05401   input_scrub_insert_file (path);
05402 }
05403 
05404 void
05405 add_include_dir (char *path)
05406 {
05407   int i;
05408 
05409   if (include_dir_count == 0)
05410     {
05411       include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
05412       include_dirs[0] = ".";       /* Current dir.  */
05413       include_dir_count = 2;
05414     }
05415   else
05416     {
05417       include_dir_count++;
05418       include_dirs =
05419        (char **) realloc (include_dirs,
05420                         include_dir_count * sizeof (*include_dirs));
05421     }
05422 
05423   include_dirs[include_dir_count - 1] = path;    /* New one.  */
05424 
05425   i = strlen (path);
05426   if (i > include_dir_maxlen)
05427     include_dir_maxlen = i;
05428 }
05429 
05430 /* Output debugging information to denote the source file.  */
05431 
05432 static void
05433 generate_file_debug (void)
05434 {
05435   if (debug_type == DEBUG_STABS)
05436     stabs_generate_asm_file ();
05437 }
05438 
05439 /* Output line number debugging information for the current source line.  */
05440 
05441 void
05442 generate_lineno_debug (void)
05443 {
05444   switch (debug_type)
05445     {
05446     case DEBUG_UNSPECIFIED:
05447     case DEBUG_NONE:
05448     case DEBUG_DWARF:
05449       break;
05450     case DEBUG_STABS:
05451       stabs_generate_asm_lineno ();
05452       break;
05453     case DEBUG_ECOFF:
05454       ecoff_generate_asm_lineno ();
05455       break;
05456     case DEBUG_DWARF2:
05457       /* ??? We could here indicate to dwarf2dbg.c that something
05458         has changed.  However, since there is additional backend
05459         support that is required (calling dwarf2_emit_insn), we
05460         let dwarf2dbg.c call as_where on its own.  */
05461       break;
05462     }
05463 }
05464 
05465 /* Output debugging information to mark a function entry point or end point.
05466    END_P is zero for .func, and non-zero for .endfunc.  */
05467 
05468 void
05469 s_func (int end_p)
05470 {
05471   do_s_func (end_p, NULL);
05472 }
05473 
05474 /* Subroutine of s_func so targets can choose a different default prefix.
05475    If DEFAULT_PREFIX is NULL, use the target's "leading char".  */
05476 
05477 static void
05478 do_s_func (int end_p, const char *default_prefix)
05479 {
05480   /* Record the current function so that we can issue an error message for
05481      misplaced .func,.endfunc, and also so that .endfunc needs no
05482      arguments.  */
05483   static char *current_name;
05484   static char *current_label;
05485 
05486   if (end_p)
05487     {
05488       if (current_name == NULL)
05489        {
05490          as_bad (_("missing .func"));
05491          ignore_rest_of_line ();
05492          return;
05493        }
05494 
05495       if (debug_type == DEBUG_STABS)
05496        stabs_generate_asm_endfunc (current_name, current_label);
05497 
05498       current_name = current_label = NULL;
05499     }
05500   else /* ! end_p */
05501     {
05502       char *name, *label;
05503       char delim1, delim2;
05504 
05505       if (current_name != NULL)
05506        {
05507          as_bad (_(".endfunc missing for previous .func"));
05508          ignore_rest_of_line ();
05509          return;
05510        }
05511 
05512       name = input_line_pointer;
05513       delim1 = get_symbol_end ();
05514       name = xstrdup (name);
05515       *input_line_pointer = delim1;
05516       SKIP_WHITESPACE ();
05517       if (*input_line_pointer != ',')
05518        {
05519          if (default_prefix)
05520            asprintf (&label, "%s%s", default_prefix, name);
05521          else
05522            {
05523              char leading_char = bfd_get_symbol_leading_char (stdoutput);
05524              /* Missing entry point, use function's name with the leading
05525                char prepended.  */
05526              if (leading_char)
05527               asprintf (&label, "%c%s", leading_char, name);
05528              else
05529               label = name;
05530            }
05531        }
05532       else
05533        {
05534          ++input_line_pointer;
05535          SKIP_WHITESPACE ();
05536          label = input_line_pointer;
05537          delim2 = get_symbol_end ();
05538          label = xstrdup (label);
05539          *input_line_pointer = delim2;
05540        }
05541 
05542       if (debug_type == DEBUG_STABS)
05543        stabs_generate_asm_func (name, label);
05544 
05545       current_name = name;
05546       current_label = label;
05547     }
05548 
05549   demand_empty_rest_of_line ();
05550 }
05551 
05552 void
05553 s_ignore (int arg ATTRIBUTE_UNUSED)
05554 {
05555   ignore_rest_of_line ();
05556 }
05557 
05558 void
05559 read_print_statistics (FILE *file)
05560 {
05561   hash_print_statistics (file, "pseudo-op table", po_hash);
05562 }
05563 
05564 /* Inserts the given line into the input stream.
05565 
05566    This call avoids macro/conditionals nesting checking, since the contents of
05567    the line are assumed to replace the contents of a line already scanned.
05568 
05569    An appropriate use of this function would be substitution of input lines when
05570    called by md_start_line_hook().  The given line is assumed to already be
05571    properly scrubbed.  */
05572 
05573 void
05574 input_scrub_insert_line (const char *line)
05575 {
05576   sb newline;
05577   sb_new (&newline);
05578   sb_add_string (&newline, line);
05579   input_scrub_include_sb (&newline, input_line_pointer, 0);
05580   sb_kill (&newline);
05581   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
05582 }
05583 
05584 /* Insert a file into the input stream; the path must resolve to an actual
05585    file; no include path searching or dependency registering is performed.  */
05586 
05587 void
05588 input_scrub_insert_file (char *path)
05589 {
05590   input_scrub_include_file (path, input_line_pointer);
05591   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
05592 }
05593 
05594 /* Find the end of a line, considering quotation and escaping of quotes.  */
05595 
05596 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
05597 # define TC_SINGLE_QUOTE_STRINGS 1
05598 #endif
05599 
05600 static char *
05601 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED)
05602 {
05603   char inquote = '\0';
05604   int inescape = 0;
05605 
05606   while (!is_end_of_line[(unsigned char) *s]
05607         || (inquote && !ISCNTRL (*s))
05608         || (inquote == '\'' && flag_mri)
05609 #ifdef TC_EOL_IN_INSN
05610         || (insn && TC_EOL_IN_INSN (s))
05611 #endif
05612        )
05613     {
05614       if (mri_string && *s == '\'')
05615        inquote ^= *s;
05616       else if (inescape)
05617        inescape = 0;
05618       else if (*s == '\\')
05619        inescape = 1;
05620       else if (!inquote
05621               ? *s == '"'
05622 #ifdef TC_SINGLE_QUOTE_STRINGS
05623                || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
05624 #endif
05625               : *s == inquote)
05626        inquote ^= *s;
05627       ++s;
05628     }
05629   if (inquote)
05630     as_warn (_("missing closing `%c'"), inquote);
05631   if (inescape)
05632     as_warn (_("stray `\\'"));
05633   return s;
05634 }
05635 
05636 char *
05637 find_end_of_line (char *s, int mri_string)
05638 {
05639   return _find_end_of_line (s, mri_string, 0);
05640 }