mirror of https://github.com/acidanthera/audk.git
BaseTools: change the Division Operator in the expression
PEP 238 -- Changing the Division Operator x/y to return a reasonable approximation of the mathematical result of the division ("true division") x//y to return the floor ("floor division") Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
00fcce9153
commit
2e300969ae
|
@ -3729,7 +3729,7 @@ class ModuleAutoGen(AutoGen):
|
|||
Padding = '0x00, '
|
||||
if Unicode:
|
||||
Padding = Padding * 2
|
||||
ArraySize = ArraySize / 2
|
||||
ArraySize = ArraySize // 2
|
||||
if ArraySize < (len(PcdValue) + 1):
|
||||
if Pcd.MaxSizeUserSet:
|
||||
EdkLogger.error("build", AUTOGEN_ERROR,
|
||||
|
|
|
@ -1050,7 +1050,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
|
|||
else:
|
||||
NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '
|
||||
if Unicode:
|
||||
ArraySize = ArraySize / 2
|
||||
ArraySize = ArraySize // 2
|
||||
Value = NewValue + '0 }'
|
||||
if ArraySize < ValueSize:
|
||||
if Pcd.MaxSizeUserSet:
|
||||
|
@ -1060,7 +1060,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
|
|||
else:
|
||||
ArraySize = Pcd.GetPcdSize()
|
||||
if Unicode:
|
||||
ArraySize = ArraySize / 2
|
||||
ArraySize = ArraySize // 2
|
||||
Array = '[%d]' % ArraySize
|
||||
#
|
||||
# skip casting for fixed at build since it breaks ARM assembly.
|
||||
|
@ -1919,7 +1919,7 @@ def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):
|
|||
else:
|
||||
ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)
|
||||
ImageBuffer += pack('B', PaletteIndex)
|
||||
Width = (BmpHeader.biWidth + 7)/8
|
||||
Width = (BmpHeader.biWidth + 7)//8
|
||||
if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
|
||||
PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
|
||||
elif BmpHeader.biBitCount == 4:
|
||||
|
@ -1928,7 +1928,7 @@ def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):
|
|||
else:
|
||||
ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)
|
||||
ImageBuffer += pack('B', PaletteIndex)
|
||||
Width = (BmpHeader.biWidth + 1)/2
|
||||
Width = (BmpHeader.biWidth + 1)//2
|
||||
if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
|
||||
PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]
|
||||
elif BmpHeader.biBitCount == 8:
|
||||
|
|
|
@ -430,7 +430,7 @@ class GenVPD :
|
|||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, 'The offset value of PCD %s should be %s-byte aligned.' % (PCD.PcdCName, Alignment))
|
||||
else:
|
||||
if PCD.PcdOccupySize % Alignment != 0:
|
||||
PCD.PcdOccupySize = (PCD.PcdOccupySize / Alignment + 1) * Alignment
|
||||
PCD.PcdOccupySize = (PCD.PcdOccupySize // Alignment + 1) * Alignment
|
||||
|
||||
PackSize = PCD.PcdOccupySize
|
||||
if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):
|
||||
|
@ -508,7 +508,7 @@ class GenVPD :
|
|||
NowOffset = 0
|
||||
for Pcd in self.PcdUnknownOffsetList :
|
||||
if NowOffset % Pcd.Alignment != 0:
|
||||
NowOffset = (NowOffset/ Pcd.Alignment + 1) * Pcd.Alignment
|
||||
NowOffset = (NowOffset // Pcd.Alignment + 1) * Pcd.Alignment
|
||||
Pcd.PcdBinOffset = NowOffset
|
||||
Pcd.PcdOffset = str(hex(Pcd.PcdBinOffset))
|
||||
NowOffset += Pcd.PcdOccupySize
|
||||
|
@ -572,7 +572,7 @@ class GenVPD :
|
|||
# Not been fixed
|
||||
if eachUnfixedPcd.PcdOffset == '*' :
|
||||
if LastOffset % eachUnfixedPcd.Alignment != 0:
|
||||
LastOffset = (LastOffset / eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment
|
||||
LastOffset = (LastOffset // eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment
|
||||
# The offset un-fixed pcd can write into this free space
|
||||
if needFixPcdSize <= (NowOffset - LastOffset) :
|
||||
# Change the offset value of un-fixed pcd
|
||||
|
@ -626,7 +626,7 @@ class GenVPD :
|
|||
|
||||
NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdOccupySize
|
||||
if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:
|
||||
NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset / NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
|
||||
NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset // NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
|
||||
|
||||
NeedFixPcd.PcdOffset = str(hex(NeedFixPcd.PcdBinOffset))
|
||||
|
||||
|
|
|
@ -425,6 +425,13 @@ class ValueExpression(BaseExpression):
|
|||
else:
|
||||
Val = Val3
|
||||
continue
|
||||
#
|
||||
# PEP 238 -- Changing the Division Operator
|
||||
# x/y to return a reasonable approximation of the mathematical result of the division ("true division")
|
||||
# x//y to return the floor ("floor division")
|
||||
#
|
||||
if Op == '/':
|
||||
Op = '//'
|
||||
try:
|
||||
Val = self.Eval(Op, Val, EvalFunc())
|
||||
except WrnExpression as Warn:
|
||||
|
@ -898,7 +905,7 @@ class ValueExpressionEx(ValueExpression):
|
|||
if TmpValue.bit_length() == 0:
|
||||
PcdValue = '{0x00}'
|
||||
else:
|
||||
for I in range((TmpValue.bit_length() + 7) / 8):
|
||||
for I in range((TmpValue.bit_length() + 7) // 8):
|
||||
TmpList.append('0x%02x' % ((TmpValue >> I * 8) & 0xff))
|
||||
PcdValue = '{' + ', '.join(TmpList) + '}'
|
||||
except:
|
||||
|
|
|
@ -1310,7 +1310,7 @@ def ParseDevPathValue (Value):
|
|||
|
||||
def ParseFieldValue (Value):
|
||||
if isinstance(Value, type(0)):
|
||||
return Value, (Value.bit_length() + 7) / 8
|
||||
return Value, (Value.bit_length() + 7) // 8
|
||||
if not isinstance(Value, type('')):
|
||||
raise BadExpression('Type %s is %s' %(Value, type(Value)))
|
||||
Value = Value.strip()
|
||||
|
@ -1431,12 +1431,12 @@ def ParseFieldValue (Value):
|
|||
raise BadExpression("invalid hex value: %s" % Value)
|
||||
if Value == 0:
|
||||
return 0, 1
|
||||
return Value, (Value.bit_length() + 7) / 8
|
||||
return Value, (Value.bit_length() + 7) // 8
|
||||
if Value[0].isdigit():
|
||||
Value = int(Value, 10)
|
||||
if Value == 0:
|
||||
return 0, 1
|
||||
return Value, (Value.bit_length() + 7) / 8
|
||||
return Value, (Value.bit_length() + 7) // 8
|
||||
if Value.lower() == 'true':
|
||||
return 1, 1
|
||||
if Value.lower() == 'false':
|
||||
|
|
|
@ -87,9 +87,9 @@ class DataSection (DataSectionClassObject):
|
|||
if ImageObj.SectionAlignment < 0x400:
|
||||
self.Alignment = str (ImageObj.SectionAlignment)
|
||||
elif ImageObj.SectionAlignment < 0x100000:
|
||||
self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
|
||||
self.Alignment = str (ImageObj.SectionAlignment // 0x400) + 'K'
|
||||
else:
|
||||
self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'
|
||||
self.Alignment = str (ImageObj.SectionAlignment // 0x100000) + 'M'
|
||||
|
||||
NoStrip = True
|
||||
if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
|
||||
|
|
|
@ -247,9 +247,9 @@ class EfiSection (EfiSectionClassObject):
|
|||
if ImageObj.SectionAlignment < 0x400:
|
||||
Align = str (ImageObj.SectionAlignment)
|
||||
elif ImageObj.SectionAlignment < 0x100000:
|
||||
Align = str (ImageObj.SectionAlignment / 0x400) + 'K'
|
||||
Align = str (ImageObj.SectionAlignment // 0x400) + 'K'
|
||||
else:
|
||||
Align = str (ImageObj.SectionAlignment / 0x100000) + 'M'
|
||||
Align = str (ImageObj.SectionAlignment // 0x100000) + 'M'
|
||||
|
||||
if File[(len(File)-4):] == '.efi':
|
||||
MapFile = File.replace('.efi', '.map')
|
||||
|
|
|
@ -770,9 +770,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
|||
if ImageObj.SectionAlignment < 0x400:
|
||||
self.Alignment = str (ImageObj.SectionAlignment)
|
||||
elif ImageObj.SectionAlignment < 0x100000:
|
||||
self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
|
||||
self.Alignment = str (ImageObj.SectionAlignment // 0x400) + 'K'
|
||||
else:
|
||||
self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'
|
||||
self.Alignment = str (ImageObj.SectionAlignment // 0x100000) + 'M'
|
||||
|
||||
if not NoStrip:
|
||||
FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')
|
||||
|
@ -812,9 +812,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
|||
if ImageObj.SectionAlignment < 0x400:
|
||||
self.Alignment = str (ImageObj.SectionAlignment)
|
||||
elif ImageObj.SectionAlignment < 0x100000:
|
||||
self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
|
||||
self.Alignment = str (ImageObj.SectionAlignment // 0x400) + 'K'
|
||||
else:
|
||||
self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'
|
||||
self.Alignment = str (ImageObj.SectionAlignment // 0x100000) + 'M'
|
||||
|
||||
if not NoStrip:
|
||||
FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')
|
||||
|
|
|
@ -212,9 +212,9 @@ class FV (FvClassObject):
|
|||
#The max alignment supported by FFS is 16M.
|
||||
self.FvAlignment = "16M"
|
||||
else:
|
||||
self.FvAlignment = str(FvAlignmentValue / 0x100000) + "M"
|
||||
self.FvAlignment = str(FvAlignmentValue // 0x100000) + "M"
|
||||
else:
|
||||
self.FvAlignment = str(FvAlignmentValue / 0x400) + "K"
|
||||
self.FvAlignment = str(FvAlignmentValue // 0x400) + "K"
|
||||
else:
|
||||
# FvAlignmentValue is less than 1K
|
||||
self.FvAlignment = str (FvAlignmentValue)
|
||||
|
|
|
@ -70,7 +70,7 @@ class FvImageSection(FvImageSectionClassObject):
|
|||
# PI FvHeader is 0x48 byte
|
||||
FvHeaderBuffer = FvFileObj.read(0x48)
|
||||
# FV alignment position.
|
||||
FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
|
||||
FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)
|
||||
FvFileObj.close()
|
||||
if FvAlignmentValue > MaxFvAlignment:
|
||||
MaxFvAlignment = FvAlignmentValue
|
||||
|
@ -86,9 +86,9 @@ class FvImageSection(FvImageSectionClassObject):
|
|||
if MaxFvAlignment >= 0x1000000:
|
||||
self.Alignment = "16M"
|
||||
else:
|
||||
self.Alignment = str(MaxFvAlignment / 0x100000) + "M"
|
||||
self.Alignment = str(MaxFvAlignment // 0x100000) + "M"
|
||||
else:
|
||||
self.Alignment = str (MaxFvAlignment / 0x400) + "K"
|
||||
self.Alignment = str (MaxFvAlignment // 0x400) + "K"
|
||||
else:
|
||||
# MaxFvAlignment is less than 1K
|
||||
self.Alignment = str (MaxFvAlignment)
|
||||
|
@ -126,9 +126,9 @@ class FvImageSection(FvImageSectionClassObject):
|
|||
if FvAlignmentValue >= 0x1000000:
|
||||
self.Alignment = "16M"
|
||||
else:
|
||||
self.Alignment = str(FvAlignmentValue / 0x100000) + "M"
|
||||
self.Alignment = str(FvAlignmentValue // 0x100000) + "M"
|
||||
else:
|
||||
self.Alignment = str (FvAlignmentValue / 0x400) + "K"
|
||||
self.Alignment = str (FvAlignmentValue // 0x400) + "K"
|
||||
else:
|
||||
# FvAlignmentValue is less than 1K
|
||||
self.Alignment = str (FvAlignmentValue)
|
||||
|
|
|
@ -684,7 +684,7 @@ class GenFds :
|
|||
F.read()
|
||||
length = F.tell()
|
||||
F.seek(4)
|
||||
TmpStr = unpack('%dh' % ((length - 4) / 2), F.read())
|
||||
TmpStr = unpack('%dh' % ((length - 4) // 2), F.read())
|
||||
Name = ''.join(chr(c) for c in TmpStr[:-1])
|
||||
else:
|
||||
FileList = []
|
||||
|
|
|
@ -296,7 +296,7 @@ class Region(RegionClassObject):
|
|||
else:
|
||||
# region ended within current blocks
|
||||
if self.Offset + self.Size <= End:
|
||||
ExpectedList.append((BlockSize, (RemindingSize + BlockSize - 1) / BlockSize))
|
||||
ExpectedList.append((BlockSize, (RemindingSize + BlockSize - 1) // BlockSize))
|
||||
break
|
||||
# region not ended yet
|
||||
else:
|
||||
|
@ -305,7 +305,7 @@ class Region(RegionClassObject):
|
|||
UsedBlockNum = BlockNum
|
||||
# region started in middle of current blocks
|
||||
else:
|
||||
UsedBlockNum = (End - self.Offset) / BlockSize
|
||||
UsedBlockNum = (End - self.Offset) // BlockSize
|
||||
Start = End
|
||||
ExpectedList.append((BlockSize, UsedBlockNum))
|
||||
RemindingSize -= BlockSize * UsedBlockNum
|
||||
|
|
|
@ -133,7 +133,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
|
|||
#
|
||||
for Index in range(ValueLength):
|
||||
ByteList[ValueOffset + Index] = ValueNumber % 0x100
|
||||
ValueNumber = ValueNumber / 0x100
|
||||
ValueNumber = ValueNumber // 0x100
|
||||
elif TypeName == TAB_VOID:
|
||||
ValueString = SavedStr
|
||||
if ValueString.startswith('L"'):
|
||||
|
|
|
@ -724,7 +724,7 @@ class PeImageInfo():
|
|||
self.OutputDir = OutputDir
|
||||
self.DebugDir = DebugDir
|
||||
self.Image = ImageClass
|
||||
self.Image.Size = (self.Image.Size / 0x1000 + 1) * 0x1000
|
||||
self.Image.Size = (self.Image.Size // 0x1000 + 1) * 0x1000
|
||||
|
||||
## The class implementing the EDK2 build process
|
||||
#
|
||||
|
@ -1597,7 +1597,7 @@ class Build():
|
|||
RtModuleList[Module.MetaFile] = ImageInfo
|
||||
#IPF runtime driver needs to be at 2 page alignment.
|
||||
if IsIpfPlatform and ImageInfo.Image.Size % 0x2000 != 0:
|
||||
ImageInfo.Image.Size = (ImageInfo.Image.Size / 0x2000 + 1) * 0x2000
|
||||
ImageInfo.Image.Size = (ImageInfo.Image.Size // 0x2000 + 1) * 0x2000
|
||||
RtSize += ImageInfo.Image.Size
|
||||
elif Module.ModuleType in [SUP_MODULE_SMM_CORE, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:
|
||||
SmmModuleList[Module.MetaFile] = ImageInfo
|
||||
|
@ -1666,21 +1666,21 @@ class Build():
|
|||
for PcdInfo in PcdTable:
|
||||
ReturnValue = 0
|
||||
if PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE:
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize / 0x1000))
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize // 0x1000))
|
||||
elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE:
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize / 0x1000))
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize // 0x1000))
|
||||
elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE:
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize / 0x1000))
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize // 0x1000))
|
||||
elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0:
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize / 0x1000))
|
||||
ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize // 0x1000))
|
||||
if ReturnValue != 0:
|
||||
EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD value failed", ExtraData=ErrorInfo)
|
||||
|
||||
MapBuffer.write('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize / 0x1000))
|
||||
MapBuffer.write('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize / 0x1000))
|
||||
MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize / 0x1000))
|
||||
MapBuffer.write('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize // 0x1000))
|
||||
MapBuffer.write('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize // 0x1000))
|
||||
MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize // 0x1000))
|
||||
if len (SmmModuleList) > 0:
|
||||
MapBuffer.write('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize / 0x1000))
|
||||
MapBuffer.write('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize // 0x1000))
|
||||
|
||||
PeiBaseAddr = TopMemoryAddress - RtSize - BtSize
|
||||
BtBaseAddr = TopMemoryAddress - RtSize
|
||||
|
|
Loading…
Reference in New Issue