aboutsummaryrefslogtreecommitdiff
path: root/binutils/defparse.y
blob: 6493c12e0fe5893f6dd88ebcb0762f3b157385c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
%{ /* defparse.y - parser for .def files */

/* Copyright 1995, 1997, 1998, 1999, 2001, 2004, 2005, 2007
   Free Software Foundation, Inc.
   
   This file is part of GNU Binutils.
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#include "sysdep.h"
#include "bfd.h"
#include "libiberty.h"
#include "dlltool.h"
%}

%union {
  char *id;
  int number;
};

%token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATA
%token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANT
%token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
%token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
%token <id> ID
%token <number> NUMBER
%type  <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
%type  <number> attr attr_list opt_number
%type  <id> opt_name opt_equal_name 

%%

start: start command
	| command
	;

command: 
		NAME opt_name opt_base { def_name ($2, $3); }
	|	LIBRARY opt_name opt_base option_list { def_library ($2, $3); }
	|	EXPORTS explist 
	|	DESCRIPTION ID { def_description ($2);}
	|	STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
	|	HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
	|	CODE attr_list { def_code ($2);}
	|	DATA attr_list  { def_data ($2);}
	|	SECTIONS seclist
	|	IMPORTS implist
	|	VERSIONK NUMBER { def_version ($2,0);}
	|	VERSIONK NUMBER '.' NUMBER { def_version ($2,$4);}
	;


explist:
		/* EMPTY */
	|	explist expline
	;

expline:
		ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
			{ def_exports ($1, $2, $3, $4, $5, $6, $7);}
	;
implist:	
		implist impline
	|	impline
	;

impline:
               ID '=' ID '.' ID '.' ID     { def_import ($1,$3,$5,$7, 0); }
       |       ID '=' ID '.' ID '.' NUMBER { def_import ($1,$3,$5, 0,$7); }
       |       ID '=' ID '.' ID            { def_import ($1,$3, 0,$5, 0); }
       |       ID '=' ID '.' NUMBER        { def_import ($1,$3, 0, 0,$5); }
       |       ID '.' ID '.' ID            { def_import ( 0,$1,$3,$5, 0); }
       |       ID '.' ID '.' NUMBER        { def_import ( 0,$1,$3, 0,$5); }
       |       ID '.' ID                   { def_import ( 0,$1, 0,$3, 0); }
       |       ID '.' NUMBER               { def_import ( 0,$1, 0, 0,$3); }
;

seclist:
		seclist secline
	|	secline
	;

secline:
	ID attr_list { def_section ($1,$2);}
	;

attr_list:
	attr_list opt_comma attr
	| attr
	;

opt_comma:
	','
	| 
	;
opt_number: ',' NUMBER { $$=$2;}
	|	   { $$=-1;}
	;
	
attr:
		READ { $$ = 1; }
	|	WRITE { $$ = 2; }
	|	EXECUTE { $$ = 4; }
	|	SHARED { $$ = 8; }
	|	NONSHARED { $$ = 0; }
	|	SINGLE { $$ = 0; }
	|	MULTIPLE { $$ = 0; }
	;

opt_CONSTANT:
		CONSTANT {$$=1;}
	|		 {$$=0;}
	;

opt_NONAME:
		NONAME {$$=1;}
	|		 {$$=0;}
	;

opt_DATA:
		DATA { $$ = 1; }
	|	     { $$ = 0; }
	;

opt_PRIVATE:
		PRIVATE { $$ = 1; }
	|		{ $$ = 0; }
	;

opt_name: ID		{ $$ =$1; }
	| ID '.' ID	
	  { 
	    char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
	    sprintf (name, "%s.%s", $1, $3);
	    $$ = name;
	  }
	|		{ $$=""; }
	;

opt_ordinal: 
	  '@' NUMBER     { $$=$2;}
	|                { $$=-1;}
	;

opt_equal_name:
          '=' ID	{ $$ = $2; }
	| '=' ID '.' ID	
	  { 
	    char *name = xmalloc (strlen ($2) + 1 + strlen ($4) + 1);
	    sprintf (name, "%s.%s", $2, $4);
	    $$ = name;
	  }
        | 		{ $$ =  0; }			 
	;

opt_base: BASE	'=' NUMBER	{ $$= $3;}
	|	{ $$=-1;}
	;

option_list:
		/* empty */
	|	option_list opt_comma option
	;

option:
		INITINSTANCE
	|	INITGLOBAL
	|	TERMINSTANCE
	|	TERMGLOBAL
	;