@typecad/cuttlefish 0.1.0-alpha.1

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 (377) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -0
  3. package/dist/api/board-types.d.ts +1 -0
  4. package/dist/api/board-types.js +4 -0
  5. package/dist/api/capabilities.d.ts +12 -0
  6. package/dist/api/capabilities.js +1 -0
  7. package/dist/api/config.d.ts +120 -0
  8. package/dist/api/config.js +7 -0
  9. package/dist/api/index.d.ts +5 -0
  10. package/dist/api/index.js +2 -0
  11. package/dist/api/schema/builder.d.ts +14 -0
  12. package/dist/api/schema/builder.js +15 -0
  13. package/dist/api/schema/index.d.ts +2 -0
  14. package/dist/api/schema/index.js +1 -0
  15. package/dist/api/schema/types.d.ts +257 -0
  16. package/dist/api/schema/types.js +4 -0
  17. package/dist/api/shared/async-runtime-static.d.ts +8 -0
  18. package/dist/api/shared/async-runtime-static.js +201 -0
  19. package/dist/api/shared/async-types.d.ts +42 -0
  20. package/dist/api/shared/async-types.js +8 -0
  21. package/dist/api/shared/board-resolver.d.ts +12 -0
  22. package/dist/api/shared/board-resolver.js +7 -0
  23. package/dist/api/shared/cpp-type-ir.d.ts +229 -0
  24. package/dist/api/shared/cpp-type-ir.js +672 -0
  25. package/dist/api/shared/display-adapter.d.ts +12 -0
  26. package/dist/api/shared/display-adapter.js +145 -0
  27. package/dist/api/shared/display-adapters/eink-mono.d.ts +2 -0
  28. package/dist/api/shared/display-adapters/eink-mono.js +53 -0
  29. package/dist/api/shared/display-adapters/sdl.d.ts +2 -0
  30. package/dist/api/shared/display-adapters/sdl.js +452 -0
  31. package/dist/api/shared/display-adapters/ssd1309.d.ts +2 -0
  32. package/dist/api/shared/display-adapters/ssd1309.js +136 -0
  33. package/dist/api/shared/display-adapters/st7796.d.ts +2 -0
  34. package/dist/api/shared/display-adapters/st7796.js +132 -0
  35. package/dist/api/shared/display-capabilities.d.ts +45 -0
  36. package/dist/api/shared/display-capabilities.js +54 -0
  37. package/dist/api/shared/display-op-ir.d.ts +62 -0
  38. package/dist/api/shared/display-op-ir.js +19 -0
  39. package/dist/api/shared/display-profile.d.ts +265 -0
  40. package/dist/api/shared/display-profile.js +338 -0
  41. package/dist/api/shared/graphics-strategy.d.ts +29 -0
  42. package/dist/api/shared/graphics-strategy.js +11 -0
  43. package/dist/api/shared/hal-op-ir.d.ts +393 -0
  44. package/dist/api/shared/hal-op-ir.js +18 -0
  45. package/dist/api/shared/index.d.ts +26 -0
  46. package/dist/api/shared/index.js +21 -0
  47. package/dist/api/shared/ir-core.d.ts +363 -0
  48. package/dist/api/shared/ir-core.js +8 -0
  49. package/dist/api/shared/ir-declarations.d.ts +201 -0
  50. package/dist/api/shared/ir-declarations.js +26 -0
  51. package/dist/api/shared/ir.d.ts +85 -0
  52. package/dist/api/shared/ir.js +13 -0
  53. package/dist/api/shared/platform-strategy.d.ts +402 -0
  54. package/dist/api/shared/platform-strategy.js +14 -0
  55. package/dist/api/shared/polyfill-helper-registry.d.ts +11 -0
  56. package/dist/api/shared/polyfill-helper-registry.js +86 -0
  57. package/dist/api/shared/polyfill-types.d.ts +33 -0
  58. package/dist/api/shared/polyfill-types.js +76 -0
  59. package/dist/api/shared/promise-runtime.d.ts +10 -0
  60. package/dist/api/shared/promise-runtime.js +244 -0
  61. package/dist/api/shared/snprintf-types.d.ts +29 -0
  62. package/dist/api/shared/snprintf-types.js +8 -0
  63. package/dist/api/shared/string-method-registry.d.ts +53 -0
  64. package/dist/api/shared/string-method-registry.js +168 -0
  65. package/dist/api/shared/toolchain-types.d.ts +63 -0
  66. package/dist/api/shared/toolchain-types.js +71 -0
  67. package/dist/api/shared/types.d.ts +50 -0
  68. package/dist/api/shared/types.js +6 -0
  69. package/dist/ast/parse.d.ts +2 -0
  70. package/dist/ast/parse.js +4 -0
  71. package/dist/cache.d.ts +26 -0
  72. package/dist/cache.js +95 -0
  73. package/dist/cli-utils.d.ts +37 -0
  74. package/dist/cli-utils.js +250 -0
  75. package/dist/cli.d.ts +2 -0
  76. package/dist/cli.js +635 -0
  77. package/dist/config-loader.d.ts +78 -0
  78. package/dist/config-loader.js +508 -0
  79. package/dist/config-schema.d.ts +233 -0
  80. package/dist/config-schema.js +83 -0
  81. package/dist/create/board-checklist.d.ts +2 -0
  82. package/dist/create/board-checklist.js +52 -0
  83. package/dist/create/board-codegen.d.ts +9 -0
  84. package/dist/create/board-codegen.js +238 -0
  85. package/dist/create/board-generators.d.ts +12 -0
  86. package/dist/create/board-generators.js +652 -0
  87. package/dist/create/board-spec.d.ts +640 -0
  88. package/dist/create/board-spec.js +215 -0
  89. package/dist/create/eslint-rules-template.d.ts +2 -0
  90. package/dist/create/eslint-rules-template.js +672 -0
  91. package/dist/create/index.d.ts +11 -0
  92. package/dist/create/index.js +8 -0
  93. package/dist/create/init-scaffold.d.ts +27 -0
  94. package/dist/create/init-scaffold.js +150 -0
  95. package/dist/create/init-templates.d.ts +24 -0
  96. package/dist/create/init-templates.js +379 -0
  97. package/dist/create/init-wizard.d.ts +8 -0
  98. package/dist/create/init-wizard.js +168 -0
  99. package/dist/debug/breakpoint-loader.d.ts +24 -0
  100. package/dist/debug/breakpoint-loader.js +137 -0
  101. package/dist/debug/index.d.ts +3 -0
  102. package/dist/debug/index.js +7 -0
  103. package/dist/debug/preprocessor.d.ts +9 -0
  104. package/dist/debug/preprocessor.js +214 -0
  105. package/dist/debug/types.d.ts +32 -0
  106. package/dist/debug/types.js +6 -0
  107. package/dist/diagnostics/diagnostics-report.d.ts +51 -0
  108. package/dist/diagnostics/diagnostics-report.js +333 -0
  109. package/dist/diagnostics/json-schema.d.ts +138 -0
  110. package/dist/diagnostics/json-schema.js +27 -0
  111. package/dist/diagnostics/md-writer.d.ts +10 -0
  112. package/dist/diagnostics/md-writer.js +336 -0
  113. package/dist/diagnostics/mermaid-builder.d.ts +65 -0
  114. package/dist/diagnostics/mermaid-builder.js +681 -0
  115. package/dist/emit/cpp-emitter.d.ts +6 -0
  116. package/dist/emit/cpp-emitter.js +48 -0
  117. package/dist/emit/emitters/class-emitter.d.ts +2 -0
  118. package/dist/emit/emitters/class-emitter.js +523 -0
  119. package/dist/emit/emitters/emitter-context.d.ts +174 -0
  120. package/dist/emit/emitters/emitter-context.js +1 -0
  121. package/dist/emit/emitters/entrypoint-synthesizer.d.ts +2 -0
  122. package/dist/emit/emitters/entrypoint-synthesizer.js +175 -0
  123. package/dist/emit/emitters/function-emitter-impl.d.ts +19 -0
  124. package/dist/emit/emitters/function-emitter-impl.js +428 -0
  125. package/dist/emit/emitters/line-appender.d.ts +15 -0
  126. package/dist/emit/emitters/line-appender.js +344 -0
  127. package/dist/emit/emitters/namespace-emitter.d.ts +2 -0
  128. package/dist/emit/emitters/namespace-emitter.js +324 -0
  129. package/dist/emit/emitters/output-finalizer.d.ts +4 -0
  130. package/dist/emit/emitters/output-finalizer.js +267 -0
  131. package/dist/emit/emitters/setup.d.ts +3 -0
  132. package/dist/emit/emitters/setup.js +851 -0
  133. package/dist/emit/emitters/top-level-prep.d.ts +2 -0
  134. package/dist/emit/emitters/top-level-prep.js +706 -0
  135. package/dist/emit/emitters/type-decl-emitter.d.ts +2 -0
  136. package/dist/emit/emitters/type-decl-emitter.js +251 -0
  137. package/dist/emit/emitters/ui-emitter.d.ts +21 -0
  138. package/dist/emit/emitters/ui-emitter.js +564 -0
  139. package/dist/emit/enum-emitter.d.ts +1 -0
  140. package/dist/emit/enum-emitter.js +1 -0
  141. package/dist/emit/expression-renderer.d.ts +283 -0
  142. package/dist/emit/expression-renderer.js +1477 -0
  143. package/dist/emit/native-helpers-emitter.d.ts +11 -0
  144. package/dist/emit/native-helpers-emitter.js +34 -0
  145. package/dist/emit/route-hal-op.d.ts +5 -0
  146. package/dist/emit/route-hal-op.js +13 -0
  147. package/dist/emit/snprintf-helpers.d.ts +17 -0
  148. package/dist/emit/snprintf-helpers.js +462 -0
  149. package/dist/emit/statement-renderer.d.ts +189 -0
  150. package/dist/emit/statement-renderer.js +948 -0
  151. package/dist/emit/utils/async-state-machine.d.ts +42 -0
  152. package/dist/emit/utils/async-state-machine.js +343 -0
  153. package/dist/emit/utils/comment-helpers.d.ts +20 -0
  154. package/dist/emit/utils/comment-helpers.js +31 -0
  155. package/dist/emit/utils/cpp-helpers.d.ts +47 -0
  156. package/dist/emit/utils/cpp-helpers.js +85 -0
  157. package/dist/emit/utils/include-resolver.d.ts +58 -0
  158. package/dist/emit/utils/include-resolver.js +155 -0
  159. package/dist/emit/utils/index.d.ts +8 -0
  160. package/dist/emit/utils/index.js +12 -0
  161. package/dist/emit/utils/type-inference.d.ts +159 -0
  162. package/dist/emit/utils/type-inference.js +559 -0
  163. package/dist/eslint-check.d.ts +10 -0
  164. package/dist/eslint-check.js +102 -0
  165. package/dist/framework-package.d.ts +10 -0
  166. package/dist/framework-package.js +58 -0
  167. package/dist/framework-registry.d.ts +39 -0
  168. package/dist/framework-registry.js +30 -0
  169. package/dist/incremental-cache.d.ts +116 -0
  170. package/dist/incremental-cache.js +335 -0
  171. package/dist/ir/adc-range-validation.d.ts +11 -0
  172. package/dist/ir/adc-range-validation.js +250 -0
  173. package/dist/ir/ast-node-utils.d.ts +8 -0
  174. package/dist/ir/ast-node-utils.js +32 -0
  175. package/dist/ir/board-pin-utils.d.ts +13 -0
  176. package/dist/ir/board-pin-utils.js +65 -0
  177. package/dist/ir/board-resolver.d.ts +36 -0
  178. package/dist/ir/board-resolver.js +437 -0
  179. package/dist/ir/build-ir-state.d.ts +167 -0
  180. package/dist/ir/build-ir-state.js +306 -0
  181. package/dist/ir/build-ir.d.ts +2 -0
  182. package/dist/ir/build-ir.js +808 -0
  183. package/dist/ir/call-graph.d.ts +35 -0
  184. package/dist/ir/call-graph.js +194 -0
  185. package/dist/ir/compile-time-only.d.ts +2 -0
  186. package/dist/ir/compile-time-only.js +16 -0
  187. package/dist/ir/declaration-builders.d.ts +9 -0
  188. package/dist/ir/declaration-builders.js +608 -0
  189. package/dist/ir/entry-points.d.ts +30 -0
  190. package/dist/ir/entry-points.js +191 -0
  191. package/dist/ir/expression-to-ir.d.ts +5 -0
  192. package/dist/ir/expression-to-ir.js +2249 -0
  193. package/dist/ir/extract-property-chain.d.ts +10 -0
  194. package/dist/ir/extract-property-chain.js +30 -0
  195. package/dist/ir/feature-prescan.d.ts +3 -0
  196. package/dist/ir/feature-prescan.js +43 -0
  197. package/dist/ir/feature-registry.d.ts +30 -0
  198. package/dist/ir/feature-registry.js +816 -0
  199. package/dist/ir/filter.d.ts +7 -0
  200. package/dist/ir/filter.js +85 -0
  201. package/dist/ir/function-builder.d.ts +19 -0
  202. package/dist/ir/function-builder.js +670 -0
  203. package/dist/ir/hal/hal-emitter.d.ts +62 -0
  204. package/dist/ir/hal/hal-emitter.js +735 -0
  205. package/dist/ir/hal/hal-parser.d.ts +61 -0
  206. package/dist/ir/hal/hal-parser.js +473 -0
  207. package/dist/ir/hal/hal-plugins.d.ts +34 -0
  208. package/dist/ir/hal/hal-plugins.js +706 -0
  209. package/dist/ir/hal-resolver.d.ts +5 -0
  210. package/dist/ir/hal-resolver.js +5 -0
  211. package/dist/ir/heap-analysis.d.ts +8 -0
  212. package/dist/ir/heap-analysis.js +350 -0
  213. package/dist/ir/heap-array-validation.d.ts +24 -0
  214. package/dist/ir/heap-array-validation.js +29 -0
  215. package/dist/ir/identifier-collector.d.ts +18 -0
  216. package/dist/ir/identifier-collector.js +439 -0
  217. package/dist/ir/interrupt-analysis.d.ts +39 -0
  218. package/dist/ir/interrupt-analysis.js +467 -0
  219. package/dist/ir/memory-budget-validation.d.ts +10 -0
  220. package/dist/ir/memory-budget-validation.js +86 -0
  221. package/dist/ir/namespace-builder.d.ts +7 -0
  222. package/dist/ir/namespace-builder.js +152 -0
  223. package/dist/ir/ownership-analysis.d.ts +9 -0
  224. package/dist/ir/ownership-analysis.js +1207 -0
  225. package/dist/ir/peripheral-ownership.d.ts +3 -0
  226. package/dist/ir/peripheral-ownership.js +152 -0
  227. package/dist/ir/peripheral-symbols.d.ts +7 -0
  228. package/dist/ir/peripheral-symbols.js +57 -0
  229. package/dist/ir/peripheral-usage.d.ts +54 -0
  230. package/dist/ir/peripheral-usage.js +691 -0
  231. package/dist/ir/peripheral-validation.d.ts +8 -0
  232. package/dist/ir/peripheral-validation.js +77 -0
  233. package/dist/ir/pin-alias-conflict.d.ts +4 -0
  234. package/dist/ir/pin-alias-conflict.js +34 -0
  235. package/dist/ir/pin-capability-validation.d.ts +6 -0
  236. package/dist/ir/pin-capability-validation.js +413 -0
  237. package/dist/ir/pin-mode-validation.d.ts +10 -0
  238. package/dist/ir/pin-mode-validation.js +301 -0
  239. package/dist/ir/pin-safety.d.ts +11 -0
  240. package/dist/ir/pin-safety.js +58 -0
  241. package/dist/ir/program-analysis.d.ts +44 -0
  242. package/dist/ir/program-analysis.js +589 -0
  243. package/dist/ir/pulldown-validation.d.ts +7 -0
  244. package/dist/ir/pulldown-validation.js +49 -0
  245. package/dist/ir/pwm-timer-sharing.d.ts +4 -0
  246. package/dist/ir/pwm-timer-sharing.js +93 -0
  247. package/dist/ir/reachability.d.ts +68 -0
  248. package/dist/ir/reachability.js +224 -0
  249. package/dist/ir/register-decorators.d.ts +6 -0
  250. package/dist/ir/register-decorators.js +49 -0
  251. package/dist/ir/render-expr.d.ts +4 -0
  252. package/dist/ir/render-expr.js +127 -0
  253. package/dist/ir/resource-analysis.d.ts +19 -0
  254. package/dist/ir/resource-analysis.js +153 -0
  255. package/dist/ir/statement-to-ir.d.ts +23 -0
  256. package/dist/ir/statement-to-ir.js +349 -0
  257. package/dist/ir/symbol-table.d.ts +68 -0
  258. package/dist/ir/symbol-table.js +179 -0
  259. package/dist/ir/symbol-types.d.ts +56 -0
  260. package/dist/ir/symbol-types.js +107 -0
  261. package/dist/ir/timer0-pwm-timing-conflict.d.ts +4 -0
  262. package/dist/ir/timer0-pwm-timing-conflict.js +71 -0
  263. package/dist/ir/timing-validation.d.ts +7 -0
  264. package/dist/ir/timing-validation.js +95 -0
  265. package/dist/ir/transformers/array-methods.d.ts +8 -0
  266. package/dist/ir/transformers/array-methods.js +493 -0
  267. package/dist/ir/transformers/call-statement.d.ts +5 -0
  268. package/dist/ir/transformers/call-statement.js +758 -0
  269. package/dist/ir/transformers/callback-context-registry.d.ts +20 -0
  270. package/dist/ir/transformers/callback-context-registry.js +55 -0
  271. package/dist/ir/transformers/canvas-lowering.d.ts +42 -0
  272. package/dist/ir/transformers/canvas-lowering.js +249 -0
  273. package/dist/ir/transformers/control-flow.d.ts +8 -0
  274. package/dist/ir/transformers/control-flow.js +508 -0
  275. package/dist/ir/transformers/expressions.d.ts +7 -0
  276. package/dist/ir/transformers/expressions.js +406 -0
  277. package/dist/ir/transformers/hal-call-resolver.d.ts +29 -0
  278. package/dist/ir/transformers/hal-call-resolver.js +274 -0
  279. package/dist/ir/transformers/hal-emit-helpers.d.ts +14 -0
  280. package/dist/ir/transformers/hal-emit-helpers.js +63 -0
  281. package/dist/ir/transformers/namespace-methods.d.ts +20 -0
  282. package/dist/ir/transformers/namespace-methods.js +110 -0
  283. package/dist/ir/transformers/register-assignment.d.ts +5 -0
  284. package/dist/ir/transformers/register-assignment.js +56 -0
  285. package/dist/ir/transformers/ui-call-resolver.d.ts +149 -0
  286. package/dist/ir/transformers/ui-call-resolver.js +1136 -0
  287. package/dist/ir/transformers/ui-callback-lowering.d.ts +62 -0
  288. package/dist/ir/transformers/ui-callback-lowering.js +623 -0
  289. package/dist/ir/transformers/ui-mount.d.ts +20 -0
  290. package/dist/ir/transformers/ui-mount.js +35 -0
  291. package/dist/ir/transformers/ui-reactive.d.ts +68 -0
  292. package/dist/ir/transformers/ui-reactive.js +129 -0
  293. package/dist/ir/transformers/variables.d.ts +14 -0
  294. package/dist/ir/transformers/variables.js +1045 -0
  295. package/dist/ir/try-catch-validation.d.ts +26 -0
  296. package/dist/ir/try-catch-validation.js +128 -0
  297. package/dist/ir/type-resolution.d.ts +31 -0
  298. package/dist/ir/type-resolution.js +977 -0
  299. package/dist/ir/ui-element-auto-wire.d.ts +50 -0
  300. package/dist/ir/ui-element-auto-wire.js +218 -0
  301. package/dist/ir/unit-suspicion-validation.d.ts +12 -0
  302. package/dist/ir/unit-suspicion-validation.js +296 -0
  303. package/dist/ir/utils/walk-ir.d.ts +6 -0
  304. package/dist/ir/utils/walk-ir.js +162 -0
  305. package/dist/ir/validation-orchestrator.d.ts +4 -0
  306. package/dist/ir/validation-orchestrator.js +45 -0
  307. package/dist/libdef/base-class-resolver.d.ts +23 -0
  308. package/dist/libdef/base-class-resolver.js +50 -0
  309. package/dist/libdef/cpp-to-decl.d.ts +34 -0
  310. package/dist/libdef/cpp-to-decl.js +584 -0
  311. package/dist/libdef/header-parser.d.ts +53 -0
  312. package/dist/libdef/header-parser.js +269 -0
  313. package/dist/libdef/registry.d.ts +10 -0
  314. package/dist/libdef/registry.js +142 -0
  315. package/dist/mapping/peripheral-names.d.ts +23 -0
  316. package/dist/mapping/peripheral-names.js +63 -0
  317. package/dist/mapping/source-map.d.ts +46 -0
  318. package/dist/mapping/source-map.js +207 -0
  319. package/dist/orchestrator/dts-generator.d.ts +17 -0
  320. package/dist/orchestrator/dts-generator.js +83 -0
  321. package/dist/orchestrator/graph-builder.d.ts +18 -0
  322. package/dist/orchestrator/graph-builder.js +218 -0
  323. package/dist/orchestrator/semantic-facts-verifier.d.ts +38 -0
  324. package/dist/orchestrator/semantic-facts-verifier.js +121 -0
  325. package/dist/orchestrator/semantic-facts.d.ts +141 -0
  326. package/dist/orchestrator/semantic-facts.js +652 -0
  327. package/dist/orchestrator/type-checker.d.ts +39 -0
  328. package/dist/orchestrator/type-checker.js +760 -0
  329. package/dist/platform/async-runtime.d.ts +8 -0
  330. package/dist/platform/async-runtime.js +26 -0
  331. package/dist/platform/generic-strategy.d.ts +101 -0
  332. package/dist/platform/generic-strategy.js +289 -0
  333. package/dist/platform/index.d.ts +4 -0
  334. package/dist/platform/index.js +9 -0
  335. package/dist/platform/registry.d.ts +21 -0
  336. package/dist/platform/registry.js +42 -0
  337. package/dist/platform/toolchain.d.ts +4 -0
  338. package/dist/platform/toolchain.js +43 -0
  339. package/dist/preview/client.d.ts +1 -0
  340. package/dist/preview/client.js +137 -0
  341. package/dist/preview/server.d.ts +5 -0
  342. package/dist/preview/server.js +199 -0
  343. package/dist/profiler/index.d.ts +28 -0
  344. package/dist/profiler/index.js +28 -0
  345. package/dist/profiler/profiler.d.ts +95 -0
  346. package/dist/profiler/profiler.js +338 -0
  347. package/dist/profiler/types.d.ts +87 -0
  348. package/dist/profiler/types.js +12 -0
  349. package/dist/stores/display-profile-store.d.ts +16 -0
  350. package/dist/stores/display-profile-store.js +48 -0
  351. package/dist/stores/theme-store.d.ts +13 -0
  352. package/dist/stores/theme-store.js +30 -0
  353. package/dist/testing.d.ts +45 -0
  354. package/dist/testing.js +47 -0
  355. package/dist/transpile/resolution.d.ts +29 -0
  356. package/dist/transpile/resolution.js +282 -0
  357. package/dist/transpile.d.ts +3 -0
  358. package/dist/transpile.js +722 -0
  359. package/dist/types.d.ts +217 -0
  360. package/dist/types.js +1 -0
  361. package/dist/ui/ui-bridge.d.ts +4 -0
  362. package/dist/ui/ui-bridge.js +34 -0
  363. package/dist/ui-hook.d.ts +84 -0
  364. package/dist/ui-hook.js +45 -0
  365. package/dist/utils/cli.d.ts +3 -0
  366. package/dist/utils/cli.js +463 -0
  367. package/dist/utils/fs.d.ts +4 -0
  368. package/dist/utils/fs.js +23 -0
  369. package/dist/utils/logger.d.ts +2 -0
  370. package/dist/utils/logger.js +8 -0
  371. package/dist/utils/strings.d.ts +35 -0
  372. package/dist/utils/strings.js +142 -0
  373. package/dist/utils/ui.d.ts +66 -0
  374. package/dist/utils/ui.js +149 -0
  375. package/dist/watch.d.ts +35 -0
  376. package/dist/watch.js +111 -0
  377. package/package.json +127 -0
@@ -0,0 +1,333 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Diagnostics Report Orchestrator
3
+ //
4
+ // Collects all available build data and generates:
5
+ // 1. diagnostics.md — human-readable report with Mermaid diagrams
6
+ // 2. diagnostics.json — machine-readable structured data
7
+ //
8
+ // Note: Source maps and transpile diagnostics are EXCLUDED from the
9
+ // Markdown report per user spec. The JSON report includes everything.
10
+ // ---------------------------------------------------------------------------
11
+ import * as path from "path";
12
+ import * as fs from "fs";
13
+ import { analyzeHeapUsage } from "../ir/heap-analysis.js";
14
+ import { buildCallGraph } from "../ir/call-graph.js";
15
+ import { generateMarkdownReport } from "./md-writer.js";
16
+ import { inferGpioMode } from "./json-schema.js";
17
+ // ── Helpers ─────────────────────────────────────────────────────────────────
18
+ function getBoardPinsFromConstants(program) {
19
+ if (!program?.boardConstants)
20
+ return [];
21
+ const pins = [];
22
+ // Iterate through pins.all.X.name until we find all pins
23
+ for (let i = 0; i < 100; i++) {
24
+ const name = program.boardConstants.get(`pins.all.${i}.name`);
25
+ if (typeof name !== "string")
26
+ break;
27
+ const numRaw = program.boardConstants.get(`pins.all.${i}.number`);
28
+ const num = typeof numRaw === "number" ? numRaw : i;
29
+ const aliasesRaw = program.boardConstants.get(`pins.all.${i}.aliases`);
30
+ const aliases = typeof aliasesRaw === "string" ? aliasesRaw.split(",") : [];
31
+ pins.push({ name, number: num, aliases });
32
+ }
33
+ return pins;
34
+ }
35
+ // ── Execution Flow Builder ──────────────────────────────────────────────────
36
+ function buildExecutionFlow(program, callGraph, asyncTaskNames, usesTimers) {
37
+ // Determine entry points
38
+ const entryPoints = [];
39
+ if (callGraph.nodes.has("setup"))
40
+ entryPoints.push("setup");
41
+ if (callGraph.nodes.has("loop"))
42
+ entryPoints.push("loop");
43
+ // If "main" or other standard entry is present add it
44
+ for (const name of callGraph.nodes.keys()) {
45
+ if (name !== "setup" &&
46
+ name !== "loop" &&
47
+ name !== "__top_level__" &&
48
+ name.startsWith("main")) {
49
+ entryPoints.push(name);
50
+ }
51
+ }
52
+ // Detect ISR handlers
53
+ const isrHandlers = [];
54
+ if (program) {
55
+ // Detect ISR handlers: functions referenced by attachInterrupt or HAL ISR registration
56
+ for (const fn of program.functions) {
57
+ // Check if this function appears as a callback in HAL interrupt registration
58
+ // in __top_level__ or setup statements (handled by existing transpiler diagnostics)
59
+ // Heuristic: functions named with "isr", "handler", or attached to interrupts
60
+ const lowerName = fn.originalName.toLowerCase();
61
+ if (lowerName.includes("isr") || lowerName.includes("handler") || lowerName.includes("interrupt")) {
62
+ isrHandlers.push(fn.originalName);
63
+ }
64
+ }
65
+ }
66
+ // Serialize call graph nodes for JSON
67
+ const serializedNodes = {};
68
+ for (const [name, node] of callGraph.nodes) {
69
+ serializedNodes[name] = {
70
+ name: node.name,
71
+ kind: node.kind,
72
+ dependencies: [...node.dependencies],
73
+ source: node.source ? { line: node.source.line, column: node.source.column } : undefined,
74
+ };
75
+ }
76
+ const serializedReferencedBy = {};
77
+ for (const [name, refs] of callGraph.referencedBy) {
78
+ serializedReferencedBy[name] = [...refs];
79
+ }
80
+ return {
81
+ callGraph: {
82
+ nodes: serializedNodes,
83
+ referencedBy: serializedReferencedBy,
84
+ },
85
+ entryPoints,
86
+ isrHandlers,
87
+ asyncTaskNames,
88
+ usesTimers,
89
+ };
90
+ }
91
+ // ── Pin Usage Builder ──────────────────────────────────────────────────────
92
+ function buildPinUsage(program, boardPinsData) {
93
+ const gpio = [];
94
+ const peripherals = [];
95
+ if (!program?.peripheralUsage) {
96
+ return {
97
+ gpio: [],
98
+ peripherals: [],
99
+ summary: { totalPins: boardPinsData.length, usedPins: 0, unusedPins: boardPinsData.length },
100
+ };
101
+ }
102
+ const usage = program.peripheralUsage;
103
+ // Map board pins to GPIO entries
104
+ for (const pin of boardPinsData) {
105
+ // Only include pins that are explicitly used in the sketch to keep the table clean
106
+ const isExplicitlyUsed = usage.pinsUsed.has(pin.name) ||
107
+ pin.aliases.some(a => usage.pinsUsed.has(a)) ||
108
+ (pin.number !== undefined && (usage.outputPins.has(pin.number) ||
109
+ usage.inputPins.has(pin.number) ||
110
+ usage.inputPullupPins.has(pin.number) ||
111
+ usage.inputPulldownPins.has(pin.number) ||
112
+ usage.pwmPinsUsed.has(pin.number) ||
113
+ usage.interruptPinsUsed.has(pin.number)));
114
+ if (isExplicitlyUsed) {
115
+ const mode = inferGpioMode(usage, pin.name, pin.number);
116
+ gpio.push({
117
+ pinName: pin.name,
118
+ pinNumber: pin.number,
119
+ mode,
120
+ });
121
+ }
122
+ }
123
+ // Build peripheral allocations — PeripheralUsageIR only has boolean flags
124
+ if (usage.i2c) {
125
+ peripherals.push({
126
+ type: "i2c",
127
+ instance: 0,
128
+ displayName: "I2C",
129
+ pins: [],
130
+ });
131
+ }
132
+ if (usage.spi) {
133
+ peripherals.push({
134
+ type: "spi",
135
+ instance: 0,
136
+ displayName: "SPI",
137
+ pins: [],
138
+ });
139
+ }
140
+ if (usage.uart) {
141
+ peripherals.push({
142
+ type: "uart",
143
+ instance: 0,
144
+ displayName: "Serial",
145
+ pins: [],
146
+ });
147
+ }
148
+ if (usage.adc) {
149
+ peripherals.push({
150
+ type: "adc",
151
+ instance: 0,
152
+ displayName: "ADC",
153
+ pins: [...usage.adcChannelsUsed].map((ch) => `A${ch}`),
154
+ });
155
+ }
156
+ if (usage.pwm) {
157
+ peripherals.push({
158
+ type: "pwm",
159
+ instance: 0,
160
+ displayName: "PWM",
161
+ pins: [...usage.pwmPinsUsed].map((n) => `D${n}`),
162
+ });
163
+ }
164
+ if (usage.timer0) {
165
+ peripherals.push({
166
+ type: "timer",
167
+ instance: 0,
168
+ displayName: "Timer0 (millis/micros)",
169
+ pins: [],
170
+ });
171
+ }
172
+ if (usage.externalInterrupts) {
173
+ peripherals.push({
174
+ type: "interrupt",
175
+ instance: 0,
176
+ displayName: "External Interrupts",
177
+ pins: [...usage.interruptPinsUsed].map((n) => `D${n}`),
178
+ });
179
+ }
180
+ const usedPins = gpio.filter((p) => p.mode !== "INPUT").length;
181
+ return {
182
+ gpio,
183
+ peripherals,
184
+ summary: {
185
+ totalPins: boardPinsData.length,
186
+ usedPins,
187
+ unusedPins: boardPinsData.length - usedPins,
188
+ },
189
+ };
190
+ }
191
+ // ── Peripheral Conflicts Builder ───────────────────────────────────────────
192
+ function buildPeripheralConflicts(_program) {
193
+ // This would normally call analyzeResourceConflicts() from resource-analysis.ts
194
+ // For now, return an empty array — the resource analysis is already run
195
+ // independently during transpile and its diagnostics are in the Diagnostic array.
196
+ // We could also import analyzeResourceConflicts directly here, but it requires
197
+ // BoardConstants which we may or may not have access to.
198
+ return [];
199
+ }
200
+ // ── Async Tasks Builder ────────────────────────────────────────────────────
201
+ function buildAsyncTasks(asyncTaskNames) {
202
+ return asyncTaskNames.map((name) => ({
203
+ name,
204
+ // intervalMs is unknown without JSDoc annotation parsing (future enhancement)
205
+ intervalMs: undefined,
206
+ }));
207
+ }
208
+ // ── Module Graph Builder ───────────────────────────────────────────────────
209
+ function buildModuleGraph(program, preBuilt) {
210
+ const nodes = new Set();
211
+ const edges = [];
212
+ if (program) {
213
+ const fromName = path.basename(program.fileName);
214
+ nodes.add(fromName);
215
+ for (const imp of program.imports) {
216
+ const toName = imp.moduleSpecifier;
217
+ nodes.add(toName);
218
+ edges.push({ from: fromName, to: toName });
219
+ }
220
+ }
221
+ if (preBuilt) {
222
+ for (const [fullPath] of preBuilt) {
223
+ const baseName = path.basename(fullPath);
224
+ nodes.add(baseName);
225
+ }
226
+ }
227
+ return { nodes: [...nodes], edges };
228
+ }
229
+ // ── Tree Shaking Report Builder ────────────────────────────────────────────
230
+ function buildTreeShakingReport(removedSymbols) {
231
+ return {
232
+ removedSymbols: removedSymbols ?? [],
233
+ };
234
+ }
235
+ // ── Build Timing Builder ────────────────────────────────────────────────────
236
+ function buildTimingReport(profiler) {
237
+ const phases = profiler?.getTimings?.() ?? {};
238
+ const values = Object.values(phases);
239
+ const totalMs = values.reduce((sum, v) => sum + v, 0);
240
+ return { phases, totalMs };
241
+ }
242
+ // ── Main Report Builder ────────────────────────────────────────────────────
243
+ /**
244
+ * Build the complete DiagnosticsReport from transpile pipeline data.
245
+ */
246
+ export function buildDiagnosticsReport(input) {
247
+ const program = input.program;
248
+ const boardPinsData = input.boardPins ?? getBoardPinsFromConstants(program);
249
+ // Build call graph
250
+ const callGraph = program ? buildCallGraph(program) : { nodes: new Map(), referencedBy: new Map() };
251
+ const executionFlow = buildExecutionFlow(program, callGraph, input.asyncTaskNames, input.usesTimers);
252
+ const pinUsage = buildPinUsage(program, boardPinsData);
253
+ const peripheralConflicts = buildPeripheralConflicts(program);
254
+ const asyncTasks = buildAsyncTasks(input.asyncTaskNames);
255
+ const heapEstimate = analyzeHeapUsage(program, input.target, callGraph.nodes);
256
+ const moduleGraph = buildModuleGraph(program, input.preBuilt);
257
+ const treeShaking = buildTreeShakingReport(input.removedSymbols);
258
+ const timing = buildTimingReport(input.profiler);
259
+ return {
260
+ metadata: {
261
+ timestamp: new Date().toISOString(),
262
+ sourceFile: path.basename(input.entryFile),
263
+ target: input.target,
264
+ board: input.boardPackage,
265
+ framework: input.frameworkPackage,
266
+ buildTarget: input.buildTarget,
267
+ outputFile: input.outputFile ?? path.basename(input.entryFile, path.extname(input.entryFile)) + ".ino",
268
+ boardDetails: program?.boardConstants ? {
269
+ mcu: program.boardConstants.get("mcu"),
270
+ architecture: program.boardConstants.get("architecture"),
271
+ flashKb: program.boardConstants.get("memory.flash") / 1024,
272
+ sramKb: program.boardConstants.get("memory.sram") / 1024,
273
+ clockSpeedMhz: program.boardConstants.get("clockSpeed") / 1000000,
274
+ } : undefined,
275
+ },
276
+ executionFlow,
277
+ pinUsage,
278
+ asyncTasks,
279
+ heapEstimate,
280
+ peripheralConflicts,
281
+ moduleGraph,
282
+ treeShaking,
283
+ sourceMaps: input.sourceMaps,
284
+ buildTiming: timing,
285
+ transpileDiagnostics: input.diagnostics.length > 0 ? input.diagnostics : undefined,
286
+ };
287
+ }
288
+ // ── File Writers ────────────────────────────────────────────────────────────
289
+ /**
290
+ * Write diagnostics.md to the output directory.
291
+ */
292
+ export function writeDiagnosticsReport(report, program, outDir) {
293
+ const callGraph = program ? buildCallGraph(program) : { nodes: new Map(), referencedBy: new Map() };
294
+ // Ensure output directory exists
295
+ if (!fs.existsSync(outDir)) {
296
+ fs.mkdirSync(outDir, { recursive: true });
297
+ }
298
+ // Write Markdown report
299
+ const mdPath = path.join(outDir, "diagnostics.md");
300
+ const mdContent = generateMarkdownReport(report, callGraph);
301
+ fs.writeFileSync(mdPath, mdContent, "utf-8");
302
+ // Write JSON report (includes everything)
303
+ const jsonPath = path.join(outDir, "diagnostics.json");
304
+ // Convert Sets to arrays for JSON serialization
305
+ const jsonReport = serializeForJson(report);
306
+ fs.writeFileSync(jsonPath, JSON.stringify(jsonReport, null, 2), "utf-8");
307
+ }
308
+ /**
309
+ * Recursively convert Set objects to arrays for JSON serialization.
310
+ */
311
+ function serializeForJson(obj) {
312
+ if (obj instanceof Set) {
313
+ return [...obj];
314
+ }
315
+ if (obj instanceof Map) {
316
+ const result = {};
317
+ for (const [k, v] of obj) {
318
+ result[k] = serializeForJson(v);
319
+ }
320
+ return result;
321
+ }
322
+ if (Array.isArray(obj)) {
323
+ return obj.map(serializeForJson);
324
+ }
325
+ if (obj !== null && typeof obj === "object") {
326
+ const result = {};
327
+ for (const [k, v] of Object.entries(obj)) {
328
+ result[k] = serializeForJson(v);
329
+ }
330
+ return result;
331
+ }
332
+ return obj;
333
+ }
@@ -0,0 +1,138 @@
1
+ import type { PeripheralUsageIR } from "../api/index.js";
2
+ import type { Diagnostic, SourceSpan } from "../types.js";
3
+ export interface GpioPinEntry {
4
+ pinName: string;
5
+ pinNumber?: number;
6
+ mode: "OUTPUT" | "INPUT" | "INPUT_PULLUP" | "INPUT_PULLDOWN" | "ANALOG" | "PWM";
7
+ /** If this pin is also allocated to a peripheral, list the peripheral name */
8
+ peripheralRole?: string;
9
+ }
10
+ export interface PeripheralAllocation {
11
+ type: "i2c" | "spi" | "uart" | "adc" | "pwm" | "timer" | "interrupt";
12
+ instance: number;
13
+ displayName: string;
14
+ pins: string[];
15
+ }
16
+ export interface CallGraphNodeEntry {
17
+ name: string;
18
+ kind: "function" | "class" | "enum" | "variable" | "type_alias";
19
+ dependencies: string[];
20
+ source?: {
21
+ line: number;
22
+ column: number;
23
+ };
24
+ }
25
+ export interface ExecutionFlow {
26
+ callGraph: {
27
+ nodes: Record<string, CallGraphNodeEntry>;
28
+ referencedBy: Record<string, string[]>;
29
+ };
30
+ entryPoints: string[];
31
+ /** Functions that are ISR handlers (attached via attachInterrupt or similar) */
32
+ isrHandlers: string[];
33
+ /** Async task names discovered during transpilation */
34
+ asyncTaskNames: string[];
35
+ /** Whether millis/micros timer is engaged */
36
+ usesTimers: boolean;
37
+ }
38
+ export interface AsyncTaskEntry {
39
+ name: string;
40
+ /** If a JSDoc @interval annotation was found */
41
+ intervalMs?: number;
42
+ }
43
+ export interface HeapEstimate {
44
+ globalVariables: {
45
+ name: string;
46
+ cppType: string;
47
+ estimatedBytes: number;
48
+ }[];
49
+ structSizes: Record<string, number>;
50
+ stringLiterals: {
51
+ value: string;
52
+ estimatedBytes: number;
53
+ }[];
54
+ totalStaticBytes: number;
55
+ /** Approximate stack depth derived from call graph maximum path length */
56
+ estimatedStackDepth: number;
57
+ /** The deepest call paths discovered during analysis */
58
+ stackPaths: string[][];
59
+ notes: string[];
60
+ }
61
+ export interface PeripheralConflictEntry {
62
+ pinName: string;
63
+ peripheralName: string;
64
+ role: string;
65
+ severity: "error" | "warning";
66
+ message: string;
67
+ suggestion: string;
68
+ sourceSpan?: SourceSpan;
69
+ }
70
+ export interface ModuleGraph {
71
+ nodes: string[];
72
+ edges: {
73
+ from: string;
74
+ to: string;
75
+ }[];
76
+ }
77
+ export interface TreeShakingReport {
78
+ removedSymbols: string[];
79
+ }
80
+ export interface SourceMapEntry {
81
+ generatedStartLine: number;
82
+ generatedStartColumn: number;
83
+ generatedEndLine: number;
84
+ generatedEndColumn: number;
85
+ tsSpan: SourceSpan;
86
+ nodeKind: string;
87
+ symbolName?: string;
88
+ }
89
+ export interface BuildTiming {
90
+ phases: Record<string, number>;
91
+ totalMs: number;
92
+ }
93
+ export interface DiagnosticsReport {
94
+ metadata: {
95
+ timestamp: string;
96
+ sourceFile: string;
97
+ target: string;
98
+ board?: string;
99
+ framework?: string;
100
+ buildTarget?: string;
101
+ outputFile: string;
102
+ boardDetails?: {
103
+ mcu?: string;
104
+ architecture?: string;
105
+ flashKb?: number;
106
+ sramKb?: number;
107
+ clockSpeedMhz?: number;
108
+ };
109
+ };
110
+ executionFlow: ExecutionFlow;
111
+ pinUsage: {
112
+ gpio: GpioPinEntry[];
113
+ peripherals: PeripheralAllocation[];
114
+ summary: {
115
+ totalPins: number;
116
+ usedPins: number;
117
+ unusedPins: number;
118
+ };
119
+ };
120
+ asyncTasks: AsyncTaskEntry[];
121
+ heapEstimate: HeapEstimate;
122
+ peripheralConflicts: PeripheralConflictEntry[];
123
+ /** Available in JSON only — excluded from Markdown per user request */
124
+ moduleGraph?: ModuleGraph;
125
+ /** Available in JSON only */
126
+ treeShaking?: TreeShakingReport;
127
+ /** Available in JSON only */
128
+ sourceMaps?: SourceMapEntry[];
129
+ /** Available in JSON only */
130
+ buildTiming?: BuildTiming;
131
+ /** Available in JSON only */
132
+ transpileDiagnostics?: Diagnostic[];
133
+ }
134
+ /**
135
+ * Infer the GPIO mode for a pin based on peripheral usage data.
136
+ * Uses PeripheralUsageIR from core (the type available at runtime).
137
+ */
138
+ export declare function inferGpioMode(usage: PeripheralUsageIR, _pinName: string, pinNumber: number | undefined): GpioPinEntry["mode"];
@@ -0,0 +1,27 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Diagnostics Report — JSON Schema Types
3
+ // ---------------------------------------------------------------------------
4
+ // ── Pin Role Inference ─────────────────────────────────────────────────────
5
+ /**
6
+ * Infer the GPIO mode for a pin based on peripheral usage data.
7
+ * Uses PeripheralUsageIR from core (the type available at runtime).
8
+ */
9
+ export function inferGpioMode(usage, _pinName, pinNumber) {
10
+ if (pinNumber !== undefined) {
11
+ if (usage.pwmPinsUsed.has(pinNumber))
12
+ return "PWM";
13
+ if (usage.adcChannelsUsed.has(pinNumber))
14
+ return "ANALOG";
15
+ if (usage.interruptPinsUsed.has(pinNumber))
16
+ return "INPUT_PULLUP";
17
+ if (usage.outputPins.has(pinNumber))
18
+ return "OUTPUT";
19
+ if (usage.inputPullupPins.has(pinNumber))
20
+ return "INPUT_PULLUP";
21
+ if (usage.inputPulldownPins.has(pinNumber))
22
+ return "INPUT_PULLDOWN";
23
+ if (usage.inputPins.has(pinNumber))
24
+ return "INPUT";
25
+ }
26
+ return "INPUT";
27
+ }
@@ -0,0 +1,10 @@
1
+ import type { CallGraph } from "../ir/call-graph.js";
2
+ import type { DiagnosticsReport } from "./json-schema.js";
3
+ /**
4
+ * Generate the complete diagnostics.md report as a string.
5
+ *
6
+ * @param report - The full diagnostics report with all data populated.
7
+ * @param callGraph - The raw CallGraph (Map-based) for Mermaid node walk.
8
+ * @returns The complete Markdown string ready to write to disk.
9
+ */
10
+ export declare function generateMarkdownReport(report: DiagnosticsReport, callGraph: CallGraph): string;