mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 04:58:21 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
|
@ -2,56 +2,58 @@
|
|||
|
||||
// Methods for traversing Expr AST nodes to generate ZAM code.
|
||||
|
||||
#include "zeek/script_opt/ZAM/Compile.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/script_opt/ZAM/Compile.h"
|
||||
|
||||
namespace zeek::detail {
|
||||
namespace zeek::detail
|
||||
{
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileExpr(const Expr* e)
|
||||
{
|
||||
switch ( e->Tag() ) {
|
||||
case EXPR_INCR:
|
||||
case EXPR_DECR:
|
||||
return CompileIncrExpr(static_cast<const IncrExpr*>(e));
|
||||
|
||||
case EXPR_APPEND_TO:
|
||||
return CompileAppendToExpr(static_cast<const AppendToExpr*>(e));
|
||||
|
||||
case EXPR_ASSIGN:
|
||||
return CompileAssignExpr(static_cast<const AssignExpr*>(e));
|
||||
|
||||
case EXPR_INDEX_ASSIGN:
|
||||
switch ( e->Tag() )
|
||||
{
|
||||
auto iae = static_cast<const IndexAssignExpr*>(e);
|
||||
auto t = iae->GetOp1()->GetType()->Tag();
|
||||
if ( t == TYPE_VECTOR )
|
||||
return AssignVecElems(iae);
|
||||
case EXPR_INCR:
|
||||
case EXPR_DECR:
|
||||
return CompileIncrExpr(static_cast<const IncrExpr*>(e));
|
||||
|
||||
ASSERT(t == TYPE_TABLE);
|
||||
return AssignTableElem(iae);
|
||||
case EXPR_APPEND_TO:
|
||||
return CompileAppendToExpr(static_cast<const AppendToExpr*>(e));
|
||||
|
||||
case EXPR_ASSIGN:
|
||||
return CompileAssignExpr(static_cast<const AssignExpr*>(e));
|
||||
|
||||
case EXPR_INDEX_ASSIGN:
|
||||
{
|
||||
auto iae = static_cast<const IndexAssignExpr*>(e);
|
||||
auto t = iae->GetOp1()->GetType()->Tag();
|
||||
if ( t == TYPE_VECTOR )
|
||||
return AssignVecElems(iae);
|
||||
|
||||
ASSERT(t == TYPE_TABLE);
|
||||
return AssignTableElem(iae);
|
||||
}
|
||||
|
||||
case EXPR_FIELD_LHS_ASSIGN:
|
||||
{
|
||||
auto flhs = static_cast<const FieldLHSAssignExpr*>(e);
|
||||
return CompileFieldLHSAssignExpr(flhs);
|
||||
}
|
||||
|
||||
case EXPR_SCHEDULE:
|
||||
return CompileScheduleExpr(static_cast<const ScheduleExpr*>(e));
|
||||
|
||||
case EXPR_EVENT:
|
||||
{
|
||||
auto ee = static_cast<const EventExpr*>(e);
|
||||
auto h = ee->Handler().Ptr();
|
||||
auto args = ee->Args();
|
||||
return EventHL(h, args);
|
||||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("bad statement type in ZAMCompile::CompileExpr");
|
||||
}
|
||||
|
||||
case EXPR_FIELD_LHS_ASSIGN:
|
||||
{
|
||||
auto flhs = static_cast<const FieldLHSAssignExpr*>(e);
|
||||
return CompileFieldLHSAssignExpr(flhs);
|
||||
}
|
||||
|
||||
case EXPR_SCHEDULE:
|
||||
return CompileScheduleExpr(static_cast<const ScheduleExpr*>(e));
|
||||
|
||||
case EXPR_EVENT:
|
||||
{
|
||||
auto ee = static_cast<const EventExpr*>(e);
|
||||
auto h = ee->Handler().Ptr();
|
||||
auto args = ee->Args();
|
||||
return EventHL(h, args);
|
||||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("bad statement type in ZAMCompile::CompileExpr");
|
||||
}
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileIncrExpr(const IncrExpr* e)
|
||||
|
@ -92,15 +94,14 @@ const ZAMStmt ZAMCompiler::CompileAppendToExpr(const AppendToExpr* e)
|
|||
return n2 ? AppendToVV(n1, n2) : AppendToVC(n1, cc);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::AppendToField(const NameExpr* n1, const NameExpr* n2,
|
||||
const ConstExpr* c, int offset)
|
||||
const ZAMStmt ZAMCompiler::AppendToField(const NameExpr* n1, const NameExpr* n2, const ConstExpr* c,
|
||||
int offset)
|
||||
{
|
||||
ZInstI z;
|
||||
|
||||
if ( n2 )
|
||||
{
|
||||
z = ZInstI(OP_APPENDTOFIELD_VVi, FrameSlot(n1), FrameSlot(n2),
|
||||
offset);
|
||||
z = ZInstI(OP_APPENDTOFIELD_VVi, FrameSlot(n1), FrameSlot(n2), offset);
|
||||
z.op_type = OP_VVV_I3;
|
||||
}
|
||||
else
|
||||
|
@ -125,16 +126,16 @@ const ZAMStmt ZAMCompiler::CompileAssignExpr(const AssignExpr* e)
|
|||
auto rhs = op2.get();
|
||||
auto r1 = rhs->GetOp1();
|
||||
|
||||
if ( rhs->Tag() == EXPR_INDEX &&
|
||||
(r1->Tag() == EXPR_NAME || r1->Tag() == EXPR_CONST) )
|
||||
if ( rhs->Tag() == EXPR_INDEX && (r1->Tag() == EXPR_NAME || r1->Tag() == EXPR_CONST) )
|
||||
return CompileAssignToIndex(lhs, rhs->AsIndexExpr());
|
||||
|
||||
switch ( rhs->Tag() ) {
|
||||
switch ( rhs->Tag() )
|
||||
{
|
||||
#include "ZAM-DirectDefs.h"
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
auto rt = rhs->GetType();
|
||||
|
||||
|
@ -176,13 +177,10 @@ const ZAMStmt ZAMCompiler::CompileAssignExpr(const AssignExpr* e)
|
|||
}
|
||||
|
||||
if ( rhs->Tag() == EXPR_ANY_INDEX )
|
||||
return AnyIndexVVi(lhs, r1->AsNameExpr(),
|
||||
rhs->AsAnyIndexExpr()->Index());
|
||||
return AnyIndexVVi(lhs, r1->AsNameExpr(), rhs->AsAnyIndexExpr()->Index());
|
||||
|
||||
if ( rhs->Tag() == EXPR_COND && r1->GetType()->Tag() == TYPE_VECTOR )
|
||||
return Bool_Vec_CondVVVV(lhs, r1->AsNameExpr(),
|
||||
r2->AsNameExpr(),
|
||||
r3->AsNameExpr());
|
||||
return Bool_Vec_CondVVVV(lhs, r1->AsNameExpr(), r2->AsNameExpr(), r3->AsNameExpr());
|
||||
|
||||
if ( rhs->Tag() == EXPR_COND && r2->IsConst() && r3->IsConst() )
|
||||
{
|
||||
|
@ -191,7 +189,7 @@ const ZAMStmt ZAMCompiler::CompileAssignExpr(const AssignExpr* e)
|
|||
auto n1 = r1->AsNameExpr();
|
||||
auto c2 = r2->AsConstExpr();
|
||||
auto c3 = r3->AsConstExpr();
|
||||
(void) CondC1VVC(lhs, n1, c2);
|
||||
(void)CondC1VVC(lhs, n1, c2);
|
||||
return CondC2VVC(lhs, n1, c3);
|
||||
}
|
||||
|
||||
|
@ -202,7 +200,8 @@ const ZAMStmt ZAMCompiler::CompileAssignExpr(const AssignExpr* e)
|
|||
|
||||
if ( v1 != v2 && rhs->Tag() != EXPR_IN )
|
||||
{
|
||||
reporter->Error("deprecated mixed vector/scalar operation not supported for ZAM compiling");
|
||||
reporter->Error(
|
||||
"deprecated mixed vector/scalar operation not supported for ZAM compiling");
|
||||
return ErrorStmt();
|
||||
}
|
||||
}
|
||||
|
@ -210,18 +209,17 @@ const ZAMStmt ZAMCompiler::CompileAssignExpr(const AssignExpr* e)
|
|||
if ( r1 && r1->IsConst() )
|
||||
#include "ZAM-GenExprsDefsC1.h"
|
||||
|
||||
else if ( r2 && r2->IsConst() )
|
||||
else if ( r2 && r2->IsConst() )
|
||||
#include "ZAM-GenExprsDefsC2.h"
|
||||
|
||||
else if ( r3 && r3->IsConst() )
|
||||
else if ( r3 && r3->IsConst() )
|
||||
#include "ZAM-GenExprsDefsC3.h"
|
||||
|
||||
else
|
||||
else
|
||||
#include "ZAM-GenExprsDefsV.h"
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileAssignToIndex(const NameExpr* lhs,
|
||||
const IndexExpr* rhs)
|
||||
const ZAMStmt ZAMCompiler::CompileAssignToIndex(const NameExpr* lhs, const IndexExpr* rhs)
|
||||
{
|
||||
auto aggr = rhs->GetOp1();
|
||||
auto const_aggr = aggr->Tag() == EXPR_CONST;
|
||||
|
@ -232,8 +230,7 @@ const ZAMStmt ZAMCompiler::CompileAssignToIndex(const NameExpr* lhs,
|
|||
auto n = const_aggr ? nullptr : aggr->AsNameExpr();
|
||||
auto con = const_aggr ? aggr->AsConstExpr() : nullptr;
|
||||
|
||||
if ( indexes.length() == 1 &&
|
||||
indexes[0]->GetType()->Tag() == TYPE_VECTOR )
|
||||
if ( indexes.length() == 1 && indexes[0]->GetType()->Tag() == TYPE_VECTOR )
|
||||
{
|
||||
auto index1 = indexes[0];
|
||||
if ( index1->Tag() == EXPR_CONST )
|
||||
|
@ -246,16 +243,14 @@ const ZAMStmt ZAMCompiler::CompileAssignToIndex(const NameExpr* lhs,
|
|||
auto ind_t = index->GetType()->AsVectorType();
|
||||
|
||||
if ( IsBool(ind_t->Yield()->Tag()) )
|
||||
return const_aggr ?
|
||||
IndexVecBoolSelectVCV(lhs, con, index) :
|
||||
IndexVecBoolSelectVVV(lhs, n, index);
|
||||
return const_aggr ? IndexVecBoolSelectVCV(lhs, con, index)
|
||||
: IndexVecBoolSelectVVV(lhs, n, index);
|
||||
|
||||
return const_aggr ? IndexVecIntSelectVCV(lhs, con, index) :
|
||||
IndexVecIntSelectVVV(lhs, n, index);
|
||||
return const_aggr ? IndexVecIntSelectVCV(lhs, con, index)
|
||||
: IndexVecIntSelectVVV(lhs, n, index);
|
||||
}
|
||||
|
||||
return const_aggr ? IndexVCL(lhs, con, indexes_expr) :
|
||||
IndexVVL(lhs, n, indexes_expr);
|
||||
return const_aggr ? IndexVCL(lhs, con, indexes_expr) : IndexVVL(lhs, n, indexes_expr);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileFieldLHSAssignExpr(const FieldLHSAssignExpr* e)
|
||||
|
@ -277,20 +272,18 @@ const ZAMStmt ZAMCompiler::CompileFieldLHSAssignExpr(const FieldLHSAssignExpr* e
|
|||
{
|
||||
auto rhs_f = rhs->AsFieldExpr();
|
||||
if ( r1->Tag() == EXPR_NAME )
|
||||
return Field_LHS_AssignFVi(e, r1->AsNameExpr(),
|
||||
rhs_f->Field());
|
||||
return Field_LHS_AssignFVi(e, r1->AsNameExpr(), rhs_f->Field());
|
||||
|
||||
return Field_LHS_AssignFCi(e, r1->AsConstExpr(),
|
||||
rhs_f->Field());
|
||||
return Field_LHS_AssignFCi(e, r1->AsConstExpr(), rhs_f->Field());
|
||||
}
|
||||
|
||||
if ( r1 && r1->IsConst() )
|
||||
#include "ZAM-GenFieldsDefsC1.h"
|
||||
|
||||
else if ( r2 && r2->IsConst() )
|
||||
else if ( r2 && r2->IsConst() )
|
||||
#include "ZAM-GenFieldsDefsC2.h"
|
||||
|
||||
else
|
||||
else
|
||||
#include "ZAM-GenFieldsDefsV.h"
|
||||
}
|
||||
|
||||
|
@ -305,15 +298,12 @@ const ZAMStmt ZAMCompiler::CompileScheduleExpr(const ScheduleExpr* e)
|
|||
bool is_interval = when->GetType()->Tag() == TYPE_INTERVAL;
|
||||
|
||||
if ( when->Tag() == EXPR_NAME )
|
||||
return ScheduleViHL(when->AsNameExpr(), is_interval,
|
||||
handler.Ptr(), event_args);
|
||||
return ScheduleViHL(when->AsNameExpr(), is_interval, handler.Ptr(), event_args);
|
||||
else
|
||||
return ScheduleCiHL(when->AsConstExpr(), is_interval,
|
||||
handler.Ptr(), event_args);
|
||||
return ScheduleCiHL(when->AsConstExpr(), is_interval, handler.Ptr(), event_args);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileSchedule(const NameExpr* n,
|
||||
const ConstExpr* c, int is_interval,
|
||||
const ZAMStmt ZAMCompiler::CompileSchedule(const NameExpr* n, const ConstExpr* c, int is_interval,
|
||||
EventHandler* h, const ListExpr* l)
|
||||
{
|
||||
int len = l->Exprs().length();
|
||||
|
@ -321,8 +311,8 @@ const ZAMStmt ZAMCompiler::CompileSchedule(const NameExpr* n,
|
|||
|
||||
if ( len == 0 )
|
||||
{
|
||||
z = n ? ZInstI(OP_SCHEDULE0_ViH, FrameSlot(n), is_interval) :
|
||||
ZInstI(OP_SCHEDULE0_CiH, is_interval, c);
|
||||
z = n ? ZInstI(OP_SCHEDULE0_ViH, FrameSlot(n), is_interval)
|
||||
: ZInstI(OP_SCHEDULE0_CiH, is_interval, c);
|
||||
z.op_type = n ? OP_VV_I2 : OP_VC_I1;
|
||||
}
|
||||
|
||||
|
@ -429,17 +419,17 @@ const ZAMStmt ZAMCompiler::CompileEvent(EventHandler* h, const ListExpr* l)
|
|||
return AddInst(z);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1,
|
||||
const NameExpr* n2,
|
||||
const ConstExpr* c2,
|
||||
const NameExpr* n3,
|
||||
const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const NameExpr* n2,
|
||||
const ConstExpr* c2, const NameExpr* n3,
|
||||
const ConstExpr* c3)
|
||||
{
|
||||
const Expr* op2 = n2;
|
||||
const Expr* op3 = n3;
|
||||
|
||||
if ( ! op2 ) op2 = c2;
|
||||
if ( ! op3 ) op3 = c3;
|
||||
if ( ! op2 )
|
||||
op2 = c2;
|
||||
if ( ! op3 )
|
||||
op3 = c3;
|
||||
|
||||
ZOp a;
|
||||
|
||||
|
@ -449,8 +439,7 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1,
|
|||
else if ( op2->GetType()->Tag() == TYPE_STRING )
|
||||
a = n2 ? (n3 ? OP_S_IN_S_VVV : OP_S_IN_S_VVC) : OP_S_IN_S_VCV;
|
||||
|
||||
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;
|
||||
|
||||
else if ( op3->GetType()->Tag() == TYPE_TABLE )
|
||||
|
@ -489,8 +478,8 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1,
|
|||
return AddInst(z);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
||||
const NameExpr* n2, const ConstExpr* c)
|
||||
const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l, const NameExpr* n2,
|
||||
const ConstExpr* c)
|
||||
{
|
||||
auto& l_e = l->Exprs();
|
||||
int n = l_e.length();
|
||||
|
@ -505,16 +494,14 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
if ( l_e[0]->Tag() == EXPR_NAME )
|
||||
{
|
||||
auto l_e0_n = l_e[0]->AsNameExpr();
|
||||
ZOp op = is_vec ? OP_VAL_IS_IN_VECTOR_VVV :
|
||||
OP_VAL_IS_IN_TABLE_VVV;
|
||||
ZOp op = is_vec ? OP_VAL_IS_IN_VECTOR_VVV : OP_VAL_IS_IN_TABLE_VVV;
|
||||
z = GenInst(op, n1, l_e0_n, n2);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
auto l_e0_c = l_e[0]->AsConstExpr();
|
||||
ZOp op = is_vec ? OP_CONST_IS_IN_VECTOR_VCV :
|
||||
OP_CONST_IS_IN_TABLE_VCV;
|
||||
ZOp op = is_vec ? OP_CONST_IS_IN_VECTOR_VCV : OP_CONST_IS_IN_TABLE_VCV;
|
||||
z = GenInst(op, n1, l_e0_c, n2);
|
||||
}
|
||||
|
||||
|
@ -525,8 +512,7 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
// Also somewhat common is a 2-element index. Here, one or both of
|
||||
// the elements might be a constant, which makes things messier.
|
||||
|
||||
if ( n == 2 && n2 &&
|
||||
(l_e[0]->Tag() == EXPR_NAME || l_e[1]->Tag() == EXPR_NAME) )
|
||||
if ( n == 2 && n2 && (l_e[0]->Tag() == EXPR_NAME || l_e[1]->Tag() == EXPR_NAME) )
|
||||
{
|
||||
auto is_name0 = l_e[0]->Tag() == EXPR_NAME;
|
||||
auto is_name1 = l_e[1]->Tag() == EXPR_NAME;
|
||||
|
@ -541,8 +527,7 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
|
||||
if ( l_e0_n && l_e1_n )
|
||||
{
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVV,
|
||||
n1, l_e0_n, l_e1_n, n2);
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVV, n1, l_e0_n, l_e1_n, n2);
|
||||
z.t2 = l_e0_n->GetType();
|
||||
}
|
||||
|
||||
|
@ -550,8 +535,7 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
{
|
||||
ASSERT(l_e1_c);
|
||||
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVC,
|
||||
n1, l_e0_n, n2, l_e1_c);
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVC, n1, l_e0_n, n2, l_e1_c);
|
||||
z.t2 = l_e0_n->GetType();
|
||||
}
|
||||
|
||||
|
@ -559,21 +543,19 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
{
|
||||
ASSERT(l_e0_c);
|
||||
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVCV,
|
||||
n1, l_e1_n, n2, l_e0_c);
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVCV, n1, l_e1_n, n2, l_e0_c);
|
||||
z.t2 = l_e1_n->GetType();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Ugh, both are constants. Assign first to
|
||||
// a temporary.
|
||||
// a temporary.
|
||||
ASSERT(l_e0_c);
|
||||
ASSERT(l_e1_c);
|
||||
|
||||
auto slot = TempForConst(l_e0_c);
|
||||
z = ZInstI(OP_VAL2_IS_IN_TABLE_VVVC, FrameSlot(n1),
|
||||
slot, FrameSlot(n2), l_e1_c);
|
||||
z = ZInstI(OP_VAL2_IS_IN_TABLE_VVVC, FrameSlot(n1), slot, FrameSlot(n2), l_e1_c);
|
||||
z.op_type = OP_VVVC;
|
||||
z.t2 = l_e0_c->GetType();
|
||||
}
|
||||
|
@ -581,7 +563,7 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
return AddInst(z);
|
||||
}
|
||||
|
||||
auto aggr = n2 ? (Expr*) n2 : (Expr*) c;
|
||||
auto aggr = n2 ? (Expr*)n2 : (Expr*)c;
|
||||
|
||||
ASSERT(aggr->GetType()->Tag() != TYPE_VECTOR);
|
||||
|
||||
|
@ -599,21 +581,19 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
|||
return AddInst(z);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, const NameExpr* n2,
|
||||
const ListExpr* l)
|
||||
const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, const NameExpr* n2, const ListExpr* l)
|
||||
{
|
||||
return CompileIndex(n1, FrameSlot(n2), n2->GetType(), l);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n, const ConstExpr* c,
|
||||
const ListExpr* l)
|
||||
const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n, const ConstExpr* c, const ListExpr* l)
|
||||
{
|
||||
auto tmp = TempForConst(c);
|
||||
return CompileIndex(n, tmp, c->GetType(), l);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
||||
const TypePtr& n2t, const ListExpr* l)
|
||||
const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot, const TypePtr& n2t,
|
||||
const ListExpr* l)
|
||||
{
|
||||
ZInstI z;
|
||||
|
||||
|
@ -642,14 +622,12 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
|||
{
|
||||
int n3_slot = FrameSlot(n3);
|
||||
auto zop = OP_INDEX_STRING_VVV;
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop),
|
||||
n2_slot, n3_slot);
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, n3_slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto zop = OP_INDEX_STRINGC_VVV;
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop),
|
||||
n2_slot, c);
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, c);
|
||||
z.op_type = OP_VVV_I3;
|
||||
}
|
||||
|
||||
|
@ -664,15 +642,12 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
|||
if ( n3 )
|
||||
{
|
||||
int n3_slot = FrameSlot(n3);
|
||||
auto zop = is_any ? OP_INDEX_ANY_VEC_VVV :
|
||||
OP_INDEX_VEC_VVV;
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop),
|
||||
n2_slot, n3_slot);
|
||||
auto zop = is_any ? OP_INDEX_ANY_VEC_VVV : OP_INDEX_VEC_VVV;
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, n3_slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto zop = is_any ? OP_INDEX_ANY_VECC_VVV :
|
||||
OP_INDEX_VECC_VVV;
|
||||
auto zop = is_any ? OP_INDEX_ANY_VECC_VVV : OP_INDEX_VECC_VVV;
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, c);
|
||||
z.op_type = OP_VVV_I3;
|
||||
}
|
||||
|
@ -686,10 +661,8 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
|||
if ( n3 )
|
||||
{
|
||||
int n3_slot = FrameSlot(n3);
|
||||
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVV,
|
||||
n1->GetType()->Tag());
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot,
|
||||
n3_slot);
|
||||
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVV, n1->GetType()->Tag());
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, n3_slot);
|
||||
z.SetType(n3->GetType());
|
||||
}
|
||||
|
||||
|
@ -697,10 +670,8 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
|||
{
|
||||
ASSERT(c3);
|
||||
|
||||
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC,
|
||||
n1->GetType()->Tag());
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop),
|
||||
n2_slot, c3);
|
||||
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC, n1->GetType()->Tag());
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, c3);
|
||||
}
|
||||
|
||||
return AddInst(z);
|
||||
|
@ -711,28 +682,29 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
|||
|
||||
ZOp op;
|
||||
|
||||
switch ( n2tag ) {
|
||||
case TYPE_VECTOR:
|
||||
op = OP_INDEX_VEC_SLICE_VV;
|
||||
z = ZInstI(op, Frame1Slot(n1, op), n2_slot);
|
||||
z.SetType(n2t);
|
||||
break;
|
||||
switch ( n2tag )
|
||||
{
|
||||
case TYPE_VECTOR:
|
||||
op = OP_INDEX_VEC_SLICE_VV;
|
||||
z = ZInstI(op, Frame1Slot(n1, op), n2_slot);
|
||||
z.SetType(n2t);
|
||||
break;
|
||||
|
||||
case TYPE_TABLE:
|
||||
op = OP_TABLE_INDEX_VV;
|
||||
z = ZInstI(op, Frame1Slot(n1, op), n2_slot);
|
||||
z.SetType(n1->GetType());
|
||||
break;
|
||||
case TYPE_TABLE:
|
||||
op = OP_TABLE_INDEX_VV;
|
||||
z = ZInstI(op, Frame1Slot(n1, op), n2_slot);
|
||||
z.SetType(n1->GetType());
|
||||
break;
|
||||
|
||||
case TYPE_STRING:
|
||||
op = OP_INDEX_STRING_SLICE_VV;
|
||||
z = ZInstI(op, Frame1Slot(n1, op), n2_slot);
|
||||
z.SetType(n1->GetType());
|
||||
break;
|
||||
case TYPE_STRING:
|
||||
op = OP_INDEX_STRING_SLICE_VV;
|
||||
z = ZInstI(op, Frame1Slot(n1, op), n2_slot);
|
||||
z.SetType(n1->GetType());
|
||||
break;
|
||||
|
||||
default:
|
||||
reporter->InternalError("bad aggregate type when compiling index");
|
||||
}
|
||||
default:
|
||||
reporter->InternalError("bad aggregate type when compiling index");
|
||||
}
|
||||
|
||||
z.aux = InternalBuildVals(l);
|
||||
z.CheckIfManaged(n1->GetType());
|
||||
|
@ -763,8 +735,7 @@ const ZAMStmt ZAMCompiler::AssignVecElems(const Expr* e)
|
|||
ASSERT(t1->Tag() == TYPE_VECTOR);
|
||||
ASSERT(t3->Tag() == TYPE_VECTOR);
|
||||
|
||||
auto z = GenInst(OP_VECTOR_SLICE_ASSIGN_VV,
|
||||
lhs, op3->AsNameExpr());
|
||||
auto z = GenInst(OP_VECTOR_SLICE_ASSIGN_VV, lhs, op3->AsNameExpr());
|
||||
|
||||
z.aux = InternalBuildVals(indexes_expr);
|
||||
|
||||
|
@ -784,11 +755,9 @@ const ZAMStmt ZAMCompiler::AssignVecElems(const Expr* e)
|
|||
auto c = op2->AsConstExpr();
|
||||
auto tmp = TempForConst(c);
|
||||
|
||||
auto zop = any_vec ? OP_ANY_VECTOR_ELEM_ASSIGN_VVC :
|
||||
OP_VECTOR_ELEM_ASSIGN_VVC;
|
||||
auto zop = any_vec ? OP_ANY_VECTOR_ELEM_ASSIGN_VVC : OP_VECTOR_ELEM_ASSIGN_VVC;
|
||||
|
||||
return AddInst(ZInstI(zop, Frame1Slot(lhs, zop), tmp,
|
||||
op3->AsConstExpr()));
|
||||
return AddInst(ZInstI(zop, Frame1Slot(lhs, zop), tmp, op3->AsConstExpr()));
|
||||
}
|
||||
|
||||
if ( op2->Tag() == EXPR_NAME )
|
||||
|
@ -892,7 +861,7 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n)
|
|||
bool indirect = ! func_id->IsGlobal() || ! func_id->GetVal();
|
||||
|
||||
if ( indirect )
|
||||
call_case = -1; // force default of CallN
|
||||
call_case = -1; // force default of CallN
|
||||
|
||||
auto nt = n ? n->GetType()->Tag() : TYPE_VOID;
|
||||
auto n_slot = n ? Frame1Slot(n, OP1_WRITE) : -1;
|
||||
|
@ -910,21 +879,17 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n)
|
|||
else if ( call_case == 1 )
|
||||
{
|
||||
auto arg0 = args[0];
|
||||
auto n0 = arg0->Tag() == EXPR_NAME ?
|
||||
arg0->AsNameExpr() : nullptr;
|
||||
auto c0 = arg0->Tag() == EXPR_CONST ?
|
||||
arg0->AsConstExpr() : nullptr;
|
||||
auto n0 = arg0->Tag() == EXPR_NAME ? arg0->AsNameExpr() : nullptr;
|
||||
auto c0 = arg0->Tag() == EXPR_CONST ? arg0->AsConstExpr() : nullptr;
|
||||
|
||||
if ( n )
|
||||
{
|
||||
if ( n0 )
|
||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VV, nt),
|
||||
n_slot, FrameSlot(n0));
|
||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VV, nt), n_slot, FrameSlot(n0));
|
||||
else
|
||||
{
|
||||
ASSERT(c0);
|
||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VC, nt),
|
||||
n_slot, c0);
|
||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VC, nt), n_slot, c0);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -957,19 +922,28 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n)
|
|||
|
||||
ZOp op;
|
||||
|
||||
switch ( call_case ) {
|
||||
case 2: op = n ? OP_CALL2_V : OP_CALL2_X; break;
|
||||
case 3: op = n ? OP_CALL3_V : OP_CALL3_X; break;
|
||||
case 4: op = n ? OP_CALL4_V : OP_CALL4_X; break;
|
||||
case 5: op = n ? OP_CALL5_V : OP_CALL5_X; break;
|
||||
switch ( call_case )
|
||||
{
|
||||
case 2:
|
||||
op = n ? OP_CALL2_V : OP_CALL2_X;
|
||||
break;
|
||||
case 3:
|
||||
op = n ? OP_CALL3_V : OP_CALL3_X;
|
||||
break;
|
||||
case 4:
|
||||
op = n ? OP_CALL4_V : OP_CALL4_X;
|
||||
break;
|
||||
case 5:
|
||||
op = n ? OP_CALL5_V : OP_CALL5_X;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( indirect )
|
||||
op = n ? OP_INDCALLN_VV : OP_INDCALLN_V;
|
||||
else
|
||||
op = n ? OP_CALLN_V : OP_CALLN_X;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if ( indirect )
|
||||
op = n ? OP_INDCALLN_VV : OP_INDCALLN_V;
|
||||
else
|
||||
op = n ? OP_CALLN_V : OP_CALLN_X;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( n )
|
||||
{
|
||||
|
@ -1134,37 +1108,38 @@ const ZAMStmt ZAMCompiler::ArithCoerce(const NameExpr* n, const Expr* e)
|
|||
|
||||
ZOp a;
|
||||
|
||||
switch ( targ_it ) {
|
||||
case TYPE_INTERNAL_DOUBLE:
|
||||
switch ( targ_it )
|
||||
{
|
||||
if ( op_it == TYPE_INTERNAL_INT )
|
||||
a = nt_is_vec ? OP_COERCE_DI_VEC_VV : OP_COERCE_DI_VV;
|
||||
else
|
||||
a = nt_is_vec ? OP_COERCE_DU_VEC_VV : OP_COERCE_DU_VV;
|
||||
break;
|
||||
}
|
||||
case TYPE_INTERNAL_DOUBLE:
|
||||
{
|
||||
if ( op_it == TYPE_INTERNAL_INT )
|
||||
a = nt_is_vec ? OP_COERCE_DI_VEC_VV : OP_COERCE_DI_VV;
|
||||
else
|
||||
a = nt_is_vec ? OP_COERCE_DU_VEC_VV : OP_COERCE_DU_VV;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_INTERNAL_INT:
|
||||
{
|
||||
if ( op_it == TYPE_INTERNAL_UNSIGNED )
|
||||
a = nt_is_vec ? OP_COERCE_IU_VEC_VV : OP_COERCE_IU_VV;
|
||||
else
|
||||
a = nt_is_vec ? OP_COERCE_ID_VEC_VV : OP_COERCE_ID_VV;
|
||||
break;
|
||||
}
|
||||
case TYPE_INTERNAL_INT:
|
||||
{
|
||||
if ( op_it == TYPE_INTERNAL_UNSIGNED )
|
||||
a = nt_is_vec ? OP_COERCE_IU_VEC_VV : OP_COERCE_IU_VV;
|
||||
else
|
||||
a = nt_is_vec ? OP_COERCE_ID_VEC_VV : OP_COERCE_ID_VV;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_INTERNAL_UNSIGNED:
|
||||
{
|
||||
if ( op_it == TYPE_INTERNAL_INT )
|
||||
a = nt_is_vec ? OP_COERCE_UI_VEC_VV : OP_COERCE_UI_VV;
|
||||
else
|
||||
a = nt_is_vec ? OP_COERCE_UD_VEC_VV : OP_COERCE_UD_VV;
|
||||
break;
|
||||
}
|
||||
case TYPE_INTERNAL_UNSIGNED:
|
||||
{
|
||||
if ( op_it == TYPE_INTERNAL_INT )
|
||||
a = nt_is_vec ? OP_COERCE_UI_VEC_VV : OP_COERCE_UI_VV;
|
||||
else
|
||||
a = nt_is_vec ? OP_COERCE_UD_VEC_VV : OP_COERCE_UD_VV;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("bad target internal type in coercion");
|
||||
}
|
||||
default:
|
||||
reporter->InternalError("bad target internal type in coercion");
|
||||
}
|
||||
|
||||
return AddInst(GenInst(a, n, op->AsNameExpr()));
|
||||
}
|
||||
|
@ -1232,4 +1207,4 @@ const ZAMStmt ZAMCompiler::Is(const NameExpr* n, const Expr* e)
|
|||
return AddInst(z);
|
||||
}
|
||||
|
||||
} // zeek::detail
|
||||
} // zeek::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue