Merge branch 'vendor/NVI2'
[dragonfly.git] / contrib / binutils-2.25 / gas / frags.h
1 /* frags.h - Header file for the frag concept.
2    Copyright (C) 1987-2014 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 3, 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 the Free
18    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19    02110-1301, USA.  */
20
21 #ifndef FRAGS_H
22 #define FRAGS_H
23
24 struct obstack;
25
26 /* A code fragment (frag) is some known number of chars, followed by some
27    unknown number of chars. Typically the unknown number of chars is an
28    instruction address whose size is yet unknown. We always know the greatest
29    possible size the unknown number of chars may become, and reserve that
30    much room at the end of the frag.
31    Once created, frags do not change address during assembly.
32    We chain the frags in (a) forward-linked list(s). The object-file address
33    of the 1st char of a frag is generally not known until after relax().
34    Many things at assembly time describe an address by {object-file-address
35    of a particular frag}+offset.
36
37    BUG: it may be smarter to have a single pointer off to various different
38    notes for different frag kinds.  See how code pans.  */
39
40 struct frag {
41   /* Object file address (as an octet offset).  */
42   addressT fr_address;
43   /* When relaxing multiple times, remember the address the frag had
44      in the last relax pass.  */
45   addressT last_fr_address;
46
47   /* (Fixed) number of octets we know we have.  May be 0.  */
48   offsetT fr_fix;
49   /* May be used for (Variable) number of octets after above.
50      The generic frag handling code no longer makes any use of fr_var.  */
51   offsetT fr_var;
52   /* For variable-length tail.  */
53   offsetT fr_offset;
54   /* For variable-length tail.  */
55   symbolS *fr_symbol;
56   /* Points to opcode low addr byte, for relaxation.  */
57   char *fr_opcode;
58
59   /* Chain forward; ascending address order.  Rooted in frch_root.  */
60   struct frag *fr_next;
61
62   /* Where the frag was created, or where it became a variant frag.  */
63   char *fr_file;
64   unsigned int fr_line;
65
66 #ifndef NO_LISTING
67   struct list_info_struct *line;
68 #endif
69
70   /* A serial number for a sequence of frags having at most one alignment
71      or org frag, and that at the tail of the sequence.  */
72   unsigned int region:16;
73
74   /* Flipped each relax pass so we can easily determine whether
75      fr_address has been adjusted.  */
76   unsigned int relax_marker:1;
77
78   /* Used to ensure that all insns are emitted on proper address
79      boundaries.  */
80   unsigned int has_code:1;
81   unsigned int insn_addr:6;
82
83   /* What state is my tail in? */
84   relax_stateT fr_type;
85   relax_substateT fr_subtype;
86
87 #ifdef USING_CGEN
88   /* Don't include this unless using CGEN to keep frag size down.  */
89   struct {
90     /* CGEN_INSN entry for this instruction.  */
91     const struct cgen_insn *insn;
92     /* Index into operand table.  */
93     int opindex;
94     /* Target specific data, usually reloc number.  */
95     int opinfo;
96   } fr_cgen;
97 #endif
98
99 #ifdef TC_FRAG_TYPE
100   TC_FRAG_TYPE tc_frag_data;
101 #endif
102 #ifdef OBJ_FRAG_TYPE
103   OBJ_FRAG_TYPE obj_frag_data;
104 #endif
105
106   /* Data begins here.  */
107   char fr_literal[1];
108 };
109
110 #define SIZEOF_STRUCT_FRAG \
111 ((char *) zero_address_frag.fr_literal - (char *) &zero_address_frag)
112 /* We want to say fr_literal[0] above.  */
113
114 /* Current frag we are building.  This frag is incomplete.  It is,
115    however, included in frchain_now.  The fr_fix field is bogus;
116    instead, use frag_now_fix ().  */
117 COMMON fragS *frag_now;
118 extern addressT frag_now_fix (void);
119 extern addressT frag_now_fix_octets (void);
120
121 /* For foreign-segment symbol fixups.  */
122 COMMON fragS zero_address_frag;
123 COMMON fragS predefined_address_frag;
124
125 extern void frag_append_1_char (int);
126 #define FRAG_APPEND_1_CHAR(X) frag_append_1_char (X)
127
128 void frag_init (void);
129 fragS *frag_alloc (struct obstack *);
130 void frag_grow (size_t nchars);
131 char *frag_more (size_t nchars);
132 void frag_align (int alignment, int fill_character, int max);
133 void frag_align_pattern (int alignment, const char *fill_pattern,
134                          size_t n_fill, int max);
135 void frag_align_code (int alignment, int max);
136 void frag_new (size_t old_frags_var_max_size);
137 void frag_wane (fragS * fragP);
138 size_t frag_room (void);
139
140 char *frag_variant (relax_stateT type,
141                     size_t max_chars,
142                     size_t var,
143                     relax_substateT subtype,
144                     symbolS * symbol,
145                     offsetT offset,
146                     char *opcode);
147
148 char *frag_var (relax_stateT type,
149                 size_t max_chars,
150                 size_t var,
151                 relax_substateT subtype,
152                 symbolS * symbol,
153                 offsetT offset,
154                 char *opcode);
155
156 bfd_boolean frag_offset_fixed_p (const fragS *, const fragS *, offsetT *);
157
158 int get_frag_count (void);
159 void clear_frag_count (void);
160
161 #endif /* FRAGS_H */