mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
consolidate information associated with function bodies
This commit is contained in:
parent
f92acb3a4c
commit
3b37eb4b3a
5 changed files with 19 additions and 20 deletions
|
@ -103,9 +103,7 @@ void CPPCompile::CreateFunction(const FuncTypePtr& ft, const ProfileFunc* pf, co
|
||||||
compiled_funcs.emplace(fname);
|
compiled_funcs.emplace(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
body_hashes[fname] = pf->HashVal();
|
body_info[fname] = {.hash = pf->HashVal(), .priority = priority, .loc = body->GetLocationInfo()};
|
||||||
body_priorities[fname] = priority;
|
|
||||||
body_locs[fname] = body->GetLocationInfo();
|
|
||||||
body_names.emplace(body.get(), fname);
|
body_names.emplace(body.get(), fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,9 +378,11 @@ void CPPCompile::RegisterCompiledBody(const string& f) {
|
||||||
ASSERT(fi != func_index.end());
|
ASSERT(fi != func_index.end());
|
||||||
auto type_signature = casting_index[fi->second];
|
auto type_signature = casting_index[fi->second];
|
||||||
|
|
||||||
auto h = body_hashes[f];
|
const auto& bi = body_info[f];
|
||||||
auto p = body_priorities[f];
|
|
||||||
auto loc = body_locs[f];
|
auto h = bi.hash;
|
||||||
|
auto p = bi.priority;
|
||||||
|
auto loc = bi.loc;
|
||||||
auto body_info = Fmt(p) + ", " + Fmt(h) + ", \"" + loc->FileName() + " (C++)\", " + Fmt(loc->FirstLine());
|
auto body_info = Fmt(p) + ", " + Fmt(h) + ", \"" + loc->FileName() + " (C++)\", " + Fmt(loc->FirstLine());
|
||||||
|
|
||||||
Emit("\tCPP_RegisterBody(\"%s\", (void*) %s, %s, %s, std::vector<std::string>(%s)),", f, f, Fmt(type_signature),
|
Emit("\tCPP_RegisterBody(\"%s\", (void*) %s, %s, %s, std::vector<std::string>(%s)),", f, f, Fmt(type_signature),
|
||||||
|
|
|
@ -224,10 +224,10 @@ p_hash_type CPPCompile::BodyHash(const Stmt* body) {
|
||||||
ASSERT(bn != body_names.end());
|
ASSERT(bn != body_names.end());
|
||||||
|
|
||||||
auto& body_name = bn->second;
|
auto& body_name = bn->second;
|
||||||
auto bh = body_hashes.find(body_name);
|
auto bi = body_info.find(body_name);
|
||||||
ASSERT(bh != body_hashes.end());
|
ASSERT(bi != body_info.end());
|
||||||
|
|
||||||
return bh->second;
|
return bi->second.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e) {
|
string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e) {
|
||||||
|
|
|
@ -51,15 +51,14 @@ std::unordered_map<std::string, std::string> compiled_simple_funcs;
|
||||||
// Maps function bodies to the names we use for them.
|
// Maps function bodies to the names we use for them.
|
||||||
std::unordered_map<const Stmt*, std::string> body_names;
|
std::unordered_map<const Stmt*, std::string> body_names;
|
||||||
|
|
||||||
// Maps function names to hashes of bodies.
|
struct BodyInfo {
|
||||||
std::unordered_map<std::string, p_hash_type> body_hashes;
|
p_hash_type hash;
|
||||||
|
int priority;
|
||||||
|
const Location* loc; // for better-than-nothing error reporting
|
||||||
|
};
|
||||||
|
|
||||||
// Maps function names to priorities, for hooks & event handlers.
|
// Maps function names to their body info.
|
||||||
std::unordered_map<std::string, int> body_priorities;
|
std::unordered_map<std::string, BodyInfo> body_info;
|
||||||
|
|
||||||
// Maps function names to script locations, for better-than-nothing error
|
|
||||||
// reporting.
|
|
||||||
std::unordered_map<std::string, const Location*> body_locs;
|
|
||||||
|
|
||||||
// Maps function names to events relevant to them.
|
// Maps function names to events relevant to them.
|
||||||
std::unordered_map<std::string, std::vector<std::string>> body_events;
|
std::unordered_map<std::string, std::vector<std::string>> body_events;
|
||||||
|
|
|
@ -285,9 +285,9 @@ void CPPCompile::GenStandaloneActivation() {
|
||||||
// We didn't wind up compiling it.
|
// We didn't wind up compiling it.
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto bh = body_hashes.find(bname);
|
auto bi = body_info.find(bname);
|
||||||
ASSERT(bh != body_hashes.end());
|
ASSERT(bi != body_info.end());
|
||||||
func_bodies[f].push_back(bh->second);
|
func_bodies[f].push_back(bi->second.hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( auto& fb : func_bodies ) {
|
for ( auto& fb : func_bodies ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue