From 4b6cec4cd854d3329415b34eddb8da77f2e617ba Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Thu, 12 Dec 2024 22:40:49 -0800 Subject: [PATCH] simplified ZAM instructions for executing "assert" statements --- src/script_opt/ZAM/OPs/stmts.op | 26 ++++++++++++-------------- src/script_opt/ZAM/Stmt.cc | 4 ++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/script_opt/ZAM/OPs/stmts.op b/src/script_opt/ZAM/OPs/stmts.op index f90ee75237..b74cbdd1e9 100644 --- a/src/script_opt/ZAM/OPs/stmts.op +++ b/src/script_opt/ZAM/OPs/stmts.op @@ -348,22 +348,20 @@ eval static auto assertion_result_hook = id::find_func("assertion_result"); $$ = ! $1 || run_result_hook; op Report-Assert -# Operands are (1) result from Should-Report-Assert, (2) assertion value, -# (3) description of the condition (always a constant). +# Operands are (1) assertion value, (2) description of the condition +# (always a constant). op1-read -classes VVC -op-types I I S -eval if ( $$ ) - { - zeek::StringValPtr msg_val = zeek::val_mgr->EmptyString(); - report_assert($1, $2->ToStdString(), msg_val, Z_LOC->Loc()); - } +classes VC +op-types I S +eval { + zeek::StringValPtr msg_val = zeek::val_mgr->EmptyString(); + report_assert($$, $1->ToStdString(), msg_val, Z_LOC->Loc()); + } op Report-Assert-With-Message # The same, but with an additional operand being the associated message -# (as a variable, so it comes in $2 rather than $3). +# (as a variable, so it comes in $1 rather than $2). op1-read -classes VVVC -op-types I I S S -eval if ( $$ ) - report_assert($1, $3->ToStdString(), {NewRef{}, $2}, Z_LOC->Loc()); +classes VVC +op-types I S S +eval report_assert($$, $2->ToStdString(), {NewRef{}, $1}, Z_LOC->Loc()); diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 5877bc4f32..a428d14dd8 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -1083,10 +1083,10 @@ const ZAMStmt ZAMCompiler::CompileAssert(const AssertStmt* as) { else msg_slot = FrameSlot(msg->AsNameExpr()); - z = ZInstI(OP_REPORT_ASSERT_WITH_MESSAGE_VVVC, decision_slot, cond_slot, msg_slot, cond_desc_e.get()); + z = ZInstI(OP_REPORT_ASSERT_WITH_MESSAGE_VVC, cond_slot, msg_slot, cond_desc_e.get()); } else - z = ZInstI(OP_REPORT_ASSERT_VVC, decision_slot, cond_slot, cond_desc_e.get()); + z = ZInstI(OP_REPORT_ASSERT_VC, cond_slot, cond_desc_e.get()); auto end_inst = AddInst(z); AddCFT(insts1.back(), CFT_BLOCK_END);