ArchiveEmitter.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===- ArchiveEmitter.cpp ---------------------------- --------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/ObjectYAML/ArchiveYAML.h"
  9. #include "llvm/ObjectYAML/yaml2obj.h"
  10. #include "llvm/Support/Error.h"
  11. #include "llvm/Support/raw_ostream.h"
  12. using namespace llvm;
  13. using namespace ArchYAML;
  14. namespace llvm {
  15. namespace yaml {
  16. bool yaml2archive(ArchYAML::Archive &Doc, raw_ostream &Out, ErrorHandler EH) {
  17. Out.write(Doc.Magic.data(), Doc.Magic.size());
  18. if (Doc.Content) {
  19. Doc.Content->writeAsBinary(Out);
  20. return true;
  21. }
  22. if (!Doc.Members)
  23. return true;
  24. auto WriteField = [&](StringRef Field, uint8_t Size) {
  25. Out.write(Field.data(), Field.size());
  26. for (size_t I = Field.size(); I != Size; ++I)
  27. Out.write(' ');
  28. };
  29. for (const Archive::Child &C : *Doc.Members) {
  30. for (auto &P : C.Fields)
  31. WriteField(P.second.Value, P.second.MaxLength);
  32. if (C.Content)
  33. C.Content->writeAsBinary(Out);
  34. if (C.PaddingByte)
  35. Out.write(*C.PaddingByte);
  36. }
  37. return true;
  38. }
  39. } // namespace yaml
  40. } // namespace llvm