Skip to content

Commit 13e1730

Browse files
committed
Support conditional fields and variable-length arrays in the Wireshark Lua backend
Add an Emboss-expression -> Lua translator so the dissector backend can handle constructs it previously skipped: * Conditional (`if`) fields are emitted as `if <cond> then ... end`. * Variable-length arrays (`T[n]`, with `n` a sibling field) and dynamically-located fields are emitted with the length/offset expression translated to Lua. Sibling field values referenced by a condition, array length, or offset are captured into `local val_*` reads. Fields whose governing expression can't be translated are still skipped with a comment, so the generator always emits valid Lua. Constant-only structs produce byte-identical output to before. Add testdata/wireshark_dynamic.emb (and its golden), expression/conditional/ array unit tests, and a TShark smoke test that loads a generated dissector and checks both branches of a conditional, length-prefixed message (the test skips itself when tshark is not installed).
1 parent c962481 commit 13e1730

8 files changed

Lines changed: 735 additions & 80 deletions

File tree

compiler/back_end/lua/BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ py_test(
6666
],
6767
)
6868

69+
# End-to-end check that runs a generated dissector under a real TShark. It
70+
# skips itself when `tshark` / `text2pcap` aren't on PATH (e.g. in CI), so it is
71+
# safe to include in the default test set.
72+
py_test(
73+
name = "tshark_smoke_test",
74+
srcs = ["tshark_smoke_test.py"],
75+
deps = [
76+
":dissector_generator",
77+
"//compiler/front_end:glue",
78+
"//compiler/util:test_util",
79+
],
80+
)
81+
6982
py_library(
7083
name = "one_golden_test_lib",
7184
srcs = ["one_golden_test.py"],
@@ -109,3 +122,9 @@ lua_golden_test(
109122
emb_file = "//testdata:wireshark.emb",
110123
golden_file = "//testdata/golden_lua:wireshark.emb.lua",
111124
)
125+
126+
lua_golden_test(
127+
name = "wireshark_dynamic_golden_test",
128+
emb_file = "//testdata:wireshark_dynamic.emb",
129+
golden_file = "//testdata/golden_lua:wireshark_dynamic.emb.lua",
130+
)

0 commit comments

Comments
 (0)