BaseTools: move PCD size calculation functions to PcdClassObject
authorCarsey, Jaben <jaben.carsey@intel.com>
Fri, 27 Apr 2018 22:32:32 +0000 (06:32 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 4 May 2018 05:03:05 +0000 (13:03 +0800)
move both GetPcdMaxSize and GetPcdSize to the PcdClassObject.
fix MAX_SIZE_TYPE to have int values

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/GenC.py
BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
BaseTools/Source/Python/Common/DataType.py
BaseTools/Source/Python/Common/VpdInfoFile.py
BaseTools/Source/Python/Workspace/BuildClassObject.py
BaseTools/Source/Python/Workspace/DscBuildData.py

index 6a2ea924f604aa0e9c8dc085a4a7314338e9eee2..d06258888269b241b1d04ea38bcac8971658cf16 100644 (file)
@@ -863,31 +863,6 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                                     % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
                 TokenCNameList.add(TokenCName)\r
 \r
-def GetPcdSize(Pcd):\r
-    if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
-        Value = Pcd.DefaultValue\r
-        if not Value:\r
-            return 1\r
-        elif Value[0] == 'L':\r
-            return (len(Value) - 2) * 2\r
-        elif Value[0] == '{':\r
-            return len(Value.split(','))\r
-        else:\r
-            return len(Value) - 1\r
-    if Pcd.DatumType == TAB_UINT64:\r
-        return 8\r
-    if Pcd.DatumType == TAB_UINT32:\r
-        return 4\r
-    if Pcd.DatumType == TAB_UINT16:\r
-        return 2\r
-    if Pcd.DatumType == TAB_UINT8:\r
-        return 1\r
-    if Pcd.DatumType == 'BOOLEAN':\r
-        return 1\r
-    else:\r
-        return Pcd.MaxDatumSize\r
-\r
-\r
 ## Create code for module PCDs\r
 #\r
 #   @param      Info        The ModuleAutoGen object\r
@@ -1110,7 +1085,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                     else:\r
-                        ArraySize = GetPcdSize(Pcd)\r
+                        ArraySize = Pcd.GetPcdSize()\r
                         if Unicode:\r
                             ArraySize = ArraySize / 2\r
                 Value = NewValue + '0 }'\r
@@ -1150,7 +1125,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
             AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))\r
                 \r
-            PcdDataSize = GetPcdSize(Pcd)\r
+            PcdDataSize = Pcd.GetPcdSize()\r
             if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
                 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
                 AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
@@ -1167,14 +1142,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             AutoGenH.Append('extern volatile %s  %s  %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
             AutoGenH.Append('#define %s  %s%s\n' % (GetModeName, Type, PcdVariableName))\r
             \r
-            PcdDataSize = GetPcdSize(Pcd)\r
+            PcdDataSize = Pcd.GetPcdSize()\r
             AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
             \r
             AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
             AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
             AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
         else:\r
-            PcdDataSize = GetPcdSize(Pcd)\r
+            PcdDataSize = Pcd.GetPcdSize()\r
             AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
             AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
             \r
@@ -1333,7 +1308,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
         else:\r
             AutoGenH.Append('extern volatile  %s  %s%s;\n' % (DatumType, PcdVariableName, Array))\r
         AutoGenH.Append('#define %s  %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
-        PcdDataSize = GetPcdSize(Pcd)\r
+        PcdDataSize = Pcd.GetPcdSize()\r
         if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
             AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))\r
             AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))\r
@@ -1367,7 +1342,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))\r
             else:\r
                 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
-        PcdDataSize = GetPcdSize(Pcd)\r
+        PcdDataSize = Pcd.GetPcdSize()\r
         if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
             if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 if ConstFixedPcd:\r
index dd78dc5200758a4603d435e7076e70d6c2174783..2f8f4fac23f8c59ac9b2392ac172e1d0f80ef4d9 100644 (file)
@@ -253,7 +253,7 @@ class VAR_CHECK_PCD_VALID_OBJ(object):
 \r
     def updateStorageWidth(self):\r
         try:\r
-            self.StorageWidth = int(MAX_SIZE_TYPE[self.PcdDataType])\r
+            self.StorageWidth = MAX_SIZE_TYPE[self.PcdDataType]\r
         except:\r
             self.StorageWidth = 0\r
             self.ValidData = False\r
index 5030df27b4daf149ea6cd4c1d75e1308b64ead23..50d582a3f68e5fcb2b1e9741b6829c837cb1b9e2 100644 (file)
@@ -292,7 +292,7 @@ TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET =  {TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_
 ## The mapping dictionary from datum type to its maximum number.\r
 MAX_VAL_TYPE = {"BOOLEAN":0x01, TAB_UINT8:0xFF, TAB_UINT16:0xFFFF, TAB_UINT32:0xFFFFFFFF, TAB_UINT64:0xFFFFFFFFFFFFFFFF}\r
 ## The mapping dictionary from datum type to size string.\r
-MAX_SIZE_TYPE = {"BOOLEAN":"1", TAB_UINT8:"1", TAB_UINT16:"2", TAB_UINT32:"4", TAB_UINT64:"8"}\r
+MAX_SIZE_TYPE = {"BOOLEAN":1, TAB_UINT8:1, TAB_UINT16:2, TAB_UINT32:4, TAB_UINT64:8}\r
 \r
 TAB_DEPEX = 'Depex'\r
 TAB_DEPEX_COMMON = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_COMMON\r
index 155693740f12057982843e11b9b294ac8d919a95..32895deb5d0c769ecc81d832609845dfb3dc03ae 100644 (file)
@@ -99,7 +99,7 @@ class VpdInfoFile:
                 EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, \r
                                 "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))\r
         elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES: \r
-            if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "":\r
+            if not Vpd.MaxDatumSize:\r
                 Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]\r
         else:\r
             if Vpd.MaxDatumSize <= 0:\r
index 258905e80f25a4bfa6e2879847dfedd22aad92d1..209315d901b2cc192cd86ea4889b7e11ca207419 100644 (file)
@@ -72,6 +72,37 @@ class PcdClassObject(object):
         self.PcdValueFromComm = ""\r
         self.DefinitionPosition = ("","")\r
 \r
+    ## Get the maximum number of bytes\r
+    def GetPcdMaxSize(self):\r
+        if self.DatumType in TAB_PCD_NUMERIC_TYPES:\r
+            return MAX_SIZE_TYPE[self.DatumType]\r
+\r
+        MaxSize = int(self.MaxDatumSize,10) if self.MaxDatumSize else 0\r
+        if self.PcdValueFromComm:\r
+            if self.PcdValueFromComm.startswith("{") and self.PcdValueFromComm.endswith("}"):\r
+                return max([len(self.PcdValueFromComm.split(",")),MaxSize])\r
+            elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFromComm.startswith("\'"):\r
+                return max([len(self.PcdValueFromComm)-2+1,MaxSize])\r
+            elif self.PcdValueFromComm.startswith("L\""):\r
+                return max([2*(len(self.PcdValueFromComm)-3+1),MaxSize])\r
+            else:\r
+                return max([len(self.PcdValueFromComm),MaxSize])\r
+        return MaxSize\r
+\r
+    ## Get the number of bytes\r
+    def GetPcdSize(self):\r
+        if self.DatumType in TAB_PCD_NUMERIC_TYPES:\r
+            return MAX_SIZE_TYPE[self.DatumType]\r
+        if not self.DefaultValue:\r
+            return 1\r
+        elif self.DefaultValue[0] == 'L':\r
+            return (len(self.DefaultValue) - 2) * 2\r
+        elif self.DefaultValue[0] == '{':\r
+            return len(self.DefaultValue.split(','))\r
+        else:\r
+            return len(self.DefaultValue) - 1\r
+\r
+\r
     ## Convert the class to a string\r
     #\r
     #  Convert each member of the class to string\r
index bb35ed44aa77ecbf6fffa8dfc72a6ee8dde14d3a..06ea7b05a33c94023ffca1dd02fe4082f55a85ae 100644 (file)
@@ -1535,23 +1535,6 @@ class DscBuildData(PlatformBuildClassObject):
         Result = Result + '"'\r
         return Result\r
 \r
-    @staticmethod\r
-    def GetPcdMaxSize(Pcd):\r
-        if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:\r
-            return MAX_SIZE_TYPE[Pcd.DatumType]\r
-\r
-        MaxSize = int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0\r
-        if Pcd.PcdValueFromComm:\r
-            if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromComm.endswith("}"):\r
-                return max([len(Pcd.PcdValueFromComm.split(",")),MaxSize])\r
-            elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFromComm.startswith("\'"):\r
-                return max([len(Pcd.PcdValueFromComm)-2+1,MaxSize])\r
-            elif Pcd.PcdValueFromComm.startswith("L\""):\r
-                return max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize])\r
-            else:\r
-                return max([len(Pcd.PcdValueFromComm),MaxSize])\r
-        return MaxSize\r
-\r
     def GenerateSizeFunction(self,Pcd):\r
         CApp = "// Default Value in Dec \n"\r
         CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
@@ -1634,7 +1617,7 @@ class DscBuildData(PlatformBuildClassObject):
                 while '[' in FieldName:\r
                     FieldName = FieldName.rsplit('[', 1)[0]\r
                     CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0])\r
-        CApp = CApp + "  *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd))\r
+        CApp = CApp + "  *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize())\r
         CApp = CApp + "}\n"\r
         return CApp\r
 \r