From nobody Sun Apr 28 09:46:03 2024 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 1519438430895834.1676548454709; Fri, 23 Feb 2018 18:13:50 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E6FF122436929; Fri, 23 Feb 2018 18:07:46 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 49BA921F6A6D2 for ; Fri, 23 Feb 2018 18:07:45 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2018 18:13:47 -0800 Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by orsmga005.jf.intel.com with ESMTP; 23 Feb 2018 18:13:46 -0800 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.88; helo=mga01.intel.com; envelope-from=yonghong.zhu@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.47,385,1515484800"; d="scan'208";a="203359320" From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Sat, 24 Feb 2018 10:13:44 +0800 Message-Id: <1519438424-25548-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [edk2] [PATCH] BaseTools/Expression: Use 2nd passes on PCD values X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Kinney, Michael D" 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" From: "Kinney, Michael D" Use 2 passes when evaluating PCD values to discover all the LABEL() operators and compute the byte offset of each LABEL(). The 2nd pass then has the information to replace the OFFSET_OF() operator with the computed byte offset. The 2 passes allows OFFSET_OF() to be used before a LABEL() is declared. Reviewed-by: Yonghong Zhu =20 --- BaseTools/Source/Python/Common/Expression.py | 26 ++++++++++++++++++++++++= +- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index 74d1b08f76..28320d78a9 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -827,6 +827,30 @@ class ValueExpressionEx(ValueExpression): LabelDict =3D {} ReLabel =3D re.compile('LABEL\((\w+)\)') ReOffset =3D re.compile('OFFSET_OF\((\w+)\)') + LabelOffset =3D 0 + for Index, Item in enumerate(ListItem): + # compute byte offset of every LABEL + Item =3D Item.strip() + try: + LabelList =3D ReLabel.findall(Item) + for Label in LabelList: + if Label not in LabelDict.keys(): + LabelDict[Label] =3D str(Label= Offset) + Item =3D ReLabel.sub('', Item) + except: + pass + if Item.startswith('UINT8'): + LabelOffset =3D LabelOffset + 1 + elif Item.startswith('UINT16'): + LabelOffset =3D LabelOffset + 2 + elif Item.startswith('UINT32'): + LabelOffset =3D LabelOffset + 4 + elif Item.startswith('UINT64'): + LabelOffset =3D LabelOffset + 8 + else: + ItemValue, ItemSize =3D ParseFieldValu= e(Item) + LabelOffset =3D LabelOffset + ItemSize + for Index, Item in enumerate(ListItem): # for LABEL parse Item =3D Item.strip() @@ -847,7 +871,7 @@ class ValueExpressionEx(ValueExpression): Re =3D re.compile('OFFSET_OF\(%s\)= '% Offset) Item =3D Re.sub(LabelDict[Offset],= Item) else: - raise BadExpression('%s not define= d before use' % Offset) + raise BadExpression('%s not define= d' % Offset) ValueType =3D "" if Item.startswith('UINT8'): ItemSize =3D 1 --=20 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel