forked from OSchip/llvm-project
[yaml2obj] Replace num_zeros with write_zeros
llvm-svn: 359091
This commit is contained in:
parent
b49e192a37
commit
de0462a500
|
@ -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, raw_ostream &OS) {
|
|||
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, raw_ostream &OS) {
|
|||
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, raw_ostream &OS) {
|
|||
<< 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, raw_ostream &OS) {
|
|||
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, raw_ostream &OS) {
|
|||
<< 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.
|
||||
|
|
Loading…
Reference in New Issue