1 %{
2 /*---------------------------------------------------------------------------*
3   Project:  NitroSDK - tools - makelcf
4   File:     spec.y
5 
6   Copyright 2003-2008 Nintendo. All rights reserved.
7 
8   These coded instructions, statements, and computer programs contain
9   proprietary information of Nintendo of America Inc. and/or Nintendo
10   Company Ltd., and are protected by Federal copyright law. They may
11   not be disclosed to third parties or copied or duplicated in any form,
12   in whole or in part, without the prior written consent of Nintendo.
13 
14   $Log: spec.y,v $
15   Revision 1.15  2006/05/10 02:06:00  yasu
16   Added support for CodeWarrior 2.x
17 
18   Revision 1.14  2005/09/01 04:30:52  yasu
19   Support for Overlay Group
20 
21   Revision 1.13  2005/06/22 00:50:06  yasu
22   Updated copyright year
23 
24   Revision 1.12  2005/06/20 12:21:48  yasu
25   Changed Surffix to Suffix
26 
27   Revision 1.11  2004/07/10 04:06:17  yasu
28   Added support for command 'Library'
29   Support for modifier ':x' in template
30   Fixed line continue '\' issue
31 
32   Revision 1.10  2004/07/08 02:58:53  yasu
33   Support section name for multi-objects as 'Objects' parameters
34 
35   Revision 1.9  2004/07/02 07:34:53  yasu
36   Added support for OBJECT( )
37 
38   Revision 1.8  2004/06/24 07:18:54  yasu
39   Support for keyword "Autoload"
40 
41   Revision 1.7  2004/06/14 11:28:45  yasu
42   Support for section filter "FOREACH.STATIC.OBJECTS=.sectionName"
43 
44   Revision 1.6  2004/02/13 07:13:03  yasu
45   Support for SDK_IRQ_STACKSIZE
46 
47   Revision 1.5  2004/02/05 07:09:03  yasu
48   Changed SDK prefix from iris to nitro
49 
50   Revision 1.4  2004/01/15 10:47:56  yasu
51   Implementation of a static StackSize
52 
53   Revision 1.3  2004/01/14 12:38:08  yasu
54   Changed OverlayName to OverlayDefs
55 
56   Revision 1.2  2004/01/07 13:10:17  yasu
57   Fixed all warnings at compile -Wall
58 
59   Revision 1.1  2004/01/05 02:32:59  yasu
60   Initial version
61 
62   $NoKeywords: $
63  *---------------------------------------------------------------------------*/
64 #include	<stdio.h>
65 #include	<stdlib.h>
66 #include	"makelcf.h"
67 
68 %}
69 
70 %token	tSTATIC
71 %token  tAUTOLOAD
72 %token  tOVERLAY
73 %token  tPROPERTY
74 %token	tGROUP
75 %token	tADDRESS
76 %token  tAFTER
77 %token  tOBJECT
78 %token  tLIBRARY
79 %token  tSEARCHSYMBOL
80 %token	tFORCE
81 %token  tSTACKSIZE
82 %token  tCOMPRESS
83 %token	tOVERLAYDEFS
84 %token  tOVERLAYTABLE
85 %token  tSUFFIX
86 %token	tBEGIN
87 %token  tEND
88 %token  tNL
89 
90 %union
91 {
92 	u32	  	integer;
93 	char*     	string;
94 	tObjectName	object;
95 };
96 
97 %token	<integer>	tNUMBER
98 %token	<string>	tSTRING_FORCE
99 %token	<string>	tSECTIONNAME
100 %token	<string>	tSTRING_STAR
101 %token	<string>	tSTRING_GROUP
102 %token	<string>	tSTRING_FUNCTION
103 %token	<string>	tSTRING_ID
104 %token	<string>	tSTRING_QUATED
105 %token	<string>	tSTRING_NOSPACE
106 %type	<string>	gFILENAME
107 %type	<object>	gOBJECTNAME
108 %%
109 
110 /*=========================================================================*
111       ConfigFile
112  *=========================================================================*/
113 
114 specFile		: sections
115 			;
116 
117 sections		: /*NULL*/
118 			| sections section
119 			;
120 
121 section			: tNL
122 			| sectionStatic
123 			| sectionOverlay
124 			| sectionAutoload
125 			| sectionProperty
126 			;
127 
128 /*===========================================================================
129  *     STATIC staticname
130  *     {
131  *        .....
132  *     }
133  */
134 sectionStatic		: staticKeyword begin staticParams end
135 			;
136 
137 staticKeyword		: tSTATIC tSTRING_ID tNL
138 			{
139 				if ( !StaticSetName( $2 ) ) YYABORT;
140 			}
141 			;
142 
143 staticParams		: /*NULL*/
144 			| staticParams staticParam
145 			;
146 
147 staticParam		: tNL
148 			| staticAddress
149 			| staticObjects
150 			| staticLibraries
151 			| staticSearchSymbols
152 			| staticForces
153 			| staticStackSize
154 			;
155 
156 staticAddress		: tADDRESS tNUMBER tNL
157 			{
158 				if ( !StaticSetAddress( $2 ) ) YYABORT;
159 			}
160 			;
161 
162 staticObjects		: tOBJECT staticObjectList tNL
163 			{
164 				if ( !StaticSetObjectSection( "*" ) ) YYABORT;
165 			}
166 			| tOBJECT staticObjectList tSECTIONNAME tNL
167 			{
168 				if ( !StaticSetObjectSection( $3 ) ) YYABORT;
169 				debug_printf( "$3=%s\n", $3 );
170 				free( $3 );
171 			}
172 			;
173 
174 staticObjectList	: /*NULL*/
175 			| staticObjectList gOBJECTNAME
176 			{
177 				if ( !StaticAddObject( $2.string, $2.type ) ) YYABORT;
178 			}
179 			;
180 
181 staticLibraries		: tLIBRARY staticLibraryList tNL
182 			{
183 				if ( !StaticSetLibrarySection( "*" ) ) YYABORT;
184 			}
185 			| tLIBRARY staticLibraryList tSECTIONNAME tNL
186 			{
187 				if ( !StaticSetLibrarySection( $3 ) ) YYABORT;
188 				debug_printf( "$3=%s\n", $3 );
189 				free( $3 );
190 			}
191 			;
192 
193 staticLibraryList	: /*NULL*/
194 			| staticLibraryList gOBJECTNAME
195 			{
196 				if ( !StaticAddLibrary( $2.string, $2.type ) ) YYABORT;
197 			}
198 			;
199 
200 staticSearchSymbols	: tSEARCHSYMBOL staticSearchSymbolList tNL
201 			;
202 
203 staticSearchSymbolList	: /*NULL*/
204 			| staticSearchSymbolList tSTRING_ID
205 			{
206 				if ( !StaticAddSearchSymbol( $2 ) ) YYABORT;
207 			}
208 			;
209 
210 staticForces	: tFORCE staticForceList tNL
211 			;
212 
213 staticForceList	: /*NULL*/
214 			| staticForceList tSTRING_FORCE
215 			{
216 				if ( !StaticAddForce( $2 ) ) YYABORT;
217 			}
218 			;
219 
220 staticStackSize		: tSTACKSIZE tNUMBER tNL
221 			{
222 				if ( !StaticSetStackSize( $2 ) ) YYABORT;
223 			}
224 			| tSTACKSIZE tNUMBER tNUMBER
225 			{
226 				if ( !StaticSetStackSize( $2 ) ) YYABORT;
227 				if ( !StaticSetStackSizeIrq( $3 ) ) YYABORT;
228 			}
229 			;
230 
231 /*===========================================================================
232  *     OVERLAY overlayname
233  *     {
234  *        .....
235  *     }
236  */
237 sectionOverlay		: overlayKeyword begin overlayParams end
238 			;
239 
240 overlayKeyword		: tOVERLAY tSTRING_ID tNL
241 			{
242 				if ( !AddOverlay( $2 ) ) YYABORT;
243 			}
244 			;
245 
246 overlayParams		: /*NULL*/
247 			| overlayParams overlayParam
248 			;
249 
250 overlayParam		: tNL
251 			| overlayGroup
252 			| overlayAddress
253 			| overlayAfters
254 			| overlayObjects
255 			| overlaySearchSymbols
256 			| overlayForces
257 			| overlayLibraries
258 			| overlayCompress
259 			;
260 
261 overlayGroup		: tGROUP tSTRING_ID tNL
262 			{
263 				if ( !OverlaySetGroup( $2 ) ) YYABORT;
264 			}
265 			;
266 
267 overlayAddress		: tADDRESS tNUMBER tNL
268 			{
269 				if ( !OverlaySetAddress( $2 ) ) YYABORT;
270 			}
271 			;
272 
273 overlayAfters		: tAFTER overlayAfterList tNL
274 			;
275 
276 overlayAfterList	: /*NULL*/
277 			| overlayAfterList tSTRING_ID
278 			{
279 				if ( !OverlayAddAfter( $2 ) ) YYABORT;
280 			}
281 			;
282 
283 overlayObjects		: tOBJECT overlayObjectList tNL
284 			{
285 				if ( !OverlaySetObjectSection( "*" ) ) YYABORT;
286 			}
287 			| tOBJECT overlayObjectList tSECTIONNAME tNL
288 			{
289 				if ( !OverlaySetObjectSection( $3 ) ) YYABORT;
290 				free( $3 );
291 			}
292 			;
293 
294 overlayObjectList	: /*NULL*/
295 			| overlayObjectList gOBJECTNAME
296 			{
297 				if ( !OverlayAddObject( $2.string, $2.type ) ) YYABORT;
298 			}
299 			;
300 
301 overlayLibraries	: tLIBRARY overlayLibraryList tNL
302 			{
303 				if ( !OverlaySetLibrarySection( "*" ) ) YYABORT;
304 			}
305 			| tLIBRARY overlayLibraryList tSECTIONNAME tNL
306 			{
307 				if ( !OverlaySetLibrarySection( $3 ) ) YYABORT;
308 				free( $3 );
309 			}
310 			;
311 
312 overlayLibraryList	: /*NULL*/
313 			| overlayLibraryList gOBJECTNAME
314 			{
315 				if ( !OverlayAddLibrary( $2.string, $2.type ) ) YYABORT;
316 			}
317 			;
318 
319 overlaySearchSymbols	: tSEARCHSYMBOL overlaySearchSymbolList tNL
320 			;
321 
322 overlaySearchSymbolList	: /*NULL*/
323 			| overlaySearchSymbolList tSTRING_ID
324 			{
325 				if ( !OverlayAddSearchSymbol( $2 ) ) YYABORT;
326 			}
327 			;
328 
329 overlayForces	: tFORCE overlayForceList tNL
330 			;
331 
332 overlayForceList	: /*NULL*/
333 			| overlayForceList tSTRING_FORCE
334 			{
335 				if ( !OverlayAddForce( $2 ) ) YYABORT;
336 			}
337 			;
338 
339 overlayCompress	: tCOMPRESS tSTRING_ID tNL
340 			{
341 				if ( !OverlaySetCompress( $2 ) ) YYABORT;
342 			}
343 			;
344 
345 /*===========================================================================
346  *     AUTOLOAD autoloadname
347  *     {
348  *        .....
349  *     }
350  */
351 sectionAutoload		: autoloadKeyword begin autoloadParams end
352 			;
353 
354 autoloadKeyword		: tAUTOLOAD tSTRING_ID tNL
355 			{
356 				if ( !AddAutoload( $2 ) ) YYABORT;
357 			}
358 			;
359 
360 autoloadParams		: /*NULL*/
361 			| autoloadParams autoloadParam
362 			;
363 
364 /* mostly same as overlayParam except no "group" */
365 autoloadParam		: tNL
366 			| overlayAddress
367 			| overlayAfters
368 			| overlayObjects
369 			| overlaySearchSymbols
370 			| overlayForces
371 			| overlayLibraries
372 			;
373 
374 /*===========================================================================
375  *     PROPERTY
376  *     {
377  *        .....
378  *     }
379  */
380 sectionProperty		: propertyKeyword begin propertyParams end
381 			;
382 
383 propertyKeyword		: tPROPERTY tNL
384 			;
385 
386 propertyParams		: /*NULL*/
387 			| propertyParams propertyParam
388 			;
389 
390 propertyParam		: tNL
391 			| propertyName
392 			| propertyOverlay
393 			| propertySuffix
394 			;
395 
396 propertyName		: tOVERLAYDEFS gFILENAME tNL
397 			{
398 				if ( !PropertySetOverlayDefs( $2 ) ) YYABORT;
399 			}
400 			;
401 
402 propertyOverlay		: tOVERLAYTABLE gFILENAME tNL
403 			{
404 				if ( !PropertySetOverlayTable( $2 ) ) YYABORT;
405 			}
406 			;
407 
408 propertySuffix		: tSUFFIX gFILENAME tNL
409 			{
410 				if ( !PropertySetSuffix( $2 ) ) YYABORT;
411 			}
412 			;
413 
414 /*===========================================================================
415  *	MISC
416  */
417 
418 begin			: tBEGIN tNL
419 			;
420 
421 end			: tEND tNL
422 			;
423 
424 gFILENAME		: tSTRING_ID
425 			| tSTRING_QUATED
426 			| tSTRING_NOSPACE
427 			;
428 
429 gOBJECTNAME		: gFILENAME
430 			{
431 				$$.string = $1;
432 				$$.type   = OBJTYPE_FILE;
433 			}
434 			| tSTRING_STAR
435 			{
436 				$$.string = $1;
437 				$$.type   = OBJTYPE_STAR;
438 			}
439 			| tSTRING_GROUP
440 			{
441 				$$.string = $1;
442 				$$.type   = OBJTYPE_GROUP;
443 			}
444 			| tSTRING_FUNCTION
445 			{
446 				$$.string = $1;
447 				$$.type   = OBJTYPE_OBJECT;
448 			}
449 			;
450 %%
451