Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / ObjectYAML / ArchiveEmitter.cpp
bloba0cf8fe360dada87f63e719c72d6b0798784d0ad
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 //===----------------------------------------------------------------------===//
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"
14 using namespace llvm;
15 using namespace ArchYAML;
17 namespace llvm {
18 namespace yaml {
20 bool yaml2archive(ArchYAML::Archive &Doc, raw_ostream &Out, ErrorHandler EH) {
21 Out.write(Doc.Magic.data(), Doc.Magic.size());
23 if (Doc.Content) {
24 Doc.Content->writeAsBinary(Out);
25 return true;
28 if (!Doc.Members)
29 return true;
31 auto WriteField = [&](StringRef Field, uint8_t Size) {
32 Out.write(Field.data(), Field.size());
33 for (size_t I = Field.size(); I != Size; ++I)
34 Out.write(' ');
37 for (const Archive::Child &C : *Doc.Members) {
38 for (auto &P : C.Fields)
39 WriteField(P.second.Value, P.second.MaxLength);
41 if (C.Content)
42 C.Content->writeAsBinary(Out);
43 if (C.PaddingByte)
44 Out.write(*C.PaddingByte);
47 return true;
50 } // namespace yaml
51 } // namespace llvm