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