]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/defparse.y
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / binutils / defparse.y
1 %{ /* defparse.y - parser for .def files */
2
3 /* Copyright (C) 1995-2024 Free Software Foundation, Inc.
4
5 This file is part of GNU Binutils.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libiberty.h"
25 #include "dlltool.h"
26 %}
27
28 %union {
29 char *id;
30 const char *id_const;
31 int number;
32 };
33
34 %token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATA
35 %token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANT
36 %token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
37 %token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
38 %token EQUAL
39 %token <id> ID
40 %token <number> NUMBER
41 %type <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
42 %type <number> attr attr_list opt_number
43 %type <id> opt_name opt_name2 opt_equal_name opt_import_name
44 %type <id_const> keyword_as_name
45
46 %%
47
48 start: start command
49 | command
50 ;
51
52 command:
53 NAME opt_name opt_base { def_name ($2, $3); }
54 | LIBRARY opt_name opt_base option_list { def_library ($2, $3); }
55 | EXPORTS explist
56 | DESCRIPTION ID { def_description ($2);}
57 | STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
58 | HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
59 | CODE attr_list { def_code ($2);}
60 | DATA attr_list { def_data ($2);}
61 | SECTIONS seclist
62 | IMPORTS implist
63 | VERSIONK NUMBER { def_version ($2,0);}
64 | VERSIONK NUMBER '.' NUMBER { def_version ($2,$4);}
65 ;
66
67
68 explist:
69 /* EMPTY */
70 | explist expline
71 ;
72
73 expline:
74 ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
75 opt_import_name
76 { def_exports ($1, $2, $3, $4, $5, $6, $7, $8);}
77 ;
78 implist:
79 implist impline
80 | impline
81 ;
82
83 impline:
84 ID '=' ID '.' ID '.' ID opt_import_name
85 { def_import ($1,$3,$5,$7, 0, $8); }
86 | ID '=' ID '.' ID '.' NUMBER opt_import_name
87 { def_import ($1,$3,$5, 0,$7, $8); }
88 | ID '=' ID '.' ID opt_import_name
89 { def_import ($1,$3, 0,$5, 0, $6); }
90 | ID '=' ID '.' NUMBER opt_import_name
91 { def_import ($1,$3, 0, 0,$5, $6); }
92 | ID '.' ID '.' ID opt_import_name
93 { def_import ( 0,$1,$3,$5, 0, $6); }
94 | ID '.' ID '.' NUMBER opt_import_name
95 { def_import ( 0,$1,$3, 0,$5, $6); }
96 | ID '.' ID opt_import_name
97 { def_import ( 0,$1, 0,$3, 0, $4); }
98 | ID '.' NUMBER opt_import_name
99 { def_import ( 0,$1, 0, 0,$3, $4); }
100 ;
101
102 seclist:
103 seclist secline
104 | secline
105 ;
106
107 secline:
108 ID attr_list { def_section ($1,$2);}
109 ;
110
111 attr_list:
112 attr_list opt_comma attr
113 | attr
114 ;
115
116 opt_comma:
117 ','
118 |
119 ;
120 opt_number: ',' NUMBER { $$=$2;}
121 | { $$=-1;}
122 ;
123
124 attr:
125 READ { $$ = 1; }
126 | WRITE { $$ = 2; }
127 | EXECUTE { $$ = 4; }
128 | SHARED { $$ = 8; }
129 | NONSHARED { $$ = 0; }
130 | SINGLE { $$ = 0; }
131 | MULTIPLE { $$ = 0; }
132 ;
133
134 opt_CONSTANT:
135 CONSTANT {$$=1;}
136 | {$$=0;}
137 ;
138
139 opt_NONAME:
140 NONAME {$$=1;}
141 | {$$=0;}
142 ;
143
144 opt_DATA:
145 DATA { $$ = 1; }
146 | { $$ = 0; }
147 ;
148
149 opt_PRIVATE:
150 PRIVATE { $$ = 1; }
151 | { $$ = 0; }
152 ;
153
154 keyword_as_name: NAME { $$ = "NAME"; }
155 /* Disabled LIBRARY keyword for a quirk in libtool. It places LIBRARY
156 command after EXPORTS list, which is illegal by specification.
157 See PR binutils/13710
158 | LIBRARY { $$ = "LIBRARY"; } */
159 | DESCRIPTION { $$ = "DESCRIPTION"; }
160 | STACKSIZE { $$ = "STACKSIZE"; }
161 | HEAPSIZE { $$ = "HEAPSIZE"; }
162 | CODE { $$ = "CODE"; }
163 | DATA { $$ = "DATA"; }
164 | SECTIONS { $$ = "SECTIONS"; }
165 | EXPORTS { $$ = "EXPORTS"; }
166 | IMPORTS { $$ = "IMPORTS"; }
167 | VERSIONK { $$ = "VERSION"; }
168 | BASE { $$ = "BASE"; }
169 | CONSTANT { $$ = "CONSTANT"; }
170 | NONAME { $$ = "NONAME"; }
171 | PRIVATE { $$ = "PRIVATE"; }
172 | READ { $$ = "READ"; }
173 | WRITE { $$ = "WRITE"; }
174 | EXECUTE { $$ = "EXECUTE"; }
175 | SHARED { $$ = "SHARED"; }
176 | NONSHARED { $$ = "NONSHARED"; }
177 | SINGLE { $$ = "SINGLE"; }
178 | MULTIPLE { $$ = "MULTIPLE"; }
179 | INITINSTANCE { $$ = "INITINSTANCE"; }
180 | INITGLOBAL { $$ = "INITGLOBAL"; }
181 | TERMINSTANCE { $$ = "TERMINSTANCE"; }
182 | TERMGLOBAL { $$ = "TERMGLOBAL"; }
183 ;
184
185 opt_name2: ID { $$ = $1; }
186 | '.' keyword_as_name
187 {
188 char *name = xmalloc (strlen ($2) + 2);
189 sprintf (name, ".%s", $2);
190 $$ = name;
191 }
192 | '.' opt_name2
193 {
194 char *name = xmalloc (strlen ($2) + 2);
195 sprintf (name, ".%s", $2);
196 $$ = name;
197 }
198 | keyword_as_name '.' opt_name2
199 {
200 char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
201 sprintf (name, "%s.%s", $1, $3);
202 $$ = name;
203 }
204 | ID '.' opt_name2
205 {
206 char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
207 sprintf (name, "%s.%s", $1, $3);
208 $$ = name;
209 }
210 ;
211 opt_name: opt_name2 { $$ =$1; }
212 | { $$=""; }
213 ;
214
215 opt_ordinal:
216 '@' NUMBER { $$=$2;}
217 | { $$=-1;}
218 ;
219
220 opt_import_name:
221 EQUAL opt_name2 { $$ = $2; }
222 | { $$ = 0; }
223 ;
224
225 opt_equal_name:
226 '=' opt_name2 { $$ = $2; }
227 | { $$ = 0; }
228 ;
229
230 opt_base: BASE '=' NUMBER { $$= $3;}
231 | { $$=-1;}
232 ;
233
234 option_list:
235 /* empty */
236 | option_list opt_comma option
237 ;
238
239 option:
240 INITINSTANCE
241 | INITGLOBAL
242 | TERMINSTANCE
243 | TERMGLOBAL
244 ;