mirror of https://github.com/acidanthera/audk.git
BaseTools: Misc - 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>
This commit is contained in:
parent
c8dca871df
commit
6686d9a125
|
@ -84,6 +84,7 @@ def _parseForXcode(lines, efifilepath, varnames):
|
||||||
if status == 1 and len(line) != 0:
|
if status == 1 and len(line) != 0:
|
||||||
for varname in varnames:
|
for varname in varnames:
|
||||||
if varname in line:
|
if varname in line:
|
||||||
|
# cannot pregenerate this RegEx since it uses varname from varnames.
|
||||||
m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
|
m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
ret.append((varname, m.group(1)))
|
ret.append((varname, m.group(1)))
|
||||||
|
@ -91,6 +92,8 @@ 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 = []
|
||||||
|
@ -109,7 +112,7 @@ def _parseForGCC(lines, efifilepath, varnames):
|
||||||
|
|
||||||
# status handler
|
# status handler
|
||||||
if status == 3:
|
if status == 3:
|
||||||
m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)
|
m = valuePattern.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:
|
||||||
|
@ -122,7 +125,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 = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', Str.strip())
|
m = pcdPattern.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]))
|
||||||
|
|
||||||
|
@ -152,16 +155,18 @@ def _parseGeneral(lines, efifilepath, varnames):
|
||||||
varoffset = []
|
varoffset = []
|
||||||
secRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
|
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 re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line):
|
if startRe.match(line):
|
||||||
status = 1
|
status = 1
|
||||||
continue
|
continue
|
||||||
if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line):
|
if addressRe.match(line):
|
||||||
status = 2
|
status = 2
|
||||||
continue
|
continue
|
||||||
if re.match("^entry point at", line):
|
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:
|
||||||
|
@ -177,6 +182,7 @@ def _parseGeneral(lines, efifilepath, varnames):
|
||||||
sec_no = int(sec_no, 16)
|
sec_no = int(sec_no, 16)
|
||||||
sym_offset = int(sym_offset, 16)
|
sym_offset = int(sym_offset, 16)
|
||||||
vir_addr = int(vir_addr, 16)
|
vir_addr = int(vir_addr, 16)
|
||||||
|
# cannot pregenerate this RegEx since it uses varname from varnames.
|
||||||
m2 = re.match('^[_]*(%s)' % varname, sym_name)
|
m2 = re.match('^[_]*(%s)' % varname, sym_name)
|
||||||
if m2 is not None:
|
if m2 is not None:
|
||||||
# fond a binary pcd entry in map file
|
# fond a binary pcd entry in map file
|
||||||
|
|
Loading…
Reference in New Issue