summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Workspace
diff options
context:
space:
mode:
authorCarsey, Jaben <jaben.carsey@intel.com>2018-04-28 06:32:32 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-05-04 13:03:05 +0800
commit5565a8c4d2196b5e55e702169feefeeb07a330d9 (patch)
tree209dad0eab7b1fe7d3993ddaff977249b4efa0b3 /BaseTools/Source/Python/Workspace
parent88252a90d1ca7846731cd2e4e8e860454f7d97a3 (diff)
downloadedk2-5565a8c4d2196b5e55e702169feefeeb07a330d9.tar.gz
edk2-5565a8c4d2196b5e55e702169feefeeb07a330d9.tar.bz2
edk2-5565a8c4d2196b5e55e702169feefeeb07a330d9.zip
BaseTools: move PCD size calculation functions to PcdClassObject
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>
Diffstat (limited to 'BaseTools/Source/Python/Workspace')
-rw-r--r--BaseTools/Source/Python/Workspace/BuildClassObject.py31
-rw-r--r--BaseTools/Source/Python/Workspace/DscBuildData.py19
2 files changed, 32 insertions, 18 deletions
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 258905e80f..209315d901 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -72,6 +72,37 @@ class PcdClassObject(object):
self.PcdValueFromComm = ""
self.DefinitionPosition = ("","")
+ ## Get the maximum number of bytes
+ def GetPcdMaxSize(self):
+ if self.DatumType in TAB_PCD_NUMERIC_TYPES:
+ return MAX_SIZE_TYPE[self.DatumType]
+
+ MaxSize = int(self.MaxDatumSize,10) if self.MaxDatumSize else 0
+ if self.PcdValueFromComm:
+ if self.PcdValueFromComm.startswith("{") and self.PcdValueFromComm.endswith("}"):
+ return max([len(self.PcdValueFromComm.split(",")),MaxSize])
+ elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFromComm.startswith("\'"):
+ return max([len(self.PcdValueFromComm)-2+1,MaxSize])
+ elif self.PcdValueFromComm.startswith("L\""):
+ return max([2*(len(self.PcdValueFromComm)-3+1),MaxSize])
+ else:
+ return max([len(self.PcdValueFromComm),MaxSize])
+ return MaxSize
+
+ ## Get the number of bytes
+ def GetPcdSize(self):
+ if self.DatumType in TAB_PCD_NUMERIC_TYPES:
+ return MAX_SIZE_TYPE[self.DatumType]
+ if not self.DefaultValue:
+ return 1
+ elif self.DefaultValue[0] == 'L':
+ return (len(self.DefaultValue) - 2) * 2
+ elif self.DefaultValue[0] == '{':
+ return len(self.DefaultValue.split(','))
+ else:
+ return len(self.DefaultValue) - 1
+
+
## Convert the class to a string
#
# Convert each member of the class to string
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index bb35ed44aa..06ea7b05a3 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1535,23 +1535,6 @@ class DscBuildData(PlatformBuildClassObject):
Result = Result + '"'
return Result
- @staticmethod
- def GetPcdMaxSize(Pcd):
- if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:
- return MAX_SIZE_TYPE[Pcd.DatumType]
-
- MaxSize = int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0
- if Pcd.PcdValueFromComm:
- if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromComm.endswith("}"):
- return max([len(Pcd.PcdValueFromComm.split(",")),MaxSize])
- elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFromComm.startswith("\'"):
- return max([len(Pcd.PcdValueFromComm)-2+1,MaxSize])
- elif Pcd.PcdValueFromComm.startswith("L\""):
- return max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize])
- else:
- return max([len(Pcd.PcdValueFromComm),MaxSize])
- return MaxSize
-
def GenerateSizeFunction(self,Pcd):
CApp = "// Default Value in Dec \n"
CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
@@ -1634,7 +1617,7 @@ class DscBuildData(PlatformBuildClassObject):
while '[' in FieldName:
FieldName = FieldName.rsplit('[', 1)[0]
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])
- CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd))
+ CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize())
CApp = CApp + "}\n"
return CApp