From a5c941139c8b623eb7dc0e9ccdc4133e1c45048f Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 6 Feb 2024 14:17:39 +0100 Subject: [PATCH] Stmt: Introduce STMT_EXTERN It's currently possible for plugin's to implement their own statement subclasses and override the Exec() implementation. This has been leveraged by ZeekJS [1] and zeek-perf-support [2] as well as a private WASM plugin. All of these used STMT_ANY as the tag of their own statement subclasses. With STMT_EXTERN, we make the possibility to add external code into the AST somewhat more supported. It's all in detail space and plugin authors have no guarantee for stability, but it seems such a powerful extension point that IMO we should keep it. I'm conscious there's the broader topic how this interacts with ZAM optimization like in-lining or rewriting of statements. However, this already applies to the STMT_ANY usage of the mentioned plugins. [1] https://github.com/corelight/zeekjs [2] https://github.com/zeek/zeek-perf-support --- src/Stmt.cc | 1 + src/StmtEnums.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index cf455c44ed..6041e16e8a 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -52,6 +52,7 @@ const char* stmt_name(StmtTag t) { "ZAM", "null", "assert", + "extern", }; return stmt_names[int(t)]; diff --git a/src/StmtEnums.h b/src/StmtEnums.h index 3eb463eab9..7a237cb043 100644 --- a/src/StmtEnums.h +++ b/src/StmtEnums.h @@ -31,7 +31,8 @@ enum StmtTag { STMT_ZAM, // a ZAM function body STMT_NULL, STMT_ASSERT, -#define NUM_STMTS (int(STMT_ASSERT) + 1) + STMT_EXTERN, // for custom Stmt subclasses provided by plugins +#define NUM_STMTS (int(STMT_EXTERN) + 1) }; enum StmtFlowType {