From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 66ADC226612A4 for ; Wed, 25 Apr 2018 01:50:28 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Apr 2018 01:50:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,325,1520924400"; d="scan'208";a="35117757" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga008.fm.intel.com with ESMTP; 25 Apr 2018 01:50:28 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 25 Apr 2018 01:50:27 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 25 Apr 2018 01:50:27 -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:50:25 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v1 02/27] BaseTools: GenPatchPcdTable - refactor RegEx to minimize multiple compiling Thread-Index: AQHT2L+G4/EBqBvWEESgGR40260prKQRM2NA Date: Wed, 25 Apr 2018 08:50:24 +0000 Message-ID: References: <9ee84ed884976a5ee7d3c019ee28881fecdbece0.1524239027.git.jaben.carsey@intel.com> In-Reply-To: <9ee84ed884976a5ee7d3c019ee28881fecdbece0.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 02/27] BaseTools: GenPatchPcdTable - refactor RegEx to minimize multiple compiling 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:50:28 -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 02/27] BaseTools: GenPatchPcdTable - refactor RegEx to m= inimize multiple compiling Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py | 24 ++++++++= ++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py b= /BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py index dc2ceaf775d8..59748763a553 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) =20 def _parseForXcode(lines, efifilepath): + valuePattern =3D re.compile('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_Binar= yPatch_([\w]+))') status =3D 0 pcds =3D [] for line in lines: @@ -72,13 +73,16 @@ def _parseForXcode(lines, efifilepath): continue if status =3D=3D 1 and len(line) !=3D 0: if '_gPcd_BinaryPatch_' in line: - m =3D re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_Binary= Patch_([\w]+))', line) + m =3D valuePattern.match(line) if m is not None: pcds.append((m.groups(0)[3], int(m.groups(0)[0], 16))) return pcds =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 [] @@ -98,15 +102,15 @@ def _parseForGCC(lines, efifilepath): =20 # status handler if status =3D=3D 3: - m =3D re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$',= line) + m =3D valuePattern.match(line) if m is not None: sections.append(m.groups(0)) if status =3D=3D 3: - m =3D re.match('^.data._gPcd_BinaryPatch_([\w_\d]+)$', line) + m =3D dataPattern.match(line) if m is not None: if lines[index + 1]: PcdName =3D m.groups(0)[0] - m =3D re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', line= s[index + 1].strip()) + m =3D pcdPattern.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 @@ -137,17 +141,19 @@ 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 re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line): + if startPattern.match(line): status =3D 1 continue - if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line)= : + if addressPattern.match(line): status =3D 2 continue - if re.match("^entry point at", line): + if line.startswith("entry point at"): status =3D 3 continue if status =3D=3D 1 and len(line) !=3D 0: @@ -162,7 +168,7 @@ def _parseGeneral(lines, efifilepath): sec_no =3D int(sec_no, 16) sym_offset =3D int(sym_offset, 16) vir_addr =3D int(vir_addr, 16) - m2 =3D re.match('^[_]+gPcd_BinaryPatch_([\w]+)', sym_name) + m2 =3D symPattern.match(sym_name) if m2 is not None: # fond a binary pcd entry in map file for sec in secs: --=20 2.16.2.windows.1