* elf32-i386.c (elf_howto_table): Set pcrel_offset to true for
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
fecd2382 1/* read.c - read a source file -
5ac34ac3 2 Copyright (C) 1986, 1987, 1990, 1991, 1993 Free Software Foundation, Inc.
3340f7e5 3
f8701a3f
SC
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GAS is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GAS; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
fecd2382 19
016e0d42 20#if 0
fecd2382
RP
21#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
25 */
016e0d42
ILT
26#else
27#define MASK_CHAR ((int)(unsigned char)-1)
28#endif
fecd2382 29
9a7d824a 30
9471a360
KR
31/* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
fecd2382 33
9471a360 34#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
fecd2382 35
016e0d42
ILT
36/* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
fecd2382 38
9471a360 39/* for isdigit() */
6efd877d
KR
40#include <ctype.h>
41
fecd2382 42#include "as.h"
9471a360
KR
43#ifdef BFD_ASSEMBLER
44#include "subsegs.h"
45#endif
fecd2382
RP
46
47#include "obstack.h"
9a7d824a
ILT
48#include "listing.h"
49
50
51#ifndef TC_START_LABEL
52#define TC_START_LABEL(x,y) (x==':')
53#endif
fecd2382 54
016e0d42
ILT
55/* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
57 * on it
58 */
59#ifndef NOP_OPCODE
60#define NOP_OPCODE 0x00
61#endif
62
63char *input_line_pointer; /*->next char of source file to parse. */
fecd2382
RP
64
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
016e0d42
ILT
76/* used by is_... macros. our ctype[] */
77const char lex_type[256] =
78{
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
81 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
82 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
c978e704 83 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
016e0d42
ILT
84 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
85 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94};
95
96
97/*
fecd2382
RP
98 * In: a character.
99 * Out: 1 if this character ends a line.
100 */
101#define _ (0)
016e0d42
ILT
102char is_end_of_line[256] =
103{
fecd2382 104#ifdef CR_EOL
016e0d42 105 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
fecd2382 106#else
016e0d42 107 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
fecd2382 108#endif
016e0d42 109 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
40324362
KR
110#ifdef TC_HPPA
111 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
112 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
113#else
016e0d42
ILT
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
115 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
40324362 116#endif
016e0d42
ILT
117 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
118 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
119 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
126};
fecd2382
RP
127#undef _
128
016e0d42
ILT
129/* Functions private to this file. */
130
131static char *buffer; /* 1st char of each buffer of lines is here. */
132static char *buffer_limit; /*->1 + last char in buffer. */
fecd2382 133
016e0d42
ILT
134static char *bignum_low; /* Lowest char of bignum. */
135static char *bignum_limit; /* 1st illegal address of bignum. */
136static char *bignum_high; /* Highest char of bignum. */
137/* May point to (bignum_start-1). */
138/* Never >= bignum_limit. */
fecd2382 139
9c6d3f66
KR
140int target_big_endian;
141
9471a360 142static char *old_buffer; /* JF a hack */
016e0d42
ILT
143static char *old_input;
144static char *old_limit;
fecd2382 145
016e0d42 146/* Variables for handling include file directory list. */
fecd2382 147
016e0d42
ILT
148char **include_dirs; /* List of pointers to directories to
149 search for .include's */
150int include_dir_count; /* How many are in the list */
151int include_dir_maxlen = 1;/* Length of longest in list */
fecd2382
RP
152
153#ifndef WORKING_DOT_WORD
016e0d42 154struct broken_word *broken_words;
9471a360 155int new_broken_words;
fecd2382
RP
156#endif
157
016e0d42
ILT
158static char *demand_copy_string PARAMS ((int *lenP));
159int is_it_end_of_statement PARAMS ((void));
160unsigned int next_char_of_string PARAMS ((void));
5ac34ac3 161static segT get_segmented_expression PARAMS ((expressionS *expP));
016e0d42
ILT
162static segT get_known_segmented_expression PARAMS ((expressionS * expP));
163static void grow_bignum PARAMS ((void));
164static void pobegin PARAMS ((void));
fecd2382 165
016e0d42 166extern int listing;
fecd2382 167\f
6efd877d 168
016e0d42
ILT
169void
170read_begin ()
fecd2382 171{
016e0d42 172 const char *p;
f8701a3f 173
6efd877d
KR
174 pobegin ();
175 obj_read_begin_hook ();
f8701a3f 176
4380166d
KR
177 /* Something close -- but not too close -- to a multiple of 1024.
178 The debugging malloc I'm using has 24 bytes of overhead. */
179 obstack_begin (&notes, 5090);
180 obstack_begin (&cond_obstack, 990);
f8701a3f 181
fecd2382 182#define BIGNUM_BEGIN_SIZE (16)
6efd877d 183 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
f8701a3f
SC
184 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
185
186 /* Use machine dependent syntax */
187 for (p = line_separator_chars; *p; p++)
188 is_end_of_line[*p] = 1;
189 /* Use more. FIXME-SOMEDAY. */
fecd2382
RP
190}
191\f
192/* set up pseudo-op tables */
193
c8863a58 194struct hash_control *po_hash;
fecd2382 195
016e0d42 196static const pseudo_typeS potable[] =
fecd2382 197{
6efd877d
KR
198 {"abort", s_abort, 0},
199 {"align", s_align_ptwo, 0},
200 {"ascii", stringer, 0},
201 {"asciz", stringer, 1},
f8701a3f 202/* block */
6efd877d
KR
203 {"byte", cons, 1},
204 {"comm", s_comm, 0},
205 {"data", s_data, 0},
f8701a3f 206/* dim */
6efd877d 207 {"double", float_cons, 'd'},
f8701a3f 208/* dsect */
6efd877d
KR
209 {"eject", listing_eject, 0}, /* Formfeed listing */
210 {"else", s_else, 0},
211 {"end", s_end, 0},
212 {"endif", s_endif, 0},
f8701a3f 213/* endef */
6efd877d 214 {"equ", s_set, 0},
f8701a3f
SC
215/* err */
216/* extend */
6efd877d 217 {"extern", s_ignore, 0}, /* We treat all undef as ext */
9a7d824a
ILT
218 {"appfile", s_app_file, 1},
219 {"appline", s_app_line, 0},
6efd877d
KR
220 {"file", s_app_file, 0},
221 {"fill", s_fill, 0},
222 {"float", float_cons, 'f'},
6efd877d
KR
223 {"global", s_globl, 0},
224 {"globl", s_globl, 0},
225 {"hword", cons, 2},
226 {"if", s_if, 0},
227 {"ifdef", s_ifdef, 0},
228 {"ifeqs", s_ifeqs, 0},
229 {"ifndef", s_ifdef, 1},
230 {"ifnes", s_ifeqs, 1},
231 {"ifnotdef", s_ifdef, 1},
232 {"include", s_include, 0},
233 {"int", cons, 4},
234 {"lcomm", s_lcomm, 0},
235 {"lflags", listing_flags, 0}, /* Listing flags */
236 {"list", listing_list, 1}, /* Turn listing on */
237 {"long", cons, 4},
238 {"lsym", s_lsym, 0},
239 {"nolist", listing_list, 0}, /* Turn listing off */
240 {"octa", big_cons, 16},
241 {"org", s_org, 0},
242 {"psize", listing_psize, 0}, /* set paper size */
f8701a3f 243/* print */
6efd877d
KR
244 {"quad", big_cons, 8},
245 {"sbttl", listing_title, 1}, /* Subtitle of listing */
f8701a3f
SC
246/* scl */
247/* sect */
6efd877d
KR
248 {"set", s_set, 0},
249 {"short", cons, 2},
250 {"single", float_cons, 'f'},
f8701a3f 251/* size */
6efd877d 252 {"space", s_space, 0},
ba71c54d 253 {"string", stringer, 1},
f8701a3f 254/* tag */
6efd877d
KR
255 {"text", s_text, 0},
256 {"title", listing_title, 0}, /* Listing title */
f8701a3f
SC
257/* type */
258/* use */
259/* val */
6efd877d
KR
260 {"word", cons, 2},
261 {NULL} /* end sentinel */
fecd2382
RP
262};
263
6efd877d
KR
264static void
265pobegin ()
266{
267 char *errtxt; /* error text */
268 const pseudo_typeS *pop;
269
270 po_hash = hash_new ();
271
272 /* Do the target-specific pseudo ops. */
273 for (pop = md_pseudo_table; pop->poc_name; pop++)
274 {
275 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
276 if (errtxt && *errtxt)
277 {
278 as_fatal ("error constructing md pseudo-op table");
279 } /* on error */
280 } /* for each op */
281
282 /* Now object specific. Skip any that were in the target table. */
283 for (pop = obj_pseudo_table; pop->poc_name; pop++)
284 {
285 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
286 if (errtxt && *errtxt)
287 {
288 if (!strcmp (errtxt, "exists"))
289 {
fecd2382 290#ifdef DIE_ON_OVERRIDES
6efd877d 291 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
fecd2382 292#endif /* DIE_ON_OVERRIDES */
6efd877d
KR
293 continue; /* OK if target table overrides. */
294 }
295 else
296 {
297 as_fatal ("error constructing obj pseudo-op table");
298 } /* if overridden */
299 } /* on error */
300 } /* for each op */
301
302 /* Now portable ones. Skip any that we've seen already. */
303 for (pop = potable; pop->poc_name; pop++)
304 {
305 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
306 if (errtxt && *errtxt)
307 {
308 if (!strcmp (errtxt, "exists"))
309 {
fecd2382 310#ifdef DIE_ON_OVERRIDES
6efd877d 311 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
fecd2382 312#endif /* DIE_ON_OVERRIDES */
6efd877d
KR
313 continue; /* OK if target table overrides. */
314 }
315 else
316 {
317 as_fatal ("error constructing obj pseudo-op table");
318 } /* if overridden */
319 } /* on error */
320 } /* for each op */
321
322 return;
323} /* pobegin() */
fecd2382
RP
324\f
325#define HANDLE_CONDITIONAL_ASSEMBLY() \
f8701a3f
SC
326 if (ignore_input ()) \
327 { \
328 while (! is_end_of_line[*input_line_pointer++]) \
329 if (input_line_pointer == buffer_limit) \
330 break; \
331 continue; \
332 }
a39116f1 333
fecd2382
RP
334
335/* read_a_source_file()
336 *
337 * We read the file, putting things into a web that
338 * represents what we have been reading.
339 */
6efd877d
KR
340void
341read_a_source_file (name)
342 char *name;
fecd2382 343{
f8701a3f 344 register char c;
6efd877d 345 register char *s; /* string of symbol, '\0' appended */
f8701a3f 346 register int temp;
6efd877d 347 pseudo_typeS *pop;
f8701a3f 348
6efd877d 349 buffer = input_scrub_new_file (name);
f8701a3f 350
6efd877d
KR
351 listing_file (name);
352 listing_newline ("");
f8701a3f 353
6efd877d
KR
354 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
355 { /* We have another line to parse. */
356 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
9471a360
KR
357 contin: /* JF this goto is my fault I admit it.
358 Someone brave please re-write the whole
359 input section here? Pleeze??? */
6efd877d 360 while (input_line_pointer < buffer_limit)
9471a360
KR
361 {
362 /* We have more of this buffer to parse. */
f8701a3f
SC
363
364 /*
365 * We now have input_line_pointer->1st char of next line.
366 * If input_line_pointer [-1] == '\n' then we just
367 * scanned another line: so bump line counters.
368 */
6efd877d
KR
369 if (input_line_pointer[-1] == '\n')
370 {
371 bump_line_counters ();
f8701a3f
SC
372
373#ifdef MRI
374 /* Text at the start of a line must be a label, we run down and stick a colon in */
6efd877d
KR
375 if (is_name_beginner (*input_line_pointer))
376 {
377 char *line_start = input_line_pointer;
378 char c = get_symbol_end ();
379 colon (line_start);
380 *input_line_pointer = c;
381 if (c == ':')
382 input_line_pointer++;
383
384 }
f8701a3f 385#endif
9471a360 386 }
f8701a3f
SC
387
388
f8701a3f
SC
389 /*
390 * We are at the begining of a line, or similar place.
391 * We expect a well-formed assembler statement.
392 * A "symbol-name:" is a statement.
393 *
394 * Depending on what compiler is used, the order of these tests
395 * may vary to catch most common case 1st.
396 * Each test is independent of all other tests at the (top) level.
397 * PLEASE make a compiler that doesn't use this assembler.
398 * It is crufty to waste a compiler's time encoding things for this
399 * assembler, which then wastes more time decoding it.
400 * (And communicating via (linear) files is silly!
401 * If you must pass stuff, please pass a tree!)
402 */
9471a360
KR
403 if ((c = *input_line_pointer++) == '\t'
404 || c == ' '
405 || c == '\f'
406 || c == 0)
6efd877d
KR
407 {
408 c = *input_line_pointer++;
409 }
410 know (c != ' '); /* No further leading whitespace. */
411 LISTING_NEWLINE ();
f8701a3f
SC
412 /*
413 * C is the 1st significant character.
414 * Input_line_pointer points after that character.
415 */
6efd877d
KR
416 if (is_name_beginner (c))
417 { /* want user-defined label or pseudo/opcode */
418 HANDLE_CONDITIONAL_ASSEMBLY ();
419
f8701a3f 420 s = --input_line_pointer;
6efd877d 421 c = get_symbol_end (); /* name's delimiter */
f8701a3f
SC
422 /*
423 * C is character after symbol.
424 * That character's place in the input line is now '\0'.
425 * S points to the beginning of the symbol.
426 * [In case of pseudo-op, s->'.'.]
427 * Input_line_pointer->'\0' where c was.
428 */
9a7d824a 429 if (TC_START_LABEL(c, input_line_pointer))
6efd877d
KR
430 {
431 colon (s); /* user-defined label */
432 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
f8701a3f 433 /* Input_line_pointer->after ':'. */
6efd877d
KR
434 SKIP_WHITESPACE ();
435
f8701a3f 436
6efd877d
KR
437 }
438 else if (c == '=' || input_line_pointer[1] == '=')
9c6d3f66 439 {
6efd877d
KR
440 equals (s);
441 demand_empty_rest_of_line ();
442 }
443 else
444 { /* expect pseudo-op or machine instruction */
f8701a3f 445#ifdef MRI
6efd877d
KR
446 if (!done_pseudo (s))
447
f8701a3f 448#else
8ff6f40e
ILT
449
450 pop = NULL;
451
452#ifdef NO_PSEUDO_DOT
453 /* The m88k uses pseudo-ops without a period. */
454 pop = (pseudo_typeS *) hash_find (po_hash, s);
cf897ce2
ILT
455 if (pop != NULL && pop->poc_handler == NULL)
456 pop = NULL;
8ff6f40e
ILT
457#endif
458
459 if (pop != NULL || *s == '.')
6efd877d
KR
460 {
461 /*
9471a360
KR
462 * PSEUDO - OP.
463 *
464 * WARNING: c has next char, which may be end-of-line.
465 * We lookup the pseudo-op table with s+1 because we
466 * already know that the pseudo-op begins with a '.'.
467 */
6efd877d 468
8ff6f40e
ILT
469 if (pop == NULL)
470 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
6efd877d
KR
471
472 /* Print the error msg now, while we still can */
8ff6f40e 473 if (pop == NULL)
6efd877d
KR
474 {
475 as_bad ("Unknown pseudo-op: `%s'", s);
f8701a3f 476 *input_line_pointer = c;
6efd877d
KR
477 s_ignore (0);
478 break;
479 }
480
481 /* Put it back for error messages etc. */
482 *input_line_pointer = c;
9c6d3f66
KR
483 /* The following skip of whitespace is compulsory.
484 A well shaped space is sometimes all that separates
485 keyword from operands. */
6efd877d
KR
486 if (c == ' ' || c == '\t')
487 {
488 input_line_pointer++;
489 } /* Skip seperator after keyword. */
490 /*
9471a360
KR
491 * Input_line is restored.
492 * Input_line_pointer->1st non-blank char
493 * after pseudo-operation.
494 */
6efd877d
KR
495 if (!pop)
496 {
497 ignore_rest_of_line ();
498 break;
499 }
500 else
501 {
502 (*pop->poc_handler) (pop->poc_val);
503 } /* if we have one */
504 }
505 else
f8701a3f 506#endif
6efd877d
KR
507 { /* machine instruction */
508 /* WARNING: c has char, which may be end-of-line. */
509 /* Also: input_line_pointer->`\0` where c was. */
510 *input_line_pointer = c;
511 while (!is_end_of_line[*input_line_pointer])
512 {
513 input_line_pointer++;
514 }
f8701a3f 515
6efd877d
KR
516 c = *input_line_pointer;
517 *input_line_pointer = '\0';
f8701a3f 518
6efd877d 519 md_assemble (s); /* Assemble 1 instruction. */
f8701a3f 520
6efd877d 521 *input_line_pointer++ = c;
f8701a3f 522
6efd877d
KR
523 /* We resume loop AFTER the end-of-line from this instruction */
524 } /* if (*s=='.') */
525
526 } /* if c==':' */
f8701a3f 527 continue;
6efd877d 528 } /* if (is_name_beginner(c) */
f8701a3f 529
f8701a3f 530
6efd877d
KR
531 if (is_end_of_line[c])
532 {
f8701a3f 533 continue;
6efd877d
KR
534 } /* empty statement */
535
536
537#if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
538 if (isdigit (c))
539 { /* local label ("4:") */
540 char *backup = input_line_pointer;
541
542 HANDLE_CONDITIONAL_ASSEMBLY ();
543
544 temp = c - '0';
545
546 while (isdigit (*input_line_pointer))
547 {
548 temp = (temp * 10) + *input_line_pointer - '0';
549 ++input_line_pointer;
550 } /* read the whole number */
551
552#ifdef LOCAL_LABELS_DOLLAR
553 if (*input_line_pointer == '$'
554 && *(input_line_pointer + 1) == ':')
555 {
556 input_line_pointer += 2;
557
558 if (dollar_label_defined (temp))
559 {
560 as_fatal ("label \"%d$\" redefined", temp);
561 }
562
563 define_dollar_label (temp);
564 colon (dollar_label_name (temp, 0));
565 continue;
566 }
f8701a3f 567#endif /* LOCAL_LABELS_DOLLAR */
6efd877d 568
f8701a3f 569#ifdef LOCAL_LABELS_FB
6efd877d
KR
570 if (*input_line_pointer++ == ':')
571 {
572 fb_label_instance_inc (temp);
573 colon (fb_label_name (temp, 0));
574 continue;
575 }
f8701a3f 576#endif /* LOCAL_LABELS_FB */
6efd877d
KR
577
578 input_line_pointer = backup;
579 } /* local label ("4:") */
f8701a3f
SC
580#endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
581
6efd877d
KR
582 if (c && strchr (line_comment_chars, c))
583 { /* Its a comment. Better say APP or NO_APP */
f8701a3f
SC
584 char *ends;
585 char *new_buf;
586 char *new_tmp;
587 int new_length;
588 char *tmp_buf = 0;
6efd877d
KR
589 extern char *scrub_string, *scrub_last_string;
590
591 bump_line_counters ();
592 s = input_line_pointer;
593 if (strncmp (s, "APP\n", 4))
594 continue; /* We ignore it */
595 s += 4;
596
597 ends = strstr (s, "#NO_APP\n");
598
599 if (!ends)
600 {
f8701a3f
SC
601 int tmp_len;
602 int num;
6efd877d 603
f8701a3f
SC
604 /* The end of the #APP wasn't in this buffer. We
605 keep reading in buffers until we find the #NO_APP
606 that goes with this #APP There is one. The specs
607 guarentee it. . . */
6efd877d 608 tmp_len = buffer_limit - s;
85825401 609 tmp_buf = xmalloc (tmp_len + 1);
4380166d 610 memcpy (tmp_buf, s, tmp_len);
6efd877d
KR
611 do
612 {
613 new_tmp = input_scrub_next_buffer (&buffer);
f8701a3f 614 if (!new_tmp)
6efd877d 615 break;
f8701a3f 616 else
6efd877d 617 buffer_limit = new_tmp;
f8701a3f 618 input_line_pointer = buffer;
6efd877d 619 ends = strstr (buffer, "#NO_APP\n");
f8701a3f 620 if (ends)
6efd877d 621 num = ends - buffer;
f8701a3f 622 else
6efd877d
KR
623 num = buffer_limit - buffer;
624
625 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
4380166d 626 memcpy (tmp_buf, buffer + tmp_len, num);
6efd877d
KR
627 tmp_len += num;
628 }
629 while (!ends);
630
631 input_line_pointer = ends ? ends + 8 : NULL;
632
633 s = tmp_buf;
634 ends = s + tmp_len;
635
636 }
637 else
638 {
639 input_line_pointer = ends + 8;
640 }
641 new_buf = xmalloc (100);
642 new_length = 100;
643 new_tmp = new_buf;
644
645 scrub_string = s;
f8701a3f 646 scrub_last_string = ends;
6efd877d
KR
647 for (;;)
648 {
f8701a3f
SC
649 int ch;
650
6efd877d
KR
651 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
652 if (ch == EOF)
653 break;
654 *new_tmp++ = ch;
655 if (new_tmp == new_buf + new_length)
656 {
657 new_buf = xrealloc (new_buf, new_length + 100);
658 new_tmp = new_buf + new_length;
659 new_length += 100;
f8701a3f 660 }
fecd2382 661 }
f8701a3f
SC
662
663 if (tmp_buf)
6efd877d
KR
664 free (tmp_buf);
665 old_buffer = buffer;
666 old_input = input_line_pointer;
667 old_limit = buffer_limit;
668 buffer = new_buf;
669 input_line_pointer = new_buf;
670 buffer_limit = new_tmp;
f8701a3f
SC
671 continue;
672 }
673
6efd877d 674 HANDLE_CONDITIONAL_ASSEMBLY ();
f8701a3f
SC
675
676 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
677 input_line_pointer--; /* Report unknown char as ignored. */
6efd877d
KR
678 ignore_rest_of_line ();
679 } /* while (input_line_pointer<buffer_limit) */
680 if (old_buffer)
681 {
682 bump_line_counters ();
683 if (old_input != 0)
684 {
685 buffer = old_buffer;
686 input_line_pointer = old_input;
687 buffer_limit = old_limit;
f8701a3f
SC
688 old_buffer = 0;
689 goto contin;
690 }
691 }
6efd877d
KR
692 } /* while (more buffers to scan) */
693 input_scrub_close (); /* Close the input file */
f8701a3f 694
6efd877d 695} /* read_a_source_file() */
fecd2382 696
6efd877d
KR
697void
698s_abort ()
699{
700 as_fatal (".abort detected. Abandoning ship.");
701} /* s_abort() */
fecd2382
RP
702
703/* For machines where ".align 4" means align to a 4 byte boundary. */
6efd877d
KR
704void
705s_align_bytes (arg)
706 int arg;
fecd2382 707{
6efd877d
KR
708 register unsigned int temp;
709 register long temp_fill;
710 unsigned int i = 0;
711 unsigned long max_alignment = 1 << 15;
f8701a3f 712
6efd877d
KR
713 if (is_end_of_line[*input_line_pointer])
714 temp = arg; /* Default value from pseudo-op table */
715 else
716 temp = get_absolute_expression ();
f8701a3f 717
6efd877d
KR
718 if (temp > max_alignment)
719 {
720 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
f8701a3f
SC
721 }
722
6efd877d 723 /*
f8701a3f
SC
724 * For the sparc, `.align (1<<n)' actually means `.align n'
725 * so we have to convert it.
726 */
6efd877d
KR
727 if (temp != 0)
728 {
729 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
730 ;
f8701a3f 731 }
6efd877d
KR
732 if (temp != 1)
733 as_bad ("Alignment not a power of 2");
f8701a3f 734
6efd877d
KR
735 temp = i;
736 if (*input_line_pointer == ',')
737 {
738 input_line_pointer++;
739 temp_fill = get_absolute_expression ();
f8701a3f 740 }
9471a360 741 else if (now_seg != data_section && now_seg != bss_section)
016e0d42 742 temp_fill = NOP_OPCODE;
6efd877d 743 else
016e0d42 744 temp_fill = 0;
6efd877d
KR
745 /* Only make a frag if we HAVE to. . . */
746 if (temp && !need_pass_2)
747 frag_align (temp, (int) temp_fill);
f8701a3f 748
49864cfa
KR
749 record_alignment (now_seg, temp);
750
6efd877d
KR
751 demand_empty_rest_of_line ();
752} /* s_align_bytes() */
fecd2382
RP
753
754/* For machines where ".align 4" means align to 2**4 boundary. */
6efd877d
KR
755void
756s_align_ptwo ()
757{
758 register int temp;
759 register long temp_fill;
760 long max_alignment = 15;
761
762 temp = get_absolute_expression ();
763 if (temp > max_alignment)
764 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
765 else if (temp < 0)
766 {
767 as_bad ("Alignment negative. 0 assumed.");
768 temp = 0;
769 }
770 if (*input_line_pointer == ',')
771 {
772 input_line_pointer++;
773 temp_fill = get_absolute_expression ();
774 }
9471a360
KR
775 /* @@ Fix this right for BFD! */
776 else if (now_seg != data_section && now_seg != bss_section)
016e0d42 777 temp_fill = NOP_OPCODE;
6efd877d
KR
778 else
779 temp_fill = 0;
780 /* Only make a frag if we HAVE to. . . */
781 if (temp && !need_pass_2)
782 frag_align (temp, (int) temp_fill);
783
784 record_alignment (now_seg, temp);
785
786 demand_empty_rest_of_line ();
787} /* s_align_ptwo() */
788
789void
790s_comm ()
791{
792 register char *name;
793 register char c;
794 register char *p;
40324362 795 valueT temp;
6efd877d
KR
796 register symbolS *symbolP;
797
798 name = input_line_pointer;
799 c = get_symbol_end ();
800 /* just after name is now '\0' */
801 p = input_line_pointer;
802 *p = c;
803 SKIP_WHITESPACE ();
804 if (*input_line_pointer != ',')
805 {
806 as_bad ("Expected comma after symbol-name: rest of line ignored.");
807 ignore_rest_of_line ();
808 return;
809 }
810 input_line_pointer++; /* skip ',' */
811 if ((temp = get_absolute_expression ()) < 0)
812 {
813 as_warn (".COMMon length (%d.) <0! Ignored.", temp);
814 ignore_rest_of_line ();
815 return;
816 }
817 *p = 0;
818 symbolP = symbol_find_or_make (name);
819 *p = c;
820 if (S_IS_DEFINED (symbolP))
821 {
822 as_bad ("Ignoring attempt to re-define symbol");
823 ignore_rest_of_line ();
824 return;
825 }
826 if (S_GET_VALUE (symbolP))
827 {
828 if (S_GET_VALUE (symbolP) != temp)
829 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
830 S_GET_NAME (symbolP),
831 S_GET_VALUE (symbolP),
832 temp);
833 }
834 else
835 {
836 S_SET_VALUE (symbolP, temp);
837 S_SET_EXTERNAL (symbolP);
838 }
9471a360
KR
839#ifdef OBJ_VMS
840 if ( (!temp) || !flagseen['1'])
841 S_GET_OTHER(symbolP) = const_flag;
842#endif /* not OBJ_VMS */
6efd877d
KR
843 know (symbolP->sy_frag == &zero_address_frag);
844 demand_empty_rest_of_line ();
845} /* s_comm() */
fecd2382
RP
846
847void
6efd877d 848s_data ()
fecd2382 849{
ffffc8fb 850 segT section;
6efd877d 851 register int temp;
f8701a3f 852
6efd877d 853 temp = get_absolute_expression ();
ffffc8fb
ILT
854 if (flagseen['R'])
855 {
856 section = text_section;
857 temp += 1000;
858 }
859 else
860 section = data_section;
861
db81c5e7 862#ifdef BFD_ASSEMBLER
ffffc8fb 863 subseg_set (section, (subsegT) temp);
db81c5e7 864#else
ffffc8fb 865 subseg_new (section, (subsegT) temp);
db81c5e7 866#endif
f8701a3f 867
9471a360 868#ifdef OBJ_VMS
6efd877d 869 const_flag = 0;
fecd2382 870#endif
6efd877d 871 demand_empty_rest_of_line ();
fecd2382
RP
872}
873
9a7d824a
ILT
874/* Handle the .appfile pseudo-op. This is automatically generated by
875 do_scrub_next_char when a preprocessor # line comment is seen with
876 a file name. This default definition may be overridden by the
877 object or CPU specific pseudo-ops. This function is also the
878 default definition for .file; the APPFILE argument is 1 for
879 .appfile, 0 for .file. */
880
6efd877d 881void
9a7d824a
ILT
882s_app_file (appfile)
883 int appfile;
6efd877d
KR
884{
885 register char *s;
886 int length;
f8701a3f 887
6efd877d
KR
888 /* Some assemblers tolerate immediately following '"' */
889 if ((s = demand_copy_string (&length)) != 0)
890 {
9a7d824a
ILT
891 /* If this is a fake .appfile, a fake newline was inserted into
892 the buffer. Passing -2 to new_logical_line tells it to
893 account for it. */
894 new_logical_line (s, appfile ? -2 : -1);
6efd877d 895 demand_empty_rest_of_line ();
9a7d824a
ILT
896#ifdef LISTING
897 if (listing)
898 listing_source_file (s);
899#endif
6efd877d 900 }
fecd2382 901#ifdef OBJ_COFF
6efd877d 902 c_dot_file_symbol (s);
fecd2382 903#endif /* OBJ_COFF */
40324362
KR
904#ifdef OBJ_ELF
905 elf_file_symbol (s);
906#endif
907}
fecd2382 908
9a7d824a
ILT
909/* Handle the .appline pseudo-op. This is automatically generated by
910 do_scrub_next_char when a preprocessor # line comment is seen.
911 This default definition may be overridden by the object or CPU
912 specific pseudo-ops. */
913
914void
915s_app_line ()
916{
917 int l;
918
919 /* The given number is that of the next line. */
920 l = get_absolute_expression () - 1;
921 new_logical_line ((char *) NULL, l);
922#ifdef LISTING
923 if (listing)
924 listing_source_line (l);
925#endif
926 demand_empty_rest_of_line ();
927}
928
6efd877d
KR
929void
930s_fill ()
931{
932 long temp_repeat = 0;
933 long temp_size = 1;
934 register long temp_fill = 0;
935 char *p;
f8701a3f 936
7c2d4011 937
6efd877d
KR
938 temp_repeat = get_absolute_expression ();
939 if (*input_line_pointer == ',')
940 {
941 input_line_pointer++;
942 temp_size = get_absolute_expression ();
943 if (*input_line_pointer == ',')
7c2d4011
SC
944 {
945 input_line_pointer++;
6efd877d 946 temp_fill = get_absolute_expression ();
fecd2382 947 }
6efd877d 948 }
c8863a58 949 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
fecd2382 950#define BSD_FILL_SIZE_CROCK_8 (8)
6efd877d
KR
951 if (temp_size > BSD_FILL_SIZE_CROCK_8)
952 {
953 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
954 temp_size = BSD_FILL_SIZE_CROCK_8;
955 }
956 if (temp_size < 0)
957 {
958 as_warn ("Size negative: .fill ignored.");
959 temp_size = 0;
960 }
961 else if (temp_repeat <= 0)
962 {
963 as_warn ("Repeat < 0, .fill ignored");
964 temp_size = 0;
965 }
7fd3560a 966
6efd877d
KR
967 if (temp_size && !need_pass_2)
968 {
969 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
c8863a58
KR
970 memset (p, 0, (int) temp_size);
971 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
972 * flavoured AS. The following bizzare behaviour is to be
973 * compatible with above. I guess they tried to take up to 8
974 * bytes from a 4-byte expression and they forgot to sign
975 * extend. Un*x Sux. */
fecd2382 976#define BSD_FILL_SIZE_CROCK_4 (4)
c8863a58
KR
977 md_number_to_chars (p, temp_fill,
978 (temp_size > BSD_FILL_SIZE_CROCK_4
979 ? BSD_FILL_SIZE_CROCK_4
980 : (int) temp_size));
981 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
982 * but emits no error message because it seems a legal thing to do.
983 * It is a degenerate case of .fill but could be emitted by a compiler.
984 */
6efd877d 985 }
6efd877d 986 demand_empty_rest_of_line ();
f8701a3f
SC
987}
988
6efd877d
KR
989void
990s_globl ()
991{
40324362
KR
992 char *name;
993 int c;
994 symbolS *symbolP;
fecd2382 995
6efd877d
KR
996 do
997 {
998 name = input_line_pointer;
999 c = get_symbol_end ();
1000 symbolP = symbol_find_or_make (name);
1001 *input_line_pointer = c;
1002 SKIP_WHITESPACE ();
1003 S_SET_EXTERNAL (symbolP);
1004 if (c == ',')
1005 {
1006 input_line_pointer++;
1007 SKIP_WHITESPACE ();
1008 if (*input_line_pointer == '\n')
1009 c = '\n';
1010 }
1011 }
1012 while (c == ',');
1013 demand_empty_rest_of_line ();
40324362 1014}
6efd877d
KR
1015
1016void
1017s_lcomm (needs_align)
c8863a58
KR
1018 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1019 (alignment); 0 if it was an ".lcomm" (2 args only) */
1020 int needs_align;
fecd2382 1021{
6efd877d
KR
1022 register char *name;
1023 register char c;
1024 register char *p;
1025 register int temp;
1026 register symbolS *symbolP;
9a7d824a
ILT
1027 segT current_seg = now_seg;
1028 subsegT current_subseg = now_subseg;
6efd877d
KR
1029 const int max_alignment = 15;
1030 int align = 0;
9a7d824a 1031 segT bss_seg = bss_section;
6efd877d
KR
1032
1033 name = input_line_pointer;
1034 c = get_symbol_end ();
1035 p = input_line_pointer;
1036 *p = c;
1037 SKIP_WHITESPACE ();
1038 if (*input_line_pointer != ',')
1039 {
1040 as_bad ("Expected comma after name");
1041 ignore_rest_of_line ();
1042 return;
1043 }
f8701a3f 1044
6efd877d 1045 ++input_line_pointer;
f8701a3f 1046
6efd877d
KR
1047 if (*input_line_pointer == '\n')
1048 {
1049 as_bad ("Missing size expression");
1050 return;
1051 }
f8701a3f 1052
6efd877d
KR
1053 if ((temp = get_absolute_expression ()) < 0)
1054 {
1055 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1056 ignore_rest_of_line ();
1057 return;
1058 }
f8701a3f 1059
9a7d824a
ILT
1060#ifdef TC_MIPS
1061#ifdef OBJ_ECOFF
1062 /* For MIPS ECOFF, small objects are put in .sbss. */
1063 if (temp <= bfd_get_gp_size (stdoutput))
1064 bss_seg = subseg_new (".sbss", 1);
1065#endif
1066#endif
1067
6efd877d
KR
1068 if (needs_align)
1069 {
1070 align = 0;
1071 SKIP_WHITESPACE ();
1072 if (*input_line_pointer != ',')
1073 {
1074 as_bad ("Expected comma after size");
1075 ignore_rest_of_line ();
1076 return;
1077 }
1078 input_line_pointer++;
1079 SKIP_WHITESPACE ();
1080 if (*input_line_pointer == '\n')
1081 {
1082 as_bad ("Missing alignment");
1083 return;
1084 }
1085 align = get_absolute_expression ();
1086 if (align > max_alignment)
1087 {
1088 align = max_alignment;
1089 as_warn ("Alignment too large: %d. assumed.", align);
1090 }
1091 else if (align < 0)
1092 {
1093 align = 0;
1094 as_warn ("Alignment negative. 0 assumed.");
1095 }
9a7d824a 1096 record_alignment (bss_seg, align);
6efd877d 1097 } /* if needs align */
f8701a3f 1098
6efd877d
KR
1099 *p = 0;
1100 symbolP = symbol_find_or_make (name);
1101 *p = c;
f8701a3f 1102
6efd877d 1103 if (
fecd2382 1104#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6efd877d
KR
1105 S_GET_OTHER (symbolP) == 0 &&
1106 S_GET_DESC (symbolP) == 0 &&
fecd2382 1107#endif /* OBJ_AOUT or OBJ_BOUT */
9a7d824a 1108 (S_GET_SEGMENT (symbolP) == bss_seg
6efd877d
KR
1109 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1110 {
85825401 1111 char *p;
85825401 1112
9471a360 1113#ifdef BFD_ASSEMBLER
9a7d824a 1114 subseg_set (bss_seg, 1);
9471a360 1115#else
9a7d824a 1116 subseg_new (bss_seg, 1);
9471a360 1117#endif
85825401
ILT
1118
1119 if (align)
1120 frag_align (align, 0);
1121 /* detach from old frag */
9a7d824a 1122 if (S_GET_SEGMENT (symbolP) == bss_seg)
85825401
ILT
1123 symbolP->sy_frag->fr_symbol = NULL;
1124
1125 symbolP->sy_frag = frag_now;
1126 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1127 temp, (char *)0);
1128 *p = 0;
f8701a3f 1129
9a7d824a 1130 S_SET_SEGMENT (symbolP, bss_seg);
85825401 1131
fecd2382 1132#ifdef OBJ_COFF
6efd877d 1133 /* The symbol may already have been created with a preceding
c8863a58
KR
1134 ".globl" directive -- be careful not to step on storage class
1135 in that case. Otherwise, set it to static. */
6efd877d
KR
1136 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1137 {
1138 S_SET_STORAGE_CLASS (symbolP, C_STAT);
fecd2382 1139 }
6efd877d 1140#endif /* OBJ_COFF */
6efd877d
KR
1141 }
1142 else
1143 {
85825401 1144 as_bad ("Ignoring attempt to re-define symbol %s.", name);
6efd877d 1145 }
f8701a3f 1146
9a7d824a
ILT
1147#ifdef BFD_ASSEMBLER
1148 subseg_set (current_seg, current_subseg);
1149#else
1150 subseg_new (current_seg, current_subseg);
1151#endif
1152
1153 demand_empty_rest_of_line ();
6efd877d 1154} /* s_lcomm() */
fecd2382
RP
1155
1156void
6efd877d 1157s_long ()
fecd2382 1158{
6efd877d 1159 cons (4);
fecd2382
RP
1160}
1161
1162void
6efd877d 1163s_int ()
fecd2382 1164{
6efd877d 1165 cons (4);
fecd2382
RP
1166}
1167
6efd877d
KR
1168void
1169s_lsym ()
1170{
1171 register char *name;
1172 register char c;
1173 register char *p;
6efd877d
KR
1174 expressionS exp;
1175 register symbolS *symbolP;
1176
1177 /* we permit ANY defined expression: BSD4.2 demands constants */
1178 name = input_line_pointer;
1179 c = get_symbol_end ();
1180 p = input_line_pointer;
1181 *p = c;
1182 SKIP_WHITESPACE ();
1183 if (*input_line_pointer != ',')
1184 {
1185 *p = 0;
1186 as_bad ("Expected comma after name \"%s\"", name);
1187 *p = c;
1188 ignore_rest_of_line ();
1189 return;
1190 }
1191 input_line_pointer++;
b31f2abb
KR
1192 expression (&exp);
1193 if (exp.X_op != O_constant
1194 && exp.X_op != O_register)
1195 {
1196 as_bad ("bad expression");
1197 ignore_rest_of_line ();
1198 return;
1199 }
6efd877d
KR
1200 *p = 0;
1201 symbolP = symbol_find_or_make (name);
f8701a3f 1202
c8863a58
KR
1203 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1204 symbolP->sy_desc == 0) out of this test because coff doesn't have
1205 those fields, and I can't see when they'd ever be tripped. I
1206 don't think I understand why they were here so I may have
1207 introduced a bug. As recently as 1.37 didn't have this test
1208 anyway. xoxorich. */
f8701a3f 1209
9471a360 1210 if (S_GET_SEGMENT (symbolP) == undefined_section
6efd877d
KR
1211 && S_GET_VALUE (symbolP) == 0)
1212 {
c8863a58
KR
1213 /* The name might be an undefined .global symbol; be sure to
1214 keep the "external" bit. */
b31f2abb
KR
1215 S_SET_SEGMENT (symbolP,
1216 (exp.X_op == O_constant
1217 ? absolute_section
1218 : reg_section));
1219 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d
KR
1220 }
1221 else
1222 {
1223 as_bad ("Symbol %s already defined", name);
1224 }
1225 *p = c;
1226 demand_empty_rest_of_line ();
1227} /* s_lsym() */
1228
1229void
1230s_org ()
1231{
1232 register segT segment;
1233 expressionS exp;
1234 register long temp_fill;
1235 register char *p;
9471a360
KR
1236 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1237 thing as a sub-segment-relative origin. Any absolute origin is
1238 given a warning, then assumed to be segment-relative. Any
1239 segmented origin expression ("foo+42") had better be in the right
1240 segment or the .org is ignored.
1241
1242 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1243 we never know sub-segment sizes when we are reading code. BSD
1244 will crash trying to emit negative numbers of filler bytes in
1245 certain .orgs. We don't crash, but see as-write for that code.
1246
1247 Don't make frag if need_pass_2==1. */
6efd877d
KR
1248 segment = get_known_segmented_expression (&exp);
1249 if (*input_line_pointer == ',')
1250 {
1251 input_line_pointer++;
1252 temp_fill = get_absolute_expression ();
1253 }
1254 else
1255 temp_fill = 0;
1256 if (!need_pass_2)
1257 {
9471a360 1258 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
1259 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1260 segment_name (segment), segment_name (now_seg));
1261 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1262 exp.X_add_number, (char *) 0);
1263 *p = temp_fill;
1264 } /* if (ok to make frag) */
1265 demand_empty_rest_of_line ();
1266} /* s_org() */
1267
1268void
1269s_set ()
1270{
1271 register char *name;
1272 register char delim;
1273 register char *end_name;
1274 register symbolS *symbolP;
1275
1276 /*
c8863a58
KR
1277 * Especial apologies for the random logic:
1278 * this just grew, and could be parsed much more simply!
1279 * Dean in haste.
1280 */
6efd877d
KR
1281 name = input_line_pointer;
1282 delim = get_symbol_end ();
1283 end_name = input_line_pointer;
1284 *end_name = delim;
1285 SKIP_WHITESPACE ();
f8701a3f 1286
6efd877d
KR
1287 if (*input_line_pointer != ',')
1288 {
1289 *end_name = 0;
1290 as_bad ("Expected comma after name \"%s\"", name);
1291 *end_name = delim;
1292 ignore_rest_of_line ();
1293 return;
1294 }
1295
1296 input_line_pointer++;
1297 *end_name = 0;
1298
1299 if (name[0] == '.' && name[1] == '\0')
1300 {
1301 /* Turn '. = mumble' into a .org mumble */
1302 register segT segment;
1303 expressionS exp;
1304 register char *ptr;
1305
1306 segment = get_known_segmented_expression (&exp);
f8701a3f 1307
6efd877d
KR
1308 if (!need_pass_2)
1309 {
9471a360 1310 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
1311 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1312 segment_name (segment),
1313 segment_name (now_seg));
1314 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1315 exp.X_add_number, (char *) 0);
1316 *ptr = 0;
1317 } /* if (ok to make frag) */
1318
1319 *end_name = delim;
1320 return;
1321 }
1322
1323 if ((symbolP = symbol_find (name)) == NULL
1324 && (symbolP = md_undefined_symbol (name)) == NULL)
1325 {
9471a360 1326 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
fecd2382 1327#ifdef OBJ_COFF
6efd877d
KR
1328 /* "set" symbols are local unless otherwise specified. */
1329 SF_SET_LOCAL (symbolP);
fecd2382 1330#endif /* OBJ_COFF */
f8701a3f 1331
6efd877d 1332 } /* make a new symbol */
f8701a3f 1333
6efd877d 1334 symbol_table_insert (symbolP);
f8701a3f 1335
6efd877d
KR
1336 *end_name = delim;
1337 pseudo_set (symbolP);
1338 demand_empty_rest_of_line ();
1339} /* s_set() */
fecd2382 1340
6efd877d
KR
1341void
1342s_space (mult)
1343 int mult;
b53ccaac 1344{
6efd877d
KR
1345 long temp_repeat;
1346 register long temp_fill;
1347 register char *p;
1348
1349 /* Just like .fill, but temp_size = 1 */
1350 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1351 {
1352 temp_fill = get_absolute_expression ();
1353 }
1354 else
1355 {
1356 input_line_pointer--; /* Backup over what was not a ','. */
1357 temp_fill = 0;
1358 }
1359 if (mult)
1360 {
bf449293 1361 temp_repeat *= mult;
6efd877d
KR
1362 }
1363 if (temp_repeat <= 0)
1364 {
1365 as_warn ("Repeat < 0, .space ignored");
1366 ignore_rest_of_line ();
1367 return;
1368 }
1369 if (!need_pass_2)
1370 {
1371 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1372 temp_repeat, (char *) 0);
1373 *p = temp_fill;
1374 }
1375 demand_empty_rest_of_line ();
1376} /* s_space() */
fecd2382
RP
1377
1378void
6efd877d 1379s_text ()
fecd2382 1380{
6efd877d 1381 register int temp;
f8701a3f 1382
6efd877d 1383 temp = get_absolute_expression ();
9471a360
KR
1384#ifdef BFD_ASSEMBLER
1385 subseg_set (text_section, (subsegT) temp);
a39116f1 1386#else
9471a360 1387 subseg_new (text_section, (subsegT) temp);
a39116f1 1388#endif
6efd877d
KR
1389 demand_empty_rest_of_line ();
1390} /* s_text() */
fecd2382 1391\f
6efd877d 1392
6efd877d
KR
1393void
1394demand_empty_rest_of_line ()
1395{
1396 SKIP_WHITESPACE ();
1397 if (is_end_of_line[*input_line_pointer])
1398 {
1399 input_line_pointer++;
1400 }
1401 else
1402 {
1403 ignore_rest_of_line ();
1404 }
1405 /* Return having already swallowed end-of-line. */
1406} /* Return pointing just after end-of-line. */
fecd2382
RP
1407
1408void
6efd877d 1409ignore_rest_of_line () /* For suspect lines: gives warning. */
fecd2382 1410{
6efd877d 1411 if (!is_end_of_line[*input_line_pointer])
f8701a3f 1412 {
6efd877d
KR
1413 if (isprint (*input_line_pointer))
1414 as_bad ("Rest of line ignored. First ignored character is `%c'.",
f8701a3f
SC
1415 *input_line_pointer);
1416 else
6efd877d 1417 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
f8701a3f
SC
1418 *input_line_pointer);
1419 while (input_line_pointer < buffer_limit
6efd877d 1420 && !is_end_of_line[*input_line_pointer])
f8701a3f 1421 {
6efd877d 1422 input_line_pointer++;
f8701a3f
SC
1423 }
1424 }
6efd877d
KR
1425 input_line_pointer++; /* Return pointing just after end-of-line. */
1426 know (is_end_of_line[input_line_pointer[-1]]);
fecd2382
RP
1427}
1428
1429/*
1430 * pseudo_set()
1431 *
1432 * In: Pointer to a symbol.
1433 * Input_line_pointer->expression.
1434 *
1435 * Out: Input_line_pointer->just after any whitespace after expression.
1436 * Tried to set symbol to value of expression.
1437 * Will change symbols type, value, and frag;
fecd2382
RP
1438 */
1439void
f8701a3f 1440pseudo_set (symbolP)
6efd877d 1441 symbolS *symbolP;
fecd2382 1442{
6efd877d 1443 expressionS exp;
fecd2382 1444#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
f8701a3f 1445 int ext;
fecd2382 1446#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 1447
6efd877d 1448 know (symbolP); /* NULL pointer is logic error. */
fecd2382 1449#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
9471a360 1450 /* @@ Fix this right for BFD. */
6efd877d 1451 ext = S_IS_EXTERNAL (symbolP);
fecd2382 1452#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 1453
5ac34ac3 1454 (void) expression (&exp);
f8701a3f 1455
5ac34ac3
ILT
1456 if (exp.X_op == O_illegal)
1457 as_bad ("illegal expression; zero assumed");
1458 else if (exp.X_op == O_absent)
1459 as_bad ("missing expression; zero assumed");
1460 else if (exp.X_op == O_big)
1461 as_bad ("%s number invalid; zero assumed",
1462 exp.X_add_number > 0 ? "bignum" : "floating point");
1463 else if (exp.X_op == O_subtract
1464 && (S_GET_SEGMENT (exp.X_add_symbol)
1465 == S_GET_SEGMENT (exp.X_op_symbol))
1466 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1467 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
9471a360 1468 {
5ac34ac3
ILT
1469 exp.X_op = O_constant;
1470 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1471 - S_GET_VALUE (exp.X_op_symbol));
9471a360 1472 }
5ac34ac3
ILT
1473
1474 switch (exp.X_op)
9471a360 1475 {
5ac34ac3
ILT
1476 case O_illegal:
1477 case O_absent:
1478 case O_big:
1479 exp.X_add_number = 0;
1480 /* Fall through. */
1481 case O_constant:
9471a360 1482 S_SET_SEGMENT (symbolP, absolute_section);
fecd2382 1483#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
9471a360 1484 /* @@ Fix this right for BFD. */
5ac34ac3
ILT
1485 if (ext)
1486 S_SET_EXTERNAL (symbolP);
6efd877d 1487 else
6efd877d 1488 S_CLEAR_EXTERNAL (symbolP);
fecd2382 1489#endif /* OBJ_AOUT or OBJ_BOUT */
6efd877d
KR
1490 S_SET_VALUE (symbolP, exp.X_add_number);
1491 symbolP->sy_frag = &zero_address_frag;
5ac34ac3 1492 break;
f8701a3f 1493
5ac34ac3
ILT
1494 case O_register:
1495 S_SET_SEGMENT (symbolP, reg_section);
1496 S_SET_VALUE (symbolP, exp.X_add_number);
1497 symbolP->sy_frag = &zero_address_frag;
1498 break;
1499
1500 case O_symbol:
1501 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1502 symbolP->sy_value = exp;
6efd877d
KR
1503 else
1504 {
5ac34ac3
ILT
1505 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1506#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1507 /* @@ Fix this right for BFD! */
1508 if (ext)
1509 S_SET_EXTERNAL (symbolP);
1510 else
1511 S_CLEAR_EXTERNAL (symbolP);
fecd2382 1512#endif /* OBJ_AOUT or OBJ_BOUT */
5ac34ac3
ILT
1513 S_SET_VALUE (symbolP,
1514 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1515 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1516 }
1517 break;
f8701a3f 1518
5ac34ac3
ILT
1519 default:
1520 /* The value is some complex expression.
1521 FIXME: Should we set the segment to anything? */
1522 symbolP->sy_value = exp;
1523 break;
f8701a3f 1524 }
fecd2382
RP
1525}
1526\f
1527/*
1528 * cons()
1529 *
1530 * CONStruct more frag of .bytes, or .words etc.
1531 * Should need_pass_2 be 1 then emit no frag(s).
1532 * This understands EXPRESSIONS, as opposed to big_cons().
1533 *
1534 * Bug (?)
1535 *
1536 * This has a split personality. We use expression() to read the
1537 * value. We can detect if the value won't fit in a byte or word.
1538 * But we can't detect if expression() discarded significant digits
1539 * in the case of a long. Not worth the crocks required to fix it.
1540 */
1541
40324362
KR
1542/* Select a parser for cons expressions. */
1543
1544/* Some targets need to parse the expression in various fancy ways.
1545 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1546 (for example, the HPPA does this). Otherwise, you can define
1547 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1548 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1549 are defined, which is the normal case, then only simple expressions
1550 are permitted. */
1551
1552#ifndef TC_PARSE_CONS_EXPRESSION
1553#ifdef BITFIELD_CONS_EXPRESSIONS
1554#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1555static void
1556parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1557#endif
1558#ifdef MRI
1559#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1560static void
1561parse_mri_cons PARAMS ((expressionS *exp));
1562#endif
1563#ifdef REPEAT_CONS_EXPRESSIONS
1564#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1565static void
1566parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1567#endif
1568
1569/* If we haven't gotten one yet, just call expression. */
1570#ifndef TC_PARSE_CONS_EXPRESSION
1571#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1572#endif
1573#endif
1574
6efd877d
KR
1575/* worker to do .byte etc statements */
1576/* clobbers input_line_pointer, checks */
1577/* end-of-line. */
1578void
1579cons (nbytes)
1580 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
fecd2382 1581{
6efd877d 1582 expressionS exp;
f8701a3f 1583
40324362 1584 if (is_it_end_of_statement ())
6efd877d 1585 {
40324362
KR
1586 demand_empty_rest_of_line ();
1587 return;
6efd877d 1588 }
40324362
KR
1589
1590 do
6efd877d 1591 {
40324362
KR
1592 TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
1593 emit_expr (&exp, nbytes);
1594 }
1595 while (*input_line_pointer++ == ',');
1596
1597 input_line_pointer--; /* Put terminator back into stream. */
1598 demand_empty_rest_of_line ();
1599} /* cons() */
f8701a3f 1600
40324362
KR
1601/* Put the contents of expression EXP into the object file using
1602 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
f8701a3f 1603
40324362
KR
1604void
1605emit_expr (exp, nbytes)
1606 expressionS *exp;
1607 unsigned int nbytes;
1608{
5ac34ac3 1609 operatorT op;
40324362 1610 register char *p;
f8701a3f 1611
40324362
KR
1612 /* Don't do anything if we are going to make another pass. */
1613 if (need_pass_2)
1614 return;
1615
5ac34ac3 1616 op = exp->X_op;
40324362 1617
5ac34ac3 1618 if (op == O_absent || op == O_illegal)
6efd877d 1619 {
5ac34ac3
ILT
1620 as_warn ("zero assumed for missing expression");
1621 exp->X_add_number = 0;
1622 op = O_constant;
6efd877d 1623 }
5ac34ac3 1624 else if (op == O_big)
6efd877d 1625 {
5ac34ac3
ILT
1626 as_bad ("%s number invalid; zero assumed",
1627 exp->X_add_number > 0 ? "bignum" : "floating point");
40324362 1628 exp->X_add_number = 0;
5ac34ac3 1629 op = O_constant;
40324362 1630 }
5ac34ac3 1631 else if (op == O_register)
6efd877d 1632 {
5ac34ac3
ILT
1633 as_warn ("register value used as expression");
1634 op = O_constant;
40324362 1635 }
6efd877d 1636
40324362 1637 p = frag_more (nbytes);
6efd877d 1638
40324362
KR
1639#ifndef WORKING_DOT_WORD
1640 /* If we have the difference of two symbols in a word, save it on
1641 the broken_words list. See the code in write.c. */
5ac34ac3 1642 if (op == O_subtract && nbytes == 2)
40324362
KR
1643 {
1644 struct broken_word *x;
1645
1646 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1647 x->next_broken_word = broken_words;
1648 broken_words = x;
1649 x->frag = frag_now;
1650 x->word_goes_here = p;
1651 x->dispfrag = 0;
1652 x->add = exp->X_add_symbol;
5ac34ac3 1653 x->sub = exp->X_op_symbol;
40324362
KR
1654 x->addnum = exp->X_add_number;
1655 x->added = 0;
1656 new_broken_words++;
1657 return;
1658 }
f8701a3f 1659#endif
6efd877d 1660
5ac34ac3 1661 if (op == O_constant)
40324362
KR
1662 {
1663 register long get;
1664 register long use;
1665 register long mask;
1666 register long unmask;
1667
1668 /* JF << of >= number of bits in the object is undefined. In
1669 particular SPARC (Sun 4) has problems */
1670 if (nbytes >= sizeof (long))
1671 mask = 0;
1672 else
1673 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
6efd877d 1674
40324362 1675 unmask = ~mask; /* Do store these bits. */
6efd877d 1676
40324362
KR
1677#ifdef NEVER
1678 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1679 mask = ~(unmask >> 1); /* Includes sign bit now. */
1680#endif
6efd877d 1681
40324362
KR
1682 get = exp->X_add_number;
1683 use = get & unmask;
1684 if ((get & mask) != 0 && (get & mask) != mask)
1685 { /* Leading bits contain both 0s & 1s. */
1686 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
1687 }
1688 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1689 }
1690 else
1691 {
1692 md_number_to_chars (p, (long) 0, nbytes);
6efd877d 1693
40324362
KR
1694 /* Now we need to generate a fixS to record the symbol value.
1695 This is easy for BFD. For other targets it can be more
1696 complex. For very complex cases (currently, the HPPA and
1697 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1698 want. For simpler cases, you can define TC_CONS_RELOC to be
1699 the name of the reloc code that should be stored in the fixS.
1700 If neither is defined, the code uses NO_RELOC if it is
1701 defined, and otherwise uses 0. */
6efd877d 1702
40324362 1703#ifdef BFD_ASSEMBLER
5ac34ac3
ILT
1704 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1705 /* @@ Should look at CPU word size. */
ba71c54d
KR
1706 nbytes == 2 ? BFD_RELOC_16
1707 : nbytes == 8 ? BFD_RELOC_64
1708 : BFD_RELOC_32);
40324362
KR
1709#else
1710#ifdef TC_CONS_FIX_NEW
1711 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1712#else
1713 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1714 it is defined, otherwise use NO_RELOC if it is defined,
1715 otherwise use 0. */
1716#ifndef TC_CONS_RELOC
1717#ifdef NO_RELOC
1718#define TC_CONS_RELOC NO_RELOC
1719#else
1720#define TC_CONS_RELOC 0
1721#endif
1722#endif
5ac34ac3
ILT
1723 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1724 TC_CONS_RELOC);
40324362
KR
1725#endif /* TC_CONS_FIX_NEW */
1726#endif /* BFD_ASSEMBLER */
1727 }
1728}
1729\f
1730#ifdef BITFIELD_CONS_EXPRESSIONS
6efd877d 1731
40324362
KR
1732/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1733 w:x,y:z, where w and y are bitwidths and x and y are values. They
1734 then pack them all together. We do a little better in that we allow
1735 them in words, longs, etc. and we'll pack them in target byte order
1736 for you.
6efd877d 1737
40324362
KR
1738 The rules are: pack least significat bit first, if a field doesn't
1739 entirely fit, put it in the next unit. Overflowing the bitfield is
1740 explicitly *not* even a warning. The bitwidth should be considered
1741 a "mask".
6efd877d 1742
40324362
KR
1743 To use this function the tc-XXX.h file should define
1744 BITFIELD_CONS_EXPRESSIONS. */
f8701a3f 1745
40324362
KR
1746static void
1747parse_bitfield_cons (exp, nbytes)
1748 expressionS *exp;
1749 unsigned int nbytes;
1750{
1751 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1752 char *hold = input_line_pointer;
f8701a3f 1753
5ac34ac3 1754 (void) expression (exp);
f8701a3f 1755
40324362
KR
1756 if (*input_line_pointer == ':')
1757 { /* bitfields */
1758 long value = 0;
f8701a3f 1759
40324362
KR
1760 for (;;)
1761 {
1762 unsigned long width;
f8701a3f 1763
40324362
KR
1764 if (*input_line_pointer != ':')
1765 {
1766 input_line_pointer = hold;
1767 break;
1768 } /* next piece is not a bitfield */
1769
1770 /* In the general case, we can't allow
1771 full expressions with symbol
1772 differences and such. The relocation
1773 entries for symbols not defined in this
1774 assembly would require arbitrary field
1775 widths, positions, and masks which most
1776 of our current object formats don't
1777 support.
1778
1779 In the specific case where a symbol
1780 *is* defined in this assembly, we
1781 *could* build fixups and track it, but
1782 this could lead to confusion for the
1783 backends. I'm lazy. I'll take any
1784 SEG_ABSOLUTE. I think that means that
1785 you can use a previous .set or
1786 .equ type symbol. xoxorich. */
1787
5ac34ac3 1788 if (exp->X_op == O_absent)
6efd877d 1789 {
5ac34ac3 1790 as_warn ("using a bit field width of zero");
40324362 1791 exp->X_add_number = 0;
5ac34ac3 1792 exp->X_op = O_constant;
40324362
KR
1793 } /* implied zero width bitfield */
1794
5ac34ac3 1795 if (exp->X_op != O_constant)
6efd877d 1796 {
40324362 1797 *input_line_pointer = '\0';
5ac34ac3 1798 as_bad ("field width \"%s\" too complex for a bitfield", hold);
40324362
KR
1799 *input_line_pointer = ':';
1800 demand_empty_rest_of_line ();
1801 return;
1802 } /* too complex */
1803
1804 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
9471a360 1805 {
5ac34ac3 1806 as_warn ("field width %d too big to fit in %d bytes: truncated to %d bits",
40324362
KR
1807 width, nbytes, (BITS_PER_CHAR * nbytes));
1808 width = BITS_PER_CHAR * nbytes;
1809 } /* too big */
1810
1811 if (width > bits_available)
9471a360 1812 {
40324362
KR
1813 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1814 input_line_pointer = hold;
1815 exp->X_add_number = value;
1816 break;
1817 } /* won't fit */
1818
1819 hold = ++input_line_pointer; /* skip ':' */
1820
5ac34ac3
ILT
1821 (void) expression (exp);
1822 if (exp->X_op != O_constant)
9471a360 1823 {
40324362
KR
1824 char cache = *input_line_pointer;
1825
1826 *input_line_pointer = '\0';
5ac34ac3 1827 as_bad ("field value \"%s\" too complex for a bitfield", hold);
40324362
KR
1828 *input_line_pointer = cache;
1829 demand_empty_rest_of_line ();
1830 return;
1831 } /* too complex */
1832
5ac34ac3
ILT
1833 value |= ((~(-1 << width) & exp->X_add_number)
1834 << ((BITS_PER_CHAR * nbytes) - bits_available));
40324362
KR
1835
1836 if ((bits_available -= width) == 0
1837 || is_it_end_of_statement ()
1838 || *input_line_pointer != ',')
1839 {
1840 break;
1841 } /* all the bitfields we're gonna get */
1842
1843 hold = ++input_line_pointer;
5ac34ac3 1844 (void) expression (exp);
40324362
KR
1845 } /* forever loop */
1846
1847 exp->X_add_number = value;
5ac34ac3 1848 exp->X_op = O_constant;
40324362
KR
1849 } /* if looks like a bitfield */
1850} /* parse_bitfield_cons() */
1851
1852#endif /* BITFIELD_CONS_EXPRESSIONS */
1853\f
1854#ifdef MRI
1855
1856static void
1857parse_mri_cons (exp, nbytes)
1858 expressionS *exp;
1859 unsigned int nbytes;
1860{
1861 if (*input_line_pointer == '\'')
1862 {
1863 /* An MRI style string, cut into as many bytes as will fit into
1864 a nbyte chunk, left justify if necessary, and separate with
1865 commas so we can try again later */
1866 int scan = 0;
1867 unsigned int result = 0;
1868 input_line_pointer++;
1869 for (scan = 0; scan < nbytes; scan++)
1870 {
1871 if (*input_line_pointer == '\'')
1872 {
1873 if (input_line_pointer[1] == '\'')
6efd877d 1874 {
40324362 1875 input_line_pointer++;
f8701a3f 1876 }
40324362
KR
1877 else
1878 break;
9471a360 1879 }
40324362
KR
1880 result = (result << 8) | (*input_line_pointer++);
1881 }
f8701a3f 1882
40324362
KR
1883 /* Left justify */
1884 while (scan < nbytes)
1885 {
1886 result <<= 8;
1887 scan++;
1888 }
1889 /* Create correct expression */
5ac34ac3 1890 exp->X_op = O_constant;
40324362 1891 exp->X_add_number = result;
40324362
KR
1892 /* Fake it so that we can read the next char too */
1893 if (input_line_pointer[0] != '\'' ||
1894 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1895 {
1896 input_line_pointer -= 2;
1897 input_line_pointer[0] = ',';
1898 input_line_pointer[1] = '\'';
1899 }
1900 else
1901 input_line_pointer++;
1902 }
1903 else
1904 expression (&exp);
1905}
1906
1907#endif /* MRI */
1908\f
1909#ifdef REPEAT_CONS_EXPRESSIONS
1910
1911/* Parse a repeat expression for cons. This is used by the MIPS
1912 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1913 object file COUNT times.
1914
1915 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1916
1917static void
1918parse_repeat_cons (exp, nbytes)
1919 expressionS *exp;
1920 unsigned int nbytes;
1921{
1922 expressionS count;
40324362
KR
1923 register int i;
1924
1925 expression (exp);
1926
1927 if (*input_line_pointer != ':')
1928 {
1929 /* No repeat count. */
1930 return;
1931 }
1932
1933 ++input_line_pointer;
5ac34ac3
ILT
1934 expression (&count);
1935 if (count.X_op != O_constant
40324362
KR
1936 || count.X_add_number <= 0)
1937 {
1938 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1939 return;
1940 }
1941
1942 /* The cons function is going to output this expression once. So we
1943 output it count - 1 times. */
1944 for (i = count.X_add_number - 1; i > 0; i--)
1945 emit_expr (exp, nbytes);
1946}
1947
1948#endif /* REPEAT_CONS_EXPRESSIONS */
fecd2382
RP
1949\f
1950/*
1951 * big_cons()
1952 *
1953 * CONStruct more frag(s) of .quads, or .octa etc.
1954 * Makes 0 or more new frags.
1955 * If need_pass_2 == 1, generate no frag.
1956 * This understands only bignums, not expressions. Cons() understands
1957 * expressions.
1958 *
1959 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1960 *
1961 * This creates objects with struct obstack_control objs, destroying
1962 * any context objs held about a partially completed object. Beware!
1963 *
1964 *
1965 * I think it sucks to have 2 different types of integers, with 2
1966 * routines to read them, store them etc.
1967 * It would be nicer to permit bignums in expressions and only
1968 * complain if the result overflowed. However, due to "efficiency"...
1969 */
ba71c54d
KR
1970/* Worker to do .quad etc statements. Clobbers input_line_pointer, checks
1971 end-of-line. 8=.quad 16=.octa ... */
fecd2382 1972
6efd877d
KR
1973void
1974big_cons (nbytes)
f8701a3f 1975 register int nbytes;
fecd2382 1976{
6efd877d 1977 register char c; /* input_line_pointer->c. */
f8701a3f 1978 register int radix;
6efd877d
KR
1979 register long length; /* Number of chars in an object. */
1980 register int digit; /* Value of 1 digit. */
1981 register int carry; /* For multi-precision arithmetic. */
1982 register int work; /* For multi-precision arithmetic. */
1983 register char *p; /* For multi-precision arithmetic. */
f8701a3f 1984
9471a360 1985 extern const char hex_value[]; /* In hex_value.c. */
f8701a3f
SC
1986
1987 /*
1988 * The following awkward logic is to parse ZERO or more strings,
1989 * comma seperated. Recall an expression includes its leading &
1990 * trailing blanks. We fake a leading ',' if there is (supposed to
1991 * be) a 1st expression, and keep demanding 1 expression for each ','.
1992 */
6efd877d 1993 if (is_it_end_of_statement ())
f8701a3f
SC
1994 {
1995 c = 0; /* Skip loop. */
1996 }
1997 else
1998 {
1999 c = ','; /* Do loop. */
6efd877d 2000 --input_line_pointer;
f8701a3f
SC
2001 }
2002 while (c == ',')
2003 {
6efd877d
KR
2004 ++input_line_pointer;
2005 SKIP_WHITESPACE ();
2006 c = *input_line_pointer;
f8701a3f
SC
2007 /* C contains 1st non-blank character of what we hope is a number. */
2008 if (c == '0')
2009 {
6efd877d
KR
2010 c = *++input_line_pointer;
2011 if (c == 'x' || c == 'X')
fecd2382 2012 {
6efd877d 2013 c = *++input_line_pointer;
f8701a3f 2014 radix = 16;
fecd2382 2015 }
f8701a3f 2016 else
fecd2382 2017 {
f8701a3f 2018 radix = 8;
fecd2382 2019 }
f8701a3f
SC
2020 }
2021 else
2022 {
2023 radix = 10;
2024 }
2025 /*
2026 * This feature (?) is here to stop people worrying about
2027 * mysterious zero constants: which is what they get when
2028 * they completely omit digits.
2029 */
6efd877d
KR
2030 if (hex_value[c] >= radix)
2031 {
2032 as_bad ("Missing digits. 0 assumed.");
2033 }
2034 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
2035 for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
f8701a3f
SC
2036 {
2037 /* Multiply existing number by radix, then add digit. */
2038 carry = digit;
6efd877d 2039 for (p = bignum_low; p <= bignum_high; p++)
fecd2382 2040 {
f8701a3f
SC
2041 work = (*p & MASK_CHAR) * radix + carry;
2042 *p = work & MASK_CHAR;
2043 carry = work >> BITS_PER_CHAR;
fecd2382 2044 }
f8701a3f
SC
2045 if (carry)
2046 {
6efd877d
KR
2047 grow_bignum ();
2048 *bignum_high = carry & MASK_CHAR;
2049 know ((carry & ~MASK_CHAR) == 0);
f8701a3f
SC
2050 }
2051 }
2052 length = bignum_high - bignum_low + 1;
2053 if (length > nbytes)
2054 {
6efd877d 2055 as_warn ("Most significant bits truncated in integer constant.");
f8701a3f
SC
2056 }
2057 else
2058 {
2059 register long leading_zeroes;
fecd2382 2060
6efd877d
KR
2061 for (leading_zeroes = nbytes - length;
2062 leading_zeroes;
2063 leading_zeroes--)
a39116f1 2064 {
6efd877d
KR
2065 grow_bignum ();
2066 *bignum_high = 0;
a39116f1 2067 }
f8701a3f 2068 }
6efd877d 2069 if (!need_pass_2)
f8701a3f 2070 {
9c6d3f66 2071 char *src = bignum_low;
f8701a3f 2072 p = frag_more (nbytes);
9c6d3f66
KR
2073 if (target_big_endian)
2074 {
2075 int i;
2076 for (i = nbytes - 1; i >= 0; i--)
2077 p[i] = *src++;
2078 }
2079 else
4380166d 2080 memcpy (p, bignum_low, (int) nbytes);
f8701a3f
SC
2081 }
2082 /* C contains character after number. */
6efd877d
KR
2083 SKIP_WHITESPACE ();
2084 c = *input_line_pointer;
f8701a3f
SC
2085 /* C contains 1st non-blank character after number. */
2086 }
6efd877d
KR
2087 demand_empty_rest_of_line ();
2088} /* big_cons() */
f8701a3f 2089
6efd877d
KR
2090/* Extend bignum by 1 char. */
2091static void
2092grow_bignum ()
2093{
f8701a3f
SC
2094 register long length;
2095
6efd877d 2096 bignum_high++;
f8701a3f
SC
2097 if (bignum_high >= bignum_limit)
2098 {
2099 length = bignum_limit - bignum_low;
6efd877d 2100 bignum_low = xrealloc (bignum_low, length + length);
f8701a3f
SC
2101 bignum_high = bignum_low + length;
2102 bignum_limit = bignum_low + length + length;
2103 }
6efd877d 2104} /* grow_bignum(); */
fecd2382
RP
2105\f
2106/*
2107 * float_cons()
2108 *
2109 * CONStruct some more frag chars of .floats .ffloats etc.
2110 * Makes 0 or more new frags.
2111 * If need_pass_2 == 1, no frags are emitted.
2112 * This understands only floating literals, not expressions. Sorry.
2113 *
2114 * A floating constant is defined by atof_generic(), except it is preceded
2115 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2116 * reading, I decided to be incompatible. This always tries to give you
2117 * rounded bits to the precision of the pseudo-op. Former AS did premature
2118 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2119 * a choice of 2 flavours of noise according to which of 2 floating-point
2120 * scanners you directed AS to use.
2121 *
2122 * In: input_line_pointer->whitespace before, or '0' of flonum.
2123 *
2124 */
2125
ba71c54d
KR
2126void
2127float_cons (float_type)
6efd877d 2128 /* Clobbers input_line-pointer, checks end-of-line. */
f8701a3f 2129 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
fecd2382 2130{
6efd877d 2131 register char *p;
6efd877d
KR
2132 int length; /* Number of chars in an object. */
2133 register char *err; /* Error from scanning floating literal. */
2134 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
f8701a3f 2135
6efd877d 2136 if (is_it_end_of_statement ())
f8701a3f 2137 {
1e9cf565
ILT
2138 demand_empty_rest_of_line ();
2139 return;
f8701a3f 2140 }
1e9cf565
ILT
2141
2142 do
f8701a3f
SC
2143 {
2144 /* input_line_pointer->1st char of a flonum (we hope!). */
6efd877d 2145 SKIP_WHITESPACE ();
1e9cf565 2146
f8701a3f
SC
2147 /* Skip any 0{letter} that may be present. Don't even check if the
2148 * letter is legal. Someone may invent a "z" format and this routine
2149 * has no use for such information. Lusers beware: you get
2150 * diagnostics if your input is ill-conditioned.
2151 */
6efd877d
KR
2152 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2153 input_line_pointer += 2;
f8701a3f
SC
2154
2155 err = md_atof (float_type, temp, &length);
6efd877d
KR
2156 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2157 know (length > 0);
9a7d824a 2158 if (err && *err)
f8701a3f 2159 {
6efd877d
KR
2160 as_bad ("Bad floating literal: %s", err);
2161 ignore_rest_of_line ();
1e9cf565 2162 return;
f8701a3f 2163 }
1e9cf565
ILT
2164
2165 if (!need_pass_2)
f8701a3f 2166 {
1e9cf565
ILT
2167 int count;
2168
2169 count = 1;
2170
2171#ifdef REPEAT_CONS_EXPRESSIONS
2172 if (*input_line_pointer == ':')
2173 {
1e9cf565
ILT
2174 expressionS count_exp;
2175
2176 ++input_line_pointer;
5ac34ac3
ILT
2177 expression (&count_exp);
2178 if (count_exp.X_op != O_constant
1e9cf565
ILT
2179 || count_exp.X_add_number <= 0)
2180 {
5ac34ac3 2181 as_warn ("unresolvable or nonpositive repeat count; using 1");
1e9cf565
ILT
2182 }
2183 else
2184 count = count_exp.X_add_number;
2185 }
2186#endif
2187
2188 while (--count >= 0)
a39116f1 2189 {
f8701a3f 2190 p = frag_more (length);
4380166d 2191 memcpy (p, temp, length);
a39116f1 2192 }
542e1629 2193 }
1e9cf565 2194 SKIP_WHITESPACE ();
f8701a3f 2195 }
1e9cf565
ILT
2196 while (*input_line_pointer++ == ',');
2197
2198 --input_line_pointer; /* Put terminator back into stream. */
6efd877d 2199 demand_empty_rest_of_line ();
f8701a3f 2200} /* float_cons() */
fecd2382
RP
2201\f
2202/*
2203 * stringer()
2204 *
2205 * We read 0 or more ',' seperated, double-quoted strings.
2206 *
2207 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2208 */
a39116f1
RP
2209
2210
6efd877d
KR
2211void
2212stringer (append_zero) /* Worker to do .ascii etc statements. */
2213 /* Checks end-of-line. */
f8701a3f 2214 register int append_zero; /* 0: don't append '\0', else 1 */
fecd2382 2215{
f8701a3f 2216 register unsigned int c;
6efd877d 2217
f8701a3f
SC
2218 /*
2219 * The following awkward logic is to parse ZERO or more strings,
2220 * comma seperated. Recall a string expression includes spaces
2221 * before the opening '\"' and spaces after the closing '\"'.
2222 * We fake a leading ',' if there is (supposed to be)
2223 * a 1st, expression. We keep demanding expressions for each
2224 * ','.
2225 */
6efd877d
KR
2226 if (is_it_end_of_statement ())
2227 {
2228 c = 0; /* Skip loop. */
2229 ++input_line_pointer; /* Compensate for end of loop. */
2230 }
f8701a3f 2231 else
6efd877d
KR
2232 {
2233 c = ','; /* Do loop. */
2234 }
2235 while (c == ',' || c == '<' || c == '"')
2236 {
2237 SKIP_WHITESPACE ();
2238 switch (*input_line_pointer)
2239 {
2240 case '\"':
2241 ++input_line_pointer; /*->1st char of string. */
2242 while (is_a_char (c = next_char_of_string ()))
2243 {
2244 FRAG_APPEND_1_CHAR (c);
2245 }
2246 if (append_zero)
2247 {
2248 FRAG_APPEND_1_CHAR (0);
2249 }
2250 know (input_line_pointer[-1] == '\"');
2251 break;
2252 case '<':
2253 input_line_pointer++;
2254 c = get_single_number ();
2255 FRAG_APPEND_1_CHAR (c);
2256 if (*input_line_pointer != '>')
2257 {
2258 as_bad ("Expected <nn>");
2259 }
2260 input_line_pointer++;
2261 break;
2262 case ',':
2263 input_line_pointer++;
2264 break;
2265 }
2266 SKIP_WHITESPACE ();
2267 c = *input_line_pointer;
f8701a3f 2268 }
f8701a3f 2269
6efd877d
KR
2270 demand_empty_rest_of_line ();
2271} /* stringer() */
fecd2382 2272\f
6efd877d 2273/* FIXME-SOMEDAY: I had trouble here on characters with the
f8701a3f
SC
2274 high bits set. We'll probably also have trouble with
2275 multibyte chars, wide chars, etc. Also be careful about
2276 returning values bigger than 1 byte. xoxorich. */
fecd2382 2277
6efd877d
KR
2278unsigned int
2279next_char_of_string ()
2280{
2281 register unsigned int c;
2282
2283 c = *input_line_pointer++ & CHAR_MASK;
2284 switch (c)
2285 {
2286 case '\"':
2287 c = NOT_A_CHAR;
2288 break;
2289
2290 case '\\':
2291 switch (c = *input_line_pointer++)
2292 {
2293 case 'b':
2294 c = '\b';
2295 break;
2296
2297 case 'f':
2298 c = '\f';
2299 break;
2300
2301 case 'n':
2302 c = '\n';
2303 break;
2304
2305 case 'r':
2306 c = '\r';
2307 break;
2308
2309 case 't':
2310 c = '\t';
2311 break;
2312
fecd2382 2313#ifdef BACKSLASH_V
6efd877d
KR
2314 case 'v':
2315 c = '\013';
2316 break;
fecd2382 2317#endif
6efd877d
KR
2318
2319 case '\\':
2320 case '"':
2321 break; /* As itself. */
2322
2323 case '0':
2324 case '1':
2325 case '2':
2326 case '3':
2327 case '4':
2328 case '5':
2329 case '6':
2330 case '7':
2331 case '8':
2332 case '9':
2333 {
2334 long number;
2335
2336 for (number = 0; isdigit (c); c = *input_line_pointer++)
2337 {
2338 number = number * 8 + c - '0';
2339 }
2340 c = number & 0xff;
2341 }
2342 --input_line_pointer;
2343 break;
2344
2345 case '\n':
2346 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2347 as_warn ("Unterminated string: Newline inserted.");
2348 c = '\n';
2349 break;
2350
2351 default:
2352
fecd2382 2353#ifdef ONLY_STANDARD_ESCAPES
6efd877d
KR
2354 as_bad ("Bad escaped character in string, '?' assumed");
2355 c = '?';
fecd2382 2356#endif /* ONLY_STANDARD_ESCAPES */
6efd877d
KR
2357
2358 break;
2359 } /* switch on escaped char */
2360 break;
2361
2362 default:
2363 break;
2364 } /* switch on char */
2365 return (c);
2366} /* next_char_of_string() */
fecd2382
RP
2367\f
2368static segT
f8701a3f 2369get_segmented_expression (expP)
6efd877d 2370 register expressionS *expP;
fecd2382 2371{
6efd877d 2372 register segT retval;
f8701a3f 2373
9471a360 2374 retval = expression (expP);
5ac34ac3
ILT
2375 if (expP->X_op == O_illegal
2376 || expP->X_op == O_absent
2377 || expP->X_op == O_big)
f8701a3f 2378 {
5ac34ac3
ILT
2379 as_bad ("expected address expression; zero assumed");
2380 expP->X_op = O_constant;
6efd877d 2381 expP->X_add_number = 0;
5ac34ac3 2382 retval = absolute_section;
f8701a3f 2383 }
5ac34ac3 2384 return retval;
fecd2382
RP
2385}
2386
6efd877d
KR
2387static segT
2388get_known_segmented_expression (expP)
2389 register expressionS *expP;
fecd2382 2390{
6efd877d 2391 register segT retval;
f8701a3f 2392
9471a360 2393 if ((retval = get_segmented_expression (expP)) == undefined_section)
f8701a3f 2394 {
5ac34ac3
ILT
2395 /* There is no easy way to extract the undefined symbol from the
2396 expression. */
2397 if (expP->X_add_symbol != NULL
2398 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2399 as_warn ("symbol \"%s\" undefined; zero assumed",
2400 S_GET_NAME (expP->X_add_symbol));
f8701a3f 2401 else
5ac34ac3
ILT
2402 as_warn ("some symbol undefined; zero assumed");
2403 retval = absolute_section;
2404 expP->X_op = O_constant;
6efd877d 2405 expP->X_add_number = 0;
f8701a3f 2406 }
5ac34ac3 2407 know (retval == absolute_section || SEG_NORMAL (retval));
f8701a3f 2408 return (retval);
fecd2382
RP
2409} /* get_known_segmented_expression() */
2410
6efd877d 2411/* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
f8701a3f 2412get_absolute_expression ()
fecd2382 2413{
6efd877d 2414 expressionS exp;
f8701a3f 2415
5ac34ac3
ILT
2416 expression (&exp);
2417 if (exp.X_op != O_constant)
f8701a3f 2418 {
5ac34ac3
ILT
2419 if (exp.X_op != O_absent)
2420 as_bad ("bad absolute expression; zero assumed");
6efd877d 2421 exp.X_add_number = 0;
f8701a3f 2422 }
5ac34ac3 2423 return exp.X_add_number;
fecd2382
RP
2424}
2425
6efd877d
KR
2426char /* return terminator */
2427get_absolute_expression_and_terminator (val_pointer)
2428 long *val_pointer; /* return value of expression */
fecd2382 2429{
6efd877d
KR
2430 *val_pointer = get_absolute_expression ();
2431 return (*input_line_pointer++);
fecd2382
RP
2432}
2433\f
2434/*
2435 * demand_copy_C_string()
2436 *
2437 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2438 * Give a warning if that happens.
2439 */
2440char *
f8701a3f 2441demand_copy_C_string (len_pointer)
6efd877d 2442 int *len_pointer;
fecd2382 2443{
6efd877d 2444 register char *s;
f8701a3f 2445
6efd877d 2446 if ((s = demand_copy_string (len_pointer)) != 0)
f8701a3f
SC
2447 {
2448 register int len;
2449
6efd877d 2450 for (len = *len_pointer;
f8701a3f
SC
2451 len > 0;
2452 len--)
2453 {
6efd877d 2454 if (*s == 0)
fecd2382 2455 {
f8701a3f
SC
2456 s = 0;
2457 len = 1;
6efd877d
KR
2458 *len_pointer = 0;
2459 as_bad ("This string may not contain \'\\0\'");
fecd2382 2460 }
f8701a3f
SC
2461 }
2462 }
2463 return (s);
fecd2382
RP
2464}
2465\f
2466/*
2467 * demand_copy_string()
2468 *
2469 * Demand string, but return a safe (=private) copy of the string.
2470 * Return NULL if we can't read a string here.
2471 */
6efd877d
KR
2472static char *
2473demand_copy_string (lenP)
2474 int *lenP;
fecd2382 2475{
6efd877d
KR
2476 register unsigned int c;
2477 register int len;
2478 char *retval;
2479
2480 len = 0;
2481 SKIP_WHITESPACE ();
2482 if (*input_line_pointer == '\"')
2483 {
2484 input_line_pointer++; /* Skip opening quote. */
2485
2486 while (is_a_char (c = next_char_of_string ()))
2487 {
2488 obstack_1grow (&notes, c);
2489 len++;
fecd2382 2490 }
6efd877d
KR
2491 /* JF this next line is so demand_copy_C_string will return a null
2492 termanated string. */
2493 obstack_1grow (&notes, '\0');
2494 retval = obstack_finish (&notes);
2495 }
2496 else
2497 {
2498 as_warn ("Missing string");
2499 retval = NULL;
2500 ignore_rest_of_line ();
2501 }
2502 *lenP = len;
2503 return (retval);
2504} /* demand_copy_string() */
fecd2382
RP
2505\f
2506/*
2507 * is_it_end_of_statement()
2508 *
2509 * In: Input_line_pointer->next character.
2510 *
2511 * Do: Skip input_line_pointer over all whitespace.
2512 *
2513 * Out: 1 if input_line_pointer->end-of-line.
f8701a3f 2514*/
6efd877d
KR
2515int
2516is_it_end_of_statement ()
2517{
2518 SKIP_WHITESPACE ();
2519 return (is_end_of_line[*input_line_pointer]);
2520} /* is_it_end_of_statement() */
fecd2382 2521
6efd877d
KR
2522void
2523equals (sym_name)
2524 char *sym_name;
fecd2382 2525{
6efd877d 2526 register symbolS *symbolP; /* symbol we are working with */
f8701a3f
SC
2527
2528 input_line_pointer++;
6efd877d 2529 if (*input_line_pointer == '=')
f8701a3f
SC
2530 input_line_pointer++;
2531
6efd877d 2532 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
f8701a3f
SC
2533 input_line_pointer++;
2534
6efd877d
KR
2535 if (sym_name[0] == '.' && sym_name[1] == '\0')
2536 {
2537 /* Turn '. = mumble' into a .org mumble */
2538 register segT segment;
2539 expressionS exp;
2540 register char *p;
f8701a3f 2541
6efd877d
KR
2542 segment = get_known_segmented_expression (&exp);
2543 if (!need_pass_2)
2544 {
9471a360 2545 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
2546 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2547 segment_name (segment),
2548 segment_name (now_seg));
2549 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2550 exp.X_add_number, (char *) 0);
2551 *p = 0;
2552 } /* if (ok to make frag) */
2553 }
2554 else
2555 {
2556 symbolP = symbol_find_or_make (sym_name);
2557 pseudo_set (symbolP);
2558 }
2559} /* equals() */
fecd2382
RP
2560
2561/* .include -- include a file at this point. */
2562
2563/* ARGSUSED */
6efd877d
KR
2564void
2565s_include (arg)
2566 int arg;
fecd2382 2567{
f8701a3f
SC
2568 char *newbuf;
2569 char *filename;
2570 int i;
2571 FILE *try;
2572 char *path;
2573
6efd877d
KR
2574 filename = demand_copy_string (&i);
2575 demand_empty_rest_of_line ();
2576 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2577 for (i = 0; i < include_dir_count; i++)
2578 {
2579 strcpy (path, include_dirs[i]);
2580 strcat (path, "/");
2581 strcat (path, filename);
2582 if (0 != (try = fopen (path, "r")))
2583 {
2584 fclose (try);
2585 goto gotit;
2586 }
2587 }
2588 free (path);
f8701a3f
SC
2589 path = filename;
2590gotit:
2591 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2592 newbuf = input_scrub_include_file (path, input_line_pointer);
2593 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6efd877d 2594} /* s_include() */
fecd2382 2595
6efd877d
KR
2596void
2597add_include_dir (path)
2598 char *path;
fecd2382 2599{
f8701a3f
SC
2600 int i;
2601
2602 if (include_dir_count == 0)
2603 {
6efd877d 2604 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
f8701a3f
SC
2605 include_dirs[0] = "."; /* Current dir */
2606 include_dir_count = 2;
2607 }
2608 else
2609 {
2610 include_dir_count++;
6efd877d
KR
2611 include_dirs = (char **) realloc (include_dirs,
2612 include_dir_count * sizeof (*include_dirs));
f8701a3f
SC
2613 }
2614
6efd877d 2615 include_dirs[include_dir_count - 1] = path; /* New one */
f8701a3f 2616
6efd877d
KR
2617 i = strlen (path);
2618 if (i > include_dir_maxlen)
2619 include_dir_maxlen = i;
2620} /* add_include_dir() */
fecd2382 2621
6efd877d
KR
2622void
2623s_ignore (arg)
2624 int arg;
fecd2382 2625{
6efd877d
KR
2626 while (!is_end_of_line[*input_line_pointer])
2627 {
2628 ++input_line_pointer;
2629 }
2630 ++input_line_pointer;
fecd2382 2631
6efd877d
KR
2632 return;
2633} /* s_ignore() */
fecd2382
RP
2634
2635/* end of read.c */
This page took 0.228642 seconds and 4 git commands to generate.