* as.h: Don't declare parameters for strstr.
[platform/upstream/binutils.git] / gas / as.h
1 /* as.h - global header file
2    Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4    This file is part of GAS, the GNU Assembler.
5
6    GAS is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GAS is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GAS; see the file COPYING.  If not, write to
18    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #ifndef GAS
21 #define GAS 1
22 /*
23  * I think this stuff is largely out of date.  xoxorich.
24  *
25  * CAPITALISED names are #defined.
26  * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
27  * "lowercaseT" is a typedef of "lowercase" objects.
28  * "lowercaseP" is type "pointer to object of type 'lowercase'".
29  * "lowercaseS" is typedef struct ... lowercaseS.
30  *
31  * #define DEBUG to enable all the "know" assertion tests.
32  * #define SUSPECT when debugging hash code.
33  * #define COMMON as "extern" for all modules except one, where you #define
34  *      COMMON as "".
35  * If TEST is #defined, then we are testing a module: #define COMMON as "".
36  */
37
38 /* These #defines are for parameters of entire assembler. */
39
40 /* These #includes are for type definitions etc. */
41
42 #include "config.h"
43
44 #include <stdio.h>
45 #ifdef DEBUG
46 #undef NDEBUG
47 #endif
48 #include <assert.h>
49
50 #include <ansidecl.h>
51 #ifdef BFD_ASSEMBLER
52 #include <bfd.h>
53 #endif
54 #include "host.h"
55 #include "flonum.h"
56
57 /* Make Saber happier on obstack.h.  */
58 #ifdef SABER
59 #undef  __PTR_TO_INT
60 #define __PTR_TO_INT(P) ((int)(P))
61 #undef  __INT_TO_PTR
62 #define __INT_TO_PTR(P) ((char *)(P))
63 #endif
64
65 #ifndef __LINE__
66 #define __LINE__ "unknown"
67 #endif /* __LINE__ */
68
69 #ifndef __FILE__
70 #define __FILE__ "unknown"
71 #endif /* __FILE__ */
72
73 #ifndef __STDC__
74 #ifndef const
75 #define const
76 #endif
77 #ifndef volatile
78 #define volatile
79 #endif
80 #endif /* ! __STDC__ */
81
82 #if !defined (__GNUC__) && !defined (inline)
83 #define inline
84 #endif
85
86 #ifndef FOPEN_WB
87 #include "fopen-same.h"
88 #endif
89
90 #define obstack_chunk_alloc xmalloc
91 #define obstack_chunk_free xfree
92
93 #define xfree free
94
95 #define BAD_CASE(val) \
96 { \
97       as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
98                (long) val, __LINE__, __FILE__); \
99            }
100
101 /* Version 2.1 of Solaris had problems with this declaration, but I
102    think that bug has since been fixed.  If it causes problems on your
103    system, just delete it.  */
104 extern char *strstr ();
105 \f
106
107 /* These are assembler-wide concepts */
108
109 #ifdef BFD_ASSEMBLER
110 extern bfd *stdoutput;
111 typedef bfd_vma addressT;
112 typedef bfd_signed_vma offsetT;
113 #else
114 typedef unsigned long addressT;
115 typedef long offsetT;
116 #endif
117
118 /* Type of symbol value, etc.  For use in prototypes.  */
119 typedef addressT valueT;
120
121 #ifndef COMMON
122 #ifdef TEST
123 #define COMMON                  /* declare our COMMONs storage here. */
124 #else
125 #define COMMON extern           /* our commons live elswhere */
126 #endif
127 #endif
128 /* COMMON now defined */
129
130 #ifdef DEBUG
131 #ifndef know
132 #define know(p) assert(p)       /* Verify our assumptions! */
133 #endif /* not yet defined */
134 #else
135 #define know(p)                 /* know() checks are no-op.ed */
136 #endif
137
138 #if defined (BROKEN_ASSERT) && !defined (NDEBUG)
139 /* Used on machines where the "assert" macro is buggy.  (For example, on the
140    RS/6000, Reiser-cpp substitution is done to put the condition into a
141    string, so if the condition contains a string, parse errors result.)  If
142    the condition fails, just drop core file.  */
143 #undef assert
144 #define assert(p) ((p) ? 0 : (abort (), 0))
145 #endif
146 \f
147 /* input_scrub.c */
148
149 /*
150  * Supplies sanitised buffers to read.c.
151  * Also understands printing line-number part of error messages.
152  */
153 \f
154
155 /* subsegs.c     Sub-segments. Also, segment(=expression type)s.*/
156
157 #ifndef BFD_ASSEMBLER
158
159 #ifdef MANY_SEGMENTS
160 #include "bfd.h"
161 #define N_SEGMENTS 10
162 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
163 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
164 #define SEG_TEXT SEG_E0
165 #define SEG_DATA SEG_E1
166 #define SEG_BSS SEG_E2
167 #else
168 #define N_SEGMENTS 3
169 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
170 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
171 #endif
172
173 typedef enum _segT
174   {
175     SEG_ABSOLUTE = 0,
176     SEG_LIST,
177     SEG_UNKNOWN,
178     SEG_GOOF,                   /* Only happens if AS has a logic error. */
179     /* Invented so we don't crash printing */
180     /* error message involving weird segment. */
181     SEG_EXPR,                   /* Intermediate expression values. */
182     SEG_DEBUG,                  /* Debug segment */
183     SEG_NTV,                    /* Transfert vector preload segment */
184     SEG_PTV,                    /* Transfert vector postload segment */
185     SEG_REGISTER                /* Mythical: a register-valued expression */
186   } segT;
187
188 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
189 #else
190 typedef asection *segT;
191 #define SEG_NORMAL(SEG)         ((SEG) != absolute_section      \
192                                  && (SEG) != undefined_section  \
193                                  && (SEG) != reg_section        \
194                                  && (SEG) != expr_section)
195 #endif
196 typedef int subsegT;
197
198 /* What subseg we are accreting now? */
199 COMMON subsegT now_subseg;
200
201 /* Segment our instructions emit to. */
202 COMMON segT now_seg;
203
204 #ifdef BFD_ASSEMBLER
205 #define segment_name(SEG)       bfd_get_section_name (stdoutput, SEG)
206 #else
207 extern char *const seg_name[];
208 #define segment_name(SEG)       seg_name[(int) (SEG)]
209 #endif
210
211 #ifndef BFD_ASSEMBLER
212 extern int section_alignment[];
213 #endif
214
215 #ifdef BFD_ASSEMBLER
216 extern segT reg_section, expr_section;
217 /* Shouldn't these be eliminated someday?  */
218 extern segT text_section, data_section, bss_section;
219 #define absolute_section        (&bfd_abs_section)
220 #define undefined_section       (&bfd_und_section)
221 #else
222 #define reg_section             SEG_REGISTER
223 #define expr_section            SEG_EXPR
224 #define text_section            SEG_TEXT
225 #define data_section            SEG_DATA
226 #define bss_section             SEG_BSS
227 #define absolute_section        SEG_ABSOLUTE
228 #define undefined_section       SEG_UNKNOWN
229 #endif
230
231 /* relax() */
232
233 typedef enum _relax_state
234   {
235     /* Variable chars to be repeated fr_offset times.
236        Fr_symbol unused. Used with fr_offset == 0 for a
237        constant length frag. */
238     rs_fill = 1,
239
240     /* Align: Fr_offset: power of 2.  Variable chars: fill pattern. */
241     rs_align,
242
243     /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
244        character. */
245     rs_org,
246
247     rs_machine_dependent
248
249 #ifndef WORKING_DOT_WORD
250     /* JF: gunpoint */
251       , rs_broken_word
252 #endif
253   } relax_stateT;
254
255 /* typedef unsigned char relax_substateT; */
256 /* JF this is more likely to leave the end of a struct frag on an align
257    boundry.  Be very careful with this.  */
258 typedef unsigned long relax_substateT;
259
260 /* Enough bits for address, but still an integer type.
261    Could be a problem, cross-assembling for 64-bit machines.  */
262 typedef addressT relax_addressT;
263 \f
264
265 /* frags.c */
266
267 /*
268  * A code fragment (frag) is some known number of chars, followed by some
269  * unknown number of chars. Typically the unknown number of chars is an
270  * instruction address whose size is yet unknown. We always know the greatest
271  * possible size the unknown number of chars may become, and reserve that
272  * much room at the end of the frag.
273  * Once created, frags do not change address during assembly.
274  * We chain the frags in (a) forward-linked list(s). The object-file address
275  * of the 1st char of a frag is generally not known until after relax().
276  * Many things at assembly time describe an address by {object-file-address
277  * of a particular frag}+offset.
278
279  BUG: it may be smarter to have a single pointer off to various different
280  notes for different frag kinds. See how code pans
281  */
282 struct frag
283 {
284   /* Object file address. */
285   addressT fr_address;
286   /* Chain forward; ascending address order.  Rooted in frch_root. */
287   struct frag *fr_next;
288
289   /* (Fixed) number of chars we know we have.  May be 0. */
290   offsetT fr_fix;
291   /* (Variable) number of chars after above.  May be 0. */
292   offsetT fr_var;
293   /* For variable-length tail. */
294   struct symbol *fr_symbol;
295   /* For variable-length tail. */
296   offsetT fr_offset;
297   /* Points to opcode low addr byte, for relaxation.  */
298   char *fr_opcode;
299
300 #ifndef NO_LISTING
301   struct list_info_struct *line;
302 #endif
303
304   /* What state is my tail in? */
305   relax_stateT fr_type;
306   relax_substateT fr_subtype;
307
308   /* These are needed only on the NS32K machines */
309   char fr_pcrel_adjust;
310   char fr_bsr;
311
312   /* Chars begin here.
313      One day we will compile fr_literal[0]. */
314   char fr_literal[1];
315 };
316
317 #define SIZEOF_STRUCT_FRAG \
318 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
319 /* We want to say fr_literal[0] above. */
320
321 typedef struct frag fragS;
322
323 /* Current frag we are building.  This frag is incomplete.  It is, however,
324    included in frchain_now.  The fr_fix field is bogus; instead, use:
325    obstack_next_free(&frags)-frag_now->fr_literal.  */
326 COMMON fragS *frag_now;
327 #define frag_now_fix() ((char*)obstack_next_free (&frags) - frag_now->fr_literal)
328
329 /* For foreign-segment symbol fixups. */
330 COMMON fragS zero_address_frag;
331 /* For local common (N_BSS segment) fixups. */
332 COMMON fragS bss_address_frag;
333
334 /* main program "as.c" (command arguments etc) */
335
336 /* ['x'] TRUE if "-x" seen. */
337 COMMON char flagseen[128];
338 COMMON unsigned char flag_readonly_data_in_text;
339 COMMON unsigned char flag_suppress_warnings;
340 COMMON unsigned char flag_always_generate_output;
341
342 /* name of emitted object file */
343 COMMON char *out_file_name;
344
345 /* TRUE if we need a second pass. */
346 COMMON int need_pass_2;
347
348 /* TRUE if we should do no relaxing, and
349    leave lots of padding.  */
350 COMMON int linkrelax;
351
352 /* TRUE if we should produce a listing.  */
353 extern int listing;
354
355 struct _pseudo_type
356   {
357     /* assembler mnemonic, lower case, no '.' */
358     char *poc_name;
359     /* Do the work */
360     void (*poc_handler) PARAMS ((int));
361     /* Value to pass to handler */
362     int poc_val;
363   };
364
365 typedef struct _pseudo_type pseudo_typeS;
366
367 #ifdef BFD_ASSEMBLER_xxx
368 struct lineno_struct
369   {
370     alent line;
371     fragS *frag;
372     struct lineno_struct *next;
373   };
374 typedef struct lineno_struct lineno;
375 #endif
376
377 #if defined (__STDC__) && !defined(NO_STDARG)
378
379 #if __GNUC__ >= 2
380 /* for use with -Wformat */
381 #define PRINTF_LIKE(FCN)        void FCN (const char *format, ...) \
382                                         __attribute__ ((format (printf, 1, 2)))
383 #define PRINTF_WHERE_LIKE(FCN)  void FCN (char *file, unsigned int line, \
384                                           const char *format, ...) \
385                                         __attribute__ ((format (printf, 3, 4)))
386 #else /* ANSI C with stdarg, but not GNU C */
387 #define PRINTF_LIKE(FCN)        void FCN (const char *format, ...)
388 #define PRINTF_WHERE_LIKE(FCN)  void FCN (char *file, unsigned int line, \
389                                           const char *format, ...)
390 #endif
391 #else /* not ANSI C, or not stdarg */
392 #define PRINTF_LIKE(FCN)        void FCN ()
393 #define PRINTF_WHERE_LIKE(FCN)  void FCN ()
394 #endif
395
396 PRINTF_LIKE (as_bad);
397 PRINTF_LIKE (as_fatal);
398 PRINTF_LIKE (as_tsktsk);
399 PRINTF_LIKE (as_warn);
400 PRINTF_WHERE_LIKE (as_bad_where);
401 PRINTF_WHERE_LIKE (as_warn_where);
402
403 void fprint_value PARAMS ((FILE *file, addressT value));
404 void sprint_value PARAMS ((char *buf, addressT value));
405
406 int had_errors PARAMS ((void));
407 int had_warnings PARAMS ((void));
408
409 void print_version_id PARAMS ((void));
410 char *app_push PARAMS ((void));
411 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
412 char *input_scrub_include_file PARAMS ((char *filename, char *position));
413 char *input_scrub_new_file PARAMS ((char *filename));
414 char *input_scrub_next_buffer PARAMS ((char **bufp));
415 PTR xmalloc PARAMS ((unsigned long size));
416 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
417 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
418 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
419                           long exponent_bits));
420 int had_err PARAMS ((void));
421 int ignore_input PARAMS ((void));
422 int scrub_from_file PARAMS ((void));
423 int scrub_from_string PARAMS ((void));
424 int seen_at_least_1_file PARAMS ((void));
425 void app_pop PARAMS ((char *arg));
426 void as_howmuch PARAMS ((FILE * stream));
427 void as_perror PARAMS ((const char *gripe, const char *filename));
428 void as_where PARAMS ((char **namep, unsigned int *linep));
429 void bump_line_counters PARAMS ((void));
430 void do_scrub_begin PARAMS ((void));
431 void input_scrub_begin PARAMS ((void));
432 void input_scrub_close PARAMS ((void));
433 void input_scrub_end PARAMS ((void));
434 void new_logical_line PARAMS ((char *fname, int line_number));
435 void scrub_to_file PARAMS ((int ch));
436 void scrub_to_string PARAMS ((int ch));
437 void subsegs_begin PARAMS ((void));
438 void subseg_change PARAMS ((segT seg, int subseg));
439 segT subseg_new PARAMS ((const char *name, subsegT subseg));
440 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
441 void subseg_set PARAMS ((segT seg, subsegT subseg));
442 #ifdef BFD_ASSEMBLER
443 segT subseg_get PARAMS ((const char *, int));
444 #endif
445
446 struct expressionS;
447 struct fix;
448 struct symbol;
449
450 #ifdef BFD_ASSEMBLER
451 /* literal.c */
452 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
453 #endif
454
455 /* this one starts the chain of target dependant headers */
456 #include "targ-env.h"
457
458 #include "expr.h"
459 #include "struc-symbol.h"
460 #include "write.h"
461 #include "frags.h"
462 #include "hash.h"
463 #include "read.h"
464 #include "symbols.h"
465
466 #include "tc.h"
467 #include "obj.h"
468
469 #include "listing.h"
470
471 #ifdef BFD_ASSEMBLER
472 /* Someday perhaps this will be selectable at run-time.  */
473 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
474 #define OUTPUT_FLAVOR bfd_target_aout_flavour
475 #endif
476 #ifdef OBJ_COFF
477 #define OUTPUT_FLAVOR bfd_target_coff_flavour
478 #endif
479 #ifdef OBJ_ECOFF
480 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
481 #endif
482 #ifdef OBJ_ELF
483 #define OUTPUT_FLAVOR bfd_target_elf_flavour
484 #endif
485 #endif /* BFD_ASSEMBLER */
486
487 #endif /* GAS */
488
489 /* end of as.h */