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/DataTypes.h"
24 /// @brief Represents an address in the target process's address space.
25 typedef uint64_t TargetAddress;
27 /// @brief Represents a symbol in the JIT.
30 typedef std::function<TargetAddress()> GetAddressFtor;
32 /// @brief Create a 'null' symbol that represents failure to find a symbol
34 JITSymbol(std::nullptr_t) : CachedAddr(0) {}
36 /// @brief Create a symbol for a definition with a known address.
37 JITSymbol(TargetAddress Addr)
40 /// @brief Create a symbol for a definition that doesn't have a known address
42 /// @param GetAddress A functor to materialize a definition (fixing the
43 /// address) on demand.
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
49 JITSymbol(GetAddressFtor GetAddress)
50 : CachedAddr(0), GetAddress(std::move(GetAddress)) {}
52 /// @brief Returns true if the symbol exists, false otherwise.
53 explicit operator bool() const { return CachedAddr || GetAddress; }
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() {
59 CachedAddr = GetAddress();
60 assert(CachedAddr && "Symbol could not be materialized.");
67 TargetAddress CachedAddr;
68 GetAddressFtor GetAddress;
71 } // End namespace orc.
72 } // End namespace llvm.
74 #endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H