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