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/MachO/TextAPIReader.h"
20 using namespace MachO
;
21 using namespace object
;
23 TapiUniversal::TapiUniversal(MemoryBufferRef Source
, Error
&Err
)
24 : Binary(ID_TapiUniversal
, Source
) {
25 auto Result
= TextAPIReader::get(Source
);
26 ErrorAsOutParameter
ErrAsOuParam(&Err
);
28 Err
= Result
.takeError();
31 ParsedFile
= std::move(Result
.get());
33 auto Archs
= ParsedFile
->getArchitectures();
34 for (auto Arch
: Archs
)
35 Architectures
.emplace_back(Arch
);
38 TapiUniversal::~TapiUniversal() = default;
40 Expected
<std::unique_ptr
<TapiFile
>>
41 TapiUniversal::ObjectForArch::getAsObjectFile() const {
42 return std::unique_ptr
<TapiFile
>(new TapiFile(Parent
->getMemoryBufferRef(),
43 *Parent
->ParsedFile
.get(),
44 Parent
->Architectures
[Index
]));
47 Expected
<std::unique_ptr
<TapiUniversal
>>
48 TapiUniversal::create(MemoryBufferRef Source
) {
49 Error Err
= Error::success();
50 std::unique_ptr
<TapiUniversal
> Ret(new TapiUniversal(Source
, Err
));
52 return std::move(Err
);
53 return std::move(Ret
);