[llvm] r359091 - [yaml2obj] Replace num_zeros with write_zeros
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 24 06:23:15 PDT 2019
Author: maskray
Date: Wed Apr 24 06:23:15 2019
New Revision: 359091
URL: http://llvm.org/viewvc/llvm-project?rev=359091&view=rev
Log:
[yaml2obj] Replace num_zeros with write_zeros
Modified:
llvm/trunk/tools/yaml2obj/yaml2coff.cpp
Modified: llvm/trunk/tools/yaml2obj/yaml2coff.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2coff.cpp?rev=359091&r1=359090&r2=359091&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2coff.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2coff.cpp Wed Apr 24 06:23:15 2019
@@ -339,22 +339,6 @@ zeros_impl<sizeof(T)> zeros(const T &) {
return zeros_impl<sizeof(T)>();
}
-struct num_zeros_impl {
- size_t N;
- num_zeros_impl(size_t N) : N(N) {}
-};
-
-raw_ostream &operator<<(raw_ostream &OS, const num_zeros_impl &NZI) {
- for (size_t I = 0; I != NZI.N; ++I)
- OS.write(0);
- return OS;
-}
-
-static num_zeros_impl num_zeros(size_t N) {
- num_zeros_impl NZI(N);
- return NZI;
-}
-
template <typename T>
static uint32_t initializeOptionalHeader(COFFParser &CP, uint16_t Magic, T Header) {
memset(Header, 0, sizeof(*Header));
@@ -431,7 +415,7 @@ static bool writeCOFF(COFFParser &CP, ra
OS.write(reinterpret_cast<char *>(&DH), sizeof(DH));
// Write padding until we reach the position of where our PE signature
// should live.
- OS << num_zeros(DOSStubSize - sizeof(DH));
+ OS.write_zeros(DOSStubSize - sizeof(DH));
// Write out the PE signature.
OS.write(COFF::PEMagic, sizeof(COFF::PEMagic));
}
@@ -515,10 +499,10 @@ static bool writeCOFF(COFFParser &CP, ra
if (!S.Header.SizeOfRawData)
continue;
assert(S.Header.PointerToRawData >= OS.tell());
- OS << num_zeros(S.Header.PointerToRawData - OS.tell());
+ OS.write_zeros(S.Header.PointerToRawData - OS.tell());
S.SectionData.writeAsBinary(OS);
assert(S.Header.SizeOfRawData >= S.SectionData.binary_size());
- OS << num_zeros(S.Header.SizeOfRawData - S.SectionData.binary_size());
+ OS.write_zeros(S.Header.SizeOfRawData - S.SectionData.binary_size());
for (const COFFYAML::Relocation &R : S.Relocations) {
uint32_t SymbolTableIndex;
if (R.SymbolTableIndex) {
@@ -550,25 +534,28 @@ static bool writeCOFF(COFFParser &CP, ra
<< binary_le(i->Header.StorageClass)
<< binary_le(i->Header.NumberOfAuxSymbols);
- if (i->FunctionDefinition)
+ if (i->FunctionDefinition) {
OS << binary_le(i->FunctionDefinition->TagIndex)
<< binary_le(i->FunctionDefinition->TotalSize)
<< binary_le(i->FunctionDefinition->PointerToLinenumber)
<< binary_le(i->FunctionDefinition->PointerToNextFunction)
- << zeros(i->FunctionDefinition->unused)
- << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
- if (i->bfAndefSymbol)
+ << zeros(i->FunctionDefinition->unused);
+ OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ }
+ if (i->bfAndefSymbol) {
OS << zeros(i->bfAndefSymbol->unused1)
<< binary_le(i->bfAndefSymbol->Linenumber)
<< zeros(i->bfAndefSymbol->unused2)
<< binary_le(i->bfAndefSymbol->PointerToNextFunction)
- << zeros(i->bfAndefSymbol->unused3)
- << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
- if (i->WeakExternal)
+ << zeros(i->bfAndefSymbol->unused3);
+ OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ }
+ if (i->WeakExternal) {
OS << binary_le(i->WeakExternal->TagIndex)
<< binary_le(i->WeakExternal->Characteristics)
- << zeros(i->WeakExternal->unused)
- << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ << zeros(i->WeakExternal->unused);
+ OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ }
if (!i->File.empty()) {
unsigned SymbolSize = CP.getSymbolSize();
uint32_t NumberOfAuxRecords =
@@ -576,9 +563,9 @@ static bool writeCOFF(COFFParser &CP, ra
uint32_t NumberOfAuxBytes = NumberOfAuxRecords * SymbolSize;
uint32_t NumZeros = NumberOfAuxBytes - i->File.size();
OS.write(i->File.data(), i->File.size());
- OS << num_zeros(NumZeros);
+ OS.write_zeros(NumZeros);
}
- if (i->SectionDefinition)
+ if (i->SectionDefinition) {
OS << binary_le(i->SectionDefinition->Length)
<< binary_le(i->SectionDefinition->NumberOfRelocations)
<< binary_le(i->SectionDefinition->NumberOfLinenumbers)
@@ -586,14 +573,16 @@ static bool writeCOFF(COFFParser &CP, ra
<< binary_le(static_cast<int16_t>(i->SectionDefinition->Number))
<< binary_le(i->SectionDefinition->Selection)
<< zeros(i->SectionDefinition->unused)
- << binary_le(static_cast<int16_t>(i->SectionDefinition->Number >> 16))
- << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
- if (i->CLRToken)
+ << binary_le(static_cast<int16_t>(i->SectionDefinition->Number >> 16));
+ OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ }
+ if (i->CLRToken) {
OS << binary_le(i->CLRToken->AuxType)
<< zeros(i->CLRToken->unused1)
<< binary_le(i->CLRToken->SymbolTableIndex)
- << zeros(i->CLRToken->unused2)
- << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ << zeros(i->CLRToken->unused2);
+ OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
+ }
}
// Output string table.
More information about the llvm-commits
mailing list