* mpw-make.sed: If linking, edit ALL_CFLAGS to CFLAGS.
[deliverable/binutils-gdb.git] / gas / read.c
1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #if 0
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
26 */
27 #else
28 #define MASK_CHAR ((int)(unsigned char)-1)
29 #endif
30
31
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
34
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
36
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
39
40 /* for isdigit() */
41 #include <ctype.h>
42
43 #include "as.h"
44 #include "subsegs.h"
45 #include "sb.h"
46 #include "macro.h"
47 #include "libiberty.h"
48 #include "obstack.h"
49 #include "listing.h"
50
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
53 #endif
54
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
63 char *input_line_pointer; /*->next char of source file to parse. */
64
65 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
66
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
70 die horribly;
71 #endif
72
73 #ifndef LEX_AT
74 /* The m88k unfortunately uses @ as a label beginner. */
75 #define LEX_AT 0
76 #endif
77
78 #ifndef LEX_BR
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
80 #define LEX_BR 0
81 #endif
82
83 #ifndef LEX_PCT
84 /* The Delta 68k assembler permits % inside label names. */
85 #define LEX_PCT 0
86 #endif
87
88 #ifndef LEX_QM
89 /* The PowerPC Windows NT assemblers permits ? inside label names. */
90 #define LEX_QM 0
91 #endif
92
93 #ifndef LEX_DOLLAR
94 /* The a29k assembler does not permits labels to start with $. */
95 #define LEX_DOLLAR 3
96 #endif
97
98 /* used by is_... macros. our ctype[] */
99 char lex_type[256] =
100 {
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
103 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
104 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
105 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
106 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
107 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
108 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 };
117
118
119 /*
120 * In: a character.
121 * Out: 1 if this character ends a line.
122 */
123 #define _ (0)
124 char is_end_of_line[256] =
125 {
126 #ifdef CR_EOL
127 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
128 #else
129 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
130 #endif
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 #ifdef TC_HPPA
133 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
135 #else
136 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
138 #endif
139 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
141 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
142 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
143 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
144 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
148 };
149 #undef _
150
151 /* Functions private to this file. */
152
153 static char *buffer; /* 1st char of each buffer of lines is here. */
154 static char *buffer_limit; /*->1 + last char in buffer. */
155
156 #ifdef TARGET_BYTES_BIG_ENDIAN
157 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
158 instead of to 0 or 1. */
159 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
160 #undef TARGET_BYTES_BIG_ENDIAN
161 #define TARGET_BYTES_BIG_ENDIAN 1
162 #endif
163 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
164 #else
165 int target_big_endian /* = 0 */;
166 #endif
167
168 static char *old_buffer; /* JF a hack */
169 static char *old_input;
170 static char *old_limit;
171
172 /* Variables for handling include file directory list. */
173
174 char **include_dirs; /* List of pointers to directories to
175 search for .include's */
176 int include_dir_count; /* How many are in the list */
177 int include_dir_maxlen = 1;/* Length of longest in list */
178
179 #ifndef WORKING_DOT_WORD
180 struct broken_word *broken_words;
181 int new_broken_words;
182 #endif
183
184 /* The current offset into the absolute section. We don't try to
185 build frags in the absolute section, since no data can be stored
186 there. We just keep track of the current offset. */
187 addressT abs_section_offset;
188
189 /* If this line had an MRI style label, it is stored in this variable.
190 This is used by some of the MRI pseudo-ops. */
191 symbolS *line_label;
192
193 /* This global variable is used to support MRI common sections. We
194 translate such sections into a common symbol. This variable is
195 non-NULL when we are in an MRI common section. */
196 symbolS *mri_common_symbol;
197
198 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
199 need to align to an even byte boundary unless the next pseudo-op is
200 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
201 may be needed. */
202 static int mri_pending_align;
203
204 static int scrub_from_string PARAMS ((char **));
205 static void do_align PARAMS ((int, char *));
206 static int hex_float PARAMS ((int, char *));
207 static void do_org PARAMS ((segT, expressionS *, int));
208 char *demand_copy_string PARAMS ((int *lenP));
209 int is_it_end_of_statement PARAMS ((void));
210 static segT get_segmented_expression PARAMS ((expressionS *expP));
211 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
212 static void pobegin PARAMS ((void));
213 static int get_line_sb PARAMS ((sb *));
214 \f
215
216 void
217 read_begin ()
218 {
219 const char *p;
220
221 pobegin ();
222 obj_read_begin_hook ();
223
224 /* Something close -- but not too close -- to a multiple of 1024.
225 The debugging malloc I'm using has 24 bytes of overhead. */
226 obstack_begin (&notes, chunksize);
227 obstack_begin (&cond_obstack, chunksize);
228
229 /* Use machine dependent syntax */
230 for (p = line_separator_chars; *p; p++)
231 is_end_of_line[(unsigned char) *p] = 1;
232 /* Use more. FIXME-SOMEDAY. */
233
234 if (flag_mri)
235 lex_type['?'] = 3;
236 }
237 \f
238 /* set up pseudo-op tables */
239
240 static struct hash_control *po_hash;
241
242 static const pseudo_typeS potable[] =
243 {
244 {"abort", s_abort, 0},
245 {"align", s_align_ptwo, 0},
246 {"ascii", stringer, 0},
247 {"asciz", stringer, 1},
248 {"balign", s_align_bytes, 0},
249 /* block */
250 {"byte", cons, 1},
251 {"comm", s_comm, 0},
252 {"common", s_mri_common, 0},
253 {"common.s", s_mri_common, 1},
254 {"data", s_data, 0},
255 {"dc", cons, 2},
256 {"dc.b", cons, 1},
257 {"dc.d", float_cons, 'd'},
258 {"dc.l", cons, 4},
259 {"dc.s", float_cons, 'f'},
260 {"dc.w", cons, 2},
261 {"dc.x", float_cons, 'x'},
262 {"dcb", s_space, 2},
263 {"dcb.b", s_space, 1},
264 {"dcb.d", s_float_space, 'd'},
265 {"dcb.l", s_space, 4},
266 {"dcb.s", s_float_space, 'f'},
267 {"dcb.w", s_space, 2},
268 {"dcb.x", s_float_space, 'x'},
269 {"ds", s_space, 2},
270 {"ds.b", s_space, 1},
271 {"ds.d", s_space, 8},
272 {"ds.l", s_space, 4},
273 {"ds.p", s_space, 12},
274 {"ds.s", s_space, 4},
275 {"ds.w", s_space, 2},
276 {"ds.x", s_space, 12},
277 {"debug", s_ignore, 0},
278 #ifdef S_SET_DESC
279 {"desc", s_desc, 0},
280 #endif
281 /* dim */
282 {"double", float_cons, 'd'},
283 /* dsect */
284 {"eject", listing_eject, 0}, /* Formfeed listing */
285 {"else", s_else, 0},
286 {"elsec", s_else, 0},
287 {"end", s_end, 0},
288 {"endc", s_endif, 0},
289 {"endif", s_endif, 0},
290 /* endef */
291 {"equ", s_set, 0},
292 {"err", s_err, 0},
293 {"exitm", s_mexit, 0},
294 /* extend */
295 {"extern", s_ignore, 0}, /* We treat all undef as ext */
296 {"appfile", s_app_file, 1},
297 {"appline", s_app_line, 0},
298 {"fail", s_fail, 0},
299 {"file", s_app_file, 0},
300 {"fill", s_fill, 0},
301 {"float", float_cons, 'f'},
302 {"format", s_ignore, 0},
303 {"global", s_globl, 0},
304 {"globl", s_globl, 0},
305 {"hword", cons, 2},
306 {"if", s_if, (int) O_ne},
307 {"ifc", s_ifc, 0},
308 {"ifdef", s_ifdef, 0},
309 {"ifeq", s_if, (int) O_eq},
310 {"ifeqs", s_ifeqs, 0},
311 {"ifge", s_if, (int) O_ge},
312 {"ifgt", s_if, (int) O_gt},
313 {"ifle", s_if, (int) O_le},
314 {"iflt", s_if, (int) O_lt},
315 {"ifnc", s_ifc, 1},
316 {"ifndef", s_ifdef, 1},
317 {"ifne", s_if, (int) O_ne},
318 {"ifnes", s_ifeqs, 1},
319 {"ifnotdef", s_ifdef, 1},
320 {"include", s_include, 0},
321 {"int", cons, 4},
322 {"irp", s_irp, 0},
323 {"irep", s_irp, 0},
324 {"irpc", s_irp, 1},
325 {"irepc", s_irp, 1},
326 {"lcomm", s_lcomm, 0},
327 {"lflags", listing_flags, 0}, /* Listing flags */
328 {"list", listing_list, 1}, /* Turn listing on */
329 {"llen", listing_psize, 1},
330 {"long", cons, 4},
331 {"lsym", s_lsym, 0},
332 {"macro", s_macro, 0},
333 {"mexit", s_mexit, 0},
334 {"noformat", s_ignore, 0},
335 {"nolist", listing_list, 0}, /* Turn listing off */
336 {"nopage", listing_nopage, 0},
337 {"octa", cons, 16},
338 {"offset", s_struct, 0},
339 {"org", s_org, 0},
340 {"p2align", s_align_ptwo, 0},
341 {"page", listing_eject, 0},
342 {"plen", listing_psize, 0},
343 {"print", s_print, 0},
344 {"psize", listing_psize, 0}, /* set paper size */
345 {"purgem", s_purgem, 0},
346 {"quad", cons, 8},
347 {"rep", s_rept, 0},
348 {"rept", s_rept, 0},
349 {"rva", s_rva, 4},
350 {"sbttl", listing_title, 1}, /* Subtitle of listing */
351 /* scl */
352 /* sect */
353 {"set", s_set, 0},
354 {"short", cons, 2},
355 {"single", float_cons, 'f'},
356 /* size */
357 {"space", s_space, 0},
358 {"spc", s_ignore, 0},
359 {"stabd", s_stab, 'd'},
360 {"stabn", s_stab, 'n'},
361 {"stabs", s_stab, 's'},
362 {"string", stringer, 1},
363 {"struct", s_struct, 0},
364 /* tag */
365 {"text", s_text, 0},
366
367 /* This is for gcc to use. It's only just been added (2/94), so gcc
368 won't be able to use it for a while -- probably a year or more.
369 But once this has been released, check with gcc maintainers
370 before deleting it or even changing the spelling. */
371 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
372 /* If we're folding case -- done for some targets, not necessarily
373 all -- the above string in an input file will be converted to
374 this one. Match it either way... */
375 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
376
377 {"title", listing_title, 0}, /* Listing title */
378 {"ttl", listing_title, 0},
379 /* type */
380 /* use */
381 /* val */
382 {"xcom", s_comm, 0},
383 {"xdef", s_globl, 0},
384 {"xref", s_ignore, 0},
385 {"xstabs", s_xstab, 's'},
386 {"word", cons, 2},
387 {"zero", s_space, 0},
388 {NULL} /* end sentinel */
389 };
390
391 static int pop_override_ok = 0;
392 static const char *pop_table_name;
393
394 void
395 pop_insert (table)
396 const pseudo_typeS *table;
397 {
398 const char *errtxt;
399 const pseudo_typeS *pop;
400 for (pop = table; pop->poc_name; pop++)
401 {
402 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
403 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
404 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
405 errtxt);
406 }
407 }
408
409 #ifndef md_pop_insert
410 #define md_pop_insert() pop_insert(md_pseudo_table)
411 #endif
412
413 #ifndef obj_pop_insert
414 #define obj_pop_insert() pop_insert(obj_pseudo_table)
415 #endif
416
417 static void
418 pobegin ()
419 {
420 po_hash = hash_new ();
421
422 /* Do the target-specific pseudo ops. */
423 pop_table_name = "md";
424 md_pop_insert ();
425
426 /* Now object specific. Skip any that were in the target table. */
427 pop_table_name = "obj";
428 pop_override_ok = 1;
429 obj_pop_insert ();
430
431 /* Now portable ones. Skip any that we've seen already. */
432 pop_table_name = "standard";
433 pop_insert (potable);
434 }
435 \f
436 #define HANDLE_CONDITIONAL_ASSEMBLY() \
437 if (ignore_input ()) \
438 { \
439 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
440 if (input_line_pointer == buffer_limit) \
441 break; \
442 continue; \
443 }
444
445
446 /* This function is used when scrubbing the characters between #APP
447 and #NO_APP. */
448
449 static char *scrub_string;
450 static char *scrub_string_end;
451
452 static int
453 scrub_from_string (from)
454 char **from;
455 {
456 int size;
457
458 *from = scrub_string;
459 size = scrub_string_end - scrub_string;
460 scrub_string = scrub_string_end;
461 return size;
462 }
463
464 /* read_a_source_file()
465 *
466 * We read the file, putting things into a web that
467 * represents what we have been reading.
468 */
469 void
470 read_a_source_file (name)
471 char *name;
472 {
473 register char c;
474 register char *s; /* string of symbol, '\0' appended */
475 register int temp;
476 pseudo_typeS *pop;
477
478 buffer = input_scrub_new_file (name);
479
480 listing_file (name);
481 listing_newline ("");
482
483 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
484 { /* We have another line to parse. */
485 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
486 contin: /* JF this goto is my fault I admit it.
487 Someone brave please re-write the whole
488 input section here? Pleeze??? */
489 while (input_line_pointer < buffer_limit)
490 {
491 /* We have more of this buffer to parse. */
492
493 /*
494 * We now have input_line_pointer->1st char of next line.
495 * If input_line_pointer [-1] == '\n' then we just
496 * scanned another line: so bump line counters.
497 */
498 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
499 {
500 #ifdef md_start_line_hook
501 md_start_line_hook ();
502 #endif
503
504 if (input_line_pointer[-1] == '\n')
505 bump_line_counters ();
506
507 line_label = NULL;
508
509 if (flag_mri
510 #ifdef LABELS_WITHOUT_COLONS
511 || 1
512 #endif
513 )
514 {
515 /* Text at the start of a line must be a label, we
516 run down and stick a colon in. */
517 if (is_name_beginner (*input_line_pointer))
518 {
519 char *line_start = input_line_pointer;
520 char c;
521
522 HANDLE_CONDITIONAL_ASSEMBLY ();
523
524 c = get_symbol_end ();
525
526 /* In MRI mode, the EQU pseudoop must be
527 handled specially. */
528 if (flag_mri)
529 {
530 char *rest = input_line_pointer + 1;
531
532 if (*rest == ':')
533 ++rest;
534 if (*rest == ' ' || *rest == '\t')
535 ++rest;
536 if ((strncasecmp (rest, "EQU", 3) == 0
537 || strncasecmp (rest, "SET", 3) == 0)
538 && (rest[3] == ' ' || rest[3] == '\t'))
539 {
540 input_line_pointer = rest + 3;
541 equals (line_start);
542 continue;
543 }
544 }
545
546 line_label = colon (line_start);
547
548 *input_line_pointer = c;
549 if (c == ':')
550 input_line_pointer++;
551 }
552 }
553 }
554
555 /*
556 * We are at the begining of a line, or similar place.
557 * We expect a well-formed assembler statement.
558 * A "symbol-name:" is a statement.
559 *
560 * Depending on what compiler is used, the order of these tests
561 * may vary to catch most common case 1st.
562 * Each test is independent of all other tests at the (top) level.
563 * PLEASE make a compiler that doesn't use this assembler.
564 * It is crufty to waste a compiler's time encoding things for this
565 * assembler, which then wastes more time decoding it.
566 * (And communicating via (linear) files is silly!
567 * If you must pass stuff, please pass a tree!)
568 */
569 if ((c = *input_line_pointer++) == '\t'
570 || c == ' '
571 || c == '\f'
572 || c == 0)
573 {
574 c = *input_line_pointer++;
575 }
576 know (c != ' '); /* No further leading whitespace. */
577 LISTING_NEWLINE ();
578 /*
579 * C is the 1st significant character.
580 * Input_line_pointer points after that character.
581 */
582 if (is_name_beginner (c))
583 {
584 /* want user-defined label or pseudo/opcode */
585 HANDLE_CONDITIONAL_ASSEMBLY ();
586
587 s = --input_line_pointer;
588 c = get_symbol_end (); /* name's delimiter */
589 /*
590 * C is character after symbol.
591 * That character's place in the input line is now '\0'.
592 * S points to the beginning of the symbol.
593 * [In case of pseudo-op, s->'.'.]
594 * Input_line_pointer->'\0' where c was.
595 */
596 if (TC_START_LABEL(c, input_line_pointer))
597 {
598 if (flag_mri)
599 {
600 char *rest = input_line_pointer + 1;
601
602 /* In MRI mode, \tsym: set 0 is permitted. */
603
604 if (*rest == ':')
605 ++rest;
606 if (*rest == ' ' || *rest == '\t')
607 ++rest;
608 if ((strncasecmp (rest, "EQU", 3) == 0
609 || strncasecmp (rest, "SET", 3) == 0)
610 && (rest[3] == ' ' || rest[3] == '\t'))
611 {
612 input_line_pointer = rest + 3;
613 equals (s);
614 continue;
615 }
616 }
617
618 line_label = colon (s); /* user-defined label */
619 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
620 /* Input_line_pointer->after ':'. */
621 SKIP_WHITESPACE ();
622
623
624 }
625 else if (c == '='
626 || (input_line_pointer[1] == '='
627 #ifdef TC_EQUAL_IN_INSN
628 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
629 #endif
630 ))
631 {
632 equals (s);
633 demand_empty_rest_of_line ();
634 }
635 else
636 { /* expect pseudo-op or machine instruction */
637 pop = NULL;
638
639 #define IGNORE_OPCODE_CASE
640 #ifdef IGNORE_OPCODE_CASE
641 {
642 char *s2 = s;
643 while (*s2)
644 {
645 if (isupper (*s2))
646 *s2 = tolower (*s2);
647 s2++;
648 }
649 }
650 #endif
651
652 #ifndef MRI_MODE_NEEDS_PSEUDO_DOT
653 #define MRI_MODE_NEEDS_PSEUDO_DOT 0
654 #endif
655
656 if ((flag_mri && ! MRI_MODE_NEEDS_PSEUDO_DOT)
657 #ifdef NO_PSEUDO_DOT
658 || 1
659 #endif
660 )
661 {
662 /* The MRI assembler and the m88k use pseudo-ops
663 without a period. */
664 pop = (pseudo_typeS *) hash_find (po_hash, s);
665 if (pop != NULL && pop->poc_handler == NULL)
666 pop = NULL;
667 }
668
669 if (pop != NULL
670 || ((! flag_mri || MRI_MODE_NEEDS_PSEUDO_DOT)
671 && *s == '.'))
672 {
673 /*
674 * PSEUDO - OP.
675 *
676 * WARNING: c has next char, which may be end-of-line.
677 * We lookup the pseudo-op table with s+1 because we
678 * already know that the pseudo-op begins with a '.'.
679 */
680
681 if (pop == NULL)
682 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
683
684 /* In MRI mode, we may need to insert an
685 automatic alignment directive. What a hack
686 this is. */
687 if (mri_pending_align
688 && (pop == NULL
689 || ! ((pop->poc_handler == cons
690 && pop->poc_val == 1)
691 || (pop->poc_handler == s_space
692 && pop->poc_val == 1))))
693 {
694 do_align (1, (char *) NULL);
695 mri_pending_align = 0;
696 }
697
698 /* Print the error msg now, while we still can */
699 if (pop == NULL)
700 {
701 as_bad ("Unknown pseudo-op: `%s'", s);
702 *input_line_pointer = c;
703 s_ignore (0);
704 continue;
705 }
706
707 /* Put it back for error messages etc. */
708 *input_line_pointer = c;
709 /* The following skip of whitespace is compulsory.
710 A well shaped space is sometimes all that separates
711 keyword from operands. */
712 if (c == ' ' || c == '\t')
713 input_line_pointer++;
714 /*
715 * Input_line is restored.
716 * Input_line_pointer->1st non-blank char
717 * after pseudo-operation.
718 */
719 (*pop->poc_handler) (pop->poc_val);
720
721 /* If that was .end, just get out now. */
722 if (pop->poc_handler == s_end)
723 goto quit;
724 }
725 else
726 { /* machine instruction */
727 int inquote = 0;
728
729 if (mri_pending_align)
730 {
731 do_align (1, (char *) NULL);
732 mri_pending_align = 0;
733 }
734
735 /* WARNING: c has char, which may be end-of-line. */
736 /* Also: input_line_pointer->`\0` where c was. */
737 *input_line_pointer = c;
738 while (!is_end_of_line[(unsigned char) *input_line_pointer]
739 || inquote
740 #ifdef TC_EOL_IN_INSN
741 || TC_EOL_IN_INSN (input_line_pointer)
742 #endif
743 )
744 {
745 if (flag_mri && *input_line_pointer == '\'')
746 inquote = ! inquote;
747 input_line_pointer++;
748 }
749
750 c = *input_line_pointer;
751 *input_line_pointer = '\0';
752
753 #ifdef OBJ_GENERATE_ASM_LINENO
754 if (generate_asm_lineno == 0)
755 {
756 if (ecoff_no_current_file ())
757 generate_asm_lineno = 1;
758 }
759 if (generate_asm_lineno == 1)
760 {
761 unsigned int lineno;
762 char *s;
763
764 as_where (&s, &lineno);
765 OBJ_GENERATE_ASM_LINENO (s, lineno);
766 }
767 #endif
768
769 if (macro_defined)
770 {
771 sb out;
772 const char *err;
773
774 if (check_macro (s, &out, '\0', &err))
775 {
776 if (err != NULL)
777 as_bad (err);
778 *input_line_pointer++ = c;
779 input_scrub_include_sb (&out,
780 input_line_pointer);
781 sb_kill (&out);
782 buffer_limit =
783 input_scrub_next_buffer (&input_line_pointer);
784 continue;
785 }
786 }
787
788 md_assemble (s); /* Assemble 1 instruction. */
789
790 *input_line_pointer++ = c;
791
792 /* We resume loop AFTER the end-of-line from
793 this instruction. */
794 } /* if (*s=='.') */
795 } /* if c==':' */
796 continue;
797 } /* if (is_name_beginner(c) */
798
799
800 /* Empty statement? */
801 if (is_end_of_line[(unsigned char) c])
802 continue;
803
804 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
805 && isdigit (c))
806 {
807 /* local label ("4:") */
808 char *backup = input_line_pointer;
809
810 HANDLE_CONDITIONAL_ASSEMBLY ();
811
812 temp = c - '0';
813
814 while (isdigit (*input_line_pointer))
815 {
816 temp = (temp * 10) + *input_line_pointer - '0';
817 ++input_line_pointer;
818 } /* read the whole number */
819
820 if (LOCAL_LABELS_DOLLAR
821 && *input_line_pointer == '$'
822 && *(input_line_pointer + 1) == ':')
823 {
824 input_line_pointer += 2;
825
826 if (dollar_label_defined (temp))
827 {
828 as_fatal ("label \"%d$\" redefined", temp);
829 }
830
831 define_dollar_label (temp);
832 colon (dollar_label_name (temp, 0));
833 continue;
834 }
835
836 if (LOCAL_LABELS_FB
837 && *input_line_pointer++ == ':')
838 {
839 fb_label_instance_inc (temp);
840 colon (fb_label_name (temp, 0));
841 continue;
842 }
843
844 input_line_pointer = backup;
845 } /* local label ("4:") */
846
847 if (c && strchr (line_comment_chars, c))
848 { /* Its a comment. Better say APP or NO_APP */
849 char *ends;
850 char *new_buf;
851 char *new_tmp;
852 unsigned int new_length;
853 char *tmp_buf = 0;
854
855 bump_line_counters ();
856 s = input_line_pointer;
857 if (strncmp (s, "APP\n", 4))
858 continue; /* We ignore it */
859 s += 4;
860
861 ends = strstr (s, "#NO_APP\n");
862
863 if (!ends)
864 {
865 unsigned int tmp_len;
866 unsigned int num;
867
868 /* The end of the #APP wasn't in this buffer. We
869 keep reading in buffers until we find the #NO_APP
870 that goes with this #APP There is one. The specs
871 guarentee it. . . */
872 tmp_len = buffer_limit - s;
873 tmp_buf = xmalloc (tmp_len + 1);
874 memcpy (tmp_buf, s, tmp_len);
875 do
876 {
877 new_tmp = input_scrub_next_buffer (&buffer);
878 if (!new_tmp)
879 break;
880 else
881 buffer_limit = new_tmp;
882 input_line_pointer = buffer;
883 ends = strstr (buffer, "#NO_APP\n");
884 if (ends)
885 num = ends - buffer;
886 else
887 num = buffer_limit - buffer;
888
889 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
890 memcpy (tmp_buf + tmp_len, buffer, num);
891 tmp_len += num;
892 }
893 while (!ends);
894
895 input_line_pointer = ends ? ends + 8 : NULL;
896
897 s = tmp_buf;
898 ends = s + tmp_len;
899
900 }
901 else
902 {
903 input_line_pointer = ends + 8;
904 }
905
906 scrub_string = s;
907 scrub_string_end = ends;
908
909 new_length = ends - s;
910 new_buf = (char *) xmalloc (new_length);
911 new_tmp = new_buf;
912 for (;;)
913 {
914 int space;
915 int size;
916
917 space = (new_buf + new_length) - new_tmp;
918 size = do_scrub_chars (scrub_from_string, new_tmp, space);
919
920 if (size < space)
921 {
922 new_tmp += size;
923 break;
924 }
925
926 new_buf = xrealloc (new_buf, new_length + 100);
927 new_tmp = new_buf + new_length;
928 new_length += 100;
929 }
930
931 if (tmp_buf)
932 free (tmp_buf);
933 old_buffer = buffer;
934 old_input = input_line_pointer;
935 old_limit = buffer_limit;
936 buffer = new_buf;
937 input_line_pointer = new_buf;
938 buffer_limit = new_tmp;
939 continue;
940 }
941
942 HANDLE_CONDITIONAL_ASSEMBLY ();
943
944 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
945 input_line_pointer--; /* Report unknown char as ignored. */
946 ignore_rest_of_line ();
947 } /* while (input_line_pointer<buffer_limit) */
948
949 #ifdef md_after_pass_hook
950 md_after_pass_hook ();
951 #endif
952
953 if (old_buffer)
954 {
955 free (buffer);
956 bump_line_counters ();
957 if (old_input != 0)
958 {
959 buffer = old_buffer;
960 input_line_pointer = old_input;
961 buffer_limit = old_limit;
962 old_buffer = 0;
963 goto contin;
964 }
965 }
966 } /* while (more buffers to scan) */
967
968 quit:
969 input_scrub_close (); /* Close the input file */
970 }
971
972 /* For most MRI pseudo-ops, the line actually ends at the first
973 nonquoted space. This function looks for that point, stuffs a null
974 in, and sets *STOPCP to the character that used to be there, and
975 returns the location.
976
977 Until I hear otherwise, I am going to assume that this is only true
978 for the m68k MRI assembler. */
979
980 char *
981 mri_comment_field (stopcp)
982 char *stopcp;
983 {
984 #ifdef TC_M68K
985
986 char *s;
987 int inquote = 0;
988
989 know (flag_mri);
990
991 for (s = input_line_pointer;
992 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
993 || inquote);
994 s++)
995 {
996 if (*s == '\'')
997 inquote = ! inquote;
998 }
999 *stopcp = *s;
1000 *s = '\0';
1001 return s;
1002
1003 #else
1004
1005 char *s;
1006
1007 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1008 ;
1009 *stopcp = *s;
1010 *s = '\0';
1011 return s;
1012
1013 #endif
1014
1015 }
1016
1017 /* Skip to the end of an MRI comment field. */
1018
1019 void
1020 mri_comment_end (stop, stopc)
1021 char *stop;
1022 int stopc;
1023 {
1024 know (flag_mri);
1025
1026 input_line_pointer = stop;
1027 *stop = stopc;
1028 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1029 ++input_line_pointer;
1030 }
1031
1032 void
1033 s_abort (ignore)
1034 int ignore;
1035 {
1036 as_fatal (".abort detected. Abandoning ship.");
1037 }
1038
1039 /* Guts of .align directive. */
1040 static void
1041 do_align (n, fill)
1042 int n;
1043 char *fill;
1044 {
1045 #ifdef md_do_align
1046 md_do_align (n, fill, just_record_alignment);
1047 #endif
1048 if (!fill)
1049 {
1050 /* @@ Fix this right for BFD! */
1051 static char zero;
1052 static char nop_opcode = NOP_OPCODE;
1053
1054 if (now_seg != data_section && now_seg != bss_section)
1055 {
1056 fill = &nop_opcode;
1057 }
1058 else
1059 {
1060 fill = &zero;
1061 }
1062 }
1063 /* Only make a frag if we HAVE to. . . */
1064 if (n && !need_pass_2)
1065 frag_align (n, *fill);
1066
1067 #ifdef md_do_align
1068 just_record_alignment:
1069 #endif
1070
1071 record_alignment (now_seg, n);
1072 }
1073
1074 /* For machines where ".align 4" means align to a 4 byte boundary. */
1075 void
1076 s_align_bytes (arg)
1077 int arg;
1078 {
1079 register unsigned int temp;
1080 char temp_fill;
1081 unsigned int i = 0;
1082 unsigned long max_alignment = 1 << 15;
1083 char *stop = NULL;
1084 char stopc;
1085
1086 if (flag_mri)
1087 stop = mri_comment_field (&stopc);
1088
1089 if (is_end_of_line[(unsigned char) *input_line_pointer])
1090 temp = arg; /* Default value from pseudo-op table */
1091 else
1092 temp = get_absolute_expression ();
1093
1094 if (temp > max_alignment)
1095 {
1096 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1097 }
1098
1099 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1100 have to convert it. */
1101 if (temp != 0)
1102 {
1103 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1104 ;
1105 }
1106 if (temp != 1)
1107 as_bad ("Alignment not a power of 2");
1108
1109 temp = i;
1110 if (*input_line_pointer == ',')
1111 {
1112 input_line_pointer++;
1113 temp_fill = get_absolute_expression ();
1114 do_align (temp, &temp_fill);
1115 }
1116 else
1117 do_align (temp, (char *) 0);
1118
1119 if (flag_mri)
1120 mri_comment_end (stop, stopc);
1121
1122 demand_empty_rest_of_line ();
1123 }
1124
1125 /* For machines where ".align 4" means align to 2**4 boundary. */
1126 void
1127 s_align_ptwo (ignore)
1128 int ignore;
1129 {
1130 register int temp;
1131 char temp_fill;
1132 long max_alignment = 15;
1133 char *stop = NULL;
1134 char stopc;
1135
1136 if (flag_mri)
1137 stop = mri_comment_field (&stopc);
1138
1139 temp = get_absolute_expression ();
1140 if (temp > max_alignment)
1141 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1142 else if (temp < 0)
1143 {
1144 as_bad ("Alignment negative. 0 assumed.");
1145 temp = 0;
1146 }
1147 if (*input_line_pointer == ',')
1148 {
1149 input_line_pointer++;
1150 temp_fill = get_absolute_expression ();
1151 do_align (temp, &temp_fill);
1152 }
1153 else
1154 do_align (temp, (char *) 0);
1155
1156 if (flag_mri)
1157 mri_comment_end (stop, stopc);
1158
1159 demand_empty_rest_of_line ();
1160 }
1161
1162 void
1163 s_comm (ignore)
1164 int ignore;
1165 {
1166 register char *name;
1167 register char c;
1168 register char *p;
1169 offsetT temp;
1170 register symbolS *symbolP;
1171 char *stop = NULL;
1172 char stopc;
1173
1174 if (flag_mri)
1175 stop = mri_comment_field (&stopc);
1176
1177 name = input_line_pointer;
1178 c = get_symbol_end ();
1179 /* just after name is now '\0' */
1180 p = input_line_pointer;
1181 *p = c;
1182 SKIP_WHITESPACE ();
1183 if (*input_line_pointer != ',')
1184 {
1185 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1186 if (flag_mri)
1187 mri_comment_end (stop, stopc);
1188 ignore_rest_of_line ();
1189 return;
1190 }
1191 input_line_pointer++; /* skip ',' */
1192 if ((temp = get_absolute_expression ()) < 0)
1193 {
1194 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1195 if (flag_mri)
1196 mri_comment_end (stop, stopc);
1197 ignore_rest_of_line ();
1198 return;
1199 }
1200 *p = 0;
1201 symbolP = symbol_find_or_make (name);
1202 *p = c;
1203 if (S_IS_DEFINED (symbolP))
1204 {
1205 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1206 S_GET_NAME (symbolP));
1207 if (flag_mri)
1208 mri_comment_end (stop, stopc);
1209 ignore_rest_of_line ();
1210 return;
1211 }
1212 if (S_GET_VALUE (symbolP))
1213 {
1214 if (S_GET_VALUE (symbolP) != (valueT) temp)
1215 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1216 S_GET_NAME (symbolP),
1217 (long) S_GET_VALUE (symbolP),
1218 (long) temp);
1219 }
1220 else
1221 {
1222 S_SET_VALUE (symbolP, (valueT) temp);
1223 S_SET_EXTERNAL (symbolP);
1224 }
1225 #ifdef OBJ_VMS
1226 {
1227 extern int flag_one;
1228 if ( (!temp) || !flag_one)
1229 S_GET_OTHER(symbolP) = const_flag;
1230 }
1231 #endif /* not OBJ_VMS */
1232 know (symbolP->sy_frag == &zero_address_frag);
1233
1234 if (flag_mri)
1235 mri_comment_end (stop, stopc);
1236
1237 demand_empty_rest_of_line ();
1238 } /* s_comm() */
1239
1240 /* The MRI COMMON pseudo-op. We handle this by creating a common
1241 symbol with the appropriate name. We make s_space do the right
1242 thing by increasing the size. */
1243
1244 void
1245 s_mri_common (small)
1246 int small;
1247 {
1248 char *name;
1249 char c;
1250 char *alc = NULL;
1251 symbolS *sym;
1252 offsetT align;
1253 char *stop = NULL;
1254 char stopc;
1255
1256 if (! flag_mri)
1257 {
1258 s_comm (0);
1259 return;
1260 }
1261
1262 stop = mri_comment_field (&stopc);
1263
1264 SKIP_WHITESPACE ();
1265
1266 name = input_line_pointer;
1267 if (! isdigit ((unsigned char) *name))
1268 c = get_symbol_end ();
1269 else
1270 {
1271 do
1272 {
1273 ++input_line_pointer;
1274 }
1275 while (isdigit ((unsigned char) *input_line_pointer));
1276 c = *input_line_pointer;
1277 *input_line_pointer = '\0';
1278
1279 if (line_label != NULL)
1280 {
1281 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1282 + (input_line_pointer - name)
1283 + 1);
1284 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1285 name = alc;
1286 }
1287 }
1288
1289 sym = symbol_find_or_make (name);
1290 *input_line_pointer = c;
1291 if (alc != NULL)
1292 free (alc);
1293
1294 if (*input_line_pointer != ',')
1295 align = 0;
1296 else
1297 {
1298 ++input_line_pointer;
1299 align = get_absolute_expression ();
1300 }
1301
1302 if (S_IS_DEFINED (sym))
1303 {
1304 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1305 if (! S_IS_COMMON (sym))
1306 #endif
1307 {
1308 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1309 mri_comment_end (stop, stopc);
1310 ignore_rest_of_line ();
1311 return;
1312 }
1313 }
1314
1315 S_SET_EXTERNAL (sym);
1316 mri_common_symbol = sym;
1317
1318 #ifdef S_SET_ALIGN
1319 if (align != 0)
1320 S_SET_ALIGN (sym, align);
1321 #endif
1322
1323 if (line_label != NULL)
1324 {
1325 line_label->sy_value.X_op = O_symbol;
1326 line_label->sy_value.X_add_symbol = sym;
1327 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1328 line_label->sy_frag = &zero_address_frag;
1329 S_SET_SEGMENT (line_label, expr_section);
1330 }
1331
1332 /* FIXME: We just ignore the small argument, which distinguishes
1333 COMMON and COMMON.S. I don't know what we can do about it. */
1334
1335 /* Ignore the type and hptype. */
1336 if (*input_line_pointer == ',')
1337 input_line_pointer += 2;
1338 if (*input_line_pointer == ',')
1339 input_line_pointer += 2;
1340
1341 mri_comment_end (stop, stopc);
1342
1343 demand_empty_rest_of_line ();
1344 }
1345
1346 void
1347 s_data (ignore)
1348 int ignore;
1349 {
1350 segT section;
1351 register int temp;
1352
1353 temp = get_absolute_expression ();
1354 if (flag_readonly_data_in_text)
1355 {
1356 section = text_section;
1357 temp += 1000;
1358 }
1359 else
1360 section = data_section;
1361
1362 subseg_set (section, (subsegT) temp);
1363
1364 #ifdef OBJ_VMS
1365 const_flag = 0;
1366 #endif
1367 demand_empty_rest_of_line ();
1368 }
1369
1370 /* Handle the .appfile pseudo-op. This is automatically generated by
1371 do_scrub_chars when a preprocessor # line comment is seen with a
1372 file name. This default definition may be overridden by the object
1373 or CPU specific pseudo-ops. This function is also the default
1374 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1375 .file. */
1376
1377 void
1378 s_app_file (appfile)
1379 int appfile;
1380 {
1381 register char *s;
1382 int length;
1383
1384 /* Some assemblers tolerate immediately following '"' */
1385 if ((s = demand_copy_string (&length)) != 0)
1386 {
1387 /* If this is a fake .appfile, a fake newline was inserted into
1388 the buffer. Passing -2 to new_logical_line tells it to
1389 account for it. */
1390 new_logical_line (s, appfile ? -2 : -1);
1391 demand_empty_rest_of_line ();
1392 #ifdef LISTING
1393 if (listing)
1394 listing_source_file (s);
1395 #endif
1396 }
1397 #ifdef obj_app_file
1398 obj_app_file (s);
1399 #endif
1400 }
1401
1402 /* Handle the .appline pseudo-op. This is automatically generated by
1403 do_scrub_chars when a preprocessor # line comment is seen. This
1404 default definition may be overridden by the object or CPU specific
1405 pseudo-ops. */
1406
1407 void
1408 s_app_line (ignore)
1409 int ignore;
1410 {
1411 int l;
1412
1413 /* The given number is that of the next line. */
1414 l = get_absolute_expression () - 1;
1415 if (l < 0)
1416 /* Some of the back ends can't deal with non-positive line numbers.
1417 Besides, it's silly. */
1418 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1419 else
1420 {
1421 new_logical_line ((char *) NULL, l);
1422 #ifdef LISTING
1423 if (listing)
1424 listing_source_line (l);
1425 #endif
1426 }
1427 demand_empty_rest_of_line ();
1428 }
1429
1430 /* Handle the .end pseudo-op. Actually, the real work is done in
1431 read_a_source_file. */
1432
1433 void
1434 s_end (ignore)
1435 int ignore;
1436 {
1437 if (flag_mri)
1438 {
1439 /* The MRI assembler permits the start symbol to follow .end,
1440 but we don't support that. */
1441 SKIP_WHITESPACE ();
1442 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1443 && *input_line_pointer != '*'
1444 && *input_line_pointer != '!')
1445 as_warn ("start address not supported");
1446 }
1447 }
1448
1449 /* Handle the .err pseudo-op. */
1450
1451 void
1452 s_err (ignore)
1453 int ignore;
1454 {
1455 as_bad (".err encountered");
1456 demand_empty_rest_of_line ();
1457 }
1458
1459 /* Handle the MRI fail pseudo-op. */
1460
1461 void
1462 s_fail (ignore)
1463 int ignore;
1464 {
1465 offsetT temp;
1466 char *stop = NULL;
1467 char stopc;
1468
1469 if (flag_mri)
1470 stop = mri_comment_field (&stopc);
1471
1472 temp = get_absolute_expression ();
1473 if (temp >= 500)
1474 as_warn (".fail %ld encountered", (long) temp);
1475 else
1476 as_bad (".fail %ld encountered", (long) temp);
1477
1478 if (flag_mri)
1479 mri_comment_end (stop, stopc);
1480
1481 demand_empty_rest_of_line ();
1482 }
1483
1484 void
1485 s_fill (ignore)
1486 int ignore;
1487 {
1488 long temp_repeat = 0;
1489 long temp_size = 1;
1490 register long temp_fill = 0;
1491 char *p;
1492
1493 #ifdef md_flush_pending_output
1494 md_flush_pending_output ();
1495 #endif
1496
1497 temp_repeat = get_absolute_expression ();
1498 if (*input_line_pointer == ',')
1499 {
1500 input_line_pointer++;
1501 temp_size = get_absolute_expression ();
1502 if (*input_line_pointer == ',')
1503 {
1504 input_line_pointer++;
1505 temp_fill = get_absolute_expression ();
1506 }
1507 }
1508 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1509 #define BSD_FILL_SIZE_CROCK_8 (8)
1510 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1511 {
1512 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1513 temp_size = BSD_FILL_SIZE_CROCK_8;
1514 }
1515 if (temp_size < 0)
1516 {
1517 as_warn ("Size negative: .fill ignored.");
1518 temp_size = 0;
1519 }
1520 else if (temp_repeat <= 0)
1521 {
1522 as_warn ("Repeat < 0, .fill ignored");
1523 temp_size = 0;
1524 }
1525
1526 if (temp_size && !need_pass_2)
1527 {
1528 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1529 memset (p, 0, (unsigned int) temp_size);
1530 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1531 * flavoured AS. The following bizzare behaviour is to be
1532 * compatible with above. I guess they tried to take up to 8
1533 * bytes from a 4-byte expression and they forgot to sign
1534 * extend. Un*x Sux. */
1535 #define BSD_FILL_SIZE_CROCK_4 (4)
1536 md_number_to_chars (p, (valueT) temp_fill,
1537 (temp_size > BSD_FILL_SIZE_CROCK_4
1538 ? BSD_FILL_SIZE_CROCK_4
1539 : (int) temp_size));
1540 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1541 * but emits no error message because it seems a legal thing to do.
1542 * It is a degenerate case of .fill but could be emitted by a compiler.
1543 */
1544 }
1545 demand_empty_rest_of_line ();
1546 }
1547
1548 void
1549 s_globl (ignore)
1550 int ignore;
1551 {
1552 char *name;
1553 int c;
1554 symbolS *symbolP;
1555 char *stop = NULL;
1556 char stopc;
1557
1558 if (flag_mri)
1559 stop = mri_comment_field (&stopc);
1560
1561 do
1562 {
1563 name = input_line_pointer;
1564 c = get_symbol_end ();
1565 symbolP = symbol_find_or_make (name);
1566 *input_line_pointer = c;
1567 SKIP_WHITESPACE ();
1568 S_SET_EXTERNAL (symbolP);
1569 if (c == ',')
1570 {
1571 input_line_pointer++;
1572 SKIP_WHITESPACE ();
1573 if (*input_line_pointer == '\n')
1574 c = '\n';
1575 }
1576 }
1577 while (c == ',');
1578
1579 if (flag_mri)
1580 mri_comment_end (stop, stopc);
1581
1582 demand_empty_rest_of_line ();
1583 }
1584
1585 /* Handle the MRI IRP and IRPC pseudo-ops. */
1586
1587 void
1588 s_irp (irpc)
1589 int irpc;
1590 {
1591 char *file;
1592 unsigned int line;
1593 sb s;
1594 const char *err;
1595 sb out;
1596
1597 as_where (&file, &line);
1598
1599 sb_new (&s);
1600 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1601 sb_add_char (&s, *input_line_pointer++);
1602
1603 sb_new (&out);
1604
1605 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1606 if (err != NULL)
1607 as_bad_where (file, line, "%s", err);
1608
1609 sb_kill (&s);
1610
1611 input_scrub_include_sb (&out, input_line_pointer);
1612 sb_kill (&out);
1613 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1614 }
1615
1616 void
1617 s_lcomm (needs_align)
1618 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1619 (alignment); 0 if it was an ".lcomm" (2 args only) */
1620 int needs_align;
1621 {
1622 register char *name;
1623 register char c;
1624 register char *p;
1625 register int temp;
1626 register symbolS *symbolP;
1627 segT current_seg = now_seg;
1628 subsegT current_subseg = now_subseg;
1629 const int max_alignment = 15;
1630 int align = 0;
1631 segT bss_seg = bss_section;
1632
1633 name = input_line_pointer;
1634 c = get_symbol_end ();
1635 p = input_line_pointer;
1636 *p = c;
1637 SKIP_WHITESPACE ();
1638
1639 /* Accept an optional comma after the name. The comma used to be
1640 required, but Irix 5 cc does not generate it. */
1641 if (*input_line_pointer == ',')
1642 {
1643 ++input_line_pointer;
1644 SKIP_WHITESPACE ();
1645 }
1646
1647 if (*input_line_pointer == '\n')
1648 {
1649 as_bad ("Missing size expression");
1650 return;
1651 }
1652
1653 if ((temp = get_absolute_expression ()) < 0)
1654 {
1655 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1656 ignore_rest_of_line ();
1657 return;
1658 }
1659
1660 #if defined (TC_MIPS) || defined (TC_ALPHA)
1661 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1662 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1663 {
1664 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1665 if (temp <= bfd_get_gp_size (stdoutput))
1666 {
1667 bss_seg = subseg_new (".sbss", 1);
1668 seg_info (bss_seg)->bss = 1;
1669 }
1670 }
1671 #endif
1672 if (!needs_align)
1673 {
1674 /* FIXME. This needs to be machine independent. */
1675 if (temp >= 8)
1676 align = 3;
1677 else if (temp >= 4)
1678 align = 2;
1679 else if (temp >= 2)
1680 align = 1;
1681 else
1682 align = 0;
1683
1684 record_alignment(bss_seg, align);
1685 }
1686
1687 if (needs_align)
1688 {
1689 align = 0;
1690 SKIP_WHITESPACE ();
1691 if (*input_line_pointer != ',')
1692 {
1693 as_bad ("Expected comma after size");
1694 ignore_rest_of_line ();
1695 return;
1696 }
1697 input_line_pointer++;
1698 SKIP_WHITESPACE ();
1699 if (*input_line_pointer == '\n')
1700 {
1701 as_bad ("Missing alignment");
1702 return;
1703 }
1704 align = get_absolute_expression ();
1705 if (align > max_alignment)
1706 {
1707 align = max_alignment;
1708 as_warn ("Alignment too large: %d. assumed.", align);
1709 }
1710 else if (align < 0)
1711 {
1712 align = 0;
1713 as_warn ("Alignment negative. 0 assumed.");
1714 }
1715 record_alignment (bss_seg, align);
1716 } /* if needs align */
1717 else
1718 {
1719 /* Assume some objects may require alignment on some systems. */
1720 #ifdef TC_ALPHA
1721 if (temp > 1)
1722 {
1723 align = ffs (temp) - 1;
1724 if (temp % (1 << align))
1725 abort ();
1726 }
1727 #endif
1728 }
1729
1730 *p = 0;
1731 symbolP = symbol_find_or_make (name);
1732 *p = c;
1733
1734 if (
1735 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1736 S_GET_OTHER (symbolP) == 0 &&
1737 S_GET_DESC (symbolP) == 0 &&
1738 #endif /* OBJ_AOUT or OBJ_BOUT */
1739 (S_GET_SEGMENT (symbolP) == bss_seg
1740 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1741 {
1742 char *pfrag;
1743
1744 subseg_set (bss_seg, 1);
1745
1746 if (align)
1747 frag_align (align, 0);
1748 /* detach from old frag */
1749 if (S_GET_SEGMENT (symbolP) == bss_seg)
1750 symbolP->sy_frag->fr_symbol = NULL;
1751
1752 symbolP->sy_frag = frag_now;
1753 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1754 temp, (char *)0);
1755 *pfrag = 0;
1756
1757 S_SET_SEGMENT (symbolP, bss_seg);
1758
1759 #ifdef OBJ_COFF
1760 /* The symbol may already have been created with a preceding
1761 ".globl" directive -- be careful not to step on storage class
1762 in that case. Otherwise, set it to static. */
1763 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1764 {
1765 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1766 }
1767 #endif /* OBJ_COFF */
1768 }
1769 else
1770 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1771 S_GET_NAME (symbolP));
1772
1773 subseg_set (current_seg, current_subseg);
1774
1775 demand_empty_rest_of_line ();
1776 } /* s_lcomm() */
1777
1778 void
1779 s_lsym (ignore)
1780 int ignore;
1781 {
1782 register char *name;
1783 register char c;
1784 register char *p;
1785 expressionS exp;
1786 register symbolS *symbolP;
1787
1788 /* we permit ANY defined expression: BSD4.2 demands constants */
1789 name = input_line_pointer;
1790 c = get_symbol_end ();
1791 p = input_line_pointer;
1792 *p = c;
1793 SKIP_WHITESPACE ();
1794 if (*input_line_pointer != ',')
1795 {
1796 *p = 0;
1797 as_bad ("Expected comma after name \"%s\"", name);
1798 *p = c;
1799 ignore_rest_of_line ();
1800 return;
1801 }
1802 input_line_pointer++;
1803 expression (&exp);
1804 if (exp.X_op != O_constant
1805 && exp.X_op != O_register)
1806 {
1807 as_bad ("bad expression");
1808 ignore_rest_of_line ();
1809 return;
1810 }
1811 *p = 0;
1812 symbolP = symbol_find_or_make (name);
1813
1814 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1815 symbolP->sy_desc == 0) out of this test because coff doesn't have
1816 those fields, and I can't see when they'd ever be tripped. I
1817 don't think I understand why they were here so I may have
1818 introduced a bug. As recently as 1.37 didn't have this test
1819 anyway. xoxorich. */
1820
1821 if (S_GET_SEGMENT (symbolP) == undefined_section
1822 && S_GET_VALUE (symbolP) == 0)
1823 {
1824 /* The name might be an undefined .global symbol; be sure to
1825 keep the "external" bit. */
1826 S_SET_SEGMENT (symbolP,
1827 (exp.X_op == O_constant
1828 ? absolute_section
1829 : reg_section));
1830 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1831 }
1832 else
1833 {
1834 as_bad ("Symbol %s already defined", name);
1835 }
1836 *p = c;
1837 demand_empty_rest_of_line ();
1838 } /* s_lsym() */
1839
1840 /* Read a line into an sb. */
1841
1842 static int
1843 get_line_sb (line)
1844 sb *line;
1845 {
1846 if (input_line_pointer >= buffer_limit)
1847 {
1848 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1849 if (buffer_limit == 0)
1850 return 0;
1851 }
1852
1853 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1854 sb_add_char (line, *input_line_pointer++);
1855 while (input_line_pointer < buffer_limit
1856 && is_end_of_line[(unsigned char) *input_line_pointer])
1857 {
1858 if (*input_line_pointer == '\n')
1859 {
1860 bump_line_counters ();
1861 LISTING_NEWLINE ();
1862 }
1863 ++input_line_pointer;
1864 }
1865 return 1;
1866 }
1867
1868 /* Define a macro. This is an interface to macro.c, which is shared
1869 between gas and gasp. */
1870
1871 void
1872 s_macro (ignore)
1873 int ignore;
1874 {
1875 char *file;
1876 unsigned int line;
1877 sb s;
1878 sb label;
1879 const char *err;
1880
1881 as_where (&file, &line);
1882
1883 sb_new (&s);
1884 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1885 sb_add_char (&s, *input_line_pointer++);
1886
1887 sb_new (&label);
1888 if (line_label != NULL)
1889 sb_add_string (&label, S_GET_NAME (line_label));
1890
1891 demand_empty_rest_of_line ();
1892
1893 err = define_macro (0, &s, &label, get_line_sb);
1894 if (err != NULL)
1895 as_bad_where (file, line, "%s", err);
1896 else
1897 {
1898 if (line_label != NULL)
1899 {
1900 S_SET_SEGMENT (line_label, undefined_section);
1901 S_SET_VALUE (line_label, 0);
1902 line_label->sy_frag = &zero_address_frag;
1903 }
1904 }
1905
1906 sb_kill (&s);
1907 }
1908
1909 /* Handle the .mexit pseudo-op, which immediately exits a macro
1910 expansion. */
1911
1912 void
1913 s_mexit (ignore)
1914 int ignore;
1915 {
1916 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1917 }
1918
1919 /* Handle changing the location counter. */
1920
1921 static void
1922 do_org (segment, exp, fill)
1923 segT segment;
1924 expressionS *exp;
1925 int fill;
1926 {
1927 if (segment != now_seg && segment != absolute_section)
1928 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1929 segment_name (segment), segment_name (now_seg));
1930
1931 if (now_seg == absolute_section)
1932 {
1933 if (fill != 0)
1934 as_warn ("ignoring fill value in absolute section");
1935 if (exp->X_op != O_constant)
1936 {
1937 as_bad ("only constant offsets supported in absolute section");
1938 exp->X_add_number = 0;
1939 }
1940 abs_section_offset = exp->X_add_number;
1941 }
1942 else
1943 {
1944 char *p;
1945
1946 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
1947 exp->X_add_number, (char *) NULL);
1948 *p = fill;
1949 }
1950 }
1951
1952 void
1953 s_org (ignore)
1954 int ignore;
1955 {
1956 register segT segment;
1957 expressionS exp;
1958 register long temp_fill;
1959
1960 #ifdef TC_M68K
1961 /* The m68k MRI assembler has a different meaning for .org. It
1962 means to create an absolute section at a given address. We can't
1963 support that--use a linker script instead. */
1964 if (flag_mri)
1965 {
1966 as_bad ("MRI style ORG pseudo-op not supported");
1967 ignore_rest_of_line ();
1968 return;
1969 }
1970 #endif
1971
1972 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1973 thing as a sub-segment-relative origin. Any absolute origin is
1974 given a warning, then assumed to be segment-relative. Any
1975 segmented origin expression ("foo+42") had better be in the right
1976 segment or the .org is ignored.
1977
1978 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1979 we never know sub-segment sizes when we are reading code. BSD
1980 will crash trying to emit negative numbers of filler bytes in
1981 certain .orgs. We don't crash, but see as-write for that code.
1982
1983 Don't make frag if need_pass_2==1. */
1984 segment = get_known_segmented_expression (&exp);
1985 if (*input_line_pointer == ',')
1986 {
1987 input_line_pointer++;
1988 temp_fill = get_absolute_expression ();
1989 }
1990 else
1991 temp_fill = 0;
1992
1993 if (!need_pass_2)
1994 do_org (segment, &exp, temp_fill);
1995
1996 demand_empty_rest_of_line ();
1997 } /* s_org() */
1998
1999 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2000 called by the obj-format routine which handles section changing
2001 when in MRI mode. It will create a new section, and return it. It
2002 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
2003 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
2004 BFD_ASSEMBLER is defined, the flags will be set in the section. */
2005
2006 void
2007 s_mri_sect (type)
2008 char *type;
2009 {
2010 #ifdef TC_M68K
2011
2012 char *name;
2013 char c;
2014 segT seg;
2015
2016 SKIP_WHITESPACE ();
2017
2018 name = input_line_pointer;
2019 if (! isdigit ((unsigned char) *name))
2020 c = get_symbol_end ();
2021 else
2022 {
2023 do
2024 {
2025 ++input_line_pointer;
2026 }
2027 while (isdigit ((unsigned char) *input_line_pointer));
2028 c = *input_line_pointer;
2029 *input_line_pointer = '\0';
2030 }
2031
2032 name = strdup (name);
2033 if (name == NULL)
2034 as_fatal ("virtual memory exhausted");
2035
2036 *input_line_pointer = c;
2037
2038 seg = subseg_new (name, 0);
2039
2040 if (*input_line_pointer == ',')
2041 {
2042 int align;
2043
2044 ++input_line_pointer;
2045 align = get_absolute_expression ();
2046 record_alignment (seg, align);
2047 }
2048
2049 *type = '\0';
2050 if (*input_line_pointer == ',')
2051 {
2052 c = *++input_line_pointer;
2053 c = toupper ((unsigned char) c);
2054 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2055 *type = c;
2056 else
2057 as_bad ("unrecognized section type");
2058 ++input_line_pointer;
2059
2060 #ifdef BFD_ASSEMBLER
2061 {
2062 flagword flags;
2063
2064 flags = SEC_NO_FLAGS;
2065 if (*type == 'C')
2066 flags = SEC_CODE;
2067 else if (*type == 'D')
2068 flags = SEC_DATA;
2069 else if (*type == 'R')
2070 flags = SEC_ROM;
2071 if (flags != SEC_NO_FLAGS)
2072 {
2073 if (! bfd_set_section_flags (stdoutput, seg, flags))
2074 as_warn ("error setting flags for \"%s\": %s",
2075 bfd_section_name (stdoutput, seg),
2076 bfd_errmsg (bfd_get_error ()));
2077 }
2078 }
2079 #endif
2080 }
2081
2082 /* Ignore the HP type. */
2083 if (*input_line_pointer == ',')
2084 input_line_pointer += 2;
2085
2086 demand_empty_rest_of_line ();
2087
2088 #else /* ! TC_M68K */
2089 #ifdef TC_I960
2090
2091 char *name;
2092 char c;
2093 segT seg;
2094
2095 SKIP_WHITESPACE ();
2096
2097 name = input_line_pointer;
2098 c = get_symbol_end ();
2099
2100 name = strdup (name);
2101 if (name == NULL)
2102 as_fatal ("virtual memory exhausted");
2103
2104 *input_line_pointer = c;
2105
2106 seg = subseg_new (name, 0);
2107
2108 if (*input_line_pointer != ',')
2109 *type = 'C';
2110 else
2111 {
2112 char *sectype;
2113
2114 ++input_line_pointer;
2115 SKIP_WHITESPACE ();
2116 sectype = input_line_pointer;
2117 c = get_symbol_end ();
2118 if (*sectype == '\0')
2119 *type = 'C';
2120 else if (strcasecmp (sectype, "text") == 0)
2121 *type = 'C';
2122 else if (strcasecmp (sectype, "data") == 0)
2123 *type = 'D';
2124 else if (strcasecmp (sectype, "romdata") == 0)
2125 *type = 'R';
2126 else
2127 as_warn ("unrecognized section type `%s'", sectype);
2128 *input_line_pointer = c;
2129 }
2130
2131 if (*input_line_pointer == ',')
2132 {
2133 char *seccmd;
2134
2135 ++input_line_pointer;
2136 SKIP_WHITESPACE ();
2137 seccmd = input_line_pointer;
2138 c = get_symbol_end ();
2139 if (strcasecmp (seccmd, "absolute") == 0)
2140 {
2141 as_bad ("absolute sections are not supported");
2142 *input_line_pointer = c;
2143 ignore_rest_of_line ();
2144 return;
2145 }
2146 else if (strcasecmp (seccmd, "align") == 0)
2147 {
2148 int align;
2149
2150 *input_line_pointer = c;
2151 align = get_absolute_expression ();
2152 record_alignment (seg, align);
2153 }
2154 else
2155 {
2156 as_warn ("unrecognized section command `%s'", seccmd);
2157 *input_line_pointer = c;
2158 }
2159 }
2160
2161 demand_empty_rest_of_line ();
2162
2163 #else /* ! TC_I960 */
2164 /* The MRI assembler seems to use different forms of .sect for
2165 different targets. */
2166 abort ();
2167 #endif /* ! TC_I960 */
2168 #endif /* ! TC_M68K */
2169 }
2170
2171 /* Handle the .print pseudo-op. */
2172
2173 void
2174 s_print (ignore)
2175 int ignore;
2176 {
2177 char *s;
2178 int len;
2179
2180 s = demand_copy_C_string (&len);
2181 printf ("%s\n", s);
2182 demand_empty_rest_of_line ();
2183 }
2184
2185 /* Handle the .purgem pseudo-op. */
2186
2187 void
2188 s_purgem (ignore)
2189 int ignore;
2190 {
2191 if (is_it_end_of_statement ())
2192 {
2193 demand_empty_rest_of_line ();
2194 return;
2195 }
2196
2197 do
2198 {
2199 char *name;
2200 char c;
2201
2202 SKIP_WHITESPACE ();
2203 name = input_line_pointer;
2204 c = get_symbol_end ();
2205 delete_macro (name);
2206 *input_line_pointer = c;
2207 SKIP_WHITESPACE ();
2208 }
2209 while (*input_line_pointer++ == ',');
2210
2211 --input_line_pointer;
2212 demand_empty_rest_of_line ();
2213 }
2214
2215 /* Handle the .rept pseudo-op. */
2216
2217 void
2218 s_rept (ignore)
2219 int ignore;
2220 {
2221 int count;
2222 sb one;
2223 sb many;
2224
2225 count = get_absolute_expression ();
2226
2227 sb_new (&one);
2228 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2229 {
2230 as_bad ("rept without endr");
2231 return;
2232 }
2233
2234 sb_new (&many);
2235 while (count-- > 0)
2236 sb_add_sb (&many, &one);
2237
2238 sb_kill (&one);
2239
2240 input_scrub_include_sb (&many, input_line_pointer);
2241 sb_kill (&many);
2242 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2243 }
2244
2245 void
2246 s_set (ignore)
2247 int ignore;
2248 {
2249 register char *name;
2250 register char delim;
2251 register char *end_name;
2252 register symbolS *symbolP;
2253
2254 /*
2255 * Especial apologies for the random logic:
2256 * this just grew, and could be parsed much more simply!
2257 * Dean in haste.
2258 */
2259 name = input_line_pointer;
2260 delim = get_symbol_end ();
2261 end_name = input_line_pointer;
2262 *end_name = delim;
2263 SKIP_WHITESPACE ();
2264
2265 if (*input_line_pointer != ',')
2266 {
2267 *end_name = 0;
2268 as_bad ("Expected comma after name \"%s\"", name);
2269 *end_name = delim;
2270 ignore_rest_of_line ();
2271 return;
2272 }
2273
2274 input_line_pointer++;
2275 *end_name = 0;
2276
2277 if (name[0] == '.' && name[1] == '\0')
2278 {
2279 /* Turn '. = mumble' into a .org mumble */
2280 register segT segment;
2281 expressionS exp;
2282
2283 segment = get_known_segmented_expression (&exp);
2284
2285 if (!need_pass_2)
2286 do_org (segment, &exp, 0);
2287
2288 *end_name = delim;
2289 return;
2290 }
2291
2292 if ((symbolP = symbol_find (name)) == NULL
2293 && (symbolP = md_undefined_symbol (name)) == NULL)
2294 {
2295 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2296 #ifdef OBJ_COFF
2297 /* "set" symbols are local unless otherwise specified. */
2298 SF_SET_LOCAL (symbolP);
2299 #endif /* OBJ_COFF */
2300
2301 } /* make a new symbol */
2302
2303 symbol_table_insert (symbolP);
2304
2305 *end_name = delim;
2306 pseudo_set (symbolP);
2307 demand_empty_rest_of_line ();
2308 } /* s_set() */
2309
2310 void
2311 s_space (mult)
2312 int mult;
2313 {
2314 expressionS exp;
2315 long temp_fill;
2316 char *p = 0;
2317 char *stop = NULL;
2318 char stopc;
2319
2320 #ifdef md_flush_pending_output
2321 md_flush_pending_output ();
2322 #endif
2323
2324 if (flag_mri)
2325 stop = mri_comment_field (&stopc);
2326
2327 /* Just like .fill, but temp_size = 1 */
2328 expression (&exp);
2329 if (exp.X_op == O_constant)
2330 {
2331 long repeat;
2332
2333 repeat = exp.X_add_number;
2334 if (mult)
2335 repeat *= mult;
2336 if (repeat <= 0)
2337 {
2338 if (! flag_mri || repeat < 0)
2339 as_warn (".space repeat count is %s, ignored",
2340 repeat ? "negative" : "zero");
2341 goto getout;
2342 }
2343
2344 /* If we are in the absolute section, just bump the offset. */
2345 if (now_seg == absolute_section)
2346 {
2347 abs_section_offset += repeat;
2348 goto getout;
2349 }
2350
2351 /* If we are secretly in an MRI common section, then creating
2352 space just increases the size of the common symbol. */
2353 if (mri_common_symbol != NULL)
2354 {
2355 S_SET_VALUE (mri_common_symbol,
2356 S_GET_VALUE (mri_common_symbol) + repeat);
2357 goto getout;
2358 }
2359
2360 if (!need_pass_2)
2361 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2362 repeat, (char *) 0);
2363 }
2364 else
2365 {
2366 if (now_seg == absolute_section)
2367 {
2368 as_bad ("space allocation too complex in absolute section");
2369 subseg_set (text_section, 0);
2370 }
2371 if (mri_common_symbol != NULL)
2372 {
2373 as_bad ("space allocation too complex in common section");
2374 mri_common_symbol = NULL;
2375 }
2376 if (!need_pass_2)
2377 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2378 make_expr_symbol (&exp), 0L, (char *) 0);
2379 }
2380 SKIP_WHITESPACE ();
2381 if (*input_line_pointer == ',')
2382 {
2383 input_line_pointer++;
2384 temp_fill = get_absolute_expression ();
2385 }
2386 else
2387 {
2388 temp_fill = 0;
2389 }
2390 if (p)
2391 {
2392 *p = temp_fill;
2393 }
2394
2395 getout:
2396 if (flag_mri)
2397 mri_comment_end (stop, stopc);
2398
2399 demand_empty_rest_of_line ();
2400 }
2401
2402 /* This is like s_space, but the value is a floating point number with
2403 the given precision. This is for the MRI dcb.s pseudo-op and
2404 friends. */
2405
2406 void
2407 s_float_space (float_type)
2408 int float_type;
2409 {
2410 offsetT count;
2411 int flen;
2412 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2413 char *stop = NULL;
2414 char stopc;
2415
2416 if (flag_mri)
2417 stop = mri_comment_field (&stopc);
2418
2419 count = get_absolute_expression ();
2420
2421 SKIP_WHITESPACE ();
2422 if (*input_line_pointer != ',')
2423 {
2424 as_bad ("missing value");
2425 if (flag_mri)
2426 mri_comment_end (stop, stopc);
2427 ignore_rest_of_line ();
2428 return;
2429 }
2430
2431 ++input_line_pointer;
2432
2433 SKIP_WHITESPACE ();
2434
2435 /* Skip any 0{letter} that may be present. Don't even check if the
2436 * letter is legal. */
2437 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2438 input_line_pointer += 2;
2439
2440 /* Accept :xxxx, where the x's are hex digits, for a floating point
2441 with the exact digits specified. */
2442 if (input_line_pointer[0] == ':')
2443 {
2444 flen = hex_float (float_type, temp);
2445 if (flen < 0)
2446 {
2447 if (flag_mri)
2448 mri_comment_end (stop, stopc);
2449 ignore_rest_of_line ();
2450 return;
2451 }
2452 }
2453 else
2454 {
2455 char *err;
2456
2457 err = md_atof (float_type, temp, &flen);
2458 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2459 know (flen > 0);
2460 if (err)
2461 {
2462 as_bad ("Bad floating literal: %s", err);
2463 if (flag_mri)
2464 mri_comment_end (stop, stopc);
2465 ignore_rest_of_line ();
2466 return;
2467 }
2468 }
2469
2470 while (--count >= 0)
2471 {
2472 char *p;
2473
2474 p = frag_more (flen);
2475 memcpy (p, temp, (unsigned int) flen);
2476 }
2477
2478 if (flag_mri)
2479 mri_comment_end (stop, stopc);
2480
2481 demand_empty_rest_of_line ();
2482 }
2483
2484 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2485
2486 void
2487 s_struct (ignore)
2488 int ignore;
2489 {
2490 char *stop = NULL;
2491 char stopc;
2492
2493 if (flag_mri)
2494 stop = mri_comment_field (&stopc);
2495 abs_section_offset = get_absolute_expression ();
2496 subseg_set (absolute_section, 0);
2497 if (flag_mri)
2498 mri_comment_end (stop, stopc);
2499 demand_empty_rest_of_line ();
2500 }
2501
2502 void
2503 s_text (ignore)
2504 int ignore;
2505 {
2506 register int temp;
2507
2508 temp = get_absolute_expression ();
2509 subseg_set (text_section, (subsegT) temp);
2510 demand_empty_rest_of_line ();
2511 #ifdef OBJ_VMS
2512 const_flag &= ~IN_DEFAULT_SECTION;
2513 #endif
2514 } /* s_text() */
2515 \f
2516
2517 void
2518 demand_empty_rest_of_line ()
2519 {
2520 SKIP_WHITESPACE ();
2521 if (is_end_of_line[(unsigned char) *input_line_pointer])
2522 {
2523 input_line_pointer++;
2524 }
2525 else
2526 {
2527 ignore_rest_of_line ();
2528 }
2529 /* Return having already swallowed end-of-line. */
2530 } /* Return pointing just after end-of-line. */
2531
2532 void
2533 ignore_rest_of_line () /* For suspect lines: gives warning. */
2534 {
2535 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2536 {
2537 if (isprint (*input_line_pointer))
2538 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2539 *input_line_pointer);
2540 else
2541 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2542 *input_line_pointer);
2543 while (input_line_pointer < buffer_limit
2544 && !is_end_of_line[(unsigned char) *input_line_pointer])
2545 {
2546 input_line_pointer++;
2547 }
2548 }
2549 input_line_pointer++; /* Return pointing just after end-of-line. */
2550 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2551 }
2552
2553 /*
2554 * pseudo_set()
2555 *
2556 * In: Pointer to a symbol.
2557 * Input_line_pointer->expression.
2558 *
2559 * Out: Input_line_pointer->just after any whitespace after expression.
2560 * Tried to set symbol to value of expression.
2561 * Will change symbols type, value, and frag;
2562 */
2563 void
2564 pseudo_set (symbolP)
2565 symbolS *symbolP;
2566 {
2567 expressionS exp;
2568 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2569 int ext;
2570 #endif /* OBJ_AOUT or OBJ_BOUT */
2571
2572 know (symbolP); /* NULL pointer is logic error. */
2573 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2574 ext = S_IS_EXTERNAL (symbolP);
2575 #endif /* OBJ_AOUT or OBJ_BOUT */
2576
2577 (void) expression (&exp);
2578
2579 if (exp.X_op == O_illegal)
2580 as_bad ("illegal expression; zero assumed");
2581 else if (exp.X_op == O_absent)
2582 as_bad ("missing expression; zero assumed");
2583 else if (exp.X_op == O_big)
2584 as_bad ("%s number invalid; zero assumed",
2585 exp.X_add_number > 0 ? "bignum" : "floating point");
2586 else if (exp.X_op == O_subtract
2587 && (S_GET_SEGMENT (exp.X_add_symbol)
2588 == S_GET_SEGMENT (exp.X_op_symbol))
2589 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2590 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2591 {
2592 exp.X_op = O_constant;
2593 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2594 - S_GET_VALUE (exp.X_op_symbol));
2595 }
2596
2597 switch (exp.X_op)
2598 {
2599 case O_illegal:
2600 case O_absent:
2601 case O_big:
2602 exp.X_add_number = 0;
2603 /* Fall through. */
2604 case O_constant:
2605 S_SET_SEGMENT (symbolP, absolute_section);
2606 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2607 if (ext)
2608 S_SET_EXTERNAL (symbolP);
2609 else
2610 S_CLEAR_EXTERNAL (symbolP);
2611 #endif /* OBJ_AOUT or OBJ_BOUT */
2612 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2613 symbolP->sy_frag = &zero_address_frag;
2614 break;
2615
2616 case O_register:
2617 S_SET_SEGMENT (symbolP, reg_section);
2618 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2619 symbolP->sy_frag = &zero_address_frag;
2620 break;
2621
2622 case O_symbol:
2623 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2624 || exp.X_add_number != 0)
2625 symbolP->sy_value = exp;
2626 else
2627 {
2628 symbolS *s = exp.X_add_symbol;
2629
2630 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2631 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2632 if (ext)
2633 S_SET_EXTERNAL (symbolP);
2634 else
2635 S_CLEAR_EXTERNAL (symbolP);
2636 #endif /* OBJ_AOUT or OBJ_BOUT */
2637 S_SET_VALUE (symbolP,
2638 exp.X_add_number + S_GET_VALUE (s));
2639 symbolP->sy_frag = s->sy_frag;
2640 copy_symbol_attributes (symbolP, s);
2641 }
2642 break;
2643
2644 default:
2645 /* The value is some complex expression.
2646 FIXME: Should we set the segment to anything? */
2647 symbolP->sy_value = exp;
2648 break;
2649 }
2650 }
2651 \f
2652 /*
2653 * cons()
2654 *
2655 * CONStruct more frag of .bytes, or .words etc.
2656 * Should need_pass_2 be 1 then emit no frag(s).
2657 * This understands EXPRESSIONS.
2658 *
2659 * Bug (?)
2660 *
2661 * This has a split personality. We use expression() to read the
2662 * value. We can detect if the value won't fit in a byte or word.
2663 * But we can't detect if expression() discarded significant digits
2664 * in the case of a long. Not worth the crocks required to fix it.
2665 */
2666
2667 /* Select a parser for cons expressions. */
2668
2669 /* Some targets need to parse the expression in various fancy ways.
2670 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2671 (for example, the HPPA does this). Otherwise, you can define
2672 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2673 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2674 are defined, which is the normal case, then only simple expressions
2675 are permitted. */
2676
2677 static void
2678 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2679
2680 #ifndef TC_PARSE_CONS_EXPRESSION
2681 #ifdef BITFIELD_CONS_EXPRESSIONS
2682 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2683 static void
2684 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2685 #endif
2686 #ifdef REPEAT_CONS_EXPRESSIONS
2687 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2688 static void
2689 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2690 #endif
2691
2692 /* If we haven't gotten one yet, just call expression. */
2693 #ifndef TC_PARSE_CONS_EXPRESSION
2694 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2695 #endif
2696 #endif
2697
2698 /* worker to do .byte etc statements */
2699 /* clobbers input_line_pointer, checks */
2700 /* end-of-line. */
2701 static void
2702 cons_worker (nbytes, rva)
2703 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
2704 int rva;
2705 {
2706 int c;
2707 expressionS exp;
2708 char *stop = NULL;
2709 char stopc;
2710
2711 #ifdef md_flush_pending_output
2712 md_flush_pending_output ();
2713 #endif
2714
2715 if (flag_mri)
2716 stop = mri_comment_field (&stopc);
2717
2718 if (is_it_end_of_statement ())
2719 {
2720 mri_comment_end (stop, stopc);
2721 demand_empty_rest_of_line ();
2722 return;
2723 }
2724
2725 c = 0;
2726 do
2727 {
2728 if (flag_mri)
2729 parse_mri_cons (&exp, (unsigned int) nbytes);
2730 else
2731 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
2732
2733 if (rva)
2734 {
2735 if (exp.X_op == O_symbol)
2736 exp.X_op = O_symbol_rva;
2737 else
2738 as_fatal ("rva without symbol");
2739 }
2740 emit_expr (&exp, (unsigned int) nbytes);
2741 ++c;
2742 }
2743 while (*input_line_pointer++ == ',');
2744
2745 /* In MRI mode, after an odd number of bytes, we must align to an
2746 even word boundary, unless the next instruction is a dc.b, ds.b
2747 or dcb.b. */
2748 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2749 mri_pending_align = 1;
2750
2751 input_line_pointer--; /* Put terminator back into stream. */
2752
2753 if (flag_mri)
2754 mri_comment_end (stop, stopc);
2755
2756 demand_empty_rest_of_line ();
2757 }
2758
2759
2760 void
2761 cons (size)
2762 int size;
2763 {
2764 cons_worker (size, 0);
2765 }
2766
2767 void
2768 s_rva (size)
2769 int size;
2770 {
2771 cons_worker (size, 1);
2772 }
2773
2774
2775 /* Put the contents of expression EXP into the object file using
2776 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2777
2778 void
2779 emit_expr (exp, nbytes)
2780 expressionS *exp;
2781 unsigned int nbytes;
2782 {
2783 operatorT op;
2784 register char *p;
2785 valueT extra_digit = 0;
2786
2787 /* Don't do anything if we are going to make another pass. */
2788 if (need_pass_2)
2789 return;
2790
2791 op = exp->X_op;
2792
2793 /* Allow `.word 0' in the absolute section. */
2794 if (now_seg == absolute_section)
2795 {
2796 if (op != O_constant || exp->X_add_number != 0)
2797 as_bad ("attempt to store value in absolute section");
2798 abs_section_offset += nbytes;
2799 return;
2800 }
2801
2802 /* Handle a negative bignum. */
2803 if (op == O_uminus
2804 && exp->X_add_number == 0
2805 && exp->X_add_symbol->sy_value.X_op == O_big
2806 && exp->X_add_symbol->sy_value.X_add_number > 0)
2807 {
2808 int i;
2809 unsigned long carry;
2810
2811 exp = &exp->X_add_symbol->sy_value;
2812
2813 /* Negate the bignum: one's complement each digit and add 1. */
2814 carry = 1;
2815 for (i = 0; i < exp->X_add_number; i++)
2816 {
2817 unsigned long next;
2818
2819 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
2820 & LITTLENUM_MASK)
2821 + carry);
2822 generic_bignum[i] = next & LITTLENUM_MASK;
2823 carry = next >> LITTLENUM_NUMBER_OF_BITS;
2824 }
2825
2826 /* We can ignore any carry out, because it will be handled by
2827 extra_digit if it is needed. */
2828
2829 extra_digit = (valueT) -1;
2830 op = O_big;
2831 }
2832
2833 if (op == O_absent || op == O_illegal)
2834 {
2835 as_warn ("zero assumed for missing expression");
2836 exp->X_add_number = 0;
2837 op = O_constant;
2838 }
2839 else if (op == O_big && exp->X_add_number <= 0)
2840 {
2841 as_bad ("floating point number invalid; zero assumed");
2842 exp->X_add_number = 0;
2843 op = O_constant;
2844 }
2845 else if (op == O_register)
2846 {
2847 as_warn ("register value used as expression");
2848 op = O_constant;
2849 }
2850
2851 p = frag_more ((int) nbytes);
2852
2853 #ifndef WORKING_DOT_WORD
2854 /* If we have the difference of two symbols in a word, save it on
2855 the broken_words list. See the code in write.c. */
2856 if (op == O_subtract && nbytes == 2)
2857 {
2858 struct broken_word *x;
2859
2860 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
2861 x->next_broken_word = broken_words;
2862 broken_words = x;
2863 x->frag = frag_now;
2864 x->word_goes_here = p;
2865 x->dispfrag = 0;
2866 x->add = exp->X_add_symbol;
2867 x->sub = exp->X_op_symbol;
2868 x->addnum = exp->X_add_number;
2869 x->added = 0;
2870 new_broken_words++;
2871 return;
2872 }
2873 #endif
2874
2875 /* If we have an integer, but the number of bytes is too large to
2876 pass to md_number_to_chars, handle it as a bignum. */
2877 if (op == O_constant && nbytes > sizeof (valueT))
2878 {
2879 valueT val;
2880 int gencnt;
2881
2882 if (! exp->X_unsigned && exp->X_add_number < 0)
2883 extra_digit = (valueT) -1;
2884 val = (valueT) exp->X_add_number;
2885 gencnt = 0;
2886 do
2887 {
2888 generic_bignum[gencnt] = val & LITTLENUM_MASK;
2889 val >>= LITTLENUM_NUMBER_OF_BITS;
2890 ++gencnt;
2891 }
2892 while (val != 0);
2893 op = exp->X_op = O_big;
2894 exp->X_add_number = gencnt;
2895 }
2896
2897 if (op == O_constant)
2898 {
2899 register valueT get;
2900 register valueT use;
2901 register valueT mask;
2902 register valueT unmask;
2903
2904 /* JF << of >= number of bits in the object is undefined. In
2905 particular SPARC (Sun 4) has problems */
2906 if (nbytes >= sizeof (valueT))
2907 mask = 0;
2908 else
2909 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
2910
2911 unmask = ~mask; /* Do store these bits. */
2912
2913 #ifdef NEVER
2914 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2915 mask = ~(unmask >> 1); /* Includes sign bit now. */
2916 #endif
2917
2918 get = exp->X_add_number;
2919 use = get & unmask;
2920 if ((get & mask) != 0 && (get & mask) != mask)
2921 { /* Leading bits contain both 0s & 1s. */
2922 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
2923 }
2924 /* put bytes in right order. */
2925 md_number_to_chars (p, use, (int) nbytes);
2926 }
2927 else if (op == O_big)
2928 {
2929 int size;
2930 LITTLENUM_TYPE *nums;
2931
2932 know (nbytes % CHARS_PER_LITTLENUM == 0);
2933
2934 size = exp->X_add_number * CHARS_PER_LITTLENUM;
2935 if (nbytes < size)
2936 {
2937 as_warn ("Bignum truncated to %d bytes", nbytes);
2938 size = nbytes;
2939 }
2940
2941 if (target_big_endian)
2942 {
2943 while (nbytes > size)
2944 {
2945 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2946 nbytes -= CHARS_PER_LITTLENUM;
2947 p += CHARS_PER_LITTLENUM;
2948 }
2949
2950 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
2951 while (size > 0)
2952 {
2953 --nums;
2954 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2955 size -= CHARS_PER_LITTLENUM;
2956 p += CHARS_PER_LITTLENUM;
2957 }
2958 }
2959 else
2960 {
2961 nums = generic_bignum;
2962 while (size > 0)
2963 {
2964 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2965 ++nums;
2966 size -= CHARS_PER_LITTLENUM;
2967 p += CHARS_PER_LITTLENUM;
2968 nbytes -= CHARS_PER_LITTLENUM;
2969 }
2970
2971 while (nbytes > 0)
2972 {
2973 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2974 nbytes -= CHARS_PER_LITTLENUM;
2975 p += CHARS_PER_LITTLENUM;
2976 }
2977 }
2978 }
2979 else
2980 {
2981 memset (p, 0, nbytes);
2982
2983 /* Now we need to generate a fixS to record the symbol value.
2984 This is easy for BFD. For other targets it can be more
2985 complex. For very complex cases (currently, the HPPA and
2986 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2987 want. For simpler cases, you can define TC_CONS_RELOC to be
2988 the name of the reloc code that should be stored in the fixS.
2989 If neither is defined, the code uses NO_RELOC if it is
2990 defined, and otherwise uses 0. */
2991
2992 #ifdef BFD_ASSEMBLER
2993 #ifdef TC_CONS_FIX_NEW
2994 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2995 #else
2996 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
2997 /* @@ Should look at CPU word size. */
2998 nbytes == 2 ? BFD_RELOC_16
2999 : nbytes == 8 ? BFD_RELOC_64
3000 : BFD_RELOC_32);
3001 #endif
3002 #else
3003 #ifdef TC_CONS_FIX_NEW
3004 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3005 #else
3006 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3007 it is defined, otherwise use NO_RELOC if it is defined,
3008 otherwise use 0. */
3009 #ifndef TC_CONS_RELOC
3010 #ifdef NO_RELOC
3011 #define TC_CONS_RELOC NO_RELOC
3012 #else
3013 #define TC_CONS_RELOC 0
3014 #endif
3015 #endif
3016 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3017 TC_CONS_RELOC);
3018 #endif /* TC_CONS_FIX_NEW */
3019 #endif /* BFD_ASSEMBLER */
3020 }
3021 }
3022 \f
3023 #ifdef BITFIELD_CONS_EXPRESSIONS
3024
3025 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3026 w:x,y:z, where w and y are bitwidths and x and y are values. They
3027 then pack them all together. We do a little better in that we allow
3028 them in words, longs, etc. and we'll pack them in target byte order
3029 for you.
3030
3031 The rules are: pack least significat bit first, if a field doesn't
3032 entirely fit, put it in the next unit. Overflowing the bitfield is
3033 explicitly *not* even a warning. The bitwidth should be considered
3034 a "mask".
3035
3036 To use this function the tc-XXX.h file should define
3037 BITFIELD_CONS_EXPRESSIONS. */
3038
3039 static void
3040 parse_bitfield_cons (exp, nbytes)
3041 expressionS *exp;
3042 unsigned int nbytes;
3043 {
3044 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3045 char *hold = input_line_pointer;
3046
3047 (void) expression (exp);
3048
3049 if (*input_line_pointer == ':')
3050 { /* bitfields */
3051 long value = 0;
3052
3053 for (;;)
3054 {
3055 unsigned long width;
3056
3057 if (*input_line_pointer != ':')
3058 {
3059 input_line_pointer = hold;
3060 break;
3061 } /* next piece is not a bitfield */
3062
3063 /* In the general case, we can't allow
3064 full expressions with symbol
3065 differences and such. The relocation
3066 entries for symbols not defined in this
3067 assembly would require arbitrary field
3068 widths, positions, and masks which most
3069 of our current object formats don't
3070 support.
3071
3072 In the specific case where a symbol
3073 *is* defined in this assembly, we
3074 *could* build fixups and track it, but
3075 this could lead to confusion for the
3076 backends. I'm lazy. I'll take any
3077 SEG_ABSOLUTE. I think that means that
3078 you can use a previous .set or
3079 .equ type symbol. xoxorich. */
3080
3081 if (exp->X_op == O_absent)
3082 {
3083 as_warn ("using a bit field width of zero");
3084 exp->X_add_number = 0;
3085 exp->X_op = O_constant;
3086 } /* implied zero width bitfield */
3087
3088 if (exp->X_op != O_constant)
3089 {
3090 *input_line_pointer = '\0';
3091 as_bad ("field width \"%s\" too complex for a bitfield", hold);
3092 *input_line_pointer = ':';
3093 demand_empty_rest_of_line ();
3094 return;
3095 } /* too complex */
3096
3097 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3098 {
3099 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3100 width, nbytes, (BITS_PER_CHAR * nbytes));
3101 width = BITS_PER_CHAR * nbytes;
3102 } /* too big */
3103
3104 if (width > bits_available)
3105 {
3106 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3107 input_line_pointer = hold;
3108 exp->X_add_number = value;
3109 break;
3110 } /* won't fit */
3111
3112 hold = ++input_line_pointer; /* skip ':' */
3113
3114 (void) expression (exp);
3115 if (exp->X_op != O_constant)
3116 {
3117 char cache = *input_line_pointer;
3118
3119 *input_line_pointer = '\0';
3120 as_bad ("field value \"%s\" too complex for a bitfield", hold);
3121 *input_line_pointer = cache;
3122 demand_empty_rest_of_line ();
3123 return;
3124 } /* too complex */
3125
3126 value |= ((~(-1 << width) & exp->X_add_number)
3127 << ((BITS_PER_CHAR * nbytes) - bits_available));
3128
3129 if ((bits_available -= width) == 0
3130 || is_it_end_of_statement ()
3131 || *input_line_pointer != ',')
3132 {
3133 break;
3134 } /* all the bitfields we're gonna get */
3135
3136 hold = ++input_line_pointer;
3137 (void) expression (exp);
3138 } /* forever loop */
3139
3140 exp->X_add_number = value;
3141 exp->X_op = O_constant;
3142 exp->X_unsigned = 1;
3143 } /* if looks like a bitfield */
3144 } /* parse_bitfield_cons() */
3145
3146 #endif /* BITFIELD_CONS_EXPRESSIONS */
3147 \f
3148 /* Handle an MRI style string expression. */
3149
3150 static void
3151 parse_mri_cons (exp, nbytes)
3152 expressionS *exp;
3153 unsigned int nbytes;
3154 {
3155 if (*input_line_pointer != '\''
3156 && (input_line_pointer[1] != '\''
3157 || (*input_line_pointer != 'A'
3158 && *input_line_pointer != 'E')))
3159 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3160 else
3161 {
3162 int scan = 0;
3163 unsigned int result = 0;
3164
3165 /* An MRI style string. Cut into as many bytes as will fit into
3166 a nbyte chunk, left justify if necessary, and separate with
3167 commas so we can try again later. */
3168 if (*input_line_pointer == 'A')
3169 ++input_line_pointer;
3170 else if (*input_line_pointer == 'E')
3171 {
3172 as_bad ("EBCDIC constants are not supported");
3173 ++input_line_pointer;
3174 }
3175
3176 input_line_pointer++;
3177 for (scan = 0; scan < nbytes; scan++)
3178 {
3179 if (*input_line_pointer == '\'')
3180 {
3181 if (input_line_pointer[1] == '\'')
3182 {
3183 input_line_pointer++;
3184 }
3185 else
3186 break;
3187 }
3188 result = (result << 8) | (*input_line_pointer++);
3189 }
3190
3191 /* Left justify */
3192 while (scan < nbytes)
3193 {
3194 result <<= 8;
3195 scan++;
3196 }
3197 /* Create correct expression */
3198 exp->X_op = O_constant;
3199 exp->X_add_number = result;
3200 /* Fake it so that we can read the next char too */
3201 if (input_line_pointer[0] != '\'' ||
3202 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3203 {
3204 input_line_pointer -= 2;
3205 input_line_pointer[0] = ',';
3206 input_line_pointer[1] = '\'';
3207 }
3208 else
3209 input_line_pointer++;
3210 }
3211 }
3212 \f
3213 #ifdef REPEAT_CONS_EXPRESSIONS
3214
3215 /* Parse a repeat expression for cons. This is used by the MIPS
3216 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3217 object file COUNT times.
3218
3219 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3220
3221 static void
3222 parse_repeat_cons (exp, nbytes)
3223 expressionS *exp;
3224 unsigned int nbytes;
3225 {
3226 expressionS count;
3227 register int i;
3228
3229 expression (exp);
3230
3231 if (*input_line_pointer != ':')
3232 {
3233 /* No repeat count. */
3234 return;
3235 }
3236
3237 ++input_line_pointer;
3238 expression (&count);
3239 if (count.X_op != O_constant
3240 || count.X_add_number <= 0)
3241 {
3242 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3243 return;
3244 }
3245
3246 /* The cons function is going to output this expression once. So we
3247 output it count - 1 times. */
3248 for (i = count.X_add_number - 1; i > 0; i--)
3249 emit_expr (exp, nbytes);
3250 }
3251
3252 #endif /* REPEAT_CONS_EXPRESSIONS */
3253 \f
3254 /* Parse a floating point number represented as a hex constant. This
3255 permits users to specify the exact bits they want in the floating
3256 point number. */
3257
3258 static int
3259 hex_float (float_type, bytes)
3260 int float_type;
3261 char *bytes;
3262 {
3263 int length;
3264 int i;
3265
3266 switch (float_type)
3267 {
3268 case 'f':
3269 case 'F':
3270 case 's':
3271 case 'S':
3272 length = 4;
3273 break;
3274
3275 case 'd':
3276 case 'D':
3277 case 'r':
3278 case 'R':
3279 length = 8;
3280 break;
3281
3282 case 'x':
3283 case 'X':
3284 length = 12;
3285 break;
3286
3287 case 'p':
3288 case 'P':
3289 length = 12;
3290 break;
3291
3292 default:
3293 as_bad ("Unknown floating type type '%c'", float_type);
3294 return -1;
3295 }
3296
3297 /* It would be nice if we could go through expression to parse the
3298 hex constant, but if we get a bignum it's a pain to sort it into
3299 the buffer correctly. */
3300 i = 0;
3301 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3302 {
3303 int d;
3304
3305 /* The MRI assembler accepts arbitrary underscores strewn about
3306 through the hex constant, so we ignore them as well. */
3307 if (*input_line_pointer == '_')
3308 {
3309 ++input_line_pointer;
3310 continue;
3311 }
3312
3313 if (i >= length)
3314 {
3315 as_warn ("Floating point constant too large");
3316 return -1;
3317 }
3318 d = hex_value (*input_line_pointer) << 4;
3319 ++input_line_pointer;
3320 while (*input_line_pointer == '_')
3321 ++input_line_pointer;
3322 if (hex_p (*input_line_pointer))
3323 {
3324 d += hex_value (*input_line_pointer);
3325 ++input_line_pointer;
3326 }
3327 if (target_big_endian)
3328 bytes[i] = d;
3329 else
3330 bytes[length - i - 1] = d;
3331 ++i;
3332 }
3333
3334 if (i < length)
3335 {
3336 if (target_big_endian)
3337 memset (bytes + i, 0, length - i);
3338 else
3339 memset (bytes, 0, length - i);
3340 }
3341
3342 return length;
3343 }
3344
3345 /*
3346 * float_cons()
3347 *
3348 * CONStruct some more frag chars of .floats .ffloats etc.
3349 * Makes 0 or more new frags.
3350 * If need_pass_2 == 1, no frags are emitted.
3351 * This understands only floating literals, not expressions. Sorry.
3352 *
3353 * A floating constant is defined by atof_generic(), except it is preceded
3354 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3355 * reading, I decided to be incompatible. This always tries to give you
3356 * rounded bits to the precision of the pseudo-op. Former AS did premature
3357 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3358 * a choice of 2 flavours of noise according to which of 2 floating-point
3359 * scanners you directed AS to use.
3360 *
3361 * In: input_line_pointer->whitespace before, or '0' of flonum.
3362 *
3363 */
3364
3365 void
3366 float_cons (float_type)
3367 /* Clobbers input_line-pointer, checks end-of-line. */
3368 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3369 {
3370 register char *p;
3371 int length; /* Number of chars in an object. */
3372 register char *err; /* Error from scanning floating literal. */
3373 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3374
3375 if (is_it_end_of_statement ())
3376 {
3377 demand_empty_rest_of_line ();
3378 return;
3379 }
3380
3381 do
3382 {
3383 /* input_line_pointer->1st char of a flonum (we hope!). */
3384 SKIP_WHITESPACE ();
3385
3386 /* Skip any 0{letter} that may be present. Don't even check if the
3387 * letter is legal. Someone may invent a "z" format and this routine
3388 * has no use for such information. Lusers beware: you get
3389 * diagnostics if your input is ill-conditioned.
3390 */
3391 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3392 input_line_pointer += 2;
3393
3394 /* Accept :xxxx, where the x's are hex digits, for a floating
3395 point with the exact digits specified. */
3396 if (input_line_pointer[0] == ':')
3397 {
3398 ++input_line_pointer;
3399 length = hex_float (float_type, temp);
3400 if (length < 0)
3401 {
3402 ignore_rest_of_line ();
3403 return;
3404 }
3405 }
3406 else
3407 {
3408 err = md_atof (float_type, temp, &length);
3409 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3410 know (length > 0);
3411 if (err)
3412 {
3413 as_bad ("Bad floating literal: %s", err);
3414 ignore_rest_of_line ();
3415 return;
3416 }
3417 }
3418
3419 if (!need_pass_2)
3420 {
3421 int count;
3422
3423 count = 1;
3424
3425 #ifdef REPEAT_CONS_EXPRESSIONS
3426 if (*input_line_pointer == ':')
3427 {
3428 expressionS count_exp;
3429
3430 ++input_line_pointer;
3431 expression (&count_exp);
3432 if (count_exp.X_op != O_constant
3433 || count_exp.X_add_number <= 0)
3434 {
3435 as_warn ("unresolvable or nonpositive repeat count; using 1");
3436 }
3437 else
3438 count = count_exp.X_add_number;
3439 }
3440 #endif
3441
3442 while (--count >= 0)
3443 {
3444 p = frag_more (length);
3445 memcpy (p, temp, (unsigned int) length);
3446 }
3447 }
3448 SKIP_WHITESPACE ();
3449 }
3450 while (*input_line_pointer++ == ',');
3451
3452 --input_line_pointer; /* Put terminator back into stream. */
3453 demand_empty_rest_of_line ();
3454 } /* float_cons() */
3455 \f
3456 /*
3457 * stringer()
3458 *
3459 * We read 0 or more ',' seperated, double-quoted strings.
3460 *
3461 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3462 */
3463
3464
3465 void
3466 stringer (append_zero) /* Worker to do .ascii etc statements. */
3467 /* Checks end-of-line. */
3468 register int append_zero; /* 0: don't append '\0', else 1 */
3469 {
3470 register unsigned int c;
3471
3472 #ifdef md_flush_pending_output
3473 md_flush_pending_output ();
3474 #endif
3475
3476 /*
3477 * The following awkward logic is to parse ZERO or more strings,
3478 * comma seperated. Recall a string expression includes spaces
3479 * before the opening '\"' and spaces after the closing '\"'.
3480 * We fake a leading ',' if there is (supposed to be)
3481 * a 1st, expression. We keep demanding expressions for each
3482 * ','.
3483 */
3484 if (is_it_end_of_statement ())
3485 {
3486 c = 0; /* Skip loop. */
3487 ++input_line_pointer; /* Compensate for end of loop. */
3488 }
3489 else
3490 {
3491 c = ','; /* Do loop. */
3492 }
3493 while (c == ',' || c == '<' || c == '"')
3494 {
3495 SKIP_WHITESPACE ();
3496 switch (*input_line_pointer)
3497 {
3498 case '\"':
3499 ++input_line_pointer; /*->1st char of string. */
3500 while (is_a_char (c = next_char_of_string ()))
3501 {
3502 FRAG_APPEND_1_CHAR (c);
3503 }
3504 if (append_zero)
3505 {
3506 FRAG_APPEND_1_CHAR (0);
3507 }
3508 know (input_line_pointer[-1] == '\"');
3509 break;
3510 case '<':
3511 input_line_pointer++;
3512 c = get_single_number ();
3513 FRAG_APPEND_1_CHAR (c);
3514 if (*input_line_pointer != '>')
3515 {
3516 as_bad ("Expected <nn>");
3517 }
3518 input_line_pointer++;
3519 break;
3520 case ',':
3521 input_line_pointer++;
3522 break;
3523 }
3524 SKIP_WHITESPACE ();
3525 c = *input_line_pointer;
3526 }
3527
3528 demand_empty_rest_of_line ();
3529 } /* stringer() */
3530 \f
3531 /* FIXME-SOMEDAY: I had trouble here on characters with the
3532 high bits set. We'll probably also have trouble with
3533 multibyte chars, wide chars, etc. Also be careful about
3534 returning values bigger than 1 byte. xoxorich. */
3535
3536 unsigned int
3537 next_char_of_string ()
3538 {
3539 register unsigned int c;
3540
3541 c = *input_line_pointer++ & CHAR_MASK;
3542 switch (c)
3543 {
3544 case '\"':
3545 c = NOT_A_CHAR;
3546 break;
3547
3548 #ifndef NO_STRING_ESCAPES
3549 case '\\':
3550 switch (c = *input_line_pointer++)
3551 {
3552 case 'b':
3553 c = '\b';
3554 break;
3555
3556 case 'f':
3557 c = '\f';
3558 break;
3559
3560 case 'n':
3561 c = '\n';
3562 break;
3563
3564 case 'r':
3565 c = '\r';
3566 break;
3567
3568 case 't':
3569 c = '\t';
3570 break;
3571
3572 case 'v':
3573 c = '\013';
3574 break;
3575
3576 case '\\':
3577 case '"':
3578 break; /* As itself. */
3579
3580 case '0':
3581 case '1':
3582 case '2':
3583 case '3':
3584 case '4':
3585 case '5':
3586 case '6':
3587 case '7':
3588 case '8':
3589 case '9':
3590 {
3591 long number;
3592 int i;
3593
3594 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3595 {
3596 number = number * 8 + c - '0';
3597 }
3598 c = number & 0xff;
3599 }
3600 --input_line_pointer;
3601 break;
3602
3603 case 'x':
3604 case 'X':
3605 {
3606 long number;
3607
3608 number = 0;
3609 c = *input_line_pointer++;
3610 while (isxdigit (c))
3611 {
3612 if (isdigit (c))
3613 number = number * 16 + c - '0';
3614 else if (isupper (c))
3615 number = number * 16 + c - 'A' + 10;
3616 else
3617 number = number * 16 + c - 'a' + 10;
3618 c = *input_line_pointer++;
3619 }
3620 c = number & 0xff;
3621 --input_line_pointer;
3622 }
3623 break;
3624
3625 case '\n':
3626 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3627 as_warn ("Unterminated string: Newline inserted.");
3628 c = '\n';
3629 break;
3630
3631 default:
3632
3633 #ifdef ONLY_STANDARD_ESCAPES
3634 as_bad ("Bad escaped character in string, '?' assumed");
3635 c = '?';
3636 #endif /* ONLY_STANDARD_ESCAPES */
3637
3638 break;
3639 } /* switch on escaped char */
3640 break;
3641 #endif /* ! defined (NO_STRING_ESCAPES) */
3642
3643 default:
3644 break;
3645 } /* switch on char */
3646 return (c);
3647 } /* next_char_of_string() */
3648 \f
3649 static segT
3650 get_segmented_expression (expP)
3651 register expressionS *expP;
3652 {
3653 register segT retval;
3654
3655 retval = expression (expP);
3656 if (expP->X_op == O_illegal
3657 || expP->X_op == O_absent
3658 || expP->X_op == O_big)
3659 {
3660 as_bad ("expected address expression; zero assumed");
3661 expP->X_op = O_constant;
3662 expP->X_add_number = 0;
3663 retval = absolute_section;
3664 }
3665 return retval;
3666 }
3667
3668 static segT
3669 get_known_segmented_expression (expP)
3670 register expressionS *expP;
3671 {
3672 register segT retval;
3673
3674 if ((retval = get_segmented_expression (expP)) == undefined_section)
3675 {
3676 /* There is no easy way to extract the undefined symbol from the
3677 expression. */
3678 if (expP->X_add_symbol != NULL
3679 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3680 as_warn ("symbol \"%s\" undefined; zero assumed",
3681 S_GET_NAME (expP->X_add_symbol));
3682 else
3683 as_warn ("some symbol undefined; zero assumed");
3684 retval = absolute_section;
3685 expP->X_op = O_constant;
3686 expP->X_add_number = 0;
3687 }
3688 know (retval == absolute_section || SEG_NORMAL (retval));
3689 return (retval);
3690 } /* get_known_segmented_expression() */
3691
3692 offsetT
3693 get_absolute_expression ()
3694 {
3695 expressionS exp;
3696
3697 expression (&exp);
3698 if (exp.X_op != O_constant)
3699 {
3700 if (exp.X_op != O_absent)
3701 as_bad ("bad or irreducible absolute expression; zero assumed");
3702 exp.X_add_number = 0;
3703 }
3704 return exp.X_add_number;
3705 }
3706
3707 char /* return terminator */
3708 get_absolute_expression_and_terminator (val_pointer)
3709 long *val_pointer; /* return value of expression */
3710 {
3711 /* FIXME: val_pointer should probably be offsetT *. */
3712 *val_pointer = (long) get_absolute_expression ();
3713 return (*input_line_pointer++);
3714 }
3715 \f
3716 /*
3717 * demand_copy_C_string()
3718 *
3719 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3720 * Give a warning if that happens.
3721 */
3722 char *
3723 demand_copy_C_string (len_pointer)
3724 int *len_pointer;
3725 {
3726 register char *s;
3727
3728 if ((s = demand_copy_string (len_pointer)) != 0)
3729 {
3730 register int len;
3731
3732 for (len = *len_pointer; len > 0; len--)
3733 {
3734 if (*s == 0)
3735 {
3736 s = 0;
3737 len = 1;
3738 *len_pointer = 0;
3739 as_bad ("This string may not contain \'\\0\'");
3740 }
3741 }
3742 }
3743 return s;
3744 }
3745 \f
3746 /*
3747 * demand_copy_string()
3748 *
3749 * Demand string, but return a safe (=private) copy of the string.
3750 * Return NULL if we can't read a string here.
3751 */
3752 char *
3753 demand_copy_string (lenP)
3754 int *lenP;
3755 {
3756 register unsigned int c;
3757 register int len;
3758 char *retval;
3759
3760 len = 0;
3761 SKIP_WHITESPACE ();
3762 if (*input_line_pointer == '\"')
3763 {
3764 input_line_pointer++; /* Skip opening quote. */
3765
3766 while (is_a_char (c = next_char_of_string ()))
3767 {
3768 obstack_1grow (&notes, c);
3769 len++;
3770 }
3771 /* JF this next line is so demand_copy_C_string will return a
3772 null terminated string. */
3773 obstack_1grow (&notes, '\0');
3774 retval = obstack_finish (&notes);
3775 }
3776 else
3777 {
3778 as_warn ("Missing string");
3779 retval = NULL;
3780 ignore_rest_of_line ();
3781 }
3782 *lenP = len;
3783 return (retval);
3784 } /* demand_copy_string() */
3785 \f
3786 /*
3787 * is_it_end_of_statement()
3788 *
3789 * In: Input_line_pointer->next character.
3790 *
3791 * Do: Skip input_line_pointer over all whitespace.
3792 *
3793 * Out: 1 if input_line_pointer->end-of-line.
3794 */
3795 int
3796 is_it_end_of_statement ()
3797 {
3798 SKIP_WHITESPACE ();
3799 return (is_end_of_line[(unsigned char) *input_line_pointer]);
3800 } /* is_it_end_of_statement() */
3801
3802 void
3803 equals (sym_name)
3804 char *sym_name;
3805 {
3806 register symbolS *symbolP; /* symbol we are working with */
3807 char *stop;
3808 char stopc;
3809
3810 input_line_pointer++;
3811 if (*input_line_pointer == '=')
3812 input_line_pointer++;
3813
3814 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
3815 input_line_pointer++;
3816
3817 if (flag_mri)
3818 stop = mri_comment_field (&stopc);
3819
3820 if (sym_name[0] == '.' && sym_name[1] == '\0')
3821 {
3822 /* Turn '. = mumble' into a .org mumble */
3823 register segT segment;
3824 expressionS exp;
3825
3826 segment = get_known_segmented_expression (&exp);
3827 if (!need_pass_2)
3828 do_org (segment, &exp, 0);
3829 }
3830 else
3831 {
3832 symbolP = symbol_find_or_make (sym_name);
3833 pseudo_set (symbolP);
3834 }
3835
3836 if (flag_mri)
3837 mri_comment_end (stop, stopc);
3838 } /* equals() */
3839
3840 /* .include -- include a file at this point. */
3841
3842 /* ARGSUSED */
3843 void
3844 s_include (arg)
3845 int arg;
3846 {
3847 char *newbuf;
3848 char *filename;
3849 int i;
3850 FILE *try;
3851 char *path;
3852
3853 if (! flag_mri)
3854 filename = demand_copy_string (&i);
3855 else
3856 {
3857 SKIP_WHITESPACE ();
3858 i = 0;
3859 while (! is_end_of_line[(unsigned char) *input_line_pointer]
3860 && *input_line_pointer != ' '
3861 && *input_line_pointer != '\t')
3862 {
3863 obstack_1grow (&notes, *input_line_pointer);
3864 ++input_line_pointer;
3865 ++i;
3866 }
3867 obstack_1grow (&notes, '\0');
3868 filename = obstack_finish (&notes);
3869 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3870 ++input_line_pointer;
3871 }
3872 demand_empty_rest_of_line ();
3873 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
3874 for (i = 0; i < include_dir_count; i++)
3875 {
3876 strcpy (path, include_dirs[i]);
3877 strcat (path, "/");
3878 strcat (path, filename);
3879 if (0 != (try = fopen (path, "r")))
3880 {
3881 fclose (try);
3882 goto gotit;
3883 }
3884 }
3885 free (path);
3886 path = filename;
3887 gotit:
3888 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3889 newbuf = input_scrub_include_file (path, input_line_pointer);
3890 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3891 } /* s_include() */
3892
3893 void
3894 add_include_dir (path)
3895 char *path;
3896 {
3897 int i;
3898
3899 if (include_dir_count == 0)
3900 {
3901 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
3902 include_dirs[0] = "."; /* Current dir */
3903 include_dir_count = 2;
3904 }
3905 else
3906 {
3907 include_dir_count++;
3908 include_dirs = (char **) realloc (include_dirs,
3909 include_dir_count * sizeof (*include_dirs));
3910 }
3911
3912 include_dirs[include_dir_count - 1] = path; /* New one */
3913
3914 i = strlen (path);
3915 if (i > include_dir_maxlen)
3916 include_dir_maxlen = i;
3917 } /* add_include_dir() */
3918
3919 void
3920 s_ignore (arg)
3921 int arg;
3922 {
3923 while (!is_end_of_line[(unsigned char) *input_line_pointer])
3924 {
3925 ++input_line_pointer;
3926 }
3927 ++input_line_pointer;
3928 }
3929
3930
3931 void
3932 read_print_statistics (file)
3933 FILE *file;
3934 {
3935 hash_print_statistics (file, "pseudo-op table", po_hash);
3936 }
3937
3938 /* end of read.c */
This page took 0.131862 seconds and 4 git commands to generate.