@jhlagado/azm 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/README.md +239 -76
  2. package/dist/src/api-artifacts.d.ts +20 -0
  3. package/dist/src/api-artifacts.js +165 -0
  4. package/dist/src/api-compile.d.ts +8 -2
  5. package/dist/src/api-compile.js +55 -227
  6. package/dist/src/api-register-contracts.d.ts +9 -0
  7. package/dist/src/api-register-contracts.js +77 -0
  8. package/dist/src/api-tooling.d.ts +2 -2
  9. package/dist/src/api-tooling.js +1 -1
  10. package/dist/src/assembly/address-planning.d.ts +1 -2
  11. package/dist/src/assembly/address-planning.js +119 -218
  12. package/dist/src/assembly/address-symbols.d.ts +12 -0
  13. package/dist/src/assembly/address-symbols.js +118 -0
  14. package/dist/src/assembly/assemble-program.js +5 -0
  15. package/dist/src/assembly/fixup-emission.js +30 -48
  16. package/dist/src/assembly/import-visibility.d.ts +3 -0
  17. package/dist/src/assembly/import-visibility.js +204 -0
  18. package/dist/src/assembly/program-emission.js +163 -164
  19. package/dist/src/cli/artifact-files.d.ts +15 -0
  20. package/dist/src/cli/artifact-files.js +86 -0
  21. package/dist/src/cli/parse-args.d.ts +6 -5
  22. package/dist/src/cli/parse-args.js +162 -136
  23. package/dist/src/cli/run.js +4 -1
  24. package/dist/src/cli/usage.d.ts +1 -0
  25. package/dist/src/cli/usage.js +33 -0
  26. package/dist/src/cli/write-artifacts.js +18 -91
  27. package/dist/src/core/compile.js +51 -274
  28. package/dist/src/core/conditional-assembly.d.ts +6 -0
  29. package/dist/src/core/conditional-assembly.js +181 -0
  30. package/dist/src/expansion/op-constant-expression.d.ts +3 -0
  31. package/dist/src/expansion/op-constant-expression.js +52 -0
  32. package/dist/src/expansion/op-expand-selected.d.ts +5 -0
  33. package/dist/src/expansion/op-expand-selected.js +143 -0
  34. package/dist/src/expansion/op-expansion.d.ts +5 -53
  35. package/dist/src/expansion/op-expansion.js +85 -815
  36. package/dist/src/expansion/op-instruction-instantiation.d.ts +3 -0
  37. package/dist/src/expansion/op-instruction-instantiation.js +194 -0
  38. package/dist/src/expansion/op-local-labels.d.ts +8 -0
  39. package/dist/src/expansion/op-local-labels.js +166 -0
  40. package/dist/src/expansion/op-operand-splitting.d.ts +1 -0
  41. package/dist/src/expansion/op-operand-splitting.js +44 -0
  42. package/dist/src/expansion/op-operands.d.ts +53 -0
  43. package/dist/src/expansion/op-operands.js +66 -0
  44. package/dist/src/expansion/op-selection.d.ts +18 -0
  45. package/dist/src/expansion/op-selection.js +172 -0
  46. package/dist/src/index.d.ts +2 -1
  47. package/dist/src/index.js +1 -1
  48. package/dist/src/model/diagnostic.d.ts +4 -0
  49. package/dist/src/model/diagnostic.js +4 -0
  50. package/dist/src/node/source-host.js +40 -13
  51. package/dist/src/outputs/asm80-expression-evaluation.d.ts +10 -0
  52. package/dist/src/outputs/asm80-expression-evaluation.js +75 -0
  53. package/dist/src/outputs/asm80-expressions.d.ts +5 -0
  54. package/dist/src/outputs/asm80-expressions.js +47 -0
  55. package/dist/src/outputs/asm80-instruction-operands.d.ts +16 -0
  56. package/dist/src/outputs/asm80-instruction-operands.js +38 -0
  57. package/dist/src/outputs/asm80-instructions.d.ts +5 -0
  58. package/dist/src/outputs/asm80-instructions.js +272 -0
  59. package/dist/src/outputs/asm80-ld-operands.d.ts +10 -0
  60. package/dist/src/outputs/asm80-ld-operands.js +157 -0
  61. package/dist/src/outputs/asm80-strings.d.ts +4 -0
  62. package/dist/src/outputs/asm80-strings.js +14 -0
  63. package/dist/src/outputs/d8-files.d.ts +10 -0
  64. package/dist/src/outputs/d8-files.js +103 -0
  65. package/dist/src/outputs/d8-helpers.d.ts +21 -0
  66. package/dist/src/outputs/d8-helpers.js +136 -0
  67. package/dist/src/outputs/hex.js +26 -18
  68. package/dist/src/outputs/types.d.ts +16 -10
  69. package/dist/src/outputs/write-asm80.js +72 -597
  70. package/dist/src/outputs/write-d8.js +6 -216
  71. package/dist/src/register-contracts/accept-output.d.ts +2 -0
  72. package/dist/src/register-contracts/analyze-helpers.d.ts +29 -0
  73. package/dist/src/register-contracts/analyze-helpers.js +162 -0
  74. package/dist/src/{register-care → register-contracts}/analyze.d.ts +6 -6
  75. package/dist/src/register-contracts/analyze.js +73 -0
  76. package/dist/src/register-contracts/annotate.d.ts +11 -0
  77. package/dist/src/{register-care → register-contracts}/annotate.js +3 -3
  78. package/dist/src/register-contracts/annotations.d.ts +8 -0
  79. package/dist/src/{register-care → register-contracts}/annotations.js +3 -3
  80. package/dist/src/register-contracts/boundaryHints.d.ts +3 -0
  81. package/dist/src/register-contracts/boundaryHints.js +24 -0
  82. package/dist/src/register-contracts/carriers.d.ts +2 -0
  83. package/dist/src/register-contracts/constants.d.ts +4 -0
  84. package/dist/src/register-contracts/constants.js +51 -0
  85. package/dist/src/register-contracts/controlFlow.d.ts +5 -0
  86. package/dist/src/register-contracts/controlFlow.js +55 -0
  87. package/dist/src/register-contracts/fix.d.ts +11 -0
  88. package/dist/src/{register-care → register-contracts}/fix.js +47 -30
  89. package/dist/src/register-contracts/instruction-head.d.ts +2 -0
  90. package/dist/src/register-contracts/instruction-head.js +3 -0
  91. package/dist/src/register-contracts/instruction-operands.d.ts +3 -0
  92. package/dist/src/register-contracts/instruction-operands.js +101 -0
  93. package/dist/src/register-contracts/instruction-predicates.d.ts +6 -0
  94. package/dist/src/register-contracts/instruction-predicates.js +44 -0
  95. package/dist/src/register-contracts/interfaceContracts.d.ts +2 -0
  96. package/dist/src/register-contracts/interfaceContracts.js +68 -0
  97. package/dist/src/register-contracts/liveness.d.ts +3 -0
  98. package/dist/src/{register-care → register-contracts}/liveness.js +111 -79
  99. package/dist/src/register-contracts/operand-register-name.d.ts +2 -0
  100. package/dist/src/register-contracts/operand-register-name.js +13 -0
  101. package/dist/src/{register-care → register-contracts}/profiles.d.ts +5 -5
  102. package/dist/src/{register-care → register-contracts}/profiles.js +2 -2
  103. package/dist/src/register-contracts/programModel-boundaries.d.ts +6 -0
  104. package/dist/src/register-contracts/programModel-boundaries.js +64 -0
  105. package/dist/src/register-contracts/programModel-routines.d.ts +7 -0
  106. package/dist/src/register-contracts/programModel-routines.js +144 -0
  107. package/dist/src/register-contracts/programModel.d.ts +3 -0
  108. package/dist/src/register-contracts/programModel.js +14 -0
  109. package/dist/src/register-contracts/report.d.ts +5 -0
  110. package/dist/src/{register-care → register-contracts}/report.js +34 -17
  111. package/dist/src/register-contracts/routine-summaries.d.ts +6 -0
  112. package/dist/src/{register-care → register-contracts}/routine-summaries.js +11 -1
  113. package/dist/src/register-contracts/smartCommentBlocks.d.ts +5 -0
  114. package/dist/src/register-contracts/smartCommentBlocks.js +30 -0
  115. package/dist/src/register-contracts/smartCommentParsing.d.ts +3 -0
  116. package/dist/src/register-contracts/smartCommentParsing.js +80 -0
  117. package/dist/src/register-contracts/smartComments.d.ts +5 -0
  118. package/dist/src/register-contracts/smartComments.js +92 -0
  119. package/dist/src/register-contracts/summaries.d.ts +12 -0
  120. package/dist/src/{register-care → register-contracts}/summaries.js +7 -7
  121. package/dist/src/register-contracts/summary-boundary.d.ts +2 -0
  122. package/dist/src/register-contracts/summary-boundary.js +40 -0
  123. package/dist/src/register-contracts/summary-contract.d.ts +2 -0
  124. package/dist/src/register-contracts/summary-contract.js +45 -0
  125. package/dist/src/register-contracts/summary-result.d.ts +7 -0
  126. package/dist/src/register-contracts/summary-result.js +122 -0
  127. package/dist/src/register-contracts/summary-state.d.ts +23 -0
  128. package/dist/src/register-contracts/summary-state.js +88 -0
  129. package/dist/src/register-contracts/summary-token-transfer.d.ts +3 -0
  130. package/dist/src/register-contracts/summary-token-transfer.js +67 -0
  131. package/dist/src/register-contracts/summary.d.ts +3 -0
  132. package/dist/src/register-contracts/summary.js +266 -0
  133. package/dist/src/register-contracts/tooling.d.ts +57 -0
  134. package/dist/src/{register-care → register-contracts}/tooling.js +8 -6
  135. package/dist/src/register-contracts/types.d.ts +188 -0
  136. package/dist/src/semantics/binary-operators.d.ts +2 -0
  137. package/dist/src/semantics/binary-operators.js +15 -0
  138. package/dist/src/semantics/byte-functions.d.ts +2 -0
  139. package/dist/src/semantics/byte-functions.js +7 -0
  140. package/dist/src/semantics/constant-operator-types.d.ts +10 -0
  141. package/dist/src/semantics/constant-operator-types.js +1 -0
  142. package/dist/src/semantics/constant-operators.d.ts +3 -0
  143. package/dist/src/semantics/constant-operators.js +3 -0
  144. package/dist/src/semantics/diagnostics.d.ts +3 -0
  145. package/dist/src/semantics/diagnostics.js +10 -0
  146. package/dist/src/semantics/expression-evaluation.d.ts +11 -19
  147. package/dist/src/semantics/expression-evaluation.js +22 -334
  148. package/dist/src/semantics/layout-evaluation.d.ts +23 -0
  149. package/dist/src/semantics/layout-evaluation.js +202 -0
  150. package/dist/src/semantics/layout-format.d.ts +5 -0
  151. package/dist/src/semantics/layout-format.js +31 -0
  152. package/dist/src/semantics/layout-path.d.ts +24 -0
  153. package/dist/src/semantics/layout-path.js +58 -0
  154. package/dist/src/semantics/unary-operators.d.ts +2 -0
  155. package/dist/src/semantics/unary-operators.js +8 -0
  156. package/dist/src/source/line-comment-scanner.d.ts +1 -0
  157. package/dist/src/source/line-comment-scanner.js +51 -0
  158. package/dist/src/source/logical-lines.d.ts +3 -0
  159. package/dist/src/source/source-span.d.ts +2 -0
  160. package/dist/src/source/strip-line-comment.js +8 -44
  161. package/dist/src/syntax/directive-aliases.js +36 -22
  162. package/dist/src/syntax/expression-tokenizer.d.ts +30 -0
  163. package/dist/src/syntax/expression-tokenizer.js +310 -0
  164. package/dist/src/syntax/parse-directive-statement.d.ts +9 -0
  165. package/dist/src/syntax/parse-directive-statement.js +309 -0
  166. package/dist/src/syntax/parse-expression.d.ts +2 -2
  167. package/dist/src/syntax/parse-expression.js +7 -568
  168. package/dist/src/syntax/parse-layout-declarations.d.ts +9 -0
  169. package/dist/src/syntax/parse-layout-declarations.js +189 -0
  170. package/dist/src/syntax/parse-layout-expression.d.ts +5 -0
  171. package/dist/src/syntax/parse-layout-expression.js +175 -0
  172. package/dist/src/syntax/parse-line.js +21 -273
  173. package/dist/src/syntax/parse-token-expression.d.ts +3 -0
  174. package/dist/src/syntax/parse-token-expression.js +133 -0
  175. package/dist/src/tooling/api.js +1 -1
  176. package/dist/src/tooling/case-style.js +47 -30
  177. package/dist/src/z80/effect-groups.d.ts +38 -0
  178. package/dist/src/z80/effect-groups.js +265 -0
  179. package/dist/src/z80/effect-units.d.ts +18 -0
  180. package/dist/src/z80/effect-units.js +165 -0
  181. package/dist/src/z80/effects.d.ts +1 -1
  182. package/dist/src/z80/effects.js +94 -557
  183. package/dist/src/z80/encode-core.d.ts +2 -0
  184. package/dist/src/z80/encode-core.js +42 -0
  185. package/dist/src/z80/encode-ld-helpers.d.ts +25 -0
  186. package/dist/src/z80/encode-ld-helpers.js +172 -0
  187. package/dist/src/z80/encode-ld.d.ts +2 -0
  188. package/dist/src/z80/encode-ld.js +285 -0
  189. package/dist/src/z80/encode.js +190 -542
  190. package/dist/src/z80/ld-support.d.ts +3 -0
  191. package/dist/src/z80/ld-support.js +146 -0
  192. package/dist/src/z80/operand-split-state.d.ts +8 -0
  193. package/dist/src/z80/operand-split-state.js +46 -0
  194. package/dist/src/z80/operand-split.d.ts +1 -0
  195. package/dist/src/z80/operand-split.js +13 -0
  196. package/dist/src/z80/parse-basic.d.ts +4 -0
  197. package/dist/src/z80/parse-basic.js +39 -0
  198. package/dist/src/z80/parse-branch.d.ts +4 -0
  199. package/dist/src/z80/parse-branch.js +218 -0
  200. package/dist/src/z80/parse-conditions.d.ts +6 -0
  201. package/dist/src/z80/parse-conditions.js +10 -0
  202. package/dist/src/z80/parse-exchange.d.ts +2 -0
  203. package/dist/src/z80/parse-exchange.js +30 -0
  204. package/dist/src/z80/parse-instruction.js +224 -1010
  205. package/dist/src/z80/parse-io-control.d.ts +5 -0
  206. package/dist/src/z80/parse-io-control.js +108 -0
  207. package/dist/src/z80/parse-ld.d.ts +2 -0
  208. package/dist/src/z80/parse-ld.js +83 -0
  209. package/dist/src/z80/parse-operands.d.ts +41 -0
  210. package/dist/src/z80/parse-operands.js +259 -0
  211. package/docs/codebase/01-orientation-and-repository-layout.md +192 -0
  212. package/docs/codebase/02-source-loading-and-parsing.md +263 -0
  213. package/docs/codebase/03-assembly-and-z80-emission.md +251 -0
  214. package/docs/codebase/04-ops-and-register-contracts.md +237 -0
  215. package/docs/codebase/05-interfaces-and-output-artifacts.md +253 -0
  216. package/docs/codebase/06-verification-and-maintenance.md +202 -0
  217. package/docs/codebase/appendices/a-directory-file-reference.md +253 -0
  218. package/docs/codebase/appendices/b-compile-flow-reference.md +103 -0
  219. package/docs/codebase/appendices/c-public-surface-reference.md +106 -0
  220. package/docs/codebase/appendices/index.md +16 -0
  221. package/docs/codebase/index.md +46 -0
  222. package/package.json +2 -3
  223. package/dist/src/register-care/accept-output.d.ts +0 -2
  224. package/dist/src/register-care/analyze.js +0 -166
  225. package/dist/src/register-care/annotate.d.ts +0 -11
  226. package/dist/src/register-care/annotations.d.ts +0 -8
  227. package/dist/src/register-care/boundaryHints.d.ts +0 -3
  228. package/dist/src/register-care/boundaryHints.js +0 -80
  229. package/dist/src/register-care/carriers.d.ts +0 -2
  230. package/dist/src/register-care/controlFlow.d.ts +0 -5
  231. package/dist/src/register-care/controlFlow.js +0 -38
  232. package/dist/src/register-care/fix.d.ts +0 -11
  233. package/dist/src/register-care/instruction-shape.d.ts +0 -11
  234. package/dist/src/register-care/instruction-shape.js +0 -129
  235. package/dist/src/register-care/liveness.d.ts +0 -3
  236. package/dist/src/register-care/programModel.d.ts +0 -3
  237. package/dist/src/register-care/programModel.js +0 -266
  238. package/dist/src/register-care/report.d.ts +0 -5
  239. package/dist/src/register-care/routine-summaries.d.ts +0 -6
  240. package/dist/src/register-care/smartComments.d.ts +0 -5
  241. package/dist/src/register-care/smartComments.js +0 -243
  242. package/dist/src/register-care/summaries.d.ts +0 -12
  243. package/dist/src/register-care/summary.d.ts +0 -3
  244. package/dist/src/register-care/summary.js +0 -474
  245. package/dist/src/register-care/tooling.d.ts +0 -43
  246. package/dist/src/register-care/types.d.ts +0 -172
  247. package/docs/reference/cli.md +0 -151
  248. package/docs/reference/tooling-api.md +0 -316
  249. /package/dist/src/{register-care → register-contracts}/accept-output.js +0 -0
  250. /package/dist/src/{register-care → register-contracts}/carriers.js +0 -0
  251. /package/dist/src/{register-care → register-contracts}/sourceText.d.ts +0 -0
  252. /package/dist/src/{register-care → register-contracts}/sourceText.js +0 -0
  253. /package/dist/src/{register-care → register-contracts}/types.js +0 -0
@@ -1,151 +0,0 @@
1
- # AZM CLI Reference
2
-
3
- Status: active user reference
4
-
5
- The `azm` command assembles `.asm` and `.z80` source files and writes the
6
- requested object artifacts.
7
-
8
- ```sh
9
- azm [options] <entry.asm|entry.z80>
10
- ```
11
-
12
- The entry file must be the final argument. AZM source uses `.asm` or `.z80`.
13
- Register-care interface files use `.asmi`; they are loaded with `--interface`
14
- and are not compile entries.
15
-
16
- ## Basic Use
17
-
18
- Build the default artifact set next to the source file:
19
-
20
- ```sh
21
- azm program.asm
22
- ```
23
-
24
- Write a specific primary output:
25
-
26
- ```sh
27
- azm --type bin --output build/program.bin program.asm
28
- azm --type hex --output build/program.hex program.asm
29
- ```
30
-
31
- Add include search paths:
32
-
33
- ```sh
34
- azm -I include -I vendor program.asm
35
- ```
36
-
37
- Load project directive aliases:
38
-
39
- ```sh
40
- azm --aliases azm.aliases.json program.asm
41
- ```
42
-
43
- Normalize Debug80 map source paths against the project root:
44
-
45
- ```sh
46
- azm --source-root . --output build/program.hex src/program.asm
47
- ```
48
-
49
- ## Output Artifacts
50
-
51
- By default AZM writes the primary output plus useful side artifacts using the
52
- same base path.
53
-
54
- | Artifact | Meaning |
55
- | -------------- | -------------------------------- |
56
- | `.hex` | Intel HEX output |
57
- | `.bin` | flat binary output |
58
- | `.d8.json` | Debug80 map |
59
- | `.z80` | lowered assembler source |
60
- | `.regcare.txt` | register-care report |
61
- | `.asmi` | inferred register-care interface |
62
-
63
- Disable standard artifacts when they are not needed:
64
-
65
- ```sh
66
- azm --nod8m program.asm
67
- azm --nobin --nohex --reg-report --rc audit program.asm
68
- ```
69
-
70
- ## Options
71
-
72
- | Option | Meaning |
73
- | --------------------------------------------- | -------------------------------------------------------------------- |
74
- | `-o, --output <file>` | Primary output path. The extension must match `--type`. |
75
- | `-t, --type <hex\|bin>` | Primary output type. Default: `hex`. |
76
- | `--nobin` | Do not write `.bin`. |
77
- | `--nohex` | Do not write `.hex`. |
78
- | `--nod8m` | Do not write `.d8.json`. |
79
- | `--asm80` | Write lowered assembler source as `.z80`. |
80
- | `--source-root <dir>` | Emit project-relative source paths in `.d8.json`. |
81
- | `--case-style <mode>` | Lint mnemonic/register/op-head case: `off`, `upper`, `lower`, or `consistent`. |
82
- | `--rc, --register-care <mode>` | Register-care mode: `off`, `audit`, `warn`, `error`, or `strict`. |
83
- | `--reg-report, --emit-register-report` | Write `.regcare.txt`. |
84
- | `--reg-interface, --emit-register-interface` | Write inferred `.asmi` interface. |
85
- | `--contracts, --annotate-register-contracts` | Update AZMDoc contract comments in source. |
86
- | `--fix` | Apply conservative register-care source fixes and update contracts. |
87
- | `--accept-out <routine:carrier>` | Promote an inferred output candidate while annotating. |
88
- | `--interface <file>` | Load external register-care contracts from `.asmi`. Repeatable. |
89
- | `--reg-profile, --register-profile <profile>` | Register-care profile. Currently `mon3`. |
90
- | `--aliases <file>` | Load project directive alias JSON. Repeatable. |
91
- | `-I, --include <dir>` | Add an include search path. Repeatable. |
92
- | `-V, --version` | Print package version. |
93
- | `-h, --help` | Print CLI help. |
94
-
95
- ## Debug80 Maps
96
-
97
- `--case-style` is a source-style lint only. It checks instruction mnemonics,
98
- register names, and visible `op` heads/bodies. It does not rename labels,
99
- constants, directives, or compile-time functions.
100
-
101
- The `.d8.json` artifact records AZM as the generator, the package version, and
102
- the input/output paths used for the map. When `--source-root` is supplied, file
103
- keys and generator input paths are written relative to that directory with `/`
104
- separators. Constants are emitted as `value` metadata without fake addresses;
105
- labels and addressable data carry `address`.
106
-
107
- ## Register-Care Examples
108
-
109
- Audit inferred contracts without failing the build:
110
-
111
- ```sh
112
- azm --rc audit --reg-report program.asm
113
- ```
114
-
115
- Treat contract conflicts as build failures:
116
-
117
- ```sh
118
- azm --rc error program.asm
119
- ```
120
-
121
- Generate compact AZMDoc blocks in source:
122
-
123
- ```sh
124
- azm --contracts --rc audit program.asm
125
- ```
126
-
127
- Load external contracts for monitor/library routines:
128
-
129
- ```sh
130
- azm --rc error --interface mon3.asmi program.asm
131
- ```
132
-
133
- ## `.asmi` Interfaces
134
-
135
- External register-care interfaces are plain metadata files:
136
-
137
- ```text
138
- extern MON_PRINT_CHAR
139
- in A
140
- clobbers A
141
- end
142
- ```
143
-
144
- Use `.asmi` for these files so they are clearly distinct from assembler source.
145
-
146
- ## Exit Behavior
147
-
148
- The CLI exits with a non-zero status when parsing, semantic checks, register-care
149
- mode, lowering, or artifact writing reports an error. Diagnostics are printed
150
- with file, line, column, severity, and diagnostic ID where that information is
151
- available.
@@ -1,316 +0,0 @@
1
- # AZM Tooling API
2
-
3
- `@jhlagado/azm` exposes a stable programmatic surface for Node tooling. Use
4
- these imports instead of deep paths under `dist/src`.
5
-
6
- Install the package once, then import from the public entry points:
7
-
8
- ```sh
9
- npm install @jhlagado/azm
10
- ```
11
-
12
- ## Stable entry points
13
-
14
- - `@jhlagado/azm`
15
- Re-exports the stable public surface.
16
- - `@jhlagado/azm/tooling`
17
- Layer A/B APIs for parsing, loading, diagnostics, spans, and semantics-only analysis.
18
- - `@jhlagado/azm/compile`
19
- Layer C compile API and default format writers.
20
-
21
- ## Debug80 Integration Path
22
-
23
- Debug80 should link through the public package entry points, not internal
24
- `dist/src/...` paths.
25
-
26
- Use this path when Debug80 needs editor-style diagnostics, symbols, or
27
- register-care information without writing files:
28
-
29
- ```ts
30
- import { analyzeProgram, analyzeRegisterCareForTools, loadProgram } from '@jhlagado/azm/tooling';
31
-
32
- const loaded = await loadProgram({
33
- entryFile: '/abs/path/to/main.asm',
34
- includeDirs: ['/abs/path/to/includes'],
35
- });
36
-
37
- if (!loaded.loadedProgram) {
38
- return loaded.diagnostics;
39
- }
40
-
41
- const analysis = analyzeProgram(loaded.loadedProgram, {
42
- caseStyle: 'consistent',
43
- requireMain: false,
44
- });
45
-
46
- const registerCare = analyzeRegisterCareForTools(loaded.loadedProgram, {
47
- mode: 'audit',
48
- registerCareProfile: 'mon3',
49
- });
50
- ```
51
-
52
- Use this path when Debug80 needs assembled bytes and debugger metadata:
53
-
54
- ```ts
55
- import { compile, defaultFormatWriters } from '@jhlagado/azm/compile';
56
-
57
- const result = await compile(
58
- '/abs/path/to/main.asm',
59
- {
60
- includeDirs: ['/abs/path/to/includes'],
61
- sourceRoot: '/abs/path/to/project',
62
- d8mInputs: {
63
- hex: '/abs/path/to/project/build/main.hex',
64
- bin: '/abs/path/to/project/build/main.bin',
65
- },
66
- outputType: 'hex',
67
- emitBin: true,
68
- emitHex: true,
69
- emitD8m: true,
70
- registerCare: 'audit',
71
- registerCareInterfaces: ['/abs/path/to/mon3.asmi'],
72
- },
73
- { formats: defaultFormatWriters },
74
- );
75
-
76
- const diagnostics = result.diagnostics;
77
- const d8m = result.artifacts.find((artifact) => artifact.kind === 'd8m');
78
- const binary = result.artifacts.find((artifact) => artifact.kind === 'bin');
79
- ```
80
-
81
- The integration contract is:
82
-
83
- - source entries are `.asm` or `.z80`
84
- - external register-care contracts are `.asmi`
85
- - include search paths are supplied explicitly with `includeDirs`
86
- - directive alias JSON files are supplied explicitly with `directiveAliasFiles`
87
- - `compile()` returns artifacts in memory; the CLI is only responsible for
88
- writing those artifacts to disk
89
- - Debug80 should consume the `d8m` artifact for source/address metadata and the
90
- `bin` artifact for loadable bytes (hex is acceptable when bin is not emitted)
91
- - Do not rely on lowered `.z80` for Debug80 integration until asm80 coverage is
92
- complete; use **bin + d8m** as the supported debugger path
93
- - pass `sourceRoot` so D8 file keys are stable project-relative source paths
94
- rather than basename-only paths
95
- - pass `d8mInputs` when Debug80 knows the intended artifact paths; AZM records
96
- those under `generator.inputs`
97
- - D8 constants use `value` without `address`; only labels and addressable data
98
- are breakpoint anchors
99
- - diagnostics are data objects and should be displayed directly rather than
100
- parsed from CLI text
101
-
102
- ## D8 Debug Map Shape
103
-
104
- The D8 artifact is typed as `D8mArtifact`, with `json: D8mJson`. Debug80 can
105
- import these types from `@jhlagado/azm/compile`.
106
-
107
- ```ts
108
- import type { D8mArtifact, D8mJson, D8mSymbol } from '@jhlagado/azm/compile';
109
- ```
110
-
111
- The top-level map contains:
112
-
113
- ```ts
114
- {
115
- format: 'd8-debug-map',
116
- version: 1,
117
- arch: 'z80',
118
- addressWidth: 16,
119
- endianness: 'little',
120
- generator: {
121
- name: 'azm',
122
- tool: 'azm',
123
- version: '0.1.1',
124
- inputs: {
125
- entry: 'src/pacmo/pacmo.z80',
126
- hex: 'build/pacmo.hex',
127
- bin: 'build/pacmo.bin',
128
- },
129
- },
130
- files: {
131
- 'src/pacmo/pacmo.z80': {
132
- segments: [],
133
- symbols: [],
134
- },
135
- },
136
- segments: [],
137
- symbols: [],
138
- }
139
- ```
140
-
141
- Constants and labels intentionally have different shapes:
142
-
143
- ```ts
144
- { name: 'ColorRed', kind: 'constant', value: 1 }
145
- { name: 'main', kind: 'label', address: 0x4000 }
146
- ```
147
-
148
- A constant value is not a breakpoint address. Debug80 should use labels and
149
- addressable data symbols as breakpoint anchors.
150
-
151
- ## Layer A: Load and Parse
152
-
153
- Use `loadProgram()` when you need the same AST, spans, and diagnostics that the compiler uses, but without lowering or writing artifacts.
154
-
155
- ```ts
156
- import { loadProgram } from '@jhlagado/azm/tooling';
157
-
158
- const result = await loadProgram({
159
- entryFile: '/abs/path/to/main.asm',
160
- includeDirs: ['/abs/path/to/includes'],
161
- preloadedText: 'ORG 0100H\\nSTART:\\n RET\\n',
162
- });
163
-
164
- if (result.loadedProgram) {
165
- console.log(result.loadedProgram.program.kind); // "Program"
166
- }
167
-
168
- for (const diagnostic of result.diagnostics) {
169
- console.log(diagnostic.id, diagnostic.message);
170
- }
171
- ```
172
-
173
- Notes:
174
-
175
- - `preloadedText` applies to the entry file only. This is intended for unsaved editor buffers.
176
- - `signal?: AbortSignal` is accepted for best-effort cancellation of stale editor work.
177
- - `parseEntryOnly` is not part of v1. Use `loadProgram()` and debounce at the caller when needed.
178
-
179
- ## Layer B: Analyze Without Emitting
180
-
181
- Use `analyzeProgram()` after `loadProgram()` to run the current non-codegen semantic checks:
182
-
183
- - entry contract validation such as `requireMain`
184
- - case-style linting
185
- - environment building
186
- - instruction acceptance checks that do not require lowering
187
-
188
- ```ts
189
- import { analyzeProgram, loadProgram } from '@jhlagado/azm/tooling';
190
-
191
- const loaded = await loadProgram({ entryFile: '/abs/path/to/main.asm' });
192
- if (!loaded.loadedProgram) {
193
- throw new Error('Parse/load failed');
194
- }
195
-
196
- const analysis = analyzeProgram(loaded.loadedProgram, {
197
- caseStyle: 'consistent',
198
- requireMain: true,
199
- });
200
-
201
- console.log(analysis.diagnostics);
202
- ```
203
-
204
- `analysis.env` is returned only when semantic analysis completes without errors.
205
-
206
- ## Register-Care Tooling
207
-
208
- Use `analyzeRegisterCareForTools()` after `loadProgram()` when an editor, lint runner, or future LSP server needs register-care diagnostics without parsing report text. The function returns the same inferred output candidates used by the CLI report, plus ready-to-apply quick-fix metadata for confirming intent at the call site.
209
-
210
- ```ts
211
- import { analyzeRegisterCareForTools, loadProgram } from '@jhlagado/azm/tooling';
212
-
213
- const loaded = await loadProgram({ entryFile: '/abs/path/to/main.z80' });
214
- if (!loaded.loadedProgram) {
215
- throw new Error('Parse/load failed');
216
- }
217
-
218
- const registerCare = analyzeRegisterCareForTools(loaded.loadedProgram, {
219
- mode: 'audit',
220
- registerCareProfile: 'mon3',
221
- });
222
-
223
- for (const diagnostic of registerCare.candidateDiagnostics) {
224
- console.log(diagnostic.file, diagnostic.line, diagnostic.message);
225
- console.log(diagnostic.autoFixable); // true when CLI --fix can safely add the hint
226
- if (diagnostic.autoFixable && diagnostic.codeAction) {
227
- console.log(diagnostic.codeAction.edit.text); // "; expects out A\n"
228
- }
229
- }
230
- ```
231
-
232
- Candidate diagnostics use `kind: "register-care-output-candidate"` and `severity: "info"`.
233
- The `autoFixable` flag distinguishes direct continuation reads that `--fix` may
234
- confirm automatically from cases that need programmer review. Code actions are
235
- intentionally simple text insertions: insert the supplied newline-terminated
236
- `text` at column 1 of the supplied `line`, so the hint is inserted above the call
237
- instruction. This keeps CLI, editor light-bulbs, and future LSP integrations
238
- aligned around one inference source.
239
-
240
- ## Layer C: Full Compile
241
-
242
- Use `compile()` when you want assembly plus output artifacts.
243
-
244
- ```ts
245
- import { compile, defaultFormatWriters } from '@jhlagado/azm/compile';
246
-
247
- const result = await compile(
248
- '/abs/path/to/main.asm',
249
- { outputType: 'hex', emitAsm80: true },
250
- { formats: defaultFormatWriters },
251
- );
252
- ```
253
-
254
- **`emitAsm80` caveat:** Lowered `.z80` emission is gated but not universal.
255
- Unsupported instructions or operand forms throw `UnsupportedAsm80LoweringError`,
256
- surfaced as `AZMN_ASM80`. When assembly already succeeded, `compile()` still
257
- returns bin/hex/d8 artifacts alongside the asm80 error. Run
258
- `npm run check:asm80-coverage` on your sources before relying on lowered output.
259
-
260
- The compiler accepts flat `.asm` / `.z80` source, retained AZM assembler
261
- features, and the same output writers used by the CLI. External register-care
262
- interfaces are `.asmi` metadata files, not compile entry files.
263
-
264
- Retained AZM features include the ASM80 baseline, compact AZMDoc `;!` comments,
265
- directive aliases, AST `op` declarations, enums, `.type` / `.union`, `sizeof`,
266
- `offset`, constant-only layout casts, and scalar type shorthand in `.ds` and
267
- `.field`.
268
-
269
- High-level ZAX constructs such as modules/imports, `func`, locals, formal args,
270
- typed assignment/storage lowering, named sections, structured control, and
271
- generated frames are outside this API contract for AZM source.
272
-
273
- ## Public Types
274
-
275
- The public tooling surface includes:
276
-
277
- - `Diagnostic`, `DiagnosticIds`, severity/id types
278
- - `LoadedProgram`
279
- - `AnalyzeProgramResult`, `LoadProgramResult`
280
- - `RegisterCareCandidateDiagnostic`, `RegisterCareCodeAction`, `RegisterCareOutputCandidate`
281
-
282
- The public tooling contract is the package export surface, not deep internal
283
- paths. Do not document retired internal modules as public API.
284
-
285
- ## Syntax Highlighting Example
286
-
287
- Syntax colouring is an example consumer of the tooling API:
288
-
289
- 1. Call `loadProgram()` with the file path and optional unsaved buffer text.
290
- 2. Walk `loadedProgram.program.files[0].items` and inspect each item's `kind` and `span`.
291
- 3. Map those spans to TextMate scopes or semantic token kinds in the editor.
292
- 4. Fall back to regex/TextMate-only colouring if parsing fails or the editor needs a cheaper fast path.
293
-
294
- The same spans and node kinds also support outline views, hover preparation, diagnostics, and navigation features.
295
-
296
- ## Migration From Deep Imports
297
-
298
- Replace unstable imports such as:
299
-
300
- ```ts
301
- import { loadProgram } from '@jhlagado/azm/dist/src/sourceLoader.js';
302
- ```
303
-
304
- with:
305
-
306
- ```ts
307
- import { loadProgram } from '@jhlagado/azm/tooling';
308
- ```
309
-
310
- Likewise, prefer `@jhlagado/azm/compile` over `@jhlagado/azm/dist/src/compile.js`.
311
-
312
- ## Semver Policy
313
-
314
- - Patch: bug fixes that preserve the intent of exported APIs and types
315
- - Minor: additive exports, additive AST fields, new optional options
316
- - Major: breaking changes to exported types, AST node shapes, or public function behavior