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