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& ids = l->OuterIDs();
for ( auto id : ids )
lambda_names[id] = CaptureName(id);
for ( auto lid : ids ) {
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);
}

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() )
if ( obj_matches_opt_files(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 ) {
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;
bodies.emplace_back(f.body);

View file

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