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