interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / doctrine / doctrine.om

1827 lines · 28177 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note doctrine: doctrine consistency check (aien-architecture#7) in seeded Omega (#316, #300).
3note Port of scripts/check_doctrine.sh (bash + GNU grep + gawk, LC_ALL=C): same inputs
4note (doctrine/*.md, docs/milestone-*-spec.md under ROOT), same checks 0-4, same output lines
5note and the same exit codes (0 pass, 1 fail, 2 ROOT unusable).
6note usage: doctrine [ROOT] (ROOT defaults to the current directory)
7note Every ERE of the script is hand-written as a matcher below; the ERE is kept in a note
8note above its matcher. Byte semantics everywhere (the script runs under LC_ALL=C): word
9note characters are [A-Za-z0-9_], [[:space:]] is 9-13 and 32, and gawk's bracket [-–] is
10note the four bytes 45, 226, 128, 147 (an en dash never matches it as one character).
11note Built only by seed/out/omc from aien-dev/omega-mv (tools/zero-legacy/omega.pin).
12
13text tbl "<!-- HISTORICAL-PROVENANCE:BEGIN -->\n<!-- HISTORICAL-PROVENANCE:END -->\nALPHA\nAlpha\nalpha.\nbin\nmanifest\nsha256\ndecode\nmemory-map\ncontrol-flow\naudit\nHandoff (EL1)\nEL1 Handoff\nEL1 handoff\nstrictly at **EL1\nEL1 Jump\nat EL1 privilege level\nMilestone\nMILESTONE\nSOVEREIGN_CLOSURE\nSOVEREIGN_MACHINE_CLOSURE\nAIEN_HUMAN_INTERFACE\n27\n28-\n31-\nilestone\nwenty-eight \nprecise \nmilestones\nhirty-one milestones\nMILESTONE \n— \n–\nM27\nBOOTSTRAP_SEED_ATLAS\nATLAS_BAREMETAL_BOOT\nATLAS_MEASUREMENT_CHAIN\nATLAS_STAGE2_ELIMINATION\nPHYSICS_CORE_MEMBRANE\nSENTINEL_GATE_\nAIEN_SEED_TRAINING\nAIEN_SEED_TOPOLOGY\n[COMPLETE]\n[IN PROGRESS]\n[REOPENED\n[COMPLETE / QEMU QUALIFIED]\n[QEMU QUALIFIED]\nPHYSICS_BOOT\nCOMPLETE\n| **M\n** |\nhysics \nero\nCOMPLETE / QEMU QUALIFIED\nCOMPLETE / HARDWARE BOUNDARY QUALIFIED\nCOMPLETE / CORRECTIVELY REQUALIFIED\nCOMPLETE / SILICON QUALIFIED\nREOPENED / IN PROGRESS\nIN PROGRESS\nPLANNED\nPhysics Zero Discovery\nGeneral AIEN\nFAIL [\n] \n: \nunbalanced-historical-marker\nalpha-naming\nfixed-el1-handoff\nobsolete-m27-closure\nobsolete-roadmap-generation\nretired-milestone-identifier\nstatus-outside-roadmap\nduplicate-roadmap-table\nphysics-zero-range\nroadmap-missing\nroadmap-structure\nmilestone-number-mismatch\nHISTORICAL-PROVENANCE marker without partner\ncanonical roadmap file not found\n expected row M\n, found M\n has unknown status \"\n\"\n is outside Physics Zero M27-M35\n must be in the Physics Zero Discovery era\n is outside General AIEN M36-M40\n expected 41 roadmap rows (M0-M40), found \n cited as M\n, is M\n in ROADMAP.md: \n----------------------------------------------------------------------\ncheck_doctrine: scanned \n files; \n failure(s); 0 deferred finding(s).\ncheck_doctrine: FAIL\ncheck_doctrine: PASS\ncheck_doctrine: cannot cd to \ndoctrine/ROADMAP.md\ndoctrine/\ndocs/\n.md\nmilestone-\n-spec.md\ndoctrine\ndocs\n:\n M\n.\n"
14
15note table entries by index:
16note 0 BEGIN marker, 1 END marker, 2-11 alpha-naming parts, 12-17 fixed-el1-handoff literals,
17note 18 Milestone, 19 MILESTONE, 20-22 m27 codes, 23 "27", 24-34 roadmap-generation parts
18note (32 is em dash + space, 33 is the en dash), 35-42 retired identifiers, 43-49 status parts,
19note 50 "| **M", 51 "** |", 52 "hysics ", 53 "ero", 54-60 roadmap statuses (49 is COMPLETE),
20note 61-62 eras, 63-65 report pieces, 66-77 check names (66 + check id), 78-90 messages,
21note 91-97 summary lines, 98 ROADMAP path, 99-105 directory and glob parts, 106 ":", 107 " M",
22note 108 "." (the default ROOT).
23
24global toff ulong 128
25global tlen ulong 128
26global fbuf uchar 8388608
27global flen ulong 1
28global fpath uchar 4096
29global fplen ulong 1
30global lb ulong 1
31global lx ulong 1
32global nl ulong 1
33global fs ulong 1
34global fe ulong 1
35global names uchar 65536
36global noff ulong 1024
37global nlen ulong 1024
38global ord ulong 1024
39global nf ulong 1
40global nused ulong 1
41global dbuf uchar 65536
42global sb uchar 128
43global nb uchar 24
44global fails ulong 1
45global mcode uchar 32768
46global moff ulong 512
47global mlen ulong 512
48global mnoff ulong 512
49global mnlen ulong 512
50global mcnt ulong 1
51global mused ulong 1
52global mi ulong 1
53
54note ---- the text table ----
55
56fn tinit to void
57k = ulong 0
58s = ulong 0
59for i ulong len tbl
60if eq get tbl i 10
61put toff k s
62put tlen k sub i s
63k = add k 1
64s = add i 1
65end
66end
67end
68
69note write table entry k to stdout
70fn wt k ulong to void
71r = write 1 tbl get toff k get tlen k
72end
73
74fn wnl to void
75put nb 0 10
76r = write 1 nb 0 1
77end
78
79fn wnum v ulong to void
80n = ulong 0
81if eq v 0
82put nb 23 48
83n = 1
84end
85x = v
86while gt x 0 bound 20
87put nb sub 23 n uchar add 48 rem x 10
88x = div x 10
89n = add n 1
90end
91r = write 1 nb sub 24 n n
92end
93
94note ---- bytes of the current line [lb, lx) of fbuf ----
95
96note byte at i inside the line, 0 at or past its end
97fn cb i ulong to ulong
98if lt i get lx 0
99ret ulong get fbuf i
100end
101ret 0
102end
103
104note table entry k is the text at i (inside the line)
105fn lit i ulong k ulong to bool
106m = get tlen k
107if gt add i m get lx 0
108ret false
109end
110o = get toff k
111for j ulong m
112if ne get fbuf add i j get tbl add o j
113ret false
114end
115end
116ret true
117end
118
119note table entry k occurs somewhere in the line
120fn has k ulong to bool
121m = get tlen k
122e = get lx 0
123if lt sub e get lb 0 m
124ret false
125end
126i = get lb 0
127e = sub e m
128while le i e bound 999999
129if lit i k
130ret true
131end
132i = add i 1
133end
134ret false
135end
136
137note ---- byte classes (C locale) ----
138
139fn isdg c ulong to bool
140if lt c 48
141ret false
142end
143ret le c 57
144end
145
146fn isup c ulong to bool
147if lt c 65
148ret false
149end
150ret le c 90
151end
152
153fn islo c ulong to bool
154if lt c 97
155ret false
156end
157ret le c 122
158end
159
160note [A-Za-z0-9]
161fn isan c ulong to bool
162if isdg c
163ret true
164end
165if isup c
166ret true
167end
168ret islo c
169end
170
171note word character of \b and \<: [A-Za-z0-9_]
172fn isw c ulong to bool
173if isan c
174ret true
175end
176ret eq c 95
177end
178
179note [A-Z0-9_]
180fn isid c ulong to bool
181if isup c
182ret true
183end
184if isdg c
185ret true
186end
187ret eq c 95
188end
189
190note [[:space:]]
191fn issp c ulong to bool
192if eq c 32
193ret true
194end
195if lt c 9
196ret false
197end
198ret le c 13
199end
200
201note \b before position i: line start or a non-word byte before i
202fn wbb i ulong to bool
203if le i get lb 0
204ret true
205end
206ret not isw ulong get fbuf sub i 1
207end
208
209note \b after a word byte ending just before i: line end or a non-word byte at i
210fn wba i ulong to bool
211ret not isw cb i
212end
213
214note ---- check 1: alpha-naming ----
215note ERE: \bALPHA\b|\bAlpha\b|\balpha\.(bin|manifest|sha256|decode|memory-map|control-flow|audit)\b
216
217fn alsuf j ulong to bool
218k = ulong 5
219while le k 11 bound 8
220if lit j k
221if wba add j get tlen k
222ret true
223end
224end
225k = add k 1
226end
227ret false
228end
229
230fn m1 to bool
231i = get lb 0
232while lt i get lx 0 bound 999999
233if wbb i
234if lit i 2
235if wba add i 5
236ret true
237end
238end
239if lit i 3
240if wba add i 5
241ret true
242end
243end
244if lit i 4
245if alsuf add i 6
246ret true
247end
248end
249end
250i = add i 1
251end
252ret false
253end
254
255note ---- check 1: fixed-el1-handoff ----
256note ERE: Monotonic Handoff \(EL1\)|Handoff \(EL1\)|EL1 [Hh]andoff|strictly at \*\*EL1|EL1 Jump|at EL1 privilege level
257note (the first alternative contains the second, so five literals decide)
258
259fn m2 to bool
260i = get lb 0
261while lt i get lx 0 bound 999999
262k = ulong 12
263while le k 17 bound 7
264if lit i k
265ret true
266end
267k = add k 1
268end
269i = add i 1
270end
271ret false
272end
273
274note ---- check 1: obsolete-m27-closure ----
275note ERE: (Milestone|MILESTONE|\bM) ?27\b[^|]*SOVEREIGN(_MACHINE)?_CLOSURE
276note | SOVEREIGN(_MACHINE)?_CLOSURE[^|]*(Milestone|MILESTONE|\bM) ?27\b
277note | (Milestone|MILESTONE|M) ?27\b[^|]*AIEN_HUMAN_INTERFACE
278note | AIEN_HUMAN_INTERFACE[^|]*(Milestone|MILESTONE|\bM) ?27\b
279
280note end of "(Milestone|MILESTONE|M) ?27\b" starting at i, 0 when none; bd 1 demands \b before a bare M
281fn tok27 i ulong bd ulong to ulong
282p = ulong 0
283if lit i 18
284p = add i 9
285end
286if lit i 19
287p = add i 9
288end
289if eq p 0
290if ne cb i 77
291ret 0
292end
293if eq bd 1
294if not wbb i
295ret 0
296end
297end
298p = add i 1
299end
300if eq cb p 32
301p = add p 1
302end
303if not lit p 23
304ret 0
305end
306if not wba add p 2
307ret 0
308end
309ret add p 2
310end
311
312note a token ends at or before s with no | between it and s
313fn m3a s ulong bd ulong to bool
314i = s
315while gt i get lb 0 bound 999999
316i = sub i 1
317if eq cb i 124
318ret false
319end
320e = tok27 i bd
321if ne e 0
322if le e s
323ret true
324end
325end
326end
327ret false
328end
329
330note a \b-token starts at or after e with no | between e and it
331fn m3b e ulong to bool
332i = e
333while lt i get lx 0 bound 999999
334if eq cb i 124
335ret false
336end
337if ne tok27 i 1 0
338ret true
339end
340i = add i 1
341end
342ret false
343end
344
345fn m3 to bool
346i = get lb 0
347while lt i get lx 0 bound 999999
348if or lit i 20 lit i 21
349if m3a i 1
350ret true
351end
352end
353if lit i 20
354if m3b add i 17
355ret true
356end
357end
358if lit i 21
359if m3b add i 25
360ret true
361end
362end
363if lit i 22
364if m3a i 0
365ret true
366end
367if m3b add i 20
368ret true
369end
370end
371i = add i 1
372end
373ret false
374end
375
376note ---- check 1: obsolete-roadmap-generation ----
377note ERE: \b(28|31)-[Mm]ilestone|[Tt]wenty-eight (precise )?milestones|[Tt]hirty-one milestones
378note | ^MILESTONE [0-9]+ +— |\bM[0-9]+ ?(-|–) ?M27\b
379
380fn m4a i ulong to bool
381if not wbb i
382ret false
383end
384if not or lit i 24 lit i 25
385ret false
386end
387c = cb add i 3
388if not or eq c 77 eq c 109
389ret false
390end
391ret lit add i 4 26
392end
393
394fn m4b i ulong to bool
395c = cb i
396if not or eq c 84 eq c 116
397ret false
398end
399if lit add i 1 30
400ret true
401end
402if not lit add i 1 27
403ret false
404end
405p = add i 13
406if lit p 28
407p = add p 8
408end
409ret lit p 29
410end
411
412fn m4c to bool
413p = get lb 0
414if not lit p 31
415ret false
416end
417p = add p 10
418if not isdg cb p
419ret false
420end
421while isdg cb p bound 999999
422p = add p 1
423end
424if ne cb p 32
425ret false
426end
427while eq cb p 32 bound 999999
428p = add p 1
429end
430ret lit p 32
431end
432
433note position after "-" or the en dash at p, 0 when neither
434fn dash p ulong to ulong
435if eq cb p 45
436ret add p 1
437end
438if lit p 33
439ret add p 3
440end
441ret 0
442end
443
444fn m4d i ulong to bool
445if not wbb i
446ret false
447end
448if ne cb i 77
449ret false
450end
451p = add i 1
452if not isdg cb p
453ret false
454end
455while isdg cb p bound 999999
456p = add p 1
457end
458if eq cb p 32
459p = add p 1
460end
461p = dash p
462if eq p 0
463ret false
464end
465if eq cb p 32
466p = add p 1
467end
468if not lit p 34
469ret false
470end
471ret wba add p 3
472end
473
474fn m4 to bool
475if m4c
476ret true
477end
478i = get lb 0
479while lt i get lx 0 bound 999999
480if m4a i
481ret true
482end
483if m4b i
484ret true
485end
486if m4d i
487ret true
488end
489i = add i 1
490end
491ret false
492end
493
494note ---- check 1: retired-milestone-identifier ----
495note ERE: \b(BOOTSTRAP_SEED_ATLAS|ATLAS_BAREMETAL_BOOT|ATLAS_MEASUREMENT_CHAIN|ATLAS_STAGE2_ELIMINATION
496note |PHYSICS_CORE_MEMBRANE|SENTINEL_GATE_[0-9]|AIEN_SEED_TRAINING|AIEN_SEED_TOPOLOGY)\b
497
498fn m5a i ulong to bool
499k = ulong 35
500while le k 42 bound 9
501if lit i k
502if eq k 40
503if isdg cb add i 14
504if wba add i 15
505ret true
506end
507end
508else
509if wba add i get tlen k
510ret true
511end
512end
513end
514k = add k 1
515end
516ret false
517end
518
519fn m5 to bool
520i = get lb 0
521while lt i get lx 0 bound 999999
522if wbb i
523if m5a i
524ret true
525end
526end
527i = add i 1
528end
529ret false
530end
531
532note ---- check 1: status-outside-roadmap ----
533note ERE: \[(COMPLETE|IN PROGRESS|REOPENED[^]]*|COMPLETE / QEMU QUALIFIED|QEMU QUALIFIED)\]|PHYSICS_BOOT[^|]*\bCOMPLETE\b
534
535fn m6a i ulong to bool
536j = add i 12
537while lt j get lx 0 bound 999999
538if eq cb j 124
539ret false
540end
541if lit j 49
542if wbb j
543if wba add j 8
544ret true
545end
546end
547end
548j = add j 1
549end
550ret false
551end
552
553fn m6b i ulong to bool
554j = add i 9
555while lt j get lx 0 bound 999999
556if eq cb j 93
557ret true
558end
559j = add j 1
560end
561ret false
562end
563
564fn m6 to bool
565i = get lb 0
566while lt i get lx 0 bound 999999
567if or lit i 43 lit i 44
568ret true
569end
570if or lit i 46 lit i 47
571ret true
572end
573if lit i 45
574if m6b i
575ret true
576end
577end
578if lit i 48
579if m6a i
580ret true
581end
582end
583i = add i 1
584end
585ret false
586end
587
588note ---- check 1: duplicate-roadmap-table ----
589note ERE: ^[[:space:]]*M[0-9]{1,2}:[[:space:]]+[A-Z][A-Z0-9_]{3,}|^\| \*\*M[0-9]{1,2}\*\* \|
590
591fn m7b to bool
592p = get lb 0
593if not lit p 50
594ret false
595end
596p = add p 5
597if not isdg cb p
598ret false
599end
600p = add p 1
601if isdg cb p
602p = add p 1
603end
604ret lit p 51
605end
606
607fn m7 to bool
608if m7b
609ret true
610end
611p = get lb 0
612while issp cb p bound 999999
613p = add p 1
614end
615if ne cb p 77
616ret false
617end
618p = add p 1
619if not isdg cb p
620ret false
621end
622p = add p 1
623if isdg cb p
624p = add p 1
625end
626if ne cb p 58
627ret false
628end
629p = add p 1
630if not issp cb p
631ret false
632end
633while issp cb p bound 999999
634p = add p 1
635end
636if not isup cb p
637ret false
638end
639p = add p 1
640n = ulong 0
641while isid cb p bound 999999
642p = add p 1
643n = add n 1
644end
645ret ge n 3
646end
647
648note ---- check 2: physics-zero-range ----
649note awk, leftmost-longest, one report per line:
650note while (match(s, /[Pp]hysics [Zz]ero[^.]{0,30}M[0-9]+ ?[-–] ?M[0-9]+|M[0-9]+ ?[-–] ?M[0-9]+ ?\([Pp]hysics [Zz]ero/))
651note t = matched; s = rest; match(t, /M[0-9]+ ?[-–] ?M[0-9]+/); r = that with spaces removed and – turned into -
652note if (r != "M27-M35") report the line and stop
653
654note one byte of gawk's C-locale bracket [-–]
655fn isdash c ulong to bool
656if eq c 45
657ret true
658end
659if eq c 226
660ret true
661end
662if eq c 128
663ret true
664end
665ret eq c 147
666end
667
668note end of M[0-9]+ ?[-–] ?M[0-9]+ at j, 0 when none
669fn rng j ulong to ulong
670if ne cb j 77
671ret 0
672end
673p = add j 1
674if not isdg cb p
675ret 0
676end
677while isdg cb p bound 999999
678p = add p 1
679end
680if eq cb p 32
681p = add p 1
682end
683if not isdash cb p
684ret 0
685end
686p = add p 1
687if eq cb p 32
688p = add p 1
689end
690if ne cb p 77
691ret 0
692end
693p = add p 1
694if not isdg cb p
695ret 0
696end
697while isdg cb p bound 999999
698p = add p 1
699end
700ret p
701end
702
703note [Pp]hysics [Zz]ero at i
704fn pz i ulong to bool
705c = cb i
706if not or eq c 80 eq c 112
707ret false
708end
709if not lit add i 1 52
710ret false
711end
712c = cb add i 8
713if not or eq c 90 eq c 122
714ret false
715end
716ret lit add i 9 53
717end
718
719note longest end of the first alternative at i, 0 when none
720fn alt1 i ulong to ulong
721if not pz i
722ret 0
723end
724b = add i 12
725best = ulong 0
726k = ulong 0
727while le k 30 bound 31
728if gt k 0
729if eq cb sub add b k 1 46
730break
731end
732end
733e = rng add b k
734if gt e best
735best = e
736end
737k = add k 1
738end
739ret best
740end
741
742note end of the second alternative at i, 0 when none
743fn alt2 i ulong to ulong
744p = rng i
745if eq p 0
746ret 0
747end
748if eq cb p 32
749p = add p 1
750end
751if ne cb p 40
752ret 0
753end
754if pz add p 1
755ret add p 13
756end
757ret 0
758end
759
760note the range at j (already known to match rng) normalizes to M27-M35
761fn rok j ulong to bool
762p = add j 1
763if not lit p 23
764ret false
765end
766p = add p 2
767if isdg cb p
768ret false
769end
770if eq cb p 32
771p = add p 1
772end
773if ne cb p 45
774ret false
775end
776p = add p 1
777if eq cb p 32
778p = add p 1
779end
780if ne cb p 77
781ret false
782end
783p = add p 1
784if ne cb p 51
785ret false
786end
787if ne cb add p 1 53
788ret false
789end
790ret not isdg cb add p 2
791end
792
793note inside t = [i, e): is the leftmost range not M27-M35
794fn m8t i ulong e ulong to bool
795sv = get lx 0
796put lx 0 e
797r = false
798j = i
799while lt j e bound 999999
800if ne rng j 0
801r = not rok j
802break
803end
804j = add j 1
805end
806put lx 0 sv
807ret r
808end
809
810fn m8 to bool
811pos = get lb 0
812while lt pos get lx 0 bound 999999
813i = pos
814e = ulong 0
815while lt i get lx 0 bound 999999
816a = alt1 i
817b = alt2 i
818if gt b a
819a = b
820end
821if gt a 0
822e = a
823break
824end
825i = add i 1
826end
827if eq e 0
828ret false
829end
830if m8t i e
831ret true
832end
833pos = e
834end
835ret false
836end
837
838note ---- roadmap rows (checks 3 and 4): fields split by | like awk -F'|' ----
839
840note field k of the line into [fs, fe); empty at the line end when the row has fewer fields
841fn fld k ulong to void
842p = get lb 0
843c = ulong 1
844while lt c k bound 999999
845if ge p get lx 0
846break
847end
848if eq cb p 124
849c = add c 1
850end
851p = add p 1
852end
853if lt c k
854put fs 0 get lx 0
855put fe 0 get lx 0
856ret
857end
858e = p
859while lt e get lx 0 bound 999999
860if eq cb e 124
861break
862end
863e = add e 1
864end
865put fs 0 p
866put fe 0 e
867end
868
869note gsub(/^ +| +$/, "") on the field
870fn trim to void
871s = get fs 0
872e = get fe 0
873while lt s e bound 999999
874if ne get fbuf s 32
875break
876end
877s = add s 1
878end
879while gt e s bound 999999
880if ne get fbuf sub e 1 32
881break
882end
883e = sub e 1
884end
885put fs 0 s
886put fe 0 e
887end
888
889note the field equals table entry k
890fn feq k ulong to bool
891if ne sub get fe 0 get fs 0 get tlen k
892ret false
893end
894ret lit get fs 0 k
895end
896
897note row regex ^\| \*\*M[0-9]+\*\* \|
898fn isrow to bool
899p = get lb 0
900if not lit p 50
901ret false
902end
903p = add p 5
904if not isdg cb p
905ret false
906end
907while isdg cb p bound 999999
908p = add p 1
909end
910ret lit p 51
911end
912
913note the row's number as awk computes it (m + 0)
914fn rowm to ulong
915p = add get lb 0 5
916m = ulong 0
917while isdg cb p bound 999999
918m = add mul m 10 sub cb p 48
919p = add p 1
920end
921ret m
922end
923
924note status in the roadmap's closed list
925fn stok to bool
926if feq 49
927ret true
928end
929k = ulong 54
930while le k 60 bound 8
931if feq k
932ret true
933end
934k = add k 1
935end
936ret false
937end
938
939note ---- reports ----
940
941note FAIL [check] path:line:␣ and count the failure
942fn hdr ci ulong to void
943wt 63
944wt add 66 ci
945wt 64
946r = write 1 fpath 0 get fplen 0
947wt 106
948wnum get nl 0
949wt 65
950put fails 0 add get fails 0 1
951end
952
953fn wline to void
954r = write 1 fbuf get lb 0 sub get lx 0 get lb 0
955end
956
957note sed 's/^[[:space:]]*//' | cut -c1-160
958fn wstrip to void
959s = get lb 0
960while issp cb s bound 999999
961s = add s 1
962end
963n = sub get lx 0 s
964if gt n 160
965n = 160
966end
967r = write 1 fbuf s n
968end
969
970fn rep ci ulong to void
971hdr ci
972if eq ci 8
973wline
974else
975wstrip
976end
977wnl
978end
979
980note roadmap-structure message " M<m><entry k>"
981fn rep3 m ulong k ulong to void
982hdr 10
983wt 107
984wnum m
985wt k
986wnl
987end
988
989fn c3era m ulong to void
990pzd = feq 61
991if pzd
992if or lt m 27 gt m 35
993rep3 m 84
994end
995end
996if and ge m 27 le m 35
997if not pzd
998rep3 m 85
999end
1000end
1001if feq 62
1002if or lt m 36 gt m 40
1003rep3 m 86
1004end
1005end
1006end
1007
1008note awk's row counter n is unset until the first row passes: printed before that, it is the
1009note empty string, not 0 (" expected row M, found M1"; "found " with no rows). Reproduced.
1010fn wcnt n ulong to void
1011if ne n 0
1012wnum n
1013end
1014end
1015
1016note one roadmap row; n = the row index expected
1017fn c3row n ulong to void
1018m = rowm
1019if ne m n
1020hdr 10
1021wt 80
1022wcnt n
1023wt 81
1024wnum m
1025wnl
1026end
1027fld 6
1028trim
1029if not stok
1030hdr 10
1031wt 107
1032wnum m
1033wt 82
1034r = write 1 fbuf get fs 0 sub get fe 0 get fs 0
1035wt 83
1036wnl
1037end
1038fld 3
1039trim
1040c3era m
1041end
1042
1043note ---- check 4: milestone-number-mismatch ----
1044note MAP: for each roadmap row, code = $4 without spaces and backticks -> number = $2 without " *M"
1045note (a digit string; awk compares it to the cited digits as strings; the last row for a code wins)
1046
1047note copy field bytes that are not ' ' and not x and not y into mcode at mused; return the length
1048fn mcopy x ulong y ulong to ulong
1049u = get mused 0
1050n = ulong 0
1051s = get fs 0
1052while lt s get fe 0 bound 999999
1053c = ulong get fbuf s
1054if ne c 32
1055if ne c x
1056if ne c y
1057put mcode add u n uchar c
1058n = add n 1
1059end
1060end
1061end
1062s = add s 1
1063end
1064put mused 0 add u n
1065ret n
1066end
1067
1068fn maprow to void
1069k = get mcnt 0
1070put moff k get mused 0
1071fld 4
1072put mlen k mcopy 96 96
1073if eq get mlen k 0
1074put mused 0 get moff k
1075ret
1076end
1077put mnoff k get mused 0
1078fld 2
1079put mnlen k mcopy 42 77
1080put mcnt 0 add k 1
1081end
1082
1083note the code [s, e) is in the map: mi = its last row
1084fn look s ulong e ulong to bool
1085k = get mcnt 0
1086while gt k 0 bound 512
1087k = sub k 1
1088if eq get mlen k sub e s
1089if same s get moff k get mlen k
1090put mi 0 k
1091ret true
1092end
1093end
1094end
1095ret false
1096end
1097
1098fn same s ulong o ulong n ulong to bool
1099for j ulong n
1100if ne get fbuf add s j get mcode add o j
1101ret false
1102end
1103end
1104ret true
1105end
1106
1107note the cited digits [d, e) equal the map number of row mi as strings
1108fn numeq d ulong e ulong to bool
1109k = get mi 0
1110if ne get mnlen k sub e d
1111ret false
1112end
1113ret same d get mnoff k get mnlen k
1114end
1115
1116fn rep4 cs ulong ce ulong ds ulong de ulong to void
1117hdr 11
1118r = write 1 fbuf cs sub ce cs
1119wt 88
1120r = write 1 fbuf ds sub de ds
1121wt 89
1122r = write 1 mcode get mnoff get mi 0 get mnlen get mi 0
1123wt 90
1124wline
1125wnl
1126end
1127
1128note first loop: (Milestones?|MILESTONE|\<M) ?[0-9]+[^A-Za-z0-9]{1,6}[A-Z][A-Z0-9_]+
1129note n = first digit run of t, c = the [A-Z][A-Z0-9_]+$ suffix of t
1130
1131note position after the keyword at i, 0 when none
1132fn kwa i ulong to ulong
1133if lit i 18
1134p = add i 9
1135if eq cb p 115
1136ret add p 1
1137end
1138ret p
1139end
1140if lit i 19
1141ret add i 9
1142end
1143if ne cb i 77
1144ret 0
1145end
1146if not wbb i
1147ret 0
1148end
1149ret add i 1
1150end
1151
1152fn ma i ulong to ulong
1153p = kwa i
1154if eq p 0
1155ret 0
1156end
1157if eq cb p 32
1158p = add p 1
1159end
1160if not isdg cb p
1161ret 0
1162end
1163while isdg cb p bound 999999
1164p = add p 1
1165end
1166q = p
1167g = ulong 0
1168while lt g 7 bound 8
1169if isan cb q
1170break
1171end
1172q = add q 1
1173g = add g 1
1174end
1175if lt g 1
1176ret 0
1177end
1178if gt g 6
1179ret 0
1180end
1181if not isup cb q
1182ret 0
1183end
1184r = add q 1
1185while isid cb r bound 999999
1186r = add r 1
1187end
1188if lt sub r q 2
1189ret 0
1190end
1191ret r
1192end
1193
1194fn ja i ulong e ulong to bool
1195q = e
1196while gt q i bound 999999
1197if not isid cb sub q 1
1198break
1199end
1200q = sub q 1
1201end
1202while not isup cb q bound 999999
1203q = add q 1
1204end
1205d = i
1206while not isdg cb d bound 999999
1207d = add d 1
1208end
1209n = d
1210while isdg cb n bound 999999
1211n = add n 1
1212end
1213if not look q e
1214ret false
1215end
1216if numeq d n
1217ret false
1218end
1219rep4 q e d n
1220ret true
1221end
1222
1223fn m9a to bool
1224pos = get lb 0
1225while lt pos get lx 0 bound 999999
1226i = pos
1227e = ulong 0
1228while lt i get lx 0 bound 999999
1229e = ma i
1230if gt e 0
1231break
1232end
1233i = add i 1
1234end
1235if eq e 0
1236ret false
1237end
1238if ja i e
1239ret true
1240end
1241pos = e
1242end
1243ret false
1244end
1245
1246note second loop: [A-Z][A-Z0-9_]+`?[^A-Za-z0-9]{1,4}\((Milestones?|MILESTONE|M) ?[0-9]+
1247note c = the ^[A-Z][A-Z0-9_]+ prefix of t, n = the [0-9]+$ suffix of t
1248
1249note position after "(Milestones?|MILESTONE|M) ?[0-9]+" at p, 0 when none
1250fn kwb p ulong to ulong
1251if lit p 18
1252p = add p 9
1253if eq cb p 115
1254p = add p 1
1255end
1256else
1257if lit p 19
1258p = add p 9
1259else
1260if ne cb p 77
1261ret 0
1262end
1263p = add p 1
1264end
1265end
1266if eq cb p 32
1267p = add p 1
1268end
1269if not isdg cb p
1270ret 0
1271end
1272while isdg cb p bound 999999
1273p = add p 1
1274end
1275ret p
1276end
1277
1278note longest end given the identifier ends at x: gap of 1..5 non-alnum bytes (5 only after a backtick), then (
1279fn mbg x ulong to ulong
1280best = ulong 0
1281g = ulong 1
1282while le g 5 bound 6
1283q = add x g
1284if isan cb sub q 1
1285break
1286end
1287if eq cb q 40
1288if or lt g 5 eq cb x 96
1289e = kwb add q 1
1290if gt e best
1291best = e
1292end
1293end
1294end
1295g = add g 1
1296end
1297ret best
1298end
1299
1300fn mb i ulong to ulong
1301if not isup cb i
1302ret 0
1303end
1304r = add i 1
1305while isid cb r bound 999999
1306r = add r 1
1307end
1308if lt sub r i 2
1309ret 0
1310end
1311best = ulong 0
1312x = add i 2
1313while le x r bound 999999
1314e = mbg x
1315if gt e best
1316best = e
1317end
1318x = add x 1
1319end
1320ret best
1321end
1322
1323fn jb i ulong e ulong to bool
1324r = add i 1
1325while isid cb r bound 999999
1326r = add r 1
1327end
1328d = e
1329while isdg cb sub d 1 bound 999999
1330d = sub d 1
1331end
1332if not look i r
1333ret false
1334end
1335if numeq d e
1336ret false
1337end
1338rep4 i r d e
1339ret true
1340end
1341
1342fn m9b to bool
1343pos = get lb 0
1344while lt pos get lx 0 bound 999999
1345i = pos
1346e = ulong 0
1347while lt i get lx 0 bound 999999
1348e = mb i
1349if gt e 0
1350break
1351end
1352i = add i 1
1353end
1354if eq e 0
1355ret false
1356end
1357if jb i e
1358ret true
1359end
1360pos = e
1361end
1362ret false
1363end
1364
1365fn m9 to bool
1366if m9a
1367ret true
1368end
1369ret m9b
1370end
1371
1372note ---- line walks over the loaded file ----
1373
1374fn eol s ulong to ulong
1375i = s
1376e = get flen 0
1377while lt i e bound 999999
1378if eq get fbuf i 10
1379ret i
1380end
1381i = add i 1
1382end
1383ret e
1384end
1385
1386fn mt ci ulong to bool
1387if eq ci 1
1388ret m1
1389end
1390if eq ci 2
1391ret m2
1392end
1393if eq ci 3
1394ret m3
1395end
1396if eq ci 4
1397ret m4
1398end
1399if eq ci 5
1400ret m5
1401end
1402if eq ci 6
1403ret m6
1404end
1405if eq ci 7
1406ret m7
1407end
1408if eq ci 8
1409ret m8
1410end
1411ret m9
1412end
1413
1414note normative lines: a line inside the historical markers is blank and matches nothing
1415fn scan ci ulong to void
1416hist = ulong 0
1417s = ulong 0
1418put nl 0 0
1419while lt s get flen 0 bound 999999
1420e = eol s
1421put nl 0 add get nl 0 1
1422put lb 0 s
1423put lx 0 e
1424if has 0
1425hist = 1
1426else
1427if has 1
1428hist = 0
1429else
1430if eq hist 0
1431if gt e s
1432if mt ci
1433if ne ci 11
1434rep ci
1435end
1436end
1437end
1438end
1439end
1440end
1441s = add e 1
1442end
1443end
1444
1445note check 0: the first unbalanced marker of the raw file. The awk prints NR and exits on a
1446note second BEGIN or a stray END; exit still runs its END rule, so a second BEGIN also prints the
1447note first BEGIN's line: the report's line field is then "NR\nopen". Reproduced, not corrected.
1448fn c0 to void
1449op = ulong 0
1450bad = ulong 0
1451s = ulong 0
1452put nl 0 0
1453while lt s get flen 0 bound 999999
1454e = eol s
1455put nl 0 add get nl 0 1
1456put lb 0 s
1457put lx 0 e
1458if has 0
1459if ne op 0
1460bad = get nl 0
1461break
1462end
1463op = get nl 0
1464else
1465if has 1
1466if eq op 0
1467bad = get nl 0
1468break
1469end
1470op = 0
1471end
1472end
1473s = add e 1
1474end
1475if eq bad 0
1476bad = op
1477op = 0
1478end
1479if ne bad 0
1480put nl 0 bad
1481hdr0 op
1482wt 78
1483wnl
1484end
1485end
1486
1487note FAIL [unbalanced-historical-marker] path:nl[\nop]:␣
1488fn hdr0 op ulong to void
1489wt 63
1490wt 66
1491wt 64
1492r = write 1 fpath 0 get fplen 0
1493wt 106
1494wnum get nl 0
1495if ne op 0
1496wnl
1497wnum op
1498end
1499wt 65
1500put fails 0 add get fails 0 1
1501end
1502
1503note check 3: roadmap structure, row by row, then the row count
1504fn c3 to void
1505hist = ulong 0
1506n = ulong 0
1507s = ulong 0
1508put nl 0 0
1509while lt s get flen 0 bound 999999
1510e = eol s
1511put nl 0 add get nl 0 1
1512put lb 0 s
1513put lx 0 e
1514if has 0
1515hist = 1
1516else
1517if has 1
1518hist = 0
1519else
1520if eq hist 0
1521if isrow
1522c3row n
1523n = add n 1
1524end
1525end
1526end
1527end
1528s = add e 1
1529end
1530if ne n 41
1531put nl 0 0
1532hdr 10
1533wt 87
1534wcnt n
1535wnl
1536end
1537end
1538
1539fn c4map to void
1540hist = ulong 0
1541s = ulong 0
1542while lt s get flen 0 bound 999999
1543e = eol s
1544put lb 0 s
1545put lx 0 e
1546if has 0
1547hist = 1
1548else
1549if has 1
1550hist = 0
1551else
1552if eq hist 0
1553if isrow
1554maprow
1555end
1556end
1557end
1558end
1559s = add e 1
1560end
1561end
1562
1563note ---- files ----
1564
1565note table entry k into fpath
1566fn setent k ulong to void
1567o = get toff k
1568n = get tlen k
1569for i ulong n
1570put fpath i get tbl add o i
1571end
1572put fplen 0 n
1573end
1574
1575note fpath[i..] is table entry k
1576fn plit i ulong k ulong to bool
1577o = get toff k
1578for j ulong get tlen k
1579if ne get fpath add i j get tbl add o j
1580ret false
1581end
1582end
1583ret true
1584end
1585
1586fn fileeq k ulong to bool
1587if ne get fplen 0 get tlen k
1588ret false
1589end
1590ret plit 0 k
1591end
1592
1593fn load to bool
1594put flen 0 0
1595fd = fopen fpath 0 get fplen 0 0 0
1596if lt fd 0
1597ret false
1598end
1599t = ulong 0
1600while lt t len fbuf bound 100000
1601r = read int fd fbuf t sub len fbuf t
1602if le r 0
1603break
1604end
1605t = add t ulong r
1606end
1607put flen 0 t
1608r = fclose int fd
1609ret true
1610end
1611
1612note [ -f fpath ]: stat follows symlinks; S_IFMT 61440, S_IFREG 32768
1613fn isreg to bool
1614r = stat fpath 0 get fplen 0 sb 0 128
1615if lt r 0
1616ret false
1617end
1618m = add ulong get sb 16 mul 256 ulong get sb 17
1619ret eq and m 61440 32768
1620end
1621
1622fn addname to void
1623n = get nf 0
1624u = get nused 0
1625put noff n u
1626put nlen n get fplen 0
1627for i ulong get fplen 0
1628put names add u i get fpath i
1629end
1630put nused 0 add u get fplen 0
1631put ord n n
1632put nf 0 add n 1
1633end
1634
1635fn less x ulong y ulong to bool
1636m = get nlen x
1637if gt m get nlen y
1638m = get nlen y
1639end
1640for i ulong m
1641a = ulong get names add get noff x i
1642b = ulong get names add get noff y i
1643if ne a b
1644ret lt a b
1645end
1646end
1647ret lt get nlen x get nlen y
1648end
1649
1650note bash glob order under LC_ALL=C: byte order, within [a, b) of ord
1651fn sortn a ulong b ulong to void
1652i = add a 1
1653while lt i b bound 1024
1654j = i
1655while gt j a bound 1024
1656if not less get ord j get ord sub j 1
1657break
1658end
1659t = get ord j
1660put ord j get ord sub j 1
1661put ord sub j 1 t
1662j = sub j 1
1663end
1664i = add i 1
1665end
1666end
1667
1668fn setpath k ulong to void
1669j = get ord k
1670o = get noff j
1671n = get nlen j
1672for i ulong n
1673put fpath i get names add o i
1674end
1675put fplen 0 n
1676end
1677
1678note the glob: kind 0 = doctrine/*.md, kind 1 = docs/milestone-*-spec.md; name at fpath[pl, pl+n)
1679fn pat pl ulong n ulong kind ulong to bool
1680if eq kind 0
1681if lt n 3
1682ret false
1683end
1684ret plit sub add pl n 3 101
1685end
1686if lt n 18
1687ret false
1688end
1689if not plit pl 102
1690ret false
1691end
1692ret plit sub add pl n 8 103
1693end
1694
1695fn reclen o ulong to ulong
1696lo = ulong get dbuf add o 16
1697hi = ulong get dbuf add o 17
1698ret add lo mul 256 hi
1699end
1700
1701note one getdents64 record at o; the prefix is already in fpath[0, fplen)
1702fn entry o ulong kind ulong to void
1703pl = get fplen 0
1704n = ulong 0
1705while ne get dbuf add o add 19 n 0 bound 256
1706put fpath add pl n get dbuf add o add 19 n
1707n = add n 1
1708end
1709if eq n 0
1710ret
1711end
1712if eq get fpath pl 46
1713ret
1714end
1715if not pat pl n kind
1716ret
1717end
1718put fplen 0 add pl n
1719if isreg
1720addname
1721end
1722put fplen 0 pl
1723end
1724
1725fn listdir kind ulong to void
1726a = get nf 0
1727setent add 104 kind
1728fd = fopen fpath 0 get fplen 0 16384 0
1729if lt fd 0
1730ret
1731end
1732setent add 99 kind
1733while true bound 100000
1734r = getdnts int fd dbuf 0 len dbuf
1735if le r 0
1736break
1737end
1738o = ulong 0
1739while lt o ulong r bound 65536
1740entry o kind
1741o = add o reclen o
1742end
1743end
1744r = fclose int fd
1745sortn a get nf 0
1746end
1747
1748note run check ci over every file (skip 1: not the roadmap)
1749fn pass ci ulong skip ulong to void
1750for k ulong get nf 0
1751setpath k
1752if eq skip 1
1753if fileeq 98
1754continue
1755end
1756end
1757if load
1758if eq ci 0
1759c0
1760else
1761scan ci
1762end
1763end
1764end
1765end
1766
1767fn main to int
1768tinit
1769put fplen 0 0
1770if ge argcnt 2
1771n = argread 1 fpath 0 4095
1772if gt n 0
1773put fplen 0 ulong n
1774end
1775end
1776if eq get fplen 0 0
1777setent 108
1778end
1779r = chdir fpath 0 get fplen 0
1780if ne r 0
1781r = write 2 tbl get toff 97 get tlen 97
1782r = write 2 fpath 0 get fplen 0
1783put nb 0 10
1784r = write 2 nb 0 1
1785ret 2
1786end
1787listdir 0
1788listdir 1
1789pass 0 0
1790pass 1 0
1791pass 2 0
1792pass 3 0
1793pass 4 0
1794pass 5 0
1795pass 6 1
1796pass 7 1
1797pass 8 1
1798setent 98
1799if not isreg
1800put nl 0 0
1801hdr 9
1802wt 79
1803wnl
1804else
1805if load
1806c3
1807c4map
1808end
1809pass 11 1
1810end
1811wt 91
1812wnl
1813wt 92
1814wnum get nf 0
1815wt 93
1816wnum get fails 0
1817wt 94
1818wnl
1819if gt get fails 0 0
1820wt 95
1821wnl
1822ret 1
1823end
1824wt 96
1825wnl
1826ret 0
1827end