llvm.org GIT mirror llvm / e5c799a
[yaml2obj] Replace num_zeros with write_zeros git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359091 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 5 months ago
1 changed file(s) with 25 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
336336 template
337337 zeros_impl zeros(const T &) {
338338 return zeros_impl();
339 }
340
341 struct num_zeros_impl {
342 size_t N;
343 num_zeros_impl(size_t N) : N(N) {}
344 };
345
346 raw_ostream &operator<<(raw_ostream &OS, const num_zeros_impl &NZI) {
347 for (size_t I = 0; I != NZI.N; ++I)
348 OS.write(0);
349 return OS;
350 }
351
352 static num_zeros_impl num_zeros(size_t N) {
353 num_zeros_impl NZI(N);
354 return NZI;
355339 }
356340
357341 template
430414 OS.write(reinterpret_cast(&DH), sizeof(DH));
431415 // Write padding until we reach the position of where our PE signature
432416 // should live.
433 OS << num_zeros(DOSStubSize - sizeof(DH));
417 OS.write_zeros(DOSStubSize - sizeof(DH));
434418 // Write out the PE signature.
435419 OS.write(COFF::PEMagic, sizeof(COFF::PEMagic));
436420 }
514498 if (!S.Header.SizeOfRawData)
515499 continue;
516500 assert(S.Header.PointerToRawData >= OS.tell());
517 OS << num_zeros(S.Header.PointerToRawData - OS.tell());
501 OS.write_zeros(S.Header.PointerToRawData - OS.tell());
518502 S.SectionData.writeAsBinary(OS);
519503 assert(S.Header.SizeOfRawData >= S.SectionData.binary_size());
520 OS << num_zeros(S.Header.SizeOfRawData - S.SectionData.binary_size());
504 OS.write_zeros(S.Header.SizeOfRawData - S.SectionData.binary_size());
521505 for (const COFFYAML::Relocation &R : S.Relocations) {
522506 uint32_t SymbolTableIndex;
523507 if (R.SymbolTableIndex) {
549533 << binary_le(i->Header.StorageClass)
550534 << binary_le(i->Header.NumberOfAuxSymbols);
551535
552 if (i->FunctionDefinition)
536 if (i->FunctionDefinition) {
553537 OS << binary_le(i->FunctionDefinition->TagIndex)
554538 << binary_le(i->FunctionDefinition->TotalSize)
555539 << binary_le(i->FunctionDefinition->PointerToLinenumber)
556540 << binary_le(i->FunctionDefinition->PointerToNextFunction)
557 << zeros(i->FunctionDefinition->unused)
558 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
559 if (i->bfAndefSymbol)
541 << zeros(i->FunctionDefinition->unused);
542 OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
543 }
544 if (i->bfAndefSymbol) {
560545 OS << zeros(i->bfAndefSymbol->unused1)
561546 << binary_le(i->bfAndefSymbol->Linenumber)
562547 << zeros(i->bfAndefSymbol->unused2)
563548 << binary_le(i->bfAndefSymbol->PointerToNextFunction)
564 << zeros(i->bfAndefSymbol->unused3)
565 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
566 if (i->WeakExternal)
549 << zeros(i->bfAndefSymbol->unused3);
550 OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
551 }
552 if (i->WeakExternal) {
567553 OS << binary_le(i->WeakExternal->TagIndex)
568554 << binary_le(i->WeakExternal->Characteristics)
569 << zeros(i->WeakExternal->unused)
570 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
555 << zeros(i->WeakExternal->unused);
556 OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
557 }
571558 if (!i->File.empty()) {
572559 unsigned SymbolSize = CP.getSymbolSize();
573560 uint32_t NumberOfAuxRecords =
575562 uint32_t NumberOfAuxBytes = NumberOfAuxRecords * SymbolSize;
576563 uint32_t NumZeros = NumberOfAuxBytes - i->File.size();
577564 OS.write(i->File.data(), i->File.size());
578 OS << num_zeros(NumZeros);
579 }
580 if (i->SectionDefinition)
565 OS.write_zeros(NumZeros);
566 }
567 if (i->SectionDefinition) {
581568 OS << binary_le(i->SectionDefinition->Length)
582569 << binary_le(i->SectionDefinition->NumberOfRelocations)
583570 << binary_le(i->SectionDefinition->NumberOfLinenumbers)
585572 << binary_le(static_cast(i->SectionDefinition->Number))
586573 << binary_le(i->SectionDefinition->Selection)
587574 << zeros(i->SectionDefinition->unused)
588 << binary_le(static_cast(i->SectionDefinition->Number >> 16))
589 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
590 if (i->CLRToken)
575 << binary_le(static_cast(i->SectionDefinition->Number >> 16));
576 OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
577 }
578 if (i->CLRToken) {
591579 OS << binary_le(i->CLRToken->AuxType)
592580 << zeros(i->CLRToken->unused1)
593581 << binary_le(i->CLRToken->SymbolTableIndex)
594 << zeros(i->CLRToken->unused2)
595 << num_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
582 << zeros(i->CLRToken->unused2);
583 OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
584 }
596585 }
597586
598587 // Output string table.