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