1 //===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Abstraction for target process addresses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
15 #define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
17 #include "llvm/ExecutionEngine/JITSymbolFlags.h"
18 #include "llvm/Support/DataTypes.h"
25 /// @brief Represents an address in the target process's address space.
26 typedef uint64_t TargetAddress;
28 /// @brief Represents a symbol in the JIT.
29 class JITSymbol : public JITSymbolBase {
32 typedef std::function<TargetAddress()> GetAddressFtor;
34 /// @brief Create a 'null' symbol that represents failure to find a symbol
36 JITSymbol(std::nullptr_t)
37 : JITSymbolBase(JITSymbolFlags::None), CachedAddr(0) {}
39 /// @brief Create a symbol for a definition with a known address.
40 JITSymbol(TargetAddress Addr, JITSymbolFlags Flags)
41 : JITSymbolBase(Flags), CachedAddr(Addr) {}
43 /// @brief Create a symbol for a definition that doesn't have a known address
45 /// @param GetAddress A functor to materialize a definition (fixing the
46 /// address) on demand.
48 /// This constructor allows a JIT layer to provide a reference to a symbol
49 /// definition without actually materializing the definition up front. The
50 /// user can materialize the definition at any time by calling the getAddress
52 JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)
53 : JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {}
55 /// @brief Returns true if the symbol exists, false otherwise.
56 explicit operator bool() const { return CachedAddr || GetAddress; }
58 /// @brief Get the address of the symbol in the target address space. Returns
59 /// '0' if the symbol does not exist.
60 TargetAddress getAddress() {
62 CachedAddr = GetAddress();
63 assert(CachedAddr && "Symbol could not be materialized.");
70 GetAddressFtor GetAddress;
71 TargetAddress CachedAddr;
74 } // End namespace orc.
75 } // End namespace llvm.
77 #endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H