fixes for -O gen-standalone-C++ generation of lambdas

This commit is contained in:
Vern Paxson 2025-01-14 17:02:12 -08:00
parent b2222e97a1
commit a3b54b69a1
4 changed files with 23 additions and 11 deletions

View file

@ -30,8 +30,13 @@ void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf) {
auto l_id = l->Ingredients()->GetID(); auto l_id = l->Ingredients()->GetID();
auto& ids = l->OuterIDs(); auto& ids = l->OuterIDs();
for ( auto id : ids ) for ( auto lid : ids ) {
lambda_names[id] = CaptureName(id); if ( lambda_names.count(lid) > 0 ) {
ASSERT(lambda_names[lid] == CaptureName(lid));
}
else
lambda_names[lid] = CaptureName(lid);
}
CreateFunction(l_id->GetType<FuncType>(), pf, lname, body, 0, l, FUNC_FLAVOR_FUNCTION); CreateFunction(l_id->GetType<FuncType>(), pf, lname, body, 0, l, FUNC_FLAVOR_FUNCTION);
} }

View file

@ -79,6 +79,10 @@ void CPPCompile::Compile(bool report_uncompilable) {
} }
} }
for ( auto& l : pfs->Lambdas() )
if ( obj_matches_opt_files(l) )
accessed_lambdas.insert(l);
for ( auto& ea : pfs->ExprAttrs() ) for ( auto& ea : pfs->ExprAttrs() )
if ( obj_matches_opt_files(ea.first) ) { if ( obj_matches_opt_files(ea.first) ) {
auto& attr = ea.first; auto& attr = ea.first;

View file

@ -177,7 +177,11 @@ FuncValPtr lookup_func__CPP(string name, int num_bodies, vector<p_hash_type> has
for ( auto h : hashes ) { for ( auto h : hashes ) {
auto cs = compiled_scripts.find(h); auto cs = compiled_scripts.find(h);
ASSERT(cs != compiled_scripts.end());
if ( cs == compiled_scripts.end() ) {
cs = compiled_standalone_scripts.find(h);
ASSERT(cs != compiled_standalone_scripts.end());
}
const auto& f = cs->second; const auto& f = cs->second;
bodies.emplace_back(f.body); bodies.emplace_back(f.body);

View file

@ -21,15 +21,14 @@ The maintenance workflow:
rm CPP-gen.cc rm CPP-gen.cc
ninja ninja
src/zeek -b -O gen-standalone-C++ \ src/zeek -O gen-standalone-C++ \
--optimize-files=base/protocols/conn \ --optimize-files=policy \
--optimize-files=base/utils/files \ policy/misc/loaded-scripts.zeek >my-test.zeek
--optimize-files=base/utils/addr \ rm -f loaded_scripts.log
base/protocols/conn >my-test.zeek
ninja ninja
src/zeek -b -r some.pcap my-test.zeek src/zeek my-test.zeek
# Confirm that it generates conn.log # Confirm that it generates loaded_scripts.log
rm CPP-gen.cc rm CPP-gen.cc loaded_scripts.log
ninja ninja
Do this first because if it can't, you'll be making changes to the Do this first because if it can't, you'll be making changes to the