From: "Zhu, Yonghong" <yonghong.zhu@intel.com>
To: "Carsey, Jaben" <jaben.carsey@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Gao, Liming" <liming.gao@intel.com>,
"Zhu, Yonghong" <yonghong.zhu@intel.com>
Subject: Re: [PATCH v1 03/27] BaseTools: Share RegEx between files
Date: Wed, 25 Apr 2018 08:51:40 +0000 [thread overview]
Message-ID: <B9726D6DCCFB8B4CA276A9169B02216D51FFC562@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <8e9e20fa37e691fba2ea8487f4e21ba990ada3b0.1524239027.git.jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Best Regards,
Zhu Yonghong
-----Original Message-----
From: Carsey, Jaben
Sent: Friday, April 20, 2018 11:51 PM
To: edk2-devel@lists.01.org
Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
Subject: [PATCH v1 03/27] 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>
---
BaseTools/Source/Python/Common/Misc.py | 22 +++++++++++---------
BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py | 15 +++++--------
2 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index bc7d0c2d9d00..4a6a29c7ae80 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -42,6 +42,13 @@ import subprocess
## Regular expression used to find out place holders in string template 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
gFileTimeStampCache = {} # {file path : file time stamp}
@@ -92,8 +99,6 @@ def _parseForXcode(lines, efifilepath, varnames):
def _parseForGCC(lines, efifilepath, varnames):
""" 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
sections = []
varoffset = []
@@ -112,7 +117,7 @@ def _parseForGCC(lines, efifilepath, varnames):
# status handler
if status == 3:
- m = valuePattern.match(line)
+ m = valuePatternGcc.match(line)
if m is not None:
sections.append(m.groups(0))
for varname in varnames:
@@ -125,7 +130,7 @@ def _parseForGCC(lines, efifilepath, varnames):
else:
Str = line[len(".data.%s" % varname):]
if Str:
- m = pcdPattern.match(Str.strip())
+ m = pcdPatternGcc.match(Str.strip())
if m is not None:
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
secs = [] # key = section name
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)
- startRe = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
- addressRe = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
for line in lines:
line = line.strip()
- if startRe.match(line):
+ if startPatternGeneral.match(line):
status = 1
continue
- if addressRe.match(line):
+ if addressPatternGeneral.match(line):
status = 2
continue
if line.startswith("entry point at"):
status = 3
continue
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
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]) diff --git a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
index 59748763a553..2a039480a00a 100644
--- a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
+++ b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
@@ -24,7 +24,7 @@ import array
from Common.BuildToolError import *
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.LongFilePathSupport import OpenLongFilePath as open
@@ -36,7 +36,6 @@ __copyright__ = "Copyright (c) 2008 - 2010, Intel Corporation. All rights reserv #====================================== Internal Libraries ========================================
#============================================== 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)
def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
@@ -80,9 +79,7 @@ def _parseForXcode(lines, efifilepath):
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 = []
@@ -102,7 +99,7 @@ def _parseForGCC(lines, efifilepath):
# status handler
if status == 3:
- m = valuePattern.match(line)
+ m = valuePatternGcc.match(line)
if m is not None:
sections.append(m.groups(0))
if status == 3:
@@ -110,7 +107,7 @@ def _parseForGCC(lines, efifilepath):
if m is not None:
if lines[index + 1]:
PcdName = m.groups(0)[0]
- m = pcdPattern.match(lines[index + 1].strip())
+ m = pcdPatternGcc.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]))
@@ -141,16 +138,14 @@ 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 startPattern.match(line):
+ if startPatternGeneral.match(line):
status = 1
continue
- if addressPattern.match(line):
+ if addressPatternGeneral.match(line):
status = 2
continue
if line.startswith("entry point at"):
--
2.16.2.windows.1
next prev parent reply other threads:[~2018-04-25 8:51 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 15:51 [PATCH v1 00/27] BaseTools refactoring Jaben Carsey
2018-04-20 15:51 ` [PATCH v1 01/27] BaseTools: Misc - refactor RegEx to minimize multiple compiling Jaben Carsey
2018-04-25 8:49 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 02/27] BaseTools: GenPatchPcdTable " Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 03/27] BaseTools: Share RegEx between files Jaben Carsey
2018-04-25 8:51 ` Zhu, Yonghong [this message]
2018-04-20 15:51 ` [PATCH v1 04/27] BaseTools: Workspace - refactor RegEx to minimize multiple compiling Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 05/27] BaseTools: Autogen - replace string constants with those from DataType Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 06/27] BaseTools: simplify if call Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 07/27] BaseTools: Workspace - refactor GetStructurePcdInfo Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 08/27] BaseTools: AutoGen - remove dictionary populated, but never accessed Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 09/27] BaseTools: AutoGen - remove unused variables Jaben Carsey
2018-04-25 8:52 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 10/27] BaseTools: Remove extra .keys() Jaben Carsey
2018-04-25 8:51 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 11/27] BaseTools: Workspace/MetaFileParser - refactor dicts Jaben Carsey
2018-04-20 15:51 ` [PATCH v1 12/27] BaseTools: remove dict from DscBuildData Jaben Carsey
2018-04-25 8:50 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 13/27] BaseTools: replace string constants used for module types Jaben Carsey
2018-04-25 5:57 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 14/27] BaseTools: Define and use a set for common list Jaben Carsey
2018-05-02 6:48 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 15/27] BaseTools: Share a dictionary instead of keeping multiples Jaben Carsey
2018-04-20 15:51 ` [PATCH v1 16/27] BaseTools: Replace EDK Component strings with predefined constant Jaben Carsey
2018-04-24 7:42 ` Zhu, Yonghong
2018-04-24 14:13 ` Carsey, Jaben
2018-04-20 15:51 ` [PATCH v1 17/27] BaseTools: DataType - cleanup list constants Jaben Carsey
2018-05-04 11:14 ` Laszlo Ersek
2018-05-04 14:18 ` Carsey, Jaben
2018-05-04 15:03 ` Laszlo Ersek
2018-04-20 15:51 ` [PATCH v1 18/27] BaseTools: Replace PCD type strings with predefined constant Jaben Carsey
2018-04-25 6:00 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 19/27] BaseTools: Replace Binary File " Jaben Carsey
2018-04-24 7:38 ` Zhu, Yonghong
2018-04-24 14:12 ` Carsey, Jaben
2018-04-20 15:51 ` [PATCH v1 20/27] BaseTools: remove duplicate variable Jaben Carsey
2018-04-25 8:51 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 21/27] BaseTools: replace string with predefined constant Jaben Carsey
2018-04-25 6:04 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 22/27] BaseTools: remove redundant if comparison Jaben Carsey
2018-05-02 6:49 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 23/27] BaseTools: AutoGen - use dafultdict instead of dict Jaben Carsey
2018-04-20 15:51 ` [PATCH v1 24/27] BaseTools: GenFds - simplify testing for Hex number Jaben Carsey
2018-04-25 8:51 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 25/27] BaseTools: AutoGen - use defaultdict to auto initialize Jaben Carsey
2018-04-25 8:52 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 26/27] BaseTools: remove unused MigrationUtilities.py Jaben Carsey
2018-05-02 6:49 ` Zhu, Yonghong
2018-04-20 15:51 ` [PATCH v1 27/27] BaseTools: CommonClass - remove unused classes Jaben Carsey
2018-04-25 8:51 ` Zhu, Yonghong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=B9726D6DCCFB8B4CA276A9169B02216D51FFC562@SHSMSX103.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox