* as.h (bfd_alloc_by_size_t): Don't declare.
[deliverable/binutils-gdb.git] / gas / as.h
1 /* as.h - global header file
2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 1997
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 #ifndef GAS
23 #define GAS 1
24 /*
25 * I think this stuff is largely out of date. xoxorich.
26 *
27 * CAPITALISED names are #defined.
28 * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
29 * "lowercaseT" is a typedef of "lowercase" objects.
30 * "lowercaseP" is type "pointer to object of type 'lowercase'".
31 * "lowercaseS" is typedef struct ... lowercaseS.
32 *
33 * #define DEBUG to enable all the "know" assertion tests.
34 * #define SUSPECT when debugging hash code.
35 * #define COMMON as "extern" for all modules except one, where you #define
36 * COMMON as "".
37 * If TEST is #defined, then we are testing a module: #define COMMON as "".
38 */
39
40 #include "config.h"
41
42 /* This is the code recommended in the autoconf documentation, almost
43 verbatim. If it doesn't work for you, let me know, and notify
44 djm@gnu.ai.mit.edu as well. */
45 /* Added #undef for DJ Delorie. The right fix is to ensure that as.h
46 is included first, before even any system header files, in all files
47 that use it. KR 1994.11.03 */
48 /* Added void* version for STDC case. This is to be compatible with
49 the declaration in bison.simple, used for m68k operand parsing.
50 --KR 1995.08.08 */
51 /* Force void* decl for hpux. This is what Bison uses. --KR 1995.08.16 */
52
53 /* AIX requires this to be the first thing in the file. */
54 #ifdef __GNUC__
55 # undef alloca
56 # define alloca __builtin_alloca
57 #else
58 # if HAVE_ALLOCA_H
59 # include <alloca.h>
60 # else
61 # ifdef _AIX
62 #pragma alloca
63 # else
64 # ifndef alloca /* predefined by HP cc +Olibcalls */
65 # if !defined (__STDC__) && !defined (__hpux)
66 char *alloca ();
67 # else
68 void *alloca ();
69 # endif /* __STDC__, __hpux */
70 # endif /* alloca */
71 # endif /* _AIX */
72 # endif /* HAVE_ALLOCA_H */
73 #endif
74
75 /* Now, tend to the rest of the configuration. */
76
77 /* System include files first... */
78 #include <stdio.h>
79 #include <ctype.h>
80 #ifdef HAVE_STRING_H
81 #include <string.h>
82 #else
83 #ifdef HAVE_STRINGS_H
84 #include <strings.h>
85 #endif
86 #endif
87 #ifdef HAVE_STDLIB_H
88 #include <stdlib.h>
89 #endif
90 #ifdef HAVE_UNISTD_H
91 #include <unistd.h>
92 #endif
93 #ifdef HAVE_SYS_TYPES_H
94 /* for size_t, pid_t */
95 #include <sys/types.h>
96 #endif
97
98 #include <getopt.h>
99 /* The first getopt value for machine-independent long options.
100 150 isn't special; it's just an arbitrary non-ASCII char value. */
101 #define OPTION_STD_BASE 150
102 /* The first getopt value for machine-dependent long options.
103 170 gives the standard options room to grow. */
104 #define OPTION_MD_BASE 170
105
106 #ifdef DEBUG
107 #undef NDEBUG
108 #endif
109 #if !defined (__GNUC__) || __GNUC_MINOR__ <= 5
110 #define __PRETTY_FUNCTION__ ((char*)0)
111 #endif
112 #if 0
113
114 /* Handle lossage with assert.h. */
115 #ifndef BROKEN_ASSERT
116 #include <assert.h>
117 #else /* BROKEN_ASSERT */
118 #ifndef NDEBUG
119 #define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
120 #else
121 #define assert(p) ((p), 0)
122 #endif
123 #endif /* BROKEN_ASSERT */
124
125 #else
126
127 #define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
128 #undef abort
129 #define abort() as_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
130
131 #endif
132
133
134 /* Now GNU header files... */
135 #include <ansidecl.h>
136 #ifdef BFD_ASSEMBLER
137 #include <bfd.h>
138 #endif
139 #include <libiberty.h>
140
141 /* Define the standard progress macros. */
142 #include <progress.h>
143
144 /* This doesn't get taken care of anywhere. */
145 #ifndef __MWERKS__ /* Metrowerks C chokes on the "defined (inline)" */
146 #if !defined (__GNUC__) && !defined (inline)
147 #define inline
148 #endif
149 #endif /* !__MWERKS__ */
150
151 /* Other stuff from config.h. */
152 #ifdef NEED_DECLARATION_STRSTR
153 extern char *strstr ();
154 #endif
155 #ifdef NEED_DECLARATION_MALLOC
156 extern PTR malloc ();
157 extern PTR realloc ();
158 #endif
159 #ifdef NEED_DECLARATION_FREE
160 extern void free ();
161 #endif
162 #ifdef NEED_DECLARATION_ERRNO
163 extern int errno;
164 #endif
165
166 /* This is needed for VMS with DEC C. */
167 #if ! defined (__GNUC__) && ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
168 #define unlink remove
169 #endif
170
171 /* Hack to make "gcc -Wall" not complain about obstack macros. */
172 #if !defined (memcpy) && !defined (bcopy)
173 #define bcopy(src,dest,size) memcpy(dest,src,size)
174 #endif
175
176 /* Make Saber happier on obstack.h. */
177 #ifdef SABER
178 #undef __PTR_TO_INT
179 #define __PTR_TO_INT(P) ((int)(P))
180 #undef __INT_TO_PTR
181 #define __INT_TO_PTR(P) ((char *)(P))
182 #endif
183
184 #ifndef __LINE__
185 #define __LINE__ "unknown"
186 #endif /* __LINE__ */
187
188 #ifndef __FILE__
189 #define __FILE__ "unknown"
190 #endif /* __FILE__ */
191
192 #ifndef FOPEN_WB
193 #ifdef GO32
194 #include "fopen-bin.h"
195 #else
196 #include "fopen-same.h"
197 #endif
198 #endif
199
200 #ifndef EXIT_SUCCESS
201 #define EXIT_SUCCESS 0
202 #define EXIT_FAILURE 1
203 #endif
204
205 #define obstack_chunk_alloc xmalloc
206 #define obstack_chunk_free xfree
207
208 #define xfree free
209
210 #define BAD_CASE(val) \
211 { \
212 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
213 (long) val, __LINE__, __FILE__); \
214 }
215 \f
216 #include "flonum.h"
217
218 /* These are assembler-wide concepts */
219
220 #ifdef BFD_ASSEMBLER
221 extern bfd *stdoutput;
222 typedef bfd_vma addressT;
223 typedef bfd_signed_vma offsetT;
224 #else
225 typedef unsigned long addressT;
226 typedef long offsetT;
227 #endif
228
229 /* Type of symbol value, etc. For use in prototypes. */
230 typedef addressT valueT;
231
232 #ifndef COMMON
233 #ifdef TEST
234 #define COMMON /* declare our COMMONs storage here. */
235 #else
236 #define COMMON extern /* our commons live elswhere */
237 #endif
238 #endif
239 /* COMMON now defined */
240
241 #ifdef DEBUG
242 #ifndef know
243 #define know(p) assert(p) /* Verify our assumptions! */
244 #endif /* not yet defined */
245 #else
246 #define know(p) /* know() checks are no-op.ed */
247 #endif
248 \f
249 /* input_scrub.c */
250
251 /*
252 * Supplies sanitised buffers to read.c.
253 * Also understands printing line-number part of error messages.
254 */
255 \f
256
257 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
258
259 #ifndef BFD_ASSEMBLER
260
261 #ifdef MANY_SEGMENTS
262 #include "bfd.h"
263 #define N_SEGMENTS 40
264 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E39)
265 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9,\
266 SEG_E10,SEG_E11,SEG_E12,SEG_E13,SEG_E14,SEG_E15,SEG_E16,SEG_E17,SEG_E18,SEG_E19,\
267 SEG_E20,SEG_E21,SEG_E22,SEG_E23,SEG_E24,SEG_E25,SEG_E26,SEG_E27,SEG_E28,SEG_E29,\
268 SEG_E30,SEG_E31,SEG_E32,SEG_E33,SEG_E34,SEG_E35,SEG_E36,SEG_E37,SEG_E38,SEG_E39
269 #define SEG_TEXT SEG_E0
270 #define SEG_DATA SEG_E1
271 #define SEG_BSS SEG_E2
272 #define SEG_LAST SEG_E39
273 #else
274 #define N_SEGMENTS 3
275 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
276 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
277 #endif
278
279 typedef enum _segT
280 {
281 SEG_ABSOLUTE = 0,
282 SEG_LIST,
283 SEG_UNKNOWN,
284 SEG_GOOF, /* Only happens if AS has a logic error. */
285 /* Invented so we don't crash printing */
286 /* error message involving weird segment. */
287 SEG_EXPR, /* Intermediate expression values. */
288 SEG_DEBUG, /* Debug segment */
289 SEG_NTV, /* Transfert vector preload segment */
290 SEG_PTV, /* Transfert vector postload segment */
291 SEG_REGISTER /* Mythical: a register-valued expression */
292 } segT;
293
294 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
295 #else
296 typedef asection *segT;
297 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
298 && (SEG) != undefined_section \
299 && (SEG) != reg_section \
300 && (SEG) != expr_section)
301 #endif
302 typedef int subsegT;
303
304 /* What subseg we are accreting now? */
305 COMMON subsegT now_subseg;
306
307 /* Segment our instructions emit to. */
308 COMMON segT now_seg;
309
310 #ifdef BFD_ASSEMBLER
311 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
312 #else
313 extern char const *const seg_name[];
314 #define segment_name(SEG) seg_name[(int) (SEG)]
315 #endif
316
317 #ifndef BFD_ASSEMBLER
318 extern int section_alignment[];
319 #endif
320
321 #ifdef BFD_ASSEMBLER
322 extern segT reg_section, expr_section;
323 /* Shouldn't these be eliminated someday? */
324 extern segT text_section, data_section, bss_section;
325 #define absolute_section bfd_abs_section_ptr
326 #define undefined_section bfd_und_section_ptr
327 #else
328 #define reg_section SEG_REGISTER
329 #define expr_section SEG_EXPR
330 #define text_section SEG_TEXT
331 #define data_section SEG_DATA
332 #define bss_section SEG_BSS
333 #define absolute_section SEG_ABSOLUTE
334 #define undefined_section SEG_UNKNOWN
335 #endif
336
337 /* relax() */
338
339 enum _relax_state
340 {
341 /* Variable chars to be repeated fr_offset times.
342 Fr_symbol unused. Used with fr_offset == 0 for a
343 constant length frag. */
344 rs_fill = 1,
345
346 /* Align. The fr_offset field holds the power of 2 to which to
347 align. The fr_var field holds the number of characters in the
348 fill pattern. The fr_subtype field holds the maximum number of
349 bytes to skip when aligning, or 0 if there is no maximum. */
350 rs_align,
351
352 /* Align code. The fr_offset field holds the power of 2 to which
353 to align. This type is only generated by machine specific
354 code, which is normally responsible for handling the fill
355 pattern. The fr_subtype field holds the maximum number of
356 bytes to skip when aligning, or 0 if there is no maximum. */
357 rs_align_code,
358
359 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
360 character. */
361 rs_org,
362
363 #ifndef WORKING_DOT_WORD
364 /* JF: gunpoint */
365 rs_broken_word,
366 #endif
367
368 /* machine-specific relaxable (or similarly alterable) instruction */
369 rs_machine_dependent,
370
371 /* .space directive with expression operand that needs to be computed
372 later. Similar to rs_org, but different.
373 fr_symbol: operand
374 1 variable char: fill character */
375 rs_space
376 };
377
378 typedef enum _relax_state relax_stateT;
379
380 /* This type is used in prototypes, so it can't be a type that will be
381 widened for argument passing. */
382 typedef unsigned int relax_substateT;
383
384 /* Enough bits for address, but still an integer type.
385 Could be a problem, cross-assembling for 64-bit machines. */
386 typedef addressT relax_addressT;
387 \f
388
389 /* frags.c */
390
391 /*
392 * A code fragment (frag) is some known number of chars, followed by some
393 * unknown number of chars. Typically the unknown number of chars is an
394 * instruction address whose size is yet unknown. We always know the greatest
395 * possible size the unknown number of chars may become, and reserve that
396 * much room at the end of the frag.
397 * Once created, frags do not change address during assembly.
398 * We chain the frags in (a) forward-linked list(s). The object-file address
399 * of the 1st char of a frag is generally not known until after relax().
400 * Many things at assembly time describe an address by {object-file-address
401 * of a particular frag}+offset.
402
403 BUG: it may be smarter to have a single pointer off to various different
404 notes for different frag kinds. See how code pans
405 */
406 struct frag
407 {
408 /* Object file address. */
409 addressT fr_address;
410 /* Chain forward; ascending address order. Rooted in frch_root. */
411 struct frag *fr_next;
412
413 /* (Fixed) number of chars we know we have. May be 0. */
414 offsetT fr_fix;
415 /* (Variable) number of chars after above. May be 0. */
416 offsetT fr_var;
417 /* For variable-length tail. */
418 struct symbol *fr_symbol;
419 /* For variable-length tail. */
420 offsetT fr_offset;
421 /* Points to opcode low addr byte, for relaxation. */
422 char *fr_opcode;
423
424 #ifndef NO_LISTING
425 struct list_info_struct *line;
426 #endif
427
428 /* What state is my tail in? */
429 relax_stateT fr_type;
430 relax_substateT fr_subtype;
431
432 /* These are needed only on the NS32K machines. But since we don't
433 include targ-cpu.h until after this structure has been defined,
434 we can't really conditionalize it. This code should be
435 rearranged a bit to make that possible.
436
437 In the meantime, if we get stuck like this with any other target,
438 create a union here. */
439 char fr_pcrel_adjust, fr_bsr;
440
441 /* Where the frag was created, or where it became a variant frag. */
442 char *fr_file;
443 unsigned int fr_line;
444
445 /* Data begins here. */
446 char fr_literal[1];
447 };
448
449 #define SIZEOF_STRUCT_FRAG \
450 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
451 /* We want to say fr_literal[0] above. */
452
453 typedef struct frag fragS;
454
455 /* Current frag we are building. This frag is incomplete. It is, however,
456 included in frchain_now. The fr_fix field is bogus; instead, use:
457 obstack_next_free(&frags)-frag_now->fr_literal. */
458 COMMON fragS *frag_now;
459 extern int frag_now_fix ();
460
461 /* For foreign-segment symbol fixups. */
462 COMMON fragS zero_address_frag;
463 /* For local common (N_BSS segment) fixups. */
464 COMMON fragS bss_address_frag;
465
466 /* main program "as.c" (command arguments etc) */
467
468 COMMON unsigned char flag_no_comments; /* -f */
469 COMMON unsigned char flag_debug; /* -D */
470 COMMON unsigned char flag_signed_overflow_ok; /* -J */
471 #ifndef WORKING_DOT_WORD
472 COMMON unsigned char flag_warn_displacement; /* -K */
473 #endif
474
475 /* True if local symbols should be retained. */
476 COMMON int flag_keep_locals; /* -L */
477
478 /* True if we are assembling in MRI mode. */
479 COMMON int flag_mri;
480
481 /* True if we are assembling in m68k MRI mode. */
482 COMMON int flag_m68k_mri;
483
484 /* Should the data section be made read-only and appended to the text
485 section? */
486 COMMON unsigned char flag_readonly_data_in_text; /* -R */
487
488 /* True if warnings should be inhibited. */
489 COMMON int flag_no_warnings; /* -W */
490
491 /* True if we should attempt to generate output even if non-fatal errors
492 are detected. */
493 COMMON unsigned char flag_always_generate_output; /* -Z */
494
495 /* This is true if the assembler should output time and space usage. */
496
497 COMMON unsigned char flag_print_statistics;
498
499 /* name of emitted object file */
500 COMMON char *out_file_name;
501
502 /* name of file defining extensions to the basic instruction set */
503 COMMON char *insttbl_file_name;
504
505 /* TRUE if we need a second pass. */
506 COMMON int need_pass_2;
507
508 /* TRUE if we should do no relaxing, and
509 leave lots of padding. */
510 COMMON int linkrelax;
511
512 /* TRUE if we should produce a listing. */
513 extern int listing;
514
515 /* Maximum level of macro nesting. */
516 extern int max_macro_nest;
517
518 /* Obstack chunk size. Keep large for efficient space use, make small to
519 increase malloc calls for monitoring memory allocation. */
520 extern int chunksize;
521
522 struct _pseudo_type
523 {
524 /* assembler mnemonic, lower case, no '.' */
525 const char *poc_name;
526 /* Do the work */
527 void (*poc_handler) PARAMS ((int));
528 /* Value to pass to handler */
529 int poc_val;
530 };
531
532 typedef struct _pseudo_type pseudo_typeS;
533
534 /* Prefer varargs for non-ANSI compiler, since some will barf if the
535 ellipsis definition is used with a no-arguments declaration. */
536 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
537 #undef HAVE_STDARG_H
538 #endif
539
540 #if defined (HAVE_STDARG_H)
541 #define USE_STDARG
542 #endif
543 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
544 #define USE_VARARGS
545 #endif
546
547 #ifdef USE_STDARG
548 #if (__GNUC__ >= 2) && !defined(VMS)
549 /* for use with -Wformat */
550 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
551 __attribute__ ((format (printf, 1, 2)))
552 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
553 const char *format, ...) \
554 __attribute__ ((format (printf, 3, 4)))
555 #else /* ANSI C with stdarg, but not GNU C */
556 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
557 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
558 unsigned int line, \
559 const char *format, ...))
560 #endif
561 #else /* not using stdarg */
562 #define PRINTF_LIKE(FCN) void FCN ()
563 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
564 #endif
565
566 PRINTF_LIKE (as_bad);
567 PRINTF_LIKE (as_fatal);
568 PRINTF_LIKE (as_tsktsk);
569 PRINTF_LIKE (as_warn);
570 PRINTF_WHERE_LIKE (as_bad_where);
571 PRINTF_WHERE_LIKE (as_warn_where);
572 void as_assert PARAMS ((const char *, int, const char *));
573 void as_abort PARAMS ((const char *, int, const char *));
574
575 void fprint_value PARAMS ((FILE *file, addressT value));
576 void sprint_value PARAMS ((char *buf, addressT value));
577
578 int had_errors PARAMS ((void));
579 int had_warnings PARAMS ((void));
580
581 void print_version_id PARAMS ((void));
582 char *app_push PARAMS ((void));
583 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
584 char *input_scrub_include_file PARAMS ((char *filename, char *position));
585 char *input_scrub_new_file PARAMS ((char *filename));
586 char *input_scrub_next_buffer PARAMS ((char **bufp));
587 int do_scrub_chars PARAMS ((int (*get) (char **), char *to, int tolen));
588 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
589 long exponent_bits));
590 int had_err PARAMS ((void));
591 int ignore_input PARAMS ((void));
592 int seen_at_least_1_file PARAMS ((void));
593 void app_pop PARAMS ((char *arg));
594 void as_howmuch PARAMS ((FILE * stream));
595 void as_perror PARAMS ((const char *gripe, const char *filename));
596 void as_where PARAMS ((char **namep, unsigned int *linep));
597 void bump_line_counters PARAMS ((void));
598 void do_scrub_begin PARAMS ((int));
599 void input_scrub_begin PARAMS ((void));
600 void input_scrub_close PARAMS ((void));
601 void input_scrub_end PARAMS ((void));
602 void new_logical_line PARAMS ((char *fname, int line_number));
603 void subsegs_begin PARAMS ((void));
604 void subseg_change PARAMS ((segT seg, int subseg));
605 segT subseg_new PARAMS ((const char *name, subsegT subseg));
606 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
607 void subseg_set PARAMS ((segT seg, subsegT subseg));
608 #ifdef BFD_ASSEMBLER
609 segT subseg_get PARAMS ((const char *, int));
610 #endif
611
612 struct expressionS;
613 struct fix;
614 struct symbol;
615 struct relax_type;
616
617 #ifdef BFD_ASSEMBLER
618 /* literal.c */
619 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
620 #endif
621
622 #include "expr.h" /* Before targ-*.h */
623
624 /* this one starts the chain of target dependant headers */
625 #include "targ-env.h"
626
627 #include "struc-symbol.h"
628 #include "write.h"
629 #include "frags.h"
630 #include "hash.h"
631 #include "read.h"
632 #include "symbols.h"
633
634 #include "tc.h"
635 #include "obj.h"
636
637 #ifdef USE_EMULATIONS
638 #include "emul.h"
639 #endif
640 #include "listing.h"
641
642 #ifndef LOCAL_LABELS_DOLLAR
643 #define LOCAL_LABELS_DOLLAR 0
644 #endif
645
646 #ifndef LOCAL_LABELS_FB
647 #define LOCAL_LABELS_FB 0
648 #endif
649
650 #endif /* GAS */
651
652 /* end of as.h */
This page took 0.057075 seconds and 5 git commands to generate.