mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
script optimization fixes for pattern tables
This commit is contained in:
parent
709d410fcd
commit
f573036099
4 changed files with 58 additions and 25 deletions
|
@ -318,20 +318,25 @@ string CPPCompile::GenInExpr(const Expr* e, GenType gt) {
|
||||||
auto t1 = op1->GetType();
|
auto t1 = op1->GetType();
|
||||||
auto t2 = op2->GetType();
|
auto t2 = op2->GetType();
|
||||||
|
|
||||||
|
auto tag1 = t1->Tag();
|
||||||
|
auto tag2 = t2->Tag();
|
||||||
|
|
||||||
string gen;
|
string gen;
|
||||||
|
|
||||||
if ( t1->Tag() == TYPE_PATTERN )
|
if ( tag1 == TYPE_STRING && tag2 == TYPE_TABLE && t2->AsTableType()->IsPatternIndex() )
|
||||||
|
gen = GenExpr(op2, GEN_DONT_CARE) + "->MatchPattern(" + GenExpr(op1, GEN_NATIVE) + ")";
|
||||||
|
else if ( tag1 == TYPE_PATTERN )
|
||||||
gen = string("(") + GenExpr(op1, GEN_DONT_CARE) + ")->MatchAnywhere(" + GenExpr(op2, GEN_DONT_CARE) +
|
gen = string("(") + GenExpr(op1, GEN_DONT_CARE) + ")->MatchAnywhere(" + GenExpr(op2, GEN_DONT_CARE) +
|
||||||
"->AsString())";
|
"->AsString())";
|
||||||
|
|
||||||
else if ( t2->Tag() == TYPE_STRING )
|
else if ( tag2 == TYPE_STRING )
|
||||||
gen = string("str_in__CPP(") + GenExpr(op1, GEN_DONT_CARE) + "->AsString(), " + GenExpr(op2, GEN_DONT_CARE) +
|
gen = string("str_in__CPP(") + GenExpr(op1, GEN_DONT_CARE) + "->AsString(), " + GenExpr(op2, GEN_DONT_CARE) +
|
||||||
"->AsString())";
|
"->AsString())";
|
||||||
|
|
||||||
else if ( t1->Tag() == TYPE_ADDR && t2->Tag() == TYPE_SUBNET )
|
else if ( tag1 == TYPE_ADDR && tag2 == TYPE_SUBNET )
|
||||||
gen = string("(") + GenExpr(op2, GEN_DONT_CARE) + ")->Contains(" + GenExpr(op1, GEN_VAL_PTR) + "->Get())";
|
gen = string("(") + GenExpr(op2, GEN_DONT_CARE) + ")->Contains(" + GenExpr(op1, GEN_VAL_PTR) + "->Get())";
|
||||||
|
|
||||||
else if ( t2->Tag() == TYPE_VECTOR )
|
else if ( tag2 == TYPE_VECTOR )
|
||||||
gen = GenExpr(op2, GEN_DONT_CARE) + "->Has(" + GenExpr(op1, GEN_NATIVE) + ")";
|
gen = GenExpr(op2, GEN_DONT_CARE) + "->Has(" + GenExpr(op1, GEN_NATIVE) + ")";
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
|
@ -332,6 +332,8 @@ ExprPtr Inliner::CheckForInlining(CallExprPtr c) {
|
||||||
auto scope = func_vf->GetScope();
|
auto scope = func_vf->GetScope();
|
||||||
auto ie = DoInline(func_vf, body, c->ArgsPtr(), scope, ia->second);
|
auto ie = DoInline(func_vf, body, c->ArgsPtr(), scope, ia->second);
|
||||||
|
|
||||||
|
printf("inlined %s\n", obj_desc(c.get()).c_str());
|
||||||
|
|
||||||
if ( ie ) {
|
if ( ie ) {
|
||||||
ie->SetOriginal(c);
|
ie->SetOriginal(c);
|
||||||
did_inline.insert(func_vf.get());
|
did_inline.insert(func_vf.get());
|
||||||
|
|
|
@ -418,7 +418,16 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const NameExpr* n2,
|
||||||
|
|
||||||
ZOp a;
|
ZOp a;
|
||||||
|
|
||||||
if ( op2->GetType()->Tag() == TYPE_PATTERN )
|
auto& op2_t = op2->GetType();
|
||||||
|
auto& op3_t = op3->GetType();
|
||||||
|
|
||||||
|
if ( op3_t->Tag() == TYPE_TABLE ) {
|
||||||
|
if ( op3_t->AsTableType()->IsPatternIndex() && op2_t->Tag() == TYPE_STRING )
|
||||||
|
a = n2 ? OP_STR_IN_PAT_TBL_VVV : OP_STR_IN_PAT_TBL_VCV;
|
||||||
|
else
|
||||||
|
a = n2 ? OP_VAL_IS_IN_TABLE_VVV : OP_CONST_IS_IN_TABLE_VCV;
|
||||||
|
}
|
||||||
|
else if ( op2->GetType()->Tag() == TYPE_PATTERN )
|
||||||
a = n2 ? (n3 ? OP_P_IN_S_VVV : OP_P_IN_S_VVC) : OP_P_IN_S_VCV;
|
a = n2 ? (n3 ? OP_P_IN_S_VVV : OP_P_IN_S_VVC) : OP_P_IN_S_VCV;
|
||||||
|
|
||||||
else if ( op2->GetType()->Tag() == TYPE_STRING )
|
else if ( op2->GetType()->Tag() == TYPE_STRING )
|
||||||
|
@ -427,9 +436,6 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const NameExpr* n2,
|
||||||
else if ( op2->GetType()->Tag() == TYPE_ADDR && op3->GetType()->Tag() == TYPE_SUBNET )
|
else if ( op2->GetType()->Tag() == TYPE_ADDR && op3->GetType()->Tag() == TYPE_SUBNET )
|
||||||
a = n2 ? (n3 ? OP_A_IN_S_VVV : OP_A_IN_S_VVC) : OP_A_IN_S_VCV;
|
a = n2 ? (n3 ? OP_A_IN_S_VVV : OP_A_IN_S_VVC) : OP_A_IN_S_VCV;
|
||||||
|
|
||||||
else if ( op3->GetType()->Tag() == TYPE_TABLE )
|
|
||||||
a = n2 ? OP_VAL_IS_IN_TABLE_VVV : OP_CONST_IS_IN_TABLE_VCV;
|
|
||||||
|
|
||||||
else
|
else
|
||||||
reporter->InternalError("bad types when compiling \"in\"");
|
reporter->InternalError("bad types when compiling \"in\"");
|
||||||
|
|
||||||
|
@ -650,19 +656,25 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot, const T
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( n2tag == TYPE_TABLE ) {
|
if ( n2tag == TYPE_TABLE ) {
|
||||||
if ( n3 ) {
|
if ( is_pat_str_ind ) {
|
||||||
|
auto n1_slot = Frame1Slot(n1, OP1_WRITE);
|
||||||
|
if ( n3 ) {
|
||||||
|
int n3_slot = FrameSlot(n3);
|
||||||
|
z = ZInstI(OP_TABLE_PATSTR_INDEX_VVV, n1_slot, n2_slot, n3_slot);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
z = ZInstI(OP_TABLE_PATSTR_INDEX_VVC, n1_slot, n2_slot, c3);
|
||||||
|
}
|
||||||
|
else if ( n3 ) {
|
||||||
int n3_slot = FrameSlot(n3);
|
int n3_slot = FrameSlot(n3);
|
||||||
auto op = is_pat_str_ind ? OP_TABLE_PATSTR_INDEX1_VVV : OP_TABLE_INDEX1_VVV;
|
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVV, n1->GetType()->Tag());
|
||||||
auto zop = AssignmentFlavor(op, n1->GetType()->Tag());
|
|
||||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, n3_slot);
|
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, n3_slot);
|
||||||
z.SetType(n3->GetType());
|
z.SetType(n3->GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
ASSERT(c3);
|
ASSERT(c3);
|
||||||
|
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC, n1->GetType()->Tag());
|
||||||
auto op = is_pat_str_ind ? OP_TABLE_PATSTR_INDEX1_VVC : OP_TABLE_INDEX1_VVC;
|
|
||||||
auto zop = AssignmentFlavor(op, n1->GetType()->Tag());
|
|
||||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, c3);
|
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, c3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -696,6 +696,17 @@ internal-op P-In-S
|
||||||
type VVC
|
type VVC
|
||||||
eval EvalPInS(frame[z.v2], z.c)
|
eval EvalPInS(frame[z.v2], z.c)
|
||||||
|
|
||||||
|
macro EvalStrInPatTbl(op1, op2)
|
||||||
|
frame[z.v1].int_val = op2.table_val->MatchPattern({NewRef{}, op1.string_val});
|
||||||
|
|
||||||
|
internal-op Str-In-Pat-Tbl
|
||||||
|
type VVV
|
||||||
|
eval EvalStrInPatTbl(frame[z.v2], frame[z.v3])
|
||||||
|
|
||||||
|
internal-op Str-In-Pat-Tbl
|
||||||
|
type VCV
|
||||||
|
eval EvalStrInPatTbl(z.c, frame[z.v2])
|
||||||
|
|
||||||
internal-binary-op S-In-S
|
internal-binary-op S-In-S
|
||||||
op-accessor string_val
|
op-accessor string_val
|
||||||
op-type I
|
op-type I
|
||||||
|
@ -1045,6 +1056,20 @@ type VV
|
||||||
eval EvalTableIndex(z.aux->ToListVal(frame))
|
eval EvalTableIndex(z.aux->ToListVal(frame))
|
||||||
AssignV1(BuildVal(v, z.t))
|
AssignV1(BuildVal(v, z.t))
|
||||||
|
|
||||||
|
macro EvalTablePatStr(index)
|
||||||
|
auto& lhs = frame[z.v1];
|
||||||
|
auto vec = ZVal(frame[z.v2].table_val->LookupPattern({NewRef{}, index.string_val}));
|
||||||
|
ZVal::DeleteManagedType(lhs);
|
||||||
|
lhs = vec;
|
||||||
|
|
||||||
|
internal-op Table-PatStr-Index
|
||||||
|
type VVV
|
||||||
|
eval EvalTablePatStr(frame[z.v3])
|
||||||
|
|
||||||
|
internal-op Table-PatStr-Index
|
||||||
|
type VVC
|
||||||
|
eval EvalTablePatStr(z.c)
|
||||||
|
|
||||||
internal-op When-Table-Index
|
internal-op When-Table-Index
|
||||||
type VV
|
type VV
|
||||||
eval EvalTableIndex(z.aux->ToListVal(frame))
|
eval EvalTableIndex(z.aux->ToListVal(frame))
|
||||||
|
@ -1080,17 +1105,6 @@ type VVC
|
||||||
assign-val v
|
assign-val v
|
||||||
eval EvalTableIndex(z.c.ToVal(z.t))
|
eval EvalTableIndex(z.c.ToVal(z.t))
|
||||||
|
|
||||||
# Same, but for indexing table[pattern] of X with a string.
|
|
||||||
internal-assignment-op Table-PatStr-Index1
|
|
||||||
type VVV
|
|
||||||
assign-val v
|
|
||||||
eval auto v = frame[z.v2].table_val->LookupPattern({NewRef{}, frame[z.v3].AsString()});
|
|
||||||
|
|
||||||
internal-assignment-op Table-PatStr-Index1
|
|
||||||
type VVC
|
|
||||||
assign-val v
|
|
||||||
eval auto v = frame[z.v2].table_val->LookupPattern({NewRef{}, z.c.AsString()});
|
|
||||||
|
|
||||||
# This version is for a variable v3.
|
# This version is for a variable v3.
|
||||||
internal-op Index-String
|
internal-op Index-String
|
||||||
type VVV
|
type VVV
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue