]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/macro.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / macro.h
1 /* macro.h - header file for macro support for gas
2 Copyright (C) 1994-2021 Free Software Foundation, Inc.
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
11 the Free Software Foundation; either version 3, or (at your option)
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
21 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 02110-1301, USA. */
23
24 #ifndef MACRO_H
25
26 #define MACRO_H
27
28 /* Structures used to store macros.
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
34 formals get the actual values attached to them. */
35
36 enum formal_type
37 {
38 FORMAL_OPTIONAL,
39 FORMAL_REQUIRED,
40 FORMAL_VARARG
41 };
42
43 /* Describe the formal arguments to a macro. */
44
45 typedef struct formal_struct {
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. */
51 enum formal_type type; /* The kind of the formal. */
52 } formal_entry;
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
59 /* Describe the macro. */
60
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. */
66 struct htab *formal_hash; /* Hash table of formals. */
67 const char *name; /* Macro name. */
68 const char *file; /* File the macro was defined in. */
69 unsigned int line; /* Line number of definition. */
70 } macro_entry;
71
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
80 /* The macro hash table. */
81
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 }
173
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 *));
178 extern void macro_set_alternate (int);
179 extern void macro_mri_mode (int);
180 extern const char *define_macro (size_t, sb *, sb *, size_t (*) (sb *),
181 const char *, unsigned int, const char **);
182 extern int check_macro (const char *, sb *, const char **, macro_entry **);
183 extern void delete_macro (const char *);
184 extern const char *expand_irp (int, size_t, sb *, sb *, size_t (*) (sb *));
185
186 #endif