interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / dgraph_receipt.om

4087 lines · 83592 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note
4note tools/dgraph_receipt.om -- pure seeded OM-2 decode-graph performance receipt generator and checker.
5om2
6
7text t_s0 "invalid JSON: "
8text t_s1 "dgraph_receipt: out of memory\n"
9text t_s2 "bad \\u escape"
10text t_s3 "lone surrogate"
11text t_s4 "NUL in string"
12text t_s5 "unterminated string"
13text t_s6 "bad escape"
14text t_s7 "expected string"
15text t_s8 "control character in string"
16text t_s9 "bad number"
17text t_s10 "number too long"
18text t_s11 "duplicate key"
19text t_s12 "expected ':'"
20text t_s13 "expected ',' or '}'"
21text t_s14 "expected ',' or ']'"
22text t_s15 "nested too deep"
23text t_s16 "unexpected end"
24text t_s17 "true"
25text t_s18 "false"
26text t_s19 "null"
27text t_s20 "unexpected character"
28text t_s21 "NUL byte"
29text t_s22 "trailing data"
30text t_s23 "tbd"
31text t_s24 "tba"
32text t_s25 "todo"
33text t_s26 "fixme"
34text t_s27 "unknown"
35text t_s28 "unk"
36text t_s29 "n/a"
37text t_s30 "na"
38text t_s31 "none"
39text t_s32 "nil"
40text t_s33 "placeholder"
41text t_s34 "xxx"
42text t_s35 "?"
43text t_s36 "??"
44text t_s37 "???"
45text t_s38 "-"
46text t_s39 "..."
47text t_s40 "<tbd>"
48text t_s41 "<unknown>"
49text t_s42 "placeholder value \""
50text t_s43 "\" at "
51text t_s44 "placeholder key \""
52text t_s45 "\" in "
53text t_s46 "missing field "
54text t_s47 "field "
55text t_s48 " has the wrong type"
56text t_s49 " is not an integer"
57text t_s50 " = "
58text t_s51 " is below "
59text t_s52 " \""
60text t_s53 "\" is not "
61text t_s54 " lowercase hex digits"
62text t_s55 " is an empty list"
63text t_s56 "["
64text t_s57 "] is not a string"
65text t_s58 "graph"
66text t_s59 "flush_each"
67text t_s60 "total_ns"
68text t_s61 "chip_ns"
69text t_s62 "host_overhead_ns"
70text t_s63 "derived "
71text t_s64 ".host_overhead_ns = "
72text t_s65 " but total_ns - chip_ns = "
73text t_s66 "launches"
74text t_s67 "submits"
75text t_s68 ".submits "
76text t_s69 " exceeds launches "
77text t_s70 "sems_done"
78text t_s71 "missing field per_token."
79text t_s72 ".sems_done"
80text t_s73 "sems_done_note"
81text t_s74 "per_token."
82text t_s75 ".sems_done must equal launches or be null with a note"
83text t_s76 "stages"
84text t_s77 "stamped_token.stages is empty"
85text t_s78 "stamped_token.stages["
86text t_s79 "] is not an object"
87text t_s80 "kind"
88text t_s81 "device_ns"
89text t_s82 "stamped_token.stages overflow a 64-bit sum at stages["
90text t_s83 "]"
91text t_s84 "derived stamped_token.stage_sum_ns = "
92text t_s85 " but the stages add up to "
93text t_s86 "stamped_token.stage_sum_ns "
94text t_s87 " differs from span_ns "
95text t_s88 " (consecutive stamps must partition the span)"
96text t_s89 "stamped_token stages count "
97text t_s90 " launches, launches = "
98text t_s91 "per_token"
99text t_s92 "statistic"
100text t_s93 "workload.tokens"
101text t_s94 "tokens"
102text t_s95 "per_token.tokens "
103text t_s96 " differs from workload.tokens "
104text t_s97 "graph.record_ns"
105text t_s98 "flush_each.identical_to_graph"
106text t_s99 "stamped_token"
107text t_s100 "span_ns"
108text t_s101 "unattributed_ns"
109text t_s102 "stage_sum_ns"
110text t_s103 "stamped_token.span_ns "
111text t_s104 " (device) exceeds chip_ns "
112text t_s105 " (the host span that contains it)"
113text t_s106 "derived stamped_token.unattributed_ns = "
114text t_s107 " but chip_ns - span_ns = "
115text t_s108 "graph.launches"
116text t_s109 "stamped_token.launches "
117text t_s110 " differs from per_token.graph.launches "
118text t_s111 "schema"
119text t_s112 "status"
120text t_s113 "status_note"
121text t_s114 "run_verdict"
122text t_s115 "not_run_reason"
123text t_s116 "source"
124text t_s117 "run"
125text t_s118 "workload"
126text t_s119 "hardware"
127text t_s120 "build"
128text t_s121 "aggregate"
129text t_s122 "serial_vs_overlap"
130text t_s123 "methodology"
131text t_s124 "evidence"
132text t_s125 "limitations"
133text t_s126 "VERIFIED"
134text t_s127 "EXPERIMENTAL"
135text t_s128 "HISTORICAL"
136text t_s129 "NOT_RUN"
137text t_s130 "FAIL"
138text t_s131 "SUPERSEDED"
139text t_s132 "methodology.counters.launches"
140text t_s133 "methodology.counters.submits"
141text t_s134 "methodology.counters.chip_ns"
142text t_s135 "methodology.counters.record_ns"
143text t_s136 "methodology.counters.total_ns"
144text t_s137 "methodology.counters.sems_done"
145text t_s138 "methodology.counters.stamps"
146text t_s139 "evidence path \""
147text t_s140 "\" must be repo-relative without '..'"
148text t_s141 "\" does not exist under "
149text t_s142 "source.commit"
150text t_s143 "source.repo"
151text t_s144 "source.repo \""
152text t_s145 "\" is not OWNER/NAME"
153text t_s146 "source.dirty"
154text t_s147 "status NOT_RUN and run_verdict NOT_RUN go together (status "
155text t_s148 ", run_verdict "
156text t_s149 ")"
157text t_s150 "status VERIFIED with source.dirty true: a dirty tree cannot be verified"
158text t_s151 "PASS"
159text t_s152 "status "
160text t_s153 " needs run_verdict PASS (got "
161text t_s154 "receipt is not a JSON object"
162text t_s155 "unknown top-level field "
163text t_s156 "omega-decode-graph-receipt/1"
164text t_s157 "schema \""
165text t_s158 "\" is not \"omega-decode-graph-receipt/1\""
166text t_s159 "receipt"
167text t_s160 "status \""
168text t_s161 "\" is not one of VERIFIED EXPERIMENTAL HISTORICAL NOT_RUN FAIL SUPERSEDED"
169text t_s162 "run_verdict \""
170text t_s163 "\" is not PASS, FAIL or NOT_RUN"
171text t_s164 "workload.model"
172text t_s165 "workload.precision"
173text t_s166 "workload.mode"
174text t_s167 "hardware.host"
175text t_s168 "hardware.gpu"
176text t_s169 "none_detected"
177text t_s170 " with hardware.gpu none_detected: a run without a detected GPU cannot be "
178text t_s171 "build.runner"
179text t_s172 "status NOT_RUN must carry per_token and stamped_token as null (nothing was measured)"
180text t_s173 "not_run_reason is only for status NOT_RUN"
181text t_s174 "build.binary_sha256"
182text t_s175 "build.library_sha256"
183text t_s176 "serial_vs_overlap.chip_ns"
184text t_s177 "serial_vs_overlap.stages"
185text t_s178 "serial_vs_overlap.overlap_measurable"
186text t_s179 "serial_vs_overlap.reason"
187text t_s180 "methodology.device_clock"
188text t_s181 "methodology.host_clock"
189text t_s182 "methodology.counters"
190text t_s183 "\\n"
191text t_s184 "\\t"
192text t_s185 "\\u00"
193text t_s186 " "
194text t_s187 "\": "
195text t_s188 "mode"
196text t_s189 "omega"
197text t_s190 "branch"
198text t_s191 "dirty"
199text t_s192 "physics_commit"
200text t_s193 "cannot read "
201text t_s194 "start "
202text t_s195 "end "
203text t_s196 "Linux "
204text t_s197 "NVIDIA"
205text t_s198 ", "
206text t_s199 " lacks the runner's start line (omega=, dirty=) or the uname line"
207text t_s200 "/gpu_decode_graph_test"
208text t_s201 "/libomega_gpu.a"
209text t_s202 " lacks the sha256 of gpu_decode_graph_test or libomega_gpu.a"
210text t_s203 "dgraph prefetch "
211text t_s204 " (red "
212text t_s205 "fp8 knobs: variant "
213text t_s206 " barrier "
214text t_s207 " ("
215text t_s208 " cached "
216text t_s209 " lacks the \"dgraph prefetch\" or \"fp8 knobs\" line: the receipt needs the run's barrier and prefetch settings"
217text t_s210 "-o build/gpu_decode_graph_test "
218text t_s211 "stats file: "
219text t_s212 " missing or not a non-negative integer"
220text t_s213 "norm"
221text t_s214 "qkv"
222text t_s215 "attn"
223text t_s216 "o_proj"
224text t_s217 "res_add"
225text t_s218 "router"
226text t_s219 "gate_up"
227text t_s220 "swiglu"
228text t_s221 "down"
229text t_s222 "combine_norm"
230text t_s223 "lm_head"
231text t_s224 "argmax"
232text t_s225 "layers"
233text t_s226 "vocab"
234text t_s227 "pos"
235text t_s228 "reps"
236text t_s229 "red"
237text t_s230 "cached_weights"
238text t_s231 "C.launches"
239text t_s232 "C.submits"
240text t_s233 "timeline.launches"
241text t_s234 "timeline.span_ns"
242text t_s235 "timeline.chip_ns"
243text t_s236 "median_ns.C_total"
244text t_s237 "median_ns.C_chip"
245text t_s238 "median_ns.C_record"
246text t_s239 "median_ns.B_total"
247text t_s240 "median_ns.B_chip"
248text t_s241 "B.launches"
249text t_s242 "B.submits"
250text t_s243 "B.identical"
251text t_s244 "checks"
252text t_s245 "failed"
253text t_s246 "verdict"
254text t_s247 "stats file: verdict missing or not PASS/FAIL"
255text t_s248 "timeline.per_kind_ns"
256text t_s249 "stats file: timeline.per_kind_ns missing or empty"
257text t_s250 "stats file and log disagree (cached "
258text t_s251 "/"
259text t_s252 ", red "
260text t_s253 "): not the same run"
261text t_s254 "stats file: verdict PASS with failed "
262text t_s255 "stats file: timeline.per_kind_ns."
263text t_s256 " is not [launches, ns]"
264text t_s257 "stats file: unknown stage kind "
265text t_s258 "reproduced from an existing evidence run ("
266text t_s259 ", started "
267text t_s260 ") by tools/dgraph_receipt.c; the chip was not run to make this receipt"
268text t_s261 " set by the operator for the run in "
269text t_s262 " (started "
270text t_s263 "repo"
271text t_s264 "commit"
272text t_s265 "dirty_basis"
273text t_s266 "\"device.txt dirty="
274text t_s267 " (git status --porcelain line count at run start)\""
275text t_s268 "started_utc"
276text t_s269 "ended_utc"
277text t_s270 "runner_mode"
278text t_s271 "test_checks"
279text t_s272 " checks, "
280text t_s273 " failed\""
281text t_s274 "model"
282text t_s275 "precision"
283text t_s276 "tokens_note"
284text t_s277 " timed graph tokens (the test's --reps), every one the same step at position "
285text t_s278 "; plus one stamped token\""
286text t_s279 "prefetch"
287text t_s280 "red_mutant"
288text t_s281 "barrier"
289text t_s282 ")\""
290text t_s283 "fp8_variant"
291text t_s284 "host"
292text t_s285 "kernel"
293text t_s286 "gpu"
294text t_s287 "driver"
295text t_s288 "basis"
296text t_s289 "device.txt: uname -a and nvidia-smi --query-gpu=name,driver_version at run start"
297text t_s290 "runner"
298text t_s291 "binary_sha256"
299text t_s292 "library_sha256"
300text t_s293 "compile_command"
301text t_s294 "compile_command_note"
302text t_s295 " bytes) holds no compile line for build/gpu_decode_graph_test: make did not rebuild it in this run, so the flags are not recorded; the binary is identified by binary_sha256\""
303text t_s296 "\"median over "
304text t_s297 " tokens (sorted value at index n/2), each field's median taken on its own, so derived differences are differences of medians\""
305text t_s298 "record_ns"
306text t_s299 "not written by gpu_decode_graph_test; submit_now() in omega_gpu_decode_graph.c fails the token when sems_done != launches, so a PASS run implies sems_done == launches for every timed token (inferred, not a recorded value)"
307text t_s300 "as for graph: not recorded, implied by the PASS verdict"
308text t_s301 "identical_to_graph"
309text t_s302 "note"
310text t_s303 "the same recorded list submitted one launch per submission (TEST ONLY set_flush_each): the batching comparison inside the same run"
311text t_s304 "one extra token run with set_stamps(1): span_ns and stage times are device PTIMER differences; chip_ns is that token's host-clock submit span; unattributed_ns = chip_ns - span_ns (submit call, front-end start, completion marker and host poll)"
312text t_s305 ""
313text t_s306 "available"
314text t_s307 "reason"
315text t_s308 "the input receipt carries per-token medians and one stamped token only, no per-token arrays or run totals, so no aggregate sums or percentiles are derived (adding them needs the test to write every token's stats)"
316text t_s309 "\"serial: the sum over the token's submissions of one host-clock span each ("
317text t_s310 " submission per graph token, "
318text t_s311 " per flush_each token); spans never overlap each other\""
319text t_s312 "\"serial partition with "
320text t_s313 " independent launches: prefetch on, each layer's o_proj prefetch is marked independent (no barrier before it) and tagged attn, so its stamp is the front-end time while the attention may still run; the attn stage is the attention+prefetch window and the stages still add up to span_ns\""
321text t_s314 "barrier 1 (none, TEST ONLY): no WAIT_FOR_IDLE before the stamps, so a stage time is a front-end interval, not a launch duration"
322text t_s315 "\"serial partition: barrier "
323text t_s316 ") puts a WAIT_FOR_IDLE before every stamp and prefetch is off, so launches run one after another and the stage times add up exactly to span_ns\""
324text t_s317 "overlap_measurable"
325text t_s318 "an overlapped window is visible (the attn stage holds attention + prefetch), but no counter splits it, so how much of the two launches overlapped is not measurable from these counters"
326text t_s319 "every launch waits for the previous one (WFI) and the host records before it submits, so nothing overlaps to measure; device time inside the host span is span_ns, the rest is unattributed_ns"
327text t_s320 "device_clock"
328text t_s321 "GPU PTIMER ns from compute-class REPORT_SEMAPHORE timestamps (omega_gpu_cmdlist.h: \"out[0] = GPU timestamp (ns, PTIMER) before launch 0, out[i + 1] = after launch i completed (taken after its WAIT_FOR_IDLE)\"); used only by stamped_token span_ns and stages"
329text t_s322 "host_clock"
330text t_s323 "omega_gpu_session_now_ns(): the platform's time_now_ns, CLOCK_MONOTONIC on Linux (omega_gpu_platform_linux.c ref_now_ns); used by chip_ns, record_ns and total_ns"
331text t_s324 "counters"
332text t_s325 "omega_gpu_decode_graph.h: \"launches recorded for the token\""
333text t_s326 "omega_gpu_decode_graph.h: \"submissions (1 normally; = launches with flush_each)\""
334text t_s327 "omega_gpu_decode_graph.h: \"sum of the list submissions' first-submit-to-last-marker time\". HOST clock, not device time: omega_gpu_cmdlist_submit() reads time_now_ns just before queue_submit and again after both completion marker words were seen and synced, so it holds device execution plus submit, fetch and poll latency"
335text t_s328 "omega_gpu_decode_graph.h: \"host: begin_token to the submit (recording)\""
336text t_s329 "omega_gpu_decode_graph.h: \"host: begin_token to end_token return\""
337text t_s330 "omega_gpu_decode_graph.h: \"launch semaphores found DONE\""
338text t_s331 "stamps"
339text t_s332 "omega_gpu_decode_graph.h: \"Launch i took stamps[i + 1] - stamps[i] ns\"; gpu_decode_graph_test sums them per kind (per_kind_ns)"
340text t_s333 "derived: total_ns - chip_ns, both host clock: recording, attention counter check, output sync, token read and lock, everything outside the submit span"
341text t_s334 "numbers copied from the stats file written by tests/gpu_decode_graph_test.c --out; settings from its log; identity from the runner's device.txt and binaries.sha256"
342text t_s335 "chip_ns is host-clock time around the device work; the only device-clock numbers are the stamped token's span_ns and stages"
343text t_s336 "per-token values are independent medians of a synthetic step on random weights (Qwen3-30B-A3B shapes, not a checkpoint), one fixed position, the same token every rep; not a serving or end-to-end tokens-per-second figure"
344text t_s337 "the stamped token is a single token: its stage times are one sample, not a distribution"
345text t_s338 "sems_done, the command list's own host_ns (method-stream build) and the marker-wait part of chip_ns are not recorded per token"
346text t_s339 "no aggregate totals or percentiles: the input has medians only"
347text t_s340 "this receipt is not a qualification: it re-expresses an existing run and claims nothing beyond that run's files"
348text t_s341 "the run's tree was dirty: the commit alone does not reproduce the binary; see worktree.diff in the run directory when present"
349text t_s342 "dgraph_receipt: "
350text t_s343 "\n"
351text t_s344 "dgraph_receipt: cannot read "
352text t_s345 ": "
353text t_s346 "device.txt"
354text t_s347 "binaries.sha256"
355text t_s348 "build.log"
356text t_s349 "dgraph_receipt: refusing to write: the receipt fails its own check: "
357text t_s350 "dgraph_receipt: cannot write "
358text t_s351 "dgraph_receipt: write failed\n"
359text t_s352 "usage: dgraph_receipt --run-dir DIR --stats FILE --log FILE --status STATUS --repo OWNER/NAME --model TEXT\n --precision TEXT --mode TEXT --runner TEXT [--evidence PATH]... [--out FILE]\n dgraph_receipt --check FILE [--evidence-root DIR]\n"
360text t_s353 "--check"
361text t_s354 "--evidence-root"
362text t_s355 "--run-dir"
363text t_s356 "--stats"
364text t_s357 "--log"
365text t_s358 "--status"
366text t_s359 "--repo"
367text t_s360 "--model"
368text t_s361 "--precision"
369text t_s362 "--mode"
370text t_s363 "--runner"
371text t_s364 "--out"
372text t_s365 "--evidence"
373text t_s366 "dgraph_receipt: REJECT "
374text t_s367 "dgraph_receipt: OK "
375note dgraph_receipt.om -- pure seeded OM-2 decode-graph performance receipt generator and checker.
376note Replaces tools/dgraph_receipt.c (same CLI, byte-identical golden output, same checker diagnostics).
377
378global JBUF uchar *
379global JLEN ulong 1
380global JPOS ulong 1
381
382global STRPOOL uchar *
383global STRUSED ulong 1
384
385note JSON AST node pools: 0=null, 1=bool, 2=num, 3=str, 4=arr, 5=obj
386global NT uchar *
387global NB uchar *
388global NI long *
389global NLAST long *
390global NC ulong *
391global NUSED ulong 1
392
393note JSON object/array entry linked-list pools
394global ENT_KOFF ulong *
395global ENT_KLEN ulong *
396global ENT_VAL ulong *
397global ENT_NEXT long *
398global EUSED ulong 1
399
400global ERRBUF uchar 512
401global ERRLEN ulong 1
402global ERROK ulong 1
403
404global OUTBUF uchar *
405global OUTLEN ulong 1
406global WDEPTH ulong 1
407global WFIRST uchar 40
408
409global FBUF uchar *
410global FLEN ulong 1
411
412global STATBUF uchar 128
413global PBUF uchar 4096
414global PLEN ulong 1
415
416note CLI args stored in flat buffer with offsets/lengths
417global ARGP uchar *
418global ARGU ulong 1
419note 0=check, 1=evroot, 2=run_dir, 3=stats, 4=log, 5=status, 6=repo, 7=model, 8=prec, 9=mode, 10=runner, 11=out
420global AOFF ulong 12
421global ALEN ulong 12
422global ASET uchar 12
423global EV_OFF ulong *
424global EV_LEN ulong *
425global NEV ulong 1
426
427note Device fields: 0=started,1=ended,2=runner_mode,3=commit,4=branch,5=physics_commit,6=host,7=kernel,8=gpu,9=driver
428global DEV_OFF ulong 10
429global DEV_LEN ulong 10
430global DEV_DIRTY long 1
431
432note Binaries sha256
433global BIN_SHA uchar 64
434global BIN_SET ulong 1
435global LIB_SHA uchar 64
436global LIB_SET ulong 1
437
438note Knobs
439global K_PREF long 1
440global K_RED long 1
441global K_FP8V long 1
442global K_BARR long 1
443global K_CACH long 1
444global K_BNAME uchar 64
445global K_BNLEN ulong 1
446
447note Stats extracted values
448global S_LAYERS long 1
449global S_VOCAB long 1
450global S_POS long 1
451global S_REPS long 1
452global S_RED long 1
453global S_CACH long 1
454global S_CL long 1
455global S_CS long 1
456global S_TL long 1
457global S_SPAN long 1
458global S_TCHIP long 1
459global S_MT long 1
460global S_MC long 1
461global S_MR long 1
462global S_BT long 1
463global S_BC long 1
464global S_BL long 1
465global S_BS long 1
466global S_BID long 1
467global S_CHECKS long 1
468global S_FAILED long 1
469global S_VERD_OFF ulong 1
470global S_VERD_LEN ulong 1
471global S_PK_ID ulong 1
472
473note Saved paths for generate(): 0=dev_p, 1=bin_p, 2=blog_p, 3=compile_line
474global G_OFF ulong 4
475global G_LEN ulong 4
476global G_BLOG_BYTES ulong 1
477
478note Scratch buffer for dynamic error messages / paths
479global TMPB uchar 512
480global TMPL ulong 1
481
482fn write_all fd int s view uchar * to void
483 n = len s
484 off = ulong 0
485 while lt off n
486 w = write int fd s off sub n off
487 if le w 0
488 ret
489 end
490 off = add off ulong w
491 end
492end
493
494fn err_reset to void
495 put ERRLEN 0 0
496 put ERROK 0 0
497end
498
499fn err_push c uchar to void
500 n = get ERRLEN 0
501 if lt n 511
502 put ERRBUF n c
503 put ERRLEN 0 add n 1
504 end
505end
506
507fn err_str s view uchar * to void
508 i = ulong 0
509 n = len s
510 while lt i n
511 err_push get s i
512 i = add i 1
513 end
514end
515
516fn err_strpool off ulong n ulong to void
517 i = ulong 0
518 while lt i n
519 err_push get STRPOOL add off i
520 i = add i 1
521 end
522end
523
524fn err_argp off ulong n ulong to void
525 i = ulong 0
526 while lt i n
527 err_push get ARGP add off i
528 i = add i 1
529 end
530end
531
532fn err_u64 v ulong to void
533 tmp = new uchar 24 0
534 if eq v 0
535 err_push 48
536 ret
537 end
538 k = ulong 0
539 while gt v 0
540 put tmp k uchar add 48 rem v 10
541 v = div v 10
542 k = add k 1
543 end
544 while gt k 0
545 k = sub k 1
546 err_push get tmp k
547 end
548end
549
550fn err_i64 v long to void
551 if lt v 0
552 err_push 45
553 if eq v sub neg long 9223372036854775807 1
554 err_u64 9223372036854775808
555 else
556 err_u64 ulong neg v
557 end
558 ret
559 end
560 err_u64 ulong v
561end
562
563fn perr m view uchar * to void
564 if eq get ERROK 0 0
565 put ERROK 0 1
566 put ERRLEN 0 0
567 err_str t_s0
568 err_str m
569 end
570end
571
572fn strpool_push c uchar to void
573 n = get STRUSED 0
574 if ge n len STRPOOL
575 nc = mul n 2
576 if lt nc 8192
577 nc = 8192
578 end
579 r = enlarge STRPOOL nc
580 if lt r 0
581 write_all 2 t_s1
582 exit 2
583 end
584 end
585 put STRPOOL n c
586 put STRUSED 0 add n 1
587end
588
589fn strpool_put_utf8 cp ulong to void
590 if lt cp 128
591 strpool_push uchar cp
592 ret
593 end
594 if lt cp 2048
595 strpool_push uchar or 192 shr cp 6
596 strpool_push uchar or 128 and cp 63
597 ret
598 end
599 if lt cp 65536
600 strpool_push uchar or 224 shr cp 12
601 strpool_push uchar or 128 and shr cp 6 63
602 strpool_push uchar or 128 and cp 63
603 ret
604 end
605 strpool_push uchar or 240 shr cp 18
606 strpool_push uchar or 128 and shr cp 12 63
607 strpool_push uchar or 128 and shr cp 6 63
608 strpool_push uchar or 128 and cp 63
609end
610
611fn jnew t uchar to ulong
612 id = get NUSED 0
613 if ge id len NT
614 nc = mul id 2
615 if lt nc 256
616 nc = 256
617 end
618 r = enlarge NT nc
619 if lt r 0
620 write_all 2 t_s1
621 exit 2
622 end
623 r = enlarge NB nc
624 if lt r 0
625 write_all 2 t_s1
626 exit 2
627 end
628 r = enlarge NI nc
629 if lt r 0
630 write_all 2 t_s1
631 exit 2
632 end
633 r = enlarge NLAST nc
634 if lt r 0
635 write_all 2 t_s1
636 exit 2
637 end
638 r = enlarge NC nc
639 if lt r 0
640 write_all 2 t_s1
641 exit 2
642 end
643 end
644 put NT id t
645 put NB id 0
646 put NI id neg long 1
647 put NLAST id neg long 1
648 put NC id 0
649 put NUSED 0 add id 1
650 ret id
651end
652
653fn ent_new koff ulong klen ulong val ulong to ulong
654 id = get EUSED 0
655 if ge id len ENT_VAL
656 nc = mul id 2
657 if lt nc 256
658 nc = 256
659 end
660 r = enlarge ENT_KOFF nc
661 if lt r 0
662 write_all 2 t_s1
663 exit 2
664 end
665 r = enlarge ENT_KLEN nc
666 if lt r 0
667 write_all 2 t_s1
668 exit 2
669 end
670 r = enlarge ENT_VAL nc
671 if lt r 0
672 write_all 2 t_s1
673 exit 2
674 end
675 r = enlarge ENT_NEXT nc
676 if lt r 0
677 write_all 2 t_s1
678 exit 2
679 end
680 end
681 put ENT_KOFF id koff
682 put ENT_KLEN id klen
683 put ENT_VAL id val
684 put ENT_NEXT id neg long 1
685 put EUSED 0 add id 1
686 ret id
687end
688
689fn strpool_eq aoff ulong alen ulong boff ulong blen ulong to bool
690 if ne alen blen
691 ret false
692 end
693 i = ulong 0
694 while lt i alen
695 if ne get STRPOOL add aoff i get STRPOOL add boff i
696 ret false
697 end
698 i = add i 1
699 end
700 ret true
701end
702
703fn strpool_eq_lit off ulong n ulong s view uchar * to bool
704 if ne n len s
705 ret false
706 end
707 i = ulong 0
708 while lt i n
709 if ne get STRPOOL add off i get s i
710 ret false
711 end
712 i = add i 1
713 end
714 ret true
715end
716
717fn skip_ws to void
718 p = get JPOS 0
719 n = get JLEN 0
720 while lt p n
721 c = get JBUF p
722 if and ne c 32 and ne c 9 and ne c 10 ne c 13
723 break
724 end
725 p = add p 1
726 end
727 put JPOS 0 p
728end
729
730fn hexv c uchar to long
731 if and ge c 48 le c 57
732 ret long sub c 48
733 end
734 if and ge c 97 le c 102
735 ret add 10 long sub c 97
736 end
737 if and ge c 65 le c 70
738 ret add 10 long sub c 65
739 end
740 ret neg long 1
741end
742
743fn read_hex4 to long
744 p = get JPOS 0
745 n = get JLEN 0
746 if lt sub n p 4
747 ret neg long 1
748 end
749 u = ulong 0
750 i = ulong 0
751 while lt i 4
752 h = hexv get JBUF add p i
753 if lt h 0
754 ret neg long 1
755 end
756 u = add mul u 16 ulong h
757 i = add i 1
758 end
759 put JPOS 0 add p 4
760 ret long u
761end
762
763fn parse_esc_u to long
764 cp = read_hex4
765 if lt cp 0
766 perr t_s2
767 ret neg long 1
768 end
769 ucp = ulong cp
770 if and ge ucp 55296 lt ucp 56320
771 p = get JPOS 0
772 n = get JLEN 0
773 if lt sub n p 6
774 perr t_s3
775 ret neg long 1
776 end
777 if or ne get JBUF p 92 ne get JBUF add p 1 117
778 perr t_s3
779 ret neg long 1
780 end
781 put JPOS 0 add p 2
782 lo = read_hex4
783 if or lt lo 56320 gt lo 57343
784 perr t_s3
785 ret neg long 1
786 end
787 ucp = add 65536 add shl sub ucp 55296 10 sub ulong lo 56320
788 else
789 if and ge ucp 56320 le ucp 57343
790 perr t_s3
791 ret neg long 1
792 end
793 end
794 if eq ucp 0
795 perr t_s4
796 ret neg long 1
797 end
798 ret long ucp
799end
800
801fn parse_str_escape to bool
802 p = get JPOS 0
803 if ge p get JLEN 0
804 perr t_s5
805 ret false
806 end
807 e = get JBUF p
808 put JPOS 0 add p 1
809 if eq e 34
810 strpool_push 34
811 ret true
812 end
813 if eq e 92
814 strpool_push 92
815 ret true
816 end
817 if eq e 47
818 strpool_push 47
819 ret true
820 end
821 if eq e 98
822 strpool_push 8
823 ret true
824 end
825 if eq e 102
826 strpool_push 12
827 ret true
828 end
829 if eq e 110
830 strpool_push 10
831 ret true
832 end
833 if eq e 114
834 strpool_push 13
835 ret true
836 end
837 if eq e 116
838 strpool_push 9
839 ret true
840 end
841 if eq e 117
842 cp = parse_esc_u
843 if lt cp 0
844 ret false
845 end
846 strpool_put_utf8 ulong cp
847 ret true
848 end
849 perr t_s6
850 ret false
851end
852
853note returns packed (off << 32) | len, or -1 on error
854fn parse_str_raw to long
855 p = get JPOS 0
856 n = get JLEN 0
857 if or ge p n ne get JBUF p 34
858 perr t_s7
859 ret neg long 1
860 end
861 put JPOS 0 add p 1
862 start = get STRUSED 0
863 while true
864 p = get JPOS 0
865 if ge p n
866 perr t_s5
867 ret neg long 1
868 end
869 c = get JBUF p
870 if eq c 34
871 put JPOS 0 add p 1
872 slen = sub get STRUSED 0 start
873 ret long or shl start 32 slen
874 end
875 if lt c 32
876 perr t_s8
877 ret neg long 1
878 end
879 put JPOS 0 add p 1
880 if eq c 92
881 if not parse_str_escape
882 ret neg long 1
883 end
884 else
885 strpool_push c
886 end
887 end
888 ret neg long 1
889end
890
891fn parse_num_int start ulong endp ulong to long
892 p = start
893 neg_ = false
894 if eq get JBUF p 45
895 neg_ = true
896 p = add p 1
897 end
898 acc = ulong 0
899 lim = ulong 9223372036854775807
900 if neg_
901 lim = 9223372036854775808
902 end
903 while lt p endp
904 d = ulong sub get JBUF p 48
905 if gt acc div sub lim d 10
906 ret 0
907 end
908 acc = add mul acc 10 d
909 p = add p 1
910 end
911 id = jnew 2
912 put NB id 1
913 if neg_
914 if eq acc 9223372036854775808
915 put NI id sub neg long 9223372036854775807 1
916 else
917 put NI id sub 0 long acc
918 end
919 else
920 put NI id long acc
921 end
922 ret long add id 1
923end
924
925fn parse_num to long
926 s = get JPOS 0
927 n = get JLEN 0
928 p = s
929 frac = false
930 if lt p n
931 if eq get JBUF p 45
932 p = add p 1
933 end
934 end
935 if ge p n
936 perr t_s9
937 ret neg long 1
938 end
939 c0 = get JBUF p
940 if or lt c0 48 gt c0 57
941 perr t_s9
942 ret neg long 1
943 end
944 if eq c0 48
945 p = add p 1
946 else
947 while lt p n
948 c = get JBUF p
949 if or lt c 48 gt c 57
950 break
951 end
952 p = add p 1
953 end
954 end
955 has_dot = false
956 if lt p n
957 if eq get JBUF p 46
958 has_dot = true
959 end
960 end
961 if has_dot
962 frac = true
963 p = add p 1
964 dbad = ge p n
965 if not dbad
966 cd_ = get JBUF p
967 if or lt cd_ 48 gt cd_ 57
968 dbad = true
969 end
970 end
971 if dbad
972 perr t_s9
973 ret neg long 1
974 end
975 while lt p n
976 c = get JBUF p
977 if or lt c 48 gt c 57
978 break
979 end
980 p = add p 1
981 end
982 end
983 has_exp = false
984 if lt p n
985 ce_ = get JBUF p
986 if or eq ce_ 101 eq ce_ 69
987 has_exp = true
988 end
989 end
990 if has_exp
991 frac = true
992 p = add p 1
993 if lt p n
994 cs_ = get JBUF p
995 if or eq cs_ 43 eq cs_ 45
996 p = add p 1
997 end
998 end
999 dbad = ge p n
1000 if not dbad
1001 cd_ = get JBUF p
1002 if or lt cd_ 48 gt cd_ 57
1003 dbad = true
1004 end
1005 end
1006 if dbad
1007 perr t_s9
1008 ret neg long 1
1009 end
1010 while lt p n
1011 c = get JBUF p
1012 if or lt c 48 gt c 57
1013 break
1014 end
1015 p = add p 1
1016 end
1017 end
1018 if ge sub p s 64
1019 perr t_s10
1020 ret neg long 1
1021 end
1022 put JPOS 0 p
1023 if not frac
1024 r = parse_num_int s p
1025 if gt r 0
1026 ret sub r 1
1027 end
1028 end
1029 id = jnew 2
1030 put NB id 0
1031 put NI id 0
1032 ret long id
1033end
1034
1035fn match_lit lit view uchar * to bool
1036 p = get JPOS 0
1037 n = get JLEN 0
1038 m = len lit
1039 if lt sub n p m
1040 ret false
1041 end
1042 i = ulong 0
1043 while lt i m
1044 if ne get JBUF add p i get lit i
1045 ret false
1046 end
1047 i = add i 1
1048 end
1049 put JPOS 0 add p m
1050 ret true
1051end
1052
1053fn obj_has_key oid ulong koff ulong klen ulong to bool
1054 e = get NI oid
1055 while ge e 0
1056 ue = ulong e
1057 if strpool_eq get ENT_KOFF ue get ENT_KLEN ue koff klen
1058 ret true
1059 end
1060 e = get ENT_NEXT ue
1061 end
1062 ret false
1063end
1064
1065fn container_append cid ulong koff ulong klen ulong vid ulong to void
1066 eid = ent_new koff klen vid
1067 last = get NLAST cid
1068 if lt last 0
1069 put NI cid long eid
1070 else
1071 put ENT_NEXT ulong last long eid
1072 end
1073 put NLAST cid long eid
1074 put NC cid add get NC cid 1
1075end
1076
1077fn parse_obj_key cid ulong to long
1078 skip_ws
1079 kr = parse_str_raw
1080 if lt kr 0
1081 ret neg long 1
1082 end
1083 koff = shr ulong kr 32
1084 klen = and ulong kr 4294967295
1085 if obj_has_key cid koff klen
1086 perr t_s11
1087 ret neg long 1
1088 end
1089 skip_ws
1090 p = get JPOS 0
1091 if or ge p get JLEN 0 ne get JBUF p 58
1092 perr t_s12
1093 ret neg long 1
1094 end
1095 put JPOS 0 add p 1
1096 ret kr
1097end
1098
1099fn parse_container is_obj bool depth ulong to long
1100 t = uchar 4
1101 endch = uchar 93
1102 if is_obj
1103 t = 5
1104 endch = 125
1105 end
1106 cid = jnew t
1107 put JPOS 0 add get JPOS 0 1
1108 skip_ws
1109 if lt get JPOS 0 get JLEN 0
1110 if eq get JBUF get JPOS 0 endch
1111 put JPOS 0 add get JPOS 0 1
1112 ret long cid
1113 end
1114 end
1115 if false
1116 put JPOS 0 add get JPOS 0 1
1117 ret long cid
1118 end
1119 while true
1120 koff = ulong 0
1121 klen = ulong 0
1122 if is_obj
1123 kr = parse_obj_key cid
1124 if lt kr 0
1125 ret neg long 1
1126 end
1127 koff = shr ulong kr 32
1128 klen = and ulong kr 4294967295
1129 end
1130 ev = parse_val add depth 1
1131 if lt ev 0
1132 ret neg long 1
1133 end
1134 container_append cid koff klen ulong ev
1135 skip_ws
1136 p = get JPOS 0
1137 if lt p get JLEN 0
1138 ch = get JBUF p
1139 if eq ch 44
1140 put JPOS 0 add p 1
1141 continue
1142 end
1143 if eq ch endch
1144 put JPOS 0 add p 1
1145 ret long cid
1146 end
1147 end
1148 if is_obj
1149 perr t_s13
1150 else
1151 perr t_s14
1152 end
1153 ret neg long 1
1154 end
1155 ret neg long 1
1156end
1157
1158fn parse_val depth ulong to long
1159 if gt depth 32
1160 perr t_s15
1161 ret neg long 1
1162 end
1163 skip_ws
1164 p = get JPOS 0
1165 if ge p get JLEN 0
1166 perr t_s16
1167 ret neg long 1
1168 end
1169 c = get JBUF p
1170 if eq c 123
1171 ret parse_container true depth
1172 end
1173 if eq c 91
1174 ret parse_container false depth
1175 end
1176 if eq c 34
1177 sr = parse_str_raw
1178 if lt sr 0
1179 ret neg long 1
1180 end
1181 id = jnew 3
1182 put NI id long shr ulong sr 32
1183 put NC id and ulong sr 4294967295
1184 ret long id
1185 end
1186 if or eq c 45 and ge c 48 le c 57
1187 ret parse_num
1188 end
1189 if match_lit t_s17
1190 id = jnew 1
1191 put NB id 1
1192 ret long id
1193 end
1194 if match_lit t_s18
1195 id = jnew 1
1196 put NB id 0
1197 ret long id
1198 end
1199 if match_lit t_s19
1200 ret long jnew 0
1201 end
1202 perr t_s20
1203 ret neg long 1
1204end
1205
1206fn jparse_current to long
1207 err_reset
1208 put NUSED 0 0
1209 put EUSED 0 0
1210 put STRUSED 0 0
1211 put JPOS 0 0
1212 n = get JLEN 0
1213 i = ulong 0
1214 while lt i n
1215 if eq get JBUF i 0
1216 perr t_s21
1217 ret neg long 1
1218 end
1219 i = add i 1
1220 end
1221 v = parse_val 0
1222 if ge v 0
1223 skip_ws
1224 if ne get JPOS 0 n
1225 perr t_s22
1226 ret neg long 1
1227 end
1228 end
1229 ret v
1230end
1231
1232fn jget oid ulong key view uchar * to long
1233 if ne get NT oid 5
1234 ret neg long 1
1235 end
1236 e = get NI oid
1237 while ge e 0
1238 ue = ulong e
1239 if strpool_eq_lit get ENT_KOFF ue get ENT_KLEN ue key
1240 ret long get ENT_VAL ue
1241 end
1242 e = get ENT_NEXT ue
1243 end
1244 ret neg long 1
1245end
1246
1247fn strpool_eq_slice koff ulong s view uchar * off ulong n ulong to bool
1248 j = ulong 0
1249 while lt j n
1250 if ne get STRPOOL add koff j get s add off j
1251 ret false
1252 end
1253 j = add j 1
1254 end
1255 ret true
1256end
1257
1258fn jget_slice oid ulong s view uchar * off ulong n ulong to long
1259 if ne get NT oid 5
1260 ret neg long 1
1261 end
1262 e = get NI oid
1263 while ge e 0
1264 ue = ulong e
1265 if eq get ENT_KLEN ue n
1266 if strpool_eq_slice get ENT_KOFF ue s off n
1267 ret long get ENT_VAL ue
1268 end
1269 end
1270 e = get ENT_NEXT ue
1271 end
1272 ret neg long 1
1273end
1274
1275fn jpath oid ulong path view uchar * to long
1276 cur = long oid
1277 pos = ulong 0
1278 plen = len path
1279 while lt pos plen
1280 dot = pos
1281 while lt dot plen
1282 if eq get path dot 46
1283 break
1284 end
1285 dot = add dot 1
1286 end
1287 cur = jget_slice ulong cur path pos sub dot pos
1288 if lt cur 0
1289 ret neg long 1
1290 end
1291 if lt dot plen
1292 pos = add dot 1
1293 else
1294 pos = dot
1295 end
1296 end
1297 ret cur
1298end
1299
1300note ---- file reading ----
1301fn copy_argp_to_pbuf off ulong plen ulong to bool
1302 if gt plen 4095
1303 ret false
1304 end
1305 i = ulong 0
1306 while lt i plen
1307 put PBUF i get ARGP add off i
1308 i = add i 1
1309 end
1310 ret true
1311end
1312
1313fn read_path_into_fbuf use_argp bool off ulong plen ulong to bool
1314 if use_argp
1315 if not copy_argp_to_pbuf off plen
1316 ret false
1317 end
1318 end
1319 fd = fopen PBUF 0 plen 0 0
1320 if lt fd 0
1321 ret false
1322 end
1323 if lt len FBUF 4096
1324 r = enlarge FBUF 4096
1325 if lt r 0
1326 cr = fclose int fd
1327 if lt cr 0
1328 exit 2
1329 end
1330 write_all 2 t_s1
1331 exit 2
1332 end
1333 end
1334 n = ulong 0
1335 while true
1336 cap = len FBUF
1337 if eq n cap
1338 if ge cap 4194304
1339 cr = fclose int fd
1340 if lt cr 0
1341 ret false
1342 end
1343 ret false
1344 end
1345 r2 = enlarge FBUF mul cap 2
1346 if lt r2 0
1347 cr = fclose int fd
1348 if lt cr 0
1349 exit 2
1350 end
1351 write_all 2 t_s1
1352 exit 2
1353 end
1354 cap = len FBUF
1355 end
1356 got = read int fd FBUF n sub cap n
1357 if lt got 0
1358 cr = fclose int fd
1359 if lt cr 0
1360 ret false
1361 end
1362 ret false
1363 end
1364 if eq got 0
1365 break
1366 end
1367 n = add n ulong got
1368 end
1369 cr = fclose int fd
1370 put FLEN 0 n
1371 ret ge cr 0
1372end
1373
1374fn copy_fbuf_to_jbuf to void
1375 n = get FLEN 0
1376 if lt len JBUF n
1377 r = enlarge JBUF n
1378 if lt r 0
1379 write_all 2 t_s1
1380 exit 2
1381 end
1382 end
1383 i = ulong 0
1384 while lt i n
1385 put JBUF i get FBUF i
1386 i = add i 1
1387 end
1388 put JLEN 0 n
1389end
1390
1391fn copy_outbuf_to_jbuf to void
1392 n = get OUTLEN 0
1393 if lt len JBUF n
1394 r = enlarge JBUF n
1395 if lt r 0
1396 write_all 2 t_s1
1397 exit 2
1398 end
1399 end
1400 i = ulong 0
1401 while lt i n
1402 put JBUF i get OUTBUF i
1403 i = add i 1
1404 end
1405 put JLEN 0 n
1406end
1407
1408note ---- checker helpers ----
1409fn to_lower c uchar to uchar
1410 if and ge c 65 le c 90
1411 ret add c 32
1412 end
1413 ret c
1414end
1415
1416fn eq_ci_strpool off ulong n ulong lit view uchar * to bool
1417 if ne n len lit
1418 ret false
1419 end
1420 i = ulong 0
1421 while lt i n
1422 if ne to_lower get STRPOOL add off i get lit i
1423 ret false
1424 end
1425 i = add i 1
1426 end
1427 ret true
1428end
1429
1430fn is_placeholder_sp off ulong n ulong to bool
1431 s = off
1432 e = add off n
1433 while lt s e
1434 c = get STRPOOL s
1435 if and ne c 32 ne c 9
1436 break
1437 end
1438 s = add s 1
1439 end
1440 while gt e s
1441 c = get STRPOOL sub e 1
1442 if and ne c 32 ne c 9
1443 break
1444 end
1445 e = sub e 1
1446 end
1447 m = sub e s
1448 if eq m 0
1449 ret true
1450 end
1451 if or eq_ci_strpool s m t_s23 or eq_ci_strpool s m t_s24 or eq_ci_strpool s m t_s25 eq_ci_strpool s m t_s26
1452 ret true
1453 end
1454 if or eq_ci_strpool s m t_s27 or eq_ci_strpool s m t_s28 or eq_ci_strpool s m t_s29 eq_ci_strpool s m t_s30
1455 ret true
1456 end
1457 if or eq_ci_strpool s m t_s31 or eq_ci_strpool s m t_s19 or eq_ci_strpool s m t_s32 eq_ci_strpool s m t_s33
1458 ret true
1459 end
1460 if or eq_ci_strpool s m t_s34 or eq_ci_strpool s m t_s35 or eq_ci_strpool s m t_s36 eq_ci_strpool s m t_s37
1461 ret true
1462 end
1463 if or eq_ci_strpool s m t_s38 or eq_ci_strpool s m t_s39 or eq_ci_strpool s m t_s40 eq_ci_strpool s m t_s41
1464 ret true
1465 end
1466 ret false
1467end
1468
1469fn tmp_push c uchar to void
1470 n = get TMPL 0
1471 if lt n 511
1472 put TMPB n c
1473 put TMPL 0 add n 1
1474 end
1475end
1476
1477fn tmp_u64 v ulong to void
1478 buf = new uchar 24 0
1479 if eq v 0
1480 tmp_push 48
1481 ret
1482 end
1483 k = ulong 0
1484 while gt v 0
1485 put buf k uchar add 48 rem v 10
1486 v = div v 10
1487 k = add k 1
1488 end
1489 while gt k 0
1490 k = sub k 1
1491 tmp_push get buf k
1492 end
1493end
1494
1495fn err_tmp to void
1496 i = ulong 0
1497 n = get TMPL 0
1498 while lt i n
1499 err_push get TMPB i
1500 i = add i 1
1501 end
1502end
1503
1504fn scan_placeholders vid ulong to bool
1505 t = get NT vid
1506 if eq t 3
1507 off = ulong get NI vid
1508 n = get NC vid
1509 if is_placeholder_sp off n
1510 put ERROK 0 1
1511 put ERRLEN 0 0
1512 err_str t_s42
1513 err_strpool off n
1514 err_str t_s43
1515 err_tmp
1516 ret false
1517 end
1518 ret true
1519 end
1520 if or eq t 4 eq t 5
1521 e = get NI vid
1522 idx = ulong 0
1523 saved = get TMPL 0
1524 while ge e 0
1525 ue = ulong e
1526 put TMPL 0 saved
1527 if eq t 5
1528 koff = get ENT_KOFF ue
1529 klen = get ENT_KLEN ue
1530 if is_placeholder_sp koff klen
1531 put ERROK 0 1
1532 put ERRLEN 0 0
1533 err_str t_s44
1534 err_strpool koff klen
1535 err_str t_s45
1536 err_tmp
1537 ret false
1538 end
1539 tmp_push 46
1540 j = ulong 0
1541 while lt j klen
1542 tmp_push get STRPOOL add koff j
1543 j = add j 1
1544 end
1545 else
1546 tmp_push 91
1547 tmp_u64 idx
1548 tmp_push 93
1549 end
1550 if not scan_placeholders get ENT_VAL ue
1551 ret false
1552 end
1553 idx = add idx 1
1554 e = get ENT_NEXT ue
1555 end
1556 put TMPL 0 saved
1557 end
1558 ret true
1559end
1560
1561fn need_node oid ulong path view uchar * want_t uchar to long
1562 v = jpath oid path
1563 if lt v 0
1564 put ERROK 0 1
1565 put ERRLEN 0 0
1566 err_str t_s46
1567 err_str path
1568 ret neg long 1
1569 end
1570 if ne get NT ulong v want_t
1571 put ERROK 0 1
1572 put ERRLEN 0 0
1573 err_str t_s47
1574 err_str path
1575 err_str t_s48
1576 ret neg long 1
1577 end
1578 ret v
1579end
1580
1581fn need_i64 oid ulong path view uchar * minv long to long
1582 v = need_node oid path 2
1583 if lt v 0
1584 ret neg long 1
1585 end
1586 uv = ulong v
1587 if eq get NB uv 0
1588 put ERROK 0 1
1589 put ERRLEN 0 0
1590 err_str t_s47
1591 err_str path
1592 err_str t_s49
1593 ret neg long 1
1594 end
1595 iv = get NI uv
1596 if lt iv minv
1597 put ERROK 0 1
1598 put ERRLEN 0 0
1599 err_str t_s47
1600 err_str path
1601 err_str t_s50
1602 err_i64 iv
1603 err_str t_s51
1604 err_i64 minv
1605 ret neg long 1
1606 end
1607 ret v
1608end
1609
1610fn is_hex_sp off ulong n ulong want ulong to bool
1611 if ne n want
1612 ret false
1613 end
1614 i = ulong 0
1615 while lt i n
1616 c = get STRPOOL add off i
1617 ok = or and ge c 48 le c 57 and ge c 97 le c 102
1618 if not ok
1619 ret false
1620 end
1621 i = add i 1
1622 end
1623 ret true
1624end
1625
1626fn need_hex oid ulong path view uchar * want ulong to bool
1627 v = need_node oid path 3
1628 if lt v 0
1629 ret false
1630 end
1631 off = ulong get NI ulong v
1632 n = get NC ulong v
1633 if not is_hex_sp off n want
1634 put ERROK 0 1
1635 put ERRLEN 0 0
1636 err_str t_s47
1637 err_str path
1638 err_str t_s52
1639 err_strpool off n
1640 err_str t_s53
1641 err_u64 want
1642 err_str t_s54
1643 ret false
1644 end
1645 ret true
1646end
1647
1648fn need_str_list oid ulong path view uchar * to bool
1649 a = need_node oid path 4
1650 if lt a 0
1651 ret false
1652 end
1653 ua = ulong a
1654 if eq get NC ua 0
1655 put ERROK 0 1
1656 put ERRLEN 0 0
1657 err_str t_s47
1658 err_str path
1659 err_str t_s55
1660 ret false
1661 end
1662 e = get NI ua
1663 idx = ulong 0
1664 while ge e 0
1665 ue = ulong e
1666 if ne get NT get ENT_VAL ue 3
1667 put ERROK 0 1
1668 put ERRLEN 0 0
1669 err_str t_s47
1670 err_str path
1671 err_str t_s56
1672 err_u64 idx
1673 err_str t_s57
1674 ret false
1675 end
1676 idx = add idx 1
1677 e = get ENT_NEXT ue
1678 end
1679 ret true
1680end
1681
1682fn check_overhead_times sid ulong is_graph bool to bool
1683 vt = need_i64 sid t_s60 0
1684 vc = need_i64 sid t_s61 0
1685 vo = need_i64 sid t_s62 sub neg long 9223372036854775807 1
1686 if or lt vt 0 or lt vc 0 lt vo 0
1687 ret false
1688 end
1689 tot = get NI ulong vt
1690 chip = get NI ulong vc
1691 oh = get NI ulong vo
1692 if ne oh sub tot chip
1693 put ERROK 0 1
1694 put ERRLEN 0 0
1695 err_str t_s63
1696 if is_graph
1697 err_str t_s58
1698 else
1699 err_str t_s59
1700 end
1701 err_str t_s64
1702 err_i64 oh
1703 err_str t_s65
1704 err_i64 sub tot chip
1705 ret false
1706 end
1707 ret true
1708end
1709
1710fn check_overhead_launches sid ulong is_graph bool to bool
1711 vl = need_i64 sid t_s66 1
1712 vs = need_i64 sid t_s67 1
1713 if or lt vl 0 lt vs 0
1714 ret false
1715 end
1716 l = get NI ulong vl
1717 s = get NI ulong vs
1718 if gt s l
1719 put ERROK 0 1
1720 put ERRLEN 0 0
1721 if is_graph
1722 err_str t_s58
1723 else
1724 err_str t_s59
1725 end
1726 err_str t_s68
1727 err_i64 s
1728 err_str t_s69
1729 err_i64 l
1730 ret false
1731 end
1732 sd = jget sid t_s70
1733 if lt sd 0
1734 put ERROK 0 1
1735 put ERRLEN 0 0
1736 err_str t_s71
1737 if is_graph
1738 err_str t_s58
1739 else
1740 err_str t_s59
1741 end
1742 err_str t_s72
1743 ret false
1744 end
1745 usd = ulong sd
1746 if eq get NT usd 0
1747 if lt need_node sid t_s73 3 0
1748 ret false
1749 end
1750 else
1751 bad = ne get NT usd 2
1752 if not bad
1753 if eq get NB usd 0
1754 bad = true
1755 end
1756 end
1757 if not bad
1758 if ne get NI usd l
1759 bad = true
1760 end
1761 end
1762 if bad
1763 put ERROK 0 1
1764 put ERRLEN 0 0
1765 err_str t_s74
1766 if is_graph
1767 err_str t_s58
1768 else
1769 err_str t_s59
1770 end
1771 err_str t_s75
1772 ret false
1773 end
1774 end
1775 ret true
1776end
1777
1778fn check_overhead pt ulong is_graph bool to bool
1779 sub_id = long 0
1780 if is_graph
1781 sub_id = need_node pt t_s58 5
1782 else
1783 sub_id = need_node pt t_s59 5
1784 end
1785 if lt sub_id 0
1786 ret false
1787 end
1788 sid = ulong sub_id
1789 if not check_overhead_times sid is_graph
1790 ret false
1791 end
1792 ret check_overhead_launches sid is_graph
1793end
1794
1795global STG_ACC long 2
1796
1797fn check_one_stage g ulong idx ulong to bool
1798 if ne get NT g 5
1799 put ERROK 0 1
1800 put ERRLEN 0 0
1801 err_str t_s78
1802 err_u64 idx
1803 err_str t_s79
1804 ret false
1805 end
1806 if lt need_node g t_s80 3 0
1807 ret false
1808 end
1809 vgl = need_i64 g t_s66 1
1810 if lt vgl 0
1811 ret false
1812 end
1813 gl = get NI ulong vgl
1814 vgn = need_i64 g t_s81 0
1815 if lt vgn 0
1816 ret false
1817 end
1818 gn = get NI ulong vgn
1819 ssum = get STG_ACC 0
1820 lsum = get STG_ACC 1
1821 if or gt gn sub 9223372036854775807 ssum gt gl sub 9223372036854775807 lsum
1822 put ERROK 0 1
1823 put ERRLEN 0 0
1824 err_str t_s82
1825 err_u64 idx
1826 err_str t_s83
1827 ret false
1828 end
1829 put STG_ACC 0 add ssum gn
1830 put STG_ACC 1 add lsum gl
1831 ret true
1832end
1833
1834fn check_stages st ulong sl long span long sum long to bool
1835 stages = need_node st t_s76 4
1836 if lt stages 0
1837 ret false
1838 end
1839 ust = ulong stages
1840 if eq get NC ust 0
1841 put ERROK 0 1
1842 put ERRLEN 0 0
1843 err_str t_s77
1844 ret false
1845 end
1846 put STG_ACC 0 0
1847 put STG_ACC 1 0
1848 e = get NI ust
1849 idx = ulong 0
1850 while ge e 0
1851 ue = ulong e
1852 if not check_one_stage get ENT_VAL ue idx
1853 ret false
1854 end
1855 idx = add idx 1
1856 e = get ENT_NEXT ue
1857 end
1858 ssum = get STG_ACC 0
1859 lsum = get STG_ACC 1
1860 if ne ssum sum
1861 put ERROK 0 1
1862 put ERRLEN 0 0
1863 err_str t_s84
1864 err_i64 sum
1865 err_str t_s85
1866 err_i64 ssum
1867 ret false
1868 end
1869 if ne sum span
1870 put ERROK 0 1
1871 put ERRLEN 0 0
1872 err_str t_s86
1873 err_i64 sum
1874 err_str t_s87
1875 err_i64 span
1876 err_str t_s88
1877 ret false
1878 end
1879 if ne lsum sl
1880 put ERROK 0 1
1881 put ERRLEN 0 0
1882 err_str t_s89
1883 err_i64 lsum
1884 err_str t_s90
1885 err_i64 sl
1886 ret false
1887 end
1888 ret true
1889end
1890
1891fn check_stamped_token r ulong gl long to bool
1892 st = need_node r t_s99 5
1893 if lt st 0
1894 ret false
1895 end
1896 ust = ulong st
1897 v = need_i64 ust t_s66 1
1898 if lt v 0
1899 ret false
1900 end
1901 sl = get NI ulong v
1902 v = need_i64 ust t_s100 1
1903 if lt v 0
1904 ret false
1905 end
1906 span = get NI ulong v
1907 v = need_i64 ust t_s61 1
1908 if lt v 0
1909 ret false
1910 end
1911 chip = get NI ulong v
1912 v = need_i64 ust t_s101 sub neg long 9223372036854775807 1
1913 if lt v 0
1914 ret false
1915 end
1916 un = get NI ulong v
1917 v = need_i64 ust t_s102 0
1918 if lt v 0
1919 ret false
1920 end
1921 sum = get NI ulong v
1922 if gt span chip
1923 put ERROK 0 1
1924 put ERRLEN 0 0
1925 err_str t_s103
1926 err_i64 span
1927 err_str t_s104
1928 err_i64 chip
1929 err_str t_s105
1930 ret false
1931 end
1932 if ne un sub chip span
1933 put ERROK 0 1
1934 put ERRLEN 0 0
1935 err_str t_s106
1936 err_i64 un
1937 err_str t_s107
1938 err_i64 sub chip span
1939 ret false
1940 end
1941 if not check_stages ust sl span sum
1942 ret false
1943 end
1944 if ne gl sl
1945 put ERROK 0 1
1946 put ERRLEN 0 0
1947 err_str t_s109
1948 err_i64 sl
1949 err_str t_s110
1950 err_i64 gl
1951 ret false
1952 end
1953 ret true
1954end
1955
1956fn check_measurements r ulong to bool
1957 pt = need_node r t_s91 5
1958 if lt pt 0
1959 ret false
1960 end
1961 upt = ulong pt
1962 if lt need_node upt t_s92 3 0
1963 ret false
1964 end
1965 vtok = need_i64 r t_s93 1
1966 if lt vtok 0
1967 ret false
1968 end
1969 tokens = get NI ulong vtok
1970 vtm = need_i64 upt t_s94 1
1971 if lt vtm 0
1972 ret false
1973 end
1974 tokm = get NI ulong vtm
1975 if ne tokm tokens
1976 put ERROK 0 1
1977 put ERRLEN 0 0
1978 err_str t_s95
1979 err_i64 tokm
1980 err_str t_s96
1981 err_i64 tokens
1982 ret false
1983 end
1984 if not check_overhead upt true
1985 ret false
1986 end
1987 if lt need_i64 upt t_s97 0 0
1988 ret false
1989 end
1990 if not check_overhead upt false
1991 ret false
1992 end
1993 if lt need_node upt t_s98 1 0
1994 ret false
1995 end
1996 vgl = need_i64 upt t_s108 1
1997 if lt vgl 0
1998 ret false
1999 end
2000 ret check_stamped_token r get NI ulong vgl
2001end
2002
2003fn is_top_key off ulong n ulong to bool
2004 if or strpool_eq_lit off n t_s111 or strpool_eq_lit off n t_s112 or strpool_eq_lit off n t_s113 strpool_eq_lit off n t_s114
2005 ret true
2006 end
2007 if or strpool_eq_lit off n t_s115 or strpool_eq_lit off n t_s116 or strpool_eq_lit off n t_s117 strpool_eq_lit off n t_s118
2008 ret true
2009 end
2010 if or strpool_eq_lit off n t_s119 or strpool_eq_lit off n t_s120 or strpool_eq_lit off n t_s91 strpool_eq_lit off n t_s99
2011 ret true
2012 end
2013 if or strpool_eq_lit off n t_s121 or strpool_eq_lit off n t_s122 or strpool_eq_lit off n t_s123 or strpool_eq_lit off n t_s124 strpool_eq_lit off n t_s125
2014 ret true
2015 end
2016 ret false
2017end
2018
2019fn is_known_status off ulong n ulong to bool
2020 if or strpool_eq_lit off n t_s126 or strpool_eq_lit off n t_s127 strpool_eq_lit off n t_s128
2021 ret true
2022 end
2023 ret or strpool_eq_lit off n t_s129 or strpool_eq_lit off n t_s130 strpool_eq_lit off n t_s131
2024end
2025
2026fn check_repo_str off ulong n ulong to bool
2027 if eq n 0
2028 ret false
2029 end
2030 if eq get STRPOOL off 47
2031 ret false
2032 end
2033 has_sl = false
2034 i = ulong 0
2035 while lt i n
2036 c = get STRPOOL add off i
2037 if eq c 32
2038 ret false
2039 end
2040 if eq c 47
2041 has_sl = true
2042 end
2043 i = add i 1
2044 end
2045 ret has_sl
2046end
2047
2048fn check_ev_path_str off ulong n ulong to bool
2049 if eq n 0
2050 ret false
2051 end
2052 if eq get STRPOOL off 47
2053 ret false
2054 end
2055 i = ulong 0
2056 while lt i n
2057 c = get STRPOOL add off i
2058 if lt add i 1 n
2059 c2 = get STRPOOL add add off i 1
2060 if and eq c 46 eq c2 46
2061 ret false
2062 end
2063 if and eq c 47 eq c2 47
2064 ret false
2065 end
2066 end
2067 i = add i 1
2068 end
2069 ret true
2070end
2071
2072fn check_ev_exists ev_off ulong ev_len ulong p_off ulong p_len ulong to bool
2073 pos = ulong 0
2074 i = ulong 0
2075 while lt i ev_len
2076 put PBUF pos get ARGP add ev_off i
2077 pos = add pos 1
2078 i = add i 1
2079 end
2080 if or eq pos 0 ne get PBUF sub pos 1 47
2081 put PBUF pos 47
2082 pos = add pos 1
2083 end
2084 i = ulong 0
2085 while lt i p_len
2086 put PBUF pos get STRPOOL add p_off i
2087 pos = add pos 1
2088 i = add i 1
2089 end
2090 ret eq stat PBUF 0 pos STATBUF 0 128 0
2091end
2092
2093fn check_counters r ulong to bool
2094 if or lt need_node r t_s132 3 0 lt need_node r t_s133 3 0
2095 ret false
2096 end
2097 if or lt need_node r t_s134 3 0 lt need_node r t_s135 3 0
2098 ret false
2099 end
2100 if or lt need_node r t_s136 3 0 or lt need_node r t_s137 3 0 lt need_node r t_s138 3 0
2101 ret false
2102 end
2103 ret true
2104end
2105
2106fn check_evidence r ulong use_evroot bool to bool
2107 if or not need_str_list r t_s124 not need_str_list r t_s125
2108 ret false
2109 end
2110 ev = ulong jget r t_s124
2111 e = get NI ev
2112 while ge e 0
2113 ue = ulong e
2114 sv = get ENT_VAL ue
2115 poff = ulong get NI sv
2116 plen = get NC sv
2117 if not check_ev_path_str poff plen
2118 put ERROK 0 1
2119 put ERRLEN 0 0
2120 err_str t_s139
2121 err_strpool poff plen
2122 err_str t_s140
2123 ret false
2124 end
2125 if use_evroot
2126 eoff = get AOFF 1
2127 elen = get ALEN 1
2128 if not check_ev_exists eoff elen poff plen
2129 put ERROK 0 1
2130 put ERRLEN 0 0
2131 err_str t_s139
2132 err_strpool poff plen
2133 err_str t_s141
2134 err_argp eoff elen
2135 ret false
2136 end
2137 end
2138 e = get ENT_NEXT ue
2139 end
2140 ret true
2141end
2142
2143fn check_source_obj r ulong to long
2144 if or lt need_node r t_s116 5 0 not need_hex r t_s142 40
2145 ret neg long 1
2146 end
2147 vre = need_node r t_s143 3
2148 if lt vre 0
2149 ret neg long 1
2150 end
2151 roff = ulong get NI ulong vre
2152 rlen = get NC ulong vre
2153 if not check_repo_str roff rlen
2154 put ERROK 0 1
2155 put ERRLEN 0 0
2156 err_str t_s144
2157 err_strpool roff rlen
2158 err_str t_s145
2159 ret neg long 1
2160 end
2161 vdir = need_node r t_s146 1
2162 if lt vdir 0
2163 ret neg long 1
2164 end
2165 if ne get NB ulong vdir 0
2166 ret 1
2167 end
2168 ret 0
2169end
2170
2171fn check_status_and_source r ulong st_off ulong st_len ulong v_off ulong v_len ulong to bool
2172 dr = check_source_obj r
2173 if lt dr 0
2174 ret false
2175 end
2176 dirty = ne dr 0
2177 not_run = strpool_eq_lit st_off st_len t_s129
2178 v_nr = strpool_eq_lit v_off v_len t_s129
2179 if ne not_run v_nr
2180 put ERROK 0 1
2181 put ERRLEN 0 0
2182 err_str t_s147
2183 err_strpool st_off st_len
2184 err_str t_s148
2185 err_strpool v_off v_len
2186 err_str t_s149
2187 ret false
2188 end
2189 is_ver = strpool_eq_lit st_off st_len t_s126
2190 if and is_ver dirty
2191 put ERROK 0 1
2192 put ERRLEN 0 0
2193 err_str t_s150
2194 ret false
2195 end
2196 is_ve = or is_ver strpool_eq_lit st_off st_len t_s127
2197 if is_ve
2198 if not strpool_eq_lit v_off v_len t_s151
2199 put ERROK 0 1
2200 put ERRLEN 0 0
2201 err_str t_s152
2202 err_strpool st_off st_len
2203 err_str t_s153
2204 err_strpool v_off v_len
2205 err_str t_s149
2206 ret false
2207 end
2208 end
2209 ret true
2210end
2211
2212fn check_receipt_body r ulong stoff ulong stlen ulong to bool
2213 if lt need_node r t_s118 5 0
2214 ret false
2215 end
2216 if lt need_node r t_s164 3 0
2217 ret false
2218 end
2219 if lt need_node r t_s165 3 0
2220 ret false
2221 end
2222 if lt need_node r t_s166 3 0
2223 ret false
2224 end
2225 if lt need_i64 r t_s93 1 0
2226 ret false
2227 end
2228 if lt need_node r t_s119 5 0
2229 ret false
2230 end
2231 if lt need_node r t_s167 3 0
2232 ret false
2233 end
2234 vgpu = need_node r t_s168 3
2235 if lt vgpu 0
2236 ret false
2237 end
2238 is_ve = or strpool_eq_lit stoff stlen t_s126 strpool_eq_lit stoff stlen t_s127
2239 if is_ve
2240 if strpool_eq_lit ulong get NI ulong vgpu get NC ulong vgpu t_s169
2241 put ERROK 0 1
2242 put ERRLEN 0 0
2243 err_str t_s152
2244 err_strpool stoff stlen
2245 err_str t_s170
2246 err_strpool stoff stlen
2247 ret false
2248 end
2249 end
2250 if lt need_node r t_s120 5 0
2251 ret false
2252 end
2253 if lt need_node r t_s171 3 0
2254 ret false
2255 end
2256 if strpool_eq_lit stoff stlen t_s129
2257 if lt need_node r t_s115 3 0
2258 ret false
2259 end
2260 pt = jget r t_s91
2261 st = jget r t_s99
2262 bad = or lt pt 0 lt st 0
2263 if not bad
2264 if ne get NT ulong pt 0
2265 bad = true
2266 end
2267 if ne get NT ulong st 0
2268 bad = true
2269 end
2270 end
2271 if bad
2272 put ERROK 0 1
2273 put ERRLEN 0 0
2274 err_str t_s172
2275 ret false
2276 end
2277 else
2278 if ge jget r t_s115 0
2279 put ERROK 0 1
2280 put ERRLEN 0 0
2281 err_str t_s173
2282 ret false
2283 end
2284 if not need_hex r t_s174 64
2285 ret false
2286 end
2287 if not need_hex r t_s175 64
2288 ret false
2289 end
2290 if not check_measurements r
2291 ret false
2292 end
2293 end
2294 ret true
2295end
2296
2297fn check_receipt_tail r ulong use_evroot bool to bool
2298 if lt need_node r t_s121 5 0
2299 ret false
2300 end
2301 if lt need_node r t_s122 5 0
2302 ret false
2303 end
2304 if lt need_node r t_s176 3 0
2305 ret false
2306 end
2307 if lt need_node r t_s177 3 0
2308 ret false
2309 end
2310 if lt need_node r t_s178 1 0
2311 ret false
2312 end
2313 if lt need_node r t_s179 3 0
2314 ret false
2315 end
2316 if lt need_node r t_s123 5 0
2317 ret false
2318 end
2319 if lt need_node r t_s180 3 0
2320 ret false
2321 end
2322 if lt need_node r t_s181 3 0
2323 ret false
2324 end
2325 if lt need_node r t_s182 5 0
2326 ret false
2327 end
2328 if not check_counters r
2329 ret false
2330 end
2331 ret check_evidence r use_evroot
2332end
2333
2334fn check_receipt_head r ulong to bool
2335 if ne get NT r 5
2336 put ERROK 0 1
2337 put ERRLEN 0 0
2338 err_str t_s154
2339 ret false
2340 end
2341 e = get NI r
2342 while ge e 0
2343 ue = ulong e
2344 koff = get ENT_KOFF ue
2345 klen = get ENT_KLEN ue
2346 if not is_top_key koff klen
2347 put ERROK 0 1
2348 put ERRLEN 0 0
2349 err_str t_s155
2350 err_strpool koff klen
2351 ret false
2352 end
2353 e = get ENT_NEXT ue
2354 end
2355 vsc = need_node r t_s111 3
2356 if lt vsc 0
2357 ret false
2358 end
2359 scoff = ulong get NI ulong vsc
2360 sclen = get NC ulong vsc
2361 if not strpool_eq_lit scoff sclen t_s156
2362 put ERROK 0 1
2363 put ERRLEN 0 0
2364 err_str t_s157
2365 err_strpool scoff sclen
2366 err_str t_s158
2367 ret false
2368 end
2369 put TMPL 0 0
2370 i = ulong 0
2371 while lt i 7
2372 tmp_push get t_s159 i
2373 i = add i 1
2374 end
2375 ret scan_placeholders r
2376end
2377
2378fn check_receipt r ulong use_evroot bool to bool
2379 if not check_receipt_head r
2380 ret false
2381 end
2382 vst = need_node r t_s112 3
2383 if lt vst 0
2384 ret false
2385 end
2386 stoff = ulong get NI ulong vst
2387 stlen = get NC ulong vst
2388 if not is_known_status stoff stlen
2389 put ERROK 0 1
2390 put ERRLEN 0 0
2391 err_str t_s160
2392 err_strpool stoff stlen
2393 err_str t_s161
2394 ret false
2395 end
2396 if lt need_node r t_s113 3 0
2397 ret false
2398 end
2399 vv = need_node r t_s114 3
2400 if lt vv 0
2401 ret false
2402 end
2403 voff = ulong get NI ulong vv
2404 vlen = get NC ulong vv
2405 vok = or strpool_eq_lit voff vlen t_s151 strpool_eq_lit voff vlen t_s130
2406 if not or vok strpool_eq_lit voff vlen t_s129
2407 put ERROK 0 1
2408 put ERRLEN 0 0
2409 err_str t_s162
2410 err_strpool voff vlen
2411 err_str t_s163
2412 ret false
2413 end
2414 if not check_status_and_source r stoff stlen voff vlen
2415 ret false
2416 end
2417 if not check_receipt_body r stoff stlen
2418 ret false
2419 end
2420 ret check_receipt_tail r use_evroot
2421end
2422
2423fn check_jbuf use_evroot bool to bool
2424 r = jparse_current
2425 if lt r 0
2426 ret false
2427 end
2428 ret check_receipt ulong r use_evroot
2429end
2430
2431note ---- JSON writer (pretty, fixed key order) ----
2432fn out_push c uchar to void
2433 n = get OUTLEN 0
2434 if ge n len OUTBUF
2435 nc = mul n 2
2436 if lt nc 8192
2437 nc = 8192
2438 end
2439 r = enlarge OUTBUF nc
2440 if lt r 0
2441 write_all 2 t_s1
2442 exit 2
2443 end
2444 end
2445 put OUTBUF n c
2446 put OUTLEN 0 add n 1
2447end
2448
2449fn out_raw s view uchar * to void
2450 i = ulong 0
2451 n = len s
2452 while lt i n
2453 out_push get s i
2454 i = add i 1
2455 end
2456end
2457
2458fn out_u64 v ulong to void
2459 tmp = new uchar 24 0
2460 if eq v 0
2461 out_push 48
2462 ret
2463 end
2464 k = ulong 0
2465 while gt v 0
2466 put tmp k uchar add 48 rem v 10
2467 v = div v 10
2468 k = add k 1
2469 end
2470 while gt k 0
2471 k = sub k 1
2472 out_push get tmp k
2473 end
2474end
2475
2476fn out_i64 v long to void
2477 if lt v 0
2478 out_push 45
2479 if eq v sub neg long 9223372036854775807 1
2480 out_u64 9223372036854775808
2481 else
2482 out_u64 ulong neg v
2483 end
2484 ret
2485 end
2486 out_u64 ulong v
2487end
2488
2489fn hex_ch v ulong to uchar
2490 if lt v 10
2491 ret uchar add 48 v
2492 end
2493 ret uchar add 87 v
2494end
2495
2496fn out_jchar c uchar to void
2497 if or eq c 34 eq c 92
2498 out_push 92
2499 out_push c
2500 ret
2501 end
2502 if eq c 10
2503 out_raw t_s183
2504 ret
2505 end
2506 if eq c 9
2507 out_raw t_s184
2508 ret
2509 end
2510 if lt c 32
2511 out_raw t_s185
2512 out_push hex_ch shr ulong c 4
2513 out_push hex_ch and ulong c 15
2514 ret
2515 end
2516 out_push c
2517end
2518
2519fn out_jstr_lit s view uchar * to void
2520 i = ulong 0
2521 n = len s
2522 while lt i n
2523 out_jchar get s i
2524 i = add i 1
2525 end
2526end
2527
2528fn out_jstr_argp off ulong n ulong to void
2529 i = ulong 0
2530 while lt i n
2531 out_jchar get ARGP add off i
2532 i = add i 1
2533 end
2534end
2535
2536fn out_jstr_sp off ulong n ulong to void
2537 i = ulong 0
2538 while lt i n
2539 out_jchar get STRPOOL add off i
2540 i = add i 1
2541 end
2542end
2543
2544fn w_indent to void
2545 out_push 10
2546 d = get WDEPTH 0
2547 i = ulong 0
2548 while lt i d
2549 out_raw t_s186
2550 i = add i 1
2551 end
2552end
2553
2554fn w_key k view uchar * to void
2555 d = get WDEPTH 0
2556 if eq get WFIRST d 0
2557 out_push 44
2558 end
2559 put WFIRST d 0
2560 w_indent
2561 if gt len k 0
2562 out_push 34
2563 out_jstr_lit k
2564 out_raw t_s187
2565 end
2566end
2567
2568fn w_open k view uchar * ch uchar to void
2569 w_key k
2570 out_push ch
2571 d = add get WDEPTH 0 1
2572 put WDEPTH 0 d
2573 put WFIRST d 1
2574end
2575
2576fn w_close ch uchar to void
2577 d = get WDEPTH 0
2578 empty = ne get WFIRST d 0
2579 put WDEPTH 0 sub d 1
2580 if not empty
2581 w_indent
2582 end
2583 out_push ch
2584end
2585
2586fn kv_s k view uchar * v view uchar * to void
2587 w_key k
2588 out_push 34
2589 out_jstr_lit v
2590 out_push 34
2591end
2592
2593fn kv_argp k view uchar * off ulong n ulong to void
2594 w_key k
2595 out_push 34
2596 out_jstr_argp off n
2597 out_push 34
2598end
2599
2600fn kv_sp k view uchar * off ulong n ulong to void
2601 w_key k
2602 out_push 34
2603 out_jstr_sp off n
2604 out_push 34
2605end
2606
2607fn kv_i k view uchar * v long to void
2608 w_key k
2609 out_i64 v
2610end
2611
2612fn kv_b k view uchar * v bool to void
2613 w_key k
2614 if v
2615 out_raw t_s17
2616 else
2617 out_raw t_s18
2618 end
2619end
2620
2621fn kv_null k view uchar * to void
2622 w_key k
2623 out_raw t_s19
2624end
2625
2626note ---- ARGP pool helpers ----
2627fn argp_push c uchar to void
2628 n = get ARGU 0
2629 if ge n len ARGP
2630 nc = mul n 2
2631 if lt nc 4096
2632 nc = 4096
2633 end
2634 r = enlarge ARGP nc
2635 if lt r 0
2636 write_all 2 t_s1
2637 exit 2
2638 end
2639 end
2640 put ARGP n c
2641 put ARGU 0 add n 1
2642end
2643
2644fn argp_store_fbuf off ulong n ulong to ulong
2645 start = get ARGU 0
2646 i = ulong 0
2647 while lt i n
2648 argp_push get FBUF add off i
2649 i = add i 1
2650 end
2651 ret start
2652end
2653
2654fn argp_store_lit s view uchar * to ulong
2655 start = get ARGU 0
2656 i = ulong 0
2657 n = len s
2658 while lt i n
2659 argp_push get s i
2660 i = add i 1
2661 end
2662 ret start
2663end
2664
2665fn argp_join dir_off ulong dir_len ulong name view uchar * slot ulong to void
2666 start = get ARGU 0
2667 i = ulong 0
2668 while lt i dir_len
2669 argp_push get ARGP add dir_off i
2670 i = add i 1
2671 end
2672 if or eq dir_len 0 ne get ARGP sub add dir_off dir_len 1 47
2673 argp_push 47
2674 end
2675 i = ulong 0
2676 n = len name
2677 while lt i n
2678 argp_push get name i
2679 i = add i 1
2680 end
2681 put G_OFF slot start
2682 put G_LEN slot sub get ARGU 0 start
2683end
2684
2685fn argp_eq_lit off ulong n ulong s view uchar * to bool
2686 if ne n len s
2687 ret false
2688 end
2689 i = ulong 0
2690 while lt i n
2691 if ne get ARGP add off i get s i
2692 ret false
2693 end
2694 i = add i 1
2695 end
2696 ret true
2697end
2698
2699note ---- generator input parsers ----
2700fn fbuf_starts off ulong lend ulong lit view uchar * to bool
2701 m = len lit
2702 if lt sub lend off m
2703 ret false
2704 end
2705 i = ulong 0
2706 while lt i m
2707 if ne get FBUF add off i get lit i
2708 ret false
2709 end
2710 i = add i 1
2711 end
2712 ret true
2713end
2714
2715fn fbuf_eq off ulong n ulong lit view uchar * to bool
2716 if ne n len lit
2717 ret false
2718 end
2719 i = ulong 0
2720 while lt i n
2721 if ne get FBUF add off i get lit i
2722 ret false
2723 end
2724 i = add i 1
2725 end
2726 ret true
2727end
2728
2729fn fbuf_find off ulong lend ulong lit view uchar * to long
2730 m = len lit
2731 if or eq m 0 lt sub lend off m
2732 ret neg long 1
2733 end
2734 lim = sub lend m
2735 i = off
2736 while le i lim
2737 j = ulong 0
2738 ok = true
2739 while lt j m
2740 if ne get FBUF add i j get lit j
2741 ok = false
2742 break
2743 end
2744 j = add j 1
2745 end
2746 if ok
2747 ret long i
2748 end
2749 i = add i 1
2750 end
2751 ret neg long 1
2752end
2753
2754fn parse_dec_fbuf off ulong lend ulong to long
2755 if ge off lend
2756 ret neg long 1
2757 end
2758 v = long 0
2759 i = off
2760 while lt i lend
2761 c = get FBUF i
2762 if or lt c 48 gt c 57
2763 ret neg long 1
2764 end
2765 v = add mul v 10 long sub c 48
2766 i = add i 1
2767 end
2768 ret v
2769end
2770
2771fn parse_device_start_line p ulong lend ulong to void
2772 first = true
2773 while lt p lend
2774 while lt p lend
2775 if ne get FBUF p 32
2776 break
2777 end
2778 p = add p 1
2779 end
2780 if ge p lend
2781 break
2782 end
2783 t0 = p
2784 while lt p lend
2785 if eq get FBUF p 32
2786 break
2787 end
2788 p = add p 1
2789 end
2790 t1 = p
2791 if first
2792 put DEV_OFF 0 argp_store_fbuf t0 sub t1 t0
2793 put DEV_LEN 0 sub t1 t0
2794 first = false
2795 continue
2796 end
2797 eqp = t0
2798 while lt eqp t1
2799 if eq get FBUF eqp 61
2800 break
2801 end
2802 eqp = add eqp 1
2803 end
2804 if ge eqp t1
2805 continue
2806 end
2807 klen = sub eqp t0
2808 v0 = add eqp 1
2809 vlen = sub t1 v0
2810 if fbuf_eq t0 klen t_s188
2811 put DEV_OFF 2 argp_store_fbuf v0 vlen
2812 put DEV_LEN 2 vlen
2813 end
2814 if fbuf_eq t0 klen t_s189
2815 put DEV_OFF 3 argp_store_fbuf v0 vlen
2816 put DEV_LEN 3 vlen
2817 end
2818 if fbuf_eq t0 klen t_s190
2819 put DEV_OFF 4 argp_store_fbuf v0 vlen
2820 put DEV_LEN 4 vlen
2821 end
2822 if fbuf_eq t0 klen t_s191
2823 put DEV_DIRTY 0 parse_dec_fbuf v0 t1
2824 end
2825 if fbuf_eq t0 klen t_s192
2826 put DEV_OFF 5 argp_store_fbuf v0 vlen
2827 put DEV_LEN 5 vlen
2828 end
2829 end
2830end
2831
2832fn parse_device_linux_line p ulong lend ulong to void
2833 note skip "Linux "
2834 while lt p lend
2835 if ne get FBUF p 32
2836 break
2837 end
2838 p = add p 1
2839 end
2840 h0 = p
2841 while lt p lend
2842 if eq get FBUF p 32
2843 break
2844 end
2845 p = add p 1
2846 end
2847 if gt p h0
2848 put DEV_OFF 6 argp_store_fbuf h0 sub p h0
2849 put DEV_LEN 6 sub p h0
2850 end
2851 while lt p lend
2852 if ne get FBUF p 32
2853 break
2854 end
2855 p = add p 1
2856 end
2857 k0 = p
2858 while lt p lend
2859 if eq get FBUF p 32
2860 break
2861 end
2862 p = add p 1
2863 end
2864 if gt p k0
2865 put DEV_OFF 7 argp_store_fbuf k0 sub p k0
2866 put DEV_LEN 7 sub p k0
2867 end
2868end
2869
2870fn read_device to bool
2871 if not read_path_into_fbuf true get G_OFF 0 get G_LEN 0
2872 err_reset
2873 err_str t_s193
2874 err_argp get G_OFF 0 get G_LEN 0
2875 ret false
2876 end
2877 i = ulong 0
2878 while lt i 10
2879 put DEV_OFF i 0
2880 put DEV_LEN i 0
2881 i = add i 1
2882 end
2883 put DEV_DIRTY 0 neg long 1
2884 pos = ulong 0
2885 n = get FLEN 0
2886 while lt pos n
2887 lend = pos
2888 while lt lend n
2889 if eq get FBUF lend 10
2890 break
2891 end
2892 lend = add lend 1
2893 end
2894 if fbuf_starts pos lend t_s194
2895 parse_device_start_line add pos 6 lend
2896 else
2897 if fbuf_starts pos lend t_s195
2898 e0 = add pos 4
2899 e1 = e0
2900 while lt e1 lend
2901 if eq get FBUF e1 32
2902 break
2903 end
2904 e1 = add e1 1
2905 end
2906 put DEV_OFF 1 argp_store_fbuf e0 sub e1 e0
2907 put DEV_LEN 1 sub e1 e0
2908 else
2909 if fbuf_starts pos lend t_s196
2910 parse_device_linux_line add pos 6 lend
2911 else
2912 if and fbuf_starts pos lend t_s197 eq get DEV_LEN 8 0
2913 cs = fbuf_find pos lend t_s198
2914 if ge cs 0
2915 ucs = ulong cs
2916 put DEV_OFF 8 argp_store_fbuf pos sub ucs pos
2917 put DEV_LEN 8 sub ucs pos
2918 d0 = add ucs 2
2919 put DEV_OFF 9 argp_store_fbuf d0 sub lend d0
2920 put DEV_LEN 9 sub lend d0
2921 else
2922 put DEV_OFF 8 argp_store_fbuf pos sub lend pos
2923 put DEV_LEN 8 sub lend pos
2924 end
2925 end
2926 end
2927 end
2928 end
2929 if lt lend n
2930 pos = add lend 1
2931 else
2932 pos = lend
2933 end
2934 end
2935 miss = eq get DEV_LEN 0 0
2936 if eq get DEV_LEN 3 0
2937 miss = true
2938 end
2939 if lt get DEV_DIRTY 0 0
2940 miss = true
2941 end
2942 if eq get DEV_LEN 6 0
2943 miss = true
2944 end
2945 if miss
2946 err_reset
2947 err_argp get G_OFF 0 get G_LEN 0
2948 err_str t_s199
2949 ret false
2950 end
2951 if eq get DEV_LEN 8 0
2952 nd = argp_store_lit t_s169
2953 put DEV_OFF 8 nd
2954 put DEV_LEN 8 13
2955 put DEV_OFF 9 nd
2956 put DEV_LEN 9 13
2957 end
2958 ret true
2959end
2960
2961fn fbuf_ends off ulong lend ulong suf view uchar * to bool
2962 m = len suf
2963 if lt sub lend off m
2964 ret false
2965 end
2966 st = sub lend m
2967 i = ulong 0
2968 while lt i m
2969 if ne get FBUF add st i get suf i
2970 ret false
2971 end
2972 i = add i 1
2973 end
2974 ret true
2975end
2976
2977fn fbuf_is_hex64 off ulong to bool
2978 i = ulong 0
2979 while lt i 64
2980 c = get FBUF add off i
2981 if not or and ge c 48 le c 57 and ge c 97 le c 102
2982 ret false
2983 end
2984 i = add i 1
2985 end
2986 ret true
2987end
2988
2989fn read_binaries to bool
2990 if not read_path_into_fbuf true get G_OFF 1 get G_LEN 1
2991 err_reset
2992 err_str t_s193
2993 err_argp get G_OFF 1 get G_LEN 1
2994 ret false
2995 end
2996 put BIN_SET 0 0
2997 put LIB_SET 0 0
2998 pos = ulong 0
2999 n = get FLEN 0
3000 while lt pos n
3001 lend = pos
3002 while lt lend n
3003 if eq get FBUF lend 10
3004 break
3005 end
3006 lend = add lend 1
3007 end
3008 if ge sub lend pos 66
3009 if fbuf_is_hex64 pos
3010 np = add pos 64
3011 while lt np lend
3012 ch_ = get FBUF np
3013 if and ne ch_ 32 ne ch_ 42
3014 break
3015 end
3016 np = add np 1
3017 end
3018 if fbuf_ends np lend t_s200
3019 j = ulong 0
3020 while lt j 64
3021 put BIN_SHA j get FBUF add pos j
3022 j = add j 1
3023 end
3024 put BIN_SET 0 1
3025 else
3026 if fbuf_ends np lend t_s201
3027 j = ulong 0
3028 while lt j 64
3029 put LIB_SHA j get FBUF add pos j
3030 j = add j 1
3031 end
3032 put LIB_SET 0 1
3033 end
3034 end
3035 end
3036 end
3037 if lt lend n
3038 pos = add lend 1
3039 else
3040 pos = lend
3041 end
3042 end
3043 if or eq get BIN_SET 0 0 eq get LIB_SET 0 0
3044 err_reset
3045 err_argp get G_OFF 1 get G_LEN 1
3046 err_str t_s202
3047 ret false
3048 end
3049 ret true
3050end
3051
3052fn parse_signed_at p ulong lend ulong to long
3053 neg_ = false
3054 if lt p lend
3055 if eq get FBUF p 45
3056 neg_ = true
3057 p = add p 1
3058 end
3059 end
3060 v = long 0
3061 while lt p lend
3062 c = get FBUF p
3063 if or lt c 48 gt c 57
3064 break
3065 end
3066 v = add mul v 10 long sub c 48
3067 p = add p 1
3068 end
3069 if neg_
3070 ret sub 0 v
3071 end
3072 ret v
3073end
3074
3075fn skip_signed_at p ulong lend ulong to ulong
3076 if lt p lend
3077 if eq get FBUF p 45
3078 p = add p 1
3079 end
3080 end
3081 while lt p lend
3082 c = get FBUF p
3083 if or lt c 48 gt c 57
3084 break
3085 end
3086 p = add p 1
3087 end
3088 ret p
3089end
3090
3091fn parse_pf_line pos ulong lend ulong to bool
3092 if not fbuf_starts pos lend t_s203
3093 ret false
3094 end
3095 p = add pos 16
3096 p1 = skip_signed_at p lend
3097 if eq p1 p
3098 ret false
3099 end
3100 pf = parse_signed_at p lend
3101 if not fbuf_starts p1 lend t_s204
3102 ret false
3103 end
3104 p2 = add p1 6
3105 p3 = skip_signed_at p2 lend
3106 if or eq p3 p2 or ge p3 lend ne get FBUF p3 41
3107 ret false
3108 end
3109 red = parse_signed_at p2 lend
3110 put K_PREF 0 pf
3111 put K_RED 0 red
3112 ret true
3113end
3114
3115fn store_bname b0 ulong b1 ulong to void
3116 blen = sub b1 b0
3117 if gt blen 63
3118 blen = 63
3119 end
3120 i = ulong 0
3121 while lt i blen
3122 put K_BNAME i get FBUF add b0 i
3123 i = add i 1
3124 end
3125 put K_BNLEN 0 blen
3126end
3127
3128fn parse_fp8_line pos ulong lend ulong to bool
3129 if not fbuf_starts pos lend t_s205
3130 ret false
3131 end
3132 p = add pos 19
3133 p1 = skip_signed_at p lend
3134 if eq p1 p
3135 ret false
3136 end
3137 fv = parse_signed_at p lend
3138 if not fbuf_starts p1 lend t_s206
3139 ret false
3140 end
3141 p2 = add p1 9
3142 p3 = skip_signed_at p2 lend
3143 if eq p3 p2
3144 ret false
3145 end
3146 bar = parse_signed_at p2 lend
3147 if not fbuf_starts p3 lend t_s207
3148 ret false
3149 end
3150 b0 = add p3 2
3151 b1 = b0
3152 while lt b1 lend
3153 if eq get FBUF b1 41
3154 break
3155 end
3156 b1 = add b1 1
3157 end
3158 if or eq b1 b0 ge b1 lend
3159 ret false
3160 end
3161 cf = fbuf_find b1 lend t_s208
3162 if lt cf 0
3163 ret false
3164 end
3165 c0 = add ulong cf 8
3166 c1 = skip_signed_at c0 lend
3167 if eq c1 c0
3168 ret false
3169 end
3170 ca = parse_signed_at c0 lend
3171 put K_FP8V 0 fv
3172 put K_BARR 0 bar
3173 put K_CACH 0 ca
3174 store_bname b0 b1
3175 ret true
3176end
3177
3178fn read_knobs to bool
3179 if not read_path_into_fbuf true get AOFF 4 get ALEN 4
3180 err_reset
3181 err_str t_s193
3182 err_argp get AOFF 4 get ALEN 4
3183 ret false
3184 end
3185 have_pf = false
3186 have_fp8 = false
3187 pos = ulong 0
3188 n = get FLEN 0
3189 while lt pos n
3190 lend = pos
3191 while lt lend n
3192 if eq get FBUF lend 10
3193 break
3194 end
3195 lend = add lend 1
3196 end
3197 if not have_pf
3198 if parse_pf_line pos lend
3199 have_pf = true
3200 end
3201 end
3202 if not have_fp8
3203 if parse_fp8_line pos lend
3204 have_fp8 = true
3205 end
3206 end
3207 if lt lend n
3208 pos = add lend 1
3209 else
3210 pos = lend
3211 end
3212 end
3213 if or not have_pf not have_fp8
3214 err_reset
3215 err_argp get AOFF 4 get ALEN 4
3216 err_str t_s209
3217 ret false
3218 end
3219 ret true
3220end
3221
3222fn read_build_log to void
3223 put G_LEN 3 0
3224 put G_BLOG_BYTES 0 0
3225 if not read_path_into_fbuf true get G_OFF 2 get G_LEN 2
3226 ret
3227 end
3228 n = get FLEN 0
3229 put G_BLOG_BYTES 0 n
3230 pos = ulong 0
3231 while lt pos n
3232 lend = pos
3233 while lt lend n
3234 if eq get FBUF lend 10
3235 break
3236 end
3237 lend = add lend 1
3238 end
3239 if ge fbuf_find pos lend t_s210 0
3240 put G_OFF 3 argp_store_fbuf pos sub lend pos
3241 put G_LEN 3 sub lend pos
3242 ret
3243 end
3244 if lt lend n
3245 pos = add lend 1
3246 else
3247 pos = lend
3248 end
3249 end
3250end
3251
3252fn sget sid ulong path view uchar * to long
3253 v = jpath sid path
3254 bad = lt v 0
3255 if not bad
3256 uv = ulong v
3257 if ne get NT uv 2
3258 bad = true
3259 end
3260 if eq get NB uv 0
3261 bad = true
3262 end
3263 if lt get NI uv 0
3264 bad = true
3265 end
3266 end
3267 if bad
3268 err_reset
3269 err_str t_s211
3270 err_str path
3271 err_str t_s212
3272 ret neg long 1
3273 end
3274 ret get NI ulong v
3275end
3276
3277fn is_stamp_kind off ulong n ulong to bool
3278 if or strpool_eq_lit off n t_s213 or strpool_eq_lit off n t_s214 or strpool_eq_lit off n t_s215 strpool_eq_lit off n t_s216
3279 ret true
3280 end
3281 if or strpool_eq_lit off n t_s217 or strpool_eq_lit off n t_s218 or strpool_eq_lit off n t_s219 strpool_eq_lit off n t_s220
3282 ret true
3283 end
3284 ret or strpool_eq_lit off n t_s221 or strpool_eq_lit off n t_s222 or strpool_eq_lit off n t_s223 strpool_eq_lit off n t_s224
3285end
3286
3287fn check_pk_entry arr ulong koff ulong klen ulong to bool
3288 bad = ne get NT arr 4
3289 if not bad
3290 if ne get NC arr 2
3291 bad = true
3292 end
3293 end
3294 if not bad
3295 e0 = ulong get NI arr
3296 e1 = ulong get ENT_NEXT e0
3297 v0 = get ENT_VAL e0
3298 v1 = get ENT_VAL e1
3299 if ne get NT v0 2
3300 bad = true
3301 end
3302 if eq get NB v0 0
3303 bad = true
3304 end
3305 if ne get NT v1 2
3306 bad = true
3307 end
3308 if eq get NB v1 0
3309 bad = true
3310 end
3311 if lt get NI v0 1
3312 bad = true
3313 end
3314 if lt get NI v1 0
3315 bad = true
3316 end
3317 end
3318 if bad
3319 err_reset
3320 err_str t_s255
3321 err_strpool koff klen
3322 err_str t_s256
3323 ret false
3324 end
3325 if not is_stamp_kind koff klen
3326 err_reset
3327 err_str t_s257
3328 err_strpool koff klen
3329 ret false
3330 end
3331 ret true
3332end
3333
3334fn check_pk_all pk ulong to bool
3335 e = get NI pk
3336 while ge e 0
3337 ue = ulong e
3338 if not check_pk_entry get ENT_VAL ue get ENT_KOFF ue get ENT_KLEN ue
3339 ret false
3340 end
3341 e = get ENT_NEXT ue
3342 end
3343 ret true
3344end
3345
3346fn extract_stats_tail s ulong to bool
3347 vd = jget s t_s246
3348 vbad = lt vd 0
3349 if not vbad
3350 if ne get NT ulong vd 3
3351 vbad = true
3352 end
3353 end
3354 if vbad
3355 err_reset
3356 err_str t_s247
3357 ret false
3358 end
3359 vdo = ulong get NI ulong vd
3360 vdl = get NC ulong vd
3361 if and not strpool_eq_lit vdo vdl t_s151 not strpool_eq_lit vdo vdl t_s130
3362 err_reset
3363 err_str t_s247
3364 ret false
3365 end
3366 put S_VERD_OFF 0 vdo
3367 put S_VERD_LEN 0 vdl
3368 pk = jpath s t_s248
3369 pbad = lt pk 0
3370 if not pbad
3371 if ne get NT ulong pk 5
3372 pbad = true
3373 end
3374 if eq get NC ulong pk 0
3375 pbad = true
3376 end
3377 end
3378 if pbad
3379 err_reset
3380 err_str t_s249
3381 ret false
3382 end
3383 put S_PK_ID 0 ulong pk
3384 mism = ne get S_CACH 0 get K_CACH 0
3385 if ne get S_RED 0 get K_RED 0
3386 mism = true
3387 end
3388 if mism
3389 err_reset
3390 err_str t_s250
3391 err_i64 get S_CACH 0
3392 err_str t_s251
3393 err_i64 get K_CACH 0
3394 err_str t_s252
3395 err_i64 get S_RED 0
3396 err_str t_s251
3397 err_i64 get K_RED 0
3398 err_str t_s253
3399 ret false
3400 end
3401 if and strpool_eq_lit vdo vdl t_s151 ne get S_FAILED 0 0
3402 err_reset
3403 err_str t_s254
3404 err_i64 get S_FAILED 0
3405 ret false
3406 end
3407 ret check_pk_all ulong pk
3408end
3409
3410fn extract_stats s ulong to bool
3411 v = sget s t_s225
3412 if lt v 0
3413 ret false
3414 end
3415 put S_LAYERS 0 v
3416 v = sget s t_s226
3417 if lt v 0
3418 ret false
3419 end
3420 put S_VOCAB 0 v
3421 v = sget s t_s227
3422 if lt v 0
3423 ret false
3424 end
3425 put S_POS 0 v
3426 v = sget s t_s228
3427 if lt v 0
3428 ret false
3429 end
3430 put S_REPS 0 v
3431 v = sget s t_s229
3432 if lt v 0
3433 ret false
3434 end
3435 put S_RED 0 v
3436 v = sget s t_s230
3437 if lt v 0
3438 ret false
3439 end
3440 put S_CACH 0 v
3441 v = sget s t_s231
3442 if lt v 0
3443 ret false
3444 end
3445 put S_CL 0 v
3446 v = sget s t_s232
3447 if lt v 0
3448 ret false
3449 end
3450 put S_CS 0 v
3451 v = sget s t_s233
3452 if lt v 0
3453 ret false
3454 end
3455 put S_TL 0 v
3456 v = sget s t_s234
3457 if lt v 0
3458 ret false
3459 end
3460 put S_SPAN 0 v
3461 v = sget s t_s235
3462 if lt v 0
3463 ret false
3464 end
3465 put S_TCHIP 0 v
3466 v = sget s t_s236
3467 if lt v 0
3468 ret false
3469 end
3470 put S_MT 0 v
3471 v = sget s t_s237
3472 if lt v 0
3473 ret false
3474 end
3475 put S_MC 0 v
3476 v = sget s t_s238
3477 if lt v 0
3478 ret false
3479 end
3480 put S_MR 0 v
3481 v = sget s t_s239
3482 if lt v 0
3483 ret false
3484 end
3485 put S_BT 0 v
3486 v = sget s t_s240
3487 if lt v 0
3488 ret false
3489 end
3490 put S_BC 0 v
3491 v = sget s t_s241
3492 if lt v 0
3493 ret false
3494 end
3495 put S_BL 0 v
3496 v = sget s t_s242
3497 if lt v 0
3498 ret false
3499 end
3500 put S_BS 0 v
3501 v = sget s t_s243
3502 if lt v 0
3503 ret false
3504 end
3505 put S_BID 0 v
3506 v = sget s t_s244
3507 if lt v 0
3508 ret false
3509 end
3510 put S_CHECKS 0 v
3511 v = sget s t_s245
3512 if lt v 0
3513 ret false
3514 end
3515 put S_FAILED 0 v
3516 ret extract_stats_tail s
3517end
3518
3519fn emit_head_and_meta to void
3520 kv_s t_s111 t_s156
3521 kv_argp t_s112 get AOFF 5 get ALEN 5
3522 w_key t_s113
3523 out_push 34
3524 if argp_eq_lit get AOFF 5 get ALEN 5 t_s128
3525 out_jstr_lit t_s258
3526 out_jstr_argp get AOFF 2 get ALEN 2
3527 out_jstr_lit t_s259
3528 out_jstr_argp get DEV_OFF 0 get DEV_LEN 0
3529 out_jstr_lit t_s260
3530 else
3531 out_jstr_lit t_s152
3532 out_jstr_argp get AOFF 5 get ALEN 5
3533 out_jstr_lit t_s261
3534 out_jstr_argp get AOFF 2 get ALEN 2
3535 out_jstr_lit t_s262
3536 out_jstr_argp get DEV_OFF 0 get DEV_LEN 0
3537 out_jstr_lit t_s149
3538 end
3539 out_push 34
3540 kv_sp t_s114 get S_VERD_OFF 0 get S_VERD_LEN 0
3541
3542 w_open t_s116 123
3543 kv_argp t_s263 get AOFF 6 get ALEN 6
3544 kv_argp t_s264 get DEV_OFF 3 get DEV_LEN 3
3545 kv_b t_s191 ne get DEV_DIRTY 0 0
3546 w_key t_s265
3547 out_raw t_s266
3548 out_i64 get DEV_DIRTY 0
3549 out_raw t_s267
3550 if gt get DEV_LEN 4 0
3551 kv_argp t_s190 get DEV_OFF 4 get DEV_LEN 4
3552 end
3553 if gt get DEV_LEN 5 0
3554 kv_argp t_s192 get DEV_OFF 5 get DEV_LEN 5
3555 end
3556 w_close 125
3557
3558 w_open t_s117 123
3559 kv_argp t_s268 get DEV_OFF 0 get DEV_LEN 0
3560 if gt get DEV_LEN 1 0
3561 kv_argp t_s269 get DEV_OFF 1 get DEV_LEN 1
3562 end
3563 if gt get DEV_LEN 2 0
3564 kv_argp t_s270 get DEV_OFF 2 get DEV_LEN 2
3565 end
3566 w_key t_s271
3567 out_push 34
3568 out_i64 get S_CHECKS 0
3569 out_raw t_s272
3570 out_i64 get S_FAILED 0
3571 out_raw t_s273
3572 w_close 125
3573end
3574
3575fn emit_workload_hw_build to void
3576 w_open t_s118 123
3577 kv_argp t_s274 get AOFF 7 get ALEN 7
3578 kv_argp t_s275 get AOFF 8 get ALEN 8
3579 kv_argp t_s188 get AOFF 9 get ALEN 9
3580 kv_i t_s94 get S_REPS 0
3581 w_key t_s276
3582 out_push 34
3583 out_i64 get S_REPS 0
3584 out_raw t_s277
3585 out_i64 get S_POS 0
3586 out_raw t_s278
3587 kv_i t_s225 get S_LAYERS 0
3588 kv_i t_s226 get S_VOCAB 0
3589 kv_i t_s227 get S_POS 0
3590 kv_b t_s230 ne get S_CACH 0 0
3591 kv_b t_s279 ne get K_PREF 0 0
3592 kv_b t_s280 ne get S_RED 0 0
3593 w_key t_s281
3594 out_push 34
3595 out_i64 get K_BARR 0
3596 out_raw t_s207
3597 i = ulong 0
3598 bn = get K_BNLEN 0
3599 while lt i bn
3600 out_jchar get K_BNAME i
3601 i = add i 1
3602 end
3603 out_raw t_s282
3604 kv_i t_s283 get K_FP8V 0
3605 w_close 125
3606
3607 w_open t_s119 123
3608 kv_argp t_s284 get DEV_OFF 6 get DEV_LEN 6
3609 if gt get DEV_LEN 7 0
3610 kv_argp t_s285 get DEV_OFF 7 get DEV_LEN 7
3611 end
3612 kv_argp t_s286 get DEV_OFF 8 get DEV_LEN 8
3613 kv_argp t_s287 get DEV_OFF 9 get DEV_LEN 9
3614 kv_s t_s288 t_s289
3615 w_close 125
3616
3617 w_open t_s120 123
3618 kv_argp t_s290 get AOFF 10 get ALEN 10
3619 w_key t_s291
3620 out_push 34
3621 i = ulong 0
3622 while lt i 64
3623 out_push get BIN_SHA i
3624 i = add i 1
3625 end
3626 out_push 34
3627 w_key t_s292
3628 out_push 34
3629 i = ulong 0
3630 while lt i 64
3631 out_push get LIB_SHA i
3632 i = add i 1
3633 end
3634 out_push 34
3635 if gt get G_LEN 3 0
3636 kv_argp t_s293 get G_OFF 3 get G_LEN 3
3637 else
3638 w_key t_s294
3639 out_push 34
3640 out_jstr_argp get G_OFF 2 get G_LEN 2
3641 out_raw t_s207
3642 out_u64 get G_BLOG_BYTES 0
3643 out_raw t_s295
3644 end
3645 w_close 125
3646end
3647
3648fn emit_measurements to void
3649 w_open t_s91 123
3650 w_key t_s92
3651 out_raw t_s296
3652 out_i64 get S_REPS 0
3653 out_raw t_s297
3654 kv_i t_s94 get S_REPS 0
3655 w_open t_s58 123
3656 kv_i t_s66 get S_CL 0
3657 kv_i t_s67 get S_CS 0
3658 kv_i t_s60 get S_MT 0
3659 kv_i t_s61 get S_MC 0
3660 kv_i t_s298 get S_MR 0
3661 kv_i t_s62 sub get S_MT 0 get S_MC 0
3662 kv_null t_s70
3663 kv_s t_s73 t_s299
3664 w_close 125
3665 w_open t_s59 123
3666 kv_i t_s66 get S_BL 0
3667 kv_i t_s67 get S_BS 0
3668 kv_i t_s60 get S_BT 0
3669 kv_i t_s61 get S_BC 0
3670 kv_i t_s62 sub get S_BT 0 get S_BC 0
3671 kv_null t_s70
3672 kv_s t_s73 t_s300
3673 kv_b t_s301 ne get S_BID 0 0
3674 kv_s t_s302 t_s303
3675 w_close 125
3676 w_close 125
3677
3678 w_open t_s99 123
3679 pk = get S_PK_ID 0
3680 ssum = long 0
3681 e = get NI pk
3682 while ge e 0
3683 ue = ulong e
3684 arr = get ENT_VAL ue
3685 e0 = ulong get NI arr
3686 e1 = ulong get ENT_NEXT e0
3687 ssum = add ssum get NI get ENT_VAL e1
3688 e = get ENT_NEXT ue
3689 end
3690 kv_i t_s66 get S_TL 0
3691 kv_i t_s100 get S_SPAN 0
3692 kv_i t_s61 get S_TCHIP 0
3693 kv_i t_s101 sub get S_TCHIP 0 get S_SPAN 0
3694 kv_i t_s102 ssum
3695 kv_s t_s302 t_s304
3696 w_open t_s76 91
3697 e = get NI pk
3698 while ge e 0
3699 ue = ulong e
3700 arr = get ENT_VAL ue
3701 e0 = ulong get NI arr
3702 e1 = ulong get ENT_NEXT e0
3703 w_open t_s305 123
3704 kv_sp t_s80 get ENT_KOFF ue get ENT_KLEN ue
3705 kv_i t_s66 get NI get ENT_VAL e0
3706 kv_i t_s81 get NI get ENT_VAL e1
3707 w_close 125
3708 e = get ENT_NEXT ue
3709 end
3710 w_close 93
3711 w_close 125
3712end
3713
3714fn emit_tail to void
3715 w_open t_s121 123
3716 kv_b t_s306 false
3717 kv_s t_s307 t_s308
3718 w_close 125
3719
3720 indep = long 0
3721 if ne get K_PREF 0 0
3722 indep = get S_LAYERS 0
3723 end
3724 w_open t_s122 123
3725 w_key t_s61
3726 out_raw t_s309
3727 out_i64 get S_CS 0
3728 out_raw t_s310
3729 out_i64 get S_BS 0
3730 out_raw t_s311
3731 if ne indep 0
3732 w_key t_s76
3733 out_raw t_s312
3734 out_i64 indep
3735 out_raw t_s313
3736 else
3737 if eq get K_BARR 0 1
3738 kv_s t_s76 t_s314
3739 else
3740 w_key t_s76
3741 out_raw t_s315
3742 out_i64 get K_BARR 0
3743 out_raw t_s207
3744 i = ulong 0
3745 bn = get K_BNLEN 0
3746 while lt i bn
3747 out_jchar get K_BNAME i
3748 i = add i 1
3749 end
3750 out_raw t_s316
3751 end
3752 end
3753 kv_b t_s317 false
3754 if ne indep 0
3755 kv_s t_s307 t_s318
3756 else
3757 kv_s t_s307 t_s319
3758 end
3759 w_close 125
3760
3761 w_open t_s123 123
3762 kv_s t_s320 t_s321
3763 kv_s t_s322 t_s323
3764 w_open t_s324 123
3765 kv_s t_s66 t_s325
3766 kv_s t_s67 t_s326
3767 kv_s t_s61 t_s327
3768 kv_s t_s298 t_s328
3769 kv_s t_s60 t_s329
3770 kv_s t_s70 t_s330
3771 kv_s t_s331 t_s332
3772 kv_s t_s62 t_s333
3773 w_close 125
3774 kv_s t_s116 t_s334
3775 w_close 125
3776
3777 w_open t_s124 91
3778 kv_argp t_s305 get AOFF 3 get ALEN 3
3779 kv_argp t_s305 get AOFF 4 get ALEN 4
3780 kv_argp t_s305 get G_OFF 0 get G_LEN 0
3781 kv_argp t_s305 get G_OFF 1 get G_LEN 1
3782 kv_argp t_s305 get G_OFF 2 get G_LEN 2
3783 i = ulong 0
3784 nev = get NEV 0
3785 while lt i nev
3786 kv_argp t_s305 get EV_OFF i get EV_LEN i
3787 i = add i 1
3788 end
3789 w_close 93
3790
3791 w_open t_s125 91
3792 kv_s t_s305 t_s335
3793 kv_s t_s305 t_s336
3794 kv_s t_s305 t_s337
3795 kv_s t_s305 t_s338
3796 kv_s t_s305 t_s339
3797 kv_s t_s305 t_s340
3798 if ne get DEV_DIRTY 0 0
3799 kv_s t_s305 t_s341
3800 end
3801 w_close 93
3802end
3803
3804fn print_err_line to void
3805 write_all 2 t_s342
3806 w = write 2 ERRBUF 0 get ERRLEN 0
3807 write_all 2 t_s343
3808 if lt w 0
3809 ret
3810 end
3811end
3812
3813fn run_generate to long
3814 if not read_path_into_fbuf true get AOFF 3 get ALEN 3
3815 write_all 2 t_s344
3816 w = write 2 ARGP get AOFF 3 get ALEN 3
3817 write_all 2 t_s343
3818 if lt w 0
3819 ret 2
3820 end
3821 ret 2
3822 end
3823 copy_fbuf_to_jbuf
3824 s = jparse_current
3825 if lt s 0
3826 write_all 2 t_s342
3827 w1 = write 2 ARGP get AOFF 3 get ALEN 3
3828 write_all 2 t_s345
3829 w2 = write 2 ERRBUF 0 get ERRLEN 0
3830 write_all 2 t_s343
3831 if or lt w1 0 lt w2 0
3832 ret 2
3833 end
3834 ret 2
3835 end
3836 argp_join get AOFF 2 get ALEN 2 t_s346 0
3837 argp_join get AOFF 2 get ALEN 2 t_s347 1
3838 argp_join get AOFF 2 get ALEN 2 t_s348 2
3839 if or not read_device or not read_binaries not read_knobs
3840 print_err_line
3841 ret 2
3842 end
3843 if not extract_stats ulong s
3844 print_err_line
3845 ret 2
3846 end
3847 read_build_log
3848 put OUTLEN 0 0
3849 put WDEPTH 0 1
3850 put WFIRST 0 1
3851 put WFIRST 1 1
3852 out_push 123
3853 emit_head_and_meta
3854 emit_workload_hw_build
3855 emit_measurements
3856 emit_tail
3857 w_close 125
3858 out_push 10
3859
3860 copy_outbuf_to_jbuf
3861 if not check_jbuf false
3862 write_all 2 t_s349
3863 w = write 2 ERRBUF 0 get ERRLEN 0
3864 write_all 2 t_s343
3865 if lt w 0
3866 ret 1
3867 end
3868 ret 1
3869 end
3870
3871 fd = long 1
3872 has_out = ne get ASET 11 0
3873 if has_out
3874 note O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC = 524865, mode 0644 = 420
3875 if not copy_argp_to_pbuf get AOFF 11 get ALEN 11
3876 fd = neg long 1
3877 else
3878 fd = fopen PBUF 0 get ALEN 11 524865 420
3879 end
3880 if lt fd 0
3881 write_all 2 t_s350
3882 w = write 2 ARGP get AOFF 11 get ALEN 11
3883 write_all 2 t_s343
3884 if lt w 0
3885 ret 2
3886 end
3887 ret 2
3888 end
3889 end
3890 n = get OUTLEN 0
3891 off = ulong 0
3892 wbad = false
3893 while lt off n
3894 w = write int fd OUTBUF off sub n off
3895 if le w 0
3896 wbad = true
3897 break
3898 end
3899 off = add off ulong w
3900 end
3901 if has_out
3902 cr = fclose int fd
3903 if lt cr 0
3904 wbad = true
3905 end
3906 end
3907 if wbad
3908 write_all 2 t_s351
3909 ret 2
3910 end
3911 ret 0
3912end
3913
3914fn usage to long
3915 write_all 2 t_s352
3916 ret 2
3917end
3918
3919fn read_arg_to_argp idx ulong to long
3920 tmp = new uchar 4096 0
3921 n = argread idx tmp 0 4095
3922 if lt n 0
3923 ret neg long 1
3924 end
3925 start = get ARGU 0
3926 i = ulong 0
3927 un = ulong n
3928 while lt i un
3929 argp_push get tmp i
3930 i = add i 1
3931 end
3932 ret long or shl start 32 un
3933end
3934
3935fn match_opt off ulong n ulong to long
3936 if argp_eq_lit off n t_s353
3937 ret 0
3938 end
3939 if argp_eq_lit off n t_s354
3940 ret 1
3941 end
3942 if argp_eq_lit off n t_s355
3943 ret 2
3944 end
3945 if argp_eq_lit off n t_s356
3946 ret 3
3947 end
3948 if argp_eq_lit off n t_s357
3949 ret 4
3950 end
3951 if argp_eq_lit off n t_s358
3952 ret 5
3953 end
3954 if argp_eq_lit off n t_s359
3955 ret 6
3956 end
3957 if argp_eq_lit off n t_s360
3958 ret 7
3959 end
3960 if argp_eq_lit off n t_s361
3961 ret 8
3962 end
3963 if argp_eq_lit off n t_s362
3964 ret 9
3965 end
3966 if argp_eq_lit off n t_s363
3967 ret 10
3968 end
3969 if argp_eq_lit off n t_s364
3970 ret 11
3971 end
3972 if argp_eq_lit off n t_s365
3973 ret 12
3974 end
3975 ret neg long 1
3976end
3977
3978fn push_ev off ulong n ulong to void
3979 cnt = get NEV 0
3980 if ge cnt len EV_OFF
3981 nc = mul cnt 2
3982 if lt nc 32
3983 nc = 32
3984 end
3985 r1 = enlarge EV_OFF nc
3986 r2 = enlarge EV_LEN nc
3987 if or lt r1 0 lt r2 0
3988 write_all 2 t_s1
3989 exit 2
3990 end
3991 end
3992 put EV_OFF cnt off
3993 put EV_LEN cnt n
3994 put NEV 0 add cnt 1
3995end
3996
3997fn main to int
3998 ac = ulong argcnt
3999 i = ulong 1
4000 while lt i ac
4001 or_ = read_arg_to_argp i
4002 if lt or_ 0
4003 ret int usage
4004 end
4005 ooff = shr ulong or_ 32
4006 olen = and ulong or_ 4294967295
4007 slot = match_opt ooff olen
4008 if lt slot 0
4009 ret int usage
4010 end
4011 if ge add i 1 ac
4012 ret int usage
4013 end
4014 vr = read_arg_to_argp add i 1
4015 if lt vr 0
4016 ret int usage
4017 end
4018 voff = shr ulong vr 32
4019 vlen = and ulong vr 4294967295
4020 if eq slot 12
4021 push_ev voff vlen
4022 else
4023 us = ulong slot
4024 if ne get ASET us 0
4025 ret int usage
4026 end
4027 put AOFF us voff
4028 put ALEN us vlen
4029 put ASET us 1
4030 end
4031 i = add i 2
4032 end
4033
4034 if ne get ASET 0 0
4035 j = ulong 2
4036 while lt j 12
4037 if ne get ASET j 0
4038 ret int usage
4039 end
4040 j = add j 1
4041 end
4042 if gt get NEV 0 0
4043 ret int usage
4044 end
4045 if not read_path_into_fbuf true get AOFF 0 get ALEN 0
4046 write_all 2 t_s344
4047 w = write 2 ARGP get AOFF 0 get ALEN 0
4048 write_all 2 t_s343
4049 if lt w 0
4050 ret 2
4051 end
4052 ret 2
4053 end
4054 copy_fbuf_to_jbuf
4055 ok = check_jbuf ne get ASET 1 0
4056 if not ok
4057 write_all 1 t_s366
4058 w1 = write 1 ARGP get AOFF 0 get ALEN 0
4059 write_all 1 t_s345
4060 w2 = write 1 ERRBUF 0 get ERRLEN 0
4061 write_all 1 t_s343
4062 if or lt w1 0 lt w2 0
4063 ret 1
4064 end
4065 ret 1
4066 end
4067 write_all 1 t_s367
4068 w3 = write 1 ARGP get AOFF 0 get ALEN 0
4069 write_all 1 t_s343
4070 if lt w3 0
4071 ret 0
4072 end
4073 ret 0
4074 end
4075
4076 if ne get ASET 1 0
4077 ret int usage
4078 end
4079 j = ulong 2
4080 while lt j 11
4081 if eq get ASET j 0
4082 ret int usage
4083 end
4084 j = add j 1
4085 end
4086 ret int run_generate
4087end