From: "Feng, Bob C" <bob.c.feng@intel.com>
To: "Carsey, Jaben" <jaben.carsey@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Gao, Liming" <liming.gao@intel.com>,
"Feng, Bob C" <bob.c.feng@intel.com>
Subject: Re: [PATCH v1 4/4] BaseTools: merge towards minimum PCD MAX <something> methods
Date: Thu, 12 Apr 2018 00:40:07 +0000 [thread overview]
Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D1553D93DF@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <fc423074e167c320796437e04747dd7bde30fd25.1523487973.git.jaben.carsey@intel.com>
Reviewed-by: Feng, Bob C <bob.c.feng@intel.com>
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben
Sent: Thursday, April 12, 2018 7:08 AM
To: edk2-devel@lists.01.org
Cc: Feng, Bob <bob.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2] [PATCH v1 4/4] 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>
---
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/Source/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 = {TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64} TAB_PCD_NUMERIC_TYPES = {TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN'} TAB_PCD_NUMERIC_TYPES_VOID = {TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN', TAB_VOID}
+## 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_EDK_SOURCE = '$(EDK_SOURCE)'
TAB_EFI_SOURCE = '$(EFI_SOURCE)'
TAB_WORKSPACE = '$(WORKSPACE)'
@@ -58,9 +63,6 @@ TAB_ARCH_ARM = 'ARM'
TAB_ARCH_EBC = 'EBC'
TAB_ARCH_AARCH64 = 'AARCH64'
-ARCH_LIST = [TAB_ARCH_IA32, TAB_ARCH_X64, TAB_ARCH_IPF, TAB_ARCH_ARM, TAB_ARCH_EBC, TAB_ARCH_AARCH64] -ARCH_LIST_FULL = [TAB_ARCH_COMMON] + ARCH_LIST
-
SUP_MODULE_BASE = 'BASE'
SUP_MODULE_SEC = 'SEC'
SUP_MODULE_PEI_CORE = '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 from CommonDataClass.Exceptions import WrnExpression import uuid from Common.Expression import PcdPattern -from Common.DataType import TAB_UINT8
+from Common.DataType import *
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
@@ -40,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_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'
-def MaxOfType(DataType):
- if DataType == TAB_UINT8:
- return int('0xFF', 16)
- if DataType == TAB_UINT16:
- return int('0xFFFF', 16)
- if DataType == TAB_UINT32:
- return int('0xFFFFFFFF', 16)
- if DataType == TAB_UINT64:
- return int('0xFFFFFFFFFFFFFFFF', 16)
-
class RangeObject(object):
def __init__(self, start, end, empty = False):
@@ -112,7 +102,7 @@ class XOROperatorObject(object):
rangeId = str(uuid.uuid1())
rangeContainer = RangeContainer()
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
return rangeId
@@ -150,7 +140,7 @@ class GEOperatorObject(object):
raise BadExpression(ERR_SNYTAX % Expr)
rangeId1 = str(uuid.uuid1())
rangeContainer = RangeContainer()
- rangeContainer.push(RangeObject(int(Operand), MaxOfType(DataType)))
+ rangeContainer.push(RangeObject(int(Operand),
+ MAX_VAL_TYPE[DataType]))
SymbolTable[rangeId1] = rangeContainer
return rangeId1
@@ -163,7 +153,7 @@ class GTOperatorObject(object):
raise BadExpression(ERR_SNYTAX % Expr)
rangeId1 = str(uuid.uuid1())
rangeContainer = RangeContainer()
- rangeContainer.push(RangeObject(int(Operand) + 1, MaxOfType(DataType)))
+ rangeContainer.push(RangeObject(int(Operand) + 1,
+ MAX_VAL_TYPE[DataType]))
SymbolTable[rangeId1] = rangeContainer
return rangeId1
@@ -308,18 +298,18 @@ class RangeExpression(object):
rangeContainer = RangeContainer()
rangeid = str(uuid.uuid1())
if rangeobj.empty:
- rangeContainer.push(RangeObject(0, MaxOfType(self.PcdDataType)))
+ rangeContainer.push(RangeObject(0,
+ 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, MaxOfType(self.PcdDataType)))
+ if rangeobj.end < MAX_VAL_TYPE[self.PcdDataType]:
+ rangeContainer.push(RangeObject(rangeobj.end + 1,
+ MAX_VAL_TYPE[self.PcdDataType]))
self.operanddict[rangeid] = rangeContainer
rangeids.append(rangeid)
if len(rangeids) == 0:
rangeContainer = RangeContainer()
- rangeContainer.push(RangeObject(0, MaxOfType(self.PcdDataType)))
+ rangeContainer.push(RangeObject(0,
+ MAX_VAL_TYPE[self.PcdDataType]))
rangeid = str(uuid.uuid1())
self.operanddict[rangeid] = rangeContainer
return rangeid
diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/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 = \ # class VpdInfoFile:
- ## 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"}
_rVpdPcdLine = None
## 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:
if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "":
- Vpd.MaxDatumSize = VpdInfoFile._MAX_SIZE_TYPE[Vpd.DatumType]
+ Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]
else:
if Vpd.MaxDatumSize <= 0:
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/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 DepexSection import DepexSection from Common.Misc import SaveFileOnChange from Common.Expression import * -from Common.DataType import TAB_UINT8
+from Common.DataType import *
## generate FFS from INF
#
#
class FfsInfStatement(FfsInfStatementClassObject):
- ## The mapping dictionary from datum type to its maximum number.
- _MAX_SIZE_TYPE = {"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 VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \
% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, 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.TokenSpaceGuidCName, Pcd.TokenCName))
self.PatchPcds.append((Pcd, DefaultValue)) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/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
def GetPcdMaxSize(self,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.DatumType not in TAB_PCD_NUMERIC_TYPES:
- if Pcd.PcdValueFromComm:
- if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromComm.endswith("}"):
- MaxSize = max([len(Pcd.PcdValueFromComm.split(",")),MaxSize])
- elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFromComm.startswith("\'"):
- MaxSize = max([len(Pcd.PcdValueFromComm)-2+1,MaxSize])
- elif Pcd.PcdValueFromComm.startswith("L\""):
- MaxSize = max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize])
- else:
- MaxSize = max([len(Pcd.PcdValueFromComm),MaxSize])
- elif Pcd.DatumType not in ['BOOLEAN',TAB_UINT8]:
- MaxSize = 1
- elif Pcd.DatumType == TAB_UINT16:
- MaxSize = 2
- elif Pcd.DatumType == TAB_UINT32:
- MaxSize = 4
- elif Pcd.DatumType == TAB_UINT64:
- MaxSize = 8
+ 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)
--
2.16.2.windows.1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
prev parent reply other threads:[~2018-04-12 0:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-11 23:08 [PATCH v1 0/4] BaseTools: refactoring (and one bug fix) Jaben
2018-04-11 23:08 ` [PATCH v1 1/4] BaseTools: remove duplicate function name Jaben
2018-04-18 8:37 ` Zhu, Yonghong
2018-04-11 23:08 ` [PATCH v1 2/4] BaseTools: replace 'UINT8', 'UINT16', 'UINT32', 'UINT64', 'VOID*' with shared constants Jaben
2018-04-17 13:32 ` Zhu, Yonghong
2018-04-11 23:08 ` [PATCH v1 3/4] BaseTools: Remove un-needed list comprehension Jaben
2018-04-18 8:38 ` Zhu, Yonghong
2018-04-11 23:08 ` [PATCH v1 4/4] BaseTools: merge towards minimum PCD MAX <something> methods Jaben
2018-04-12 0:40 ` Feng, Bob C [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=08650203BA1BD64D8AD9B6D5D74A85D1553D93DF@SHSMSX101.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox