(target i386-*-netbsd0.8): Use 386bsd emulation.
[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. */
9d90491e
ILT
1106 if (temp >= 8)
1107 align = 3;
1108 else if (temp >= 4)
ede7bc1c
SC
1109 align = 2;
1110 else if (temp >= 2)
1111 align = 1;
1112 else
1113 align = temp;
1114
1115 record_alignment(bss_seg, align);
1116 }
9a7d824a 1117
6efd877d
KR
1118 if (needs_align)
1119 {
1120 align = 0;
1121 SKIP_WHITESPACE ();
1122 if (*input_line_pointer != ',')
1123 {
1124 as_bad ("Expected comma after size");
1125 ignore_rest_of_line ();
1126 return;
1127 }
1128 input_line_pointer++;
1129 SKIP_WHITESPACE ();
1130 if (*input_line_pointer == '\n')
1131 {
1132 as_bad ("Missing alignment");
1133 return;
1134 }
1135 align = get_absolute_expression ();
1136 if (align > max_alignment)
1137 {
1138 align = max_alignment;
1139 as_warn ("Alignment too large: %d. assumed.", align);
1140 }
1141 else if (align < 0)
1142 {
1143 align = 0;
1144 as_warn ("Alignment negative. 0 assumed.");
1145 }
9a7d824a 1146 record_alignment (bss_seg, align);
6efd877d 1147 } /* if needs align */
4075afe1
KR
1148 else
1149 {
1150 /* Assume some objects may require alignment on some systems. */
1151#ifdef TC_ALPHA
1152 if (temp > 1)
1153 {
1154 align = ffs (temp) - 1;
1155 if (temp % (1 << align))
1156 abort ();
1157 }
1158#endif
1159 }
f8701a3f 1160
6efd877d
KR
1161 *p = 0;
1162 symbolP = symbol_find_or_make (name);
1163 *p = c;
f8701a3f 1164
6efd877d 1165 if (
fecd2382 1166#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6efd877d
KR
1167 S_GET_OTHER (symbolP) == 0 &&
1168 S_GET_DESC (symbolP) == 0 &&
fecd2382 1169#endif /* OBJ_AOUT or OBJ_BOUT */
9a7d824a 1170 (S_GET_SEGMENT (symbolP) == bss_seg
6efd877d
KR
1171 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1172 {
604633ae 1173 char *pfrag;
85825401 1174
9a7d824a 1175 subseg_set (bss_seg, 1);
85825401
ILT
1176
1177 if (align)
1178 frag_align (align, 0);
1179 /* detach from old frag */
9a7d824a 1180 if (S_GET_SEGMENT (symbolP) == bss_seg)
85825401
ILT
1181 symbolP->sy_frag->fr_symbol = NULL;
1182
1183 symbolP->sy_frag = frag_now;
604633ae
ILT
1184 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1185 temp, (char *)0);
1186 *pfrag = 0;
f8701a3f 1187
9a7d824a 1188 S_SET_SEGMENT (symbolP, bss_seg);
85825401 1189
fecd2382 1190#ifdef OBJ_COFF
6efd877d 1191 /* The symbol may already have been created with a preceding
c8863a58
KR
1192 ".globl" directive -- be careful not to step on storage class
1193 in that case. Otherwise, set it to static. */
6efd877d
KR
1194 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1195 {
1196 S_SET_STORAGE_CLASS (symbolP, C_STAT);
fecd2382 1197 }
6efd877d 1198#endif /* OBJ_COFF */
6efd877d
KR
1199 }
1200 else
1201 {
85825401 1202 as_bad ("Ignoring attempt to re-define symbol %s.", name);
6efd877d 1203 }
f8701a3f 1204
9a7d824a 1205 subseg_set (current_seg, current_subseg);
9a7d824a
ILT
1206
1207 demand_empty_rest_of_line ();
6efd877d 1208} /* s_lcomm() */
fecd2382 1209
6efd877d 1210void
604633ae
ILT
1211s_lsym (ignore)
1212 int ignore;
6efd877d
KR
1213{
1214 register char *name;
1215 register char c;
1216 register char *p;
6efd877d
KR
1217 expressionS exp;
1218 register symbolS *symbolP;
1219
1220 /* we permit ANY defined expression: BSD4.2 demands constants */
1221 name = input_line_pointer;
1222 c = get_symbol_end ();
1223 p = input_line_pointer;
1224 *p = c;
1225 SKIP_WHITESPACE ();
1226 if (*input_line_pointer != ',')
1227 {
1228 *p = 0;
1229 as_bad ("Expected comma after name \"%s\"", name);
1230 *p = c;
1231 ignore_rest_of_line ();
1232 return;
1233 }
1234 input_line_pointer++;
b31f2abb
KR
1235 expression (&exp);
1236 if (exp.X_op != O_constant
1237 && exp.X_op != O_register)
1238 {
1239 as_bad ("bad expression");
1240 ignore_rest_of_line ();
1241 return;
1242 }
6efd877d
KR
1243 *p = 0;
1244 symbolP = symbol_find_or_make (name);
f8701a3f 1245
c8863a58
KR
1246 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1247 symbolP->sy_desc == 0) out of this test because coff doesn't have
1248 those fields, and I can't see when they'd ever be tripped. I
1249 don't think I understand why they were here so I may have
1250 introduced a bug. As recently as 1.37 didn't have this test
1251 anyway. xoxorich. */
f8701a3f 1252
9471a360 1253 if (S_GET_SEGMENT (symbolP) == undefined_section
6efd877d
KR
1254 && S_GET_VALUE (symbolP) == 0)
1255 {
c8863a58
KR
1256 /* The name might be an undefined .global symbol; be sure to
1257 keep the "external" bit. */
b31f2abb
KR
1258 S_SET_SEGMENT (symbolP,
1259 (exp.X_op == O_constant
1260 ? absolute_section
1261 : reg_section));
1262 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d
KR
1263 }
1264 else
1265 {
1266 as_bad ("Symbol %s already defined", name);
1267 }
1268 *p = c;
1269 demand_empty_rest_of_line ();
1270} /* s_lsym() */
1271
1272void
604633ae
ILT
1273s_org (ignore)
1274 int ignore;
6efd877d
KR
1275{
1276 register segT segment;
1277 expressionS exp;
1278 register long temp_fill;
1279 register char *p;
9471a360
KR
1280 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1281 thing as a sub-segment-relative origin. Any absolute origin is
1282 given a warning, then assumed to be segment-relative. Any
1283 segmented origin expression ("foo+42") had better be in the right
1284 segment or the .org is ignored.
1285
1286 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1287 we never know sub-segment sizes when we are reading code. BSD
1288 will crash trying to emit negative numbers of filler bytes in
1289 certain .orgs. We don't crash, but see as-write for that code.
1290
1291 Don't make frag if need_pass_2==1. */
6efd877d
KR
1292 segment = get_known_segmented_expression (&exp);
1293 if (*input_line_pointer == ',')
1294 {
1295 input_line_pointer++;
1296 temp_fill = get_absolute_expression ();
1297 }
1298 else
1299 temp_fill = 0;
1300 if (!need_pass_2)
1301 {
9471a360 1302 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
1303 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1304 segment_name (segment), segment_name (now_seg));
1305 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1306 exp.X_add_number, (char *) 0);
1307 *p = temp_fill;
1308 } /* if (ok to make frag) */
1309 demand_empty_rest_of_line ();
1310} /* s_org() */
1311
1312void
604633ae
ILT
1313s_set (ignore)
1314 int ignore;
6efd877d
KR
1315{
1316 register char *name;
1317 register char delim;
1318 register char *end_name;
1319 register symbolS *symbolP;
1320
1321 /*
c8863a58
KR
1322 * Especial apologies for the random logic:
1323 * this just grew, and could be parsed much more simply!
1324 * Dean in haste.
1325 */
6efd877d
KR
1326 name = input_line_pointer;
1327 delim = get_symbol_end ();
1328 end_name = input_line_pointer;
1329 *end_name = delim;
1330 SKIP_WHITESPACE ();
f8701a3f 1331
6efd877d
KR
1332 if (*input_line_pointer != ',')
1333 {
1334 *end_name = 0;
1335 as_bad ("Expected comma after name \"%s\"", name);
1336 *end_name = delim;
1337 ignore_rest_of_line ();
1338 return;
1339 }
1340
1341 input_line_pointer++;
1342 *end_name = 0;
1343
1344 if (name[0] == '.' && name[1] == '\0')
1345 {
1346 /* Turn '. = mumble' into a .org mumble */
1347 register segT segment;
1348 expressionS exp;
1349 register char *ptr;
1350
1351 segment = get_known_segmented_expression (&exp);
f8701a3f 1352
6efd877d
KR
1353 if (!need_pass_2)
1354 {
9471a360 1355 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
1356 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1357 segment_name (segment),
1358 segment_name (now_seg));
1359 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1360 exp.X_add_number, (char *) 0);
1361 *ptr = 0;
1362 } /* if (ok to make frag) */
1363
1364 *end_name = delim;
1365 return;
1366 }
1367
1368 if ((symbolP = symbol_find (name)) == NULL
1369 && (symbolP = md_undefined_symbol (name)) == NULL)
1370 {
9471a360 1371 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
fecd2382 1372#ifdef OBJ_COFF
6efd877d
KR
1373 /* "set" symbols are local unless otherwise specified. */
1374 SF_SET_LOCAL (symbolP);
fecd2382 1375#endif /* OBJ_COFF */
f8701a3f 1376
6efd877d 1377 } /* make a new symbol */
f8701a3f 1378
6efd877d 1379 symbol_table_insert (symbolP);
f8701a3f 1380
6efd877d
KR
1381 *end_name = delim;
1382 pseudo_set (symbolP);
1383 demand_empty_rest_of_line ();
1384} /* s_set() */
fecd2382 1385
6efd877d
KR
1386void
1387s_space (mult)
1388 int mult;
b53ccaac 1389{
6efd877d
KR
1390 long temp_repeat;
1391 register long temp_fill;
1392 register char *p;
1393
1394 /* Just like .fill, but temp_size = 1 */
1395 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1396 {
1397 temp_fill = get_absolute_expression ();
1398 }
1399 else
1400 {
1401 input_line_pointer--; /* Backup over what was not a ','. */
1402 temp_fill = 0;
1403 }
1404 if (mult)
1405 {
bf449293 1406 temp_repeat *= mult;
6efd877d
KR
1407 }
1408 if (temp_repeat <= 0)
1409 {
1410 as_warn ("Repeat < 0, .space ignored");
1411 ignore_rest_of_line ();
1412 return;
1413 }
1414 if (!need_pass_2)
1415 {
1416 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1417 temp_repeat, (char *) 0);
1418 *p = temp_fill;
1419 }
1420 demand_empty_rest_of_line ();
1421} /* s_space() */
fecd2382
RP
1422
1423void
604633ae
ILT
1424s_text (ignore)
1425 int ignore;
fecd2382 1426{
6efd877d 1427 register int temp;
f8701a3f 1428
6efd877d 1429 temp = get_absolute_expression ();
9471a360 1430 subseg_set (text_section, (subsegT) temp);
6efd877d
KR
1431 demand_empty_rest_of_line ();
1432} /* s_text() */
fecd2382 1433\f
6efd877d 1434
6efd877d
KR
1435void
1436demand_empty_rest_of_line ()
1437{
1438 SKIP_WHITESPACE ();
58d4951d 1439 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
1440 {
1441 input_line_pointer++;
1442 }
1443 else
1444 {
1445 ignore_rest_of_line ();
1446 }
1447 /* Return having already swallowed end-of-line. */
1448} /* Return pointing just after end-of-line. */
fecd2382
RP
1449
1450void
6efd877d 1451ignore_rest_of_line () /* For suspect lines: gives warning. */
fecd2382 1452{
58d4951d 1453 if (!is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 1454 {
6efd877d
KR
1455 if (isprint (*input_line_pointer))
1456 as_bad ("Rest of line ignored. First ignored character is `%c'.",
f8701a3f
SC
1457 *input_line_pointer);
1458 else
6efd877d 1459 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
f8701a3f
SC
1460 *input_line_pointer);
1461 while (input_line_pointer < buffer_limit
58d4951d 1462 && !is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 1463 {
6efd877d 1464 input_line_pointer++;
f8701a3f
SC
1465 }
1466 }
6efd877d 1467 input_line_pointer++; /* Return pointing just after end-of-line. */
58d4951d 1468 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
fecd2382
RP
1469}
1470
1471/*
1472 * pseudo_set()
1473 *
1474 * In: Pointer to a symbol.
1475 * Input_line_pointer->expression.
1476 *
1477 * Out: Input_line_pointer->just after any whitespace after expression.
1478 * Tried to set symbol to value of expression.
1479 * Will change symbols type, value, and frag;
fecd2382
RP
1480 */
1481void
f8701a3f 1482pseudo_set (symbolP)
6efd877d 1483 symbolS *symbolP;
fecd2382 1484{
6efd877d 1485 expressionS exp;
fecd2382 1486#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
f8701a3f 1487 int ext;
fecd2382 1488#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 1489
6efd877d 1490 know (symbolP); /* NULL pointer is logic error. */
fecd2382 1491#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
9471a360 1492 /* @@ Fix this right for BFD. */
6efd877d 1493 ext = S_IS_EXTERNAL (symbolP);
fecd2382 1494#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 1495
5ac34ac3 1496 (void) expression (&exp);
f8701a3f 1497
5ac34ac3
ILT
1498 if (exp.X_op == O_illegal)
1499 as_bad ("illegal expression; zero assumed");
1500 else if (exp.X_op == O_absent)
1501 as_bad ("missing expression; zero assumed");
1502 else if (exp.X_op == O_big)
1503 as_bad ("%s number invalid; zero assumed",
1504 exp.X_add_number > 0 ? "bignum" : "floating point");
1505 else if (exp.X_op == O_subtract
1506 && (S_GET_SEGMENT (exp.X_add_symbol)
1507 == S_GET_SEGMENT (exp.X_op_symbol))
1508 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1509 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
9471a360 1510 {
5ac34ac3
ILT
1511 exp.X_op = O_constant;
1512 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1513 - S_GET_VALUE (exp.X_op_symbol));
9471a360 1514 }
5ac34ac3
ILT
1515
1516 switch (exp.X_op)
9471a360 1517 {
5ac34ac3
ILT
1518 case O_illegal:
1519 case O_absent:
1520 case O_big:
1521 exp.X_add_number = 0;
1522 /* Fall through. */
1523 case O_constant:
9471a360 1524 S_SET_SEGMENT (symbolP, absolute_section);
fecd2382 1525#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
9471a360 1526 /* @@ Fix this right for BFD. */
5ac34ac3
ILT
1527 if (ext)
1528 S_SET_EXTERNAL (symbolP);
6efd877d 1529 else
6efd877d 1530 S_CLEAR_EXTERNAL (symbolP);
fecd2382 1531#endif /* OBJ_AOUT or OBJ_BOUT */
604633ae 1532 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d 1533 symbolP->sy_frag = &zero_address_frag;
5ac34ac3 1534 break;
f8701a3f 1535
5ac34ac3
ILT
1536 case O_register:
1537 S_SET_SEGMENT (symbolP, reg_section);
604633ae 1538 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
5ac34ac3
ILT
1539 symbolP->sy_frag = &zero_address_frag;
1540 break;
1541
1542 case O_symbol:
1543 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1544 symbolP->sy_value = exp;
6efd877d
KR
1545 else
1546 {
5ac34ac3
ILT
1547 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1548#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1549 /* @@ Fix this right for BFD! */
1550 if (ext)
1551 S_SET_EXTERNAL (symbolP);
1552 else
1553 S_CLEAR_EXTERNAL (symbolP);
fecd2382 1554#endif /* OBJ_AOUT or OBJ_BOUT */
5ac34ac3
ILT
1555 S_SET_VALUE (symbolP,
1556 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1557 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1558 }
1559 break;
f8701a3f 1560
5ac34ac3
ILT
1561 default:
1562 /* The value is some complex expression.
1563 FIXME: Should we set the segment to anything? */
1564 symbolP->sy_value = exp;
1565 break;
f8701a3f 1566 }
fecd2382
RP
1567}
1568\f
1569/*
1570 * cons()
1571 *
1572 * CONStruct more frag of .bytes, or .words etc.
1573 * Should need_pass_2 be 1 then emit no frag(s).
80aab579 1574 * This understands EXPRESSIONS.
fecd2382
RP
1575 *
1576 * Bug (?)
1577 *
1578 * This has a split personality. We use expression() to read the
1579 * value. We can detect if the value won't fit in a byte or word.
1580 * But we can't detect if expression() discarded significant digits
1581 * in the case of a long. Not worth the crocks required to fix it.
1582 */
1583
40324362
KR
1584/* Select a parser for cons expressions. */
1585
1586/* Some targets need to parse the expression in various fancy ways.
1587 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1588 (for example, the HPPA does this). Otherwise, you can define
1589 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1590 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1591 are defined, which is the normal case, then only simple expressions
1592 are permitted. */
1593
1594#ifndef TC_PARSE_CONS_EXPRESSION
1595#ifdef BITFIELD_CONS_EXPRESSIONS
1596#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1597static void
1598parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1599#endif
1600#ifdef MRI
1601#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1602static void
1603parse_mri_cons PARAMS ((expressionS *exp));
1604#endif
1605#ifdef REPEAT_CONS_EXPRESSIONS
1606#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1607static void
1608parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1609#endif
1610
1611/* If we haven't gotten one yet, just call expression. */
1612#ifndef TC_PARSE_CONS_EXPRESSION
1613#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1614#endif
1615#endif
1616
6efd877d
KR
1617/* worker to do .byte etc statements */
1618/* clobbers input_line_pointer, checks */
1619/* end-of-line. */
1620void
1621cons (nbytes)
604633ae 1622 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
fecd2382 1623{
6efd877d 1624 expressionS exp;
f8701a3f 1625
40324362 1626 if (is_it_end_of_statement ())
6efd877d 1627 {
40324362
KR
1628 demand_empty_rest_of_line ();
1629 return;
6efd877d 1630 }
40324362
KR
1631
1632 do
6efd877d 1633 {
604633ae
ILT
1634 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
1635 emit_expr (&exp, (unsigned int) nbytes);
40324362
KR
1636 }
1637 while (*input_line_pointer++ == ',');
1638
1639 input_line_pointer--; /* Put terminator back into stream. */
1640 demand_empty_rest_of_line ();
30d3a445 1641}
f8701a3f 1642
40324362
KR
1643/* Put the contents of expression EXP into the object file using
1644 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
f8701a3f 1645
40324362
KR
1646void
1647emit_expr (exp, nbytes)
1648 expressionS *exp;
1649 unsigned int nbytes;
1650{
5ac34ac3 1651 operatorT op;
40324362 1652 register char *p;
80aab579 1653 valueT extra_digit = 0;
f8701a3f 1654
40324362
KR
1655 /* Don't do anything if we are going to make another pass. */
1656 if (need_pass_2)
1657 return;
1658
5ac34ac3 1659 op = exp->X_op;
40324362 1660
80aab579
ILT
1661 /* Handle a negative bignum. */
1662 if (op == O_uminus
1663 && exp->X_add_number == 0
1664 && exp->X_add_symbol->sy_value.X_op == O_big
1665 && exp->X_add_symbol->sy_value.X_add_number > 0)
1666 {
1667 int i;
1668 unsigned long carry;
1669
1670 exp = &exp->X_add_symbol->sy_value;
1671
1672 /* Negate the bignum: one's complement each digit and add 1. */
1673 carry = 1;
1674 for (i = 0; i < exp->X_add_number; i++)
1675 {
1676 unsigned long next;
1677
1678 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
1679 & LITTLENUM_MASK)
1680 + carry);
1681 generic_bignum[i] = next & LITTLENUM_MASK;
1682 carry = next >> LITTLENUM_NUMBER_OF_BITS;
1683 }
1684
1685 /* We can ignore any carry out, because it will be handled by
1686 extra_digit if it is needed. */
1687
1688 extra_digit = (valueT) -1;
1689 op = O_big;
1690 }
1691
5ac34ac3 1692 if (op == O_absent || op == O_illegal)
6efd877d 1693 {
5ac34ac3
ILT
1694 as_warn ("zero assumed for missing expression");
1695 exp->X_add_number = 0;
1696 op = O_constant;
6efd877d 1697 }
80aab579 1698 else if (op == O_big && exp->X_add_number <= 0)
6efd877d 1699 {
80aab579 1700 as_bad ("floating point number invalid; zero assumed");
40324362 1701 exp->X_add_number = 0;
5ac34ac3 1702 op = O_constant;
40324362 1703 }
5ac34ac3 1704 else if (op == O_register)
6efd877d 1705 {
5ac34ac3
ILT
1706 as_warn ("register value used as expression");
1707 op = O_constant;
40324362 1708 }
6efd877d 1709
604633ae 1710 p = frag_more ((int) nbytes);
6efd877d 1711
40324362
KR
1712#ifndef WORKING_DOT_WORD
1713 /* If we have the difference of two symbols in a word, save it on
1714 the broken_words list. See the code in write.c. */
5ac34ac3 1715 if (op == O_subtract && nbytes == 2)
40324362
KR
1716 {
1717 struct broken_word *x;
1718
1719 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1720 x->next_broken_word = broken_words;
1721 broken_words = x;
1722 x->frag = frag_now;
1723 x->word_goes_here = p;
1724 x->dispfrag = 0;
1725 x->add = exp->X_add_symbol;
5ac34ac3 1726 x->sub = exp->X_op_symbol;
40324362
KR
1727 x->addnum = exp->X_add_number;
1728 x->added = 0;
1729 new_broken_words++;
1730 return;
1731 }
f8701a3f 1732#endif
6efd877d 1733
80aab579
ILT
1734 /* If we have an integer, but the number of bytes is too large to
1735 pass to md_number_to_chars, handle it as a bignum. */
1736 if (op == O_constant && nbytes > sizeof (valueT))
1737 {
1738 valueT val;
1739 int gencnt;
1740
1741 if (! exp->X_unsigned && exp->X_add_number < 0)
1742 extra_digit = (valueT) -1;
1743 val = (valueT) exp->X_add_number;
1744 gencnt = 0;
1745 do
1746 {
1747 generic_bignum[gencnt] = val & LITTLENUM_MASK;
1748 val >>= LITTLENUM_NUMBER_OF_BITS;
1749 ++gencnt;
1750 }
1751 while (val != 0);
1752 op = exp->X_op = O_big;
1753 exp->X_add_number = gencnt;
1754 }
1755
5ac34ac3 1756 if (op == O_constant)
40324362 1757 {
44ce2f32
DE
1758 register valueT get;
1759 register valueT use;
1760 register valueT mask;
1761 register valueT unmask;
40324362
KR
1762
1763 /* JF << of >= number of bits in the object is undefined. In
1764 particular SPARC (Sun 4) has problems */
44ce2f32 1765 if (nbytes >= sizeof (valueT))
40324362
KR
1766 mask = 0;
1767 else
d2550c72 1768 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
6efd877d 1769
40324362 1770 unmask = ~mask; /* Do store these bits. */
6efd877d 1771
40324362
KR
1772#ifdef NEVER
1773 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1774 mask = ~(unmask >> 1); /* Includes sign bit now. */
1775#endif
6efd877d 1776
40324362
KR
1777 get = exp->X_add_number;
1778 use = get & unmask;
1779 if ((get & mask) != 0 && (get & mask) != mask)
1780 { /* Leading bits contain both 0s & 1s. */
58d4951d 1781 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
40324362 1782 }
604633ae 1783 /* put bytes in right order. */
44ce2f32 1784 md_number_to_chars (p, use, (int) nbytes);
40324362 1785 }
80aab579
ILT
1786 else if (op == O_big)
1787 {
1788 int size;
1789 LITTLENUM_TYPE *nums;
1790
1791 know (nbytes % CHARS_PER_LITTLENUM == 0);
1792
1793 size = exp->X_add_number * CHARS_PER_LITTLENUM;
1794 if (nbytes < size)
1795 {
1796 as_warn ("Bignum truncated to %d bytes", nbytes);
1797 size = nbytes;
1798 }
1799
1800 if (target_big_endian)
1801 {
1802 while (nbytes > size)
1803 {
1804 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1805 nbytes -= CHARS_PER_LITTLENUM;
1806 p += CHARS_PER_LITTLENUM;
1807 }
1808
1809 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
1810 while (size > 0)
1811 {
1812 --nums;
1813 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1814 size -= CHARS_PER_LITTLENUM;
1815 p += CHARS_PER_LITTLENUM;
1816 }
1817 }
1818 else
1819 {
1820 nums = generic_bignum;
1821 while (size > 0)
1822 {
1823 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1824 ++nums;
1825 size -= CHARS_PER_LITTLENUM;
1826 p += CHARS_PER_LITTLENUM;
1827 nbytes -= CHARS_PER_LITTLENUM;
1828 }
1829
1830 while (nbytes > 0)
1831 {
1832 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1833 nbytes -= CHARS_PER_LITTLENUM;
1834 p += CHARS_PER_LITTLENUM;
1835 }
1836 }
1837 }
40324362
KR
1838 else
1839 {
604633ae 1840 md_number_to_chars (p, (valueT) 0, (int) nbytes);
6efd877d 1841
40324362
KR
1842 /* Now we need to generate a fixS to record the symbol value.
1843 This is easy for BFD. For other targets it can be more
1844 complex. For very complex cases (currently, the HPPA and
1845 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1846 want. For simpler cases, you can define TC_CONS_RELOC to be
1847 the name of the reloc code that should be stored in the fixS.
1848 If neither is defined, the code uses NO_RELOC if it is
1849 defined, and otherwise uses 0. */
6efd877d 1850
40324362 1851#ifdef BFD_ASSEMBLER
4064305e
SS
1852#ifdef TC_CONS_FIX_NEW
1853 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1854#else
604633ae 1855 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 1856 /* @@ Should look at CPU word size. */
ba71c54d
KR
1857 nbytes == 2 ? BFD_RELOC_16
1858 : nbytes == 8 ? BFD_RELOC_64
1859 : BFD_RELOC_32);
4064305e 1860#endif
40324362
KR
1861#else
1862#ifdef TC_CONS_FIX_NEW
1863 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1864#else
1865 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1866 it is defined, otherwise use NO_RELOC if it is defined,
1867 otherwise use 0. */
1868#ifndef TC_CONS_RELOC
1869#ifdef NO_RELOC
1870#define TC_CONS_RELOC NO_RELOC
1871#else
1872#define TC_CONS_RELOC 0
1873#endif
1874#endif
80aab579 1875 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 1876 TC_CONS_RELOC);
40324362
KR
1877#endif /* TC_CONS_FIX_NEW */
1878#endif /* BFD_ASSEMBLER */
1879 }
1880}
1881\f
1882#ifdef BITFIELD_CONS_EXPRESSIONS
6efd877d 1883
40324362
KR
1884/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1885 w:x,y:z, where w and y are bitwidths and x and y are values. They
1886 then pack them all together. We do a little better in that we allow
1887 them in words, longs, etc. and we'll pack them in target byte order
1888 for you.
6efd877d 1889
40324362
KR
1890 The rules are: pack least significat bit first, if a field doesn't
1891 entirely fit, put it in the next unit. Overflowing the bitfield is
1892 explicitly *not* even a warning. The bitwidth should be considered
1893 a "mask".
6efd877d 1894
40324362
KR
1895 To use this function the tc-XXX.h file should define
1896 BITFIELD_CONS_EXPRESSIONS. */
f8701a3f 1897
40324362
KR
1898static void
1899parse_bitfield_cons (exp, nbytes)
1900 expressionS *exp;
1901 unsigned int nbytes;
1902{
1903 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1904 char *hold = input_line_pointer;
f8701a3f 1905
5ac34ac3 1906 (void) expression (exp);
f8701a3f 1907
40324362
KR
1908 if (*input_line_pointer == ':')
1909 { /* bitfields */
1910 long value = 0;
f8701a3f 1911
40324362
KR
1912 for (;;)
1913 {
1914 unsigned long width;
f8701a3f 1915
40324362
KR
1916 if (*input_line_pointer != ':')
1917 {
1918 input_line_pointer = hold;
1919 break;
1920 } /* next piece is not a bitfield */
1921
1922 /* In the general case, we can't allow
1923 full expressions with symbol
1924 differences and such. The relocation
1925 entries for symbols not defined in this
1926 assembly would require arbitrary field
1927 widths, positions, and masks which most
1928 of our current object formats don't
1929 support.
1930
1931 In the specific case where a symbol
1932 *is* defined in this assembly, we
1933 *could* build fixups and track it, but
1934 this could lead to confusion for the
1935 backends. I'm lazy. I'll take any
1936 SEG_ABSOLUTE. I think that means that
1937 you can use a previous .set or
1938 .equ type symbol. xoxorich. */
1939
5ac34ac3 1940 if (exp->X_op == O_absent)
6efd877d 1941 {
5ac34ac3 1942 as_warn ("using a bit field width of zero");
40324362 1943 exp->X_add_number = 0;
5ac34ac3 1944 exp->X_op = O_constant;
40324362
KR
1945 } /* implied zero width bitfield */
1946
5ac34ac3 1947 if (exp->X_op != O_constant)
6efd877d 1948 {
40324362 1949 *input_line_pointer = '\0';
5ac34ac3 1950 as_bad ("field width \"%s\" too complex for a bitfield", hold);
40324362
KR
1951 *input_line_pointer = ':';
1952 demand_empty_rest_of_line ();
1953 return;
1954 } /* too complex */
1955
1956 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
9471a360 1957 {
80aab579 1958 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
40324362
KR
1959 width, nbytes, (BITS_PER_CHAR * nbytes));
1960 width = BITS_PER_CHAR * nbytes;
1961 } /* too big */
1962
1963 if (width > bits_available)
9471a360 1964 {
40324362
KR
1965 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1966 input_line_pointer = hold;
1967 exp->X_add_number = value;
1968 break;
1969 } /* won't fit */
1970
1971 hold = ++input_line_pointer; /* skip ':' */
1972
5ac34ac3
ILT
1973 (void) expression (exp);
1974 if (exp->X_op != O_constant)
9471a360 1975 {
40324362
KR
1976 char cache = *input_line_pointer;
1977
1978 *input_line_pointer = '\0';
5ac34ac3 1979 as_bad ("field value \"%s\" too complex for a bitfield", hold);
40324362
KR
1980 *input_line_pointer = cache;
1981 demand_empty_rest_of_line ();
1982 return;
1983 } /* too complex */
1984
5ac34ac3
ILT
1985 value |= ((~(-1 << width) & exp->X_add_number)
1986 << ((BITS_PER_CHAR * nbytes) - bits_available));
40324362
KR
1987
1988 if ((bits_available -= width) == 0
1989 || is_it_end_of_statement ()
1990 || *input_line_pointer != ',')
1991 {
1992 break;
1993 } /* all the bitfields we're gonna get */
1994
1995 hold = ++input_line_pointer;
5ac34ac3 1996 (void) expression (exp);
40324362
KR
1997 } /* forever loop */
1998
1999 exp->X_add_number = value;
5ac34ac3 2000 exp->X_op = O_constant;
80aab579 2001 exp->X_unsigned = 1;
40324362
KR
2002 } /* if looks like a bitfield */
2003} /* parse_bitfield_cons() */
2004
2005#endif /* BITFIELD_CONS_EXPRESSIONS */
2006\f
2007#ifdef MRI
2008
2009static void
2010parse_mri_cons (exp, nbytes)
2011 expressionS *exp;
2012 unsigned int nbytes;
2013{
2014 if (*input_line_pointer == '\'')
2015 {
2016 /* An MRI style string, cut into as many bytes as will fit into
2017 a nbyte chunk, left justify if necessary, and separate with
2018 commas so we can try again later */
2019 int scan = 0;
2020 unsigned int result = 0;
2021 input_line_pointer++;
2022 for (scan = 0; scan < nbytes; scan++)
2023 {
2024 if (*input_line_pointer == '\'')
2025 {
2026 if (input_line_pointer[1] == '\'')
6efd877d 2027 {
40324362 2028 input_line_pointer++;
f8701a3f 2029 }
40324362
KR
2030 else
2031 break;
9471a360 2032 }
40324362
KR
2033 result = (result << 8) | (*input_line_pointer++);
2034 }
f8701a3f 2035
40324362
KR
2036 /* Left justify */
2037 while (scan < nbytes)
2038 {
2039 result <<= 8;
2040 scan++;
2041 }
2042 /* Create correct expression */
5ac34ac3 2043 exp->X_op = O_constant;
40324362 2044 exp->X_add_number = result;
40324362
KR
2045 /* Fake it so that we can read the next char too */
2046 if (input_line_pointer[0] != '\'' ||
2047 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2048 {
2049 input_line_pointer -= 2;
2050 input_line_pointer[0] = ',';
2051 input_line_pointer[1] = '\'';
2052 }
2053 else
2054 input_line_pointer++;
2055 }
2056 else
2057 expression (&exp);
2058}
2059
2060#endif /* MRI */
2061\f
2062#ifdef REPEAT_CONS_EXPRESSIONS
2063
2064/* Parse a repeat expression for cons. This is used by the MIPS
2065 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2066 object file COUNT times.
2067
2068 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2069
2070static void
2071parse_repeat_cons (exp, nbytes)
2072 expressionS *exp;
2073 unsigned int nbytes;
2074{
2075 expressionS count;
40324362
KR
2076 register int i;
2077
2078 expression (exp);
2079
2080 if (*input_line_pointer != ':')
2081 {
2082 /* No repeat count. */
2083 return;
2084 }
2085
2086 ++input_line_pointer;
5ac34ac3
ILT
2087 expression (&count);
2088 if (count.X_op != O_constant
40324362
KR
2089 || count.X_add_number <= 0)
2090 {
2091 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2092 return;
2093 }
2094
2095 /* The cons function is going to output this expression once. So we
2096 output it count - 1 times. */
2097 for (i = count.X_add_number - 1; i > 0; i--)
2098 emit_expr (exp, nbytes);
2099}
2100
2101#endif /* REPEAT_CONS_EXPRESSIONS */
fecd2382 2102\f
fecd2382
RP
2103/*
2104 * float_cons()
2105 *
2106 * CONStruct some more frag chars of .floats .ffloats etc.
2107 * Makes 0 or more new frags.
2108 * If need_pass_2 == 1, no frags are emitted.
2109 * This understands only floating literals, not expressions. Sorry.
2110 *
2111 * A floating constant is defined by atof_generic(), except it is preceded
2112 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2113 * reading, I decided to be incompatible. This always tries to give you
2114 * rounded bits to the precision of the pseudo-op. Former AS did premature
2115 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2116 * a choice of 2 flavours of noise according to which of 2 floating-point
2117 * scanners you directed AS to use.
2118 *
2119 * In: input_line_pointer->whitespace before, or '0' of flonum.
2120 *
2121 */
2122
ba71c54d
KR
2123void
2124float_cons (float_type)
6efd877d 2125 /* Clobbers input_line-pointer, checks end-of-line. */
f8701a3f 2126 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
fecd2382 2127{
6efd877d 2128 register char *p;
6efd877d
KR
2129 int length; /* Number of chars in an object. */
2130 register char *err; /* Error from scanning floating literal. */
2131 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
f8701a3f 2132
6efd877d 2133 if (is_it_end_of_statement ())
f8701a3f 2134 {
1e9cf565
ILT
2135 demand_empty_rest_of_line ();
2136 return;
f8701a3f 2137 }
1e9cf565
ILT
2138
2139 do
f8701a3f
SC
2140 {
2141 /* input_line_pointer->1st char of a flonum (we hope!). */
6efd877d 2142 SKIP_WHITESPACE ();
1e9cf565 2143
f8701a3f
SC
2144 /* Skip any 0{letter} that may be present. Don't even check if the
2145 * letter is legal. Someone may invent a "z" format and this routine
2146 * has no use for such information. Lusers beware: you get
2147 * diagnostics if your input is ill-conditioned.
2148 */
6efd877d
KR
2149 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2150 input_line_pointer += 2;
f8701a3f
SC
2151
2152 err = md_atof (float_type, temp, &length);
6efd877d
KR
2153 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2154 know (length > 0);
80aab579 2155 if (err)
f8701a3f 2156 {
6efd877d
KR
2157 as_bad ("Bad floating literal: %s", err);
2158 ignore_rest_of_line ();
1e9cf565 2159 return;
f8701a3f 2160 }
1e9cf565
ILT
2161
2162 if (!need_pass_2)
f8701a3f 2163 {
1e9cf565
ILT
2164 int count;
2165
2166 count = 1;
2167
2168#ifdef REPEAT_CONS_EXPRESSIONS
2169 if (*input_line_pointer == ':')
2170 {
1e9cf565
ILT
2171 expressionS count_exp;
2172
2173 ++input_line_pointer;
5ac34ac3
ILT
2174 expression (&count_exp);
2175 if (count_exp.X_op != O_constant
1e9cf565
ILT
2176 || count_exp.X_add_number <= 0)
2177 {
5ac34ac3 2178 as_warn ("unresolvable or nonpositive repeat count; using 1");
1e9cf565
ILT
2179 }
2180 else
2181 count = count_exp.X_add_number;
2182 }
2183#endif
2184
2185 while (--count >= 0)
a39116f1 2186 {
f8701a3f 2187 p = frag_more (length);
604633ae 2188 memcpy (p, temp, (unsigned int) length);
a39116f1 2189 }
542e1629 2190 }
1e9cf565 2191 SKIP_WHITESPACE ();
f8701a3f 2192 }
1e9cf565
ILT
2193 while (*input_line_pointer++ == ',');
2194
2195 --input_line_pointer; /* Put terminator back into stream. */
6efd877d 2196 demand_empty_rest_of_line ();
f8701a3f 2197} /* float_cons() */
fecd2382
RP
2198\f
2199/*
2200 * stringer()
2201 *
2202 * We read 0 or more ',' seperated, double-quoted strings.
2203 *
2204 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2205 */
a39116f1
RP
2206
2207
6efd877d
KR
2208void
2209stringer (append_zero) /* Worker to do .ascii etc statements. */
2210 /* Checks end-of-line. */
f8701a3f 2211 register int append_zero; /* 0: don't append '\0', else 1 */
fecd2382 2212{
f8701a3f 2213 register unsigned int c;
6efd877d 2214
f8701a3f
SC
2215 /*
2216 * The following awkward logic is to parse ZERO or more strings,
2217 * comma seperated. Recall a string expression includes spaces
2218 * before the opening '\"' and spaces after the closing '\"'.
2219 * We fake a leading ',' if there is (supposed to be)
2220 * a 1st, expression. We keep demanding expressions for each
2221 * ','.
2222 */
6efd877d
KR
2223 if (is_it_end_of_statement ())
2224 {
2225 c = 0; /* Skip loop. */
2226 ++input_line_pointer; /* Compensate for end of loop. */
2227 }
f8701a3f 2228 else
6efd877d
KR
2229 {
2230 c = ','; /* Do loop. */
2231 }
2232 while (c == ',' || c == '<' || c == '"')
2233 {
2234 SKIP_WHITESPACE ();
2235 switch (*input_line_pointer)
2236 {
2237 case '\"':
2238 ++input_line_pointer; /*->1st char of string. */
2239 while (is_a_char (c = next_char_of_string ()))
2240 {
2241 FRAG_APPEND_1_CHAR (c);
2242 }
2243 if (append_zero)
2244 {
2245 FRAG_APPEND_1_CHAR (0);
2246 }
2247 know (input_line_pointer[-1] == '\"');
2248 break;
2249 case '<':
2250 input_line_pointer++;
2251 c = get_single_number ();
2252 FRAG_APPEND_1_CHAR (c);
2253 if (*input_line_pointer != '>')
2254 {
2255 as_bad ("Expected <nn>");
2256 }
2257 input_line_pointer++;
2258 break;
2259 case ',':
2260 input_line_pointer++;
2261 break;
2262 }
2263 SKIP_WHITESPACE ();
2264 c = *input_line_pointer;
f8701a3f 2265 }
f8701a3f 2266
6efd877d
KR
2267 demand_empty_rest_of_line ();
2268} /* stringer() */
fecd2382 2269\f
6efd877d 2270/* FIXME-SOMEDAY: I had trouble here on characters with the
f8701a3f
SC
2271 high bits set. We'll probably also have trouble with
2272 multibyte chars, wide chars, etc. Also be careful about
2273 returning values bigger than 1 byte. xoxorich. */
fecd2382 2274
6efd877d
KR
2275unsigned int
2276next_char_of_string ()
2277{
2278 register unsigned int c;
2279
2280 c = *input_line_pointer++ & CHAR_MASK;
2281 switch (c)
2282 {
2283 case '\"':
2284 c = NOT_A_CHAR;
2285 break;
2286
ddb393cf 2287#ifndef NO_STRING_ESCAPES
6efd877d
KR
2288 case '\\':
2289 switch (c = *input_line_pointer++)
2290 {
2291 case 'b':
2292 c = '\b';
2293 break;
2294
2295 case 'f':
2296 c = '\f';
2297 break;
2298
2299 case 'n':
2300 c = '\n';
2301 break;
2302
2303 case 'r':
2304 c = '\r';
2305 break;
2306
2307 case 't':
2308 c = '\t';
2309 break;
2310
fecd2382 2311#ifdef BACKSLASH_V
6efd877d
KR
2312 case 'v':
2313 c = '\013';
2314 break;
fecd2382 2315#endif
6efd877d
KR
2316
2317 case '\\':
2318 case '"':
2319 break; /* As itself. */
2320
2321 case '0':
2322 case '1':
2323 case '2':
2324 case '3':
2325 case '4':
2326 case '5':
2327 case '6':
2328 case '7':
2329 case '8':
2330 case '9':
2331 {
2332 long number;
d4c8cbd8 2333 int i;
6efd877d 2334
d4c8cbd8 2335 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
6efd877d
KR
2336 {
2337 number = number * 8 + c - '0';
2338 }
2339 c = number & 0xff;
2340 }
2341 --input_line_pointer;
2342 break;
2343
d4c8cbd8
JL
2344 case 'x':
2345 case 'X':
2346 {
2347 long number;
2348
2349 number = 0;
2350 c = *input_line_pointer++;
2351 while (isxdigit (c))
2352 {
2353 if (isdigit (c))
2354 number = number * 16 + c - '0';
2355 else if (isupper (c))
2356 number = number * 16 + c - 'A' + 10;
2357 else
2358 number = number * 16 + c - 'a' + 10;
2359 c = *input_line_pointer++;
2360 }
2361 c = number & 0xff;
2362 --input_line_pointer;
2363 }
2364 break;
2365
6efd877d
KR
2366 case '\n':
2367 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2368 as_warn ("Unterminated string: Newline inserted.");
2369 c = '\n';
2370 break;
2371
2372 default:
2373
fecd2382 2374#ifdef ONLY_STANDARD_ESCAPES
6efd877d
KR
2375 as_bad ("Bad escaped character in string, '?' assumed");
2376 c = '?';
fecd2382 2377#endif /* ONLY_STANDARD_ESCAPES */
6efd877d
KR
2378
2379 break;
2380 } /* switch on escaped char */
2381 break;
ddb393cf 2382#endif /* ! defined (NO_STRING_ESCAPES) */
6efd877d
KR
2383
2384 default:
2385 break;
2386 } /* switch on char */
2387 return (c);
2388} /* next_char_of_string() */
fecd2382
RP
2389\f
2390static segT
f8701a3f 2391get_segmented_expression (expP)
6efd877d 2392 register expressionS *expP;
fecd2382 2393{
6efd877d 2394 register segT retval;
f8701a3f 2395
9471a360 2396 retval = expression (expP);
5ac34ac3
ILT
2397 if (expP->X_op == O_illegal
2398 || expP->X_op == O_absent
2399 || expP->X_op == O_big)
f8701a3f 2400 {
5ac34ac3
ILT
2401 as_bad ("expected address expression; zero assumed");
2402 expP->X_op = O_constant;
6efd877d 2403 expP->X_add_number = 0;
5ac34ac3 2404 retval = absolute_section;
f8701a3f 2405 }
5ac34ac3 2406 return retval;
fecd2382
RP
2407}
2408
6efd877d
KR
2409static segT
2410get_known_segmented_expression (expP)
2411 register expressionS *expP;
fecd2382 2412{
6efd877d 2413 register segT retval;
f8701a3f 2414
9471a360 2415 if ((retval = get_segmented_expression (expP)) == undefined_section)
f8701a3f 2416 {
5ac34ac3
ILT
2417 /* There is no easy way to extract the undefined symbol from the
2418 expression. */
2419 if (expP->X_add_symbol != NULL
2420 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2421 as_warn ("symbol \"%s\" undefined; zero assumed",
2422 S_GET_NAME (expP->X_add_symbol));
f8701a3f 2423 else
5ac34ac3
ILT
2424 as_warn ("some symbol undefined; zero assumed");
2425 retval = absolute_section;
2426 expP->X_op = O_constant;
6efd877d 2427 expP->X_add_number = 0;
f8701a3f 2428 }
5ac34ac3 2429 know (retval == absolute_section || SEG_NORMAL (retval));
f8701a3f 2430 return (retval);
fecd2382
RP
2431} /* get_known_segmented_expression() */
2432
58d4951d 2433offsetT
f8701a3f 2434get_absolute_expression ()
fecd2382 2435{
6efd877d 2436 expressionS exp;
f8701a3f 2437
5ac34ac3
ILT
2438 expression (&exp);
2439 if (exp.X_op != O_constant)
f8701a3f 2440 {
5ac34ac3
ILT
2441 if (exp.X_op != O_absent)
2442 as_bad ("bad absolute expression; zero assumed");
6efd877d 2443 exp.X_add_number = 0;
f8701a3f 2444 }
5ac34ac3 2445 return exp.X_add_number;
fecd2382
RP
2446}
2447
6efd877d
KR
2448char /* return terminator */
2449get_absolute_expression_and_terminator (val_pointer)
2450 long *val_pointer; /* return value of expression */
fecd2382 2451{
58d4951d
ILT
2452 /* FIXME: val_pointer should probably be offsetT *. */
2453 *val_pointer = (long) get_absolute_expression ();
6efd877d 2454 return (*input_line_pointer++);
fecd2382
RP
2455}
2456\f
2457/*
2458 * demand_copy_C_string()
2459 *
2460 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2461 * Give a warning if that happens.
2462 */
2463char *
f8701a3f 2464demand_copy_C_string (len_pointer)
6efd877d 2465 int *len_pointer;
fecd2382 2466{
6efd877d 2467 register char *s;
f8701a3f 2468
6efd877d 2469 if ((s = demand_copy_string (len_pointer)) != 0)
f8701a3f
SC
2470 {
2471 register int len;
2472
6efd877d 2473 for (len = *len_pointer;
f8701a3f
SC
2474 len > 0;
2475 len--)
2476 {
6efd877d 2477 if (*s == 0)
fecd2382 2478 {
f8701a3f
SC
2479 s = 0;
2480 len = 1;
6efd877d
KR
2481 *len_pointer = 0;
2482 as_bad ("This string may not contain \'\\0\'");
fecd2382 2483 }
f8701a3f
SC
2484 }
2485 }
2486 return (s);
fecd2382
RP
2487}
2488\f
2489/*
2490 * demand_copy_string()
2491 *
2492 * Demand string, but return a safe (=private) copy of the string.
2493 * Return NULL if we can't read a string here.
2494 */
6efd877d
KR
2495static char *
2496demand_copy_string (lenP)
2497 int *lenP;
fecd2382 2498{
6efd877d
KR
2499 register unsigned int c;
2500 register int len;
2501 char *retval;
2502
2503 len = 0;
2504 SKIP_WHITESPACE ();
2505 if (*input_line_pointer == '\"')
2506 {
2507 input_line_pointer++; /* Skip opening quote. */
2508
2509 while (is_a_char (c = next_char_of_string ()))
2510 {
2511 obstack_1grow (&notes, c);
2512 len++;
fecd2382 2513 }
6efd877d
KR
2514 /* JF this next line is so demand_copy_C_string will return a null
2515 termanated string. */
2516 obstack_1grow (&notes, '\0');
2517 retval = obstack_finish (&notes);
2518 }
2519 else
2520 {
2521 as_warn ("Missing string");
2522 retval = NULL;
2523 ignore_rest_of_line ();
2524 }
2525 *lenP = len;
2526 return (retval);
2527} /* demand_copy_string() */
fecd2382
RP
2528\f
2529/*
2530 * is_it_end_of_statement()
2531 *
2532 * In: Input_line_pointer->next character.
2533 *
2534 * Do: Skip input_line_pointer over all whitespace.
2535 *
2536 * Out: 1 if input_line_pointer->end-of-line.
f8701a3f 2537*/
6efd877d
KR
2538int
2539is_it_end_of_statement ()
2540{
2541 SKIP_WHITESPACE ();
58d4951d 2542 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6efd877d 2543} /* is_it_end_of_statement() */
fecd2382 2544
6efd877d
KR
2545void
2546equals (sym_name)
2547 char *sym_name;
fecd2382 2548{
6efd877d 2549 register symbolS *symbolP; /* symbol we are working with */
f8701a3f
SC
2550
2551 input_line_pointer++;
6efd877d 2552 if (*input_line_pointer == '=')
f8701a3f
SC
2553 input_line_pointer++;
2554
6efd877d 2555 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
f8701a3f
SC
2556 input_line_pointer++;
2557
6efd877d
KR
2558 if (sym_name[0] == '.' && sym_name[1] == '\0')
2559 {
2560 /* Turn '. = mumble' into a .org mumble */
2561 register segT segment;
2562 expressionS exp;
2563 register char *p;
f8701a3f 2564
6efd877d
KR
2565 segment = get_known_segmented_expression (&exp);
2566 if (!need_pass_2)
2567 {
9471a360 2568 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
2569 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2570 segment_name (segment),
2571 segment_name (now_seg));
2572 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2573 exp.X_add_number, (char *) 0);
2574 *p = 0;
2575 } /* if (ok to make frag) */
2576 }
2577 else
2578 {
2579 symbolP = symbol_find_or_make (sym_name);
2580 pseudo_set (symbolP);
2581 }
2582} /* equals() */
fecd2382
RP
2583
2584/* .include -- include a file at this point. */
2585
2586/* ARGSUSED */
6efd877d
KR
2587void
2588s_include (arg)
2589 int arg;
fecd2382 2590{
f8701a3f
SC
2591 char *newbuf;
2592 char *filename;
2593 int i;
2594 FILE *try;
2595 char *path;
2596
6efd877d
KR
2597 filename = demand_copy_string (&i);
2598 demand_empty_rest_of_line ();
604633ae 2599 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
6efd877d
KR
2600 for (i = 0; i < include_dir_count; i++)
2601 {
2602 strcpy (path, include_dirs[i]);
2603 strcat (path, "/");
2604 strcat (path, filename);
30d3a445 2605 if (0 != (try = fopen (path, FOPEN_RT)))
6efd877d
KR
2606 {
2607 fclose (try);
2608 goto gotit;
2609 }
2610 }
2611 free (path);
f8701a3f
SC
2612 path = filename;
2613gotit:
2614 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2615 newbuf = input_scrub_include_file (path, input_line_pointer);
2616 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6efd877d 2617} /* s_include() */
fecd2382 2618
6efd877d
KR
2619void
2620add_include_dir (path)
2621 char *path;
fecd2382 2622{
f8701a3f
SC
2623 int i;
2624
2625 if (include_dir_count == 0)
2626 {
6efd877d 2627 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
f8701a3f
SC
2628 include_dirs[0] = "."; /* Current dir */
2629 include_dir_count = 2;
2630 }
2631 else
2632 {
2633 include_dir_count++;
6efd877d
KR
2634 include_dirs = (char **) realloc (include_dirs,
2635 include_dir_count * sizeof (*include_dirs));
f8701a3f
SC
2636 }
2637
6efd877d 2638 include_dirs[include_dir_count - 1] = path; /* New one */
f8701a3f 2639
6efd877d
KR
2640 i = strlen (path);
2641 if (i > include_dir_maxlen)
2642 include_dir_maxlen = i;
2643} /* add_include_dir() */
fecd2382 2644
6efd877d
KR
2645void
2646s_ignore (arg)
2647 int arg;
fecd2382 2648{
58d4951d 2649 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
2650 {
2651 ++input_line_pointer;
2652 }
2653 ++input_line_pointer;
4064305e
SS
2654}
2655
604633ae 2656
fecd2382 2657/* end of read.c */
This page took 0.274338 seconds and 4 git commands to generate.