Example #1
0
ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
                                               BumpPtrAllocator &Alloc) {
  TypeTableBuilder TTB(Alloc, false);
  uint32_t Size = sizeof(uint32_t);
  for (const auto &Leaf : Leafs) {
    CVType T = Leaf.toCodeViewRecord(TTB);
    Size += T.length();
    assert(T.length() % 4 == 0 && "Improper type record alignment!");
  }
  uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
  MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
  BinaryStreamWriter Writer(Output, support::little);
  ExitOnError Err("Error writing type record to .debug$T section");
  Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
  for (const auto &R : TTB.records()) {
    Err(Writer.writeBytes(R));
  }
  assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");
  return Output;
}
 static size_t length(const CVType &Item) { return Item.length(); }