mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-08 03:18:19 +00:00
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229335 91177308-0d34-0410-b5e6-96231b3b80d8
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
//===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Abstraction for target process addresses.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
|
|
#define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
#include <cassert>
|
|
#include <functional>
|
|
|
|
namespace llvm {
|
|
|
|
/// @brief Represents an address in the target process's address space.
|
|
typedef uint64_t TargetAddress;
|
|
|
|
/// @brief Represents a symbol in the JIT.
|
|
class JITSymbol {
|
|
public:
|
|
typedef std::function<TargetAddress()> GetAddressFtor;
|
|
|
|
JITSymbol(std::nullptr_t) : CachedAddr(0) {}
|
|
|
|
JITSymbol(GetAddressFtor GetAddress)
|
|
: CachedAddr(0), GetAddress(std::move(GetAddress)) {}
|
|
|
|
/// @brief Returns true if the symbol exists, false otherwise.
|
|
explicit operator bool() const { return CachedAddr || GetAddress; }
|
|
|
|
/// @brief Get the address of the symbol in the target address space. Returns
|
|
/// '0' if the symbol does not exist.
|
|
TargetAddress getAddress() {
|
|
if (GetAddress) {
|
|
CachedAddr = GetAddress();
|
|
assert(CachedAddr && "Symbol could not be materialized.");
|
|
GetAddress = nullptr;
|
|
}
|
|
return CachedAddr;
|
|
}
|
|
|
|
private:
|
|
TargetAddress CachedAddr;
|
|
GetAddressFtor GetAddress;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
|