From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 33/42] BaseTools: AutoGen - add Opcode constants
Date: Fri, 27 Apr 2018 15:32:47 -0700 [thread overview]
Message-ID: <0c0ee4469616a05baf8f01294d22a5315b5069ba.1524868034.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1524868033.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1524868033.git.jaben.carsey@intel.com>
add constants for dependency expression opcode strings
use these new opcode string constants
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
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 expression
#
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD 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 *
## Regular expression for matching "DEPENDENCY_START ... DEPENDENCY_END"
gStartClosePattern = re.compile(".*DEPENDENCY_START(.+)DEPENDENCY_END.*", re.S)
@@ -70,65 +71,62 @@ class DependencyExpression:
)
OpcodePriority = {
- "AND" : 1,
- "OR" : 1,
- "NOT" : 2,
- # "SOR" : 9,
- # "BEFORE": 9,
- # "AFTER" : 9,
+ DEPEX_OPCODE_AND : 1,
+ DEPEX_OPCODE_OR : 1,
+ DEPEX_OPCODE_NOT : 2,
}
Opcode = {
"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
},
"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
},
"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
}
}
# all supported op codes and operands
- SupportedOpcode = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "END", "SOR"]
- SupportedOperand = ["TRUE", "FALSE"]
+ SupportedOpcode = [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER, DEPEX_OPCODE_PUSH, DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_NOT, DEPEX_OPCODE_END, DEPEX_OPCODE_SOR]
+ SupportedOperand = [DEPEX_OPCODE_TRUE, DEPEX_OPCODE_FALSE]
- OpcodeWithSingleOperand = ['NOT', 'BEFORE', 'AFTER']
- OpcodeWithTwoOperand = ['AND', 'OR']
+ OpcodeWithSingleOperand = [DEPEX_OPCODE_NOT, DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER]
+ OpcodeWithTwoOperand = [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]
# op code that should not be the last one
- NonEndingOpcode = ["AND", "OR", "NOT", 'SOR']
+ NonEndingOpcode = [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_NOT, DEPEX_OPCODE_SOR]
# op code must not present at the same time
- ExclusiveOpcode = ["BEFORE", "AFTER"]
+ ExclusiveOpcode = [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER]
# op code that should be the first one if it presents
- AboveAllOpcode = ["SOR", "BEFORE", "AFTER"]
+ AboveAllOpcode = [DEPEX_OPCODE_SOR, DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER]
#
# 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 == "NOT":
+ if Token == DEPEX_OPCODE_NOT:
if LastToken not in self.SupportedOpcode + ['(', '', None]:
EdkLogger.error("GenDepex", PARSER_ERROR, "Invalid dependency expression: missing operator before NOT",
ExtraData="Near %s" % LastToken)
@@ -222,10 +220,10 @@ class DependencyExpression:
ExtraData="Near %s" % LastToken)
if len(self.OpcodeList) == 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 == "END":
+ if Token == DEPEX_OPCODE_END:
break
self.OpcodeList.append(Token)
else:
@@ -241,8 +239,8 @@ class DependencyExpression:
ExtraData=str(self))
while len(Stack) > 0:
self.PostfixNotation.append(Stack.pop())
- if self.PostfixNotation[-1] != 'END':
- self.PostfixNotation.append("END")
+ if self.PostfixNotation[-1] != DEPEX_OPCODE_END:
+ self.PostfixNotation.append(DEPEX_OPCODE_END)
## Validate the dependency expression
def ValidateOpcode(self):
@@ -262,20 +260,20 @@ class DependencyExpression:
if len(self.PostfixNotation) < 3:
EdkLogger.error("GenDepex", PARSER_ERROR, "Missing operand for %s" % Op,
ExtraData=str(self))
- if self.TokenList[-1] != 'END' and self.TokenList[-1] in self.NonEndingOpcode:
+ if self.TokenList[-1] != 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=str(self))
- if self.TokenList[-1] == 'END' and self.TokenList[-2] in self.NonEndingOpcode:
+ if self.TokenList[-1] == 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=str(self))
- if "END" in self.TokenList and "END" != self.TokenList[-1]:
+ if DEPEX_OPCODE_END in self.TokenList and DEPEX_OPCODE_END != self.TokenList[-1]:
EdkLogger.error("GenDepex", PARSER_ERROR, "Extra expressions after END",
ExtraData=str(self))
## Simply optimize the dependency expression by removing duplicated operands
def Optimize(self):
ValidOpcode = list(set(self.OpcodeList))
- if len(ValidOpcode) != 1 or ValidOpcode[0] not in ['AND', 'OR']:
+ if len(ValidOpcode) != 1 or ValidOpcode[0] not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]:
return
Op = ValidOpcode[0]
NewOperand = []
@@ -284,14 +282,14 @@ class DependencyExpression:
if Token in self.SupportedOpcode or Token in NewOperand:
continue
AllOperand.add(Token)
- if Token == 'TRUE':
- if Op == 'AND':
+ if Token == DEPEX_OPCODE_TRUE:
+ if Op == DEPEX_OPCODE_AND:
continue
else:
NewOperand.append(Token)
break
- elif Token == 'FALSE':
- if Op == 'OR':
+ elif Token == DEPEX_OPCODE_FALSE:
+ if Op == DEPEX_OPCODE_OR:
continue
else:
NewOperand.append(Token)
@@ -299,13 +297,13 @@ class DependencyExpression:
NewOperand.append(Token)
# don't generate depex if only TRUE operand left
- if self.ModuleType == 'PEIM' and len(NewOperand) == 1 and NewOperand[0] == 'TRUE':
+ if self.ModuleType == 'PEIM' and len(NewOperand) == 1 and NewOperand[0] == DEPEX_OPCODE_TRUE:
self.PostfixNotation = []
return
# don't generate depex if all operands are architecture protocols
if self.ModuleType in ['UEFI_DRIVER', 'DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'DXE_SMM_DRIVER', 'MM_STANDALONE'] and \
- Op == 'AND' and \
+ Op == DEPEX_OPCODE_AND and \
self.ArchProtocols == set([GuidStructureStringToGuidString(Guid) for Guid in AllOperand]):
self.PostfixNotation = []
return
@@ -371,7 +369,7 @@ class DependencyExpression:
versionNumber = ("0.04" + " " + gBUILD_VERSION)
__version__ = "%prog Version " + versionNumber
-__copyright__ = "Copyright (c) 2007-2010, Intel Corporation All rights reserved."
+__copyright__ = "Copyright (c) 2007-2018, Intel Corporation All rights reserved."
__usage__ = "%prog [options] [dependency_expression_file]"
## 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 = ":memory:" #"BuildDatabase.db"
# used by ECC
MODIFIER_LIST = ['IN', 'OUT', 'OPTIONAL', 'UNALIGNED', 'EFI_RUNTIMESERVICE', 'EFI_BOOTSERVICE', 'EFIAPI']
+# Dependency Opcodes
+DEPEX_OPCODE_BEFORE = "BEFORE"
+DEPEX_OPCODE_AFTER = "AFTER"
+DEPEX_OPCODE_PUSH = "PUSH"
+DEPEX_OPCODE_AND = "AND"
+DEPEX_OPCODE_OR = "OR"
+DEPEX_OPCODE_NOT = "NOT"
+DEPEX_OPCODE_END = "END"
+DEPEX_OPCODE_SOR = "SOR"
+DEPEX_OPCODE_TRUE = "TRUE"
+DEPEX_OPCODE_FALSE = "FALSE"
+
# Dependency Expression
DEPEX_SUPPORTED_OPCODE = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "END", "SOR", "TRUE", "FALSE", '(', ')']
--
2.16.2.windows.1
next prev parent reply other threads:[~2018-04-27 22:33 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-27 22:32 [PATCH v1 00/42] BaseTools: refactoring patches Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 01/42] BaseTools: FdfParser - update to remove duplicate constant value Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 02/42] BaseTools: AutoGen " Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 03/42] BaseTools: check before accessing members in __eq__ Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 04/42] BaseTools: this function has no purpose Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 05/42] BaseTools: AutoGen - refactor assemble_variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 06/42] BaseTools: AutoGen - refactor dictionary access Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 07/42] BaseTools: AutoGen - GenVar refactor static methods Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 08/42] BaseTools: AutoGen - share StripComments API Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 09/42] BaseTools: AutoGen - refactor class factory Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 10/42] BaseTools: Eot - remove unused lists Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 11/42] BaseTools: Eot - refactor global data Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 12/42] BaseTools: AutoGen - remove global line Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 13/42] BaseTools: AutoGen - UniClassObject refactor static methods Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 14/42] BaseTools: refactor to use list not dict Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 15/42] BaseTools: eliminate {} from dictionary contructor call Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 16/42] BaseTools: remove Compound statements Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 17/42] BaseTools: Workspace - refactor a dict Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 18/42] BaseTools: move PCD size calculation functions to PcdClassObject Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 19/42] BaseTools: AutoGen - refactor out functions only called in __init__ Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 20/42] BaseTools: AutoGen - refactor out a list Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 21/42] BaseTools: AutoGen - refactor out a useless class Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 22/42] BaseTools: AutoGen - no need to recompute Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 23/42] BaseTools: refactor __init__ functions to not compute temporary variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 24/42] BaseTools: AutoGen - remove function no one calls Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 25/42] BaseTools: AutoGen - move function to clean file namespace Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 26/42] BaseTools: AutoGen - remove another function no one calls Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 27/42] BaseTools: Refactor to share GUID packing function Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 28/42] BaseTools: AutoGen - refactor function to remove extra variables Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 29/42] BaseTools: AutoGen - refactor more functions only called in __init__ Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 30/42] BaseTools: remove unused member variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 31/42] BaseTools: remove redundant content in InfSectionParser Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 32/42] BaseTools: trim whitespace Jaben Carsey
2018-04-27 22:32 ` Jaben Carsey [this message]
2018-04-27 22:32 ` [PATCH v1 34/42] BaseTools: standardize GUID and pack size Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 35/42] BaseTools: remove unused variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 36/42] BaseTools: GenFds - use existing shared string Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 37/42] BaseTools: missed a copyright update Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 38/42] BaseTools: Remove lists form set construction Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 39/42] BaseTools: refactor Depex optomization Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 40/42] BaseTools: dont make iterator into list if not needed Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 41/42] BaseTools: create base expression class Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 42/42] BaseTools: use set instead of list Jaben Carsey
2018-05-04 4:33 ` [PATCH v1 00/42] BaseTools: refactoring patches Zhu, Yonghong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0c0ee4469616a05baf8f01294d22a5315b5069ba.1524868034.git.jaben.carsey@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox