1 %{
2 /*---------------------------------------------------------------------------*
3   Project:  TwlSDK - 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   $Date:: 2009-11-11#$
15   $Rev: 11140 $
16   $Author: kitase_hirotake $
17  *---------------------------------------------------------------------------*/
18 #include	<stdio.h>
19 #include	<stdlib.h>
20 #include	"makelcf.h"
21 
22 %}
23 
24 %token	tSTATIC
25 %token  tAUTOLOAD
26 %token  tOVERLAY
27 %token  tLTDAUTOLOAD
28 %token  tLTDOVERLAY
29 %token  tPROPERTY
30 %token	tGROUP
31 %token	tADDRESS
32 %token  tAFTER
33 %token  tOBJECT
34 %token  tLIBRARY
35 %token  tSEARCHSYMBOL
36 %token  tFORCE
37 %token  tSTACKSIZE
38 %token  tCOMPRESS
39 %token	tOVERLAYDEFS
40 %token  tOVERLAYTABLE
41 %token  tLTDOVERLAYDEFS
42 %token  tLTDOVERLAYTABLE
43 %token  tSUFFIX
44 %token  tFLXSUFFIX
45 %token  tLTDSUFFIX
46 %token	tBEGIN
47 %token  tEND
48 %token  tNL
49 
50 %union
51 {
52 	u32	  	integer;
53 	char*     	string;
54 	tObjectName	object;
55 };
56 
57 %token	<integer>	tNUMBER
58 %token	<string>	tSTRING_FORCE
59 %token	<string>	tSECTIONNAME
60 %token	<string>	tSTRING_STAR
61 %token	<string>	tSTRING_GROUP
62 %token	<string>	tSTRING_FUNCTION
63 %token	<string>	tSTRING_ID
64 %token	<string>	tSTRING_QUATED
65 %token	<string>	tSTRING_NOSPACE
66 %type	<string>	gFILENAME
67 %type	<object>	gOBJECTNAME
68 %%
69 
70 /*=========================================================================*
71       ConfigFile
72  *=========================================================================*/
73 
74 specFile		: sections
75 			;
76 
77 sections		: /*NULL*/
78 			| sections section
79 			;
80 
81 section			: tNL
82 			| sectionStatic
83 			| sectionOverlay
84 			| sectionAutoload
85 			| sectionLtdoverlay
86 			| sectionLtdautoload
87 			| sectionProperty
88 			;
89 
90 /*===========================================================================
91  *     STATIC staticname
92  *     {
93  *        .....
94  *     }
95  */
96 sectionStatic		: staticKeyword begin staticParams end
97 			;
98 
99 staticKeyword		: tSTATIC tSTRING_ID tNL
100 			{
101 				if ( !StaticSetName( $2 ) ) YYABORT;
102 			}
103 			;
104 
105 staticParams		: /*NULL*/
106 			| staticParams staticParam
107 			;
108 
109 staticParam		: tNL
110 			| staticAddress
111 			| staticObjects
112 			| staticLibraries
113 			| staticSearchSymbols
114 			| staticForces
115 			| staticStackSize
116 			;
117 
118 staticAddress		: tADDRESS tNUMBER tNL
119 			{
120 				if ( !StaticSetAddress( $2 ) ) YYABORT;
121 			}
122 			;
123 
124 staticObjects		: tOBJECT staticObjectList tNL
125 			{
126 				if ( !StaticSetObjectSection( "*" ) ) YYABORT;
127 			}
128 			| tOBJECT staticObjectList tSECTIONNAME tNL
129 			{
130 				if ( !StaticSetObjectSection( $3 ) ) YYABORT;
131 				debug_printf( "$3=%s\n", $3 );
132 				free( $3 );
133 			}
134 			;
135 
136 staticObjectList	: /*NULL*/
137 			| staticObjectList gOBJECTNAME
138 			{
139 				if ( !StaticAddObject( $2.string, $2.type ) ) YYABORT;
140 			}
141 			;
142 
143 staticLibraries		: tLIBRARY staticLibraryList tNL
144 			{
145 				if ( !StaticSetLibrarySection( "*" ) ) YYABORT;
146 			}
147 			| tLIBRARY staticLibraryList tSECTIONNAME tNL
148 			{
149 				if ( !StaticSetLibrarySection( $3 ) ) YYABORT;
150 				debug_printf( "$3=%s\n", $3 );
151 				free( $3 );
152 			}
153 			;
154 
155 staticLibraryList	: /*NULL*/
156 			| staticLibraryList gOBJECTNAME
157 			{
158 				if ( !StaticAddLibrary( $2.string, $2.type ) ) YYABORT;
159 			}
160 			;
161 
162 staticSearchSymbols	: tSEARCHSYMBOL staticSearchSymbolList tNL
163 			;
164 
165 staticSearchSymbolList	: /*NULL*/
166 			| staticSearchSymbolList tSTRING_ID
167 			{
168 				if ( !StaticAddSearchSymbol( $2 ) ) YYABORT;
169 			}
170 			;
171 
172 staticForces	: tFORCE staticForceList tNL
173 			;
174 
175 staticForceList	: /*NULL*/
176 			| staticForceList tSTRING_FORCE
177 			{
178 				if ( !StaticAddForce( $2 ) ) YYABORT;
179 			}
180 			;
181 
182 staticStackSize		: tSTACKSIZE tNUMBER tNL
183 			{
184 				if ( !StaticSetStackSize( $2 ) ) YYABORT;
185 			}
186 			| tSTACKSIZE tNUMBER tNUMBER
187 			{
188 				if ( !StaticSetStackSize( $2 ) ) YYABORT;
189 				if ( !StaticSetStackSizeIrq( $3 ) ) YYABORT;
190 			}
191 			;
192 
193 /*===========================================================================
194  *     OVERLAY overlayname
195  *     {
196  *        .....
197  *     }
198  */
199 sectionOverlay		: overlayKeyword begin overlayParams end
200 			;
201 
202 overlayKeyword		: tOVERLAY tSTRING_ID tNL
203 			{
204 				if ( !AddOverlay( $2 ) ) YYABORT;
205 			}
206 			;
207 
208 overlayParams		: /*NULL*/
209 			| overlayParams overlayParam
210 			;
211 
212 overlayParam		: tNL
213 			| overlayGroup
214 			| overlayAddress
215 			| overlayAfters
216 			| overlayObjects
217 			| overlaySearchSymbols
218 			| overlayForces
219 			| overlayLibraries
220 			| overlayCompress
221 			;
222 
223 overlayGroup		: tGROUP tSTRING_ID tNL
224 			{
225 				if ( !OverlaySetGroup( $2 ) ) YYABORT;
226 			}
227 			;
228 
229 overlayAddress		: tADDRESS tNUMBER tNL
230 			{
231 				if ( !OverlaySetAddress( $2 ) ) YYABORT;
232 			}
233 			;
234 
235 overlayAfters		: tAFTER overlayAfterList tNL
236 			;
237 
238 overlayAfterList	: /*NULL*/
239 			| overlayAfterList tSTRING_ID
240 			{
241 				if ( !OverlayAddAfter( $2 ) ) YYABORT;
242 			}
243 			;
244 
245 overlayObjects		: tOBJECT overlayObjectList tNL
246 			{
247 				if ( !OverlaySetObjectSection( "*" ) ) YYABORT;
248 			}
249 			| tOBJECT overlayObjectList tSECTIONNAME tNL
250 			{
251 				if ( !OverlaySetObjectSection( $3 ) ) YYABORT;
252 				free( $3 );
253 			}
254 			;
255 
256 overlayObjectList	: /*NULL*/
257 			| overlayObjectList gOBJECTNAME
258 			{
259 				if ( !OverlayAddObject( $2.string, $2.type ) ) YYABORT;
260 			}
261 			;
262 
263 overlayLibraries	: tLIBRARY overlayLibraryList tNL
264 			{
265 				if ( !OverlaySetLibrarySection( "*" ) ) YYABORT;
266 			}
267 			| tLIBRARY overlayLibraryList tSECTIONNAME tNL
268 			{
269 				if ( !OverlaySetLibrarySection( $3 ) ) YYABORT;
270 				free( $3 );
271 			}
272 			;
273 
274 overlayLibraryList	: /*NULL*/
275 			| overlayLibraryList gOBJECTNAME
276 			{
277 				if ( !OverlayAddLibrary( $2.string, $2.type ) ) YYABORT;
278 			}
279 			;
280 
281 overlaySearchSymbols	: tSEARCHSYMBOL overlaySearchSymbolList tNL
282 			;
283 
284 overlaySearchSymbolList	: /*NULL*/
285 			| overlaySearchSymbolList tSTRING_ID
286 			{
287 				if ( !OverlayAddSearchSymbol( $2 ) ) YYABORT;
288 			}
289 			;
290 
291 overlayForces	: tFORCE overlayForceList tNL
292 			;
293 
294 overlayForceList	: /*NULL*/
295 			| overlayForceList tSTRING_FORCE
296 			{
297 				if ( !OverlayAddForce( $2 ) ) YYABORT;
298 			}
299 			;
300 
301 overlayCompress	: tCOMPRESS tSTRING_ID tNL
302 			{
303 				if ( !OverlaySetCompress( $2 ) ) YYABORT;
304 			}
305 			;
306 
307 /*===========================================================================
308  *     AUTOLOAD autoloadname
309  *     {
310  *        .....
311  *     }
312  */
313 sectionAutoload		: autoloadKeyword begin autoloadParams end
314 			;
315 
316 autoloadKeyword		: tAUTOLOAD tSTRING_ID tNL
317 			{
318 				if ( !AddAutoload( $2 ) ) YYABORT;
319 			}
320 			;
321 
322 autoloadParams		: /*NULL*/
323 			| autoloadParams autoloadParam
324 			;
325 
326 /* mostly same as overlayParam except no "group" */
327 autoloadParam		: tNL
328 			| overlayAddress
329 			| overlayAfters
330 			| overlayObjects
331 			| overlaySearchSymbols
332 			| overlayForces
333 			| overlayLibraries
334 			;
335 
336 /*===========================================================================
337  *     LTDOVERLAY ltdoverlayname
338  *     {
339  *        .....
340  *     }
341  */
342 sectionLtdoverlay		: ltdoverlayKeyword begin ltdoverlayParams end
343 			;
344 
345 ltdoverlayKeyword		: tLTDOVERLAY tSTRING_ID tNL
346 			{
347 				if ( !AddLtdoverlay( $2 ) ) YYABORT;
348 			}
349 			;
350 
351 ltdoverlayParams		: /*NULL*/
352 			| ltdoverlayParams ltdoverlayParam
353 			;
354 
355 ltdoverlayParam		: tNL
356 			| overlayGroup
357 			| overlayAddress
358 			| overlayAfters
359 			| overlayObjects
360 			| overlaySearchSymbols
361 			| overlayForces
362 			| overlayLibraries
363 			| overlayCompress
364 			;
365 
366 /*===========================================================================
367  *     LTDAUTOLOAD ltdautoloadname
368  *     {
369  *        .....
370  *     }
371  */
372 sectionLtdautoload		: ltdautoloadKeyword begin ltdautoloadParams end
373 			;
374 
375 ltdautoloadKeyword		: tLTDAUTOLOAD tSTRING_ID tNL
376 			{
377 				if ( !AddLtdautoload( $2 ) ) YYABORT;
378 			}
379 			;
380 
381 ltdautoloadParams		: /*NULL*/
382 			| ltdautoloadParams ltdautoloadParam
383 			;
384 
385 /* mostly same as overlayParam except no "group" */
386 ltdautoloadParam		: tNL
387 			| overlayAddress
388 			| overlayAfters
389 			| overlayObjects
390 			| overlaySearchSymbols
391 			| overlayForces
392 			| overlayLibraries
393 			;
394 
395 /*===========================================================================
396  *     PROPERTY
397  *     {
398  *        .....
399  *     }
400  */
401 sectionProperty		: propertyKeyword begin propertyParams end
402 			;
403 
404 propertyKeyword		: tPROPERTY tNL
405 			;
406 
407 propertyParams		: /*NULL*/
408 			| propertyParams propertyParam
409 			;
410 
411 propertyParam		: tNL
412 			| propertyName
413 			| propertyOverlay
414 			| propertyLtdname
415 			| propertyLtdoverlay
416 			| propertySuffix
417 			| propertyFlxsuffix
418 			| propertyLtdsuffix
419 			;
420 
421 propertyName		: tOVERLAYDEFS gFILENAME tNL
422 			{
423 				if ( !PropertySetOverlayDefs( $2 ) ) YYABORT;
424 			}
425 			;
426 
427 propertyOverlay		: tOVERLAYTABLE gFILENAME tNL
428 			{
429 				if ( !PropertySetOverlayTable( $2 ) ) YYABORT;
430 			}
431 			;
432 
433 propertyLtdname		: tLTDOVERLAYDEFS gFILENAME tNL
434 			{
435 				if ( !PropertySetLtdoverlayDefs( $2 ) ) YYABORT;
436 			}
437 			;
438 
439 propertyLtdoverlay		: tLTDOVERLAYTABLE gFILENAME tNL
440 			{
441 				if ( !PropertySetLtdoverlayTable( $2 ) ) YYABORT;
442 			}
443 			;
444 
445 propertySuffix		: tSUFFIX gFILENAME tNL
446 			{
447 				if ( !PropertySetSuffix( $2 ) ) YYABORT;
448 			}
449 			;
450 
451 propertyFlxsuffix	: tFLXSUFFIX gFILENAME tNL
452 			{
453 				if ( !PropertySetFlxsuffix( $2 ) ) YYABORT;
454 			}
455 			;
456 
457 propertyLtdsuffix	: tLTDSUFFIX gFILENAME tNL
458 			{
459 				if ( !PropertySetLtdsuffix( $2 ) ) YYABORT;
460 			}
461 			;
462 
463 /*===========================================================================
464  *	MISC
465  */
466 
467 begin			: tBEGIN tNL
468 			;
469 
470 end			: tEND tNL
471 			;
472 
473 gFILENAME		: tSTRING_ID
474 			| tSTRING_QUATED
475 			| tSTRING_NOSPACE
476 			;
477 
478 gOBJECTNAME		: gFILENAME
479 			{
480 				$$.string = $1;
481 				$$.type   = OBJTYPE_FILE;
482 			}
483 			| tSTRING_STAR
484 			{
485 				$$.string = $1;
486 				$$.type   = OBJTYPE_STAR;
487 			}
488 			| tSTRING_GROUP
489 			{
490 				$$.string = $1;
491 				$$.type   = OBJTYPE_GROUP;
492 			}
493 			| tSTRING_FUNCTION
494 			{
495 				$$.string = $1;
496 				$$.type   = OBJTYPE_OBJECT;
497 			}
498 			;
499 %%
500