Commit | Line | Data |
---|---|---|
fea17916 | 1 | /* macro.h - header file for macro support for gas |
250d07de | 2 | Copyright (C) 1994-2021 Free Software Foundation, Inc. |
252b5132 RH |
3 | |
4 | Written by Steve and Judy Chamberlain of Cygnus Support, | |
5 | sac@cygnus.com | |
6 | ||
7 | This file is part of GAS, the GNU Assembler. | |
8 | ||
9 | GAS is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 11 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
12 | any later version. |
13 | ||
14 | GAS is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
21 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
22 | 02110-1301, USA. */ | |
252b5132 RH |
23 | |
24 | #ifndef MACRO_H | |
25 | ||
26 | #define MACRO_H | |
27 | ||
a01b9fa4 | 28 | /* Structures used to store macros. |
9f10757c TW |
29 | |
30 | Each macro knows its name and included text. It gets built with a | |
31 | list of formal arguments, and also keeps a hash table which points | |
32 | into the list to speed up formal search. Each formal knows its | |
33 | name and its default value. Each time the macro is expanded, the | |
47eebc20 | 34 | formals get the actual values attached to them. */ |
9f10757c | 35 | |
1e9cc1c2 NC |
36 | enum formal_type |
37 | { | |
38 | FORMAL_OPTIONAL, | |
39 | FORMAL_REQUIRED, | |
40 | FORMAL_VARARG | |
41 | }; | |
42 | ||
fea17916 | 43 | /* Describe the formal arguments to a macro. */ |
9f10757c | 44 | |
ef99799a | 45 | typedef struct formal_struct { |
fea17916 NC |
46 | struct formal_struct *next; /* Next formal in list. */ |
47 | sb name; /* Name of the formal. */ | |
48 | sb def; /* The default value. */ | |
49 | sb actual; /* The actual argument (changed on each expansion). */ | |
50 | int index; /* The index of the formal 0..formal_count - 1. */ | |
1e9cc1c2 | 51 | enum formal_type type; /* The kind of the formal. */ |
ef99799a | 52 | } formal_entry; |
9f10757c TW |
53 | |
54 | /* Other values found in the index field of a formal_entry. */ | |
55 | #define QUAL_INDEX (-1) | |
56 | #define NARG_INDEX (-2) | |
57 | #define LOCAL_INDEX (-3) | |
58 | ||
fea17916 | 59 | /* Describe the macro. */ |
9f10757c | 60 | |
fea17916 NC |
61 | typedef struct macro_struct |
62 | { | |
63 | sb sub; /* Substitution text. */ | |
64 | int formal_count; /* Number of formal args. */ | |
65 | formal_entry *formals; /* Pointer to list of formal_structs. */ | |
2b272f44 | 66 | struct htab *formal_hash; /* Hash table of formals. */ |
02ddf156 | 67 | const char *name; /* Macro name. */ |
3b4dbbbf | 68 | const char *file; /* File the macro was defined in. */ |
02ddf156 | 69 | unsigned int line; /* Line number of definition. */ |
ef99799a | 70 | } macro_entry; |
9f10757c | 71 | |
252b5132 RH |
72 | /* Whether any macros have been defined. */ |
73 | ||
74 | extern int macro_defined; | |
75 | ||
76 | /* The macro nesting level. */ | |
77 | ||
78 | extern int macro_nest; | |
79 | ||
c1d05a60 NC |
80 | /* The macro hash table. */ |
81 | ||
2b272f44 ML |
82 | extern struct htab *macro_hash; |
83 | ||
84 | struct macro_hash_entry | |
85 | { | |
86 | const char *name; | |
87 | macro_entry *macro; | |
88 | }; | |
89 | ||
90 | typedef struct macro_hash_entry macro_hash_entry_t; | |
91 | ||
92 | /* Hash function for a macro_hash_entry. */ | |
93 | ||
94 | static inline hashval_t | |
95 | hash_macro_entry (const void *e) | |
96 | { | |
97 | const macro_hash_entry_t *entry = (const macro_hash_entry_t *) e; | |
98 | return htab_hash_string (entry->name); | |
99 | } | |
100 | ||
101 | /* Equality function for a macro_hash_entry. */ | |
102 | ||
103 | static inline int | |
104 | eq_macro_entry (const void *a, const void *b) | |
105 | { | |
106 | const macro_hash_entry_t *ea = (const macro_hash_entry_t *) a; | |
107 | const macro_hash_entry_t *eb = (const macro_hash_entry_t *) b; | |
108 | ||
109 | return strcmp (ea->name, eb->name) == 0; | |
110 | } | |
111 | ||
112 | static inline macro_hash_entry_t * | |
113 | macro_entry_alloc (const char *name, macro_entry *macro) | |
114 | { | |
115 | macro_hash_entry_t *entry = XNEW (macro_hash_entry_t); | |
116 | entry->name = name; | |
117 | entry->macro = macro; | |
118 | return entry; | |
119 | } | |
120 | ||
121 | static inline macro_entry * | |
122 | macro_entry_find (htab_t table, const char *name) | |
123 | { | |
124 | macro_hash_entry_t needle = { name, NULL }; | |
125 | macro_hash_entry_t *entry = htab_find (table, &needle); | |
126 | return entry != NULL ? entry->macro : NULL; | |
127 | } | |
128 | ||
129 | struct formal_hash_entry | |
130 | { | |
131 | const char *name; | |
132 | formal_entry *formal; | |
133 | }; | |
134 | ||
135 | typedef struct formal_hash_entry formal_hash_entry_t; | |
136 | ||
137 | /* Hash function for a macro_hash_entry. */ | |
138 | ||
139 | static inline hashval_t | |
140 | hash_formal_entry (const void *e) | |
141 | { | |
142 | const formal_hash_entry_t *entry = (const formal_hash_entry_t *) e; | |
143 | return htab_hash_string (entry->name); | |
144 | } | |
145 | ||
146 | /* Equality function for a formal_hash_entry. */ | |
147 | ||
148 | static inline int | |
149 | eq_formal_entry (const void *a, const void *b) | |
150 | { | |
151 | const formal_hash_entry_t *ea = (const formal_hash_entry_t *) a; | |
152 | const formal_hash_entry_t *eb = (const formal_hash_entry_t *) b; | |
153 | ||
154 | return strcmp (ea->name, eb->name) == 0; | |
155 | } | |
156 | ||
157 | static inline formal_hash_entry_t * | |
158 | formal_entry_alloc (const char *name, formal_entry *formal) | |
159 | { | |
160 | formal_hash_entry_t *entry = XNEW (formal_hash_entry_t); | |
161 | entry->name = name; | |
162 | entry->formal = formal; | |
163 | return entry; | |
164 | } | |
165 | ||
166 | static inline formal_entry * | |
167 | formal_entry_find (htab_t table, const char *name) | |
168 | { | |
169 | formal_hash_entry_t needle = { name, NULL }; | |
170 | formal_hash_entry_t *entry = htab_find (table, &needle); | |
171 | return entry != NULL ? entry->formal : NULL; | |
172 | } | |
c1d05a60 | 173 | |
39a45edc AM |
174 | extern int buffer_and_nest (const char *, const char *, sb *, |
175 | size_t (*) (sb *)); | |
176 | extern void macro_init (int, int, int, | |
177 | size_t (*) (const char *, size_t, sb *, offsetT *)); | |
caa32fe5 | 178 | extern void macro_set_alternate (int); |
254d758c | 179 | extern void macro_mri_mode (int); |
39a45edc | 180 | extern const char *define_macro (size_t, sb *, sb *, size_t (*) (sb *), |
3b4dbbbf | 181 | const char *, unsigned int, const char **); |
254d758c KH |
182 | extern int check_macro (const char *, sb *, const char **, macro_entry **); |
183 | extern void delete_macro (const char *); | |
39a45edc | 184 | extern const char *expand_irp (int, size_t, sb *, sb *, size_t (*) (sb *)); |
252b5132 RH |
185 | |
186 | #endif |