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/Support/Compiler.h"
23 /// @brief Represents an address in the target process's address space.
24 typedef uint64_t TargetAddress;
26 /// @brief Represents a symbol in the JIT.
29 typedef std::function<TargetAddress()> GetAddressFtor;
31 /// @brief Create a 'null' symbol that represents failure to find a symbol
33 JITSymbol(std::nullptr_t) : CachedAddr(0) {}
35 /// @brief Create a symbol for a definition with a known address.
36 JITSymbol(TargetAddress Addr)
39 /// @brief Create a symbol for a definition that doesn't have a known address
41 /// @param GetAddress A functor to materialize a definition (fixing the
42 /// address) on demand.
44 /// This constructor allows a JIT layer to provide a reference to a symbol
45 /// definition without actually materializing the definition up front. The
46 /// user can materialize the definition at any time by calling the getAddress
48 JITSymbol(GetAddressFtor GetAddress)
49 : CachedAddr(0), GetAddress(std::move(GetAddress)) {}
51 /// @brief Returns true if the symbol exists, false otherwise.
52 explicit operator bool() const { return CachedAddr || GetAddress; }
54 /// @brief Get the address of the symbol in the target address space. Returns
55 /// '0' if the symbol does not exist.
56 TargetAddress getAddress() {
58 CachedAddr = GetAddress();
59 assert(CachedAddr && "Symbol could not be materialized.");
66 TargetAddress CachedAddr;
67 GetAddressFtor GetAddress;
72 #endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H