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 AB14F21F6A6E1 for ; Fri, 23 Feb 2018 23:18:03 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2018 23:24:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,386,1515484800"; d="scan'208";a="29441436" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 23 Feb 2018 23:24:05 -0800 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 23 Feb 2018 23:24:05 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 23 Feb 2018 23:24:04 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by shsmsx102.ccr.corp.intel.com ([169.254.2.124]) with mapi id 14.03.0319.002; Sat, 24 Feb 2018 15:24:02 +0800 From: "Zhu, Yonghong" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Zhu, Yonghong" Thread-Topic: [edk2] [PATCH] BaseTools/Expression: Use 2nd passes on PCD values Thread-Index: AQHTrRUf1ym3GnJaCUOcqmu0GdxtiaOzJrEA Date: Sat, 24 Feb 2018 07:24:02 +0000 Message-ID: References: <1519438424-25548-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1519438424-25548-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNDI5OWM0ZmMtNjM1ZS00MzVlLWI1MmEtMDUxMmZlMTAwZjkyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6ImNsTklmQUJEVlwvUGVxN0lEUlkyXC9neUV5U2F4ZXRzWmZveUg3OHU0aCtNND0ifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Sat, 24 Feb 2018 07:18:04 -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: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yong= hong Zhu Sent: Saturday, February 24, 2018 10:14 AM To: edk2-devel@lists.01.org Cc: Kinney, Michael D Subject: [edk2] [PATCH] BaseTools/Expression: Use 2nd passes on PCD values From: "Kinney, Michael D" Use 2 passes when evaluating PCD values to discover all the LABEL() operato= rs 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 offs= et. The 2 passes allows OFFSET_OF() to be used before a LABEL() is declare= d. --- 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 +=20 + 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=20 + defined' % Offset) ValueType =3D "" if Item.startswith('UINT8'): ItemSize =3D 1 -- 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel