[clang] Add test for CWG190 "Layout-compatible POD-struct types" (#121668)
[llvm-project.git] / llvm / lib / ObjectYAML / ArchiveEmitter.cpp
blob238e6f3d37ab2f775e7f47c655f7cd23998ab9e0
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/raw_ostream.h"
13 using namespace llvm;
14 using namespace ArchYAML;
16 namespace llvm {
17 namespace yaml {
19 bool yaml2archive(ArchYAML::Archive &Doc, raw_ostream &Out, ErrorHandler EH) {
20 Out.write(Doc.Magic.data(), Doc.Magic.size());
22 if (Doc.Content) {
23 Doc.Content->writeAsBinary(Out);
24 return true;
27 if (!Doc.Members)
28 return true;
30 auto WriteField = [&](StringRef Field, uint8_t Size) {
31 Out.write(Field.data(), Field.size());
32 for (size_t I = Field.size(); I != Size; ++I)
33 Out.write(' ');
36 for (const Archive::Child &C : *Doc.Members) {
37 for (auto &P : C.Fields)
38 WriteField(P.second.Value, P.second.MaxLength);
40 if (C.Content)
41 C.Content->writeAsBinary(Out);
42 if (C.PaddingByte)
43 Out.write(*C.PaddingByte);
46 return true;
49 } // namespace yaml
50 } // namespace llvm