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