Skip to content
Snippets Groups Projects
Commit 559f76aa authored by Vassil Vassilev's avatar Vassil Vassilev
Browse files

[cling] Constify.

parent a3afb447
No related branches found
No related tags found
No related merge requests found
...@@ -148,8 +148,8 @@ void unresolvedSymbol() ...@@ -148,8 +148,8 @@ void unresolvedSymbol()
// throw exception instead? // throw exception instead?
} }
void* IncrementalExecutor::HandleMissingFunction(const std::string& mangled_name) void*
{ IncrementalExecutor::HandleMissingFunction(const std::string& mangled_name) const {
// Not found in the map, add the symbol in the list of unresolved symbols // Not found in the map, add the symbol in the list of unresolved symbols
if (m_unresolvedSymbols.insert(mangled_name).second) { if (m_unresolvedSymbols.insert(mangled_name).second) {
//cling::errs() << "IncrementalExecutor: use of undefined symbol '" //cling::errs() << "IncrementalExecutor: use of undefined symbol '"
...@@ -159,10 +159,9 @@ void* IncrementalExecutor::HandleMissingFunction(const std::string& mangled_name ...@@ -159,10 +159,9 @@ void* IncrementalExecutor::HandleMissingFunction(const std::string& mangled_name
return utils::FunctionToVoidPtr(&unresolvedSymbol); return utils::FunctionToVoidPtr(&unresolvedSymbol);
} }
void* IncrementalExecutor::NotifyLazyFunctionCreators(const std::string& mangled_name) void*
{ IncrementalExecutor::NotifyLazyFunctionCreators(const std::string& mangled_name) const {
for (std::vector<LazyFunctionCreatorFunc_t>::iterator it for (auto it = m_lazyFuncCreator.begin(), et = m_lazyFuncCreator.end();
= m_lazyFuncCreator.begin(), et = m_lazyFuncCreator.end();
it != et; ++it) { it != et; ++it) {
void* ret = (void*)((LazyFunctionCreatorFunc_t)*it)(mangled_name); void* ret = (void*)((LazyFunctionCreatorFunc_t)*it)(mangled_name);
if (ret) if (ret)
...@@ -208,7 +207,7 @@ freeCallersOfUnresolvedSymbols(llvm::SmallVectorImpl<llvm::Function*>& ...@@ -208,7 +207,7 @@ freeCallersOfUnresolvedSymbols(llvm::SmallVectorImpl<llvm::Function*>&
#endif #endif
IncrementalExecutor::ExecutionResult IncrementalExecutor::ExecutionResult
IncrementalExecutor::runStaticInitializersOnce(const Transaction& T) { IncrementalExecutor::runStaticInitializersOnce(const Transaction& T) const {
auto m = T.getModule(); auto m = T.getModule();
assert(m.get() && "Module must not be null"); assert(m.get() && "Module must not be null");
...@@ -326,7 +325,7 @@ static void flushOutBuffers() { ...@@ -326,7 +325,7 @@ static void flushOutBuffers() {
IncrementalExecutor::ExecutionResult IncrementalExecutor::ExecutionResult
IncrementalExecutor::executeWrapper(llvm::StringRef function, IncrementalExecutor::executeWrapper(llvm::StringRef function,
Value* returnValue/* =0*/) { Value* returnValue/* =0*/) const {
// Set the value to cling::invalid. // Set the value to cling::invalid.
if (returnValue) if (returnValue)
*returnValue = Value(); *returnValue = Value();
...@@ -351,12 +350,12 @@ IncrementalExecutor::installLazyFunctionCreator(LazyFunctionCreatorFunc_t fp) ...@@ -351,12 +350,12 @@ IncrementalExecutor::installLazyFunctionCreator(LazyFunctionCreatorFunc_t fp)
bool bool
IncrementalExecutor::addSymbol(const char* Name, void* Addr, IncrementalExecutor::addSymbol(const char* Name, void* Addr,
bool Jit) { bool Jit) const {
return m_JIT->lookupSymbol(Name, Addr, Jit).second; return m_JIT->lookupSymbol(Name, Addr, Jit).second;
} }
void* IncrementalExecutor::getAddressOfGlobal(llvm::StringRef symbolName, void* IncrementalExecutor::getAddressOfGlobal(llvm::StringRef symbolName,
bool* fromJIT /*=0*/) { bool* fromJIT /*=0*/) const {
// Return a symbol's address, and whether it was jitted. // Return a symbol's address, and whether it was jitted.
void* address = m_JIT->lookupSymbol(symbolName).first; void* address = m_JIT->lookupSymbol(symbolName).first;
...@@ -371,7 +370,7 @@ void* IncrementalExecutor::getAddressOfGlobal(llvm::StringRef symbolName, ...@@ -371,7 +370,7 @@ void* IncrementalExecutor::getAddressOfGlobal(llvm::StringRef symbolName,
} }
void* void*
IncrementalExecutor::getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) { IncrementalExecutor::getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) const {
// Get the function / variable pointer referenced by GV. // Get the function / variable pointer referenced by GV.
// We don't care whether something was unresolved before. // We don't care whether something was unresolved before.
...@@ -386,7 +385,7 @@ IncrementalExecutor::getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) { ...@@ -386,7 +385,7 @@ IncrementalExecutor::getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) {
} }
bool IncrementalExecutor::diagnoseUnresolvedSymbols(llvm::StringRef trigger, bool IncrementalExecutor::diagnoseUnresolvedSymbols(llvm::StringRef trigger,
llvm::StringRef title) { llvm::StringRef title) const {
if (m_unresolvedSymbols.empty()) if (m_unresolvedSymbols.empty())
return false; return false;
......
...@@ -133,7 +133,7 @@ namespace cling { ...@@ -133,7 +133,7 @@ namespace cling {
///\brief Set of the symbols that the JIT couldn't resolve. ///\brief Set of the symbols that the JIT couldn't resolve.
/// ///
std::unordered_set<std::string> m_unresolvedSymbols; mutable std::unordered_set<std::string> m_unresolvedSymbols;
#if 0 // See FIXME in IncrementalExecutor.cpp #if 0 // See FIXME in IncrementalExecutor.cpp
///\brief The diagnostics engine, printing out issues coming from the ///\brief The diagnostics engine, printing out issues coming from the
...@@ -164,7 +164,7 @@ namespace cling { ...@@ -164,7 +164,7 @@ namespace cling {
void installLazyFunctionCreator(LazyFunctionCreatorFunc_t fp); void installLazyFunctionCreator(LazyFunctionCreatorFunc_t fp);
///\brief Unload a set of JIT symbols. ///\brief Unload a set of JIT symbols.
bool unloadModule(const std::shared_ptr<llvm::Module>& M) { bool unloadModule(const std::shared_ptr<llvm::Module>& M) const {
// FIXME: Propagate the error in a more verbose way. // FIXME: Propagate the error in a more verbose way.
if (auto Err = m_JIT->removeModule(M)) if (auto Err = m_JIT->removeModule(M))
return false; return false;
...@@ -172,7 +172,7 @@ namespace cling { ...@@ -172,7 +172,7 @@ namespace cling {
} }
///\brief Run the static initializers of all modules collected to far. ///\brief Run the static initializers of all modules collected to far.
ExecutionResult runStaticInitializersOnce(const Transaction& T); ExecutionResult runStaticInitializersOnce(const Transaction& T) const;
///\brief Runs all destructors bound to the given transaction and removes ///\brief Runs all destructors bound to the given transaction and removes
/// them from the list. /// them from the list.
...@@ -182,7 +182,7 @@ namespace cling { ...@@ -182,7 +182,7 @@ namespace cling {
///\brief Runs a wrapper function. ///\brief Runs a wrapper function.
ExecutionResult executeWrapper(llvm::StringRef function, ExecutionResult executeWrapper(llvm::StringRef function,
Value* returnValue = 0); Value* returnValue = 0) const;
///\brief Adds a symbol (function) to the execution engine. ///\brief Adds a symbol (function) to the execution engine.
/// ///
/// Allows runtime declaration of a function passing its pointer for being /// Allows runtime declaration of a function passing its pointer for being
...@@ -194,13 +194,14 @@ namespace cling { ...@@ -194,13 +194,14 @@ namespace cling {
/// @param[in] JIT - Add to the JIT injected symbol table /// @param[in] JIT - Add to the JIT injected symbol table
/// @returns true if the symbol is successfully registered, false otherwise. /// @returns true if the symbol is successfully registered, false otherwise.
/// ///
bool addSymbol(const char* Name, void* Address, bool JIT = false); bool addSymbol(const char* Name, void* Address, bool JIT = false) const;
///\brief Emit a llvm::Module to the JIT. ///\brief Emit a llvm::Module to the JIT.
/// ///
/// @param[in] module - The module to pass to the execution engine. /// @param[in] module - The module to pass to the execution engine.
/// @param[in] optLevel - The optimization level to be used. /// @param[in] optLevel - The optimization level to be used.
void emitModule(const std::shared_ptr<llvm::Module>& module, int optLevel) { void
emitModule(const std::shared_ptr<llvm::Module>& module, int optLevel) const {
if (m_BackendPasses) if (m_BackendPasses)
m_BackendPasses->runOnModule(*module, optLevel); m_BackendPasses->runOnModule(*module, optLevel);
...@@ -223,14 +224,15 @@ namespace cling { ...@@ -223,14 +224,15 @@ namespace cling {
///\param[in] mangledName - the globa's name ///\param[in] mangledName - the globa's name
///\param[out] fromJIT - whether the symbol was JITted. ///\param[out] fromJIT - whether the symbol was JITted.
/// ///
void* getAddressOfGlobal(llvm::StringRef mangledName, bool* fromJIT = 0); void*
getAddressOfGlobal(llvm::StringRef mangledName, bool* fromJIT = 0) const;
///\brief Return the address of a global from the JIT (as ///\brief Return the address of a global from the JIT (as
/// opposed to dynamic libraries). Forces the emission of the symbol if /// opposed to dynamic libraries). Forces the emission of the symbol if
/// it has not happened yet. /// it has not happened yet.
/// ///
///param[in] GV - global value for which the address will be returned. ///param[in] GV - global value for which the address will be returned.
void* getPointerToGlobalFromJIT(const llvm::GlobalValue& GV); void* getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) const;
///\brief Keep track of the entities whose dtor we need to call. ///\brief Keep track of the entities whose dtor we need to call.
/// ///
...@@ -239,19 +241,19 @@ namespace cling { ...@@ -239,19 +241,19 @@ namespace cling {
///\brief Try to resolve a symbol through our LazyFunctionCreators; ///\brief Try to resolve a symbol through our LazyFunctionCreators;
/// print an error message if that fails. /// print an error message if that fails.
void* NotifyLazyFunctionCreators(const std::string&); void* NotifyLazyFunctionCreators(const std::string&) const;
private: private:
///\brief Report and empty m_unresolvedSymbols. ///\brief Report and empty m_unresolvedSymbols.
///\return true if m_unresolvedSymbols was non-empty. ///\return true if m_unresolvedSymbols was non-empty.
bool diagnoseUnresolvedSymbols(llvm::StringRef trigger, bool diagnoseUnresolvedSymbols(llvm::StringRef trigger,
llvm::StringRef title = llvm::StringRef()); llvm::StringRef title = llvm::StringRef()) const;
///\brief Remember that the symbol could not be resolved by the JIT. ///\brief Remember that the symbol could not be resolved by the JIT.
void* HandleMissingFunction(const std::string& symbol); void* HandleMissingFunction(const std::string& symbol) const;
///\brief Runs an initializer function. ///\brief Runs an initializer function.
ExecutionResult executeInit(llvm::StringRef function) { ExecutionResult executeInit(llvm::StringRef function) const {
typedef void (*InitFun_t)(); typedef void (*InitFun_t)();
InitFun_t fun; InitFun_t fun;
ExecutionResult res = jitInitOrWrapper(function, fun); ExecutionResult res = jitInitOrWrapper(function, fun);
...@@ -263,7 +265,7 @@ namespace cling { ...@@ -263,7 +265,7 @@ namespace cling {
} }
template <class T> template <class T>
ExecutionResult jitInitOrWrapper(llvm::StringRef funcname, T& fun) { ExecutionResult jitInitOrWrapper(llvm::StringRef funcname, T& fun) const {
fun = utils::UIntToFunctionPtr<T>(m_JIT->getSymbolAddress(funcname, fun = utils::UIntToFunctionPtr<T>(m_JIT->getSymbolAddress(funcname,
false /*dlsym*/)); false /*dlsym*/));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment