3
|
1 |
#
|
|
2 |
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# MMPParser module
|
|
16 |
# This module provides a parser for MMP files which can work
|
|
17 |
# with any supplied MMPBackend
|
|
18 |
#
|
|
19 |
|
|
20 |
|
|
21 |
# We have to define the grammar in the following order:
|
|
22 |
# Actions - because the rules reference them
|
|
23 |
# Terminals - because the rules use them
|
|
24 |
# Rules
|
|
25 |
# Root rule - e.g. "an MMP is a list of statements"
|
|
26 |
#
|
|
27 |
# This seems inverted but it's just the price of
|
|
28 |
# being able to use python to define the grammar.
|
|
29 |
|
|
30 |
|
|
31 |
from pyparsing import *
|
|
32 |
import sys
|
|
33 |
|
|
34 |
# For multiline matching we must exclude \n from the list of whitespace
|
|
35 |
# characters. If we don't then Parse Elements like OneOrMore won't stop
|
|
36 |
# at line boundaries.
|
|
37 |
# \r doesn't matter as it is always followed by \n anyhow it is
|
|
38 |
# redundant and may be thrown away without any loss of information.
|
|
39 |
ParserElement.setDefaultWhitespaceChars('\t\r ')
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
## Useful Parse Elements #########################################
|
|
45 |
def String():
|
|
46 |
return Regex('[^ \n]+')
|
|
47 |
|
|
48 |
def StringList():
|
|
49 |
return Group(OneOrMore(Regex('[^ \n]+')))
|
|
50 |
|
|
51 |
def HexOrDecNumber():
|
|
52 |
return Regex('(0[xX][0-9a-fA-Z]+)|([0-9]+)')
|
|
53 |
|
|
54 |
def Line(pattern):
|
|
55 |
return pattern.copy() + LineEnd().suppress()
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
class MMPParser(object):
|
|
60 |
# Tools for whom options may be specified
|
|
61 |
tools = [ 'ARMCC', 'CW', 'GCC', 'MSVC', 'GCCXML', 'ARMASM', 'GCCE' ]
|
|
62 |
|
|
63 |
|
|
64 |
def __init__(self,statemachine):
|
|
65 |
self.backend = statemachine
|
|
66 |
# Create Tokens for the tools we support
|
|
67 |
self.toolName = CaselessKeyword(MMPParser.tools[0])
|
|
68 |
for thisTool in MMPParser.tools[1:]:
|
|
69 |
self.toolName ^= CaselessKeyword(thisTool)
|
|
70 |
|
|
71 |
self.assignment = \
|
|
72 |
( \
|
|
73 |
Line(CaselessKeyword('ARMFPU') + String()) ^ \
|
9
|
74 |
Line(CaselessKeyword('APPLY') + String()) ^ \
|
3
|
75 |
Line(CaselessKeyword('ASSPLIBRARY') + StringList()) ^ \
|
|
76 |
Line(CaselessKeyword('CAPABILITY') + StringList()) ^ \
|
|
77 |
Line(CaselessKeyword('DOCUMENT') + StringList()) ^ \
|
|
78 |
Line(CaselessKeyword('EPOCHEAPSIZE') + HexOrDecNumber() + HexOrDecNumber()) ^ \
|
|
79 |
Line(CaselessKeyword('EPOCPROCESSPRIORITY') + String()) ^ \
|
|
80 |
Line(CaselessKeyword('FIRSTLIB') + String()) ^ \
|
|
81 |
Line(CaselessKeyword('TARGET') + String()) ^ \
|
|
82 |
Line(CaselessKeyword('ROMTARGET') + Optional(StringList())) ^ \
|
|
83 |
Line(CaselessKeyword('RAMTARGET') + String()) ^ \
|
|
84 |
Line(CaselessKeyword('TARGETTYPE') + String()) ^ \
|
|
85 |
Line(CaselessKeyword('TARGETPATH') + String()) ^ \
|
|
86 |
Line(CaselessKeyword('SYSTEMINCLUDE') + StringList()) ^ \
|
|
87 |
Line(CaselessKeyword('USERINCLUDE') + StringList()) ^ \
|
|
88 |
Line(CaselessKeyword('DEFFILE') + String()) ^ \
|
|
89 |
Line(CaselessKeyword('EXPORTLIBRARY') + String()) ^ \
|
|
90 |
Line(CaselessKeyword('LINKAS') + String()) ^ \
|
|
91 |
Line(CaselessKeyword('VENDORID') + HexOrDecNumber()) ^ \
|
|
92 |
Line(CaselessKeyword('OPTION') + self.toolName + StringList()) ^ \
|
|
93 |
Line(CaselessKeyword('LINKEROPTION') + self.toolName + StringList()) ^\
|
|
94 |
Line(CaselessKeyword('OPTION_REPLACE') + self.toolName + StringList()) ^ \
|
|
95 |
Line(CaselessKeyword('SECUREID') + HexOrDecNumber()) ^ \
|
|
96 |
Line(CaselessKeyword('EPOCSTACKSIZE') + HexOrDecNumber()) ^ \
|
|
97 |
Line(CaselessKeyword('VERSION') + String() + Optional(CaselessKeyword('EXPLICIT'))) ^ \
|
|
98 |
Line(CaselessKeyword('EPOCPROCESSPRIORITY') + String()) ^ \
|
|
99 |
Line(CaselessKeyword('NEWLIB') + String()) \
|
|
100 |
).setParseAction(self.backend.doAssignment) ^ \
|
|
101 |
( \
|
|
102 |
Line(CaselessKeyword('SOURCE') + StringList()).setParseAction(self.backend.doSourceAssignment) \
|
|
103 |
).setParseAction(self.backend.doSourceAssignment) ^ \
|
|
104 |
( \
|
|
105 |
Line(CaselessKeyword('RESOURCE') + StringList()).setParseAction(self.backend.doOldResourceAssignment) \
|
|
106 |
).setParseAction(self.backend.doOldResourceAssignment) ^ \
|
|
107 |
( \
|
|
108 |
Line(CaselessKeyword('SYSTEMRESOURCE') + StringList()).setParseAction(self.backend.doResourceAssignment) \
|
|
109 |
).setParseAction(self.backend.doOldResourceAssignment) ^ \
|
|
110 |
( \
|
|
111 |
Line(CaselessKeyword('SOURCEPATH') + String()).setParseAction(self.backend.doSourceAssignment) \
|
|
112 |
).setParseAction(self.backend.doSourcePathAssignment) ^ \
|
|
113 |
( \
|
|
114 |
Line((CaselessKeyword('UID') + Group(HexOrDecNumber() + Optional(HexOrDecNumber())))).setParseAction(self.backend.doUIDAssignment) \
|
|
115 |
).setParseAction(self.backend.doUIDAssignment) ^ \
|
|
116 |
( \
|
|
117 |
Line(CaselessKeyword('LANG') + StringList()) \
|
|
118 |
).setParseAction(self.backend.doAppend) ^ \
|
|
119 |
( \
|
|
120 |
Line(CaselessKeyword('LIBRARY') + StringList()) \
|
|
121 |
).setParseAction(self.backend.doAppend) ^ \
|
|
122 |
( \
|
|
123 |
Line(CaselessKeyword('DEBUGLIBRARY') + StringList()) \
|
|
124 |
).setParseAction(self.backend.doAppend) ^ \
|
|
125 |
( \
|
|
126 |
Line(CaselessKeyword('MACRO') + Optional(StringList())) \
|
|
127 |
).setParseAction(self.backend.doAppend) ^ \
|
|
128 |
( \
|
|
129 |
Line(CaselessKeyword('AIF') + StringList()) \
|
|
130 |
).setParseAction(self.backend.doDeprecated) ^ \
|
|
131 |
( \
|
|
132 |
Line(CaselessKeyword('STATICLIBRARY') + StringList()) \
|
|
133 |
).setParseAction(self.backend.doAppend)
|
|
134 |
|
|
135 |
self.switch = \
|
|
136 |
(Line( \
|
|
137 |
CaselessKeyword('ALWAYS_BUILD_AS_ARM') ^ \
|
|
138 |
CaselessKeyword('ASSPEXPORTS') ^ \
|
|
139 |
CaselessKeyword('ASSPABI') ^ \
|
|
140 |
CaselessKeyword('ASSPEXPORTS') ^ \
|
|
141 |
CaselessKeyword('DEBUGGABLE') ^ \
|
|
142 |
CaselessKeyword('DEBUGGABLE_UDEBONLY') ^ \
|
|
143 |
CaselessKeyword('EPOCALLOWDLLDATA') ^ \
|
|
144 |
CaselessKeyword('EPOCCALLDLLENTRYPOINTS') ^ \
|
|
145 |
CaselessKeyword('EPOCFIXEDPROCESS') ^ \
|
|
146 |
CaselessKeyword('EXPORTUNFROZEN') ^ \
|
|
147 |
CaselessKeyword('FEATUREVARIANT') ^ \
|
|
148 |
CaselessKeyword('BYTEPAIRCOMPRESSTARGET') ^ \
|
|
149 |
CaselessKeyword('INFLATECOMPRESSTARGET') ^ \
|
|
150 |
CaselessKeyword('NOCOMPRESSTARGET') ^ \
|
|
151 |
CaselessKeyword('NOLINKTIMECODEGENERATION') ^ \
|
|
152 |
CaselessKeyword('NOMULTIFILECOMPILATION') ^ \
|
|
153 |
CaselessKeyword('COMPRESSTARGET') ^ \
|
|
154 |
CaselessKeyword('NOEXPORTLIBRARY') ^ \
|
|
155 |
CaselessKeyword('NOSTRICTDEF') ^ \
|
|
156 |
CaselessKeyword('SRCDBG') ^ \
|
|
157 |
CaselessKeyword('STRICTDEPEND') ^ \
|
|
158 |
CaselessKeyword('STDCPP') ^ \
|
|
159 |
CaselessKeyword('NOSTDCPP') ^ \
|
|
160 |
CaselessKeyword('SMPSAFE') ^ \
|
|
161 |
CaselessKeyword('PAGED') ^ \
|
|
162 |
CaselessKeyword('PAGEDCODE') ^ \
|
|
163 |
CaselessKeyword('PAGEDDATA') ^ \
|
|
164 |
CaselessKeyword('UNPAGED') ^ \
|
|
165 |
CaselessKeyword('UNPAGEDCODE') ^ \
|
|
166 |
CaselessKeyword('UNPAGEDDATA') ^ \
|
|
167 |
CaselessKeyword('WCHARENTRYPOINT') \
|
|
168 |
)).setParseAction(self.backend.doSetSwitch)
|
|
169 |
|
|
170 |
# General
|
|
171 |
|
|
172 |
self.blankline = (LineStart() + Regex('[\t\r ]*') + LineEnd().suppress() \
|
|
173 |
).setParseAction(self.backend.doBlankLine)
|
|
174 |
|
|
175 |
self.preProcessorComment = (LineStart() + Regex('# .*') + LineEnd().suppress()
|
|
176 |
).setParseAction(self.backend.doPreProcessorComment)
|
|
177 |
|
|
178 |
self.unknownstatement = (LineStart() + Regex('.*\S+') + LineEnd().suppress() \
|
|
179 |
).setParseAction(self.backend.doUnknownStatement)
|
|
180 |
|
|
181 |
self.unknownBlockBody = (\
|
|
182 |
(Regex("[^\n]+?\s*") + LineEnd().suppress()).setParseAction(self.backend.doStartUnknown) + \
|
|
183 |
ZeroOrMore(self.unknownstatement) \
|
|
184 |
).setParseAction(self.backend.doEndUnknown)
|
|
185 |
|
|
186 |
# Platform
|
|
187 |
|
|
188 |
self.ARMCCBlockStatement = \
|
|
189 |
self.blankline ^ self.preProcessorComment ^ \
|
|
190 |
Line( \
|
|
191 |
CaselessKeyword('ARMRT') ^ \
|
|
192 |
CaselessKeyword('ARMINC') \
|
|
193 |
).setParseAction(self.backend.doSetSwitch) ^ \
|
|
194 |
Line( \
|
|
195 |
(CaselessKeyword('ARMLIBS') + StringList()) \
|
|
196 |
).setParseAction(self.backend.doAppend)
|
|
197 |
|
|
198 |
self.WINSBlockStatement = \
|
|
199 |
self.blankline ^ self.preProcessorComment ^ \
|
|
200 |
Line( \
|
|
201 |
(CaselessKeyword('BASEADDRESS') + HexOrDecNumber()) \
|
|
202 |
).setParseAction(self.backend.doAssignment) ^ \
|
|
203 |
Line( \
|
|
204 |
(CaselessKeyword('WIN32_LIBRARY') + StringList()) \
|
|
205 |
).setParseAction(self.backend.doAppend) ^ \
|
|
206 |
Line( \
|
|
207 |
(CaselessKeyword('WIN32_RESOURCE') + StringList()) \
|
|
208 |
).setParseAction(self.backend.doAppend) ^ \
|
|
209 |
Line( \
|
|
210 |
CaselessKeyword('WIN32_HEADERS') ^ \
|
|
211 |
CaselessKeyword('COPY_FOR_STATIC_LINKAGE')
|
|
212 |
).setParseAction(self.backend.doSetSwitch)
|
|
213 |
|
|
214 |
self.TOOLSBlockStatement = \
|
|
215 |
self.blankline ^ self.preProcessorComment ^ \
|
|
216 |
Line( \
|
|
217 |
(CaselessKeyword('WIN32_LIBRARY') + StringList()) \
|
|
218 |
).setParseAction(self.backend.doAppend)
|
|
219 |
|
|
220 |
self.platformBlock = ( \
|
|
221 |
((CaselessKeyword('ARMCC') + LineEnd().suppress()).setParseAction(self.backend.doStartPlatform) + ZeroOrMore(self.ARMCCBlockStatement)) ^ \
|
|
222 |
((CaselessKeyword('WINS') + LineEnd().suppress()).setParseAction(self.backend.doStartPlatform) + ZeroOrMore(self.WINSBlockStatement)) ^ \
|
|
223 |
((CaselessKeyword('WINSCW') + LineEnd().suppress()).setParseAction(self.backend.doStartPlatform) + ZeroOrMore(self.WINSBlockStatement)) ^ \
|
|
224 |
(CaselessKeyword('MARM') + LineEnd().suppress()).setParseAction(self.backend.doStartPlatform) ^ \
|
|
225 |
((CaselessKeyword('TOOLS') + LineEnd().suppress()).setParseAction(self.backend.doStartPlatform) + ZeroOrMore(self.TOOLSBlockStatement)) ^ \
|
|
226 |
(CaselessKeyword('WINC') + LineEnd().suppress()).setParseAction(self.backend.doStartPlatform) + ZeroOrMore(self.WINSBlockStatement) \
|
|
227 |
).setParseAction(self.backend.doEndPlatform)
|
|
228 |
|
|
229 |
# Resource
|
|
230 |
|
|
231 |
self.resourceSetting= \
|
|
232 |
self.blankline ^ self.preProcessorComment ^ \
|
|
233 |
Line( \
|
|
234 |
(CaselessKeyword('TARGET') + String()) ^ \
|
|
235 |
(CaselessKeyword('TARGETPATH') + String()) ^ \
|
|
236 |
(CaselessKeyword('UID') + HexOrDecNumber()) \
|
|
237 |
).setParseAction(self.backend.doResourceAssignment) ^ \
|
|
238 |
Line( \
|
|
239 |
(CaselessKeyword('DEPENDS') + StringList()) ^ \
|
|
240 |
(CaselessKeyword('LANG') + StringList()) \
|
|
241 |
).setParseAction(self.backend.doResourceAppend) ^ \
|
|
242 |
Line( \
|
|
243 |
CaselessKeyword('HEADER') ^ \
|
|
244 |
CaselessKeyword('HEADERONLY')
|
|
245 |
).setParseAction(self.backend.doResourceSetSwitch)
|
|
246 |
|
|
247 |
self.resourceBlockBody = (\
|
|
248 |
(CaselessKeyword('RESOURCE') + String() + LineEnd().suppress()).setParseAction(self.backend.doStartResource) \
|
|
249 |
+ ZeroOrMore(self.resourceSetting) \
|
|
250 |
).setParseAction(self.backend.doEndResource)
|
|
251 |
|
|
252 |
# Bitmap
|
|
253 |
|
|
254 |
self.bitmapSetting = \
|
|
255 |
self.blankline ^ self.preProcessorComment ^ \
|
|
256 |
Line( \
|
|
257 |
(CaselessKeyword('TARGETPATH') + String()) \
|
|
258 |
).setParseAction(self.backend.doBitmapAssignment) ^\
|
|
259 |
Line( \
|
|
260 |
(CaselessKeyword('SOURCE') + StringList())
|
|
261 |
).setParseAction(self.backend.doBitmapSourceAssignment) ^\
|
|
262 |
Line( \
|
|
263 |
(CaselessKeyword('SOURCEPATH') + String())
|
|
264 |
).setParseAction(self.backend.doBitmapSourcePathAssignment) ^\
|
|
265 |
Line( \
|
|
266 |
CaselessKeyword('HEADER')
|
|
267 |
).setParseAction(self.backend.doBitmapSetSwitch)
|
|
268 |
|
|
269 |
self.bitmapBlockBody = (\
|
|
270 |
(CaselessKeyword('BITMAP') + String() + LineEnd().suppress()).setParseAction(self.backend.doStartBitmap) + \
|
|
271 |
ZeroOrMore(self.bitmapSetting) \
|
|
272 |
).setParseAction(self.backend.doEndBitmap)
|
|
273 |
|
|
274 |
# Stringtable
|
|
275 |
|
|
276 |
self.stringTableSetting = \
|
|
277 |
self.blankline ^ self.preProcessorComment ^ \
|
|
278 |
Line( \
|
|
279 |
(CaselessKeyword('EXPORTPATH') + String())
|
|
280 |
).setParseAction(self.backend.doStringTableAssignment) ^\
|
|
281 |
Line( \
|
|
282 |
CaselessKeyword('HEADERONLY') \
|
|
283 |
).setParseAction(self.backend.doStringTableSetSwitch)
|
|
284 |
|
|
285 |
self.stringTableBlockBody = (\
|
|
286 |
(CaselessKeyword('STRINGTABLE') + String() + LineEnd().suppress()).setParseAction(self.backend.doStartStringTable) + \
|
|
287 |
ZeroOrMore(self.stringTableSetting) \
|
|
288 |
).setParseAction(self.backend.doEndStringTable)
|
|
289 |
|
|
290 |
# Top-level
|
|
291 |
self.block = \
|
|
292 |
LineStart() + CaselessLiteral("START") + White().suppress() + \
|
|
293 |
(self.platformBlock ^ self.resourceBlockBody ^ self.bitmapBlockBody ^ self.stringTableBlockBody ^self.unknownBlockBody) + \
|
|
294 |
LineStart() + CaselessLiteral("END") + LineEnd().suppress()
|
|
295 |
|
|
296 |
|
|
297 |
self.command = \
|
|
298 |
self.assignment ^ self.switch
|
|
299 |
|
|
300 |
# Unknown blocks and statements are ordered i.e. if there's a failure to match something before,
|
|
301 |
# then they're "caught" appropriately
|
|
302 |
|
|
303 |
self.mmp = (ZeroOrMore(self.preProcessorComment ^ self.blankline ^ self.block ^ self.command ^ self.unknownstatement)).setParseAction(self.backend.doMMP)
|
|
304 |
|
|
305 |
|
|
306 |
## MMP Parsing Backends #########################################
|
|
307 |
class MMPBackend(object):
|
|
308 |
"""A "backend" for the MMP language
|
|
309 |
This may be used to implement a build system,
|
|
310 |
source analysis tool or anything else"""
|
|
311 |
def __init__(self):
|
|
312 |
super(MMPBackend,self).__init__()
|
|
313 |
def doPreProcessorComment(self,s,loc,toks):
|
|
314 |
return "OK"
|
|
315 |
|
|
316 |
def doStartPlatform(self,s,loc,toks):
|
|
317 |
return "OK"
|
|
318 |
def doEndPlatform(self,s,loc,toks):
|
|
319 |
return "OK"
|
|
320 |
|
|
321 |
def doStartResource(self,s,loc,toks):
|
|
322 |
return "OK"
|
|
323 |
def doResourceAssignment(self,s,loc,toks):
|
|
324 |
return "OK"
|
|
325 |
def doResourceAppend(self,s,loc,toks):
|
|
326 |
return "OK"
|
|
327 |
def doResourceSetSwitch(self,s,loc,toks):
|
|
328 |
return "OK"
|
|
329 |
def doEndResource(self,s,loc,toks):
|
|
330 |
return "OK"
|
|
331 |
|
|
332 |
def doStartBitmap(self,s,loc,toks):
|
|
333 |
return "OK"
|
|
334 |
def doBitmapAssignment(self,s,loc,toks):
|
|
335 |
return "OK"
|
|
336 |
def doBitmapSourceAssignment(self,s,loc,toks):
|
|
337 |
return "OK"
|
|
338 |
def doBitmapSourcePathAssignment(self,s,loc,toks):
|
|
339 |
return "OK"
|
|
340 |
def doBitmapSetSwitch(self,s,loc,toks):
|
|
341 |
return "OK"
|
|
342 |
def doEndBitmap(self,s,loc,toks):
|
|
343 |
return "OK"
|
|
344 |
|
|
345 |
def doStartStringtable(self,s,loc,toks):
|
|
346 |
return "OK"
|
|
347 |
def doStringTableAssignment(self,s,loc,toks):
|
|
348 |
return "OK"
|
|
349 |
def doStringTableSetSwitch(self,s,loc,toks):
|
|
350 |
return "OK"
|
|
351 |
def doEndStringtable(self,s,loc,toks):
|
|
352 |
return "OK"
|
|
353 |
|
|
354 |
def doSetSwitch(self,s,loc,toks):
|
|
355 |
return "OK"
|
|
356 |
def doAppend(self,s,loc,toks):
|
|
357 |
return "OK"
|
|
358 |
def doAssignment(self,s,loc,toks):
|
|
359 |
return "OK"
|
|
360 |
def doUIDAssignment(self,s,loc,toks):
|
|
361 |
return "OK"
|
|
362 |
def doSourcePathAssignment(self,s,loc,toks):
|
|
363 |
return "OK"
|
|
364 |
def doSourceAssignment(self,s,loc,toks):
|
|
365 |
return "OK"
|
|
366 |
|
|
367 |
def doOldResourceAssignment(self,s,loc,toks):
|
|
368 |
return "OK"
|
|
369 |
|
|
370 |
def doUnknownStatement(self,s,loc,toks):
|
|
371 |
return "OK"
|
|
372 |
def doStartUnknown(self,s,loc,toks):
|
|
373 |
return "OK"
|
|
374 |
def doEndUnknown(self,s,loc,toks):
|
|
375 |
return "OK"
|
|
376 |
|
|
377 |
def doBlankLine(self,s,loc,toks):
|
|
378 |
return "OK"
|
|
379 |
|
|
380 |
def doDeprecated(self,s,loc,toks):
|
|
381 |
return "OK"
|
|
382 |
|
|
383 |
def doNothing(self):
|
|
384 |
return "OK"
|
|
385 |
|
|
386 |
def doMMP(self,s,loc,toks):
|
|
387 |
return "MMP"
|
|
388 |
|
|
389 |
|