summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/GenPatchPcdTable
diff options
context:
space:
mode:
authorCarsey, Jaben <jaben.carsey@intel.com>2018-04-20 23:51:22 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-04-26 14:27:59 +0800
commit2a9aac46a639e2a6f253d57ba699ce712f819532 (patch)
treeb9ecc60b95488c84e9b61dc4ac26b46eb399e391 /BaseTools/Source/Python/GenPatchPcdTable
parent6686d9a125398115fb33cc6b1dd87c7924729f1d (diff)
downloadedk2-2a9aac46a639e2a6f253d57ba699ce712f819532.tar.gz
edk2-2a9aac46a639e2a6f253d57ba699ce712f819532.tar.bz2
edk2-2a9aac46a639e2a6f253d57ba699ce712f819532.zip
BaseTools: GenPatchPcdTable - refactor RegEx to minimize multiple compiling
Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/GenPatchPcdTable')
-rw-r--r--BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
index dc2ceaf775..59748763a5 100644
--- a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
+++ b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
@@ -63,6 +63,7 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
return _parseGeneral(lines, efifilepath)
def _parseForXcode(lines, efifilepath):
+ valuePattern = re.compile('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))')
status = 0
pcds = []
for line in lines:
@@ -72,13 +73,16 @@ def _parseForXcode(lines, efifilepath):
continue
if status == 1 and len(line) != 0:
if '_gPcd_BinaryPatch_' in line:
- m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))', line)
+ m = valuePattern.match(line)
if m is not None:
pcds.append((m.groups(0)[3], int(m.groups(0)[0], 16)))
return pcds
def _parseForGCC(lines, efifilepath):
""" Parse map file generated by GCC linker """
+ valuePattern = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
+ dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')
+ pcdPattern = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
status = 0
imageBase = -1
sections = []
@@ -98,15 +102,15 @@ def _parseForGCC(lines, efifilepath):
# status handler
if status == 3:
- m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)
+ m = valuePattern.match(line)
if m is not None:
sections.append(m.groups(0))
if status == 3:
- m = re.match('^.data._gPcd_BinaryPatch_([\w_\d]+)$', line)
+ m = dataPattern.match(line)
if m is not None:
if lines[index + 1]:
PcdName = m.groups(0)[0]
- m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', lines[index + 1].strip())
+ m = pcdPattern.match(lines[index + 1].strip())
if m is not None:
bpcds.append((PcdName, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))
@@ -137,17 +141,19 @@ def _parseGeneral(lines, efifilepath):
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
secs = [] # key = section name
bPcds = []
-
+ startPattern = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
+ addressPattern = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
+ symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)')
for line in lines:
line = line.strip()
- if re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line):
+ if startPattern.match(line):
status = 1
continue
- if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line):
+ if addressPattern.match(line):
status = 2
continue
- if re.match("^entry point at", line):
+ if line.startswith("entry point at"):
status = 3
continue
if status == 1 and len(line) != 0:
@@ -162,7 +168,7 @@ def _parseGeneral(lines, efifilepath):
sec_no = int(sec_no, 16)
sym_offset = int(sym_offset, 16)
vir_addr = int(vir_addr, 16)
- m2 = re.match('^[_]+gPcd_BinaryPatch_([\w]+)', sym_name)
+ m2 = symPattern.match(sym_name)
if m2 is not None:
# fond a binary pcd entry in map file
for sec in secs: