From nobody Tue Feb 10 11:29:38 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 1524868513988580.7589573153448; Fri, 27 Apr 2018 15:35:13 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 402B6207DF462; Fri, 27 Apr 2018 15:33:10 -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 10C832034C8DD for ; Fri, 27 Apr 2018 15:33:03 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2018 15:33:02 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga002.jf.intel.com with ESMTP; 27 Apr 2018 15:33:01 -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,336,1520924400"; d="scan'208";a="54252871" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Fri, 27 Apr 2018 15:32:47 -0700 Message-Id: <0c0ee4469616a05baf8f01294d22a5315b5069ba.1524868034.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 33/42] BaseTools: AutoGen - add Opcode constants 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" add constants for dependency expression opcode strings use these new opcode string constants Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/GenDepex.py | 112 ++++++++++---------- BaseTools/Source/Python/Common/DataType.py | 12 +++ 2 files changed, 67 insertions(+), 57 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py b/BaseTools/Source= /Python/AutoGen/GenDepex.py index 9acea8f6bfed..3dcbad5be666 100644 --- a/BaseTools/Source/Python/AutoGen/GenDepex.py +++ b/BaseTools/Source/Python/AutoGen/GenDepex.py @@ -1,7 +1,7 @@ ## @file # This file is used to generate DEPEX file for module's dependency express= ion # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may= be found at @@ -24,6 +24,7 @@ from Common.Misc import SaveFileOnChange from Common.Misc import GuidStructureStringToGuidString from Common import EdkLogger as EdkLogger from Common.BuildVersion import gBUILD_VERSION +from Common.DataType import * =20 ## Regular expression for matching "DEPENDENCY_START ... DEPENDENCY_END" gStartClosePattern =3D re.compile(".*DEPENDENCY_START(.+)DEPENDENCY_END.*"= , re.S) @@ -70,65 +71,62 @@ class DependencyExpression: ) =20 OpcodePriority =3D { - "AND" : 1, - "OR" : 1, - "NOT" : 2, - # "SOR" : 9, - # "BEFORE": 9, - # "AFTER" : 9, + DEPEX_OPCODE_AND : 1, + DEPEX_OPCODE_OR : 1, + DEPEX_OPCODE_NOT : 2, } =20 Opcode =3D { "PEI" : { - "PUSH" : 0x02, - "AND" : 0x03, - "OR" : 0x04, - "NOT" : 0x05, - "TRUE" : 0x06, - "FALSE" : 0x07, - "END" : 0x08 + DEPEX_OPCODE_PUSH : 0x02, + DEPEX_OPCODE_AND : 0x03, + DEPEX_OPCODE_OR : 0x04, + DEPEX_OPCODE_NOT : 0x05, + DEPEX_OPCODE_TRUE : 0x06, + DEPEX_OPCODE_FALSE : 0x07, + DEPEX_OPCODE_END : 0x08 }, =20 "DXE" : { - "BEFORE": 0x00, - "AFTER" : 0x01, - "PUSH" : 0x02, - "AND" : 0x03, - "OR" : 0x04, - "NOT" : 0x05, - "TRUE" : 0x06, - "FALSE" : 0x07, - "END" : 0x08, - "SOR" : 0x09 + DEPEX_OPCODE_BEFORE: 0x00, + DEPEX_OPCODE_AFTER : 0x01, + DEPEX_OPCODE_PUSH : 0x02, + DEPEX_OPCODE_AND : 0x03, + DEPEX_OPCODE_OR : 0x04, + DEPEX_OPCODE_NOT : 0x05, + DEPEX_OPCODE_TRUE : 0x06, + DEPEX_OPCODE_FALSE : 0x07, + DEPEX_OPCODE_END : 0x08, + DEPEX_OPCODE_SOR : 0x09 }, =20 "MM" : { - "BEFORE": 0x00, - "AFTER" : 0x01, - "PUSH" : 0x02, - "AND" : 0x03, - "OR" : 0x04, - "NOT" : 0x05, - "TRUE" : 0x06, - "FALSE" : 0x07, - "END" : 0x08, - "SOR" : 0x09 + DEPEX_OPCODE_BEFORE: 0x00, + DEPEX_OPCODE_AFTER : 0x01, + DEPEX_OPCODE_PUSH : 0x02, + DEPEX_OPCODE_AND : 0x03, + DEPEX_OPCODE_OR : 0x04, + DEPEX_OPCODE_NOT : 0x05, + DEPEX_OPCODE_TRUE : 0x06, + DEPEX_OPCODE_FALSE : 0x07, + DEPEX_OPCODE_END : 0x08, + DEPEX_OPCODE_SOR : 0x09 } } =20 # all supported op codes and operands - SupportedOpcode =3D ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "E= ND", "SOR"] - SupportedOperand =3D ["TRUE", "FALSE"] + SupportedOpcode =3D [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER, DEPEX_OP= CODE_PUSH, DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_NOT, DEPEX_OPCOD= E_END, DEPEX_OPCODE_SOR] + SupportedOperand =3D [DEPEX_OPCODE_TRUE, DEPEX_OPCODE_FALSE] =20 - OpcodeWithSingleOperand =3D ['NOT', 'BEFORE', 'AFTER'] - OpcodeWithTwoOperand =3D ['AND', 'OR'] + OpcodeWithSingleOperand =3D [DEPEX_OPCODE_NOT, DEPEX_OPCODE_BEFORE, DE= PEX_OPCODE_AFTER] + OpcodeWithTwoOperand =3D [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR] =20 # op code that should not be the last one - NonEndingOpcode =3D ["AND", "OR", "NOT", 'SOR'] + NonEndingOpcode =3D [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_N= OT, DEPEX_OPCODE_SOR] # op code must not present at the same time - ExclusiveOpcode =3D ["BEFORE", "AFTER"] + ExclusiveOpcode =3D [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER] # op code that should be the first one if it presents - AboveAllOpcode =3D ["SOR", "BEFORE", "AFTER"] + AboveAllOpcode =3D [DEPEX_OPCODE_SOR, DEPEX_OPCODE_BEFORE, DEPEX_OPCOD= E_AFTER] =20 # # open and close brace must be taken as individual tokens @@ -200,7 +198,7 @@ class DependencyExpression: break self.PostfixNotation.append(Stack.pop()) elif Token in self.OpcodePriority: - if Token =3D=3D "NOT": + if Token =3D=3D DEPEX_OPCODE_NOT: if LastToken not in self.SupportedOpcode + ['(', '', N= one]: EdkLogger.error("GenDepex", PARSER_ERROR, "Invalid= dependency expression: missing operator before NOT", ExtraData=3D"Near %s" % LastToken) @@ -222,10 +220,10 @@ class DependencyExpression: ExtraData=3D"Near %s" % LastToken) if len(self.OpcodeList) =3D=3D 0 or self.OpcodeList[-1= ] not in self.ExclusiveOpcode: if Token not in self.SupportedOperand: - self.PostfixNotation.append("PUSH") + self.PostfixNotation.append(DEPEX_OPCODE_PUSH) # check if OP is valid in this phase elif Token in self.Opcode[self.Phase]: - if Token =3D=3D "END": + if Token =3D=3D DEPEX_OPCODE_END: break self.OpcodeList.append(Token) else: @@ -241,8 +239,8 @@ class DependencyExpression: ExtraData=3Dstr(self)) while len(Stack) > 0: self.PostfixNotation.append(Stack.pop()) - if self.PostfixNotation[-1] !=3D 'END': - self.PostfixNotation.append("END") + if self.PostfixNotation[-1] !=3D DEPEX_OPCODE_END: + self.PostfixNotation.append(DEPEX_OPCODE_END) =20 ## Validate the dependency expression def ValidateOpcode(self): @@ -262,20 +260,20 @@ class DependencyExpression: if len(self.PostfixNotation) < 3: EdkLogger.error("GenDepex", PARSER_ERROR, "Missing ope= rand for %s" % Op, ExtraData=3Dstr(self)) - if self.TokenList[-1] !=3D 'END' and self.TokenList[-1] in self.No= nEndingOpcode: + if self.TokenList[-1] !=3D DEPEX_OPCODE_END and self.TokenList[-1]= in self.NonEndingOpcode: EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end= of the dependency expression" % self.TokenList[-1], ExtraData=3Dstr(self)) - if self.TokenList[-1] =3D=3D 'END' and self.TokenList[-2] in self.= NonEndingOpcode: + if self.TokenList[-1] =3D=3D DEPEX_OPCODE_END and self.TokenList[-= 2] in self.NonEndingOpcode: EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end= of the dependency expression" % self.TokenList[-2], ExtraData=3Dstr(self)) - if "END" in self.TokenList and "END" !=3D self.TokenList[-1]: + if DEPEX_OPCODE_END in self.TokenList and DEPEX_OPCODE_END !=3D se= lf.TokenList[-1]: EdkLogger.error("GenDepex", PARSER_ERROR, "Extra expressions a= fter END", ExtraData=3Dstr(self)) =20 ## Simply optimize the dependency expression by removing duplicated op= erands def Optimize(self): ValidOpcode =3D list(set(self.OpcodeList)) - if len(ValidOpcode) !=3D 1 or ValidOpcode[0] not in ['AND', 'OR']: + if len(ValidOpcode) !=3D 1 or ValidOpcode[0] not in [DEPEX_OPCODE_= AND, DEPEX_OPCODE_OR]: return Op =3D ValidOpcode[0] NewOperand =3D [] @@ -284,14 +282,14 @@ class DependencyExpression: if Token in self.SupportedOpcode or Token in NewOperand: continue AllOperand.add(Token) - if Token =3D=3D 'TRUE': - if Op =3D=3D 'AND': + if Token =3D=3D DEPEX_OPCODE_TRUE: + if Op =3D=3D DEPEX_OPCODE_AND: continue else: NewOperand.append(Token) break - elif Token =3D=3D 'FALSE': - if Op =3D=3D 'OR': + elif Token =3D=3D DEPEX_OPCODE_FALSE: + if Op =3D=3D DEPEX_OPCODE_OR: continue else: NewOperand.append(Token) @@ -299,13 +297,13 @@ class DependencyExpression: NewOperand.append(Token) =20 # don't generate depex if only TRUE operand left - if self.ModuleType =3D=3D 'PEIM' and len(NewOperand) =3D=3D 1 and = NewOperand[0] =3D=3D 'TRUE': + if self.ModuleType =3D=3D 'PEIM' and len(NewOperand) =3D=3D 1 and = NewOperand[0] =3D=3D DEPEX_OPCODE_TRUE: self.PostfixNotation =3D [] return =20 # don't generate depex if all operands are architecture protocols if self.ModuleType in ['UEFI_DRIVER', 'DXE_DRIVER', 'DXE_RUNTIME_D= RIVER', 'DXE_SAL_DRIVER', 'DXE_SMM_DRIVER', 'MM_STANDALONE'] and \ - Op =3D=3D 'AND' and \ + Op =3D=3D DEPEX_OPCODE_AND and \ self.ArchProtocols =3D=3D set([GuidStructureStringToGuidString(= Guid) for Guid in AllOperand]): self.PostfixNotation =3D [] return @@ -371,7 +369,7 @@ class DependencyExpression: =20 versionNumber =3D ("0.04" + " " + gBUILD_VERSION) __version__ =3D "%prog Version " + versionNumber -__copyright__ =3D "Copyright (c) 2007-2010, Intel Corporation All rights = reserved." +__copyright__ =3D "Copyright (c) 2007-2018, Intel Corporation All rights = reserved." __usage__ =3D "%prog [options] [dependency_expression_file]" =20 ## Parse command line options diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/= Python/Common/DataType.py index 8af94354620c..48700ba82012 100644 --- a/BaseTools/Source/Python/Common/DataType.py +++ b/BaseTools/Source/Python/Common/DataType.py @@ -473,6 +473,18 @@ DATABASE_PATH =3D ":memory:" #"BuildDatabase.db" # used by ECC MODIFIER_LIST =3D ['IN', 'OUT', 'OPTIONAL', 'UNALIGNED', 'EFI_RUNTIMESERVI= CE', 'EFI_BOOTSERVICE', 'EFIAPI'] =20 +# Dependency Opcodes +DEPEX_OPCODE_BEFORE =3D "BEFORE" +DEPEX_OPCODE_AFTER =3D "AFTER" +DEPEX_OPCODE_PUSH =3D "PUSH" +DEPEX_OPCODE_AND =3D "AND" +DEPEX_OPCODE_OR =3D "OR" +DEPEX_OPCODE_NOT =3D "NOT" +DEPEX_OPCODE_END =3D "END" +DEPEX_OPCODE_SOR =3D "SOR" +DEPEX_OPCODE_TRUE =3D "TRUE" +DEPEX_OPCODE_FALSE =3D "FALSE" + # Dependency Expression DEPEX_SUPPORTED_OPCODE =3D ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT",= "END", "SOR", "TRUE", "FALSE", '(', ')'] =20 --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel