xref: /netbsd-src/external/gpl3/binutils.old/dist/binutils/defparse.y (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos %{ /* defparse.y - parser for .def files */
275fd0b74Schristos 
3*e992f068Schristos /* Copyright (C) 1995-2022 Free Software Foundation, Inc.
475fd0b74Schristos 
575fd0b74Schristos    This file is part of GNU Binutils.
675fd0b74Schristos 
775fd0b74Schristos    This program is free software; you can redistribute it and/or modify
875fd0b74Schristos    it under the terms of the GNU General Public License as published by
975fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
1075fd0b74Schristos    (at your option) any later version.
1175fd0b74Schristos 
1275fd0b74Schristos    This program is distributed in the hope that it will be useful,
1375fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1475fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1575fd0b74Schristos    GNU General Public License for more details.
1675fd0b74Schristos 
1775fd0b74Schristos    You should have received a copy of the GNU General Public License
1875fd0b74Schristos    along with this program; if not, write to the Free Software
1975fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2075fd0b74Schristos    MA 02110-1301, USA.  */
2175fd0b74Schristos 
2275fd0b74Schristos #include "sysdep.h"
2375fd0b74Schristos #include "bfd.h"
2475fd0b74Schristos #include "libiberty.h"
2575fd0b74Schristos #include "dlltool.h"
2675fd0b74Schristos %}
2775fd0b74Schristos 
2875fd0b74Schristos %union {
2975fd0b74Schristos   char *id;
3075fd0b74Schristos   const char *id_const;
3175fd0b74Schristos   int number;
3275fd0b74Schristos };
3375fd0b74Schristos 
3475fd0b74Schristos %token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATA
3575fd0b74Schristos %token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANT
3675fd0b74Schristos %token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
3775fd0b74Schristos %token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
3875fd0b74Schristos %token EQUAL
3975fd0b74Schristos %token <id> ID
4075fd0b74Schristos %token <number> NUMBER
4175fd0b74Schristos %type  <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
4275fd0b74Schristos %type  <number> attr attr_list opt_number
4375fd0b74Schristos %type  <id> opt_name opt_name2 opt_equal_name opt_import_name
4475fd0b74Schristos %type  <id_const> keyword_as_name
4575fd0b74Schristos 
4675fd0b74Schristos %%
4775fd0b74Schristos 
4875fd0b74Schristos start: start command
4975fd0b74Schristos 	| command
5075fd0b74Schristos 	;
5175fd0b74Schristos 
5275fd0b74Schristos command:
5375fd0b74Schristos 		NAME opt_name opt_base { def_name ($2, $3); }
5475fd0b74Schristos 	|	LIBRARY opt_name opt_base option_list { def_library ($2, $3); }
5575fd0b74Schristos 	|	EXPORTS explist
5675fd0b74Schristos 	|	DESCRIPTION ID { def_description ($2);}
5775fd0b74Schristos 	|	STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
5875fd0b74Schristos 	|	HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
5975fd0b74Schristos 	|	CODE attr_list { def_code ($2);}
6075fd0b74Schristos 	|	DATA attr_list  { def_data ($2);}
6175fd0b74Schristos 	|	SECTIONS seclist
6275fd0b74Schristos 	|	IMPORTS implist
6375fd0b74Schristos 	|	VERSIONK NUMBER { def_version ($2,0);}
6475fd0b74Schristos 	|	VERSIONK NUMBER '.' NUMBER { def_version ($2,$4);}
6575fd0b74Schristos 	;
6675fd0b74Schristos 
6775fd0b74Schristos 
6875fd0b74Schristos explist:
6975fd0b74Schristos 		/* EMPTY */
7075fd0b74Schristos 	|	explist expline
7175fd0b74Schristos 	;
7275fd0b74Schristos 
7375fd0b74Schristos expline:
7475fd0b74Schristos 		ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
7575fd0b74Schristos 		opt_import_name
7675fd0b74Schristos 			{ def_exports ($1, $2, $3, $4, $5, $6, $7, $8);}
7775fd0b74Schristos 	;
7875fd0b74Schristos implist:
7975fd0b74Schristos 		implist impline
8075fd0b74Schristos 	|	impline
8175fd0b74Schristos 	;
8275fd0b74Schristos 
8375fd0b74Schristos impline:
8475fd0b74Schristos                ID '=' ID '.' ID '.' ID opt_import_name
8575fd0b74Schristos 		 { def_import ($1,$3,$5,$7, 0, $8); }
8675fd0b74Schristos        |       ID '=' ID '.' ID '.' NUMBER opt_import_name
8775fd0b74Schristos 		 { def_import ($1,$3,$5, 0,$7, $8); }
8875fd0b74Schristos        |       ID '=' ID '.' ID opt_import_name
8975fd0b74Schristos 		 { def_import ($1,$3, 0,$5, 0, $6); }
9075fd0b74Schristos        |       ID '=' ID '.' NUMBER opt_import_name
9175fd0b74Schristos 		 { def_import ($1,$3, 0, 0,$5, $6); }
9275fd0b74Schristos        |       ID '.' ID '.' ID opt_import_name
9375fd0b74Schristos 		 { def_import ( 0,$1,$3,$5, 0, $6); }
9475fd0b74Schristos        |       ID '.' ID '.' NUMBER opt_import_name
9575fd0b74Schristos 		 { def_import ( 0,$1,$3, 0,$5, $6); }
9675fd0b74Schristos        |       ID '.' ID opt_import_name
9775fd0b74Schristos 		 { def_import ( 0,$1, 0,$3, 0, $4); }
9875fd0b74Schristos        |       ID '.' NUMBER opt_import_name
9975fd0b74Schristos 		 { def_import ( 0,$1, 0, 0,$3, $4); }
10075fd0b74Schristos ;
10175fd0b74Schristos 
10275fd0b74Schristos seclist:
10375fd0b74Schristos 		seclist secline
10475fd0b74Schristos 	|	secline
10575fd0b74Schristos 	;
10675fd0b74Schristos 
10775fd0b74Schristos secline:
10875fd0b74Schristos 	ID attr_list { def_section ($1,$2);}
10975fd0b74Schristos 	;
11075fd0b74Schristos 
11175fd0b74Schristos attr_list:
11275fd0b74Schristos 	attr_list opt_comma attr
11375fd0b74Schristos 	| attr
11475fd0b74Schristos 	;
11575fd0b74Schristos 
11675fd0b74Schristos opt_comma:
11775fd0b74Schristos 	','
11875fd0b74Schristos 	|
11975fd0b74Schristos 	;
12075fd0b74Schristos opt_number: ',' NUMBER { $$=$2;}
12175fd0b74Schristos 	|	   { $$=-1;}
12275fd0b74Schristos 	;
12375fd0b74Schristos 
12475fd0b74Schristos attr:
12575fd0b74Schristos 		READ { $$ = 1; }
12675fd0b74Schristos 	|	WRITE { $$ = 2; }
12775fd0b74Schristos 	|	EXECUTE { $$ = 4; }
12875fd0b74Schristos 	|	SHARED { $$ = 8; }
12975fd0b74Schristos 	|	NONSHARED { $$ = 0; }
13075fd0b74Schristos 	|	SINGLE { $$ = 0; }
13175fd0b74Schristos 	|	MULTIPLE { $$ = 0; }
13275fd0b74Schristos 	;
13375fd0b74Schristos 
13475fd0b74Schristos opt_CONSTANT:
13575fd0b74Schristos 		CONSTANT {$$=1;}
13675fd0b74Schristos 	|		 {$$=0;}
13775fd0b74Schristos 	;
13875fd0b74Schristos 
13975fd0b74Schristos opt_NONAME:
14075fd0b74Schristos 		NONAME {$$=1;}
14175fd0b74Schristos 	|		 {$$=0;}
14275fd0b74Schristos 	;
14375fd0b74Schristos 
14475fd0b74Schristos opt_DATA:
14575fd0b74Schristos 		DATA { $$ = 1; }
14675fd0b74Schristos 	|	     { $$ = 0; }
14775fd0b74Schristos 	;
14875fd0b74Schristos 
14975fd0b74Schristos opt_PRIVATE:
15075fd0b74Schristos 		PRIVATE { $$ = 1; }
15175fd0b74Schristos 	|		{ $$ = 0; }
15275fd0b74Schristos 	;
15375fd0b74Schristos 
15475fd0b74Schristos keyword_as_name: NAME { $$ = "NAME"; }
15575fd0b74Schristos /*  Disabled LIBRARY keyword for a quirk in libtool. It places LIBRARY
15675fd0b74Schristos     command after EXPORTS list, which is illegal by specification.
15775fd0b74Schristos     See PR binutils/13710
15875fd0b74Schristos 	| LIBRARY { $$ = "LIBRARY"; } */
15975fd0b74Schristos 	| DESCRIPTION { $$ = "DESCRIPTION"; }
16075fd0b74Schristos 	| STACKSIZE { $$ = "STACKSIZE"; }
16175fd0b74Schristos 	| HEAPSIZE { $$ = "HEAPSIZE"; }
16275fd0b74Schristos 	| CODE { $$ = "CODE"; }
16375fd0b74Schristos 	| DATA { $$ = "DATA"; }
16475fd0b74Schristos 	| SECTIONS { $$ = "SECTIONS"; }
16575fd0b74Schristos 	| EXPORTS { $$ = "EXPORTS"; }
16675fd0b74Schristos 	| IMPORTS { $$ = "IMPORTS"; }
16775fd0b74Schristos 	| VERSIONK { $$ = "VERSION"; }
16875fd0b74Schristos 	| BASE { $$ = "BASE"; }
16975fd0b74Schristos 	| CONSTANT { $$ = "CONSTANT"; }
17075fd0b74Schristos 	| NONAME { $$ = "NONAME"; }
17175fd0b74Schristos 	| PRIVATE { $$ = "PRIVATE"; }
17275fd0b74Schristos 	| READ { $$ = "READ"; }
17375fd0b74Schristos 	| WRITE { $$ = "WRITE"; }
17475fd0b74Schristos 	| EXECUTE { $$ = "EXECUTE"; }
17575fd0b74Schristos 	| SHARED { $$ = "SHARED"; }
17675fd0b74Schristos 	| NONSHARED { $$ = "NONSHARED"; }
17775fd0b74Schristos 	| SINGLE { $$ = "SINGLE"; }
17875fd0b74Schristos 	| MULTIPLE { $$ = "MULTIPLE"; }
17975fd0b74Schristos 	| INITINSTANCE { $$ = "INITINSTANCE"; }
18075fd0b74Schristos 	| INITGLOBAL { $$ = "INITGLOBAL"; }
18175fd0b74Schristos 	| TERMINSTANCE { $$ = "TERMINSTANCE"; }
18275fd0b74Schristos 	| TERMGLOBAL { $$ = "TERMGLOBAL"; }
18375fd0b74Schristos 	;
18475fd0b74Schristos 
18575fd0b74Schristos opt_name2: ID { $$ = $1; }
18675fd0b74Schristos 	| '.' keyword_as_name
18775fd0b74Schristos 	  {
18875fd0b74Schristos 	    char *name = xmalloc (strlen ($2) + 2);
18975fd0b74Schristos 	    sprintf (name, ".%s", $2);
19075fd0b74Schristos 	    $$ = name;
19175fd0b74Schristos 	  }
19275fd0b74Schristos 	| '.' opt_name2
19375fd0b74Schristos 	  {
19475fd0b74Schristos 	    char *name = xmalloc (strlen ($2) + 2);
19575fd0b74Schristos 	    sprintf (name, ".%s", $2);
19675fd0b74Schristos 	    $$ = name;
19775fd0b74Schristos 	  }
19875fd0b74Schristos 	| keyword_as_name '.' opt_name2
19975fd0b74Schristos 	  {
20075fd0b74Schristos 	    char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
20175fd0b74Schristos 	    sprintf (name, "%s.%s", $1, $3);
20275fd0b74Schristos 	    $$ = name;
20375fd0b74Schristos 	  }
20475fd0b74Schristos 	| ID '.' opt_name2
20575fd0b74Schristos 	  {
20675fd0b74Schristos 	    char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
20775fd0b74Schristos 	    sprintf (name, "%s.%s", $1, $3);
20875fd0b74Schristos 	    $$ = name;
20975fd0b74Schristos 	  }
21075fd0b74Schristos 	;
21175fd0b74Schristos opt_name: opt_name2 { $$ =$1; }
21275fd0b74Schristos 	|		{ $$=""; }
21375fd0b74Schristos 	;
21475fd0b74Schristos 
21575fd0b74Schristos opt_ordinal:
21675fd0b74Schristos 	  '@' NUMBER     { $$=$2;}
21775fd0b74Schristos 	|                { $$=-1;}
21875fd0b74Schristos 	;
21975fd0b74Schristos 
22075fd0b74Schristos opt_import_name:
22175fd0b74Schristos 	  EQUAL opt_name2	{ $$ = $2; }
22275fd0b74Schristos 	|		{ $$ = 0; }
22375fd0b74Schristos 	;
22475fd0b74Schristos 
22575fd0b74Schristos opt_equal_name:
22675fd0b74Schristos           '=' opt_name2	{ $$ = $2; }
22775fd0b74Schristos         | 		{ $$ =  0; }
22875fd0b74Schristos 	;
22975fd0b74Schristos 
23075fd0b74Schristos opt_base: BASE	'=' NUMBER	{ $$= $3;}
23175fd0b74Schristos 	|	{ $$=-1;}
23275fd0b74Schristos 	;
23375fd0b74Schristos 
23475fd0b74Schristos option_list:
23575fd0b74Schristos 		/* empty */
23675fd0b74Schristos 	|	option_list opt_comma option
23775fd0b74Schristos 	;
23875fd0b74Schristos 
23975fd0b74Schristos option:
24075fd0b74Schristos 		INITINSTANCE
24175fd0b74Schristos 	|	INITGLOBAL
24275fd0b74Schristos 	|	TERMINSTANCE
24375fd0b74Schristos 	|	TERMGLOBAL
24475fd0b74Schristos 	;
245