[Hexagon] Removing unused patterns.
[oota-llvm.git] / include / llvm / ExecutionEngine / Orc / JITSymbol.h
1 //===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Abstraction for target process addresses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
15 #define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include <cassert>
19 #include <functional>
20
21 namespace llvm {
22 namespace orc {
23
24 /// @brief Represents an address in the target process's address space.
25 typedef uint64_t TargetAddress;
26
27 /// @brief Represents a symbol in the JIT.
28 class JITSymbol {
29 public:
30   typedef std::function<TargetAddress()> GetAddressFtor;
31
32   /// @brief Create a 'null' symbol that represents failure to find a symbol
33   ///        definition.
34   JITSymbol(std::nullptr_t) : CachedAddr(0) {}
35
36   /// @brief Create a symbol for a definition with a known address.
37   JITSymbol(TargetAddress Addr)
38     : CachedAddr(Addr) {}
39
40   /// @brief Create a symbol for a definition that doesn't have a known address
41   ///        yet.
42   /// @param GetAddress A functor to materialize a definition (fixing the
43   ///        address) on demand.
44   ///
45   ///   This constructor allows a JIT layer to provide a reference to a symbol
46   /// definition without actually materializing the definition up front. The
47   /// user can materialize the definition at any time by calling the getAddress
48   /// method.
49   JITSymbol(GetAddressFtor GetAddress)
50     : CachedAddr(0), GetAddress(std::move(GetAddress)) {}
51
52   /// @brief Returns true if the symbol exists, false otherwise.
53   explicit operator bool() const { return CachedAddr || GetAddress; }
54
55   /// @brief Get the address of the symbol in the target address space. Returns
56   ///        '0' if the symbol does not exist.
57   TargetAddress getAddress() {
58     if (GetAddress) {
59       CachedAddr = GetAddress();
60       assert(CachedAddr && "Symbol could not be materialized.");
61       GetAddress = nullptr;
62     }
63     return CachedAddr;
64   }
65
66 private:
67   TargetAddress CachedAddr;
68   GetAddressFtor GetAddress;
69 };
70
71 } // End namespace orc.
72 } // End namespace llvm.
73
74 #endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H