From 9f30e401282ff27072fd9463b4de1fa79f085b79 Mon Sep 17 00:00:00 2001 From: "Feng, Bob C" Date: Mon, 21 Jan 2019 17:44:50 +0800 Subject: [PATCH] BaseTools: Enable CODE format in DEC file BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1292. Enable CODE format in DEC File. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao Reviewed-by: Liming Gao --- .../Source/Python/Workspace/DscBuildData.py | 38 +++---- .../Source/Python/Workspace/MetaFileParser.py | 99 ++++++++++++------- BaseTools/Source/Python/build/BuildReport.py | 2 +- 3 files changed, 86 insertions(+), 53 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index afcf99e66b..a59966c0ab 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -1796,7 +1796,8 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2])) Value, ValueSize = ParseFieldValue(Value) - CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]); + if not Pcd.IsArray: + CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]); else: NewFieldName = '' FieldName_ori = FieldName.strip('.') @@ -1805,7 +1806,7 @@ class DscBuildData(PlatformBuildClassObject): ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) FieldName = FieldName.split(']', 1)[1] FieldName = NewFieldName + FieldName - while '[' in FieldName: + while '[' in FieldName and not Pcd.IsArray: 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, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0]) for skuname in Pcd.SkuOverrideValues: @@ -1827,7 +1828,8 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2])) Value, ValueSize = ParseFieldValue(Value) - CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]); + if not Pcd.IsArray: + CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]); else: NewFieldName = '' FieldName_ori = FieldName.strip('.') @@ -1836,7 +1838,7 @@ class DscBuildData(PlatformBuildClassObject): ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) FieldName = FieldName.split(']', 1)[1] FieldName = NewFieldName + FieldName - while '[' in FieldName: + while '[' in FieldName and not Pcd.IsArray: 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, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0]) if Pcd.PcdFieldValueFromFdf: @@ -1851,7 +1853,8 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2])) Value, ValueSize = ParseFieldValue(Value) - CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0]); + if not Pcd.IsArray: + CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0]); else: NewFieldName = '' FieldName_ori = FieldName.strip('.') @@ -1875,7 +1878,8 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2])) Value, ValueSize = ParseFieldValue(Value) - CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]); + if not Pcd.IsArray: + CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]); else: NewFieldName = '' FieldName_ori = FieldName.strip('.') @@ -1884,7 +1888,7 @@ class DscBuildData(PlatformBuildClassObject): ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0]) FieldName = FieldName.split(']', 1)[1] FieldName = NewFieldName + FieldName - while '[' in FieldName: + while '[' in FieldName and not Pcd.IsArray: 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]) if Pcd.GetPcdMaxSize(): @@ -1915,10 +1919,11 @@ class DscBuildData(PlatformBuildClassObject): PcdDefValue = Pcd.DefaultValue if lastoneisEmpty: if "{CODE(" not in PcdDefValue: - sizebasevalue_plus = "(%s / sizeof(%s) + 1)" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), "".join(r_datatype))) - sizebasevalue = "(%s / sizeof(%s))" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), "".join(r_datatype))) + sizebasevalue_plus = "(%s / sizeof(%s) + 1)" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), Pcd.BaseDatumType)) + sizebasevalue = "(%s / sizeof(%s))" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), Pcd.BaseDatumType)) sizeof = "sizeof(%s)" % Pcd.BaseDatumType - CApp = ' Size = %s %% %s ? %s : %s ;\n' % ( (DscBuildData.GetStructurePcdMaxSize(Pcd), sizeof, sizebasevalue_plus, sizebasevalue)) + CApp = ' int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData.GetStructurePcdMaxSize(Pcd), sizeof, sizebasevalue_plus, sizebasevalue)) + CApp += ' Size = ArraySize * sizeof(%s); \n' % Pcd.BaseDatumType else: CApp = " Size = 0;\n" else: @@ -1978,9 +1983,7 @@ class DscBuildData(PlatformBuildClassObject): (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec)) DefaultValueFromDec = StringToArray(DefaultValueFromDec) Value, ValueSize = ParseFieldValue (DefaultValueFromDec) - if isinstance(Value, str): - CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec) - elif IsArray: + if IsArray: # # Use memcpy() to copy value into field # @@ -1989,6 +1992,8 @@ class DscBuildData(PlatformBuildClassObject): else: CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec) CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) + elif isinstance(Value, str): + CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec) for index in Pcd.DefaultValues: FieldList = Pcd.DefaultValues[index] if not FieldList: @@ -2008,9 +2013,7 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2])) indicator = self.GetIndicator(index, FieldName,Pcd) - if isinstance(Value, str): - CApp = CApp + ' %s = %s; // From %s Line %d Value %s\n' % (indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) - elif IsArray: + if IsArray: # # Use memcpy() to copy value into field # @@ -2019,7 +2022,8 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) CApp = CApp + ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize) - + elif isinstance(Value, str): + CApp = CApp + ' %s = %s; // From %s Line %d Value %s\n' % (indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) else: if '[' in FieldName and ']' in FieldName: Index = int(FieldName.split('[')[1].split(']')[0]) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index b2428a535c..311d0faf38 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -192,6 +192,10 @@ class MetaFileParser(object): self._Version = 0 self._GuidDict = {} # for Parser PCD value {GUID(gTokeSpaceGuidName)} + self._PcdCodeValue = "" + self._PcdDataTypeCODE = False + self._CurrentPcdName = "" + ## Store the parsed data in table def _Store(self, *Args): return self._Table.Insert(*Args) @@ -483,6 +487,39 @@ class MetaFileParser(object): return Macros + def ProcessMultipleLineCODEValue(self,Content): + CODEBegin = False + CODELine = "" + continuelinecount = 0 + newContent = [] + for Index in range(0, len(Content)): + Line = Content[Index] + if CODEBegin: + CODELine = CODELine + Line + continuelinecount +=1 + if ")}" in Line: + newContent.append(CODELine) + for _ in range(continuelinecount): + newContent.append("") + CODEBegin = False + CODELine = "" + continuelinecount = 0 + else: + if not Line: + newContent.append(Line) + continue + if "{CODE(" not in Line: + newContent.append(Line) + continue + elif CODEPattern.findall(Line): + newContent.append(Line) + continue + else: + CODEBegin = True + CODELine = Line + + return newContent + _SectionParser = {} ## INF file parser class @@ -907,9 +944,6 @@ class DscParser(MetaFileParser): # self._IdMapping = {-1:-1} - self._PcdCodeValue = "" - self._PcdDataTypeCODE = False - self._CurrentPcdName = "" self._Content = None ## Parser starter @@ -1140,38 +1174,6 @@ class DscParser(MetaFileParser): def _LibraryInstanceParser(self): self._ValueList[0] = self._CurrentLine - def ProcessMultipleLineCODEValue(self,Content): - CODEBegin = False - CODELine = "" - continuelinecount = 0 - newContent = [] - for Index in range(0, len(Content)): - Line = Content[Index] - if CODEBegin: - CODELine = CODELine + Line - continuelinecount +=1 - if ")}" in Line: - newContent.append(CODELine) - for _ in range(continuelinecount): - newContent.append("") - CODEBegin = False - CODELine = "" - continuelinecount = 0 - else: - if not Line: - newContent.append(Line) - continue - if "{CODE(" not in Line: - newContent.append(Line) - continue - elif CODEPattern.findall(Line): - newContent.append(Line) - continue - else: - CODEBegin = True - CODELine = Line - - return newContent def _DecodeCODEData(self): pass @@ -1778,6 +1780,8 @@ class DecParser(MetaFileParser): self._include_flag = False self._package_flag = False + self._RestofValue = "" + ## Parser starter def Start(self): Content = '' @@ -1786,6 +1790,8 @@ class DecParser(MetaFileParser): except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) + Content = self.ProcessMultipleLineCODEValue(Content) + self._DefinesCount = 0 for Index in range(0, len(Content)): Line, Comment = CleanString2(Content[Index]) @@ -1983,6 +1989,7 @@ class DecParser(MetaFileParser): # @ParseMacro def _PcdParser(self): + if self._CurrentStructurePcdName: self._ValueList[0] = self._CurrentStructurePcdName @@ -2028,7 +2035,29 @@ class DecParser(MetaFileParser): self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:]) self._ValueList[2] = PcdTockens[1] if not self._CurrentStructurePcdName: + if self._PcdDataTypeCODE: + if ")}" in self._CurrentLine: + ValuePart,RestofValue = self._CurrentLine.split(")}") + self._PcdCodeValue = self._PcdCodeValue + "\n " + ValuePart + self._CurrentLine = "|".join((self._CurrentPcdName, self._PcdCodeValue,RestofValue)) + self._PcdDataTypeCODE = False + self._PcdCodeValue = "" + else: + self._PcdCodeValue = self._PcdCodeValue + "\n " + self._CurrentLine + self._ValueList = None + return TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1) + self._CurrentPcdName = TokenList[0] + if len(TokenList) == 2 and TokenList[1].strip().startswith("{CODE"): + if ")}" in self._CurrentLine: + self._PcdDataTypeCODE = False + self._PcdCodeValue = "" + else: + self._PcdDataTypeCODE = True + self._PcdCodeValue = TokenList[1].strip() + self._ValueList = None + return + self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT) ValueRe = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*') # check PCD information diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py index 8d3b030151..44f7706bb3 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -149,7 +149,7 @@ def ByteArrayForamt(Value): IsByteArray = False SplitNum = 16 ArrayList = [] - if Value.startswith('{') and Value.endswith('}'): + if Value.startswith('{') and Value.endswith('}') and not Value.startswith("{CODE("): Value = Value[1:-1] ValueList = Value.split(',') if len(ValueList) >= SplitNum: