From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0F8CD226612AA for ; Wed, 25 Apr 2018 01:51:45 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Apr 2018 01:51:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,325,1520924400"; d="scan'208";a="49773303" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga001.fm.intel.com with ESMTP; 25 Apr 2018 01:51:44 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 25 Apr 2018 01:51:43 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 25 Apr 2018 01:51:43 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.210]) by shsmsx102.ccr.corp.intel.com ([169.254.2.79]) with mapi id 14.03.0319.002; Wed, 25 Apr 2018 16:51:41 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v1 03/27] BaseTools: Share RegEx between files Thread-Index: AQHT2L+Jp6P4q5PbvUWgiz1P4fENZqQRM75Q Date: Wed, 25 Apr 2018 08:51:40 +0000 Message-ID: References: <8e9e20fa37e691fba2ea8487f4e21ba990ada3b0.1524239027.git.jaben.carsey@intel.com> In-Reply-To: <8e9e20fa37e691fba2ea8487f4e21ba990ada3b0.1524239027.git.jaben.carsey@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v1 03/27] BaseTools: Share RegEx between files X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Apr 2018 08:51:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: Carsey, Jaben=20 Sent: Friday, April 20, 2018 11:51 PM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zhu, Yonghong Subject: [PATCH v1 03/27] BaseTools: Share RegEx between files Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- 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/Pyth= on/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 g= PlaceholderPattern =3D re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UN= ICODE) =20 +## regular expressions for map file processing startPatternGeneral =3D=20 +re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")=20 +addressPatternGeneral =3D re.compile("^Address[' ']+Publics by Value['=20 +']+Rva\+Base") valuePatternGcc =3D re.compile('^([\w_\.]+)=20 ++([\da-fA-Fx]+) +([\da-fA-Fx]+)$') pcdPatternGcc =3D=20 +re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)') secReGeneral =3D=20 +re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]?=20 ++([.\w\$]+) +(\w+)', re.UNICODE) + ## Dictionary used to store file time stamp for quick re-access gFileTimeStampCache =3D {} # {file path : file time stamp} =20 @@ -92,8 +99,6 @@ def _parseForXcode(lines, efifilepath, varnames): =20 def _parseForGCC(lines, efifilepath, varnames): """ Parse map file generated by GCC linker """ - valuePattern =3D re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]= +)$') - pcdPattern =3D re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)') status =3D 0 sections =3D [] varoffset =3D [] @@ -112,7 +117,7 @@ def _parseForGCC(lines, efifilepath, varnames): =20 # status handler if status =3D=3D 3: - m =3D valuePattern.match(line) + m =3D 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 =3D line[len(".data.%s" % varname):] if Str: - m =3D pcdPattern.match(Str.strip()) + m =3D 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])) =20 @@ -153,24 +158,21 @@ def _parseGeneral(lines, efifilepath, varnames): status =3D 0 #0 - beginning of file; 1 - PE section definition; 2 -= symbol table secs =3D [] # key =3D section name varoffset =3D [] - secRe =3D re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]?= +([.\w\$]+) +(\w+)', re.UNICODE) symRe =3D re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$]+= ) +([\da-fA-F]+)', re.UNICODE) - startRe =3D re.compile("^Start[' ']+Length[' ']+Name[' ']+Class") - addressRe =3D re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Bas= e") =20 for line in lines: line =3D line.strip() - if startRe.match(line): + if startPatternGeneral.match(line): status =3D 1 continue - if addressRe.match(line): + if addressPatternGeneral.match(line): status =3D 2 continue if line.startswith("entry point at"): status =3D 3 continue =20 if status =3D=3D 1 and len(line) !=3D 0: - m =3D secRe.match(line) + m =3D 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 =3D m.group= s(0) secs.append([int(sec_no, 16), int(sec_start, 16), int(sec_leng= th, 16), sec_name, sec_class]) diff --git a/BaseTools/Source/Python/GenPatc= hPcdTable/GenPatchPcdTable.py b/BaseTools/Source/Python/GenPatchPcdTable/Ge= nPatchPcdTable.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 =20 from Common.BuildToolError import * import Common.EdkLogger as EdkLogger -from Common.Misc import PeImageClass +from Common.Misc import PeImageClass, startPatternGeneral,=20 +addressPatternGeneral, valuePatternGcc, pcdPatternGcc, secReGeneral from Common.BuildVersion import gBUILD_VERSION from Common.LongFilePathSu= pport import OpenLongFilePath as open =20 @@ -36,7 +36,6 @@ __copyright__ =3D "Copyright (c) 2008 - 2010, Intel Corpo= ration. All rights reserv #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Inte= rnal Libraries =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Code =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -secRe =3D re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([= .\w\$]+) +(\w+)', re.UNICODE) symRe =3D re.compile('^([\da-fA-F]+):([\da-f= A-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE) =20 def parsePcdInfoFromMapFile(mapfilepath, efifilepath): @@ -80,9 +79,7 @@ def _parseForXcode(lines, efifilepath): =20 def _parseForGCC(lines, efifilepath): """ Parse map file generated by GCC linker """ - valuePattern =3D re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]= +)$') dataPattern =3D re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$') - pcdPattern =3D re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)') status =3D 0 imageBase =3D -1 sections =3D [] @@ -102,7 +99,7 @@ def _parseForGCC(lines, efifilepath): =20 # status handler if status =3D=3D 3: - m =3D valuePattern.match(line) + m =3D valuePatternGcc.match(line) if m is not None: sections.append(m.groups(0)) if status =3D=3D 3: @@ -110,7 +107,7 @@ def _parseForGCC(lines, efifilepath): if m is not None: if lines[index + 1]: PcdName =3D m.groups(0)[0] - m =3D pcdPattern.match(lines[index + 1].strip()) + m =3D pcdPatternGcc.match(lines[index + 1].strip()) if m is not None: bpcds.append((PcdName, int(m.groups(0)[0], 16) , i= nt(sections[-1][1], 16), sections[-1][0])) =20 @@ -141,16 +138,14 @@ def _parseGeneral(lines, efifilepath): status =3D 0 #0 - beginning of file; 1 - PE section definition; 2 -= symbol table secs =3D [] # key =3D section name bPcds =3D [] - startPattern =3D re.compile("^Start[' ']+Length[' ']+Name[' ']+Class") - addressPattern =3D re.compile("^Address[' ']+Publics by Value[' ']+Rva= \+Base") symPattern =3D re.compile('^[_]+gPcd_BinaryPatch_([\w]+)') =20 for line in lines: line =3D line.strip() - if startPattern.match(line): + if startPatternGeneral.match(line): status =3D 1 continue - if addressPattern.match(line): + if addressPatternGeneral.match(line): status =3D 2 continue if line.startswith("entry point at"): -- 2.16.2.windows.1