mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
factoring of generating C++ initializations, no semantic changes
This commit is contained in:
parent
2f7137999f
commit
86288426fb
2 changed files with 104 additions and 48 deletions
|
@ -301,6 +301,20 @@ private:
|
||||||
// in support of run-time initialization of various dynamic values.
|
// in support of run-time initialization of various dynamic values.
|
||||||
void GenEpilog();
|
void GenEpilog();
|
||||||
|
|
||||||
|
// Generate the main method of the CPPDynStmt class, doing dynamic
|
||||||
|
// dispatch for function invocation.
|
||||||
|
void GenCPPDynStmt();
|
||||||
|
|
||||||
|
// Generate a function to load BiFs.
|
||||||
|
void GenLoadBiFs();
|
||||||
|
|
||||||
|
// Generate the main initialization function, which finalizes
|
||||||
|
// the run-time environment.
|
||||||
|
void GenFinishInit();
|
||||||
|
|
||||||
|
// Generate the function that registers compiled script bodies.
|
||||||
|
void GenRegisterBodies();
|
||||||
|
|
||||||
// True if the given function (plus body and profile) is one
|
// True if the given function (plus body and profile) is one
|
||||||
// that should be compiled. If non-nil, sets reason to the
|
// that should be compiled. If non-nil, sets reason to the
|
||||||
// the reason why, if there's a fundamental problem. If however
|
// the reason why, if there's a fundamental problem. If however
|
||||||
|
|
|
@ -306,9 +306,65 @@ void CPPCompile::GenEpilog()
|
||||||
GenInitExpr(ii.second);
|
GenInitExpr(ii.second);
|
||||||
|
|
||||||
NL();
|
NL();
|
||||||
Emit("ValPtr CPPDynStmt::Exec(Frame* f, StmtFlowType& flow)");
|
GenCPPDynStmt();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
for ( auto gi : all_global_info )
|
||||||
|
gi->GenerateInitializers(this);
|
||||||
|
|
||||||
|
NL();
|
||||||
|
InitializeEnumMappings();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
InitializeFieldMappings();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
InitializeBiFs();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
indices_mgr.Generate(this);
|
||||||
|
|
||||||
|
NL();
|
||||||
|
InitializeStrings();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
InitializeHashes();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
InitializeConsts();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
GenLoadBiFs();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
GenFinishInit();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
GenRegisterBodies();
|
||||||
|
|
||||||
|
NL();
|
||||||
|
Emit("void init__CPP()");
|
||||||
StartBlock();
|
StartBlock();
|
||||||
|
Emit("register_bodies__CPP();");
|
||||||
|
EndBlock();
|
||||||
|
|
||||||
|
if ( standalone )
|
||||||
|
GenStandaloneActivation();
|
||||||
|
|
||||||
|
GenInitHook();
|
||||||
|
|
||||||
|
Emit("} // %s\n\n", scope_prefix(addl_tag));
|
||||||
|
Emit("} // zeek::detail");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPPCompile::GenCPPDynStmt()
|
||||||
|
{
|
||||||
|
Emit("ValPtr CPPDynStmt::Exec(Frame* f, StmtFlowType& flow)");
|
||||||
|
|
||||||
|
StartBlock();
|
||||||
|
|
||||||
Emit("flow = FLOW_RETURN;");
|
Emit("flow = FLOW_RETURN;");
|
||||||
|
|
||||||
Emit("switch ( type_signature )");
|
Emit("switch ( type_signature )");
|
||||||
StartBlock();
|
StartBlock();
|
||||||
for ( auto i = 0U; i < func_casting_glue.size(); ++i )
|
for ( auto i = 0U; i < func_casting_glue.size(); ++i )
|
||||||
|
@ -343,41 +399,29 @@ void CPPCompile::GenEpilog()
|
||||||
|
|
||||||
EndBlock();
|
EndBlock();
|
||||||
EndBlock();
|
EndBlock();
|
||||||
|
}
|
||||||
|
|
||||||
NL();
|
void CPPCompile::GenLoadBiFs()
|
||||||
|
{
|
||||||
|
Emit("void load_BiFs__CPP()");
|
||||||
|
StartBlock();
|
||||||
|
Emit("for ( auto& b : CPP__BiF_lookups__ )");
|
||||||
|
Emit("\tb.ResolveBiF();");
|
||||||
|
EndBlock();
|
||||||
|
}
|
||||||
|
|
||||||
for ( auto gi : all_global_info )
|
void CPPCompile::GenFinishInit()
|
||||||
gi->GenerateInitializers(this);
|
{
|
||||||
|
Emit("void finish_init__CPP()");
|
||||||
if ( standalone )
|
|
||||||
GenStandaloneActivation();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
InitializeEnumMappings();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
InitializeFieldMappings();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
InitializeBiFs();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
indices_mgr.Generate(this);
|
|
||||||
|
|
||||||
NL();
|
|
||||||
InitializeStrings();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
InitializeHashes();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
InitializeConsts();
|
|
||||||
|
|
||||||
NL();
|
|
||||||
Emit("void init__CPP()");
|
|
||||||
|
|
||||||
StartBlock();
|
StartBlock();
|
||||||
|
|
||||||
|
Emit("static bool did_init = false;");
|
||||||
|
Emit("if ( did_init )");
|
||||||
|
Emit("\treturn;");
|
||||||
|
Emit("did_init = true;");
|
||||||
|
|
||||||
|
NL();
|
||||||
Emit("std::vector<std::vector<int>> InitIndices;");
|
Emit("std::vector<std::vector<int>> InitIndices;");
|
||||||
Emit("generate_indices_set(CPP__Indices__init, InitIndices);");
|
Emit("generate_indices_set(CPP__Indices__init, InitIndices);");
|
||||||
|
|
||||||
|
@ -394,13 +438,6 @@ void CPPCompile::GenEpilog()
|
||||||
Emit("InitsManager im(CPP__ConstVals, InitConsts, InitIndices, CPP__Strings, CPP__Hashes, "
|
Emit("InitsManager im(CPP__ConstVals, InitConsts, InitIndices, CPP__Strings, CPP__Hashes, "
|
||||||
"CPP__Type__, CPP__Attributes__, CPP__Attr__, CPP__CallExpr__);");
|
"CPP__Type__, CPP__Attributes__, CPP__Attr__, CPP__CallExpr__);");
|
||||||
|
|
||||||
NL();
|
|
||||||
Emit("for ( auto& b : CPP__bodies_to_register )");
|
|
||||||
StartBlock();
|
|
||||||
Emit("auto f = make_intrusive<CPPDynStmt>(b.func_name.c_str(), b.func, b.type_signature);");
|
|
||||||
Emit("register_body__CPP(f, b.priority, b.h, b.events);");
|
|
||||||
EndBlock();
|
|
||||||
|
|
||||||
NL();
|
NL();
|
||||||
int max_cohort = 0;
|
int max_cohort = 0;
|
||||||
for ( auto gi : all_global_info )
|
for ( auto gi : all_global_info )
|
||||||
|
@ -411,10 +448,6 @@ void CPPCompile::GenEpilog()
|
||||||
if ( gi->CohortSize(c) > 0 )
|
if ( gi->CohortSize(c) > 0 )
|
||||||
Emit("%s.InitializeCohort(&im, %s);", gi->InitializersName(), Fmt(c));
|
Emit("%s.InitializeCohort(&im, %s);", gi->InitializersName(), Fmt(c));
|
||||||
|
|
||||||
NL();
|
|
||||||
Emit("for ( auto& b : CPP__BiF_lookups__ )");
|
|
||||||
Emit("\tb.ResolveBiF();");
|
|
||||||
|
|
||||||
// Populate mappings for dynamic offsets.
|
// Populate mappings for dynamic offsets.
|
||||||
NL();
|
NL();
|
||||||
Emit("for ( auto& em : CPP__enum_mappings__ )");
|
Emit("for ( auto& em : CPP__enum_mappings__ )");
|
||||||
|
@ -423,15 +456,24 @@ void CPPCompile::GenEpilog()
|
||||||
Emit("for ( auto& fm : CPP__field_mappings__ )");
|
Emit("for ( auto& fm : CPP__field_mappings__ )");
|
||||||
Emit("\tfield_mapping.push_back(fm.ComputeOffset(&im));");
|
Emit("\tfield_mapping.push_back(fm.ComputeOffset(&im));");
|
||||||
|
|
||||||
if ( standalone )
|
NL();
|
||||||
Emit("standalone_init__CPP();");
|
Emit("load_BiFs__CPP();");
|
||||||
|
|
||||||
EndBlock(true);
|
EndBlock();
|
||||||
|
}
|
||||||
|
|
||||||
GenInitHook();
|
void CPPCompile::GenRegisterBodies()
|
||||||
|
{
|
||||||
|
Emit("void register_bodies__CPP()");
|
||||||
|
StartBlock();
|
||||||
|
|
||||||
Emit("} // %s\n\n", scope_prefix(addl_tag));
|
Emit("for ( auto& b : CPP__bodies_to_register )");
|
||||||
Emit("} // zeek::detail");
|
StartBlock();
|
||||||
|
Emit("auto f = make_intrusive<CPPDynStmt>(b.func_name.c_str(), b.func, b.type_signature);");
|
||||||
|
Emit("register_body__CPP(f, b.priority, b.h, b.events, finish_init__CPP);");
|
||||||
|
EndBlock();
|
||||||
|
|
||||||
|
EndBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPPCompile::IsCompilable(const FuncInfo& func, const char** reason)
|
bool CPPCompile::IsCompilable(const FuncInfo& func, const char** reason)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue