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