mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
switch to ID definition regions; reworked driver functions; more info for reporting uncompilable functions
This commit is contained in:
parent
83a0d89caf
commit
da6ac0b521
15 changed files with 619 additions and 581 deletions
|
@ -135,7 +135,8 @@ class CPPCompile {
|
|||
public:
|
||||
CPPCompile(std::vector<FuncInfo>& _funcs, ProfileFuncs& pfs,
|
||||
const std::string& gen_name, const std::string& addl_name,
|
||||
CPPHashManager& _hm, bool _update, bool _standalone);
|
||||
CPPHashManager& _hm, bool _update, bool _standalone,
|
||||
bool report_uncompilable);
|
||||
~CPPCompile();
|
||||
|
||||
private:
|
||||
|
@ -145,7 +146,7 @@ private:
|
|||
//
|
||||
|
||||
// Main driver, invoked by constructor.
|
||||
void Compile();
|
||||
void Compile(bool report_uncompilable);
|
||||
|
||||
// Generate the beginning of the compiled code: run-time functions,
|
||||
// namespace, auxiliary globals.
|
||||
|
@ -161,8 +162,11 @@ private:
|
|||
void GenEpilog();
|
||||
|
||||
// True if the given function (plus body and profile) is one
|
||||
// that should be compiled.
|
||||
bool IsCompilable(const FuncInfo& func);
|
||||
// that should be compiled. If non-nil, sets reason to the
|
||||
// the reason why, if there's a fundamental problem. If however
|
||||
// the function should be skipped for other reasons, then sets
|
||||
// it to nil.
|
||||
bool IsCompilable(const FuncInfo& func, const char** reason = nullptr);
|
||||
|
||||
// The set of functions/bodies we're compiling.
|
||||
std::vector<FuncInfo>& funcs;
|
||||
|
|
|
@ -14,7 +14,8 @@ using namespace std;
|
|||
|
||||
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
|
||||
const string& gen_name, const string& _addl_name,
|
||||
CPPHashManager& _hm, bool _update, bool _standalone)
|
||||
CPPHashManager& _hm, bool _update, bool _standalone,
|
||||
bool report_uncompilable)
|
||||
: funcs(_funcs), pfs(_pfs), hm(_hm),
|
||||
update(_update), standalone(_standalone)
|
||||
{
|
||||
|
@ -67,7 +68,7 @@ CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
|
|||
fclose(addl_f);
|
||||
}
|
||||
|
||||
Compile();
|
||||
Compile(report_uncompilable);
|
||||
}
|
||||
|
||||
CPPCompile::~CPPCompile()
|
||||
|
@ -75,7 +76,7 @@ CPPCompile::~CPPCompile()
|
|||
fclose(write_file);
|
||||
}
|
||||
|
||||
void CPPCompile::Compile()
|
||||
void CPPCompile::Compile(bool report_uncompilable)
|
||||
{
|
||||
// Get the working directory so we can use it in diagnostic messages
|
||||
// as a way to identify this compilation. Only germane when doing
|
||||
|
@ -100,8 +101,13 @@ void CPPCompile::Compile()
|
|||
// Can't be called directly.
|
||||
continue;
|
||||
|
||||
if ( IsCompilable(func) )
|
||||
const char* reason;
|
||||
if ( IsCompilable(func, &reason) )
|
||||
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);
|
||||
|
||||
auto h = func.Profile()->HashVal();
|
||||
if ( hm.HasHash(h) )
|
||||
|
@ -341,17 +347,24 @@ void CPPCompile::GenEpilog()
|
|||
Emit("} // zeek::detail");
|
||||
}
|
||||
|
||||
bool CPPCompile::IsCompilable(const FuncInfo& func)
|
||||
bool CPPCompile::IsCompilable(const FuncInfo& func, const char** reason)
|
||||
{
|
||||
if ( ! is_CPP_compilable(func.Profile(), reason) )
|
||||
return false;
|
||||
|
||||
if ( reason )
|
||||
// Indicate that there's no fundamental reason it can't be
|
||||
// compiled.
|
||||
*reason = nullptr;
|
||||
|
||||
if ( func.ShouldSkip() )
|
||||
// Caller marked this function as one to skip.
|
||||
return false;
|
||||
|
||||
if ( hm.HasHash(func.Profile()->HashVal()) )
|
||||
// We've already compiled it.
|
||||
return false;
|
||||
|
||||
return is_CPP_compilable(func.Profile());
|
||||
return true;
|
||||
}
|
||||
|
||||
} // zeek::detail
|
||||
|
|
|
@ -33,13 +33,21 @@ string scope_prefix(int scope)
|
|||
return scope_prefix(to_string(scope));
|
||||
}
|
||||
|
||||
bool is_CPP_compilable(const ProfileFunc* pf)
|
||||
bool is_CPP_compilable(const ProfileFunc* pf, const char** reason)
|
||||
{
|
||||
if ( pf->NumWhenStmts() > 0 )
|
||||
{
|
||||
if ( reason )
|
||||
*reason = "use of \"when\"";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( pf->TypeSwitches().size() > 0 )
|
||||
{
|
||||
if ( reason )
|
||||
*reason = "use of type-based \"switch\"";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,11 @@ extern std::string scope_prefix(const std::string& scope);
|
|||
// Same, but for scopes identified with numbers.
|
||||
extern std::string scope_prefix(int scope);
|
||||
|
||||
// True if the given function is compilable to C++.
|
||||
extern bool is_CPP_compilable(const ProfileFunc* pf);
|
||||
// True if the given function is compilable to C++. If it isn't, and
|
||||
// the second argument is non-nil, then on return it points to text
|
||||
// explaining why not.
|
||||
extern bool is_CPP_compilable(const ProfileFunc* pf,
|
||||
const char** reason = nullptr);
|
||||
|
||||
// Helper utilities for file locking, to ensure that hash files
|
||||
// don't receive conflicting writes due to concurrent compilations.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue