replace --optimize-only with --optimize-funcs and --optimize-files

This commit is contained in:
Vern Paxson 2021-12-10 12:45:27 -08:00
parent aa91f72b34
commit 9069e744f9
8 changed files with 176 additions and 125 deletions

View file

@ -6,6 +6,8 @@
#include "zeek/script_opt/CPP/Compile.h"
extern std::unordered_set<std::string> files_with_conditionals;
namespace zeek::detail
{
@ -72,29 +74,48 @@ void CPPCompile::Compile(bool report_uncompilable)
GenProlog();
unordered_set<string> filenames_reported_as_skipped;
// Determine which functions we can call directly, and reuse
// previously compiled instances of those if present.
for ( const auto& func : funcs )
for ( auto& func : funcs )
{
const auto& f = func.Func();
auto& ofiles = analysis_options.only_files;
string fn = func.Body()->GetLocationInfo()->filename;
if ( ! func.ShouldSkip() && ! ofiles.empty() && files_with_conditionals.count(fn) > 0 )
{
if ( filenames_reported_as_skipped.count(fn) == 0 )
{
reporter->Warning(
"skipping compilation of files in %s due to presence of conditional code",
fn.c_str());
filenames_reported_as_skipped.insert(fn);
}
func.SetSkip(true);
}
if ( func.ShouldSkip() )
{
not_fully_compilable.insert(func.Func()->Name());
not_fully_compilable.insert(f->Name());
continue;
}
if ( func.Func()->Flavor() != FUNC_FLAVOR_FUNCTION )
// Can't be called directly.
continue;
const char* reason;
if ( IsCompilable(func, &reason) )
compilable_funcs.insert(BodyName(func));
{
if ( f->Flavor() == FUNC_FLAVOR_FUNCTION )
// Note this as a callable compiled function.
compilable_funcs.insert(BodyName(func));
}
else
{
if ( reason && report_uncompilable )
fprintf(stderr, "%s cannot be compiled to C++ due to %s\n", func.Func()->Name(),
reason);
not_fully_compilable.insert(func.Func()->Name());
fprintf(stderr, "%s cannot be compiled to C++ due to %s\n", f->Name(), reason);
not_fully_compilable.insert(f->Name());
}
}
@ -105,7 +126,6 @@ void CPPCompile::Compile(bool report_uncompilable)
types.AddKey(tp, pfs.HashType(t));
}
// ### This doesn't work for -O add-C++
Emit("TypePtr types__CPP[%s];", Fmt(static_cast<int>(types.DistinctKeys().size())));
NL();