1 //===- TapiUniversal.cpp --------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the Text-based Dynamic Library Stub format.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Object/TapiUniversal.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/Error.h"
16 #include "llvm/Support/MemoryBuffer.h"
17 #include "llvm/TextAPI/TextAPIReader.h"
20 using namespace MachO
;
21 using namespace object
;
23 TapiUniversal::TapiUniversal(MemoryBufferRef Source
, Error
&Err
)
24 : Binary(ID_TapiUniversal
, Source
) {
25 Expected
<std::unique_ptr
<InterfaceFile
>> Result
= TextAPIReader::get(Source
);
26 ErrorAsOutParameter
ErrAsOuParam(&Err
);
28 Err
= Result
.takeError();
31 ParsedFile
= std::move(Result
.get());
33 auto FlattenObjectInfo
= [this](const auto &File
) {
34 StringRef Name
= File
->getInstallName();
35 for (const Architecture Arch
: File
->getArchitectures())
36 Libraries
.emplace_back(Library({Name
, Arch
}));
39 FlattenObjectInfo(ParsedFile
);
40 // Get inlined documents from tapi file.
41 for (const std::shared_ptr
<InterfaceFile
> &File
: ParsedFile
->documents())
42 FlattenObjectInfo(File
);
45 TapiUniversal::~TapiUniversal() = default;
47 Expected
<std::unique_ptr
<TapiFile
>>
48 TapiUniversal::ObjectForArch::getAsObjectFile() const {
49 return std::unique_ptr
<TapiFile
>(new TapiFile(Parent
->getMemoryBufferRef(),
50 *Parent
->ParsedFile
.get(),
51 Parent
->Libraries
[Index
].Arch
));
54 Expected
<std::unique_ptr
<TapiUniversal
>>
55 TapiUniversal::create(MemoryBufferRef Source
) {
56 Error Err
= Error::success();
57 std::unique_ptr
<TapiUniversal
> Ret(new TapiUniversal(Source
, Err
));
59 return std::move(Err
);
60 return std::move(Ret
);