mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge remote-tracking branch 'origin/topic/vern/global-stmts'
* origin/topic/vern/global-stmts: whitespace adjustment "balance" tests with multiple Zeek scripts to load the same elements put global statements into a quasi-function to support script optimization
This commit is contained in:
commit
c033bd20aa
8 changed files with 42 additions and 5 deletions
6
CHANGES
6
CHANGES
|
@ -1,4 +1,10 @@
|
|||
|
||||
4.1.0-dev.438 | 2021-03-29 15:42:25 -0700
|
||||
|
||||
* "balance" tests with multiple Zeek scripts to load the same elements (Vern Paxson, Corelight)
|
||||
|
||||
* put global statements into a quasi-function to support script optimization (Vern Paxson, Corelight)
|
||||
|
||||
4.1.0-dev.434 | 2021-03-29 13:18:18 -0700
|
||||
|
||||
* Fix sign-compare compiler warning in coerce_to_record() (Jon Siwek, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
4.1.0-dev.434
|
||||
4.1.0-dev.438
|
||||
|
|
|
@ -266,7 +266,7 @@ static bool expr_is_table_type_name(const zeek::detail::Expr* expr)
|
|||
|
||||
%%
|
||||
|
||||
bro:
|
||||
zeek:
|
||||
decl_list stmt_list
|
||||
{
|
||||
if ( zeek::detail::stmts )
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "zeek/Options.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/module_util.h"
|
||||
#include "zeek/script_opt/ScriptOpt.h"
|
||||
#include "zeek/script_opt/ProfileFunc.h"
|
||||
#include "zeek/script_opt/Inline.h"
|
||||
|
@ -153,6 +154,27 @@ void analyze_func(ScriptFuncPtr f)
|
|||
funcs.emplace_back(f, ScopePtr{NewRef{}, f->GetScope()}, f->CurrentBody());
|
||||
}
|
||||
|
||||
const FuncInfo* analyze_global_stmts(Stmt* stmts)
|
||||
{
|
||||
// We ignore analysis_options.only_func - if it's in use, later
|
||||
// logic will keep this function from being compiled, but it's handy
|
||||
// now to enter it into "funcs" so we have a FuncInfo to return.
|
||||
|
||||
auto id = install_ID("<global-stmts>", GLOBAL_MODULE_NAME, true, false);
|
||||
auto empty_args_t = make_intrusive<RecordType>(nullptr);
|
||||
auto func_t = make_intrusive<FuncType>(empty_args_t, nullptr, FUNC_FLAVOR_FUNCTION);
|
||||
id->SetType(func_t);
|
||||
|
||||
auto sc = current_scope();
|
||||
std::vector<IDPtr> empty_inits;
|
||||
StmtPtr stmts_p{NewRef{}, stmts};
|
||||
auto sf = make_intrusive<ScriptFunc>(id, stmts_p, empty_inits, sc->Length(), 0);
|
||||
|
||||
funcs.emplace_back(sf, ScopePtr{NewRef{}, sc}, stmts_p);
|
||||
|
||||
return &funcs.back();
|
||||
}
|
||||
|
||||
static void check_env_opt(const char* opt, bool& opt_flag)
|
||||
{
|
||||
if ( getenv(opt) )
|
||||
|
|
|
@ -96,6 +96,11 @@ extern std::unordered_set<const Func*> non_recursive_funcs;
|
|||
// Analyze a given function for optimization.
|
||||
extern void analyze_func(ScriptFuncPtr f);
|
||||
|
||||
// Analyze the given top-level statement(s) for optimization. Returns
|
||||
// a pointer to a FuncInfo for an argument-less quasi-function that can
|
||||
// be Invoked, or its body executed directly, to execute the statements.
|
||||
extern const FuncInfo* analyze_global_stmts(Stmt* stmts);
|
||||
|
||||
// Analyze all of the parsed scripts collectively for optimization.
|
||||
extern void analyze_scripts();
|
||||
|
||||
|
|
|
@ -752,6 +752,8 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
}
|
||||
}
|
||||
|
||||
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr;
|
||||
|
||||
analyze_scripts();
|
||||
|
||||
if ( analysis_options.report_recursive )
|
||||
|
@ -838,15 +840,15 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
// cause more severe problems.
|
||||
ZEEK_LSAN_ENABLE();
|
||||
|
||||
if ( stmts )
|
||||
if ( init_stmts )
|
||||
{
|
||||
StmtFlowType flow;
|
||||
Frame f(current_scope()->Length(), nullptr, nullptr);
|
||||
Frame f(init_stmts->Scope()->Length(), nullptr, nullptr);
|
||||
g_frame_stack.push_back(&f);
|
||||
|
||||
try
|
||||
{
|
||||
stmts->Exec(&f, flow);
|
||||
init_stmts->Body()->Exec(&f, flow);
|
||||
}
|
||||
catch ( InterpreterException& )
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
@TEST-START-FILE send.zeek
|
||||
|
||||
@load base/frameworks/netcontrol
|
||||
@load base/frameworks/broker
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
global have_peer = F;
|
||||
|
|
|
@ -82,6 +82,7 @@ event OpenFlow::flow_mod_failure(name: string, match: OpenFlow::ofp_match, flow_
|
|||
|
||||
@TEST-START-FILE recv.zeek
|
||||
|
||||
@load base/protocols/conn
|
||||
@load base/frameworks/openflow
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue