[Orc] Add missing casserts header to JITSymbol.h.
[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/Compiler.h"
18 #include <cassert>
19 #include <functional>
20
21 namespace llvm {
22
23 /// @brief Represents an address in the target process's address space.
24 typedef uint64_t TargetAddress;
25
26 /// @brief Represents a symbol in the JIT.
27 class JITSymbol {
28 public:
29   typedef std::function<TargetAddress()> GetAddressFtor;
30
31   JITSymbol(std::nullptr_t) : CachedAddr(0) {}
32
33   JITSymbol(GetAddressFtor GetAddress)
34       : CachedAddr(0), GetAddress(std::move(GetAddress)) {}
35
36   /// @brief Returns true if the symbol exists, false otherwise.
37   LLVM_EXPLICIT operator bool() const { return CachedAddr || GetAddress; }
38
39   /// @brief Get the address of the symbol in the target address space. Returns
40   ///        '0' if the symbol does not exist.
41   TargetAddress getAddress() {
42     if (GetAddress) {
43       CachedAddr = GetAddress();
44       assert(CachedAddr && "Symbol could not be materialized.");
45       GetAddress = nullptr;
46     }
47     return CachedAddr;
48   }
49
50 private:
51   TargetAddress CachedAddr;
52   GetAddressFtor GetAddress;
53 };
54
55 }
56
57 #endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H