BaseTools: merge towards minimum PCD MAX <something> methods

we have 5 different max val or max byte for PCDs.
refactor and remove 2 methods.
we need 3, as one computes for VOID* PCDs.

Cc: Bob Feng <bob.feng@intel.com>
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>
This commit is contained in:
Carsey, Jaben 2018-04-12 07:08:08 +08:00 committed by Yonghong Zhu
parent 9eb87141ec
commit 25598f8bdb
5 changed files with 31 additions and 44 deletions

View File

@ -273,6 +273,11 @@ TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_LIST = [TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_
TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE, \ TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE, \
TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE] TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE]
## The mapping dictionary from datum type to its maximum number.
MAX_VAL_TYPE = {"BOOLEAN":0x01, TAB_UINT8:0xFF, TAB_UINT16:0xFFFF, TAB_UINT32:0xFFFFFFFF, TAB_UINT64:0xFFFFFFFFFFFFFFFF}
## The mapping dictionary from datum type to size string.
MAX_SIZE_TYPE = {"BOOLEAN":"1", TAB_UINT8:"1", TAB_UINT16:"2", TAB_UINT32:"4", TAB_UINT64:"8"}
TAB_DEPEX = 'Depex' TAB_DEPEX = 'Depex'
TAB_DEPEX_COMMON = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_COMMON TAB_DEPEX_COMMON = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_COMMON
TAB_DEPEX_IA32 = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_IA32 TAB_DEPEX_IA32 = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_IA32

View File

@ -17,6 +17,7 @@ from CommonDataClass.Exceptions import BadExpression
from CommonDataClass.Exceptions import WrnExpression from CommonDataClass.Exceptions import WrnExpression
import uuid import uuid
from Common.Expression import PcdPattern from Common.Expression import PcdPattern
from Common.DataType import *
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].' ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].' ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
@ -39,16 +40,6 @@ ERR_ARRAY_ELE = 'This must be HEX value for NList or Array: [%s].'
ERR_EMPTY_EXPR = 'Empty expression is not allowed.' ERR_EMPTY_EXPR = 'Empty expression is not allowed.'
ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).' ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'
def MaxOfType(DataType):
if DataType == 'UINT8':
return int('0xFF', 16)
if DataType == 'UINT16':
return int('0xFFFF', 16)
if DataType == 'UINT32':
return int('0xFFFFFFFF', 16)
if DataType == 'UINT64':
return int('0xFFFFFFFFFFFFFFFF', 16)
class RangeObject(object): class RangeObject(object):
def __init__(self, start, end, empty = False): def __init__(self, start, end, empty = False):
@ -111,7 +102,7 @@ class XOROperatorObject(object):
rangeId = str(uuid.uuid1()) rangeId = str(uuid.uuid1())
rangeContainer = RangeContainer() rangeContainer = RangeContainer()
rangeContainer.push(RangeObject(0, int(Operand) - 1)) rangeContainer.push(RangeObject(0, int(Operand) - 1))
rangeContainer.push(RangeObject(int(Operand) + 1, MaxOfType(DataType))) rangeContainer.push(RangeObject(int(Operand) + 1, MAX_VAL_TYPE[DataType]))
SymbolTable[rangeId] = rangeContainer SymbolTable[rangeId] = rangeContainer
return rangeId return rangeId
@ -149,7 +140,7 @@ class GEOperatorObject(object):
raise BadExpression(ERR_SNYTAX % Expr) raise BadExpression(ERR_SNYTAX % Expr)
rangeId1 = str(uuid.uuid1()) rangeId1 = str(uuid.uuid1())
rangeContainer = RangeContainer() rangeContainer = RangeContainer()
rangeContainer.push(RangeObject(int(Operand), MaxOfType(DataType))) rangeContainer.push(RangeObject(int(Operand), MAX_VAL_TYPE[DataType]))
SymbolTable[rangeId1] = rangeContainer SymbolTable[rangeId1] = rangeContainer
return rangeId1 return rangeId1
@ -162,7 +153,7 @@ class GTOperatorObject(object):
raise BadExpression(ERR_SNYTAX % Expr) raise BadExpression(ERR_SNYTAX % Expr)
rangeId1 = str(uuid.uuid1()) rangeId1 = str(uuid.uuid1())
rangeContainer = RangeContainer() rangeContainer = RangeContainer()
rangeContainer.push(RangeObject(int(Operand) + 1, MaxOfType(DataType))) rangeContainer.push(RangeObject(int(Operand) + 1, MAX_VAL_TYPE[DataType]))
SymbolTable[rangeId1] = rangeContainer SymbolTable[rangeId1] = rangeContainer
return rangeId1 return rangeId1
@ -307,18 +298,18 @@ class RangeExpression(object):
rangeContainer = RangeContainer() rangeContainer = RangeContainer()
rangeid = str(uuid.uuid1()) rangeid = str(uuid.uuid1())
if rangeobj.empty: if rangeobj.empty:
rangeContainer.push(RangeObject(0, MaxOfType(self.PcdDataType))) rangeContainer.push(RangeObject(0, MAX_VAL_TYPE[self.PcdDataType]))
else: else:
if rangeobj.start > 0: if rangeobj.start > 0:
rangeContainer.push(RangeObject(0, rangeobj.start - 1)) rangeContainer.push(RangeObject(0, rangeobj.start - 1))
if rangeobj.end < MaxOfType(self.PcdDataType): if rangeobj.end < MAX_VAL_TYPE[self.PcdDataType]:
rangeContainer.push(RangeObject(rangeobj.end + 1, MaxOfType(self.PcdDataType))) rangeContainer.push(RangeObject(rangeobj.end + 1, MAX_VAL_TYPE[self.PcdDataType]))
self.operanddict[rangeid] = rangeContainer self.operanddict[rangeid] = rangeContainer
rangeids.append(rangeid) rangeids.append(rangeid)
if len(rangeids) == 0: if len(rangeids) == 0:
rangeContainer = RangeContainer() rangeContainer = RangeContainer()
rangeContainer.push(RangeObject(0, MaxOfType(self.PcdDataType))) rangeContainer.push(RangeObject(0, MAX_VAL_TYPE[self.PcdDataType]))
rangeid = str(uuid.uuid1()) rangeid = str(uuid.uuid1())
self.operanddict[rangeid] = rangeContainer self.operanddict[rangeid] = rangeContainer
return rangeid return rangeid

View File

@ -23,6 +23,7 @@ import subprocess
import Common.GlobalData as GlobalData import Common.GlobalData as GlobalData
from Common.LongFilePathSupport import OpenLongFilePath as open from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.Misc import SaveFileOnChange from Common.Misc import SaveFileOnChange
from Common.DataType import *
FILE_COMMENT_TEMPLATE = \ FILE_COMMENT_TEMPLATE = \
""" """
@ -68,8 +69,6 @@ FILE_COMMENT_TEMPLATE = \
# #
class VpdInfoFile: class VpdInfoFile:
## The mapping dictionary from datum type to size string.
_MAX_SIZE_TYPE = {"BOOLEAN":"1", "UINT8":"1", "UINT16":"2", "UINT32":"4", "UINT64":"8"}
_rVpdPcdLine = None _rVpdPcdLine = None
## Constructor ## Constructor
def __init__(self): def __init__(self):
@ -101,7 +100,7 @@ class VpdInfoFile:
"Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName)) "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
elif Vpd.DatumType in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64"]: elif Vpd.DatumType in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64"]:
if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "": if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "":
Vpd.MaxDatumSize = VpdInfoFile._MAX_SIZE_TYPE[Vpd.DatumType] Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]
else: else:
if Vpd.MaxDatumSize <= 0: if Vpd.MaxDatumSize <= 0:
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,

View File

@ -47,14 +47,12 @@ import Common.GlobalData as GlobalData
from DepexSection import DepexSection from DepexSection import DepexSection
from Common.Misc import SaveFileOnChange from Common.Misc import SaveFileOnChange
from Common.Expression import * from Common.Expression import *
from Common.DataType import TAB_COMMON from Common.DataType import *
## generate FFS from INF ## generate FFS from INF
# #
# #
class FfsInfStatement(FfsInfStatementClassObject): class FfsInfStatement(FfsInfStatementClassObject):
## The mapping dictionary from datum type to its maximum number.
_MAX_SIZE_TYPE = {"BOOLEAN":0x01, "UINT8":0xFF, "UINT16":0xFFFF, "UINT32":0xFFFFFFFF, "UINT64":0xFFFFFFFFFFFFFFFF}
## The constructor ## The constructor
# #
# @param self The object pointer # @param self The object pointer
@ -333,8 +331,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \ EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \
% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize))) % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize)))
else: else:
if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType] \ if PcdValueInDscOrFdf > MAX_VAL_TYPE[Pcd.DatumType] \
or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType]: or PcdValueInImg > MAX_VAL_TYPE[Pcd.DatumType]:
EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \ EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \
% (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)) % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
self.PatchPcds.append((Pcd, DefaultValue)) self.PatchPcds.append((Pcd, DefaultValue))

View File

@ -1542,25 +1542,19 @@ class DscBuildData(PlatformBuildClassObject):
@staticmethod @staticmethod
def GetPcdMaxSize(Pcd): 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 MaxSize = int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0
if Pcd.DatumType not in ['BOOLEAN','UINT8','UINT16','UINT32','UINT64']: if Pcd.PcdValueFromComm:
if Pcd.PcdValueFromComm: if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromComm.endswith("}"):
if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromComm.endswith("}"): return max([len(Pcd.PcdValueFromComm.split(",")),MaxSize])
MaxSize = max([len(Pcd.PcdValueFromComm.split(",")),MaxSize]) elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFromComm.startswith("\'"):
elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFromComm.startswith("\'"): return max([len(Pcd.PcdValueFromComm)-2+1,MaxSize])
MaxSize = max([len(Pcd.PcdValueFromComm)-2+1,MaxSize]) elif Pcd.PcdValueFromComm.startswith("L\""):
elif Pcd.PcdValueFromComm.startswith("L\""): return max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize])
MaxSize = max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize]) else:
else: return max([len(Pcd.PcdValueFromComm),MaxSize])
MaxSize = max([len(Pcd.PcdValueFromComm),MaxSize])
elif Pcd.DatumType not in ['BOOLEAN','UINT8']:
MaxSize = 1
elif Pcd.DatumType == 'UINT16':
MaxSize = 2
elif Pcd.DatumType == 'UINT32':
MaxSize = 4
elif Pcd.DatumType == 'UINT64':
MaxSize = 8
return MaxSize return MaxSize
def GenerateSizeFunction(self,Pcd): def GenerateSizeFunction(self,Pcd):