consolidate information associated with function bodies

This commit is contained in:
Vern Paxson 2025-09-12 18:15:42 -07:00
parent f92acb3a4c
commit 3b37eb4b3a
5 changed files with 19 additions and 20 deletions

View file

@ -103,9 +103,7 @@ void CPPCompile::CreateFunction(const FuncTypePtr& ft, const ProfileFunc* pf, co
compiled_funcs.emplace(fname);
}
body_hashes[fname] = pf->HashVal();
body_priorities[fname] = priority;
body_locs[fname] = body->GetLocationInfo();
body_info[fname] = {.hash = pf->HashVal(), .priority = priority, .loc = body->GetLocationInfo()};
body_names.emplace(body.get(), fname);
}

View file

@ -378,9 +378,11 @@ void CPPCompile::RegisterCompiledBody(const string& f) {
ASSERT(fi != func_index.end());
auto type_signature = casting_index[fi->second];
auto h = body_hashes[f];
auto p = body_priorities[f];
auto loc = body_locs[f];
const auto& bi = body_info[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());
Emit("\tCPP_RegisterBody(\"%s\", (void*) %s, %s, %s, std::vector<std::string>(%s)),", f, f, Fmt(type_signature),

View file

@ -224,10 +224,10 @@ p_hash_type CPPCompile::BodyHash(const Stmt* body) {
ASSERT(bn != body_names.end());
auto& body_name = bn->second;
auto bh = body_hashes.find(body_name);
ASSERT(bh != body_hashes.end());
auto bi = body_info.find(body_name);
ASSERT(bi != body_info.end());
return bh->second;
return bi->second.hash;
}
string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e) {

View file

@ -51,15 +51,14 @@ std::unordered_map<std::string, std::string> compiled_simple_funcs;
// Maps function bodies to the names we use for them.
std::unordered_map<const Stmt*, std::string> body_names;
// Maps function names to hashes of bodies.
std::unordered_map<std::string, p_hash_type> body_hashes;
struct BodyInfo {
p_hash_type hash;
int priority;
const Location* loc; // for better-than-nothing error reporting
};
// Maps function names to priorities, for hooks & event handlers.
std::unordered_map<std::string, int> body_priorities;
// 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 their body info.
std::unordered_map<std::string, BodyInfo> body_info;
// Maps function names to events relevant to them.
std::unordered_map<std::string, std::vector<std::string>> body_events;

View file

@ -285,9 +285,9 @@ void CPPCompile::GenStandaloneActivation() {
// We didn't wind up compiling it.
continue;
auto bh = body_hashes.find(bname);
ASSERT(bh != body_hashes.end());
func_bodies[f].push_back(bh->second);
auto bi = body_info.find(bname);
ASSERT(bi != body_info.end());
func_bodies[f].push_back(bi->second.hash);
}
for ( auto& fb : func_bodies ) {