mirror of https://github.com/acidanthera/audk.git
BaseTools: Share RegEx between files
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>
This commit is contained in:
parent
2a9aac46a6
commit
1eb72acddd
|
@ -42,6 +42,13 @@ import subprocess
|
||||||
## Regular expression used to find out place holders in string template
|
## Regular expression used to find out place holders in string template
|
||||||
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
||||||
|
|
||||||
|
## regular expressions for map file processing
|
||||||
|
startPatternGeneral = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
|
||||||
|
addressPatternGeneral = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
|
||||||
|
valuePatternGcc = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
|
||||||
|
pcdPatternGcc = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
|
||||||
|
secReGeneral = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
|
||||||
|
|
||||||
## Dictionary used to store file time stamp for quick re-access
|
## Dictionary used to store file time stamp for quick re-access
|
||||||
gFileTimeStampCache = {} # {file path : file time stamp}
|
gFileTimeStampCache = {} # {file path : file time stamp}
|
||||||
|
|
||||||
|
@ -92,8 +99,6 @@ def _parseForXcode(lines, efifilepath, varnames):
|
||||||
|
|
||||||
def _parseForGCC(lines, efifilepath, varnames):
|
def _parseForGCC(lines, efifilepath, varnames):
|
||||||
""" Parse map file generated by GCC linker """
|
""" Parse map file generated by GCC linker """
|
||||||
valuePattern = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
|
|
||||||
pcdPattern = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
|
|
||||||
status = 0
|
status = 0
|
||||||
sections = []
|
sections = []
|
||||||
varoffset = []
|
varoffset = []
|
||||||
|
@ -112,7 +117,7 @@ def _parseForGCC(lines, efifilepath, varnames):
|
||||||
|
|
||||||
# status handler
|
# status handler
|
||||||
if status == 3:
|
if status == 3:
|
||||||
m = valuePattern.match(line)
|
m = valuePatternGcc.match(line)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
sections.append(m.groups(0))
|
sections.append(m.groups(0))
|
||||||
for varname in varnames:
|
for varname in varnames:
|
||||||
|
@ -125,7 +130,7 @@ def _parseForGCC(lines, efifilepath, varnames):
|
||||||
else:
|
else:
|
||||||
Str = line[len(".data.%s" % varname):]
|
Str = line[len(".data.%s" % varname):]
|
||||||
if Str:
|
if Str:
|
||||||
m = pcdPattern.match(Str.strip())
|
m = pcdPatternGcc.match(Str.strip())
|
||||||
if m is not None:
|
if m is not None:
|
||||||
varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))
|
varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))
|
||||||
|
|
||||||
|
@ -153,24 +158,21 @@ def _parseGeneral(lines, efifilepath, varnames):
|
||||||
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
|
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
|
||||||
secs = [] # key = section name
|
secs = [] # key = section name
|
||||||
varoffset = []
|
varoffset = []
|
||||||
secRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
|
|
||||||
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$]+) +([\da-fA-F]+)', re.UNICODE)
|
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$]+) +([\da-fA-F]+)', re.UNICODE)
|
||||||
startRe = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
|
|
||||||
addressRe = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if startRe.match(line):
|
if startPatternGeneral.match(line):
|
||||||
status = 1
|
status = 1
|
||||||
continue
|
continue
|
||||||
if addressRe.match(line):
|
if addressPatternGeneral.match(line):
|
||||||
status = 2
|
status = 2
|
||||||
continue
|
continue
|
||||||
if line.startswith("entry point at"):
|
if line.startswith("entry point at"):
|
||||||
status = 3
|
status = 3
|
||||||
continue
|
continue
|
||||||
if status == 1 and len(line) != 0:
|
if status == 1 and len(line) != 0:
|
||||||
m = secRe.match(line)
|
m = secReGeneral.match(line)
|
||||||
assert m is not None, "Fail to parse the section in map file , line is %s" % line
|
assert m is not None, "Fail to parse the section in map file , line is %s" % line
|
||||||
sec_no, sec_start, sec_length, sec_name, sec_class = m.groups(0)
|
sec_no, sec_start, sec_length, sec_name, sec_class = m.groups(0)
|
||||||
secs.append([int(sec_no, 16), int(sec_start, 16), int(sec_length, 16), sec_name, sec_class])
|
secs.append([int(sec_no, 16), int(sec_start, 16), int(sec_length, 16), sec_name, sec_class])
|
||||||
|
|
|
@ -24,7 +24,7 @@ import array
|
||||||
|
|
||||||
from Common.BuildToolError import *
|
from Common.BuildToolError import *
|
||||||
import Common.EdkLogger as EdkLogger
|
import Common.EdkLogger as EdkLogger
|
||||||
from Common.Misc import PeImageClass
|
from Common.Misc import PeImageClass, startPatternGeneral, addressPatternGeneral, valuePatternGcc, pcdPatternGcc, secReGeneral
|
||||||
from Common.BuildVersion import gBUILD_VERSION
|
from Common.BuildVersion import gBUILD_VERSION
|
||||||
from Common.LongFilePathSupport import OpenLongFilePath as open
|
from Common.LongFilePathSupport import OpenLongFilePath as open
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ __copyright__ = "Copyright (c) 2008 - 2010, Intel Corporation. All rights reserv
|
||||||
#====================================== Internal Libraries ========================================
|
#====================================== Internal Libraries ========================================
|
||||||
|
|
||||||
#============================================== Code ===============================================
|
#============================================== Code ===============================================
|
||||||
secRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
|
|
||||||
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE)
|
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE)
|
||||||
|
|
||||||
def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
|
def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
|
||||||
|
@ -80,9 +79,7 @@ def _parseForXcode(lines, efifilepath):
|
||||||
|
|
||||||
def _parseForGCC(lines, efifilepath):
|
def _parseForGCC(lines, efifilepath):
|
||||||
""" Parse map file generated by GCC linker """
|
""" 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]+)$')
|
dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')
|
||||||
pcdPattern = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
|
|
||||||
status = 0
|
status = 0
|
||||||
imageBase = -1
|
imageBase = -1
|
||||||
sections = []
|
sections = []
|
||||||
|
@ -102,7 +99,7 @@ def _parseForGCC(lines, efifilepath):
|
||||||
|
|
||||||
# status handler
|
# status handler
|
||||||
if status == 3:
|
if status == 3:
|
||||||
m = valuePattern.match(line)
|
m = valuePatternGcc.match(line)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
sections.append(m.groups(0))
|
sections.append(m.groups(0))
|
||||||
if status == 3:
|
if status == 3:
|
||||||
|
@ -110,7 +107,7 @@ def _parseForGCC(lines, efifilepath):
|
||||||
if m is not None:
|
if m is not None:
|
||||||
if lines[index + 1]:
|
if lines[index + 1]:
|
||||||
PcdName = m.groups(0)[0]
|
PcdName = m.groups(0)[0]
|
||||||
m = pcdPattern.match(lines[index + 1].strip())
|
m = pcdPatternGcc.match(lines[index + 1].strip())
|
||||||
if m is not None:
|
if m is not None:
|
||||||
bpcds.append((PcdName, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))
|
bpcds.append((PcdName, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))
|
||||||
|
|
||||||
|
@ -141,16 +138,14 @@ def _parseGeneral(lines, efifilepath):
|
||||||
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
|
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
|
||||||
secs = [] # key = section name
|
secs = [] # key = section name
|
||||||
bPcds = []
|
bPcds = []
|
||||||
startPattern = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
|
|
||||||
addressPattern = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
|
|
||||||
symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)')
|
symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)')
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if startPattern.match(line):
|
if startPatternGeneral.match(line):
|
||||||
status = 1
|
status = 1
|
||||||
continue
|
continue
|
||||||
if addressPattern.match(line):
|
if addressPatternGeneral.match(line):
|
||||||
status = 2
|
status = 2
|
||||||
continue
|
continue
|
||||||
if line.startswith("entry point at"):
|
if line.startswith("entry point at"):
|
||||||
|
|
Loading…
Reference in New Issue