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