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