ruso_runtime/opcode.rs
1//! Opcode and bytecode wire-format contract (version 1).
2//!
3//! # File layout (`RUSO` + version byte)
4//!
5//! 1. Metadata (name, description, impact, severity, author, report title)
6//! 2. Probe table (HTTP / DNS / TCP specs)
7//! 3. String pool
8//! 4. Matcher pool (`QualifiedMatch`)
9//! 5. Extract pool (`ExtractSource`)
10//! 6. Evidence pool (`EvidenceKind`)
11//! 7. Payload pool (raw bytes for `Send` overrides)
12//! 8. Instruction stream (`Opcode` discriminants)
13//!
14//! # Instruction opcodes (wire `u8`)
15//!
16//! | Byte | Variant | Payload |
17//! |------|-------------|----------------------------------|
18//! | 1 | Set | `name_id: u32`, `value_id: u32` |
19//! | 2 | Send | `probe_id: u32`, optional payload index |
20//! | 3 | Match | `matcher_id: u32` |
21//! | 4 | MatchAll | `start: u32`, `len: u16` |
22//! | 5 | MatchAny | `start: u32`, `len: u16` |
23//! | 6 | Assert | `matcher_id: u32` |
24//! | 7 | Extract | `name_id: u32`, `source_id: u32` |
25//! | 8 | IfMatch | `matcher_id: u32`, `else_pc: u32`|
26//! | 9 | Save | `from_id: u32`, `to_id: u32` |
27//! | 10 | Evidence | `kind_id: u32` |
28//! | 11 | Retry | `probe_id: u32`, `count: u32` |
29//! | 12 | RetryDelay | `duration_id: u32` |
30//! | 13 | Sleep | `duration_id: u32` |
31//! | 14 | Stop | — |
32//! | 15 | Fail | — |
33//! | 16 | Continue | — |
34//! | 17 | Exit | — |
35//! | 18 | (reserved) | was `Repeat`, removed |
36//! | 19 | LoopBack | — |
37//! | 20 | Break | — |
38//! | 21 | SetList | `name_id: u32`, `start: u32`, `len: u16` |
39//! | 22 | ForList | `item_id: u32`, `start: u32`, `len: u16`, `end_pc: u32` |
40//! | 23 | ForVar | `item_id: u32`, `list_id: u32`, `end_pc: u32` |
41//!
42//! Compilers must emit [`crate::BytecodeProgram`] compatible with [`crate::VERSION`].
43
44pub use crate::runtime::binary::{MAGIC, VERSION};
45pub use crate::runtime::bytecode::{BytecodeProgram, Instr as Opcode, Pc};
46
47pub const OP_SET: u8 = 1;
48pub const OP_SEND: u8 = 2;
49pub const OP_MATCH: u8 = 3;
50pub const OP_MATCH_ALL: u8 = 4;
51pub const OP_MATCH_ANY: u8 = 5;
52pub const OP_ASSERT: u8 = 6;
53pub const OP_EXTRACT: u8 = 7;
54pub const OP_IF_MATCH: u8 = 8;
55pub const OP_SAVE: u8 = 9;
56pub const OP_EVIDENCE: u8 = 10;
57pub const OP_RETRY: u8 = 11;
58pub const OP_RETRY_DELAY: u8 = 12;
59pub const OP_SLEEP: u8 = 13;
60pub const OP_STOP: u8 = 14;
61pub const OP_FAIL: u8 = 15;
62pub const OP_CONTINUE: u8 = 16;
63pub const OP_EXIT: u8 = 17;
64// 18 reserved: was `Repeat`, removed from the language and VM.
65pub const OP_LOOP_BACK: u8 = 19;
66pub const OP_BREAK: u8 = 20;
67pub const OP_SET_LIST: u8 = 21;
68pub const OP_FOR_LIST: u8 = 22;
69pub const OP_FOR_VAR: u8 = 23;