From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 425EE2265A331 for ; Wed, 11 Apr 2018 17:40:11 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2018 17:40:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,438,1517904000"; d="scan'208";a="215935813" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga005.jf.intel.com with ESMTP; 11 Apr 2018 17:40:10 -0700 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 11 Apr 2018 17:40:10 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 11 Apr 2018 17:40:10 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.115]) by shsmsx102.ccr.corp.intel.com ([169.254.2.184]) with mapi id 14.03.0319.002; Thu, 12 Apr 2018 08:40:07 +0800 From: "Feng, Bob C" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Feng, Bob C" Thread-Topic: [edk2] [PATCH v1 4/4] BaseTools: merge towards minimum PCD MAX methods Thread-Index: AQHT0eoFM+NEVXCC9ECBrwdJGB+5IKP8STiA Date: Thu, 12 Apr 2018 00:40:07 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D1553D93DF@SHSMSX101.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v1 4/4] BaseTools: merge towards minimum PCD MAX methods X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Apr 2018 00:40:12 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Feng, Bob C =20 -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jabe= n Sent: Thursday, April 12, 2018 7:08 AM To: edk2-devel@lists.01.org Cc: Feng, Bob ; Gao, Liming Subject: [edk2] [PATCH v1 4/4] BaseTools: merge towards minimum PCD MAX 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 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Common/DataType.py | 8 +++-- BaseTools/Source/Python/Common/RangeExpression.py | 26 +++++----------- BaseTools/Source/Python/Common/VpdInfoFile.py | 4 +-- BaseTools/Source/Python/GenFds/FfsInfStatement.py | 8 ++--- BaseTools/So= urce/Python/Workspace/DscBuildData.py | 31 ++++++++------------ 5 files changed, 30 insertions(+), 47 deletions(-) diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/= Python/Common/DataType.py index 58fe82583c41..2a58cba44552 100644 --- a/BaseTools/Source/Python/Common/DataType.py +++ b/BaseTools/Source/Python/Common/DataType.py @@ -45,6 +45,11 @@ TAB_PCD_CLEAN_NUMERIC_TYPES =3D {TAB_UINT8, TAB_UINT16, = TAB_UINT32, TAB_UINT64} TAB_PCD_NUMERIC_TYPES =3D {TAB_UINT8, TAB_UINT16, = TAB_UINT32, TAB_UINT64, 'BOOLEAN'} TAB_PCD_NUMERIC_TYPES_VOID =3D {TAB_UIN= T8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN', TAB_VOID} =20 +## The mapping dictionary from datum type to its maximum number. +MAX_VAL_TYPE =3D {"BOOLEAN":0x01, TAB_UINT8:0xFF, TAB_UINT16:0xFFFF,=20 +TAB_UINT32:0xFFFFFFFF, TAB_UINT64:0xFFFFFFFFFFFFFFFF} ## The mapping dicti= onary from datum type to size string. +MAX_SIZE_TYPE =3D {"BOOLEAN":"1", TAB_UINT8:"1", TAB_UINT16:"2",=20 +TAB_UINT32:"4", TAB_UINT64:"8"} + TAB_EDK_SOURCE =3D '$(EDK_SOURCE)' TAB_EFI_SOURCE =3D '$(EFI_SOURCE)' TAB_WORKSPACE =3D '$(WORKSPACE)' @@ -58,9 +63,6 @@ TAB_ARCH_ARM =3D 'ARM' TAB_ARCH_EBC =3D 'EBC' TAB_ARCH_AARCH64 =3D 'AARCH64' =20 -ARCH_LIST =3D [TAB_ARCH_IA32, TAB_ARCH_X64, TAB_ARCH_IPF, TAB_ARCH_ARM, TA= B_ARCH_EBC, TAB_ARCH_AARCH64] -ARCH_LIST_FULL =3D [TAB_ARCH_COMMON] + ARCH_= LIST - SUP_MODULE_BASE =3D 'BASE' SUP_MODULE_SEC =3D 'SEC' SUP_MODULE_PEI_CORE =3D 'PEI_CORE' diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/= Source/Python/Common/RangeExpression.py index 78bb13988eff..4d07bd752330 100644 --- a/BaseTools/Source/Python/Common/RangeExpression.py +++ b/BaseTools/Source/Python/Common/RangeExpression.py @@ -17,7 +17,7 @@ from CommonDataClass.Exceptions import BadExpression fro= m CommonDataClass.Exceptions import WrnExpression import uuid from Common= .Expression import PcdPattern -from Common.DataType import TAB_UINT8 +from Common.DataType import * =20 ERR_STRING_EXPR =3D 'This operator cannot be used in string expression: [%= s].' ERR_SNYTAX =3D 'Syntax error, the rest of expression cannot be evaluated: = [%s].' @@ -40,16 +40,6 @@ ERR_ARRAY_ELE =3D 'This must be HEX value for NList or A= rray: [%s].' ERR_EMPTY_EXPR =3D 'Empty expression is not allowed.' ERR_IN_OPERAND =3D 'Macro after IN operator can only be: $(FAMILY), $(ARCH= ), $(TOOL_CHAIN_TAG) and $(TARGET).' =20 -def MaxOfType(DataType): - if DataType =3D=3D TAB_UINT8: - return int('0xFF', 16) - if DataType =3D=3D TAB_UINT16: - return int('0xFFFF', 16) - if DataType =3D=3D TAB_UINT32: - return int('0xFFFFFFFF', 16) - if DataType =3D=3D TAB_UINT64: - return int('0xFFFFFFFFFFFFFFFF', 16) - class RangeObject(object): def __init__(self, start, end, empty =3D False): =20 @@ -112,7 +102,7 @@ class XOROperatorObject(object): rangeId =3D str(uuid.uuid1()) rangeContainer =3D RangeContainer() rangeContainer.push(RangeObject(0, int(Operand) - 1)) - rangeContainer.push(RangeObject(int(Operand) + 1, MaxOfType(DataTy= pe))) + rangeContainer.push(RangeObject(int(Operand) + 1,=20 + MAX_VAL_TYPE[DataType])) SymbolTable[rangeId] =3D rangeContainer return rangeId =20 @@ -150,7 +140,7 @@ class GEOperatorObject(object): raise BadExpression(ERR_SNYTAX % Expr) rangeId1 =3D str(uuid.uuid1()) rangeContainer =3D RangeContainer() - rangeContainer.push(RangeObject(int(Operand), MaxOfType(DataType))= ) + rangeContainer.push(RangeObject(int(Operand),=20 + MAX_VAL_TYPE[DataType])) SymbolTable[rangeId1] =3D rangeContainer return rangeId1 =20 =20 @@ -163,7 +153,7 @@ class GTOperatorObject(object): raise BadExpression(ERR_SNYTAX % Expr) rangeId1 =3D str(uuid.uuid1()) rangeContainer =3D RangeContainer() - rangeContainer.push(RangeObject(int(Operand) + 1, MaxOfType(DataTy= pe))) + rangeContainer.push(RangeObject(int(Operand) + 1,=20 + MAX_VAL_TYPE[DataType])) SymbolTable[rangeId1] =3D rangeContainer return rangeId1 =20 =20 @@ -308,18 +298,18 @@ class RangeExpression(object): rangeContainer =3D RangeContainer() rangeid =3D str(uuid.uuid1()) if rangeobj.empty: - rangeContainer.push(RangeObject(0, MaxOfType(self.PcdDataT= ype))) + rangeContainer.push(RangeObject(0,=20 + MAX_VAL_TYPE[self.PcdDataType])) else: if rangeobj.start > 0: rangeContainer.push(RangeObject(0, rangeobj.start - 1)= ) - if rangeobj.end < MaxOfType(self.PcdDataType): - rangeContainer.push(RangeObject(rangeobj.end + 1, MaxO= fType(self.PcdDataType))) + if rangeobj.end < MAX_VAL_TYPE[self.PcdDataType]: + rangeContainer.push(RangeObject(rangeobj.end + 1,=20 + MAX_VAL_TYPE[self.PcdDataType])) self.operanddict[rangeid] =3D rangeContainer rangeids.append(rangeid) =20 if len(rangeids) =3D=3D 0: rangeContainer =3D RangeContainer() - rangeContainer.push(RangeObject(0, MaxOfType(self.PcdDataType)= )) + rangeContainer.push(RangeObject(0,=20 + MAX_VAL_TYPE[self.PcdDataType])) rangeid =3D str(uuid.uuid1()) self.operanddict[rangeid] =3D rangeContainer return rangeid diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Sour= ce/Python/Common/VpdInfoFile.py index b8c8907ac91b..e1ea844eb7fd 100644 --- a/BaseTools/Source/Python/Common/VpdInfoFile.py +++ b/BaseTools/Source/Python/Common/VpdInfoFile.py @@ -69,8 +69,6 @@ FILE_COMMENT_TEMPLATE =3D \ # class VpdInfoFile: =20 - ## The mapping dictionary from datum type to size string. - _MAX_SIZE_TYPE =3D {"BOOLEAN":"1", TAB_UINT8:"1", TAB_UINT16:"2", TAB_= UINT32:"4", TAB_UINT64:"8"} _rVpdPcdLine =3D None=20 ## Constructor def __init__(self): @@ -102,7 +100,7 @@ class VpdInfoFile: "Invalid max datum size for VPD PCD %s.%s"= % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName)) elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:=20 if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize =3D=3D "": - Vpd.MaxDatumSize =3D VpdInfoFile._MAX_SIZE_TYPE[Vpd.DatumT= ype] + Vpd.MaxDatumSize =3D MAX_SIZE_TYPE[Vpd.DatumType] else: if Vpd.MaxDatumSize <=3D 0: EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_IN= VALID, diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/Bas= eTools/Source/Python/GenFds/FfsInfStatement.py index ab2b58de5d89..6542b44398d3 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -47,14 +47,12 @@ import Common.GlobalData as GlobalData from DepexSecti= on import DepexSection from Common.Misc import SaveFileOnChange from Comm= on.Expression import * -from Common.DataType import TAB_UINT8 +from Common.DataType import * =20 ## generate FFS from INF # # class FfsInfStatement(FfsInfStatementClassObject): - ## The mapping dictionary from datum type to its maximum number. - _MAX_SIZE_TYPE =3D {"BOOLEAN":0x01, TAB_UINT8:0xFF, TAB_UINT16:0xFFFF,= TAB_UINT32:0xFFFFFFFF, TAB_UINT64:0xFFFFFFFFFFFFFFFF} ## The constructor # # @param self The object pointer @@ -333,8 +331,8 @@ class FfsInfStatement(FfsInfStatementClassObject): EdkLogger.error("GenFds", GENFDS_ERROR, "The size of V= OID* type PCD '%s.%s' exceeds its maximum size %d bytes." \ % (Pcd.TokenSpaceGuidCName, Pcd.TokenC= Name, int(MaxDatumSize) - int(Pcd.MaxDatumSize))) else: - if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd= .DatumType] \ - or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.= DatumType]: + if PcdValueInDscOrFdf > MAX_VAL_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." \ % (Pcd.DatumType, Pcd.TokenSpaceGuidCN= ame, Pcd.TokenCName)) self.PatchPcds.append((Pcd, DefaultValue)) diff --git a/BaseTo= ols/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Works= pace/DscBuildData.py index e71f19750a56..c214e14398b6 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -1565,26 +1565,21 @@ class DscBuildData(PlatformBuildClassObject): return Result =20 def GetPcdMaxSize(self,Pcd): + if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES: + return MAX_SIZE_TYPE[Pcd.DatumType] + MaxSize =3D int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0 - if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: - if Pcd.PcdValueFromComm: - if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFr= omComm.endswith("}"): - MaxSize =3D max([len(Pcd.PcdValueFromComm.split(",")),= MaxSize]) - elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValue= FromComm.startswith("\'"): - MaxSize =3D max([len(Pcd.PcdValueFromComm)-2+1,MaxSize= ]) - elif Pcd.PcdValueFromComm.startswith("L\""): - MaxSize =3D max([2*(len(Pcd.PcdValueFromComm)-3+1),Max= Size]) - else: - MaxSize =3D max([len(Pcd.PcdValueFromComm),MaxSize]) - elif Pcd.DatumType not in ['BOOLEAN',TAB_UINT8]: - MaxSize =3D 1 - elif Pcd.DatumType =3D=3D TAB_UINT16: - MaxSize =3D 2 - elif Pcd.DatumType =3D=3D TAB_UINT32: - MaxSize =3D 4 - elif Pcd.DatumType =3D=3D TAB_UINT64: - MaxSize =3D 8 + if Pcd.PcdValueFromComm: + if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromCo= mm.endswith("}"): + return max([len(Pcd.PcdValueFromComm.split(",")),MaxSize]) + elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFrom= Comm.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 =3D "// Default Value in Dec \n" CApp =3D CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.Toke= nSpaceGuidCName, Pcd.TokenCName) -- 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel