Update my e-mail address.
[binutils-gdb.git] / binutils / defparse.y
blob72538b5e572c8a47c4cee82506c15d95a1abb462
1 %{ /* defparse.y - parser for .def files */
3 /* Copyright (C) 1995-2017 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
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.
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.
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. */
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libiberty.h"
25 #include "dlltool.h"
28 %union {
29 char *id;
30 const char *id_const;
31 int number;
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
48 start: start command
49 | command
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);}
68 explist:
69 /* EMPTY */
70 | explist expline
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);}
78 implist:
79 implist impline
80 | impline
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); }
102 seclist:
103 seclist secline
104 | secline
107 secline:
108 ID attr_list { def_section ($1,$2);}
111 attr_list:
112 attr_list opt_comma attr
113 | attr
116 opt_comma:
120 opt_number: ',' NUMBER { $$=$2;}
121 | { $$=-1;}
124 attr:
125 READ { $$ = 1; }
126 | WRITE { $$ = 2; }
127 | EXECUTE { $$ = 4; }
128 | SHARED { $$ = 8; }
129 | NONSHARED { $$ = 0; }
130 | SINGLE { $$ = 0; }
131 | MULTIPLE { $$ = 0; }
134 opt_CONSTANT:
135 CONSTANT {$$=1;}
136 | {$$=0;}
139 opt_NONAME:
140 NONAME {$$=1;}
141 | {$$=0;}
144 opt_DATA:
145 DATA { $$ = 1; }
146 | { $$ = 0; }
149 opt_PRIVATE:
150 PRIVATE { $$ = 1; }
151 | { $$ = 0; }
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"; }
185 opt_name2: ID { $$ = $1; }
186 | '.' keyword_as_name
188 char *name = xmalloc (strlen ($2) + 2);
189 sprintf (name, ".%s", $2);
190 $$ = name;
192 | '.' opt_name2
194 char *name = xmalloc (strlen ($2) + 2);
195 sprintf (name, ".%s", $2);
196 $$ = name;
198 | keyword_as_name '.' opt_name2
200 char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
201 sprintf (name, "%s.%s", $1, $3);
202 $$ = name;
204 | ID '.' opt_name2
206 char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
207 sprintf (name, "%s.%s", $1, $3);
208 $$ = name;
211 opt_name: opt_name2 { $$ =$1; }
212 | { $$=""; }
215 opt_ordinal:
216 '@' NUMBER { $$=$2;}
217 | { $$=-1;}
220 opt_import_name:
221 EQUAL opt_name2 { $$ = $2; }
222 | { $$ = 0; }
225 opt_equal_name:
226 '=' opt_name2 { $$ = $2; }
227 | { $$ = 0; }
230 opt_base: BASE '=' NUMBER { $$= $3;}
231 | { $$=-1;}
234 option_list:
235 /* empty */
236 | option_list opt_comma option
239 option:
240 INITINSTANCE
241 | INITGLOBAL
242 | TERMINSTANCE
243 | TERMGLOBAL