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
9#include "llvm/ObjectYAML/ArchiveYAML.h"
10#include "llvm/ObjectYAML/yaml2obj.h"
11#include "llvm/Support/Error.h"
12#include "llvm/Support/raw_ostream.h"
13
14using namespace llvm;
15using namespace ArchYAML;
16
17namespace llvm {
18namespace yaml {
19
20bool yaml2archive(ArchYAML::Archive &Doc, raw_ostream &Out, ErrorHandler EH) {
21 Out.write(Ptr: Doc.Magic.data(), Size: Doc.Magic.size());
22
23 if (Doc.Content) {
24 Doc.Content->writeAsBinary(OS&: Out);
25 return true;
26 }
27
28 if (!Doc.Members)
29 return true;
30
31 auto WriteField = [&](StringRef Field, uint8_t Size) {
32 Out.write(Ptr: Field.data(), Size: Field.size());
33 for (size_t I = Field.size(); I != Size; ++I)
34 Out.write(C: ' ');
35 };
36
37 for (const Archive::Child &C : *Doc.Members) {
38 for (auto &P : C.Fields)
39 WriteField(P.second.Value, P.second.MaxLength);
40
41 if (C.Content)
42 C.Content->writeAsBinary(OS&: Out);
43 if (C.PaddingByte)
44 Out.write(C: *C.PaddingByte);
45 }
46
47 return true;
48}
49
50} // namespace yaml
51} // namespace llvm
52

source code of llvm/lib/ObjectYAML/ArchiveEmitter.cpp