mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 20:06:03 +03:00
func map
This commit is contained in:
parent
a27d6492c3
commit
c6a454b367
1 changed files with 23 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "callback_ostream.h"
|
||||
#include "context.h"
|
||||
|
@ -92,8 +93,10 @@ private:
|
|||
struct Func {
|
||||
llvm::StringRef name;
|
||||
void **thunkVar;
|
||||
void *originalFunc;
|
||||
};
|
||||
std::vector<Func> funcs;
|
||||
mutable std::unordered_map<const void *, const Func *> funcsMap;
|
||||
|
||||
public:
|
||||
JitModuleInfo(const Context &context,
|
||||
|
@ -101,12 +104,31 @@ public:
|
|||
enumModules(modlist_head, context, [&](const RtCompileModuleList ¤t) {
|
||||
for (auto &&fun : toArray(current.funcList, static_cast<std::size_t>(
|
||||
current.funcListSize))) {
|
||||
funcs.push_back({fun.name, fun.func});
|
||||
funcs.push_back({fun.name, fun.func, fun.originalFunc});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<Func> &functions() const { return funcs; }
|
||||
|
||||
const std::unordered_map<const void *, const Func *> &functionsMap() const {
|
||||
if (funcsMap.empty() && !funcs.empty()) {
|
||||
for (auto &&fun : funcs) {
|
||||
funcsMap.insert({fun.originalFunc, &fun});
|
||||
}
|
||||
}
|
||||
return funcsMap;
|
||||
}
|
||||
|
||||
const Func *getFunc(const void *ptr) const {
|
||||
assert(ptr != nullptr);
|
||||
auto &funcMap = functionsMap();
|
||||
auto it = funcMap.find(ptr);
|
||||
if (funcMap.end() != it) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
std::string decorate(const std::string &name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue