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.31; helo=mga06.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 BBB4C21F6A6E7 for ; Fri, 23 Feb 2018 23:28:01 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2018 23:34:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,386,1515484800"; d="scan'208";a="206604171" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by fmsmga005.fm.intel.com with ESMTP; 23 Feb 2018 23:34:02 -0800 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: "Kinney, Michael D" , Liming Gao Date: Sat, 24 Feb 2018 15:34:00 +0800 Message-Id: <1519457640-28400-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [PATCH V2] 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:28:03 -0000 From: "Kinney, Michael D" V2: Add bugzilla issue info and signed-off info 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. fixes:https://bugzilla.tianocore.org/show_bug.cgi?id=880 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney Reviewed-by: Yonghong Zhu --- 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/Source/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 = {} ReLabel = re.compile('LABEL\((\w+)\)') ReOffset = re.compile('OFFSET_OF\((\w+)\)') + LabelOffset = 0 + for Index, Item in enumerate(ListItem): + # compute byte offset of every LABEL + Item = Item.strip() + try: + LabelList = ReLabel.findall(Item) + for Label in LabelList: + if Label not in LabelDict.keys(): + LabelDict[Label] = str(LabelOffset) + Item = ReLabel.sub('', Item) + except: + pass + if Item.startswith('UINT8'): + LabelOffset = LabelOffset + 1 + elif Item.startswith('UINT16'): + LabelOffset = LabelOffset + 2 + elif Item.startswith('UINT32'): + LabelOffset = LabelOffset + 4 + elif Item.startswith('UINT64'): + LabelOffset = LabelOffset + 8 + else: + ItemValue, ItemSize = ParseFieldValue(Item) + LabelOffset = LabelOffset + ItemSize + for Index, Item in enumerate(ListItem): # for LABEL parse Item = Item.strip() @@ -847,7 +871,7 @@ class ValueExpressionEx(ValueExpression): Re = re.compile('OFFSET_OF\(%s\)'% Offset) Item = Re.sub(LabelDict[Offset], Item) else: - raise BadExpression('%s not defined before use' % Offset) + raise BadExpression('%s not defined' % Offset) ValueType = "" if Item.startswith('UINT8'): ItemSize = 1 -- 2.14.2.windows.3