]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfBinarySectionParser.py
1 ## @file
2 # This file contained the parser for [Binaries] sections in INF file
3 #
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8 '''
9 InfBinarySectionParser
10 '''
11 ##
12 # Import Modules
13 #
14
15 import Logger.Log as Logger
16 from Logger import StringTable as ST
17 from Logger.ToolError import FORMAT_INVALID
18 from Parser.InfParserMisc import InfExpandMacro
19 from Library import DataType as DT
20 from Library.Parsing import MacroParser
21 from Library.Misc import GetSplitValueList
22 from Object.Parser.InfCommonObject import InfLineCommentObject
23 from Object.Parser.InfCommonObject import CurrentLine
24 from Parser.InfParserMisc import InfParserSectionRoot
25
26 class InfBinarySectionParser(InfParserSectionRoot):
27 ## InfBinaryParser
28 #
29 #
30 def InfBinaryParser(self, SectionString, InfSectionObject, FileName):
31 #
32 # Macro defined in this section
33 #
34 SectionMacros = {}
35 ValueList = []
36 #
37 # For UI (UI, SEC_UI, UNI_UI) binaries
38 # One and only one UI section can be included
39 #
40 UiBinaryList = []
41 #
42 # For Version (VER, SEC_VER, UNI_VER).
43 # One and only one VER section on be included
44 #
45 VerBinaryList = []
46 #
47 # For other common type binaries
48 #
49 ComBinaryList = []
50
51 StillCommentFalg = False
52 HeaderComments = []
53 LineComment = None
54
55 AllSectionContent = ''
56 #
57 # Parse section content
58 #
59 for Line in SectionString:
60 BinLineContent = Line[0]
61 BinLineNo = Line[1]
62
63 if BinLineContent.strip() == '':
64 continue
65
66 CurrentLineObj = CurrentLine()
67 CurrentLineObj.FileName = FileName
68 CurrentLineObj.LineString = BinLineContent
69 CurrentLineObj.LineNo = BinLineNo
70 #
71 # Found Header Comments
72 #
73 if BinLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
74 #
75 # Last line is comments, and this line go on.
76 #
77 if StillCommentFalg:
78 HeaderComments.append(Line)
79 AllSectionContent += BinLineContent + DT.END_OF_LINE
80 continue
81 #
82 # First time encounter comment
83 #
84 else:
85 #
86 # Clear original data
87 #
88 HeaderComments = []
89 HeaderComments.append(Line)
90 AllSectionContent += BinLineContent + DT.END_OF_LINE
91 StillCommentFalg = True
92 continue
93 else:
94 StillCommentFalg = False
95
96 if len(HeaderComments) >= 1:
97 LineComment = InfLineCommentObject()
98 LineCommentContent = ''
99 for Item in HeaderComments:
100 LineCommentContent += Item[0] + DT.END_OF_LINE
101 LineComment.SetHeaderComments(LineCommentContent)
102
103 #
104 # Find Tail comment.
105 #
106 if BinLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
107 TailComments = BinLineContent[BinLineContent.find(DT.TAB_COMMENT_SPLIT):]
108 BinLineContent = BinLineContent[:BinLineContent.find(DT.TAB_COMMENT_SPLIT)]
109 if LineComment is None:
110 LineComment = InfLineCommentObject()
111 LineComment.SetTailComments(TailComments)
112
113 #
114 # Find Macro
115 #
116 MacroDef = MacroParser((BinLineContent, BinLineNo),
117 FileName,
118 DT.MODEL_EFI_BINARY_FILE,
119 self.FileLocalMacros)
120 if MacroDef[0] is not None:
121 SectionMacros[MacroDef[0]] = MacroDef[1]
122 LineComment = None
123 HeaderComments = []
124 continue
125
126 #
127 # Replace with Local section Macro and [Defines] section Macro.
128 #
129 LineContent = InfExpandMacro(BinLineContent,
130 (FileName, BinLineContent, BinLineNo),
131 self.FileLocalMacros,
132 SectionMacros, True)
133
134 AllSectionContent += LineContent + DT.END_OF_LINE
135 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)
136 ValueList[0:len(TokenList)] = TokenList
137
138 #
139 # Should equal to UI/SEC_UI/UNI_UI
140 #
141 ValueList[0] = ValueList[0].strip()
142 if ValueList[0] == DT.BINARY_FILE_TYPE_UNI_UI or \
143 ValueList[0] == DT.BINARY_FILE_TYPE_SEC_UI or \
144 ValueList[0] == DT.BINARY_FILE_TYPE_UI:
145 if len(ValueList) == 2:
146 TokenList = GetSplitValueList(ValueList[1],
147 DT.TAB_VALUE_SPLIT,
148 2)
149 NewValueList = []
150 NewValueList.append(ValueList[0])
151 for Item in TokenList:
152 NewValueList.append(Item)
153 UiBinaryList.append((NewValueList,
154 LineComment,
155 CurrentLineObj))
156 #
157 # Should equal to VER/SEC_VER/UNI_VER
158 #
159 elif ValueList[0] == DT.BINARY_FILE_TYPE_UNI_VER or \
160 ValueList[0] == DT.BINARY_FILE_TYPE_SEC_VER or \
161 ValueList[0] == DT.BINARY_FILE_TYPE_VER:
162 if len(ValueList) == 2:
163 TokenList = GetSplitValueList(ValueList[1],
164 DT.TAB_VALUE_SPLIT,
165 2)
166 NewValueList = []
167 NewValueList.append(ValueList[0])
168 for Item in TokenList:
169 NewValueList.append(Item)
170 VerBinaryList.append((NewValueList,
171 LineComment,
172 CurrentLineObj))
173 else:
174 if len(ValueList) == 2:
175 if ValueList[0].strip() == 'SUBTYPE_GUID':
176 TokenList = GetSplitValueList(ValueList[1],
177 DT.TAB_VALUE_SPLIT,
178 5)
179 else:
180 TokenList = GetSplitValueList(ValueList[1],
181 DT.TAB_VALUE_SPLIT,
182 4)
183
184 NewValueList = []
185 NewValueList.append(ValueList[0])
186 for Item in TokenList:
187 NewValueList.append(Item)
188 ComBinaryList.append((NewValueList,
189 LineComment,
190 CurrentLineObj))
191 elif len(ValueList) == 1:
192 NewValueList = []
193 NewValueList.append(ValueList[0])
194 ComBinaryList.append((NewValueList,
195 LineComment,
196 CurrentLineObj))
197
198
199
200
201 ValueList = []
202 LineComment = None
203 TailComments = ''
204 HeaderComments = []
205 continue
206
207 #
208 # Current section archs
209 #
210 ArchList = []
211 for Item in self.LastSectionHeaderContent:
212 if Item[1] not in ArchList:
213 ArchList.append(Item[1])
214 InfSectionObject.SetSupArchList(Item[1])
215
216 InfSectionObject.SetAllContent(AllSectionContent)
217 if not InfSectionObject.SetBinary(UiBinaryList,
218 VerBinaryList,
219 ComBinaryList,
220 ArchList):
221 Logger.Error('InfParser',
222 FORMAT_INVALID,
223 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Binaries]"),
224 File=FileName,
225 Line=Item[3])
226