extensive rewrite of generation & execution of run-time initialization

This commit is contained in:
Vern Paxson 2021-11-07 17:00:19 -08:00
parent bc3bf4ea6c
commit e1a760e674
26 changed files with 3459 additions and 1580 deletions

View file

@ -34,10 +34,8 @@ void CPPCompile::CompileLambda(const LambdaExpr* l, const ProfileFunc* pf)
DefineBody(l_id->GetType<FuncType>(), pf, lname, body, &ids, FUNC_FLAVOR_FUNCTION);
}
void CPPCompile::GenInvokeBody(const string& fname, const TypePtr& t, const string& args)
void CPPCompile::GenInvokeBody(const string& call, const TypePtr& t)
{
auto call = fname + "(" + args + ")";
if ( ! t || t->Tag() == TYPE_VOID )
{
Emit("%s;", call);
@ -144,7 +142,7 @@ void CPPCompile::InitializeEvents(const ProfileFunc* pf)
// returns an EventHandlerPtr, sigh.
Emit("if ( event_registry->Lookup(\"%s\") )", e);
StartBlock();
Emit("%s = event_registry->Register(\"%s\");", ev_name.c_str(), e);
Emit("%s = event_registry->Register(\"%s\");", ev_name, e);
EndBlock();
Emit("did_init = true;");
EndBlock();
@ -233,6 +231,16 @@ string CPPCompile::BodyName(const FuncInfo& func)
return fname + "__" + Fmt(static_cast<int>(i));
}
p_hash_type CPPCompile::BodyHash(const Stmt* body)
{
ASSERT(body_names.count(body) > 0);
auto& body_name = body_names[body];
ASSERT(body_hashes.count(body_name) > 0);
return body_hashes[body_name];
}
string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e)
{
const auto& exprs = e->AsListExpr()->Exprs();