LLVM  12.0.0git
TapiUniversal.cpp
Go to the documentation of this file.
1 //===- TapiUniversal.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 // This file defines the Text-based Dynamic Library Stub format.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/Error.h"
18 
19 using namespace llvm;
20 using namespace MachO;
21 using namespace object;
22 
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);
27  if (!Result) {
28  Err = Result.takeError();
29  return;
30  }
31  ParsedFile = std::move(Result.get());
32 
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}));
37  };
38 
39  FlattenObjectInfo(ParsedFile);
40  // Get inlined documents from tapi file.
41  for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())
42  FlattenObjectInfo(File);
43 }
44 
46 
49  return std::unique_ptr<TapiFile>(new TapiFile(Parent->getMemoryBufferRef(),
50  *Parent->ParsedFile.get(),
51  Parent->Libraries[Index].Arch));
52 }
53 
56  Error Err = Error::success();
57  std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err));
58  if (Err)
59  return std::move(Err);
60  return std::move(Ret);
61 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Error takeError()
Take ownership of the stored error.
Definition: Error.h:557
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
TapiUniversal(MemoryBufferRef Source, Error &Err)
Expected< std::unique_ptr< TapiFile > > getAsObjectFile() const
Instrumentation for Order File
static Expected< std::unique_ptr< TapiUniversal > > create(MemoryBufferRef Source)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
reference get()
Returns a reference to the stored T value.
Definition: Error.h:537
Helper for Errors used as out-parameters.
Definition: Error.h:1060
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57