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