mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
a number of low-level tweaks from code review
This commit is contained in:
parent
c10737d168
commit
b6daf14868
12 changed files with 79 additions and 80 deletions
|
@ -15,7 +15,7 @@ using namespace std;
|
||||||
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
|
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
|
||||||
const string& gen_name, const string& _addl_name,
|
const string& gen_name, const string& _addl_name,
|
||||||
CPPHashManager& _hm, bool _update, bool _standalone,
|
CPPHashManager& _hm, bool _update, bool _standalone,
|
||||||
bool report_uncompilable)
|
bool report_uncompilable)
|
||||||
: funcs(_funcs), pfs(_pfs), hm(_hm),
|
: funcs(_funcs), pfs(_pfs), hm(_hm),
|
||||||
update(_update), standalone(_standalone)
|
update(_update), standalone(_standalone)
|
||||||
{
|
{
|
||||||
|
|
|
@ -280,10 +280,7 @@ void CPPCompile::AddInit(const Obj* o, const string& init)
|
||||||
void CPPCompile::AddInit(const Obj* o)
|
void CPPCompile::AddInit(const Obj* o)
|
||||||
{
|
{
|
||||||
if ( obj_inits.count(o) == 0 )
|
if ( obj_inits.count(o) == 0 )
|
||||||
{
|
obj_inits[o] = {};
|
||||||
vector<string> empty;
|
|
||||||
obj_inits[o] = empty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPCompile::NoteInitDependency(const Obj* o1, const Obj* o2)
|
void CPPCompile::NoteInitDependency(const Obj* o1, const Obj* o2)
|
||||||
|
|
|
@ -27,9 +27,7 @@ void GenIDDefs::TraverseFunction(const Func* f, ScopePtr scope, StmtPtr body)
|
||||||
// Establish the outermost barrior and associated set of
|
// Establish the outermost barrior and associated set of
|
||||||
// identifiers.
|
// identifiers.
|
||||||
barrier_blocks.push_back(0);
|
barrier_blocks.push_back(0);
|
||||||
|
modified_IDs.push_back({});
|
||||||
std::unordered_set<const ID*> empty_IDs;
|
|
||||||
modified_IDs.push_back(empty_IDs);
|
|
||||||
|
|
||||||
for ( const auto& g : pf->Globals() )
|
for ( const auto& g : pf->Globals() )
|
||||||
{
|
{
|
||||||
|
@ -442,9 +440,7 @@ void GenIDDefs::StartConfluenceBlock(const Stmt* s)
|
||||||
barrier_blocks.push_back(confluence_blocks.size());
|
barrier_blocks.push_back(confluence_blocks.size());
|
||||||
|
|
||||||
confluence_blocks.push_back(s);
|
confluence_blocks.push_back(s);
|
||||||
|
modified_IDs.push_back({});
|
||||||
std::unordered_set<const ID*> empty_IDs;
|
|
||||||
modified_IDs.push_back(empty_IDs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenIDDefs::EndConfluenceBlock(bool no_orig)
|
void GenIDDefs::EndConfluenceBlock(bool no_orig)
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace zeek::detail {
|
||||||
|
|
||||||
|
|
||||||
RD_Decorate::RD_Decorate(std::shared_ptr<ProfileFunc> _pf, const Func* f,
|
RD_Decorate::RD_Decorate(std::shared_ptr<ProfileFunc> _pf, const Func* f,
|
||||||
ScopePtr scope, StmtPtr body)
|
ScopePtr scope, StmtPtr body)
|
||||||
: pf(std::move(_pf))
|
: pf(std::move(_pf))
|
||||||
{
|
{
|
||||||
TraverseFunction(f, scope, body);
|
TraverseFunction(f, scope, body);
|
||||||
|
|
|
@ -257,8 +257,7 @@ void IDOptInfo::StartConfluenceBlock(const Stmt* s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfluenceSet empty_set;
|
pending_confluences[s] = {};
|
||||||
pending_confluences[s] = empty_set;
|
|
||||||
confluence_stmts.push_back(s);
|
confluence_stmts.push_back(s);
|
||||||
block_has_orig_flow.push_back(s_oi->contains_branch_beyond);
|
block_has_orig_flow.push_back(s_oi->contains_branch_beyond);
|
||||||
|
|
||||||
|
|
|
@ -281,7 +281,7 @@ protected:
|
||||||
// profile is compilable. Alternatively we could derive subclasses
|
// profile is compilable. Alternatively we could derive subclasses
|
||||||
// from ProfileFuncs and use a virtual method for this, but that seems
|
// from ProfileFuncs and use a virtual method for this, but that seems
|
||||||
// heavier-weight for what's really a simple notion.
|
// heavier-weight for what's really a simple notion.
|
||||||
typedef bool (*is_compilable_pred)(const ProfileFunc*, const char** reason);
|
using is_compilable_pred = bool (*)(const ProfileFunc*, const char** reason);
|
||||||
|
|
||||||
// Collectively profile an entire collection of functions.
|
// Collectively profile an entire collection of functions.
|
||||||
class ProfileFuncs {
|
class ProfileFuncs {
|
||||||
|
|
|
@ -11,8 +11,7 @@ namespace zeek::detail {
|
||||||
|
|
||||||
void ZAMCompiler::PushGoTos(GoToSets& gotos)
|
void ZAMCompiler::PushGoTos(GoToSets& gotos)
|
||||||
{
|
{
|
||||||
std::vector<ZAMStmt> vi;
|
gotos.push_back({});
|
||||||
gotos.push_back(vi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l)
|
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l)
|
||||||
|
|
|
@ -79,7 +79,7 @@ void ZAMCompiler::InitArgs()
|
||||||
|
|
||||||
push_existing_scope(scope);
|
push_existing_scope(scope);
|
||||||
|
|
||||||
for ( auto a : args )
|
for ( auto& a : args )
|
||||||
{
|
{
|
||||||
if ( --nparam < 0 )
|
if ( --nparam < 0 )
|
||||||
break;
|
break;
|
||||||
|
@ -369,7 +369,7 @@ void ZAMCompiler::ConcretizeSwitchTables(const CaseMapsI<T>& abstract_cases,
|
||||||
CaseMap<T> cm;
|
CaseMap<T> cm;
|
||||||
for ( auto& targ : targs )
|
for ( auto& targ : targs )
|
||||||
cm[targ.first] = targ.second->inst_num;
|
cm[targ.first] = targ.second->inst_num;
|
||||||
concrete_cases.push_back(cm);
|
concrete_cases.emplace_back(cm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ ArgsManager::ArgsManager(const vector<ZAM_OperandType>& ot, ZAM_InstClass zc)
|
||||||
int n = 0;
|
int n = 0;
|
||||||
bool add_field = false;
|
bool add_field = false;
|
||||||
|
|
||||||
for ( auto ot_i : ot )
|
for ( const auto& ot_i : ot )
|
||||||
{
|
{
|
||||||
if ( ot_i == ZAM_OT_NONE )
|
if ( ot_i == ZAM_OT_NONE )
|
||||||
{ // it had better be the only operand type
|
{ // it had better be the only operand type
|
||||||
|
@ -421,11 +421,10 @@ int ZAM_OpTemplate::ExtractTypeParam(const string& arg)
|
||||||
if ( arg == "$$" )
|
if ( arg == "$$" )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
auto param_str = arg.c_str();
|
if ( arg[0] != '$' )
|
||||||
if ( *param_str != '$' )
|
|
||||||
g->Gripe("bad set-type parameter, should be $n", arg);
|
g->Gripe("bad set-type parameter, should be $n", arg);
|
||||||
|
|
||||||
int param = atoi(¶m_str[1]);
|
int param = atoi(&arg[1]);
|
||||||
|
|
||||||
if ( param <= 0 || param > 2 )
|
if ( param <= 0 || param > 2 )
|
||||||
g->Gripe("bad set-type parameter, should be $1 or $2", arg);
|
g->Gripe("bad set-type parameter, should be $1 or $2", arg);
|
||||||
|
@ -571,10 +570,7 @@ void ZAM_OpTemplate::InstantiateMethodCore(const vector<ZAM_OperandType>& ot,
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgsManager args(ot, zc);
|
ArgsManager args(ot, zc);
|
||||||
|
BuildInstruction(ot, args.Params(), full_suffix, zc);
|
||||||
auto params = args.Params();
|
|
||||||
|
|
||||||
BuildInstruction(ot, params, full_suffix, zc);
|
|
||||||
|
|
||||||
auto tp = GetTypeParam();
|
auto tp = GetTypeParam();
|
||||||
if ( tp > 0 )
|
if ( tp > 0 )
|
||||||
|
|
|
@ -316,7 +316,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
||||||
if ( do_profile )
|
if ( do_profile )
|
||||||
{
|
{
|
||||||
double dt = curr_CPU_time() - profile_CPU;
|
double dt = curr_CPU_time() - profile_CPU;
|
||||||
(*inst_CPU)[profile_pc] += dt;
|
inst_CPU->at(profile_pc) += dt;
|
||||||
ZOP_CPU[z.op] += dt;
|
ZOP_CPU[z.op] += dt;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -137,64 +137,76 @@ void ZInst::Dump(const string& id1, const string& id2, const string& id3,
|
||||||
int ZInst::NumFrameSlots() const
|
int ZInst::NumFrameSlots() const
|
||||||
{
|
{
|
||||||
switch ( op_type ) {
|
switch ( op_type ) {
|
||||||
case OP_X: return 0;
|
case OP_X:
|
||||||
case OP_V: return 1;
|
case OP_C:
|
||||||
case OP_VV: return 2;
|
case OP_V_I1:
|
||||||
case OP_VVV: return 3;
|
case OP_VC_I1:
|
||||||
case OP_VVVV: return 4;
|
case OP_VV_I1_I2:
|
||||||
case OP_VVVC: return 3;
|
case OP_VVVC_I1_I2_I3:
|
||||||
case OP_C: return 0;
|
return 0;
|
||||||
case OP_VC: return 1;
|
|
||||||
case OP_VVC: return 2;
|
|
||||||
|
|
||||||
case OP_V_I1: return 0;
|
case OP_V:
|
||||||
case OP_VC_I1: return 0;
|
case OP_VC:
|
||||||
case OP_VV_I1_I2: return 0;
|
case OP_VV_FRAME:
|
||||||
case OP_VV_FRAME: return 1;
|
case OP_VV_I2:
|
||||||
case OP_VV_I2: return 1;
|
case OP_VVC_I2:
|
||||||
case OP_VVC_I2: return 1;
|
case OP_VVV_I2_I3:
|
||||||
case OP_VVV_I3: return 2;
|
case OP_VVVC_I2_I3:
|
||||||
case OP_VVV_I2_I3: return 1;
|
case OP_VVVV_I2_I3_I4:
|
||||||
|
return 1;
|
||||||
|
|
||||||
case OP_VVVV_I4: return 3;
|
case OP_VV:
|
||||||
case OP_VVVV_I3_I4: return 2;
|
case OP_VVC:
|
||||||
case OP_VVVV_I2_I3_I4: return 1;
|
case OP_VVV_I3:
|
||||||
case OP_VVVC_I3: return 2;
|
case OP_VVVC_I3:
|
||||||
case OP_VVVC_I2_I3: return 1;
|
case OP_VVVV_I3_I4:
|
||||||
case OP_VVVC_I1_I2_I3: return 0;
|
return 2;
|
||||||
|
|
||||||
|
case OP_VVV:
|
||||||
|
case OP_VVVC:
|
||||||
|
case OP_VVVV_I4:
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
case OP_VVVV:
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZInst::NumSlots() const
|
int ZInst::NumSlots() const
|
||||||
{
|
{
|
||||||
switch ( op_type ) {
|
switch ( op_type ) {
|
||||||
case OP_X: return 0;
|
case OP_C:
|
||||||
case OP_C: return 0;
|
case OP_X:
|
||||||
case OP_V: return 1;
|
return 0;
|
||||||
case OP_VC: return 1;
|
|
||||||
case OP_VV: return 2;
|
|
||||||
case OP_VVC: return 2;
|
|
||||||
case OP_VVV: return 3;
|
|
||||||
case OP_VVVC: return 3;
|
|
||||||
case OP_VVVV: return 4;
|
|
||||||
|
|
||||||
case OP_V_I1: return 1;
|
case OP_V:
|
||||||
case OP_VC_I1: return 1;
|
case OP_V_I1:
|
||||||
|
case OP_VC:
|
||||||
|
case OP_VC_I1:
|
||||||
|
return 1;
|
||||||
|
|
||||||
case OP_VV_I1_I2: return 2;
|
case OP_VV:
|
||||||
case OP_VV_FRAME: return 2;
|
case OP_VVC:
|
||||||
case OP_VV_I2: return 2;
|
case OP_VV_FRAME:
|
||||||
case OP_VVC_I2: return 2;
|
case OP_VV_I2:
|
||||||
|
case OP_VVC_I2:
|
||||||
|
case OP_VV_I1_I2:
|
||||||
|
return 2;
|
||||||
|
|
||||||
case OP_VVV_I3: return 3;
|
case OP_VVV:
|
||||||
case OP_VVV_I2_I3: return 3;
|
case OP_VVV_I3:
|
||||||
case OP_VVVC_I3: return 3;
|
case OP_VVV_I2_I3:
|
||||||
case OP_VVVC_I2_I3: return 3;
|
case OP_VVVC:
|
||||||
case OP_VVVC_I1_I2_I3: return 3;
|
case OP_VVVC_I3:
|
||||||
|
case OP_VVVC_I2_I3:
|
||||||
|
case OP_VVVC_I1_I2_I3:
|
||||||
|
return 3;
|
||||||
|
|
||||||
case OP_VVVV_I4: return 4;
|
case OP_VVVV:
|
||||||
case OP_VVVV_I3_I4: return 4;
|
case OP_VVVV_I4:
|
||||||
case OP_VVVV_I2_I3_I4: return 4;
|
case OP_VVVV_I3_I4:
|
||||||
|
case OP_VVVV_I2_I3_I4:
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
namespace zeek::detail {
|
namespace zeek::detail {
|
||||||
|
|
||||||
// Opcodes associated with ZAM instructions.
|
// Opcodes associated with ZAM instructions.
|
||||||
typedef enum {
|
enum ZOp {
|
||||||
#include "zeek/ZAM-OpsDefs.h"
|
#include "zeek/ZAM-OpsDefs.h"
|
||||||
OP_NOP,
|
OP_NOP,
|
||||||
} ZOp;
|
};
|
||||||
|
|
||||||
|
|
||||||
// Possible types of instruction operands in terms of which fields they use.
|
// Possible types of instruction operands in terms of which fields they use.
|
||||||
|
@ -22,7 +22,7 @@ typedef enum {
|
||||||
// I1/I2/I3/I4: the instruction's integer value, used directly (not as a slot)
|
// I1/I2/I3/I4: the instruction's integer value, used directly (not as a slot)
|
||||||
// FRAME: a slot in the (intrepreter) Frame object
|
// FRAME: a slot in the (intrepreter) Frame object
|
||||||
// X: no operands
|
// X: no operands
|
||||||
typedef enum {
|
enum ZAMOpType {
|
||||||
OP_X, OP_C, OP_V, OP_V_I1, OP_VC_I1,
|
OP_X, OP_C, OP_V, OP_V_I1, OP_VC_I1,
|
||||||
|
|
||||||
OP_VC,
|
OP_VC,
|
||||||
|
@ -46,15 +46,15 @@ typedef enum {
|
||||||
OP_VVVV_I3_I4,
|
OP_VVVV_I3_I4,
|
||||||
OP_VVVV_I2_I3_I4,
|
OP_VVVV_I2_I3_I4,
|
||||||
|
|
||||||
} ZAMOpType;
|
};
|
||||||
|
|
||||||
// Possible "flavors" for an operator's first slot.
|
// Possible "flavors" for an operator's first slot.
|
||||||
typedef enum {
|
enum ZAMOp1Flavor {
|
||||||
OP1_READ, // the slot is read, not modified
|
OP1_READ, // the slot is read, not modified
|
||||||
OP1_WRITE, // the slot is modified, not read - the most common
|
OP1_WRITE, // the slot is modified, not read - the most common
|
||||||
OP1_READ_WRITE, // the slot is both read and then modified, e.g. "++"
|
OP1_READ_WRITE, // the slot is both read and then modified, e.g. "++"
|
||||||
OP1_INTERNAL, // we're doing some internal manipulation of the slot
|
OP1_INTERNAL, // we're doing some internal manipulation of the slot
|
||||||
} ZAMOp1Flavor;
|
};
|
||||||
|
|
||||||
// Maps an operand to its flavor.
|
// Maps an operand to its flavor.
|
||||||
extern ZAMOp1Flavor op1_flavor[];
|
extern ZAMOp1Flavor op1_flavor[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue