Skip to content

Commit 345dd89

Browse files
committed
doc update
1 parent 6411011 commit 345dd89

1 file changed

Lines changed: 106 additions & 3 deletions

File tree

docs/tools/zem.md

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,18 @@ compiler | bin/zem --debug-events-only --source-name program.jsonl --debug-scrip
8989

9090
## Common flags
9191

92-
## IR corpus modes
92+
## Tools
9393

94-
These are not separate tools.
94+
These are not separate binaries. They are built into `zem`.
9595

96-
`zem` also includes a few IR corpus-oriented modes, invoked as flags:
96+
These flags select a different top-level action than “run the emulator”. In these modes, `zem` is operating on IR files and/or running external commands, not executing an IR program.
97+
98+
Which one should you use?
99+
100+
- Use `--irdiff` when you have two IR files and you want to know whether they match (and why not).
101+
- Use `--min-ir` when you have one “bad” IR file and you want the smallest IR that still triggers a failure in some command.
102+
- Use `--triage` when you have many IR files and you want to run a command over all of them and group failures by signature.
103+
- Use `--duel` when you want to compare two commands (A vs B) across inputs and find cases where they diverge (optionally minimizing a divergent case).
97104

98105
- `zem --irdiff ...` — compare two IR JSONL files
99106
- `zem --min-ir ...` — delta-minimize an IR JSONL file against a predicate
@@ -109,6 +116,102 @@ bin/zem --triage --summary corpus/*.jsonl -- bin/zld {}
109116
bin/zem --duel --corpus corpus --a bin/zir --canon --b bin/zir --canon --assign-ids
110117
```
111118

119+
### `--irdiff`
120+
121+
Compares two IR JSONL files for semantic-ish equality (record-by-record after filtering).
122+
123+
- Inputs: exactly two `.jsonl` files.
124+
- Output: no output on success; prints a short mismatch report on stderr when different.
125+
- Exit codes: `0` equal, `1` different, `2` error.
126+
127+
Useful options:
128+
129+
- `--include-ids` include v1.1 stable record ids in comparison.
130+
- `--include-src` include v1.1 `src_ref` in comparison.
131+
- `--include-loc` include `loc.line` in comparison.
132+
133+
Example:
134+
135+
```sh
136+
bin/zem --irdiff --include-ids a.ir.jsonl b.ir.jsonl
137+
```
138+
139+
### `--min-ir`
140+
141+
Delta-minimizes a single IR JSONL file against a predicate command.
142+
143+
You provide:
144+
145+
- an input IR JSONL file, and
146+
- a predicate command (after `--`) that is run repeatedly.
147+
148+
Command templating:
149+
150+
- If any predicate arg is exactly `{}`, it is replaced with the candidate path.
151+
- Otherwise the candidate path is appended as the last arg.
152+
153+
Predicate selection:
154+
155+
- `--want-exit N` predicate is satisfied iff the command exits with code `N`.
156+
- `--want-nonzero` predicate is satisfied iff the command exits nonzero (default).
157+
158+
Example (minimize while still failing `zir --canon`):
159+
160+
```sh
161+
bin/zem --min-ir --want-nonzero -o /tmp/min.jsonl input.ir.jsonl -- bin/zir --canon {}
162+
```
163+
164+
### `--triage`
165+
166+
Runs an external command across many input IR files and groups failures by a stderr signature.
167+
168+
- Inputs: one or more `.jsonl` files, followed by `-- <cmd> ...`.
169+
- Output:
170+
- A per-input JSONL stream (to stdout, or `--jsonl PATH`).
171+
- Optional human summary to stderr (`--summary`).
172+
173+
The output JSONL records include (at minimum):
174+
175+
- `k: "triage"`
176+
- `path`: input path
177+
- `exit`: command exit code
178+
- `fail`: boolean
179+
- `sig`: captured stderr prefix (see `--max-stderr`)
180+
181+
Example:
182+
183+
```sh
184+
bin/zem --triage --want-nonzero --summary --jsonl /tmp/triage.jsonl corpus/*.jsonl -- bin/zld {}
185+
```
186+
187+
### `--duel`
188+
189+
Runs two external commands (A and B) over inputs and checks whether they diverge.
190+
191+
Two input styles are supported:
192+
193+
- Explicit inputs:
194+
`bin/zem --duel --a <cmd...> --b <cmd...> -- <inputs...>`
195+
- Corpus directory:
196+
`bin/zem --duel --corpus <dir> --a <cmd...> --b <cmd...>` (runs over `*.jsonl`)
197+
198+
Comparison modes:
199+
200+
- `--compare exit|stdout|stderr|both` (default: `both`)
201+
202+
Common workflows:
203+
204+
- `--check` is for a single input: exit `1` iff divergent.
205+
- `--out DIR` writes per-case artifacts (captured stdout/stderr/metadata).
206+
- `--minimize` minimizes a divergent case by invoking `zem --min-ir`.
207+
- `--zem PATH` can override which `zem` executable is used for that re-run.
208+
209+
Example (A/B compare `zir --canon`):
210+
211+
```sh
212+
bin/zem --duel --corpus corpus --compare stdout --a bin/zir --canon --b bin/zir --canon --assign-ids
213+
```
214+
112215
### Tracing
113216

114217
- `--trace` emits per-instruction JSONL events to stderr.

0 commit comments

Comments
 (0)