LLVM  13.0.0git
IRObjectFile.h
Go to the documentation of this file.
1 //===- IRObjectFile.h - LLVM IR object file implementation ------*- C++ -*-===//
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 declares the IRObjectFile template class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_OBJECT_IROBJECTFILE_H
14 #define LLVM_OBJECT_IROBJECTFILE_H
15 
16 #include "llvm/ADT/PointerUnion.h"
17 #include "llvm/Object/IRSymtab.h"
20 
21 namespace llvm {
22 class BitcodeModule;
23 class Mangler;
24 class Module;
25 class GlobalValue;
26 class Triple;
27 
28 namespace object {
29 class ObjectFile;
30 
31 class IRObjectFile : public SymbolicFile {
32  std::vector<std::unique_ptr<Module>> Mods;
33  ModuleSymbolTable SymTab;
35  std::vector<std::unique_ptr<Module>> Mods);
36 
37 public:
38  ~IRObjectFile() override;
39  void moveSymbolNext(DataRefImpl &Symb) const override;
40  Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override;
41  Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
42  basic_symbol_iterator symbol_begin() const override;
43  basic_symbol_iterator symbol_end() const override;
44 
45  StringRef getTargetTriple() const;
46 
47  static bool classof(const Binary *v) {
48  return v->isIR();
49  }
50 
51  using module_iterator =
53  const Module>;
54 
55  module_iterator module_begin() const { return module_iterator(Mods.begin()); }
56  module_iterator module_end() const { return module_iterator(Mods.end()); }
57 
59  return make_range(module_begin(), module_end());
60  }
61 
62  /// Finds and returns bitcode embedded in the given object file, or an
63  /// error code if not found.
65 
66  /// Finds and returns bitcode in the given memory buffer (which may
67  /// be either a bitcode file or a native object file with embedded bitcode),
68  /// or an error code if not found.
71 
74 };
75 
76 /// The contents of a bitcode file and its irsymtab. Any underlying data
77 /// for the irsymtab are owned by Symtab and Strtab.
78 struct IRSymtabFile {
79  std::vector<BitcodeModule> Mods;
82 };
83 
84 /// Reads a bitcode file, creating its irsymtab if necessary.
86 
87 }
88 
89 }
90 
91 #endif
llvm::object::IRSymtabFile
The contents of a bitcode file and its irsymtab.
Definition: IRObjectFile.h:78
llvm
Definition: AllocatorList.h:23
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::object::readIRSymtab
Expected< IRSymtabFile > readIRSymtab(MemoryBufferRef MBRef)
Reads a bitcode file, creating its irsymtab if necessary.
Definition: IRObjectFile.cpp:136
llvm::SmallVector< char, 0 >
llvm::object::IRObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition: IRObjectFile.cpp:41
llvm::object::IRSymtabFile::Strtab
SmallVector< char, 0 > Strtab
Definition: IRObjectFile.h:80
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
SymbolicFile.h
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::object::IRObjectFile::getTargetTriple
StringRef getTargetTriple() const
Definition: IRObjectFile.cpp:67
llvm::object::IRObjectFile::module_end
module_iterator module_end() const
Definition: IRObjectFile.h:56
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::OutputFileType::Object
@ Object
llvm::object::IRObjectFile::findBitcodeInObject
static Expected< MemoryBufferRef > findBitcodeInObject(const ObjectFile &Obj)
Finds and returns bitcode embedded in the given object file, or an error code if not found.
Definition: IRObjectFile.cpp:74
llvm::object::IRSymtabFile::Symtab
SmallVector< char, 0 > Symtab
Definition: IRObjectFile.h:80
llvm::object::IRObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: IRObjectFile.cpp:54
IRSymtab.h
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::object::IRObjectFile::classof
static bool classof(const Binary *v)
Definition: IRObjectFile.h:47
llvm::irsymtab::Reader
This class can be used to read a Symtab and Strtab produced by irsymtab::build.
Definition: IRSymtab.h:232
llvm::object::IRObjectFile::module_iterator
pointee_iterator< std::vector< std::unique_ptr< Module > >::const_iterator, const Module > module_iterator
Definition: IRObjectFile.h:53
llvm::object::IRObjectFile
Definition: IRObjectFile.h:31
llvm::object::content_iterator
Definition: SymbolicFile.h:67
PointerUnion.h
llvm::codeview::CodeViewContainer::ObjectFile
@ ObjectFile
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::object::IRObjectFile::~IRObjectFile
~IRObjectFile() override
Definition: IRObjectFile.cpp:35
llvm::object::IRObjectFile::printSymbolName
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
Definition: IRObjectFile.cpp:45
ModuleSymbolTable.h
llvm::object::IRObjectFile::module_begin
module_iterator module_begin() const
Definition: IRObjectFile.h:55
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:228
llvm::object::IRSymtabFile::TheReader
irsymtab::Reader TheReader
Definition: IRObjectFile.h:81
llvm::object::Binary
Definition: Binary.h:32
const_iterator
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::object::DataRefImpl
Definition: SymbolicFile.h:33
llvm::object::IRObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition: IRObjectFile.cpp:50
llvm::object::IRObjectFile::modules
iterator_range< module_iterator > modules() const
Definition: IRObjectFile.h:58
llvm::object::IRObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition: IRObjectFile.cpp:60
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::object::IRSymtabFile::Mods
std::vector< BitcodeModule > Mods
Definition: IRObjectFile.h:79
llvm::ModuleSymbolTable
Definition: ModuleSymbolTable.h:33
llvm::object::IRObjectFile::create
static Expected< std::unique_ptr< IRObjectFile > > create(MemoryBufferRef Object, LLVMContext &Context)
Definition: IRObjectFile.cpp:111
llvm::object::Binary::isIR
bool isIR() const
Definition: Binary.h:140
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::pointee_iterator
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:296
llvm::object::SymbolicFile
Definition: SymbolicFile.h:143
llvm::object::IRObjectFile::findBitcodeInMemBuffer
static Expected< MemoryBufferRef > findBitcodeInMemBuffer(MemoryBufferRef Object)
Finds and returns bitcode in the given memory buffer (which may be either a bitcode file or a native ...
Definition: IRObjectFile.cpp:90