]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfParserMisc.py
Add PCI PMC and PMCSR register definitions from PCI Power Management Interface Specif...
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfParserMisc.py
CommitLineData
4234283c
LG
1## @file\r
2# This file contained the miscellaneous functions for INF parser \r
3#\r
4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials are licensed and made available \r
7# under the terms and conditions of the BSD License which accompanies this \r
8# distribution. The full text of the license may be found at \r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15'''\r
16InfParserMisc\r
17'''\r
18\r
19##\r
20# Import Modules\r
21#\r
22import re\r
23\r
24\r
25from Library import DataType as DT\r
26\r
27\r
28from Library.String import gMACRO_PATTERN\r
29from Library.String import ReplaceMacro\r
30from Object.Parser.InfMisc import ErrorInInf\r
31from Logger.StringTable import ERR_MARCO_DEFINITION_MISS_ERROR\r
32\r
33#\r
34# Global variable\r
35#\r
36\r
37#\r
38# Sections can exist in INF file\r
39#\r
40gINF_SECTION_DEF = {\r
41 DT.TAB_UNKNOWN.upper() : DT.MODEL_UNKNOWN,\r
42 DT.TAB_HEADER.upper() : DT.MODEL_META_DATA_FILE_HEADER,\r
43 DT.TAB_INF_DEFINES.upper() : DT.MODEL_META_DATA_DEFINE,\r
44 DT.TAB_BUILD_OPTIONS.upper() : DT.MODEL_META_DATA_BUILD_OPTION,\r
45 DT.TAB_LIBRARY_CLASSES.upper() : DT.MODEL_EFI_LIBRARY_CLASS,\r
46 DT.TAB_PACKAGES.upper() : DT.MODEL_META_DATA_PACKAGE,\r
47 DT.TAB_INF_FIXED_PCD.upper() : DT.MODEL_PCD_FIXED_AT_BUILD,\r
48 DT.TAB_INF_PATCH_PCD.upper() : DT.MODEL_PCD_PATCHABLE_IN_MODULE,\r
49 DT.TAB_INF_FEATURE_PCD.upper() : DT.MODEL_PCD_FEATURE_FLAG,\r
50 DT.TAB_INF_PCD_EX.upper() : DT.MODEL_PCD_DYNAMIC_EX,\r
51 DT.TAB_INF_PCD.upper() : DT.MODEL_PCD_DYNAMIC,\r
52 DT.TAB_SOURCES.upper() : DT.MODEL_EFI_SOURCE_FILE,\r
53 DT.TAB_GUIDS.upper() : DT.MODEL_EFI_GUID,\r
54 DT.TAB_PROTOCOLS.upper() : DT.MODEL_EFI_PROTOCOL,\r
55 DT.TAB_PPIS.upper() : DT.MODEL_EFI_PPI,\r
56 DT.TAB_DEPEX.upper() : DT.MODEL_EFI_DEPEX,\r
57 DT.TAB_BINARIES.upper() : DT.MODEL_EFI_BINARY_FILE,\r
58 DT.TAB_USER_EXTENSIONS.upper() : DT.MODEL_META_DATA_USER_EXTENSION\r
59 #\r
60 # EDK1 section\r
61 # TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE\r
62 # \r
63 }\r
64\r
65## InfExpandMacro\r
66#\r
67# Expand MACRO definition with MACROs defined in [Defines] section and specific section. \r
68# The MACROs defined in specific section has high priority and will be expanded firstly.\r
69#\r
70# @param LineInfo Contain information of FileName, LineContent, LineNo\r
71# @param GlobalMacros MACROs defined in INF [Defines] section\r
72# @param SectionMacros MACROs defined in INF specific section\r
73# @param Flag If the flag set to True, need to skip macros in a quoted string \r
74#\r
75def InfExpandMacro(Content, LineInfo, GlobalMacros=None, SectionMacros=None, Flag=False):\r
76 if GlobalMacros == None:\r
77 GlobalMacros = {}\r
78 if SectionMacros == None:\r
79 SectionMacros = {}\r
80 \r
81 FileName = LineInfo[0]\r
82 LineContent = LineInfo[1]\r
83 LineNo = LineInfo[2]\r
84 \r
85 NewLineInfo = (FileName, LineNo, LineContent)\r
86 \r
87 #\r
88 # First, replace MARCOs with value defined in specific section\r
89 #\r
90 Content = ReplaceMacro (Content, \r
91 SectionMacros,\r
92 False,\r
93 (LineContent, LineNo),\r
94 FileName,\r
95 Flag)\r
96 #\r
97 # Then replace MARCOs with value defined in [Defines] section\r
98 #\r
99 Content = ReplaceMacro (Content, \r
100 GlobalMacros,\r
101 False,\r
102 (LineContent, LineNo),\r
103 FileName,\r
104 Flag)\r
105 \r
106 MacroUsed = gMACRO_PATTERN.findall(Content)\r
107 #\r
108 # no macro found in String, stop replacing\r
109 #\r
110 if len(MacroUsed) == 0:\r
111 return Content\r
112 else:\r
113 for Macro in MacroUsed:\r
114 gQuotedMacro = re.compile(".*\".*\$\(%s\).*\".*"%(Macro))\r
115 if not gQuotedMacro.match(Content):\r
116 #\r
117 # Still have MACROs can't be expanded.\r
118 #\r
119 ErrorInInf (ERR_MARCO_DEFINITION_MISS_ERROR,\r
120 LineInfo=NewLineInfo)\r
121 \r
122 return Content\r
123 \r
124\r
125## IsBinaryInf\r
126#\r
127# Judge whether the INF file is Binary INF or Common INF\r
128#\r
129# @param FileLineList A list contain all INF file content.\r
130#\r
131def IsBinaryInf(FileLineList):\r
132 if not FileLineList:\r
133 return False\r
134 \r
135 ReIsSourcesSection = re.compile("^\s*\[Sources.*\]\s.*$", re.IGNORECASE)\r
136 ReIsBinarySection = re.compile("^\s*\[Binaries.*\]\s.*$", re.IGNORECASE)\r
137 BinarySectionFoundFlag = False\r
138 \r
139 for Line in FileLineList:\r
140 if ReIsSourcesSection.match(Line):\r
141 return False\r
142 if ReIsBinarySection.match(Line):\r
143 BinarySectionFoundFlag = True\r
144 \r
145 if BinarySectionFoundFlag:\r
146 return True\r
147 \r
148 return False\r
149 \r
150 \r
151## IsLibInstanceInfo\r
152# \r
153# Judge whether the string contain the information of ## @LIB_INSTANCES.\r
154#\r
155# @param String\r
156#\r
157# @return Flag\r
158#\r
159def IsLibInstanceInfo(String):\r
160 ReIsLibInstance = re.compile("^\s*##\s*@LIB_INSTANCES\s*$")\r
161 if ReIsLibInstance.match(String):\r
162 return True\r
163 else:\r
164 return False\r
165 \r
166 \r
167## IsAsBuildOptionInfo\r
168# \r
169# Judge whether the string contain the information of ## @ASBUILD.\r
170#\r
171# @param String\r
172#\r
173# @return Flag\r
174#\r
175def IsAsBuildOptionInfo(String):\r
176 ReIsAsBuildInstance = re.compile("^\s*##\s*@AsBuilt\s*$")\r
177 if ReIsAsBuildInstance.match(String):\r
178 return True\r
179 else:\r
180 return False \r
181 \r
182\r
183class InfParserSectionRoot(object):\r
184 def __init__(self):\r
185 #\r
186 # Macros defined in [Define] section are file scope global\r
187 #\r
188 self.FileLocalMacros = {}\r
189 \r
190 #\r
191 # Current Section Header content. \r
192 #\r
193 self.SectionHeaderContent = []\r
194\r
195 #\r
196 # Last time Section Header content. \r
197 #\r
198 self.LastSectionHeaderContent = [] \r
199 \r
200 self.FullPath = ''\r
201 \r
202 self.InfDefSection = None\r
203 self.InfBuildOptionSection = None\r
204 self.InfLibraryClassSection = None\r
205 self.InfPackageSection = None\r
206 self.InfPcdSection = None\r
207 self.InfSourcesSection = None\r
208 self.InfUserExtensionSection = None\r
209 self.InfProtocolSection = None\r
210 self.InfPpiSection = None\r
211 self.InfGuidSection = None\r
212 self.InfDepexSection = None\r
213 self.InfPeiDepexSection = None\r
214 self.InfDxeDepexSection = None\r
215 self.InfSmmDepexSection = None\r
216 self.InfBinariesSection = None\r
217 self.InfHeader = None\r
218 self.InfSpecialCommentSection = None \r