From nobody Tue Feb 10 00:45:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1524239522007746.2349503296136; Fri, 20 Apr 2018 08:52:02 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 95193226EA5A7; Fri, 20 Apr 2018 08:51:56 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 5E4202251212F for ; Fri, 20 Apr 2018 08:51:55 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Apr 2018 08:51:54 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga003.jf.intel.com with ESMTP; 20 Apr 2018 08:51:52 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,302,1520924400"; d="scan'208";a="44811533" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Fri, 20 Apr 2018 08:51:21 -0700 Message-Id: <2a976f16c253e6d5074f1715d98337e3e63fd5c3.1524239027.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 01/27] BaseTools: Misc - 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey Reviewed-by: Yonghong Zhu =20 --- BaseTools/Source/Python/Common/Misc.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index 4f2bfd63cfc3..bc7d0c2d9d00 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -84,6 +84,7 @@ def _parseForXcode(lines, efifilepath, varnames): if status =3D=3D 1 and len(line) !=3D 0: for varname in varnames: if varname in line: + # cannot pregenerate this RegEx since it uses varname = from varnames. m =3D re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % = varname, line) if m is not None: ret.append((varname, m.group(1))) @@ -91,6 +92,8 @@ 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 [] @@ -109,7 +112,7 @@ def _parseForGCC(lines, efifilepath, varnames): =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)) for varname in varnames: @@ -122,7 +125,7 @@ def _parseForGCC(lines, efifilepath, varnames): else: Str =3D line[len(".data.%s" % varname):] if Str: - m =3D re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', = Str.strip()) + m =3D pcdPattern.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 @@ -152,16 +155,18 @@ def _parseGeneral(lines, efifilepath, varnames): 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 re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line): + if startRe.match(line): status =3D 1 continue - if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line): + if addressRe.match(line): status =3D 2 continue - if re.match("^entry point at", line): + if line.startswith("entry point at"): status =3D 3 continue =20 if status =3D=3D 1 and len(line) !=3D 0: @@ -177,6 +182,7 @@ def _parseGeneral(lines, efifilepath, varnames): sec_no =3D int(sec_no, 16) sym_offset =3D int(sym_offset, 16) vir_addr =3D int(vir_addr, 16) + # cannot pregenerate this RegEx since it uses varname from= varnames. m2 =3D re.match('^[_]*(%s)' % varname, sym_name) if m2 is not None: # fond a binary pcd entry in map file --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel