* configure.in (sparclet-*-aout*): New config.
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
fecd2382 1/* read.c - read a source file -
cef72a92 2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 1996
ddb393cf 3 Free Software Foundation, Inc.
3340f7e5 4
f8701a3f
SC
5This file is part of GAS, the GNU Assembler.
6
7GAS is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GAS is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GAS; see the file COPYING. If not, write to
a2a5a4fa 19the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
fecd2382 20
016e0d42 21#if 0
fecd2382
RP
22#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
26 */
016e0d42
ILT
27#else
28#define MASK_CHAR ((int)(unsigned char)-1)
29#endif
fecd2382 30
9a7d824a 31
9471a360
KR
32/* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
fecd2382 34
9471a360 35#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
fecd2382 36
016e0d42
ILT
37/* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
fecd2382 39
9471a360 40/* for isdigit() */
6efd877d
KR
41#include <ctype.h>
42
fecd2382 43#include "as.h"
9471a360 44#include "subsegs.h"
7e047ac2
ILT
45#include "sb.h"
46#include "macro.h"
1356d77d 47#include "libiberty.h"
fecd2382 48#include "obstack.h"
9a7d824a
ILT
49#include "listing.h"
50
9a7d824a
ILT
51#ifndef TC_START_LABEL
52#define TC_START_LABEL(x,y) (x==':')
53#endif
fecd2382 54
016e0d42
ILT
55/* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
57 * on it
58 */
59#ifndef NOP_OPCODE
60#define NOP_OPCODE 0x00
61#endif
62
63char *input_line_pointer; /*->next char of source file to parse. */
fecd2382 64
326d16ca 65int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
daad3bbf 66
fecd2382 67#if BITS_PER_CHAR != 8
6efd877d
KR
68/* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
70die horribly;
fecd2382 71#endif
f8701a3f 72
c978e704
ILT
73#ifndef LEX_AT
74/* The m88k unfortunately uses @ as a label beginner. */
75#define LEX_AT 0
76#endif
77
ddb393cf
ILT
78#ifndef LEX_BR
79/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
80#define LEX_BR 0
81#endif
82
6ef37255
KR
83#ifndef LEX_PCT
84/* The Delta 68k assembler permits % inside label names. */
85#define LEX_PCT 0
86#endif
87
18c9057f
ILT
88#ifndef LEX_QM
89/* The PowerPC Windows NT assemblers permits ? inside label names. */
90#define LEX_QM 0
91#endif
92
6594d6b9
KR
93#ifndef LEX_DOLLAR
94/* The a29k assembler does not permits labels to start with $. */
95#define LEX_DOLLAR 3
96#endif
97
016e0d42 98/* used by is_... macros. our ctype[] */
1356d77d 99char lex_type[256] =
016e0d42
ILT
100{
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
6594d6b9 103 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
18c9057f 104 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
c978e704 105 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
ddb393cf 106 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
016e0d42 107 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
ddb393cf 108 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
016e0d42
ILT
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116};
117
118
119/*
fecd2382
RP
120 * In: a character.
121 * Out: 1 if this character ends a line.
122 */
123#define _ (0)
016e0d42
ILT
124char is_end_of_line[256] =
125{
fecd2382 126#ifdef CR_EOL
016e0d42 127 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
fecd2382 128#else
016e0d42 129 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
fecd2382 130#endif
016e0d42 131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
40324362
KR
132#ifdef TC_HPPA
133 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
135#else
016e0d42
ILT
136 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
40324362 138#endif
016e0d42
ILT
139 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
141 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
142 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
143 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
144 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
148};
fecd2382
RP
149#undef _
150
016e0d42
ILT
151/* Functions private to this file. */
152
153static char *buffer; /* 1st char of each buffer of lines is here. */
154static char *buffer_limit; /*->1 + last char in buffer. */
fecd2382 155
2209b19c
KR
156#ifdef TARGET_BYTES_BIG_ENDIAN
157/* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
158 instead of to 0 or 1. */
159#if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
160#undef TARGET_BYTES_BIG_ENDIAN
161#define TARGET_BYTES_BIG_ENDIAN 1
162#endif
163int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
164#else
165int target_big_endian /* = 0 */;
166#endif
9c6d3f66 167
9471a360 168static char *old_buffer; /* JF a hack */
016e0d42
ILT
169static char *old_input;
170static char *old_limit;
fecd2382 171
016e0d42 172/* Variables for handling include file directory list. */
fecd2382 173
016e0d42
ILT
174char **include_dirs; /* List of pointers to directories to
175 search for .include's */
176int include_dir_count; /* How many are in the list */
177int include_dir_maxlen = 1;/* Length of longest in list */
fecd2382
RP
178
179#ifndef WORKING_DOT_WORD
016e0d42 180struct broken_word *broken_words;
9471a360 181int new_broken_words;
fecd2382
RP
182#endif
183
e28c40d7
ILT
184/* The current offset into the absolute section. We don't try to
185 build frags in the absolute section, since no data can be stored
186 there. We just keep track of the current offset. */
187addressT abs_section_offset;
188
1356d77d
ILT
189/* If this line had an MRI style label, it is stored in this variable.
190 This is used by some of the MRI pseudo-ops. */
7e047ac2 191symbolS *line_label;
1356d77d
ILT
192
193/* This global variable is used to support MRI common sections. We
194 translate such sections into a common symbol. This variable is
195 non-NULL when we are in an MRI common section. */
196symbolS *mri_common_symbol;
197
286cb27a
ILT
198/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
199 need to align to an even byte boundary unless the next pseudo-op is
200 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
201 may be needed. */
202static int mri_pending_align;
203
86038ada 204static int scrub_from_string PARAMS ((char **));
71dd3c40 205static void do_align PARAMS ((int, char *, int));
e28c40d7
ILT
206static int hex_float PARAMS ((int, char *));
207static void do_org PARAMS ((segT, expressionS *, int));
6ef37255 208char *demand_copy_string PARAMS ((int *lenP));
016e0d42 209int is_it_end_of_statement PARAMS ((void));
5ac34ac3 210static segT get_segmented_expression PARAMS ((expressionS *expP));
016e0d42 211static segT get_known_segmented_expression PARAMS ((expressionS * expP));
016e0d42 212static void pobegin PARAMS ((void));
7e047ac2 213static int get_line_sb PARAMS ((sb *));
fecd2382 214\f
6efd877d 215
016e0d42
ILT
216void
217read_begin ()
fecd2382 218{
016e0d42 219 const char *p;
f8701a3f 220
6efd877d
KR
221 pobegin ();
222 obj_read_begin_hook ();
f8701a3f 223
4380166d
KR
224 /* Something close -- but not too close -- to a multiple of 1024.
225 The debugging malloc I'm using has 24 bytes of overhead. */
6594d6b9
KR
226 obstack_begin (&notes, chunksize);
227 obstack_begin (&cond_obstack, chunksize);
f8701a3f 228
f8701a3f
SC
229 /* Use machine dependent syntax */
230 for (p = line_separator_chars; *p; p++)
58d4951d 231 is_end_of_line[(unsigned char) *p] = 1;
f8701a3f 232 /* Use more. FIXME-SOMEDAY. */
1356d77d
ILT
233
234 if (flag_mri)
235 lex_type['?'] = 3;
fecd2382
RP
236}
237\f
238/* set up pseudo-op tables */
239
1356d77d 240static struct hash_control *po_hash;
fecd2382 241
016e0d42 242static const pseudo_typeS potable[] =
fecd2382 243{
6efd877d
KR
244 {"abort", s_abort, 0},
245 {"align", s_align_ptwo, 0},
246 {"ascii", stringer, 0},
247 {"asciz", stringer, 1},
931a8fab 248 {"balign", s_align_bytes, 0},
4080c270
ILT
249 {"balignw", s_align_bytes, -2},
250 {"balignl", s_align_bytes, -4},
f8701a3f 251/* block */
6efd877d
KR
252 {"byte", cons, 1},
253 {"comm", s_comm, 0},
1356d77d
ILT
254 {"common", s_mri_common, 0},
255 {"common.s", s_mri_common, 1},
6efd877d 256 {"data", s_data, 0},
1356d77d
ILT
257 {"dc", cons, 2},
258 {"dc.b", cons, 1},
259 {"dc.d", float_cons, 'd'},
260 {"dc.l", cons, 4},
261 {"dc.s", float_cons, 'f'},
262 {"dc.w", cons, 2},
263 {"dc.x", float_cons, 'x'},
e28c40d7
ILT
264 {"dcb", s_space, 2},
265 {"dcb.b", s_space, 1},
266 {"dcb.d", s_float_space, 'd'},
267 {"dcb.l", s_space, 4},
268 {"dcb.s", s_float_space, 'f'},
269 {"dcb.w", s_space, 2},
270 {"dcb.x", s_float_space, 'x'},
1356d77d
ILT
271 {"ds", s_space, 2},
272 {"ds.b", s_space, 1},
e28c40d7 273 {"ds.d", s_space, 8},
1356d77d 274 {"ds.l", s_space, 4},
e28c40d7
ILT
275 {"ds.p", s_space, 12},
276 {"ds.s", s_space, 4},
1356d77d 277 {"ds.w", s_space, 2},
e28c40d7 278 {"ds.x", s_space, 12},
42ac8fa8 279 {"debug", s_ignore, 0},
604633ae 280#ifdef S_SET_DESC
4064305e 281 {"desc", s_desc, 0},
604633ae 282#endif
f8701a3f 283/* dim */
6efd877d 284 {"double", float_cons, 'd'},
f8701a3f 285/* dsect */
6efd877d
KR
286 {"eject", listing_eject, 0}, /* Formfeed listing */
287 {"else", s_else, 0},
e28c40d7 288 {"elsec", s_else, 0},
6efd877d 289 {"end", s_end, 0},
e28c40d7 290 {"endc", s_endif, 0},
6efd877d 291 {"endif", s_endif, 0},
f8701a3f 292/* endef */
6efd877d 293 {"equ", s_set, 0},
42ac8fa8 294 {"err", s_err, 0},
7e047ac2 295 {"exitm", s_mexit, 0},
f8701a3f 296/* extend */
6efd877d 297 {"extern", s_ignore, 0}, /* We treat all undef as ext */
9a7d824a
ILT
298 {"appfile", s_app_file, 1},
299 {"appline", s_app_line, 0},
e28c40d7 300 {"fail", s_fail, 0},
6efd877d
KR
301 {"file", s_app_file, 0},
302 {"fill", s_fill, 0},
303 {"float", float_cons, 'f'},
e28c40d7 304 {"format", s_ignore, 0},
6efd877d
KR
305 {"global", s_globl, 0},
306 {"globl", s_globl, 0},
307 {"hword", cons, 2},
e28c40d7 308 {"if", s_if, (int) O_ne},
7e047ac2 309 {"ifc", s_ifc, 0},
6efd877d 310 {"ifdef", s_ifdef, 0},
e28c40d7 311 {"ifeq", s_if, (int) O_eq},
6efd877d 312 {"ifeqs", s_ifeqs, 0},
e28c40d7
ILT
313 {"ifge", s_if, (int) O_ge},
314 {"ifgt", s_if, (int) O_gt},
315 {"ifle", s_if, (int) O_le},
316 {"iflt", s_if, (int) O_lt},
7e047ac2 317 {"ifnc", s_ifc, 1},
6efd877d 318 {"ifndef", s_ifdef, 1},
e28c40d7 319 {"ifne", s_if, (int) O_ne},
6efd877d
KR
320 {"ifnes", s_ifeqs, 1},
321 {"ifnotdef", s_ifdef, 1},
322 {"include", s_include, 0},
323 {"int", cons, 4},
7e047ac2 324 {"irp", s_irp, 0},
42ac8fa8 325 {"irep", s_irp, 0},
7e047ac2 326 {"irpc", s_irp, 1},
42ac8fa8 327 {"irepc", s_irp, 1},
6efd877d
KR
328 {"lcomm", s_lcomm, 0},
329 {"lflags", listing_flags, 0}, /* Listing flags */
330 {"list", listing_list, 1}, /* Turn listing on */
e28c40d7 331 {"llen", listing_psize, 1},
6efd877d
KR
332 {"long", cons, 4},
333 {"lsym", s_lsym, 0},
7e047ac2
ILT
334 {"macro", s_macro, 0},
335 {"mexit", s_mexit, 0},
cef72a92 336 {"name", s_ignore, 0},
e28c40d7 337 {"noformat", s_ignore, 0},
6efd877d 338 {"nolist", listing_list, 0}, /* Turn listing off */
69e077f3 339 {"nopage", listing_nopage, 0},
80aab579 340 {"octa", cons, 16},
e28c40d7 341 {"offset", s_struct, 0},
6efd877d 342 {"org", s_org, 0},
931a8fab 343 {"p2align", s_align_ptwo, 0},
4080c270
ILT
344 {"p2alignw", s_align_ptwo, -2},
345 {"p2alignl", s_align_ptwo, -4},
69e077f3
ILT
346 {"page", listing_eject, 0},
347 {"plen", listing_psize, 0},
42ac8fa8 348 {"print", s_print, 0},
6efd877d 349 {"psize", listing_psize, 0}, /* set paper size */
42ac8fa8 350 {"purgem", s_purgem, 0},
80aab579 351 {"quad", cons, 8},
42ac8fa8 352 {"rep", s_rept, 0},
7e047ac2 353 {"rept", s_rept, 0},
86038ada 354 {"rva", s_rva, 4},
6efd877d 355 {"sbttl", listing_title, 1}, /* Subtitle of listing */
f8701a3f
SC
356/* scl */
357/* sect */
6efd877d
KR
358 {"set", s_set, 0},
359 {"short", cons, 2},
360 {"single", float_cons, 'f'},
f8701a3f 361/* size */
6efd877d 362 {"space", s_space, 0},
e14994d9 363 {"spc", s_ignore, 0},
4064305e
SS
364 {"stabd", s_stab, 'd'},
365 {"stabn", s_stab, 'n'},
366 {"stabs", s_stab, 's'},
ba71c54d 367 {"string", stringer, 1},
e28c40d7 368 {"struct", s_struct, 0},
f8701a3f 369/* tag */
6efd877d 370 {"text", s_text, 0},
6ef37255
KR
371
372 /* This is for gcc to use. It's only just been added (2/94), so gcc
373 won't be able to use it for a while -- probably a year or more.
374 But once this has been released, check with gcc maintainers
375 before deleting it or even changing the spelling. */
376 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
377 /* If we're folding case -- done for some targets, not necessarily
378 all -- the above string in an input file will be converted to
379 this one. Match it either way... */
380 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
381
6efd877d 382 {"title", listing_title, 0}, /* Listing title */
e14994d9 383 {"ttl", listing_title, 0},
f8701a3f
SC
384/* type */
385/* use */
386/* val */
e14994d9 387 {"xcom", s_comm, 0},
1356d77d 388 {"xdef", s_globl, 0},
e14994d9 389 {"xref", s_ignore, 0},
4064305e 390 {"xstabs", s_xstab, 's'},
6efd877d 391 {"word", cons, 2},
c02fd8dc 392 {"zero", s_space, 0},
6efd877d 393 {NULL} /* end sentinel */
fecd2382
RP
394};
395
2209b19c
KR
396static int pop_override_ok = 0;
397static const char *pop_table_name;
398
399void
400pop_insert (table)
401 const pseudo_typeS *table;
6efd877d 402{
2209b19c 403 const char *errtxt;
6efd877d 404 const pseudo_typeS *pop;
2209b19c
KR
405 for (pop = table; pop->poc_name; pop++)
406 {
407 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
408 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
6594d6b9
KR
409 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
410 errtxt);
2209b19c
KR
411 }
412}
6efd877d 413
2209b19c
KR
414#ifndef md_pop_insert
415#define md_pop_insert() pop_insert(md_pseudo_table)
416#endif
417
418#ifndef obj_pop_insert
419#define obj_pop_insert() pop_insert(obj_pseudo_table)
420#endif
421
422static void
423pobegin ()
424{
6efd877d
KR
425 po_hash = hash_new ();
426
427 /* Do the target-specific pseudo ops. */
2209b19c
KR
428 pop_table_name = "md";
429 md_pop_insert ();
6efd877d
KR
430
431 /* Now object specific. Skip any that were in the target table. */
2209b19c
KR
432 pop_table_name = "obj";
433 pop_override_ok = 1;
434 obj_pop_insert ();
6efd877d
KR
435
436 /* Now portable ones. Skip any that we've seen already. */
2209b19c
KR
437 pop_table_name = "standard";
438 pop_insert (potable);
439}
fecd2382 440\f
58d4951d
ILT
441#define HANDLE_CONDITIONAL_ASSEMBLY() \
442 if (ignore_input ()) \
443 { \
444 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
445 if (input_line_pointer == buffer_limit) \
446 break; \
447 continue; \
f8701a3f 448 }
a39116f1 449
fecd2382 450
86038ada
ILT
451/* This function is used when scrubbing the characters between #APP
452 and #NO_APP. */
453
454static char *scrub_string;
455static char *scrub_string_end;
456
457static int
458scrub_from_string (from)
459 char **from;
460{
461 int size;
462
463 *from = scrub_string;
464 size = scrub_string_end - scrub_string;
465 scrub_string = scrub_string_end;
466 return size;
467}
468
fecd2382
RP
469/* read_a_source_file()
470 *
471 * We read the file, putting things into a web that
472 * represents what we have been reading.
473 */
6efd877d
KR
474void
475read_a_source_file (name)
476 char *name;
fecd2382 477{
f8701a3f 478 register char c;
6efd877d 479 register char *s; /* string of symbol, '\0' appended */
f8701a3f 480 register int temp;
6efd877d 481 pseudo_typeS *pop;
f8701a3f 482
6efd877d 483 buffer = input_scrub_new_file (name);
f8701a3f 484
6efd877d
KR
485 listing_file (name);
486 listing_newline ("");
f8701a3f 487
6efd877d
KR
488 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
489 { /* We have another line to parse. */
490 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
9471a360
KR
491 contin: /* JF this goto is my fault I admit it.
492 Someone brave please re-write the whole
493 input section here? Pleeze??? */
6efd877d 494 while (input_line_pointer < buffer_limit)
9471a360
KR
495 {
496 /* We have more of this buffer to parse. */
f8701a3f
SC
497
498 /*
499 * We now have input_line_pointer->1st char of next line.
500 * If input_line_pointer [-1] == '\n' then we just
501 * scanned another line: so bump line counters.
502 */
d2550c72 503 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
6efd877d 504 {
a2a5a4fa
KR
505#ifdef md_start_line_hook
506 md_start_line_hook ();
507#endif
508
385ce433
JL
509 if (input_line_pointer[-1] == '\n')
510 bump_line_counters ();
f8701a3f 511
7e047ac2
ILT
512 line_label = NULL;
513
cef72a92 514 if (flag_m68k_mri
1356d77d
ILT
515#ifdef LABELS_WITHOUT_COLONS
516 || 1
517#endif
518 )
6efd877d 519 {
1356d77d
ILT
520 /* Text at the start of a line must be a label, we
521 run down and stick a colon in. */
522 if (is_name_beginner (*input_line_pointer))
523 {
524 char *line_start = input_line_pointer;
7e047ac2
ILT
525 char c;
526
527 HANDLE_CONDITIONAL_ASSEMBLY ();
1356d77d 528
7e047ac2
ILT
529 c = get_symbol_end ();
530
531 /* In MRI mode, the EQU pseudoop must be
532 handled specially. */
cef72a92 533 if (flag_m68k_mri)
1356d77d 534 {
7e047ac2
ILT
535 char *rest = input_line_pointer + 1;
536
537 if (*rest == ':')
538 ++rest;
539 if (*rest == ' ' || *rest == '\t')
540 ++rest;
541 if ((strncasecmp (rest, "EQU", 3) == 0
542 || strncasecmp (rest, "SET", 3) == 0)
543 && (rest[3] == ' ' || rest[3] == '\t'))
1356d77d 544 {
7e047ac2
ILT
545 input_line_pointer = rest + 3;
546 equals (line_start);
547 continue;
1356d77d
ILT
548 }
549 }
6efd877d 550
7e047ac2
ILT
551 line_label = colon (line_start);
552
1356d77d
ILT
553 *input_line_pointer = c;
554 if (c == ':')
555 input_line_pointer++;
556 }
6efd877d 557 }
9471a360 558 }
f8701a3f 559
f8701a3f
SC
560 /*
561 * We are at the begining of a line, or similar place.
562 * We expect a well-formed assembler statement.
563 * A "symbol-name:" is a statement.
564 *
565 * Depending on what compiler is used, the order of these tests
566 * may vary to catch most common case 1st.
567 * Each test is independent of all other tests at the (top) level.
568 * PLEASE make a compiler that doesn't use this assembler.
569 * It is crufty to waste a compiler's time encoding things for this
570 * assembler, which then wastes more time decoding it.
571 * (And communicating via (linear) files is silly!
572 * If you must pass stuff, please pass a tree!)
573 */
9471a360
KR
574 if ((c = *input_line_pointer++) == '\t'
575 || c == ' '
576 || c == '\f'
577 || c == 0)
6efd877d
KR
578 {
579 c = *input_line_pointer++;
580 }
581 know (c != ' '); /* No further leading whitespace. */
582 LISTING_NEWLINE ();
f8701a3f
SC
583 /*
584 * C is the 1st significant character.
585 * Input_line_pointer points after that character.
586 */
6efd877d 587 if (is_name_beginner (c))
6ef37255
KR
588 {
589 /* want user-defined label or pseudo/opcode */
6efd877d
KR
590 HANDLE_CONDITIONAL_ASSEMBLY ();
591
f8701a3f 592 s = --input_line_pointer;
6efd877d 593 c = get_symbol_end (); /* name's delimiter */
f8701a3f
SC
594 /*
595 * C is character after symbol.
596 * That character's place in the input line is now '\0'.
597 * S points to the beginning of the symbol.
598 * [In case of pseudo-op, s->'.'.]
599 * Input_line_pointer->'\0' where c was.
600 */
9a7d824a 601 if (TC_START_LABEL(c, input_line_pointer))
6efd877d 602 {
cef72a92 603 if (flag_m68k_mri)
7e047ac2
ILT
604 {
605 char *rest = input_line_pointer + 1;
606
607 /* In MRI mode, \tsym: set 0 is permitted. */
608
609 if (*rest == ':')
610 ++rest;
611 if (*rest == ' ' || *rest == '\t')
612 ++rest;
613 if ((strncasecmp (rest, "EQU", 3) == 0
614 || strncasecmp (rest, "SET", 3) == 0)
615 && (rest[3] == ' ' || rest[3] == '\t'))
616 {
617 input_line_pointer = rest + 3;
618 equals (s);
619 continue;
620 }
621 }
622
623 line_label = colon (s); /* user-defined label */
6efd877d 624 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
f8701a3f 625 /* Input_line_pointer->after ':'. */
6efd877d
KR
626 SKIP_WHITESPACE ();
627
f8701a3f 628
6efd877d 629 }
4064305e
SS
630 else if (c == '='
631 || (input_line_pointer[1] == '='
632#ifdef TC_EQUAL_IN_INSN
633 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
634#endif
635 ))
9c6d3f66 636 {
6efd877d
KR
637 equals (s);
638 demand_empty_rest_of_line ();
639 }
640 else
641 { /* expect pseudo-op or machine instruction */
8ff6f40e
ILT
642 pop = NULL;
643
d4c8cbd8
JL
644#define IGNORE_OPCODE_CASE
645#ifdef IGNORE_OPCODE_CASE
646 {
647 char *s2 = s;
648 while (*s2)
649 {
650 if (isupper (*s2))
651 *s2 = tolower (*s2);
652 s2++;
653 }
654 }
655#endif
656
cef72a92 657 if (flag_m68k_mri
8ff6f40e 658#ifdef NO_PSEUDO_DOT
1356d77d 659 || 1
8ff6f40e 660#endif
1356d77d
ILT
661 )
662 {
663 /* The MRI assembler and the m88k use pseudo-ops
664 without a period. */
665 pop = (pseudo_typeS *) hash_find (po_hash, s);
666 if (pop != NULL && pop->poc_handler == NULL)
667 pop = NULL;
668 }
8ff6f40e 669
7e047ac2 670 if (pop != NULL
cef72a92 671 || (! flag_m68k_mri && *s == '.'))
6efd877d
KR
672 {
673 /*
9471a360
KR
674 * PSEUDO - OP.
675 *
676 * WARNING: c has next char, which may be end-of-line.
677 * We lookup the pseudo-op table with s+1 because we
678 * already know that the pseudo-op begins with a '.'.
679 */
6efd877d 680
8ff6f40e
ILT
681 if (pop == NULL)
682 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
6efd877d 683
286cb27a
ILT
684 /* In MRI mode, we may need to insert an
685 automatic alignment directive. What a hack
686 this is. */
687 if (mri_pending_align
688 && (pop == NULL
689 || ! ((pop->poc_handler == cons
690 && pop->poc_val == 1)
691 || (pop->poc_handler == s_space
692 && pop->poc_val == 1))))
693 {
71dd3c40 694 do_align (1, (char *) NULL, 0);
286cb27a
ILT
695 mri_pending_align = 0;
696 }
697
6efd877d 698 /* Print the error msg now, while we still can */
8ff6f40e 699 if (pop == NULL)
6efd877d
KR
700 {
701 as_bad ("Unknown pseudo-op: `%s'", s);
f8701a3f 702 *input_line_pointer = c;
6efd877d 703 s_ignore (0);
46b81190 704 continue;
6efd877d
KR
705 }
706
707 /* Put it back for error messages etc. */
708 *input_line_pointer = c;
9c6d3f66
KR
709 /* The following skip of whitespace is compulsory.
710 A well shaped space is sometimes all that separates
711 keyword from operands. */
6efd877d 712 if (c == ' ' || c == '\t')
d4c8cbd8 713 input_line_pointer++;
6efd877d 714 /*
9471a360
KR
715 * Input_line is restored.
716 * Input_line_pointer->1st non-blank char
717 * after pseudo-operation.
718 */
46b81190 719 (*pop->poc_handler) (pop->poc_val);
e28c40d7
ILT
720
721 /* If that was .end, just get out now. */
722 if (pop->poc_handler == s_end)
723 goto quit;
6efd877d
KR
724 }
725 else
6efd877d 726 { /* machine instruction */
4026c122
ILT
727 int inquote = 0;
728
286cb27a
ILT
729 if (mri_pending_align)
730 {
71dd3c40 731 do_align (1, (char *) NULL, 0);
286cb27a
ILT
732 mri_pending_align = 0;
733 }
734
6efd877d
KR
735 /* WARNING: c has char, which may be end-of-line. */
736 /* Also: input_line_pointer->`\0` where c was. */
737 *input_line_pointer = c;
58d4951d 738 while (!is_end_of_line[(unsigned char) *input_line_pointer]
4026c122 739 || inquote
4064305e
SS
740#ifdef TC_EOL_IN_INSN
741 || TC_EOL_IN_INSN (input_line_pointer)
742#endif
743 )
6efd877d 744 {
cef72a92 745 if (flag_m68k_mri && *input_line_pointer == '\'')
4026c122 746 inquote = ! inquote;
6efd877d
KR
747 input_line_pointer++;
748 }
f8701a3f 749
6efd877d
KR
750 c = *input_line_pointer;
751 *input_line_pointer = '\0';
f8701a3f 752
326d16ca
KH
753#ifdef OBJ_GENERATE_ASM_LINENO
754 if (generate_asm_lineno == 0)
755 {
f10a96cb 756 if (ecoff_no_current_file ())
326d16ca
KH
757 generate_asm_lineno = 1;
758 }
f10a96cb
ILT
759 if (generate_asm_lineno == 1)
760 {
1b434ced
ILT
761 unsigned int lineno;
762 char *s;
763
daad3bbf 764 as_where (&s, &lineno);
326d16ca 765 OBJ_GENERATE_ASM_LINENO (s, lineno);
f10a96cb 766 }
daad3bbf
KH
767#endif
768
7e047ac2
ILT
769 if (macro_defined)
770 {
771 sb out;
772 const char *err;
773
774 if (check_macro (s, &out, '\0', &err))
775 {
776 if (err != NULL)
777 as_bad (err);
778 *input_line_pointer++ = c;
779 input_scrub_include_sb (&out,
780 input_line_pointer);
781 sb_kill (&out);
782 buffer_limit =
783 input_scrub_next_buffer (&input_line_pointer);
784 continue;
785 }
786 }
787
6efd877d 788 md_assemble (s); /* Assemble 1 instruction. */
f8701a3f 789
6efd877d 790 *input_line_pointer++ = c;
f8701a3f 791
d4c8cbd8
JL
792 /* We resume loop AFTER the end-of-line from
793 this instruction. */
6efd877d 794 } /* if (*s=='.') */
6efd877d 795 } /* if c==':' */
f8701a3f 796 continue;
6efd877d 797 } /* if (is_name_beginner(c) */
f8701a3f 798
f8701a3f 799
d4c8cbd8 800 /* Empty statement? */
58d4951d 801 if (is_end_of_line[(unsigned char) c])
d4c8cbd8 802 continue;
6efd877d 803
9777b772
KR
804 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
805 && isdigit (c))
d4c8cbd8
JL
806 {
807 /* local label ("4:") */
6efd877d
KR
808 char *backup = input_line_pointer;
809
810 HANDLE_CONDITIONAL_ASSEMBLY ();
811
812 temp = c - '0';
813
814 while (isdigit (*input_line_pointer))
815 {
816 temp = (temp * 10) + *input_line_pointer - '0';
817 ++input_line_pointer;
818 } /* read the whole number */
819
9777b772
KR
820 if (LOCAL_LABELS_DOLLAR
821 && *input_line_pointer == '$'
6efd877d
KR
822 && *(input_line_pointer + 1) == ':')
823 {
824 input_line_pointer += 2;
825
826 if (dollar_label_defined (temp))
827 {
828 as_fatal ("label \"%d$\" redefined", temp);
829 }
830
831 define_dollar_label (temp);
832 colon (dollar_label_name (temp, 0));
833 continue;
834 }
6efd877d 835
9777b772
KR
836 if (LOCAL_LABELS_FB
837 && *input_line_pointer++ == ':')
6efd877d
KR
838 {
839 fb_label_instance_inc (temp);
840 colon (fb_label_name (temp, 0));
841 continue;
842 }
6efd877d
KR
843
844 input_line_pointer = backup;
845 } /* local label ("4:") */
f8701a3f 846
6efd877d
KR
847 if (c && strchr (line_comment_chars, c))
848 { /* Its a comment. Better say APP or NO_APP */
f8701a3f
SC
849 char *ends;
850 char *new_buf;
851 char *new_tmp;
604633ae 852 unsigned int new_length;
f8701a3f 853 char *tmp_buf = 0;
6efd877d
KR
854
855 bump_line_counters ();
856 s = input_line_pointer;
857 if (strncmp (s, "APP\n", 4))
858 continue; /* We ignore it */
859 s += 4;
860
861 ends = strstr (s, "#NO_APP\n");
862
863 if (!ends)
864 {
604633ae
ILT
865 unsigned int tmp_len;
866 unsigned int num;
6efd877d 867
f8701a3f
SC
868 /* The end of the #APP wasn't in this buffer. We
869 keep reading in buffers until we find the #NO_APP
870 that goes with this #APP There is one. The specs
871 guarentee it. . . */
6efd877d 872 tmp_len = buffer_limit - s;
85825401 873 tmp_buf = xmalloc (tmp_len + 1);
4380166d 874 memcpy (tmp_buf, s, tmp_len);
6efd877d
KR
875 do
876 {
877 new_tmp = input_scrub_next_buffer (&buffer);
f8701a3f 878 if (!new_tmp)
6efd877d 879 break;
f8701a3f 880 else
6efd877d 881 buffer_limit = new_tmp;
f8701a3f 882 input_line_pointer = buffer;
6efd877d 883 ends = strstr (buffer, "#NO_APP\n");
f8701a3f 884 if (ends)
6efd877d 885 num = ends - buffer;
f8701a3f 886 else
6efd877d
KR
887 num = buffer_limit - buffer;
888
889 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
9eb5f4b8 890 memcpy (tmp_buf + tmp_len, buffer, num);
6efd877d
KR
891 tmp_len += num;
892 }
893 while (!ends);
894
895 input_line_pointer = ends ? ends + 8 : NULL;
896
897 s = tmp_buf;
898 ends = s + tmp_len;
899
900 }
901 else
902 {
903 input_line_pointer = ends + 8;
904 }
6efd877d
KR
905
906 scrub_string = s;
86038ada
ILT
907 scrub_string_end = ends;
908
909 new_length = ends - s;
910 new_buf = (char *) xmalloc (new_length);
911 new_tmp = new_buf;
6efd877d
KR
912 for (;;)
913 {
86038ada
ILT
914 int space;
915 int size;
f8701a3f 916
86038ada
ILT
917 space = (new_buf + new_length) - new_tmp;
918 size = do_scrub_chars (scrub_from_string, new_tmp, space);
919
920 if (size < space)
6efd877d 921 {
86038ada
ILT
922 new_tmp += size;
923 break;
f8701a3f 924 }
86038ada
ILT
925
926 new_buf = xrealloc (new_buf, new_length + 100);
927 new_tmp = new_buf + new_length;
928 new_length += 100;
fecd2382 929 }
f8701a3f
SC
930
931 if (tmp_buf)
6efd877d
KR
932 free (tmp_buf);
933 old_buffer = buffer;
934 old_input = input_line_pointer;
935 old_limit = buffer_limit;
936 buffer = new_buf;
937 input_line_pointer = new_buf;
938 buffer_limit = new_tmp;
f8701a3f
SC
939 continue;
940 }
941
6efd877d 942 HANDLE_CONDITIONAL_ASSEMBLY ();
f8701a3f 943
cef72a92
ILT
944#ifdef tc_unrecognized_line
945 if (tc_unrecognized_line (c))
946 continue;
947#endif
948
f8701a3f
SC
949 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
950 input_line_pointer--; /* Report unknown char as ignored. */
6efd877d
KR
951 ignore_rest_of_line ();
952 } /* while (input_line_pointer<buffer_limit) */
a2a5a4fa
KR
953
954#ifdef md_after_pass_hook
955 md_after_pass_hook ();
956#endif
957
6efd877d
KR
958 if (old_buffer)
959 {
86038ada 960 free (buffer);
6efd877d
KR
961 bump_line_counters ();
962 if (old_input != 0)
963 {
964 buffer = old_buffer;
965 input_line_pointer = old_input;
966 buffer_limit = old_limit;
f8701a3f
SC
967 old_buffer = 0;
968 goto contin;
969 }
970 }
6efd877d 971 } /* while (more buffers to scan) */
f8701a3f 972
e28c40d7
ILT
973 quit:
974 input_scrub_close (); /* Close the input file */
4075afe1 975}
fecd2382 976
18c9057f
ILT
977/* For most MRI pseudo-ops, the line actually ends at the first
978 nonquoted space. This function looks for that point, stuffs a null
979 in, and sets *STOPCP to the character that used to be there, and
42ac8fa8
ILT
980 returns the location.
981
982 Until I hear otherwise, I am going to assume that this is only true
983 for the m68k MRI assembler. */
18c9057f
ILT
984
985char *
986mri_comment_field (stopcp)
987 char *stopcp;
988{
42ac8fa8
ILT
989#ifdef TC_M68K
990
18c9057f
ILT
991 char *s;
992 int inquote = 0;
993
cef72a92 994 know (flag_m68k_mri);
18c9057f
ILT
995
996 for (s = input_line_pointer;
997 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
998 || inquote);
999 s++)
1000 {
1001 if (*s == '\'')
1002 inquote = ! inquote;
1003 }
1004 *stopcp = *s;
1005 *s = '\0';
1006 return s;
42ac8fa8
ILT
1007
1008#else
1009
1010 char *s;
1011
1012 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1013 ;
1014 *stopcp = *s;
1015 *s = '\0';
1016 return s;
1017
1018#endif
1019
18c9057f
ILT
1020}
1021
1022/* Skip to the end of an MRI comment field. */
1023
1024void
1025mri_comment_end (stop, stopc)
1026 char *stop;
1027 int stopc;
1028{
1029 know (flag_mri);
1030
1031 input_line_pointer = stop;
1032 *stop = stopc;
1033 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1034 ++input_line_pointer;
1035}
1036
6efd877d 1037void
604633ae
ILT
1038s_abort (ignore)
1039 int ignore;
6efd877d
KR
1040{
1041 as_fatal (".abort detected. Abandoning ship.");
4075afe1
KR
1042}
1043
1044/* Guts of .align directive. */
1045static void
71dd3c40 1046do_align (n, fill, len)
4075afe1
KR
1047 int n;
1048 char *fill;
71dd3c40 1049 int len;
4075afe1
KR
1050{
1051#ifdef md_do_align
71dd3c40 1052 md_do_align (n, fill, len, just_record_alignment);
4075afe1
KR
1053#endif
1054 if (!fill)
1055 {
1056 /* @@ Fix this right for BFD! */
1057 static char zero;
1058 static char nop_opcode = NOP_OPCODE;
1059
1060 if (now_seg != data_section && now_seg != bss_section)
1061 {
1062 fill = &nop_opcode;
1063 }
1064 else
1065 {
1066 fill = &zero;
1067 }
71dd3c40 1068 len = 1;
4075afe1 1069 }
71dd3c40 1070
4075afe1
KR
1071 /* Only make a frag if we HAVE to. . . */
1072 if (n && !need_pass_2)
71dd3c40
ILT
1073 {
1074 if (len <= 1)
1075 frag_align (n, *fill);
1076 else
1077 frag_align_pattern (n, fill, len);
1078 }
4075afe1 1079
c02fd8dc 1080#ifdef md_do_align
4075afe1 1081 just_record_alignment:
c02fd8dc
ILT
1082#endif
1083
4075afe1
KR
1084 record_alignment (now_seg, n);
1085}
fecd2382
RP
1086
1087/* For machines where ".align 4" means align to a 4 byte boundary. */
6efd877d
KR
1088void
1089s_align_bytes (arg)
1090 int arg;
fecd2382 1091{
6efd877d 1092 register unsigned int temp;
4075afe1 1093 char temp_fill;
6efd877d
KR
1094 unsigned int i = 0;
1095 unsigned long max_alignment = 1 << 15;
18c9057f
ILT
1096 char *stop = NULL;
1097 char stopc;
1098
1099 if (flag_mri)
1100 stop = mri_comment_field (&stopc);
f8701a3f 1101
58d4951d 1102 if (is_end_of_line[(unsigned char) *input_line_pointer])
4080c270
ILT
1103 {
1104 if (arg < 0)
1105 temp = 0;
1106 else
1107 temp = arg; /* Default value from pseudo-op table */
1108 }
6efd877d
KR
1109 else
1110 temp = get_absolute_expression ();
f8701a3f 1111
6efd877d
KR
1112 if (temp > max_alignment)
1113 {
1114 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
f8701a3f
SC
1115 }
1116
4075afe1
KR
1117 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1118 have to convert it. */
6efd877d
KR
1119 if (temp != 0)
1120 {
1121 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1122 ;
f8701a3f 1123 }
6efd877d
KR
1124 if (temp != 1)
1125 as_bad ("Alignment not a power of 2");
f8701a3f 1126
6efd877d
KR
1127 temp = i;
1128 if (*input_line_pointer == ',')
1129 {
71dd3c40 1130 offsetT fillval;
4080c270 1131 int len;
71dd3c40 1132
6efd877d 1133 input_line_pointer++;
71dd3c40 1134 fillval = get_absolute_expression ();
4080c270
ILT
1135 if (arg >= 0)
1136 len = 1;
1137 else
1138 len = - arg;
1139 if (len <= 1)
71dd3c40
ILT
1140 {
1141 temp_fill = fillval;
4080c270 1142 do_align (temp, &temp_fill, len);
71dd3c40
ILT
1143 }
1144 else
1145 {
1146 char ab[16];
1147
4080c270 1148 if (len > sizeof ab)
71dd3c40 1149 abort ();
4080c270
ILT
1150 md_number_to_chars (ab, fillval, len);
1151 do_align (temp, ab, len);
71dd3c40 1152 }
f8701a3f 1153 }
6efd877d 1154 else
71dd3c40 1155 {
4080c270 1156 if (arg < 0)
71dd3c40
ILT
1157 as_warn ("expected fill pattern missing");
1158 do_align (temp, (char *) NULL, 0);
1159 }
49864cfa 1160
18c9057f
ILT
1161 if (flag_mri)
1162 mri_comment_end (stop, stopc);
1163
6efd877d 1164 demand_empty_rest_of_line ();
4075afe1 1165}
fecd2382
RP
1166
1167/* For machines where ".align 4" means align to 2**4 boundary. */
6efd877d 1168void
71dd3c40
ILT
1169s_align_ptwo (arg)
1170 int arg;
6efd877d
KR
1171{
1172 register int temp;
4075afe1 1173 char temp_fill;
6efd877d 1174 long max_alignment = 15;
18c9057f
ILT
1175 char *stop = NULL;
1176 char stopc;
1177
1178 if (flag_mri)
1179 stop = mri_comment_field (&stopc);
6efd877d
KR
1180
1181 temp = get_absolute_expression ();
1182 if (temp > max_alignment)
1183 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1184 else if (temp < 0)
1185 {
1186 as_bad ("Alignment negative. 0 assumed.");
1187 temp = 0;
1188 }
1189 if (*input_line_pointer == ',')
1190 {
71dd3c40 1191 offsetT fillval;
4080c270 1192 int len;
71dd3c40 1193
6efd877d 1194 input_line_pointer++;
71dd3c40 1195 fillval = get_absolute_expression ();
4080c270
ILT
1196 if (arg >= 0)
1197 len = 1;
1198 else
1199 len = - arg;
1200 if (len <= 1)
71dd3c40
ILT
1201 {
1202 temp_fill = fillval;
4080c270 1203 do_align (temp, &temp_fill, len);
71dd3c40
ILT
1204 }
1205 else
1206 {
1207 char ab[16];
1208
4080c270 1209 if (len > sizeof ab)
71dd3c40 1210 abort ();
4080c270
ILT
1211 md_number_to_chars (ab, fillval, len);
1212 do_align (temp, ab, len);
71dd3c40 1213 }
6efd877d
KR
1214 }
1215 else
71dd3c40 1216 {
4080c270 1217 if (arg < 0)
71dd3c40
ILT
1218 as_warn ("expected fill pattern missing");
1219 do_align (temp, (char *) NULL, 0);
1220 }
6efd877d 1221
18c9057f
ILT
1222 if (flag_mri)
1223 mri_comment_end (stop, stopc);
1224
6efd877d 1225 demand_empty_rest_of_line ();
4075afe1 1226}
6efd877d
KR
1227
1228void
604633ae
ILT
1229s_comm (ignore)
1230 int ignore;
6efd877d
KR
1231{
1232 register char *name;
1233 register char c;
1234 register char *p;
58d4951d 1235 offsetT temp;
6efd877d 1236 register symbolS *symbolP;
18c9057f
ILT
1237 char *stop = NULL;
1238 char stopc;
1239
1240 if (flag_mri)
1241 stop = mri_comment_field (&stopc);
6efd877d
KR
1242
1243 name = input_line_pointer;
1244 c = get_symbol_end ();
1245 /* just after name is now '\0' */
1246 p = input_line_pointer;
1247 *p = c;
1248 SKIP_WHITESPACE ();
1249 if (*input_line_pointer != ',')
1250 {
1251 as_bad ("Expected comma after symbol-name: rest of line ignored.");
18c9057f
ILT
1252 if (flag_mri)
1253 mri_comment_end (stop, stopc);
6efd877d
KR
1254 ignore_rest_of_line ();
1255 return;
1256 }
1257 input_line_pointer++; /* skip ',' */
1258 if ((temp = get_absolute_expression ()) < 0)
1259 {
58d4951d 1260 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
18c9057f
ILT
1261 if (flag_mri)
1262 mri_comment_end (stop, stopc);
6efd877d
KR
1263 ignore_rest_of_line ();
1264 return;
1265 }
1266 *p = 0;
1267 symbolP = symbol_find_or_make (name);
1268 *p = c;
1269 if (S_IS_DEFINED (symbolP))
1270 {
6ef37255
KR
1271 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1272 S_GET_NAME (symbolP));
18c9057f
ILT
1273 if (flag_mri)
1274 mri_comment_end (stop, stopc);
6efd877d
KR
1275 ignore_rest_of_line ();
1276 return;
1277 }
1278 if (S_GET_VALUE (symbolP))
1279 {
58d4951d
ILT
1280 if (S_GET_VALUE (symbolP) != (valueT) temp)
1281 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
6efd877d 1282 S_GET_NAME (symbolP),
58d4951d
ILT
1283 (long) S_GET_VALUE (symbolP),
1284 (long) temp);
6efd877d
KR
1285 }
1286 else
1287 {
58d4951d 1288 S_SET_VALUE (symbolP, (valueT) temp);
6efd877d
KR
1289 S_SET_EXTERNAL (symbolP);
1290 }
9471a360 1291#ifdef OBJ_VMS
def66e24
DM
1292 {
1293 extern int flag_one;
1294 if ( (!temp) || !flag_one)
1295 S_GET_OTHER(symbolP) = const_flag;
1296 }
9471a360 1297#endif /* not OBJ_VMS */
6efd877d 1298 know (symbolP->sy_frag == &zero_address_frag);
18c9057f
ILT
1299
1300 if (flag_mri)
1301 mri_comment_end (stop, stopc);
1302
6efd877d
KR
1303 demand_empty_rest_of_line ();
1304} /* s_comm() */
fecd2382 1305
1356d77d
ILT
1306/* The MRI COMMON pseudo-op. We handle this by creating a common
1307 symbol with the appropriate name. We make s_space do the right
1308 thing by increasing the size. */
1309
1310void
1311s_mri_common (small)
1312 int small;
1313{
1314 char *name;
1315 char c;
1316 char *alc = NULL;
1317 symbolS *sym;
1318 offsetT align;
18c9057f
ILT
1319 char *stop = NULL;
1320 char stopc;
1356d77d
ILT
1321
1322 if (! flag_mri)
1323 {
1324 s_comm (0);
1325 return;
1326 }
1327
18c9057f
ILT
1328 stop = mri_comment_field (&stopc);
1329
1356d77d
ILT
1330 SKIP_WHITESPACE ();
1331
1332 name = input_line_pointer;
1333 if (! isdigit ((unsigned char) *name))
1334 c = get_symbol_end ();
1335 else
1336 {
1337 do
1338 {
1339 ++input_line_pointer;
1340 }
1341 while (isdigit ((unsigned char) *input_line_pointer));
1342 c = *input_line_pointer;
1343 *input_line_pointer = '\0';
1344
7e047ac2 1345 if (line_label != NULL)
1356d77d 1346 {
7e047ac2 1347 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1356d77d
ILT
1348 + (input_line_pointer - name)
1349 + 1);
7e047ac2 1350 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1356d77d
ILT
1351 name = alc;
1352 }
1353 }
1354
1355 sym = symbol_find_or_make (name);
1356 *input_line_pointer = c;
1357 if (alc != NULL)
1358 free (alc);
1359
1360 if (*input_line_pointer != ',')
1361 align = 0;
1362 else
1363 {
1364 ++input_line_pointer;
1365 align = get_absolute_expression ();
1366 }
1367
1368 if (S_IS_DEFINED (sym))
1369 {
1370#if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1371 if (! S_IS_COMMON (sym))
1372#endif
1373 {
1374 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
18c9057f 1375 mri_comment_end (stop, stopc);
1356d77d
ILT
1376 ignore_rest_of_line ();
1377 return;
1378 }
1379 }
1380
1381 S_SET_EXTERNAL (sym);
1382 mri_common_symbol = sym;
1383
1384#ifdef S_SET_ALIGN
1385 if (align != 0)
1386 S_SET_ALIGN (sym, align);
1387#endif
1388
7e047ac2 1389 if (line_label != NULL)
1356d77d 1390 {
7e047ac2
ILT
1391 line_label->sy_value.X_op = O_symbol;
1392 line_label->sy_value.X_add_symbol = sym;
1393 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1394 line_label->sy_frag = &zero_address_frag;
1395 S_SET_SEGMENT (line_label, expr_section);
1356d77d
ILT
1396 }
1397
1398 /* FIXME: We just ignore the small argument, which distinguishes
1399 COMMON and COMMON.S. I don't know what we can do about it. */
1400
1401 /* Ignore the type and hptype. */
1402 if (*input_line_pointer == ',')
1403 input_line_pointer += 2;
1404 if (*input_line_pointer == ',')
1405 input_line_pointer += 2;
18c9057f
ILT
1406
1407 mri_comment_end (stop, stopc);
1408
1356d77d
ILT
1409 demand_empty_rest_of_line ();
1410}
1411
fecd2382 1412void
604633ae
ILT
1413s_data (ignore)
1414 int ignore;
fecd2382 1415{
ffffc8fb 1416 segT section;
6efd877d 1417 register int temp;
f8701a3f 1418
6efd877d 1419 temp = get_absolute_expression ();
def66e24 1420 if (flag_readonly_data_in_text)
ffffc8fb
ILT
1421 {
1422 section = text_section;
1423 temp += 1000;
1424 }
1425 else
1426 section = data_section;
1427
ffffc8fb 1428 subseg_set (section, (subsegT) temp);
f8701a3f 1429
9471a360 1430#ifdef OBJ_VMS
6efd877d 1431 const_flag = 0;
fecd2382 1432#endif
6efd877d 1433 demand_empty_rest_of_line ();
fecd2382
RP
1434}
1435
9a7d824a 1436/* Handle the .appfile pseudo-op. This is automatically generated by
86038ada
ILT
1437 do_scrub_chars when a preprocessor # line comment is seen with a
1438 file name. This default definition may be overridden by the object
1439 or CPU specific pseudo-ops. This function is also the default
1440 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1441 .file. */
9a7d824a 1442
6efd877d 1443void
9a7d824a
ILT
1444s_app_file (appfile)
1445 int appfile;
6efd877d
KR
1446{
1447 register char *s;
1448 int length;
f8701a3f 1449
6efd877d
KR
1450 /* Some assemblers tolerate immediately following '"' */
1451 if ((s = demand_copy_string (&length)) != 0)
1452 {
9a7d824a
ILT
1453 /* If this is a fake .appfile, a fake newline was inserted into
1454 the buffer. Passing -2 to new_logical_line tells it to
1455 account for it. */
1456 new_logical_line (s, appfile ? -2 : -1);
cef72a92
ILT
1457
1458 /* In MRI mode, the preprocessor may have inserted an extraneous
1459 backquote. */
1460 if (flag_m68k_mri
1461 && *input_line_pointer == '\''
1462 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1463 ++input_line_pointer;
1464
6efd877d 1465 demand_empty_rest_of_line ();
9a7d824a
ILT
1466#ifdef LISTING
1467 if (listing)
1468 listing_source_file (s);
1469#endif
6efd877d 1470 }
2209b19c
KR
1471#ifdef obj_app_file
1472 obj_app_file (s);
40324362
KR
1473#endif
1474}
fecd2382 1475
9a7d824a 1476/* Handle the .appline pseudo-op. This is automatically generated by
86038ada
ILT
1477 do_scrub_chars when a preprocessor # line comment is seen. This
1478 default definition may be overridden by the object or CPU specific
1479 pseudo-ops. */
9a7d824a
ILT
1480
1481void
604633ae
ILT
1482s_app_line (ignore)
1483 int ignore;
9a7d824a
ILT
1484{
1485 int l;
1486
1487 /* The given number is that of the next line. */
1488 l = get_absolute_expression () - 1;
931a8fab
KR
1489 if (l < 0)
1490 /* Some of the back ends can't deal with non-positive line numbers.
1491 Besides, it's silly. */
1492 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1493 else
1494 {
1495 new_logical_line ((char *) NULL, l);
9a7d824a 1496#ifdef LISTING
931a8fab
KR
1497 if (listing)
1498 listing_source_line (l);
9a7d824a 1499#endif
931a8fab 1500 }
9a7d824a
ILT
1501 demand_empty_rest_of_line ();
1502}
1503
e28c40d7
ILT
1504/* Handle the .end pseudo-op. Actually, the real work is done in
1505 read_a_source_file. */
1506
1507void
1508s_end (ignore)
1509 int ignore;
1510{
1511 if (flag_mri)
1512 {
1513 /* The MRI assembler permits the start symbol to follow .end,
1514 but we don't support that. */
1515 SKIP_WHITESPACE ();
18c9057f
ILT
1516 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1517 && *input_line_pointer != '*'
1518 && *input_line_pointer != '!')
e28c40d7
ILT
1519 as_warn ("start address not supported");
1520 }
1521}
1522
42ac8fa8
ILT
1523/* Handle the .err pseudo-op. */
1524
1525void
1526s_err (ignore)
1527 int ignore;
1528{
1529 as_bad (".err encountered");
1530 demand_empty_rest_of_line ();
1531}
1532
e28c40d7
ILT
1533/* Handle the MRI fail pseudo-op. */
1534
1535void
1536s_fail (ignore)
1537 int ignore;
1538{
1539 offsetT temp;
18c9057f
ILT
1540 char *stop = NULL;
1541 char stopc;
1542
1543 if (flag_mri)
1544 stop = mri_comment_field (&stopc);
e28c40d7
ILT
1545
1546 temp = get_absolute_expression ();
1547 if (temp >= 500)
1548 as_warn (".fail %ld encountered", (long) temp);
1549 else
1550 as_bad (".fail %ld encountered", (long) temp);
18c9057f
ILT
1551
1552 if (flag_mri)
1553 mri_comment_end (stop, stopc);
1554
e28c40d7
ILT
1555 demand_empty_rest_of_line ();
1556}
1557
6efd877d 1558void
604633ae
ILT
1559s_fill (ignore)
1560 int ignore;
6efd877d
KR
1561{
1562 long temp_repeat = 0;
1563 long temp_size = 1;
1564 register long temp_fill = 0;
1565 char *p;
f8701a3f 1566
624c91d1
KR
1567#ifdef md_flush_pending_output
1568 md_flush_pending_output ();
1569#endif
7c2d4011 1570
6efd877d
KR
1571 temp_repeat = get_absolute_expression ();
1572 if (*input_line_pointer == ',')
1573 {
1574 input_line_pointer++;
1575 temp_size = get_absolute_expression ();
1576 if (*input_line_pointer == ',')
7c2d4011
SC
1577 {
1578 input_line_pointer++;
6efd877d 1579 temp_fill = get_absolute_expression ();
fecd2382 1580 }
6efd877d 1581 }
c8863a58 1582 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
fecd2382 1583#define BSD_FILL_SIZE_CROCK_8 (8)
6efd877d
KR
1584 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1585 {
1586 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1587 temp_size = BSD_FILL_SIZE_CROCK_8;
1588 }
1589 if (temp_size < 0)
1590 {
1591 as_warn ("Size negative: .fill ignored.");
1592 temp_size = 0;
1593 }
1594 else if (temp_repeat <= 0)
1595 {
1596 as_warn ("Repeat < 0, .fill ignored");
1597 temp_size = 0;
1598 }
7fd3560a 1599
6efd877d
KR
1600 if (temp_size && !need_pass_2)
1601 {
1602 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
604633ae 1603 memset (p, 0, (unsigned int) temp_size);
c8863a58
KR
1604 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1605 * flavoured AS. The following bizzare behaviour is to be
1606 * compatible with above. I guess they tried to take up to 8
1607 * bytes from a 4-byte expression and they forgot to sign
1608 * extend. Un*x Sux. */
fecd2382 1609#define BSD_FILL_SIZE_CROCK_4 (4)
604633ae 1610 md_number_to_chars (p, (valueT) temp_fill,
c8863a58
KR
1611 (temp_size > BSD_FILL_SIZE_CROCK_4
1612 ? BSD_FILL_SIZE_CROCK_4
1613 : (int) temp_size));
1614 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1615 * but emits no error message because it seems a legal thing to do.
1616 * It is a degenerate case of .fill but could be emitted by a compiler.
1617 */
6efd877d 1618 }
6efd877d 1619 demand_empty_rest_of_line ();
f8701a3f
SC
1620}
1621
6efd877d 1622void
604633ae
ILT
1623s_globl (ignore)
1624 int ignore;
6efd877d 1625{
40324362
KR
1626 char *name;
1627 int c;
1628 symbolS *symbolP;
18c9057f
ILT
1629 char *stop = NULL;
1630 char stopc;
1631
1632 if (flag_mri)
1633 stop = mri_comment_field (&stopc);
fecd2382 1634
6efd877d
KR
1635 do
1636 {
1637 name = input_line_pointer;
1638 c = get_symbol_end ();
1639 symbolP = symbol_find_or_make (name);
1640 *input_line_pointer = c;
1641 SKIP_WHITESPACE ();
1642 S_SET_EXTERNAL (symbolP);
1643 if (c == ',')
1644 {
1645 input_line_pointer++;
1646 SKIP_WHITESPACE ();
1647 if (*input_line_pointer == '\n')
1648 c = '\n';
1649 }
1650 }
1651 while (c == ',');
18c9057f
ILT
1652
1653 if (flag_mri)
1654 mri_comment_end (stop, stopc);
1655
6efd877d 1656 demand_empty_rest_of_line ();
40324362 1657}
6efd877d 1658
7e047ac2
ILT
1659/* Handle the MRI IRP and IRPC pseudo-ops. */
1660
1661void
1662s_irp (irpc)
1663 int irpc;
1664{
1665 char *file;
1666 unsigned int line;
1667 sb s;
1668 const char *err;
1669 sb out;
1670
1671 as_where (&file, &line);
1672
1673 sb_new (&s);
1674 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1675 sb_add_char (&s, *input_line_pointer++);
1676
1677 sb_new (&out);
1678
1679 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1680 if (err != NULL)
1681 as_bad_where (file, line, "%s", err);
1682
1683 sb_kill (&s);
1684
1685 input_scrub_include_sb (&out, input_line_pointer);
1686 sb_kill (&out);
1687 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1688}
1689
6efd877d
KR
1690void
1691s_lcomm (needs_align)
c8863a58
KR
1692 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1693 (alignment); 0 if it was an ".lcomm" (2 args only) */
1694 int needs_align;
fecd2382 1695{
6efd877d
KR
1696 register char *name;
1697 register char c;
1698 register char *p;
1699 register int temp;
1700 register symbolS *symbolP;
9a7d824a
ILT
1701 segT current_seg = now_seg;
1702 subsegT current_subseg = now_subseg;
6efd877d
KR
1703 const int max_alignment = 15;
1704 int align = 0;
9a7d824a 1705 segT bss_seg = bss_section;
6efd877d
KR
1706
1707 name = input_line_pointer;
1708 c = get_symbol_end ();
1709 p = input_line_pointer;
1710 *p = c;
1711 SKIP_WHITESPACE ();
46b81190
ILT
1712
1713 /* Accept an optional comma after the name. The comma used to be
1714 required, but Irix 5 cc does not generate it. */
1715 if (*input_line_pointer == ',')
6efd877d 1716 {
46b81190
ILT
1717 ++input_line_pointer;
1718 SKIP_WHITESPACE ();
6efd877d 1719 }
f8701a3f 1720
6efd877d
KR
1721 if (*input_line_pointer == '\n')
1722 {
1723 as_bad ("Missing size expression");
1724 return;
1725 }
f8701a3f 1726
6efd877d
KR
1727 if ((temp = get_absolute_expression ()) < 0)
1728 {
1729 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1730 ignore_rest_of_line ();
1731 return;
1732 }
f8701a3f 1733
2ef7731d 1734#if defined (TC_MIPS) || defined (TC_ALPHA)
a2a5a4fa
KR
1735 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1736 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
46b81190 1737 {
a2a5a4fa
KR
1738 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1739 if (temp <= bfd_get_gp_size (stdoutput))
1740 {
1741 bss_seg = subseg_new (".sbss", 1);
1742 seg_info (bss_seg)->bss = 1;
1743 }
46b81190 1744 }
9a7d824a 1745#endif
ede7bc1c
SC
1746 if (!needs_align)
1747 {
1748 /* FIXME. This needs to be machine independent. */
9d90491e
ILT
1749 if (temp >= 8)
1750 align = 3;
1751 else if (temp >= 4)
ede7bc1c
SC
1752 align = 2;
1753 else if (temp >= 2)
1754 align = 1;
1755 else
c71a604a 1756 align = 0;
ede7bc1c
SC
1757
1758 record_alignment(bss_seg, align);
1759 }
9a7d824a 1760
6efd877d
KR
1761 if (needs_align)
1762 {
1763 align = 0;
1764 SKIP_WHITESPACE ();
1765 if (*input_line_pointer != ',')
1766 {
1767 as_bad ("Expected comma after size");
1768 ignore_rest_of_line ();
1769 return;
1770 }
1771 input_line_pointer++;
1772 SKIP_WHITESPACE ();
1773 if (*input_line_pointer == '\n')
1774 {
1775 as_bad ("Missing alignment");
1776 return;
1777 }
1778 align = get_absolute_expression ();
1779 if (align > max_alignment)
1780 {
1781 align = max_alignment;
1782 as_warn ("Alignment too large: %d. assumed.", align);
1783 }
1784 else if (align < 0)
1785 {
1786 align = 0;
1787 as_warn ("Alignment negative. 0 assumed.");
1788 }
9a7d824a 1789 record_alignment (bss_seg, align);
6efd877d 1790 } /* if needs align */
4075afe1
KR
1791 else
1792 {
1793 /* Assume some objects may require alignment on some systems. */
1794#ifdef TC_ALPHA
1795 if (temp > 1)
1796 {
1797 align = ffs (temp) - 1;
1798 if (temp % (1 << align))
1799 abort ();
1800 }
1801#endif
1802 }
f8701a3f 1803
6efd877d
KR
1804 *p = 0;
1805 symbolP = symbol_find_or_make (name);
1806 *p = c;
f8701a3f 1807
6efd877d 1808 if (
fecd2382 1809#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6efd877d
KR
1810 S_GET_OTHER (symbolP) == 0 &&
1811 S_GET_DESC (symbolP) == 0 &&
fecd2382 1812#endif /* OBJ_AOUT or OBJ_BOUT */
9a7d824a 1813 (S_GET_SEGMENT (symbolP) == bss_seg
6efd877d
KR
1814 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1815 {
604633ae 1816 char *pfrag;
85825401 1817
9a7d824a 1818 subseg_set (bss_seg, 1);
85825401
ILT
1819
1820 if (align)
1821 frag_align (align, 0);
1822 /* detach from old frag */
9a7d824a 1823 if (S_GET_SEGMENT (symbolP) == bss_seg)
85825401
ILT
1824 symbolP->sy_frag->fr_symbol = NULL;
1825
1826 symbolP->sy_frag = frag_now;
604633ae
ILT
1827 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1828 temp, (char *)0);
1829 *pfrag = 0;
f8701a3f 1830
9a7d824a 1831 S_SET_SEGMENT (symbolP, bss_seg);
85825401 1832
fecd2382 1833#ifdef OBJ_COFF
6efd877d 1834 /* The symbol may already have been created with a preceding
c8863a58
KR
1835 ".globl" directive -- be careful not to step on storage class
1836 in that case. Otherwise, set it to static. */
6efd877d
KR
1837 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1838 {
1839 S_SET_STORAGE_CLASS (symbolP, C_STAT);
fecd2382 1840 }
6efd877d 1841#endif /* OBJ_COFF */
cef72a92
ILT
1842
1843#ifdef S_SET_SIZE
1844 S_SET_SIZE (symbolP, temp);
1845#endif
6efd877d
KR
1846 }
1847 else
6ef37255
KR
1848 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1849 S_GET_NAME (symbolP));
f8701a3f 1850
9a7d824a 1851 subseg_set (current_seg, current_subseg);
9a7d824a
ILT
1852
1853 demand_empty_rest_of_line ();
6efd877d 1854} /* s_lcomm() */
fecd2382 1855
6efd877d 1856void
604633ae
ILT
1857s_lsym (ignore)
1858 int ignore;
6efd877d
KR
1859{
1860 register char *name;
1861 register char c;
1862 register char *p;
6efd877d
KR
1863 expressionS exp;
1864 register symbolS *symbolP;
1865
1866 /* we permit ANY defined expression: BSD4.2 demands constants */
1867 name = input_line_pointer;
1868 c = get_symbol_end ();
1869 p = input_line_pointer;
1870 *p = c;
1871 SKIP_WHITESPACE ();
1872 if (*input_line_pointer != ',')
1873 {
1874 *p = 0;
1875 as_bad ("Expected comma after name \"%s\"", name);
1876 *p = c;
1877 ignore_rest_of_line ();
1878 return;
1879 }
1880 input_line_pointer++;
b31f2abb
KR
1881 expression (&exp);
1882 if (exp.X_op != O_constant
1883 && exp.X_op != O_register)
1884 {
1885 as_bad ("bad expression");
1886 ignore_rest_of_line ();
1887 return;
1888 }
6efd877d
KR
1889 *p = 0;
1890 symbolP = symbol_find_or_make (name);
f8701a3f 1891
c8863a58
KR
1892 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1893 symbolP->sy_desc == 0) out of this test because coff doesn't have
1894 those fields, and I can't see when they'd ever be tripped. I
1895 don't think I understand why they were here so I may have
1896 introduced a bug. As recently as 1.37 didn't have this test
1897 anyway. xoxorich. */
f8701a3f 1898
9471a360 1899 if (S_GET_SEGMENT (symbolP) == undefined_section
6efd877d
KR
1900 && S_GET_VALUE (symbolP) == 0)
1901 {
c8863a58
KR
1902 /* The name might be an undefined .global symbol; be sure to
1903 keep the "external" bit. */
b31f2abb
KR
1904 S_SET_SEGMENT (symbolP,
1905 (exp.X_op == O_constant
1906 ? absolute_section
1907 : reg_section));
1908 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d
KR
1909 }
1910 else
1911 {
1912 as_bad ("Symbol %s already defined", name);
1913 }
1914 *p = c;
1915 demand_empty_rest_of_line ();
1916} /* s_lsym() */
1917
7e047ac2
ILT
1918/* Read a line into an sb. */
1919
1920static int
1921get_line_sb (line)
1922 sb *line;
1923{
1924 if (input_line_pointer >= buffer_limit)
1925 {
1926 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1927 if (buffer_limit == 0)
1928 return 0;
1929 }
1930
1931 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1932 sb_add_char (line, *input_line_pointer++);
42ac8fa8
ILT
1933 while (input_line_pointer < buffer_limit
1934 && is_end_of_line[(unsigned char) *input_line_pointer])
7e047ac2
ILT
1935 {
1936 if (*input_line_pointer == '\n')
1937 {
1938 bump_line_counters ();
1939 LISTING_NEWLINE ();
1940 }
1941 ++input_line_pointer;
1942 }
1943 return 1;
1944}
1945
1946/* Define a macro. This is an interface to macro.c, which is shared
1947 between gas and gasp. */
1948
1949void
1950s_macro (ignore)
1951 int ignore;
1952{
1953 char *file;
1954 unsigned int line;
1955 sb s;
1956 sb label;
1957 const char *err;
1958
1959 as_where (&file, &line);
1960
1961 sb_new (&s);
1962 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1963 sb_add_char (&s, *input_line_pointer++);
1964
1965 sb_new (&label);
1966 if (line_label != NULL)
1967 sb_add_string (&label, S_GET_NAME (line_label));
1968
1969 demand_empty_rest_of_line ();
1970
1971 err = define_macro (0, &s, &label, get_line_sb);
1972 if (err != NULL)
1973 as_bad_where (file, line, "%s", err);
1974 else
1975 {
1976 if (line_label != NULL)
1977 {
1978 S_SET_SEGMENT (line_label, undefined_section);
1979 S_SET_VALUE (line_label, 0);
1980 line_label->sy_frag = &zero_address_frag;
1981 }
1982 }
1983
1984 sb_kill (&s);
1985}
1986
1987/* Handle the .mexit pseudo-op, which immediately exits a macro
1988 expansion. */
1989
1990void
1991s_mexit (ignore)
1992 int ignore;
1993{
1994 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1995}
1996
e28c40d7
ILT
1997/* Handle changing the location counter. */
1998
1999static void
2000do_org (segment, exp, fill)
2001 segT segment;
2002 expressionS *exp;
2003 int fill;
2004{
2005 if (segment != now_seg && segment != absolute_section)
2006 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2007 segment_name (segment), segment_name (now_seg));
2008
2009 if (now_seg == absolute_section)
2010 {
2011 if (fill != 0)
2012 as_warn ("ignoring fill value in absolute section");
2013 if (exp->X_op != O_constant)
2014 {
2015 as_bad ("only constant offsets supported in absolute section");
2016 exp->X_add_number = 0;
2017 }
2018 abs_section_offset = exp->X_add_number;
2019 }
2020 else
2021 {
2022 char *p;
2023
2024 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2025 exp->X_add_number, (char *) NULL);
2026 *p = fill;
2027 }
2028}
2029
6efd877d 2030void
604633ae
ILT
2031s_org (ignore)
2032 int ignore;
6efd877d
KR
2033{
2034 register segT segment;
2035 expressionS exp;
2036 register long temp_fill;
e28c40d7 2037
42ac8fa8
ILT
2038 /* The m68k MRI assembler has a different meaning for .org. It
2039 means to create an absolute section at a given address. We can't
2040 support that--use a linker script instead. */
cef72a92 2041 if (flag_m68k_mri)
69e077f3
ILT
2042 {
2043 as_bad ("MRI style ORG pseudo-op not supported");
2044 ignore_rest_of_line ();
2045 return;
2046 }
2047
9471a360
KR
2048 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2049 thing as a sub-segment-relative origin. Any absolute origin is
2050 given a warning, then assumed to be segment-relative. Any
2051 segmented origin expression ("foo+42") had better be in the right
2052 segment or the .org is ignored.
2053
2054 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2055 we never know sub-segment sizes when we are reading code. BSD
2056 will crash trying to emit negative numbers of filler bytes in
2057 certain .orgs. We don't crash, but see as-write for that code.
2058
2059 Don't make frag if need_pass_2==1. */
6efd877d
KR
2060 segment = get_known_segmented_expression (&exp);
2061 if (*input_line_pointer == ',')
2062 {
2063 input_line_pointer++;
2064 temp_fill = get_absolute_expression ();
2065 }
2066 else
2067 temp_fill = 0;
e28c40d7 2068
6efd877d 2069 if (!need_pass_2)
e28c40d7
ILT
2070 do_org (segment, &exp, temp_fill);
2071
6efd877d
KR
2072 demand_empty_rest_of_line ();
2073} /* s_org() */
2074
e14994d9
ILT
2075/* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2076 called by the obj-format routine which handles section changing
2077 when in MRI mode. It will create a new section, and return it. It
2078 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
2079 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
2080 BFD_ASSEMBLER is defined, the flags will be set in the section. */
2081
2082void
2083s_mri_sect (type)
2084 char *type;
2085{
42ac8fa8
ILT
2086#ifdef TC_M68K
2087
e14994d9
ILT
2088 char *name;
2089 char c;
2090 segT seg;
2091
2092 SKIP_WHITESPACE ();
2093
2094 name = input_line_pointer;
2095 if (! isdigit ((unsigned char) *name))
2096 c = get_symbol_end ();
2097 else
2098 {
2099 do
2100 {
2101 ++input_line_pointer;
2102 }
2103 while (isdigit ((unsigned char) *input_line_pointer));
2104 c = *input_line_pointer;
2105 *input_line_pointer = '\0';
2106 }
2107
2108 name = strdup (name);
2109 if (name == NULL)
2110 as_fatal ("virtual memory exhausted");
2111
2112 *input_line_pointer = c;
2113
2114 seg = subseg_new (name, 0);
2115
2116 if (*input_line_pointer == ',')
2117 {
2118 int align;
2119
2120 ++input_line_pointer;
2121 align = get_absolute_expression ();
2122 record_alignment (seg, align);
2123 }
2124
2125 *type = '\0';
2126 if (*input_line_pointer == ',')
2127 {
2128 c = *++input_line_pointer;
2129 c = toupper ((unsigned char) c);
2130 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2131 *type = c;
2132 else
2133 as_bad ("unrecognized section type");
2134 ++input_line_pointer;
2135
2136#ifdef BFD_ASSEMBLER
2137 {
2138 flagword flags;
2139
2140 flags = SEC_NO_FLAGS;
ca232972 2141 if (*type == 'C')
e14994d9 2142 flags = SEC_CODE;
ca232972 2143 else if (*type == 'D')
e14994d9 2144 flags = SEC_DATA;
ca232972 2145 else if (*type == 'R')
e14994d9
ILT
2146 flags = SEC_ROM;
2147 if (flags != SEC_NO_FLAGS)
2148 {
2149 if (! bfd_set_section_flags (stdoutput, seg, flags))
2150 as_warn ("error setting flags for \"%s\": %s",
ca232972 2151 bfd_section_name (stdoutput, seg),
e14994d9
ILT
2152 bfd_errmsg (bfd_get_error ()));
2153 }
2154 }
2155#endif
2156 }
2157
2158 /* Ignore the HP type. */
2159 if (*input_line_pointer == ',')
2160 input_line_pointer += 2;
2161
2162 demand_empty_rest_of_line ();
42ac8fa8
ILT
2163
2164#else /* ! TC_M68K */
2165#ifdef TC_I960
2166
2167 char *name;
2168 char c;
2169 segT seg;
2170
2171 SKIP_WHITESPACE ();
2172
2173 name = input_line_pointer;
2174 c = get_symbol_end ();
2175
2176 name = strdup (name);
2177 if (name == NULL)
2178 as_fatal ("virtual memory exhausted");
2179
2180 *input_line_pointer = c;
2181
2182 seg = subseg_new (name, 0);
2183
2184 if (*input_line_pointer != ',')
2185 *type = 'C';
2186 else
2187 {
2188 char *sectype;
2189
2190 ++input_line_pointer;
2191 SKIP_WHITESPACE ();
2192 sectype = input_line_pointer;
2193 c = get_symbol_end ();
2194 if (*sectype == '\0')
2195 *type = 'C';
2196 else if (strcasecmp (sectype, "text") == 0)
2197 *type = 'C';
2198 else if (strcasecmp (sectype, "data") == 0)
2199 *type = 'D';
2200 else if (strcasecmp (sectype, "romdata") == 0)
2201 *type = 'R';
2202 else
2203 as_warn ("unrecognized section type `%s'", sectype);
2204 *input_line_pointer = c;
2205 }
2206
2207 if (*input_line_pointer == ',')
2208 {
2209 char *seccmd;
2210
2211 ++input_line_pointer;
2212 SKIP_WHITESPACE ();
2213 seccmd = input_line_pointer;
2214 c = get_symbol_end ();
2215 if (strcasecmp (seccmd, "absolute") == 0)
2216 {
2217 as_bad ("absolute sections are not supported");
2218 *input_line_pointer = c;
2219 ignore_rest_of_line ();
2220 return;
2221 }
2222 else if (strcasecmp (seccmd, "align") == 0)
2223 {
2224 int align;
2225
2226 *input_line_pointer = c;
2227 align = get_absolute_expression ();
2228 record_alignment (seg, align);
2229 }
2230 else
2231 {
2232 as_warn ("unrecognized section command `%s'", seccmd);
2233 *input_line_pointer = c;
2234 }
2235 }
2236
2237 demand_empty_rest_of_line ();
2238
2239#else /* ! TC_I960 */
2240 /* The MRI assembler seems to use different forms of .sect for
2241 different targets. */
2242 abort ();
2243#endif /* ! TC_I960 */
2244#endif /* ! TC_M68K */
2245}
2246
2247/* Handle the .print pseudo-op. */
2248
2249void
2250s_print (ignore)
2251 int ignore;
2252{
2253 char *s;
2254 int len;
2255
2256 s = demand_copy_C_string (&len);
2257 printf ("%s\n", s);
2258 demand_empty_rest_of_line ();
2259}
2260
2261/* Handle the .purgem pseudo-op. */
2262
2263void
2264s_purgem (ignore)
2265 int ignore;
2266{
2267 if (is_it_end_of_statement ())
2268 {
2269 demand_empty_rest_of_line ();
2270 return;
2271 }
2272
2273 do
2274 {
2275 char *name;
2276 char c;
2277
2278 SKIP_WHITESPACE ();
2279 name = input_line_pointer;
2280 c = get_symbol_end ();
2281 delete_macro (name);
2282 *input_line_pointer = c;
2283 SKIP_WHITESPACE ();
2284 }
2285 while (*input_line_pointer++ == ',');
2286
2287 --input_line_pointer;
2288 demand_empty_rest_of_line ();
e14994d9
ILT
2289}
2290
7e047ac2
ILT
2291/* Handle the .rept pseudo-op. */
2292
2293void
2294s_rept (ignore)
2295 int ignore;
2296{
2297 int count;
2298 sb one;
2299 sb many;
2300
2301 count = get_absolute_expression ();
2302
2303 sb_new (&one);
2304 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2305 {
2306 as_bad ("rept without endr");
2307 return;
2308 }
2309
2310 sb_new (&many);
2311 while (count-- > 0)
2312 sb_add_sb (&many, &one);
2313
2314 sb_kill (&one);
2315
2316 input_scrub_include_sb (&many, input_line_pointer);
2317 sb_kill (&many);
2318 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2319}
2320
6efd877d 2321void
604633ae
ILT
2322s_set (ignore)
2323 int ignore;
6efd877d
KR
2324{
2325 register char *name;
2326 register char delim;
2327 register char *end_name;
2328 register symbolS *symbolP;
2329
2330 /*
c8863a58
KR
2331 * Especial apologies for the random logic:
2332 * this just grew, and could be parsed much more simply!
2333 * Dean in haste.
2334 */
6efd877d
KR
2335 name = input_line_pointer;
2336 delim = get_symbol_end ();
2337 end_name = input_line_pointer;
2338 *end_name = delim;
2339 SKIP_WHITESPACE ();
f8701a3f 2340
6efd877d
KR
2341 if (*input_line_pointer != ',')
2342 {
2343 *end_name = 0;
2344 as_bad ("Expected comma after name \"%s\"", name);
2345 *end_name = delim;
2346 ignore_rest_of_line ();
2347 return;
2348 }
2349
2350 input_line_pointer++;
2351 *end_name = 0;
2352
2353 if (name[0] == '.' && name[1] == '\0')
2354 {
2355 /* Turn '. = mumble' into a .org mumble */
2356 register segT segment;
2357 expressionS exp;
6efd877d
KR
2358
2359 segment = get_known_segmented_expression (&exp);
f8701a3f 2360
6efd877d 2361 if (!need_pass_2)
e28c40d7 2362 do_org (segment, &exp, 0);
6efd877d
KR
2363
2364 *end_name = delim;
2365 return;
2366 }
2367
2368 if ((symbolP = symbol_find (name)) == NULL
2369 && (symbolP = md_undefined_symbol (name)) == NULL)
2370 {
9471a360 2371 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
fecd2382 2372#ifdef OBJ_COFF
6efd877d
KR
2373 /* "set" symbols are local unless otherwise specified. */
2374 SF_SET_LOCAL (symbolP);
fecd2382 2375#endif /* OBJ_COFF */
f8701a3f 2376
6efd877d 2377 } /* make a new symbol */
f8701a3f 2378
6efd877d 2379 symbol_table_insert (symbolP);
f8701a3f 2380
6efd877d
KR
2381 *end_name = delim;
2382 pseudo_set (symbolP);
2383 demand_empty_rest_of_line ();
2384} /* s_set() */
fecd2382 2385
6efd877d
KR
2386void
2387s_space (mult)
2388 int mult;
b53ccaac 2389{
cd3b81bd 2390 expressionS exp;
931a8fab 2391 long temp_fill;
cd3b81bd 2392 char *p = 0;
3dce804d
ILT
2393 char *stop = NULL;
2394 char stopc;
6efd877d 2395
a2a5a4fa
KR
2396#ifdef md_flush_pending_output
2397 md_flush_pending_output ();
2398#endif
2399
3dce804d 2400 if (flag_mri)
18c9057f 2401 stop = mri_comment_field (&stopc);
3dce804d 2402
6efd877d 2403 /* Just like .fill, but temp_size = 1 */
cd3b81bd 2404 expression (&exp);
931a8fab 2405 if (exp.X_op == O_constant)
6efd877d 2406 {
cd3b81bd
KR
2407 long repeat;
2408
2409 repeat = exp.X_add_number;
2410 if (mult)
2411 repeat *= mult;
2412 if (repeat <= 0)
2413 {
4026c122
ILT
2414 if (! flag_mri || repeat < 0)
2415 as_warn (".space repeat count is %s, ignored",
2416 repeat ? "negative" : "zero");
3dce804d 2417 goto getout;
cd3b81bd
KR
2418 }
2419
e28c40d7
ILT
2420 /* If we are in the absolute section, just bump the offset. */
2421 if (now_seg == absolute_section)
2422 {
2423 abs_section_offset += repeat;
3dce804d 2424 goto getout;
e28c40d7
ILT
2425 }
2426
1356d77d
ILT
2427 /* If we are secretly in an MRI common section, then creating
2428 space just increases the size of the common symbol. */
2429 if (mri_common_symbol != NULL)
2430 {
2431 S_SET_VALUE (mri_common_symbol,
2432 S_GET_VALUE (mri_common_symbol) + repeat);
3dce804d 2433 goto getout;
1356d77d
ILT
2434 }
2435
cd3b81bd
KR
2436 if (!need_pass_2)
2437 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
931a8fab 2438 repeat, (char *) 0);
6efd877d
KR
2439 }
2440 else
2441 {
e28c40d7
ILT
2442 if (now_seg == absolute_section)
2443 {
2444 as_bad ("space allocation too complex in absolute section");
2445 subseg_set (text_section, 0);
2446 }
1356d77d
ILT
2447 if (mri_common_symbol != NULL)
2448 {
2449 as_bad ("space allocation too complex in common section");
2450 mri_common_symbol = NULL;
2451 }
cd3b81bd
KR
2452 if (!need_pass_2)
2453 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2454 make_expr_symbol (&exp), 0L, (char *) 0);
6efd877d 2455 }
931a8fab
KR
2456 SKIP_WHITESPACE ();
2457 if (*input_line_pointer == ',')
6efd877d 2458 {
931a8fab 2459 input_line_pointer++;
cd3b81bd 2460 temp_fill = get_absolute_expression ();
6efd877d 2461 }
cd3b81bd 2462 else
6efd877d 2463 {
cd3b81bd 2464 temp_fill = 0;
6efd877d 2465 }
cd3b81bd 2466 if (p)
6efd877d 2467 {
6efd877d
KR
2468 *p = temp_fill;
2469 }
3dce804d
ILT
2470
2471 getout:
2472 if (flag_mri)
18c9057f 2473 mri_comment_end (stop, stopc);
3dce804d 2474
6efd877d 2475 demand_empty_rest_of_line ();
cd3b81bd 2476}
fecd2382 2477
e28c40d7
ILT
2478/* This is like s_space, but the value is a floating point number with
2479 the given precision. This is for the MRI dcb.s pseudo-op and
2480 friends. */
2481
2482void
2483s_float_space (float_type)
2484 int float_type;
2485{
2486 offsetT count;
2487 int flen;
2488 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
18c9057f
ILT
2489 char *stop = NULL;
2490 char stopc;
2491
2492 if (flag_mri)
2493 stop = mri_comment_field (&stopc);
e28c40d7
ILT
2494
2495 count = get_absolute_expression ();
2496
2497 SKIP_WHITESPACE ();
2498 if (*input_line_pointer != ',')
2499 {
2500 as_bad ("missing value");
18c9057f
ILT
2501 if (flag_mri)
2502 mri_comment_end (stop, stopc);
e28c40d7
ILT
2503 ignore_rest_of_line ();
2504 return;
2505 }
2506
2507 ++input_line_pointer;
2508
2509 SKIP_WHITESPACE ();
2510
2511 /* Skip any 0{letter} that may be present. Don't even check if the
2512 * letter is legal. */
2513 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2514 input_line_pointer += 2;
2515
2516 /* Accept :xxxx, where the x's are hex digits, for a floating point
2517 with the exact digits specified. */
2518 if (input_line_pointer[0] == ':')
2519 {
2520 flen = hex_float (float_type, temp);
2521 if (flen < 0)
2522 {
18c9057f
ILT
2523 if (flag_mri)
2524 mri_comment_end (stop, stopc);
e28c40d7
ILT
2525 ignore_rest_of_line ();
2526 return;
2527 }
2528 }
2529 else
2530 {
2531 char *err;
2532
2533 err = md_atof (float_type, temp, &flen);
2534 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2535 know (flen > 0);
2536 if (err)
2537 {
2538 as_bad ("Bad floating literal: %s", err);
18c9057f
ILT
2539 if (flag_mri)
2540 mri_comment_end (stop, stopc);
e28c40d7
ILT
2541 ignore_rest_of_line ();
2542 return;
2543 }
2544 }
2545
2546 while (--count >= 0)
2547 {
2548 char *p;
2549
2550 p = frag_more (flen);
2551 memcpy (p, temp, (unsigned int) flen);
2552 }
2553
18c9057f
ILT
2554 if (flag_mri)
2555 mri_comment_end (stop, stopc);
2556
e28c40d7
ILT
2557 demand_empty_rest_of_line ();
2558}
2559
2560/* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2561
2562void
2563s_struct (ignore)
2564 int ignore;
2565{
18c9057f
ILT
2566 char *stop = NULL;
2567 char stopc;
2568
2569 if (flag_mri)
2570 stop = mri_comment_field (&stopc);
e28c40d7
ILT
2571 abs_section_offset = get_absolute_expression ();
2572 subseg_set (absolute_section, 0);
18c9057f
ILT
2573 if (flag_mri)
2574 mri_comment_end (stop, stopc);
e28c40d7
ILT
2575 demand_empty_rest_of_line ();
2576}
2577
fecd2382 2578void
604633ae
ILT
2579s_text (ignore)
2580 int ignore;
fecd2382 2581{
6efd877d 2582 register int temp;
f8701a3f 2583
6efd877d 2584 temp = get_absolute_expression ();
9471a360 2585 subseg_set (text_section, (subsegT) temp);
6efd877d 2586 demand_empty_rest_of_line ();
80d80c64
KR
2587#ifdef OBJ_VMS
2588 const_flag &= ~IN_DEFAULT_SECTION;
2589#endif
6efd877d 2590} /* s_text() */
fecd2382 2591\f
6efd877d 2592
6efd877d
KR
2593void
2594demand_empty_rest_of_line ()
2595{
2596 SKIP_WHITESPACE ();
58d4951d 2597 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
2598 {
2599 input_line_pointer++;
2600 }
2601 else
2602 {
2603 ignore_rest_of_line ();
2604 }
2605 /* Return having already swallowed end-of-line. */
2606} /* Return pointing just after end-of-line. */
fecd2382
RP
2607
2608void
6efd877d 2609ignore_rest_of_line () /* For suspect lines: gives warning. */
fecd2382 2610{
58d4951d 2611 if (!is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 2612 {
6efd877d
KR
2613 if (isprint (*input_line_pointer))
2614 as_bad ("Rest of line ignored. First ignored character is `%c'.",
f8701a3f
SC
2615 *input_line_pointer);
2616 else
6efd877d 2617 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
f8701a3f
SC
2618 *input_line_pointer);
2619 while (input_line_pointer < buffer_limit
58d4951d 2620 && !is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 2621 {
6efd877d 2622 input_line_pointer++;
f8701a3f
SC
2623 }
2624 }
6efd877d 2625 input_line_pointer++; /* Return pointing just after end-of-line. */
58d4951d 2626 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
fecd2382
RP
2627}
2628
2629/*
2630 * pseudo_set()
2631 *
2632 * In: Pointer to a symbol.
2633 * Input_line_pointer->expression.
2634 *
2635 * Out: Input_line_pointer->just after any whitespace after expression.
2636 * Tried to set symbol to value of expression.
2637 * Will change symbols type, value, and frag;
fecd2382
RP
2638 */
2639void
f8701a3f 2640pseudo_set (symbolP)
6efd877d 2641 symbolS *symbolP;
fecd2382 2642{
6efd877d 2643 expressionS exp;
daad3bbf 2644#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
f8701a3f 2645 int ext;
fecd2382 2646#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 2647
6efd877d 2648 know (symbolP); /* NULL pointer is logic error. */
daad3bbf 2649#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
6efd877d 2650 ext = S_IS_EXTERNAL (symbolP);
fecd2382 2651#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 2652
5ac34ac3 2653 (void) expression (&exp);
f8701a3f 2654
5ac34ac3
ILT
2655 if (exp.X_op == O_illegal)
2656 as_bad ("illegal expression; zero assumed");
2657 else if (exp.X_op == O_absent)
2658 as_bad ("missing expression; zero assumed");
2659 else if (exp.X_op == O_big)
2660 as_bad ("%s number invalid; zero assumed",
2661 exp.X_add_number > 0 ? "bignum" : "floating point");
2662 else if (exp.X_op == O_subtract
2663 && (S_GET_SEGMENT (exp.X_add_symbol)
2664 == S_GET_SEGMENT (exp.X_op_symbol))
2665 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2666 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
9471a360 2667 {
5ac34ac3
ILT
2668 exp.X_op = O_constant;
2669 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2670 - S_GET_VALUE (exp.X_op_symbol));
9471a360 2671 }
5ac34ac3
ILT
2672
2673 switch (exp.X_op)
9471a360 2674 {
5ac34ac3
ILT
2675 case O_illegal:
2676 case O_absent:
2677 case O_big:
2678 exp.X_add_number = 0;
2679 /* Fall through. */
2680 case O_constant:
9471a360 2681 S_SET_SEGMENT (symbolP, absolute_section);
daad3bbf 2682#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
5ac34ac3
ILT
2683 if (ext)
2684 S_SET_EXTERNAL (symbolP);
6efd877d 2685 else
6efd877d 2686 S_CLEAR_EXTERNAL (symbolP);
fecd2382 2687#endif /* OBJ_AOUT or OBJ_BOUT */
604633ae 2688 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d 2689 symbolP->sy_frag = &zero_address_frag;
5ac34ac3 2690 break;
f8701a3f 2691
5ac34ac3
ILT
2692 case O_register:
2693 S_SET_SEGMENT (symbolP, reg_section);
604633ae 2694 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
5ac34ac3
ILT
2695 symbolP->sy_frag = &zero_address_frag;
2696 break;
2697
2698 case O_symbol:
ef198870
KR
2699 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2700 || exp.X_add_number != 0)
5ac34ac3 2701 symbolP->sy_value = exp;
6efd877d
KR
2702 else
2703 {
80d80c64
KR
2704 symbolS *s = exp.X_add_symbol;
2705
2706 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
daad3bbf 2707#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
5ac34ac3
ILT
2708 if (ext)
2709 S_SET_EXTERNAL (symbolP);
2710 else
2711 S_CLEAR_EXTERNAL (symbolP);
fecd2382 2712#endif /* OBJ_AOUT or OBJ_BOUT */
5ac34ac3 2713 S_SET_VALUE (symbolP,
80d80c64
KR
2714 exp.X_add_number + S_GET_VALUE (s));
2715 symbolP->sy_frag = s->sy_frag;
ef198870 2716 copy_symbol_attributes (symbolP, s);
5ac34ac3
ILT
2717 }
2718 break;
f8701a3f 2719
5ac34ac3
ILT
2720 default:
2721 /* The value is some complex expression.
2722 FIXME: Should we set the segment to anything? */
2723 symbolP->sy_value = exp;
2724 break;
f8701a3f 2725 }
fecd2382
RP
2726}
2727\f
2728/*
2729 * cons()
2730 *
2731 * CONStruct more frag of .bytes, or .words etc.
2732 * Should need_pass_2 be 1 then emit no frag(s).
80aab579 2733 * This understands EXPRESSIONS.
fecd2382
RP
2734 *
2735 * Bug (?)
2736 *
2737 * This has a split personality. We use expression() to read the
2738 * value. We can detect if the value won't fit in a byte or word.
2739 * But we can't detect if expression() discarded significant digits
2740 * in the case of a long. Not worth the crocks required to fix it.
2741 */
2742
40324362
KR
2743/* Select a parser for cons expressions. */
2744
2745/* Some targets need to parse the expression in various fancy ways.
2746 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2747 (for example, the HPPA does this). Otherwise, you can define
2748 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2749 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2750 are defined, which is the normal case, then only simple expressions
2751 are permitted. */
2752
1356d77d
ILT
2753static void
2754parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2755
40324362
KR
2756#ifndef TC_PARSE_CONS_EXPRESSION
2757#ifdef BITFIELD_CONS_EXPRESSIONS
2758#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2759static void
2760parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2761#endif
40324362
KR
2762#ifdef REPEAT_CONS_EXPRESSIONS
2763#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2764static void
2765parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2766#endif
2767
2768/* If we haven't gotten one yet, just call expression. */
2769#ifndef TC_PARSE_CONS_EXPRESSION
2770#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2771#endif
2772#endif
2773
6efd877d
KR
2774/* worker to do .byte etc statements */
2775/* clobbers input_line_pointer, checks */
2776/* end-of-line. */
86038ada
ILT
2777static void
2778cons_worker (nbytes, rva)
604633ae 2779 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
86038ada 2780 int rva;
fecd2382 2781{
286cb27a 2782 int c;
6efd877d 2783 expressionS exp;
86038ada 2784 char *stop = NULL;
3dce804d 2785 char stopc;
f8701a3f 2786
a2a5a4fa
KR
2787#ifdef md_flush_pending_output
2788 md_flush_pending_output ();
2789#endif
2790
18c9057f
ILT
2791 if (flag_mri)
2792 stop = mri_comment_field (&stopc);
2793
40324362 2794 if (is_it_end_of_statement ())
6efd877d 2795 {
cef72a92
ILT
2796 if (flag_mri)
2797 mri_comment_end (stop, stopc);
40324362
KR
2798 demand_empty_rest_of_line ();
2799 return;
6efd877d 2800 }
40324362 2801
286cb27a 2802 c = 0;
40324362 2803 do
6efd877d 2804 {
cef72a92 2805 if (flag_m68k_mri)
1356d77d
ILT
2806 parse_mri_cons (&exp, (unsigned int) nbytes);
2807 else
2808 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
6594d6b9
KR
2809
2810 if (rva)
2811 {
2812 if (exp.X_op == O_symbol)
2813 exp.X_op = O_symbol_rva;
2814 else
2815 as_fatal ("rva without symbol");
2816 }
2817 emit_expr (&exp, (unsigned int) nbytes);
286cb27a 2818 ++c;
40324362 2819 }
18c9057f 2820 while (*input_line_pointer++ == ',');
40324362 2821
286cb27a
ILT
2822 /* In MRI mode, after an odd number of bytes, we must align to an
2823 even word boundary, unless the next instruction is a dc.b, ds.b
2824 or dcb.b. */
2825 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2826 mri_pending_align = 1;
2827
40324362 2828 input_line_pointer--; /* Put terminator back into stream. */
86038ada
ILT
2829
2830 if (flag_mri)
18c9057f 2831 mri_comment_end (stop, stopc);
86038ada 2832
40324362 2833 demand_empty_rest_of_line ();
30d3a445 2834}
f8701a3f 2835
86038ada
ILT
2836
2837void
2838cons (size)
2839 int size;
2840{
2841 cons_worker (size, 0);
2842}
2843
2844void
2845s_rva (size)
2846 int size;
2847{
2848 cons_worker (size, 1);
2849}
2850
2851
40324362
KR
2852/* Put the contents of expression EXP into the object file using
2853 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
f8701a3f 2854
40324362
KR
2855void
2856emit_expr (exp, nbytes)
2857 expressionS *exp;
2858 unsigned int nbytes;
2859{
5ac34ac3 2860 operatorT op;
40324362 2861 register char *p;
80aab579 2862 valueT extra_digit = 0;
f8701a3f 2863
40324362
KR
2864 /* Don't do anything if we are going to make another pass. */
2865 if (need_pass_2)
2866 return;
2867
5ac34ac3 2868 op = exp->X_op;
40324362 2869
e28c40d7
ILT
2870 /* Allow `.word 0' in the absolute section. */
2871 if (now_seg == absolute_section)
2872 {
2873 if (op != O_constant || exp->X_add_number != 0)
2874 as_bad ("attempt to store value in absolute section");
2875 abs_section_offset += nbytes;
2876 return;
2877 }
2878
80aab579
ILT
2879 /* Handle a negative bignum. */
2880 if (op == O_uminus
2881 && exp->X_add_number == 0
2882 && exp->X_add_symbol->sy_value.X_op == O_big
2883 && exp->X_add_symbol->sy_value.X_add_number > 0)
2884 {
2885 int i;
2886 unsigned long carry;
2887
2888 exp = &exp->X_add_symbol->sy_value;
2889
2890 /* Negate the bignum: one's complement each digit and add 1. */
2891 carry = 1;
2892 for (i = 0; i < exp->X_add_number; i++)
2893 {
2894 unsigned long next;
2895
2896 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
2897 & LITTLENUM_MASK)
2898 + carry);
2899 generic_bignum[i] = next & LITTLENUM_MASK;
2900 carry = next >> LITTLENUM_NUMBER_OF_BITS;
2901 }
2902
2903 /* We can ignore any carry out, because it will be handled by
2904 extra_digit if it is needed. */
2905
2906 extra_digit = (valueT) -1;
2907 op = O_big;
2908 }
2909
5ac34ac3 2910 if (op == O_absent || op == O_illegal)
6efd877d 2911 {
5ac34ac3
ILT
2912 as_warn ("zero assumed for missing expression");
2913 exp->X_add_number = 0;
2914 op = O_constant;
6efd877d 2915 }
80aab579 2916 else if (op == O_big && exp->X_add_number <= 0)
6efd877d 2917 {
80aab579 2918 as_bad ("floating point number invalid; zero assumed");
40324362 2919 exp->X_add_number = 0;
5ac34ac3 2920 op = O_constant;
40324362 2921 }
5ac34ac3 2922 else if (op == O_register)
6efd877d 2923 {
5ac34ac3
ILT
2924 as_warn ("register value used as expression");
2925 op = O_constant;
40324362 2926 }
6efd877d 2927
604633ae 2928 p = frag_more ((int) nbytes);
6efd877d 2929
40324362
KR
2930#ifndef WORKING_DOT_WORD
2931 /* If we have the difference of two symbols in a word, save it on
2932 the broken_words list. See the code in write.c. */
5ac34ac3 2933 if (op == O_subtract && nbytes == 2)
40324362
KR
2934 {
2935 struct broken_word *x;
2936
2937 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
2938 x->next_broken_word = broken_words;
2939 broken_words = x;
2940 x->frag = frag_now;
2941 x->word_goes_here = p;
2942 x->dispfrag = 0;
2943 x->add = exp->X_add_symbol;
5ac34ac3 2944 x->sub = exp->X_op_symbol;
40324362
KR
2945 x->addnum = exp->X_add_number;
2946 x->added = 0;
2947 new_broken_words++;
2948 return;
2949 }
f8701a3f 2950#endif
6efd877d 2951
80aab579
ILT
2952 /* If we have an integer, but the number of bytes is too large to
2953 pass to md_number_to_chars, handle it as a bignum. */
2954 if (op == O_constant && nbytes > sizeof (valueT))
2955 {
2956 valueT val;
2957 int gencnt;
2958
2959 if (! exp->X_unsigned && exp->X_add_number < 0)
2960 extra_digit = (valueT) -1;
2961 val = (valueT) exp->X_add_number;
2962 gencnt = 0;
2963 do
2964 {
2965 generic_bignum[gencnt] = val & LITTLENUM_MASK;
2966 val >>= LITTLENUM_NUMBER_OF_BITS;
2967 ++gencnt;
2968 }
2969 while (val != 0);
2970 op = exp->X_op = O_big;
2971 exp->X_add_number = gencnt;
2972 }
2973
5ac34ac3 2974 if (op == O_constant)
40324362 2975 {
44ce2f32
DE
2976 register valueT get;
2977 register valueT use;
2978 register valueT mask;
2979 register valueT unmask;
40324362
KR
2980
2981 /* JF << of >= number of bits in the object is undefined. In
2982 particular SPARC (Sun 4) has problems */
44ce2f32 2983 if (nbytes >= sizeof (valueT))
40324362
KR
2984 mask = 0;
2985 else
d2550c72 2986 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
6efd877d 2987
40324362 2988 unmask = ~mask; /* Do store these bits. */
6efd877d 2989
40324362
KR
2990#ifdef NEVER
2991 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2992 mask = ~(unmask >> 1); /* Includes sign bit now. */
2993#endif
6efd877d 2994
40324362
KR
2995 get = exp->X_add_number;
2996 use = get & unmask;
2997 if ((get & mask) != 0 && (get & mask) != mask)
2998 { /* Leading bits contain both 0s & 1s. */
58d4951d 2999 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
40324362 3000 }
604633ae 3001 /* put bytes in right order. */
44ce2f32 3002 md_number_to_chars (p, use, (int) nbytes);
40324362 3003 }
80aab579
ILT
3004 else if (op == O_big)
3005 {
3006 int size;
3007 LITTLENUM_TYPE *nums;
3008
3009 know (nbytes % CHARS_PER_LITTLENUM == 0);
3010
3011 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3012 if (nbytes < size)
3013 {
3014 as_warn ("Bignum truncated to %d bytes", nbytes);
3015 size = nbytes;
3016 }
3017
3018 if (target_big_endian)
3019 {
3020 while (nbytes > size)
3021 {
3022 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3023 nbytes -= CHARS_PER_LITTLENUM;
3024 p += CHARS_PER_LITTLENUM;
3025 }
3026
3027 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3028 while (size > 0)
3029 {
3030 --nums;
3031 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3032 size -= CHARS_PER_LITTLENUM;
3033 p += CHARS_PER_LITTLENUM;
3034 }
3035 }
3036 else
3037 {
3038 nums = generic_bignum;
3039 while (size > 0)
3040 {
3041 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3042 ++nums;
3043 size -= CHARS_PER_LITTLENUM;
3044 p += CHARS_PER_LITTLENUM;
3045 nbytes -= CHARS_PER_LITTLENUM;
3046 }
3047
3048 while (nbytes > 0)
3049 {
3050 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3051 nbytes -= CHARS_PER_LITTLENUM;
3052 p += CHARS_PER_LITTLENUM;
3053 }
3054 }
3055 }
40324362
KR
3056 else
3057 {
1fbfe108 3058 memset (p, 0, nbytes);
6efd877d 3059
40324362
KR
3060 /* Now we need to generate a fixS to record the symbol value.
3061 This is easy for BFD. For other targets it can be more
3062 complex. For very complex cases (currently, the HPPA and
3063 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3064 want. For simpler cases, you can define TC_CONS_RELOC to be
3065 the name of the reloc code that should be stored in the fixS.
3066 If neither is defined, the code uses NO_RELOC if it is
3067 defined, and otherwise uses 0. */
6efd877d 3068
40324362 3069#ifdef BFD_ASSEMBLER
4064305e
SS
3070#ifdef TC_CONS_FIX_NEW
3071 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3072#else
604633ae 3073 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 3074 /* @@ Should look at CPU word size. */
ba71c54d 3075 nbytes == 2 ? BFD_RELOC_16
86038ada
ILT
3076 : nbytes == 8 ? BFD_RELOC_64
3077 : BFD_RELOC_32);
4064305e 3078#endif
40324362
KR
3079#else
3080#ifdef TC_CONS_FIX_NEW
3081 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3082#else
3083 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3084 it is defined, otherwise use NO_RELOC if it is defined,
3085 otherwise use 0. */
3086#ifndef TC_CONS_RELOC
3087#ifdef NO_RELOC
3088#define TC_CONS_RELOC NO_RELOC
3089#else
3090#define TC_CONS_RELOC 0
3091#endif
3092#endif
80aab579 3093 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 3094 TC_CONS_RELOC);
40324362
KR
3095#endif /* TC_CONS_FIX_NEW */
3096#endif /* BFD_ASSEMBLER */
3097 }
3098}
3099\f
3100#ifdef BITFIELD_CONS_EXPRESSIONS
6efd877d 3101
40324362
KR
3102/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3103 w:x,y:z, where w and y are bitwidths and x and y are values. They
3104 then pack them all together. We do a little better in that we allow
3105 them in words, longs, etc. and we'll pack them in target byte order
3106 for you.
6efd877d 3107
40324362
KR
3108 The rules are: pack least significat bit first, if a field doesn't
3109 entirely fit, put it in the next unit. Overflowing the bitfield is
3110 explicitly *not* even a warning. The bitwidth should be considered
3111 a "mask".
6efd877d 3112
40324362
KR
3113 To use this function the tc-XXX.h file should define
3114 BITFIELD_CONS_EXPRESSIONS. */
f8701a3f 3115
40324362
KR
3116static void
3117parse_bitfield_cons (exp, nbytes)
3118 expressionS *exp;
3119 unsigned int nbytes;
3120{
3121 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3122 char *hold = input_line_pointer;
f8701a3f 3123
5ac34ac3 3124 (void) expression (exp);
f8701a3f 3125
40324362
KR
3126 if (*input_line_pointer == ':')
3127 { /* bitfields */
3128 long value = 0;
f8701a3f 3129
40324362
KR
3130 for (;;)
3131 {
3132 unsigned long width;
f8701a3f 3133
40324362
KR
3134 if (*input_line_pointer != ':')
3135 {
3136 input_line_pointer = hold;
3137 break;
3138 } /* next piece is not a bitfield */
3139
3140 /* In the general case, we can't allow
3141 full expressions with symbol
3142 differences and such. The relocation
3143 entries for symbols not defined in this
3144 assembly would require arbitrary field
3145 widths, positions, and masks which most
3146 of our current object formats don't
3147 support.
cd3b81bd 3148
40324362
KR
3149 In the specific case where a symbol
3150 *is* defined in this assembly, we
3151 *could* build fixups and track it, but
3152 this could lead to confusion for the
3153 backends. I'm lazy. I'll take any
3154 SEG_ABSOLUTE. I think that means that
3155 you can use a previous .set or
3156 .equ type symbol. xoxorich. */
3157
5ac34ac3 3158 if (exp->X_op == O_absent)
6efd877d 3159 {
5ac34ac3 3160 as_warn ("using a bit field width of zero");
40324362 3161 exp->X_add_number = 0;
5ac34ac3 3162 exp->X_op = O_constant;
40324362
KR
3163 } /* implied zero width bitfield */
3164
5ac34ac3 3165 if (exp->X_op != O_constant)
6efd877d 3166 {
40324362 3167 *input_line_pointer = '\0';
5ac34ac3 3168 as_bad ("field width \"%s\" too complex for a bitfield", hold);
40324362
KR
3169 *input_line_pointer = ':';
3170 demand_empty_rest_of_line ();
3171 return;
3172 } /* too complex */
3173
3174 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
9471a360 3175 {
80aab579 3176 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
40324362
KR
3177 width, nbytes, (BITS_PER_CHAR * nbytes));
3178 width = BITS_PER_CHAR * nbytes;
3179 } /* too big */
3180
3181 if (width > bits_available)
9471a360 3182 {
40324362
KR
3183 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3184 input_line_pointer = hold;
3185 exp->X_add_number = value;
3186 break;
3187 } /* won't fit */
3188
3189 hold = ++input_line_pointer; /* skip ':' */
3190
5ac34ac3
ILT
3191 (void) expression (exp);
3192 if (exp->X_op != O_constant)
9471a360 3193 {
40324362
KR
3194 char cache = *input_line_pointer;
3195
3196 *input_line_pointer = '\0';
5ac34ac3 3197 as_bad ("field value \"%s\" too complex for a bitfield", hold);
40324362
KR
3198 *input_line_pointer = cache;
3199 demand_empty_rest_of_line ();
3200 return;
3201 } /* too complex */
3202
5ac34ac3
ILT
3203 value |= ((~(-1 << width) & exp->X_add_number)
3204 << ((BITS_PER_CHAR * nbytes) - bits_available));
40324362
KR
3205
3206 if ((bits_available -= width) == 0
3207 || is_it_end_of_statement ()
3208 || *input_line_pointer != ',')
3209 {
3210 break;
3211 } /* all the bitfields we're gonna get */
3212
3213 hold = ++input_line_pointer;
5ac34ac3 3214 (void) expression (exp);
40324362
KR
3215 } /* forever loop */
3216
3217 exp->X_add_number = value;
5ac34ac3 3218 exp->X_op = O_constant;
80aab579 3219 exp->X_unsigned = 1;
40324362
KR
3220 } /* if looks like a bitfield */
3221} /* parse_bitfield_cons() */
3222
3223#endif /* BITFIELD_CONS_EXPRESSIONS */
3224\f
1356d77d 3225/* Handle an MRI style string expression. */
40324362
KR
3226
3227static void
3228parse_mri_cons (exp, nbytes)
3229 expressionS *exp;
3230 unsigned int nbytes;
3231{
1356d77d
ILT
3232 if (*input_line_pointer != '\''
3233 && (input_line_pointer[1] != '\''
3234 || (*input_line_pointer != 'A'
3235 && *input_line_pointer != 'E')))
3236 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3237 else
40324362 3238 {
40324362
KR
3239 int scan = 0;
3240 unsigned int result = 0;
1356d77d
ILT
3241
3242 /* An MRI style string. Cut into as many bytes as will fit into
3243 a nbyte chunk, left justify if necessary, and separate with
3244 commas so we can try again later. */
3245 if (*input_line_pointer == 'A')
3246 ++input_line_pointer;
3247 else if (*input_line_pointer == 'E')
3248 {
3249 as_bad ("EBCDIC constants are not supported");
3250 ++input_line_pointer;
3251 }
3252
40324362
KR
3253 input_line_pointer++;
3254 for (scan = 0; scan < nbytes; scan++)
3255 {
3256 if (*input_line_pointer == '\'')
3257 {
3258 if (input_line_pointer[1] == '\'')
6efd877d 3259 {
40324362 3260 input_line_pointer++;
f8701a3f 3261 }
40324362
KR
3262 else
3263 break;
9471a360 3264 }
40324362
KR
3265 result = (result << 8) | (*input_line_pointer++);
3266 }
f8701a3f 3267
40324362
KR
3268 /* Left justify */
3269 while (scan < nbytes)
3270 {
3271 result <<= 8;
3272 scan++;
3273 }
3274 /* Create correct expression */
5ac34ac3 3275 exp->X_op = O_constant;
40324362 3276 exp->X_add_number = result;
40324362
KR
3277 /* Fake it so that we can read the next char too */
3278 if (input_line_pointer[0] != '\'' ||
3279 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3280 {
3281 input_line_pointer -= 2;
3282 input_line_pointer[0] = ',';
3283 input_line_pointer[1] = '\'';
3284 }
3285 else
3286 input_line_pointer++;
3287 }
40324362 3288}
40324362
KR
3289\f
3290#ifdef REPEAT_CONS_EXPRESSIONS
3291
3292/* Parse a repeat expression for cons. This is used by the MIPS
3293 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3294 object file COUNT times.
3295
3296 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3297
3298static void
3299parse_repeat_cons (exp, nbytes)
3300 expressionS *exp;
3301 unsigned int nbytes;
3302{
3303 expressionS count;
40324362
KR
3304 register int i;
3305
3306 expression (exp);
3307
3308 if (*input_line_pointer != ':')
3309 {
3310 /* No repeat count. */
3311 return;
3312 }
3313
3314 ++input_line_pointer;
5ac34ac3
ILT
3315 expression (&count);
3316 if (count.X_op != O_constant
40324362
KR
3317 || count.X_add_number <= 0)
3318 {
3319 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3320 return;
3321 }
3322
3323 /* The cons function is going to output this expression once. So we
3324 output it count - 1 times. */
3325 for (i = count.X_add_number - 1; i > 0; i--)
3326 emit_expr (exp, nbytes);
3327}
3328
3329#endif /* REPEAT_CONS_EXPRESSIONS */
fecd2382 3330\f
e28c40d7
ILT
3331/* Parse a floating point number represented as a hex constant. This
3332 permits users to specify the exact bits they want in the floating
3333 point number. */
3334
3335static int
3336hex_float (float_type, bytes)
3337 int float_type;
3338 char *bytes;
3339{
3340 int length;
3341 int i;
3342
3343 switch (float_type)
3344 {
3345 case 'f':
3346 case 'F':
3347 case 's':
3348 case 'S':
3349 length = 4;
3350 break;
3351
3352 case 'd':
3353 case 'D':
3354 case 'r':
3355 case 'R':
3356 length = 8;
3357 break;
3358
3359 case 'x':
3360 case 'X':
3361 length = 12;
3362 break;
3363
3364 case 'p':
3365 case 'P':
3366 length = 12;
3367 break;
3368
3369 default:
3370 as_bad ("Unknown floating type type '%c'", float_type);
3371 return -1;
3372 }
3373
3374 /* It would be nice if we could go through expression to parse the
3375 hex constant, but if we get a bignum it's a pain to sort it into
3376 the buffer correctly. */
3377 i = 0;
3378 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3379 {
3380 int d;
3381
3382 /* The MRI assembler accepts arbitrary underscores strewn about
3383 through the hex constant, so we ignore them as well. */
3384 if (*input_line_pointer == '_')
3385 {
3386 ++input_line_pointer;
3387 continue;
3388 }
3389
3390 if (i >= length)
3391 {
3392 as_warn ("Floating point constant too large");
3393 return -1;
3394 }
3395 d = hex_value (*input_line_pointer) << 4;
3396 ++input_line_pointer;
3397 while (*input_line_pointer == '_')
3398 ++input_line_pointer;
3399 if (hex_p (*input_line_pointer))
3400 {
3401 d += hex_value (*input_line_pointer);
3402 ++input_line_pointer;
3403 }
a920b693
ILT
3404 if (target_big_endian)
3405 bytes[i] = d;
3406 else
3407 bytes[length - i - 1] = d;
3408 ++i;
e28c40d7
ILT
3409 }
3410
3411 if (i < length)
a920b693
ILT
3412 {
3413 if (target_big_endian)
3414 memset (bytes + i, 0, length - i);
3415 else
3416 memset (bytes, 0, length - i);
3417 }
e28c40d7
ILT
3418
3419 return length;
3420}
3421
fecd2382
RP
3422/*
3423 * float_cons()
3424 *
3425 * CONStruct some more frag chars of .floats .ffloats etc.
3426 * Makes 0 or more new frags.
3427 * If need_pass_2 == 1, no frags are emitted.
3428 * This understands only floating literals, not expressions. Sorry.
3429 *
3430 * A floating constant is defined by atof_generic(), except it is preceded
3431 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3432 * reading, I decided to be incompatible. This always tries to give you
3433 * rounded bits to the precision of the pseudo-op. Former AS did premature
3434 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3435 * a choice of 2 flavours of noise according to which of 2 floating-point
3436 * scanners you directed AS to use.
3437 *
3438 * In: input_line_pointer->whitespace before, or '0' of flonum.
3439 *
3440 */
3441
ba71c54d
KR
3442void
3443float_cons (float_type)
6efd877d 3444 /* Clobbers input_line-pointer, checks end-of-line. */
f8701a3f 3445 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
fecd2382 3446{
6efd877d 3447 register char *p;
6efd877d
KR
3448 int length; /* Number of chars in an object. */
3449 register char *err; /* Error from scanning floating literal. */
3450 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
f8701a3f 3451
6efd877d 3452 if (is_it_end_of_statement ())
f8701a3f 3453 {
1e9cf565
ILT
3454 demand_empty_rest_of_line ();
3455 return;
f8701a3f 3456 }
1e9cf565
ILT
3457
3458 do
f8701a3f
SC
3459 {
3460 /* input_line_pointer->1st char of a flonum (we hope!). */
6efd877d 3461 SKIP_WHITESPACE ();
1e9cf565 3462
f8701a3f
SC
3463 /* Skip any 0{letter} that may be present. Don't even check if the
3464 * letter is legal. Someone may invent a "z" format and this routine
3465 * has no use for such information. Lusers beware: you get
3466 * diagnostics if your input is ill-conditioned.
3467 */
6efd877d
KR
3468 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3469 input_line_pointer += 2;
f8701a3f 3470
1356d77d
ILT
3471 /* Accept :xxxx, where the x's are hex digits, for a floating
3472 point with the exact digits specified. */
3473 if (input_line_pointer[0] == ':')
f8701a3f 3474 {
e28c40d7
ILT
3475 ++input_line_pointer;
3476 length = hex_float (float_type, temp);
3477 if (length < 0)
1356d77d 3478 {
1356d77d
ILT
3479 ignore_rest_of_line ();
3480 return;
3481 }
1356d77d
ILT
3482 }
3483 else
3484 {
3485 err = md_atof (float_type, temp, &length);
3486 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3487 know (length > 0);
3488 if (err)
3489 {
3490 as_bad ("Bad floating literal: %s", err);
3491 ignore_rest_of_line ();
3492 return;
3493 }
f8701a3f 3494 }
1e9cf565
ILT
3495
3496 if (!need_pass_2)
f8701a3f 3497 {
1e9cf565
ILT
3498 int count;
3499
3500 count = 1;
3501
3502#ifdef REPEAT_CONS_EXPRESSIONS
3503 if (*input_line_pointer == ':')
3504 {
1e9cf565
ILT
3505 expressionS count_exp;
3506
3507 ++input_line_pointer;
5ac34ac3
ILT
3508 expression (&count_exp);
3509 if (count_exp.X_op != O_constant
1e9cf565
ILT
3510 || count_exp.X_add_number <= 0)
3511 {
5ac34ac3 3512 as_warn ("unresolvable or nonpositive repeat count; using 1");
1e9cf565
ILT
3513 }
3514 else
3515 count = count_exp.X_add_number;
3516 }
3517#endif
3518
3519 while (--count >= 0)
a39116f1 3520 {
f8701a3f 3521 p = frag_more (length);
604633ae 3522 memcpy (p, temp, (unsigned int) length);
a39116f1 3523 }
542e1629 3524 }
1e9cf565 3525 SKIP_WHITESPACE ();
f8701a3f 3526 }
1e9cf565
ILT
3527 while (*input_line_pointer++ == ',');
3528
3529 --input_line_pointer; /* Put terminator back into stream. */
6efd877d 3530 demand_empty_rest_of_line ();
f8701a3f 3531} /* float_cons() */
fecd2382
RP
3532\f
3533/*
3534 * stringer()
3535 *
3536 * We read 0 or more ',' seperated, double-quoted strings.
3537 *
3538 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3539 */
a39116f1
RP
3540
3541
6efd877d
KR
3542void
3543stringer (append_zero) /* Worker to do .ascii etc statements. */
3544 /* Checks end-of-line. */
f8701a3f 3545 register int append_zero; /* 0: don't append '\0', else 1 */
fecd2382 3546{
f8701a3f 3547 register unsigned int c;
6efd877d 3548
a2a5a4fa
KR
3549#ifdef md_flush_pending_output
3550 md_flush_pending_output ();
3551#endif
3552
f8701a3f
SC
3553 /*
3554 * The following awkward logic is to parse ZERO or more strings,
3555 * comma seperated. Recall a string expression includes spaces
3556 * before the opening '\"' and spaces after the closing '\"'.
3557 * We fake a leading ',' if there is (supposed to be)
3558 * a 1st, expression. We keep demanding expressions for each
3559 * ','.
3560 */
6efd877d
KR
3561 if (is_it_end_of_statement ())
3562 {
3563 c = 0; /* Skip loop. */
3564 ++input_line_pointer; /* Compensate for end of loop. */
3565 }
f8701a3f 3566 else
6efd877d
KR
3567 {
3568 c = ','; /* Do loop. */
3569 }
3570 while (c == ',' || c == '<' || c == '"')
3571 {
3572 SKIP_WHITESPACE ();
3573 switch (*input_line_pointer)
3574 {
3575 case '\"':
3576 ++input_line_pointer; /*->1st char of string. */
3577 while (is_a_char (c = next_char_of_string ()))
3578 {
3579 FRAG_APPEND_1_CHAR (c);
3580 }
3581 if (append_zero)
3582 {
3583 FRAG_APPEND_1_CHAR (0);
3584 }
3585 know (input_line_pointer[-1] == '\"');
3586 break;
3587 case '<':
3588 input_line_pointer++;
3589 c = get_single_number ();
3590 FRAG_APPEND_1_CHAR (c);
3591 if (*input_line_pointer != '>')
3592 {
3593 as_bad ("Expected <nn>");
3594 }
3595 input_line_pointer++;
3596 break;
3597 case ',':
3598 input_line_pointer++;
3599 break;
3600 }
3601 SKIP_WHITESPACE ();
3602 c = *input_line_pointer;
f8701a3f 3603 }
f8701a3f 3604
6efd877d
KR
3605 demand_empty_rest_of_line ();
3606} /* stringer() */
fecd2382 3607\f
6efd877d 3608/* FIXME-SOMEDAY: I had trouble here on characters with the
f8701a3f
SC
3609 high bits set. We'll probably also have trouble with
3610 multibyte chars, wide chars, etc. Also be careful about
3611 returning values bigger than 1 byte. xoxorich. */
fecd2382 3612
6efd877d
KR
3613unsigned int
3614next_char_of_string ()
3615{
3616 register unsigned int c;
3617
3618 c = *input_line_pointer++ & CHAR_MASK;
3619 switch (c)
3620 {
3621 case '\"':
3622 c = NOT_A_CHAR;
3623 break;
3624
ddb393cf 3625#ifndef NO_STRING_ESCAPES
6efd877d
KR
3626 case '\\':
3627 switch (c = *input_line_pointer++)
3628 {
3629 case 'b':
3630 c = '\b';
3631 break;
3632
3633 case 'f':
3634 c = '\f';
3635 break;
3636
3637 case 'n':
3638 c = '\n';
3639 break;
3640
3641 case 'r':
3642 c = '\r';
3643 break;
3644
3645 case 't':
3646 c = '\t';
3647 break;
3648
6efd877d
KR
3649 case 'v':
3650 c = '\013';
3651 break;
6efd877d
KR
3652
3653 case '\\':
3654 case '"':
3655 break; /* As itself. */
3656
3657 case '0':
3658 case '1':
3659 case '2':
3660 case '3':
3661 case '4':
3662 case '5':
3663 case '6':
3664 case '7':
3665 case '8':
3666 case '9':
3667 {
3668 long number;
d4c8cbd8 3669 int i;
6efd877d 3670
d4c8cbd8 3671 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
6efd877d
KR
3672 {
3673 number = number * 8 + c - '0';
3674 }
3675 c = number & 0xff;
3676 }
3677 --input_line_pointer;
3678 break;
3679
d4c8cbd8
JL
3680 case 'x':
3681 case 'X':
3682 {
3683 long number;
3684
3685 number = 0;
3686 c = *input_line_pointer++;
3687 while (isxdigit (c))
3688 {
3689 if (isdigit (c))
3690 number = number * 16 + c - '0';
3691 else if (isupper (c))
3692 number = number * 16 + c - 'A' + 10;
3693 else
3694 number = number * 16 + c - 'a' + 10;
3695 c = *input_line_pointer++;
3696 }
3697 c = number & 0xff;
3698 --input_line_pointer;
3699 }
3700 break;
3701
6efd877d
KR
3702 case '\n':
3703 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3704 as_warn ("Unterminated string: Newline inserted.");
3705 c = '\n';
3706 break;
3707
3708 default:
3709
fecd2382 3710#ifdef ONLY_STANDARD_ESCAPES
6efd877d
KR
3711 as_bad ("Bad escaped character in string, '?' assumed");
3712 c = '?';
fecd2382 3713#endif /* ONLY_STANDARD_ESCAPES */
6efd877d
KR
3714
3715 break;
3716 } /* switch on escaped char */
3717 break;
ddb393cf 3718#endif /* ! defined (NO_STRING_ESCAPES) */
6efd877d
KR
3719
3720 default:
3721 break;
3722 } /* switch on char */
3723 return (c);
3724} /* next_char_of_string() */
fecd2382
RP
3725\f
3726static segT
f8701a3f 3727get_segmented_expression (expP)
6efd877d 3728 register expressionS *expP;
fecd2382 3729{
6efd877d 3730 register segT retval;
f8701a3f 3731
9471a360 3732 retval = expression (expP);
5ac34ac3
ILT
3733 if (expP->X_op == O_illegal
3734 || expP->X_op == O_absent
3735 || expP->X_op == O_big)
f8701a3f 3736 {
5ac34ac3
ILT
3737 as_bad ("expected address expression; zero assumed");
3738 expP->X_op = O_constant;
6efd877d 3739 expP->X_add_number = 0;
5ac34ac3 3740 retval = absolute_section;
f8701a3f 3741 }
5ac34ac3 3742 return retval;
fecd2382
RP
3743}
3744
6efd877d
KR
3745static segT
3746get_known_segmented_expression (expP)
3747 register expressionS *expP;
fecd2382 3748{
6efd877d 3749 register segT retval;
f8701a3f 3750
9471a360 3751 if ((retval = get_segmented_expression (expP)) == undefined_section)
f8701a3f 3752 {
5ac34ac3
ILT
3753 /* There is no easy way to extract the undefined symbol from the
3754 expression. */
3755 if (expP->X_add_symbol != NULL
3756 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3757 as_warn ("symbol \"%s\" undefined; zero assumed",
3758 S_GET_NAME (expP->X_add_symbol));
f8701a3f 3759 else
5ac34ac3
ILT
3760 as_warn ("some symbol undefined; zero assumed");
3761 retval = absolute_section;
3762 expP->X_op = O_constant;
6efd877d 3763 expP->X_add_number = 0;
f8701a3f 3764 }
5ac34ac3 3765 know (retval == absolute_section || SEG_NORMAL (retval));
f8701a3f 3766 return (retval);
fecd2382
RP
3767} /* get_known_segmented_expression() */
3768
58d4951d 3769offsetT
f8701a3f 3770get_absolute_expression ()
fecd2382 3771{
6efd877d 3772 expressionS exp;
f8701a3f 3773
5ac34ac3
ILT
3774 expression (&exp);
3775 if (exp.X_op != O_constant)
f8701a3f 3776 {
5ac34ac3 3777 if (exp.X_op != O_absent)
cd3b81bd 3778 as_bad ("bad or irreducible absolute expression; zero assumed");
6efd877d 3779 exp.X_add_number = 0;
f8701a3f 3780 }
5ac34ac3 3781 return exp.X_add_number;
fecd2382
RP
3782}
3783
6efd877d
KR
3784char /* return terminator */
3785get_absolute_expression_and_terminator (val_pointer)
3786 long *val_pointer; /* return value of expression */
fecd2382 3787{
58d4951d
ILT
3788 /* FIXME: val_pointer should probably be offsetT *. */
3789 *val_pointer = (long) get_absolute_expression ();
6efd877d 3790 return (*input_line_pointer++);
fecd2382
RP
3791}
3792\f
3793/*
3794 * demand_copy_C_string()
3795 *
3796 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3797 * Give a warning if that happens.
3798 */
3799char *
f8701a3f 3800demand_copy_C_string (len_pointer)
6efd877d 3801 int *len_pointer;
fecd2382 3802{
6efd877d 3803 register char *s;
f8701a3f 3804
6efd877d 3805 if ((s = demand_copy_string (len_pointer)) != 0)
f8701a3f
SC
3806 {
3807 register int len;
3808
6594d6b9 3809 for (len = *len_pointer; len > 0; len--)
f8701a3f 3810 {
6efd877d 3811 if (*s == 0)
fecd2382 3812 {
f8701a3f
SC
3813 s = 0;
3814 len = 1;
6efd877d
KR
3815 *len_pointer = 0;
3816 as_bad ("This string may not contain \'\\0\'");
fecd2382 3817 }
f8701a3f
SC
3818 }
3819 }
6594d6b9 3820 return s;
fecd2382
RP
3821}
3822\f
3823/*
3824 * demand_copy_string()
3825 *
3826 * Demand string, but return a safe (=private) copy of the string.
3827 * Return NULL if we can't read a string here.
3828 */
6ef37255 3829char *
6efd877d
KR
3830demand_copy_string (lenP)
3831 int *lenP;
fecd2382 3832{
6efd877d
KR
3833 register unsigned int c;
3834 register int len;
3835 char *retval;
3836
3837 len = 0;
3838 SKIP_WHITESPACE ();
3839 if (*input_line_pointer == '\"')
3840 {
3841 input_line_pointer++; /* Skip opening quote. */
3842
3843 while (is_a_char (c = next_char_of_string ()))
3844 {
3845 obstack_1grow (&notes, c);
3846 len++;
fecd2382 3847 }
42ac8fa8
ILT
3848 /* JF this next line is so demand_copy_C_string will return a
3849 null terminated string. */
6efd877d
KR
3850 obstack_1grow (&notes, '\0');
3851 retval = obstack_finish (&notes);
3852 }
3853 else
3854 {
3855 as_warn ("Missing string");
3856 retval = NULL;
3857 ignore_rest_of_line ();
3858 }
3859 *lenP = len;
3860 return (retval);
3861} /* demand_copy_string() */
fecd2382
RP
3862\f
3863/*
3864 * is_it_end_of_statement()
3865 *
3866 * In: Input_line_pointer->next character.
3867 *
3868 * Do: Skip input_line_pointer over all whitespace.
3869 *
3870 * Out: 1 if input_line_pointer->end-of-line.
f8701a3f 3871*/
6efd877d
KR
3872int
3873is_it_end_of_statement ()
3874{
3875 SKIP_WHITESPACE ();
58d4951d 3876 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6efd877d 3877} /* is_it_end_of_statement() */
fecd2382 3878
6efd877d
KR
3879void
3880equals (sym_name)
3881 char *sym_name;
fecd2382 3882{
6efd877d 3883 register symbolS *symbolP; /* symbol we are working with */
86038ada 3884 char *stop;
18c9057f 3885 char stopc;
f8701a3f
SC
3886
3887 input_line_pointer++;
6efd877d 3888 if (*input_line_pointer == '=')
f8701a3f
SC
3889 input_line_pointer++;
3890
6efd877d 3891 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
f8701a3f
SC
3892 input_line_pointer++;
3893
86038ada 3894 if (flag_mri)
18c9057f 3895 stop = mri_comment_field (&stopc);
86038ada 3896
6efd877d
KR
3897 if (sym_name[0] == '.' && sym_name[1] == '\0')
3898 {
3899 /* Turn '. = mumble' into a .org mumble */
3900 register segT segment;
3901 expressionS exp;
f8701a3f 3902
6efd877d
KR
3903 segment = get_known_segmented_expression (&exp);
3904 if (!need_pass_2)
e28c40d7 3905 do_org (segment, &exp, 0);
6efd877d
KR
3906 }
3907 else
3908 {
3909 symbolP = symbol_find_or_make (sym_name);
3910 pseudo_set (symbolP);
3911 }
86038ada
ILT
3912
3913 if (flag_mri)
18c9057f 3914 mri_comment_end (stop, stopc);
6efd877d 3915} /* equals() */
fecd2382
RP
3916
3917/* .include -- include a file at this point. */
3918
3919/* ARGSUSED */
6efd877d
KR
3920void
3921s_include (arg)
3922 int arg;
fecd2382 3923{
f8701a3f
SC
3924 char *newbuf;
3925 char *filename;
3926 int i;
3927 FILE *try;
3928 char *path;
3929
cef72a92 3930 if (! flag_m68k_mri)
ca232972
ILT
3931 filename = demand_copy_string (&i);
3932 else
3933 {
3934 SKIP_WHITESPACE ();
3935 i = 0;
3936 while (! is_end_of_line[(unsigned char) *input_line_pointer]
3937 && *input_line_pointer != ' '
3938 && *input_line_pointer != '\t')
3939 {
3940 obstack_1grow (&notes, *input_line_pointer);
3941 ++input_line_pointer;
3942 ++i;
3943 }
3944 obstack_1grow (&notes, '\0');
3945 filename = obstack_finish (&notes);
42ac8fa8
ILT
3946 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3947 ++input_line_pointer;
ca232972 3948 }
6efd877d 3949 demand_empty_rest_of_line ();
604633ae 3950 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
6efd877d
KR
3951 for (i = 0; i < include_dir_count; i++)
3952 {
3953 strcpy (path, include_dirs[i]);
3954 strcat (path, "/");
3955 strcat (path, filename);
f2889110 3956 if (0 != (try = fopen (path, "r")))
6efd877d
KR
3957 {
3958 fclose (try);
3959 goto gotit;
3960 }
3961 }
3962 free (path);
f8701a3f
SC
3963 path = filename;
3964gotit:
3965 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3966 newbuf = input_scrub_include_file (path, input_line_pointer);
3967 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6efd877d 3968} /* s_include() */
fecd2382 3969
6efd877d
KR
3970void
3971add_include_dir (path)
3972 char *path;
fecd2382 3973{
f8701a3f
SC
3974 int i;
3975
3976 if (include_dir_count == 0)
3977 {
6efd877d 3978 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
f8701a3f
SC
3979 include_dirs[0] = "."; /* Current dir */
3980 include_dir_count = 2;
3981 }
3982 else
3983 {
3984 include_dir_count++;
6efd877d
KR
3985 include_dirs = (char **) realloc (include_dirs,
3986 include_dir_count * sizeof (*include_dirs));
f8701a3f
SC
3987 }
3988
6efd877d 3989 include_dirs[include_dir_count - 1] = path; /* New one */
f8701a3f 3990
6efd877d
KR
3991 i = strlen (path);
3992 if (i > include_dir_maxlen)
3993 include_dir_maxlen = i;
3994} /* add_include_dir() */
fecd2382 3995
6efd877d
KR
3996void
3997s_ignore (arg)
3998 int arg;
fecd2382 3999{
58d4951d 4000 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
4001 {
4002 ++input_line_pointer;
4003 }
4004 ++input_line_pointer;
4064305e
SS
4005}
4006
604633ae 4007
6594d6b9
KR
4008void
4009read_print_statistics (file)
4010 FILE *file;
4011{
4012 hash_print_statistics (file, "pseudo-op table", po_hash);
4013}
4014
fecd2382 4015/* end of read.c */
This page took 0.426097 seconds and 4 git commands to generate.