]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: AutoGen - add Opcode constants
authorCarsey, Jaben <jaben.carsey@intel.com>
Fri, 27 Apr 2018 22:32:47 +0000 (06:32 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 4 May 2018 05:03:11 +0000 (13:03 +0800)
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>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/AutoGen/GenDepex.py
BaseTools/Source/Python/Common/DataType.py

index 100f1250b31f918ffd071b695d61132a191ce5ad..7126fdcddf7aa6d34b4f7336a86cb2e889f97fdf 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to generate DEPEX file for module's dependency expression\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.    The full text of the license may be found at\r
@@ -71,65 +71,62 @@ class DependencyExpression:
                     )\r
 \r
     OpcodePriority = {\r
-        "AND"   :   1,\r
-        "OR"    :   1,\r
-        "NOT"   :   2,\r
-        # "SOR"   :   9,\r
-        # "BEFORE":   9,\r
-        # "AFTER" :   9,\r
+        DEPEX_OPCODE_AND   :   1,\r
+        DEPEX_OPCODE_OR    :   1,\r
+        DEPEX_OPCODE_NOT   :   2,\r
     }\r
 \r
     Opcode = {\r
         "PEI"   : {\r
-            "PUSH"  :   0x02,\r
-            "AND"   :   0x03,\r
-            "OR"    :   0x04,\r
-            "NOT"   :   0x05,\r
-            "TRUE"  :   0x06,\r
-            "FALSE" :   0x07,\r
-            "END"   :   0x08\r
+            DEPEX_OPCODE_PUSH  :   0x02,\r
+            DEPEX_OPCODE_AND   :   0x03,\r
+            DEPEX_OPCODE_OR    :   0x04,\r
+            DEPEX_OPCODE_NOT   :   0x05,\r
+            DEPEX_OPCODE_TRUE  :   0x06,\r
+            DEPEX_OPCODE_FALSE :   0x07,\r
+            DEPEX_OPCODE_END   :   0x08\r
         },\r
 \r
         "DXE"   : {\r
-            "BEFORE":   0x00,\r
-            "AFTER" :   0x01,\r
-            "PUSH"  :   0x02,\r
-            "AND"   :   0x03,\r
-            "OR"    :   0x04,\r
-            "NOT"   :   0x05,\r
-            "TRUE"  :   0x06,\r
-            "FALSE" :   0x07,\r
-            "END"   :   0x08,\r
-            "SOR"   :   0x09\r
+            DEPEX_OPCODE_BEFORE:   0x00,\r
+            DEPEX_OPCODE_AFTER :   0x01,\r
+            DEPEX_OPCODE_PUSH  :   0x02,\r
+            DEPEX_OPCODE_AND   :   0x03,\r
+            DEPEX_OPCODE_OR    :   0x04,\r
+            DEPEX_OPCODE_NOT   :   0x05,\r
+            DEPEX_OPCODE_TRUE  :   0x06,\r
+            DEPEX_OPCODE_FALSE :   0x07,\r
+            DEPEX_OPCODE_END   :   0x08,\r
+            DEPEX_OPCODE_SOR   :   0x09\r
         },\r
 \r
         "MM"   : {\r
-            "BEFORE":   0x00,\r
-            "AFTER" :   0x01,\r
-            "PUSH"  :   0x02,\r
-            "AND"   :   0x03,\r
-            "OR"    :   0x04,\r
-            "NOT"   :   0x05,\r
-            "TRUE"  :   0x06,\r
-            "FALSE" :   0x07,\r
-            "END"   :   0x08,\r
-            "SOR"   :   0x09\r
+            DEPEX_OPCODE_BEFORE:   0x00,\r
+            DEPEX_OPCODE_AFTER :   0x01,\r
+            DEPEX_OPCODE_PUSH  :   0x02,\r
+            DEPEX_OPCODE_AND   :   0x03,\r
+            DEPEX_OPCODE_OR    :   0x04,\r
+            DEPEX_OPCODE_NOT   :   0x05,\r
+            DEPEX_OPCODE_TRUE  :   0x06,\r
+            DEPEX_OPCODE_FALSE :   0x07,\r
+            DEPEX_OPCODE_END   :   0x08,\r
+            DEPEX_OPCODE_SOR   :   0x09\r
         }\r
     }\r
 \r
     # all supported op codes and operands\r
-    SupportedOpcode = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "END", "SOR"]\r
-    SupportedOperand = ["TRUE", "FALSE"]\r
+    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]\r
+    SupportedOperand = [DEPEX_OPCODE_TRUE, DEPEX_OPCODE_FALSE]\r
 \r
-    OpcodeWithSingleOperand = ['NOT', 'BEFORE', 'AFTER']\r
-    OpcodeWithTwoOperand = ['AND', 'OR']\r
+    OpcodeWithSingleOperand = [DEPEX_OPCODE_NOT, DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER]\r
+    OpcodeWithTwoOperand = [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]\r
 \r
     # op code that should not be the last one\r
-    NonEndingOpcode = ["AND", "OR", "NOT", 'SOR']\r
+    NonEndingOpcode = [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_NOT, DEPEX_OPCODE_SOR]\r
     # op code must not present at the same time\r
-    ExclusiveOpcode = ["BEFORE", "AFTER"]\r
+    ExclusiveOpcode = [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER]\r
     # op code that should be the first one if it presents\r
-    AboveAllOpcode = ["SOR", "BEFORE", "AFTER"]\r
+    AboveAllOpcode = [DEPEX_OPCODE_SOR, DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER]\r
 \r
     #\r
     # open and close brace must be taken as individual tokens\r
@@ -201,7 +198,7 @@ class DependencyExpression:
                         break\r
                     self.PostfixNotation.append(Stack.pop())\r
             elif Token in self.OpcodePriority:\r
-                if Token == "NOT":\r
+                if Token == DEPEX_OPCODE_NOT:\r
                     if LastToken not in self.SupportedOpcode + ['(', '', None]:\r
                         EdkLogger.error("GenDepex", PARSER_ERROR, "Invalid dependency expression: missing operator before NOT",\r
                                         ExtraData="Near %s" % LastToken)\r
@@ -223,10 +220,10 @@ class DependencyExpression:
                                         ExtraData="Near %s" % LastToken)\r
                     if len(self.OpcodeList) == 0 or self.OpcodeList[-1] not in self.ExclusiveOpcode:\r
                         if Token not in self.SupportedOperand:\r
-                            self.PostfixNotation.append("PUSH")\r
+                            self.PostfixNotation.append(DEPEX_OPCODE_PUSH)\r
                 # check if OP is valid in this phase\r
                 elif Token in self.Opcode[self.Phase]:\r
-                    if Token == "END":\r
+                    if Token == DEPEX_OPCODE_END:\r
                         break\r
                     self.OpcodeList.append(Token)\r
                 else:\r
@@ -242,8 +239,8 @@ class DependencyExpression:
                             ExtraData=str(self))\r
         while len(Stack) > 0:\r
             self.PostfixNotation.append(Stack.pop())\r
-        if self.PostfixNotation[-1] != 'END':\r
-            self.PostfixNotation.append("END")\r
+        if self.PostfixNotation[-1] != DEPEX_OPCODE_END:\r
+            self.PostfixNotation.append(DEPEX_OPCODE_END)\r
 \r
     ## Validate the dependency expression\r
     def ValidateOpcode(self):\r
@@ -263,20 +260,20 @@ class DependencyExpression:
                 if len(self.PostfixNotation) < 3:\r
                     EdkLogger.error("GenDepex", PARSER_ERROR, "Missing operand for %s" % Op,\r
                                     ExtraData=str(self))\r
-        if self.TokenList[-1] != 'END' and self.TokenList[-1] in self.NonEndingOpcode:\r
+        if self.TokenList[-1] != DEPEX_OPCODE_END and self.TokenList[-1] in self.NonEndingOpcode:\r
             EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-1],\r
                             ExtraData=str(self))\r
-        if self.TokenList[-1] == 'END' and self.TokenList[-2] in self.NonEndingOpcode:\r
+        if self.TokenList[-1] == DEPEX_OPCODE_END and self.TokenList[-2] in self.NonEndingOpcode:\r
             EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-2],\r
                             ExtraData=str(self))\r
-        if "END" in self.TokenList and "END" != self.TokenList[-1]:\r
+        if DEPEX_OPCODE_END in self.TokenList and DEPEX_OPCODE_END != self.TokenList[-1]:\r
             EdkLogger.error("GenDepex", PARSER_ERROR, "Extra expressions after END",\r
                             ExtraData=str(self))\r
 \r
     ## Simply optimize the dependency expression by removing duplicated operands\r
     def Optimize(self):\r
         ValidOpcode = list(set(self.OpcodeList))\r
-        if len(ValidOpcode) != 1 or ValidOpcode[0] not in ['AND', 'OR']:\r
+        if len(ValidOpcode) != 1 or ValidOpcode[0] not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]:\r
             return\r
         Op = ValidOpcode[0]\r
         NewOperand = []\r
@@ -285,14 +282,14 @@ class DependencyExpression:
             if Token in self.SupportedOpcode or Token in NewOperand:\r
                 continue\r
             AllOperand.add(Token)\r
-            if Token == 'TRUE':\r
-                if Op == 'AND':\r
+            if Token == DEPEX_OPCODE_TRUE:\r
+                if Op == DEPEX_OPCODE_AND:\r
                     continue\r
                 else:\r
                     NewOperand.append(Token)\r
                     break\r
-            elif Token == 'FALSE':\r
-                if Op == 'OR':\r
+            elif Token == DEPEX_OPCODE_FALSE:\r
+                if Op == DEPEX_OPCODE_OR:\r
                     continue\r
                 else:\r
                     NewOperand.append(Token)\r
@@ -300,13 +297,13 @@ class DependencyExpression:
             NewOperand.append(Token)\r
 \r
         # don't generate depex if only TRUE operand left\r
-        if self.ModuleType == SUP_MODULE_PEIM and len(NewOperand) == 1 and NewOperand[0] == 'TRUE':\r
+        if self.ModuleType == SUP_MODULE_PEIM and len(NewOperand) == 1 and NewOperand[0] == DEPEX_OPCODE_TRUE:\r
             self.PostfixNotation = []\r
             return\r
 \r
         # don't generate depex if all operands are architecture protocols\r
         if self.ModuleType in [SUP_MODULE_UEFI_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_MM_STANDALONE] and \\r
-           Op == 'AND' and \\r
+           Op == DEPEX_OPCODE_AND and \\r
            self.ArchProtocols == set([GuidStructureStringToGuidString(Guid) for Guid in AllOperand]):\r
             self.PostfixNotation = []\r
             return\r
@@ -372,7 +369,7 @@ class DependencyExpression:
 \r
 versionNumber = ("0.04" + " " + gBUILD_VERSION)\r
 __version__ = "%prog Version " + versionNumber\r
-__copyright__ = "Copyright (c) 2007-2010, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2007-2018, Intel Corporation  All rights reserved."\r
 __usage__ = "%prog [options] [dependency_expression_file]"\r
 \r
 ## Parse command line options\r
index 50d582a3f68e5fcb2b1e9741b6829c837cb1b9e2..56f5bfedd6b4078a5ee87ea23a00a4e3b541855d 100644 (file)
@@ -487,6 +487,18 @@ DATABASE_PATH = ":memory:" #"BuildDatabase.db"
 # used by ECC\r
 MODIFIER_SET = {'IN', 'OUT', 'OPTIONAL', 'UNALIGNED', 'EFI_RUNTIMESERVICE', 'EFI_BOOTSERVICE', 'EFIAPI'}\r
 \r
+# Dependency Opcodes\r
+DEPEX_OPCODE_BEFORE = "BEFORE"\r
+DEPEX_OPCODE_AFTER = "AFTER"\r
+DEPEX_OPCODE_PUSH = "PUSH"\r
+DEPEX_OPCODE_AND = "AND"\r
+DEPEX_OPCODE_OR = "OR"\r
+DEPEX_OPCODE_NOT = "NOT"\r
+DEPEX_OPCODE_END = "END"\r
+DEPEX_OPCODE_SOR = "SOR"\r
+DEPEX_OPCODE_TRUE = "TRUE"\r
+DEPEX_OPCODE_FALSE = "FALSE"\r
+\r
 # Dependency Expression\r
 DEPEX_SUPPORTED_OPCODE_SET = {"BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "END", "SOR", "TRUE", "FALSE", '(', ')'}\r
 \r