sta

    Single-clock NLDM gate-level timing analysis using MoonLiberty

    sta
    timing
    liberty
    eda
    sdc
    nldm
    yosys
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    3 days ago
    Downloads
    31

    #MoonBit STA

    单理想时钟、单角 NLDM(标量/1D/2D)门级时序分析库。参赛账号 yesuifengliu01,项目 ID liberty,模块 yesuifengliu/sta。源码仓库:yesuifengliu01/moonbit-liberty。

    独立实现网表校验/拓扑排序、集中负载聚合、rise/fall 图传播、clock-to-Q、建立时间约束和可解释路径。Liberty 文本解析、领域模型、Boolean AST 与查表复用 SongYZZZ/moon-liberty 0.5.0;OpenSTA 仅作独立验证进程,运行时不依赖它。

    生态定位(2026-11-30 检索 Mooncakes 全量已发布模块,结论限于已查包):SongYZZZ/moon-liberty(0.5.0)提供 Liberty 解析、库版本变更审计与组合 NLDM 查表;dtzrttp/moonbit-rtl 和 yzfyzf12345678/moonbit-rtl 侧重 Verilog/RTL 前端;moonrcinspect 侧重 SPEF 寄生 RC;pzq893/moonbit-spice 与 hsy-bit/moonbit-circuit-solver 侧重 SPICE 模拟电路求解。本项目复用 Liberty 解析,在已映射单元网表上做 setup STA,并以受限 Yosys write_json 导入衔接综合输出。未在 Mooncakes 发现重复的门级 STA + SDC + Yosys 导入分析包。

    #安装与运行

    按 MoonBit 官方安装教程安装工具链(要求 moonc 不低于 1.0.0-rc1),并从 Node.js 官网安装 Node.js 24。运行 moon version --all 与 node --version 确认实际版本。本项目在 Windows 使用 MoonBit SDK 1.0.0-rc1+3c0520448(moonc v1.0.0-rc1+3c0520448、moon 0.1.20261126)及 Node.js 24.18.0 验证;CI 固定的 SDK/core 下载和 SHA256 见 tools/ci-toolchain.json,原 WSL Ubuntu 基线见 VALIDATION.md。

    从公开仓库获取源码后,在仓库根目录执行下方命令;moon update 下载 moon.mod 声明的 MoonLiberty 0.5.0 依赖。分析 CLI 也可从其他目录调用:

    git clone https://github.com/yesuifengliu01/moonbit-liberty.git cd moonbit-liberty

    首次使用可运行 node tools/sta.cjs --help,查看参数、输入要求、退出码与模型边界;无需预先构建或提供输入,也不等待 stdin。只有单独的 --help 进入帮助模式,正常输出退出 0;帮助输出失败仍报 stderr、退出 2。也可直接用 moon run cmd/main 运行内置 Sky130 最小 MoonBit 示例。Node 分析命令需要下面的 JS 构建。

    moon update moon check --target all --deny-warn moon fmt --check moon run cmd/main moon build --target js --release node tools/sta.cjs examples/sky130-demo.lib examples/sequential.json moon test --target js --deny-warn moon test --target wasm-gc --deny-warn moon test --target native --deny-warn

    源码已完整迁移至 MoonBit 1.0.0-rc1 规范(包括 #derive(...) 属性语法、Int::to_int64、显式 extend 以及 JS 适配层的 pkgtype(kind: "foreign_library") 与 #export_name(...) 导出),检查与 CI 对所有编译器警告继续按错误处理(--deny-warn)。CI 还执行全目标 release 构建、Mooncakes 归档生成与内容校验、格式检查和真实文件消费者。tools/ci-package.py 核对归档中的 README、许可证、示例与源码,并拒绝凭据、构建缓存和不安全路径。

    消费者成功输出 {"ok":true,"schema":"moonbit.sta.v1","result":...}。分析/参数/IO 错误退出码 2;默认模式正常分析即使存在负 slack 仍退出 0,调用者应检查 worst_slack_seconds。tools/sta.cjs 负责请求 IO、调用 MoonBit 导出及映射检查退出码;时序计算在 MoonBit 核心。

    CLI 的相对输入路径相对于调用者当前目录,编译核心按工具自身位置定位。从其他目录调用时,使用工具的实际路径,并对含空格的路径加引号;中文与 Unicode 文件路径已有实际验证。文件读取失败输出到 stderr 并退出 2;已读取的坏 JSON 则由核心输出 ok:false JSON 并退出 2。

    若 stdout 写入失败(例如下游提前关闭管道),CLI 在 stderr 报告 stdout: 错误并退出 2,覆盖本次计算的 0/3/4;接收端关闭后无法保证完整 JSON。正常接收报告时仍使用原退出规则。成功写入只说明操作系统接受了数据,调用方仍负责解析和保存报告。

    Node CLI 的库/请求文件及请求 stdin 必须是合法 UTF-8。坏字节在核心解析前以 Invalid UTF-8 in Liberty input 或 Invalid UTF-8 in request input 报到 stderr、退出 2,stdout 为空,避免名称被静默替换为 �。合法编码的字面 U+FFFD、中文、emoji 和内部 U+FEFF 保留;不按字符内容拒绝名称。直接 JS API 接收已解码的 String,原始字节验证属于 CLI IO 边界。

    Node 分析 CLI 及两个分析 JS 适配入口可读取 UTF-8 或带单个 UTF-8 BOM 的库/请求文本。只处理整个输入文本最开头的 U+FEFF;内部名称、SDC 字符串中的字符和源文件字节保留。默认可选 JSON、显式检查和错误优先级不变,当前依赖为 MoonLiberty 0.5.0。物理带 BOM 的请求例程可直接运行:

    node tools/sta.cjs --check-setup examples/sky130-demo.lib examples/setup-check-utf8bom.json

    该例程退出 0、摘要为 Met;文件本身的 setup_summary:false 仍只在显式检查模式被请求为摘要。只处理首个文件签名,剩余非法内容仍由原解析器报告。

    生成器可用 --request-stdin 传入现有 JSON 请求:库仍是文件,最后一个参数必须是 -。读取 UTF-8 至 EOF 后执行一次分析;接受单个初始 BOM,空输入、坏 JSON 或多个 JSON 文档报错。可与 --check-setup 组合,两个 flag 可交换顺序;检查退出码仍为 0/2/3/4。未指定此 flag 时,- 仍是普通文件名。

    # Bash / cmd 重定向;普通分析可省略 --check-setup node tools/sta.cjs --check-setup --request-stdin examples/sky130-demo.lib - < examples/setup-check-utf8bom.json # Python 3 示例直接传原始字节,也适用于 PowerShell,不依赖 shell 编码设置 python examples/setup-check-stdin.py

    示例等待生产者关闭标准输入(EOF),返回 Met 和退出 0;接入自己的生成器时传同一请求结构即可。

    另有自编 examples/chain.json、rca4.json、seq_path.json、four_paths.json,以及同图 Verilog/SDC,便于复现。Sky130 文件是六类单元的真实 TT/25°C/1.80V 数据子集,不是完整 PDK。

    #公共 API

    精确签名见 pkg.generated.mbti(moon info --target all 生成)。核心入口:

    // 在导入本地 sta 与上游 liberty 的消费者中:
    let library = @liberty.load_library(liberty_text)
    let netlist = @sta.netlist_from_json(netlist_json)
    let constraints = @sta.parse_sdc(sdc_text, library, netlist)
    let report = @sta.STAEngine::new(library, netlist, constraints)
    .run_setup_analysis()

    Netlist 的 ports、gates、nets 是已映射的标量结构;实例 connections 使用 cell 的原始 pin 名称。核心不解析完整 Verilog。Net.wire_cap_farads、结构化 Clock/PortValue 都使用 秒/法拉。JSON 请求结构为(direction 的规范写法为 input/output,也兼容 MoonBit Netlist.ToJson 派生的 Input/Output):

    { "netlist": { "ports": [{"name":"a","net":"a","direction":"input"}], "gates": [], "nets": [{"name":"a","wire_cap_farads":0}] }, "sdc": "...", "range_policy": "extrapolate" }

    该片段仅说明字段形状;完整可运行输入见 examples。range_policy 支持 extrapolate(默认)、reject、clamp。外推是上游端区间延拓,会返回诊断;不是切平面外推。NaN/Inf、坏坐标或缺模型不能静默绕过;有限输入若使最终派生 arrival/required/slack 溢出,返回明确错误,不输出 Infinity。SDC 非零数值若在解析或 SI 单位换算时下溢为零也会拒绝,字面零仍接受。仍可表示的大数继续支持。

    #导入已映射的 Yosys JSON 网表

    可将请求中的 netlist 换成 yosys_netlist(完整的 Yosys write_json 对象)与必填的 yosys_module(模块名),原有 sdc、range_policy、period_budget 和 setup_summary 用法不变。两种网表入口不能同时提供。核心提供 netlist_from_yosys_json(value, module),转换为同一个 Netlist 后再做相同的约束绑定和时序分析。

    moon build --target js --release node tools/sta.cjs examples/sky130-demo.lib examples/yosys-chain.json

    examples/yosys-chain.json 是按 Yosys 官方 write_json 格式手写的最小已映射样例,与 examples/chain.json 表示同一条三反相器链。CI 运行两者并按 pin/edge 对齐比较时序结果。在 Yosys 中完成技术映射后,用 write_json -noscopeinfo mapped.json 导出,再把完整对象放入请求的 yosys_netlist;默认导出中可能出现的 $scopeinfo 不属于可分析单元,会被拒绝。入口只接收平坦的单比特端口和单比特已映射单元连接;Yosys 整数 bit ID 负责连接及别名,单元类型仍必须存在于所给 Liberty 库,综合和分析须使用匹配的 cell/pin 接口。向量、常量位、inout、存储器和未映射/层次单元不能作为受支持的时序网表,遇到时返回错误。Yosys 导出不含线寄生,本导入器将线电容设为 0;需要实际线电容时可使用原生 Netlist 入口。该入口不运行综合,也不解析 Verilog。

    STAResult 含:每 pin/edge 的 arrival、slew、driver net 总 load;每端点 required/slack/setup;最坏 slack;拓扑次序和诊断;带 pin/edge/单弧 delay 的 predecessor 路径。DFF launch 在非零 ideal latency 时先列出 CLK 的 clock_latency 步,再列 tCQ,使路径 delay 求和等于 arrival。JSON 的 Option 无值字段被省略,表示未约束,不是 0。slew_contributor 与 arrival path 分列,因为图分析分别合并最坏 slew 与最晚 arrival,不能把结果解释为精确相关的单路径波形。零 slew 仍记录真实贡献来源;NLDM 外推得到的负 slew 按物理下限取 0。topological_order 是按输出求值的实例序列,连续同名合并,交错时可重复实例名(如 pair→invert→pair);按 pin/edge 查询节点。

    #报告中的 pin 标识

    Netlist、SDC 和结构化约束始终使用原始名字。报告的 NodeTiming.pin、EndpointTiming.pin、PathStep.pin 和 slew_contributor 使用可逆的唯一标识:端口是一个转义分量,内部 pin 是 E(instance)/E(pin);E 仅把 ~ 编为 ~0、/ 编为 ~1,其余 Unicode 字符原样保留,不做规范化。分量规则来自 RFC6901 §3,整体标识不是完整 JSON Pointer。

    例如原始端口 u/Y 报为 u~1Y,实例 u 的输出 Y 报为 u/Y;原始 u~1Y 则报为 u~01Y。解码时先按分隔 / 拆分,再在各分量依次还原 ~1、~0。普通不含 ~ 或 / 的名字保持原输出。topological_order 仍列原始实例名字。

    #明确模型

    • 单库、单角、单理想时钟,数据图按寄存器切开,寄存器反馈合法;真实组合环报错。组合 DAG 以实际 timing arc 和驱动输出 pin 建立,支持同一多输出实例的通道交错求值。
    • CombinationalLoopDetected 的实例名单只包含确实位于有向环中的输出任务所属实例,按原输出任务顺序去重;包括自环和多个环分量。环下游被阻塞的实例不会误列入,单实例多个输出通道仍按各自弧依赖分析。名单用于定位参与者;图的原校验、寄存器切开、拒绝类型/退出码和正常时序结果保持。可用 node tools/sta.cjs examples/cycle-diagnosis.lib examples/cycle-diagnosis-request.json 查看仅报告 loop、退出2的例程,其中 tail 确实只在环下游。
    • 集中负载 Cwire + Σ Cpin(edge) + Cexternal(edge);优先使用 rise/fall capacitance,回退通用/声明的默认输入电容。R=0、net delay=0;无 SPEF、RC、OCV/PVT scaling。
    • 正/反单调展开对应边沿;多条反向/同向弧分别处理,non_unate 保守展开两种输入沿。缺省 timing_sense 时按 output function 的信号极性推断;显式声明优先,混合极性/XOR、缺函数或无法解析时保守保留双沿。when 条件弧明确拒绝,不假装完成 case analysis。
    • 单上升沿、无异步 set/reset 的 D/CLK/Q ff;支持真实 sky130_fd_sc_hd__dfxtp_1 的 rising_edge tCQ 和 setup_rising 数据/时钟 slew 约束表。setup 可为负数。传播与约束表可按单沿拆成 timing group;传播 delay/slew 仍须按沿配对,必要边沿的模型不能缺失。
    • 默认不缩放 slew_derate;库声明值须为 1。同库输入/输出阈值必须具有一致定义;不实现跨库阈值换算。
    • 四类路径 PI→PO、PI→D、Q→PO、Q→D;捕获 required = period + ideal latency − uncertainty − setup/output delay,数据 arrival 包含 launch latency 与 tCQ/input delay。
    • 缺 I/O delay 的数据保留 unconstrained;缺输入 slew、缺弧、非法方向/连接、重复身份、多驱动、无驱动或负电容均报错。约束报告的负 slack 是结果,不是异常。

    本期不承诺 hold、recovery/removal、latch、多时钟/异步域、generated/propagated clocks、条件逻辑求值、完整 SDC/Verilog、功耗或生产签核。

    #Setup 周期预算

    一次分析同时得到原时序结果、逐端点周期下界、限制沿及约束覆盖状态:

    let analysis = @sta.STAEngine::new(library, netlist, constraints)
    .run_period_analysis()
    let budget = analysis.budget
    // analysis.timing 是原 STAResult;budget 的时间为秒,频率为 Hz。

    Node 请求显式加 "period_budget": true 才在原 result 旁增加 period_budget;省略或 false 保持旧输出。可直接运行:

    node tools/sta.cjs examples/sky130-demo.lib examples/period-budget.json node tools/sta.cjs examples/sky130-demo.lib examples/period-budget-partial.json

    完整示例的实际 setup 下界约 0.487723672 ns、模型内频率上限约 2.050341325 GHz;Partial 示例保留未约束沿,整体周期/频率无值。endpoint_bounds 的 bound_seconds 缺失表示该沿未约束;有值可以为负。limiting_endpoints 列出正最大下界的所有沿,pin 标识沿用上述转义规则。

    status整体结果
    Complete所有端点沿均约束,正周期下界与有限频率都有值
    Partial / Unconstrained部分或全部缺约束(也含没有端点),不给整体周期/频率
    NoPositiveLimit当前模型没有正的 setup 周期限制;下界0,频率无值,不代表可创建零周期时钟
    FrequencyOverflow周期下界仍是正有限数,倒数不可表示,频率无值

    固定所有非周期参数的绝对值,仅改变 period;传播时保留共同时钟参考下的到达值,用于路径比较、slack 和预算,避免大共同 latency 淹没小数据延迟。绝对 arrival/required 仍按 Double 报告,发生舍入时不宜自行相减恢复 slack。由 P >= arrival - latency + uncertainty + setup/output_delay 直接计算下界,避免大基准 period 减 slack 的消减误差。最终下界非有限时显式报错,不能输出 Infinity。这是现有单理想时钟 setup 模型的下界,未包含 hold、器件最小脉宽/最小周期、RC/OCV 或签核保证;不处理随周期比例变化的外部约束。

    required、稳定 slack 和周期下界中的三/四项有限约束先精确累加,再一次舍入到 Double,避免有符号约束相消丢失小量,也接受中间加减超范围但最终结果有限的输入。此处理仅限这些短约束表达式;逐弧传播仍使用 Double。相对 arrival 自身超范围时,slack 保留原绝对通道行为;周期下界合并 arrival、−latency、uncertainty 和 offset 后判断最终范围。

    #Setup 违例摘要

    已有报告可调用 report.setup_summary(),直接从端点 slack 派生摘要,无需再次传播或读取库。返回 SetupSummary:端点数(按报告 pin 身份去重)、已约束/未约束沿数、违例沿数、违例端点数、最坏 slack 与 WNS。一个端点的 rise/fall 都负时,计两个违例沿、一个违例端点;别名输出端口各自是独立端点。负值严格 < 0,零不算违例;WNS 为 min(0, worst_slack),没有已知 slack 时无值。公开手工构造的报告若含非有限 slack、空 pin 或重复 pin/edge 身份,此方法用现有 STAError 拒绝,以免重复行被计作多个端点沿。

    status含义
    Met非空端点沿全部有已知 slack,且没有负值
    Violated至少一个已知负 slack;仍需查看未约束沿计数
    PartialCoverage有已知 slack、没有负值,同时仍有未知沿
    NoCoverage端点存在,但所有沿的 slack 未知
    NoEndpoints没有端点,不能视作 setup 已通过

    JSON 请求可加 "setup_summary":true,在原 result 旁添加 setup_summary;缺省或 false 不添加字段,坏类型报错。可以与 "period_budget":true 组合,两者共享同一次时序结果。无值字段在 JSON 中省略。默认调用成功分析即使摘要为 Violated 仍退出 0;自动化调用者可读取 status/覆盖计数,或使用下文显式 CLI 检查模式。

    node tools/sta.cjs examples/sky130-demo.lib examples/setup-summary.json node tools/sta.cjs examples/sky130-demo.lib examples/setup-summary-partial.json

    第一个例程有 3 个输出端点、6 个已约束沿、3 个违例沿与 2 个违例端点,WNS 约 −0.2ns;第二个仅 rise 有约束且 slack 为正,状态为 PartialCoverage。摘要只描述现有受限 setup 模型的端点记录。

    #CLI setup 检查

    显式开启 --check-setup 可用于 CI:只有摘要为 Met 才通过。完整 JSON 仍输出到 stdout,WNS、端点/沿计数与原时序结果保持原含义。

    退出码检查模式含义
    0Met
    3Violated,包括已有违例但另有未知沿
    4PartialCoverage、NoCoverage 或 NoEndpoints
    2参数、读取、JSON、分析或报告写入错误

    # 退出 0;请求文件无需预先开启 setup_summary node tools/sta.cjs --check-setup examples/sky130-demo.lib examples/setup-check-met.json # 退出 3;JSON 中仍有完整报告与违例摘要 node tools/sta.cjs --check-setup examples/sky130-demo.lib examples/setup-summary.json # 退出 4;覆盖不足不能当作通过 node tools/sta.cjs --check-setup examples/sky130-demo.lib examples/setup-summary-partial.json

    flag 放在两个文件路径之前。检查模式在 MoonBit JS 适配层请求现有摘要:缺省或合法 false 都强制为 true,不改写原文件;坏类型仍由原核心报错。可选 period_budget 不变。旧双路径调用与普通 JS 导出 analyze_json 保持原行为;两个路径参数中即使库的字面文件名是 --check-setup,也仍按旧模式读取。检查只判断现有受限 setup 模型的摘要。

    #Netlist JSON 字段路径诊断

    netlist_from_json 保留原 STAError。可选的 netlist_from_json_with_diagnostics(value) 解析相同结构与数值,失败时抛出 NetlistJsonDiagnostic(original_error, pointer),便于在多个 ports/gates/connections 对象中定位缺失或类型错误。它不修改传入的 Json。

    pointer 是相对于独立 Netlist 根的 JSON Pointer:空字符串表示根,数组下标是 0-based 元素下标。例如 /gates/1/connections/1/net 指第二个单元的第二条连接的 net;它不是行列、字节或 UTF-16 offset。缺失字段指向预期的子字段;应为对象但实际为其他类型时指向该值本身。路径只遍历已有的 ASCII schema 键,Unicode 名称/值不作为路径片段,未知键(包括 Unicode、/、~)仍忽略。

    首错沿用原解码顺序,不按 JSON 对象键的书写顺序排序:先 ports,再 gates,再 nets;数组从 0 递增。端口先 direction,再 name/net;单元先 connections(每项先 pin 再 net),再 name/cell;net 先 wire_cap_farads,再 name。输入/输出方向仍接受 input/Input/output/Output,数值类型接受政策和空数组政策保持原样。

    moon build --target js --release node tools/check-netlist.cjs --help # 退出 0;含多个对象、Unicode 名称和未知扩展键的合法结构 node tools/check-netlist.cjs examples/netlist-diagnostic-valid.json # 退出 2;保留 JSON string required,pointer 为 /gates/1/connections/1/net node tools/check-netlist.cjs examples/netlist-diagnostic-error.json

    独立 JSON schema 为 moonbit.sta.netlist.v1:成功返回 ok:true;失败返回 ok:false、原 error 和 pointer。无可解码语义位置的 JSON 语法错误使用 pointer:null,已解码但类型错误的根使用 pointer:""。核心 check_netlist_json(text) 和同名 JS 导出提供此边界;JS/文件入口允许单个首 BOM,文件须为合法 UTF-8,源字节不改写。文件/编码/输出错误写入 stderr 并退出 2,--help 无需构建。

    此检查只解码已有 Netlist 结构,不执行图、驱动、引脚/库匹配、数值范围或时序分析;例如负线电容仍能被结构解码,后续 STA 保留原来的数值校验。原分析 API、默认错误 JSON、SDC 诊断及所有时序结果合同不变。

    #未约束端点的因果见证

    原报告已经能按 pin/edge 定位未知 slack,也能区分 arrival 和 required 缺失。需要解释缺失 arrival 的上游来源时,可选调用 engine.run_setup_with_constraint_context():在同一次 setup 传播中返回原 timing 和 constraint_context,不改变默认分析、摘要、周期预算、JSON 或错误合同。

    每个原有未知 slack 端点边沿最多带一条 launch_witness:原始输入端口 port、既有转义报告身份 pin、源 edge、实际接受的 net/时序弧路径。MissingInputDelay 表示该输入边沿未设 delay;IdealClockNoDataArrival 表示理想 clock 端口本来不作为数据 arrival,不能据此给 clock 添加被禁止的 input delay。DFF 的 Q 从时钟发射,切断 D 的缺失来源。缺少输出 delay 的端口另以原始名 missing_output_delay_port 标出,两类原因可同时存在。

    见证的 path 不伪造 arrival:source 步没有 delay_seconds,net 步按现有模型为 0,时序弧步保留本次已查表的延迟,单位为秒。它按引擎既有接受弧/相关输入/边沿顺序选择一条缺失来源,不是最坏时序路径、全部缺失输入清单或完整路径覆盖认证。若另一路已有 arrival,保持原端点覆盖规则,不把该端点重新归类为未覆盖。

    moon build --target js --release node tools/constraint-context.cjs --help node tools/constraint-context.cjs examples/constraint-context.lib examples/constraint-context-netlist.json examples/constraint-context-partial.sdc node tools/constraint-context.cjs examples/constraint-context.lib examples/constraint-context-netlist.json examples/constraint-context-complete.sdc

    自编常数 1D 反相器例子中,partial 输出 out~1~0😀/Rise 追到输入 a~1~0😀/Fall,经 inv~1~0😀/A、inv~1~0😀/Y 的 0.2ns 反相弧;直连 alias~1#/Fall 还缺自身的 output delay。完整对照输入为 0.6ns、反相器 arrival 为 0.8ns、required 为 1.8ns、slack 为 1.0ns,context 为空。该合成数据只用于手算验证,来源见 SOURCES。

    独立三文本核心/JS 入口 analyze_constraint_context_json(library, netlist, sdc) 使用默认 Extrapolate,返回 moonbit.sta.constraint-context.v1,包含原 result、原方法派生的 setup_summary 和 constraint_context。网表是独立 Netlist JSON,SDC 保持原文;库/网表文件允许单个首 BOM,所有文件须为 UTF-8,文件不改写。它不接收旧 request flags 或计算周期预算;原入口继续提供那些能力。

    文件工具退出 0 表示分析完成,包含 PartialCoverage 或负 slack 的情况;输入/分析/输出错误退出 2,主机 IO/编码诊断写 stderr。--help 无需构建。这是对现有受限模型报告的因果解释,不是时序闭合、所有路径约束完整或生产签核保证。

    #指定发射端与捕获端的路径查询

    全局报告只保存每个节点的一条最晚 arrival 路径。指定来源在汇合处落选时,筛选原 path 找不回它的后续弧。可选入口在同次原分析中保留所有实际接受弧已算出的延迟,再沿原输出 DAG 查询一个精确来源:

    let query : @sta.PathQuery = {
    launch: InputPort("b", Rise),
    capture: OutputPort("out", Rise),
    }
    let analysis = engine.run_setup_path_query(query)
    // analysis.timing 是原全局报告;analysis.path_query 是指定来源的结果。

    PathLaunch 是 InputPort(raw_name, edge) 或 RegisterQ(raw_instance, raw_pin, edge);PathCapture 是 OutputPort(raw_name, edge) 或 RegisterD(raw_instance, raw_pin, edge)。寄存器点必须是已支持 ff 的真实 Q/D。原始分量按字面精确匹配,不展开通配符,输出的 launch/capture/path pin 沿用原可逆报告身份。

    node tools/path-query.cjs examples/path-query.lib examples/path-query-netlist.json examples/path-query.sdc examples/path-query.json node tools/path-query.cjs examples/path-query-changed.lib examples/path-query-netlist.json examples/path-query.sdc examples/path-query.json node tools/path-query.cjs --batch examples/path-query.lib examples/path-query-netlist.json examples/path-query.sdc examples/path-queries.json cat examples/path-queries.json | node tools/path-query.cjs --batch --query-stdin examples/path-query.lib examples/path-query-netlist.json examples/path-query.sdc -

    查询 JSON 为 {"from":{"kind":"input_port","name":"b","edge":"rise"},"to":{"kind":"output_port","name":"out","edge":"rise"}}。寄存器 kind 分别是 register_q / register_d,用 instance、pin 代替 name;edge 只接受 rise / fall。顶层可选 range_policy 沿用 extrapolate(默认)/reject/clamp。

    示例中 A 以1ns发射,经过0.2+0.3ns,全局 arrival1.5ns、slack0.3ns;B 以0.1ns发射,经过0.4+0.3ns,查询 arrival0.8ns、required1.8ns、slack1ns。第二个库仅把落选 B 弧改为0.6ns,原完整报告相同,查询 arrival 变为1ns、slack0.8ns。输入与逐步独立期望见 examples/path-query-cases.json。

    四文本核心/JS 入口 analyze_path_query_json(library, netlist, sdc, query) 返回独立 moonbit.sta.path-query.v1,包含原 result 与 path_query。查询结果明确使用 queried_arrival_seconds、queried_slack_seconds,还有 required_seconds、身份和一条 owned path;全为秒,未知数值省略。

    批量入口 engine.run_setup_path_queries(queries) 和 analyze_path_queries_json(library, netlist, sdc, queries_json) 在一次完整 STA 分析后按输入顺序处理最多 1024 条精确查询。JSON 输入为 {"queries":[{"from":...,"to":...}, ...]},顶层同样可选 range_policy;响应 schema 为 moonbit.sta.path-queries.v1,包含一份原 result 和同序 path_queries。空数组返回完整报告和空查询列表。每条查询保留单查询的 Found/NoPath/UnconstrainedLaunch 语义;任一查询点非法会使整个批量请求失败。完整文件样例见 examples/path-queries.json。

    status含义
    Found实际接受的边沿路径存在且发射 arrival 已知;缺捕获约束时 required/slack 仍省略
    NoPath两个合法查询点之间不存在该边沿数据路径;path为空,无数值查询字段
    UnconstrainedLaunch路径存在但发射 arrival 未知;path为空,无数值查询字段

    新 JSON 边界先解析 Netlist、库、SDC,再解析 query 形状/范围策略;typed 引擎先完成原 setup 分析,再按 launch、capture 顺序验证点,最后判可达性。不可达优先 NoPath,可达且 launch 未知才是 UnconstrainedLaunch。坏原输入与非法查询是错误。三种有效状态均退出0,包括负查询 slack;参数/编码/IO/分析/查询/输出失败退出2。--help 无需构建或输入。--query-stdin 把末尾 - 作为标准输入的查询 JSON(读到 EOF);可与 --batch 任意顺序组合,未加该选项时 - 仍是文件名。入口严格 UTF-8,库/网表/query 允许单个首 BOM,SDC 保持原文,源文件不改写,相对路径以调用者 cwd 为准。

    每条弧权使用完整原设计的 GBA worst-slew 和实际负载,捕获 setup 也沿用原分析;不沿指定路径重算 slew/load。Q 使用原 clock-latency/tCQ 前缀独立发射,数据图没有 D→Q 边。查询 slack 不能当全局 WNS或签核结论。同值沿用原 timing-group/related-pin/edge 遍历顺序取一条;不支持 all paths/top-K、through、内部端点、路径异常或新的时序模型。默认报告、诊断、数学和原可选入口保持。

    examples/path_query_receiver 是单独编译、只调用公开 typed API 的自编消费包;python3 tools/ci-path-query.py 从其他 cwd 用真实四文件调用并核对冻结的完整路径/时间/状态,保留原始 stdout/stderr。它们属于自编集成验证,不代表第三方采用。

    #映射设计的 pin 电气上限

    Setup Met 和查表坐标合法并不等于满足库里声明的 pin 上限。可选 engine.run_pin_limit_analysis() 先运行原 setup,再用原完整设计的每 pin/edge slew 和输出 driver load 检查:

    • 实例输出 pin 的简单标量 max_capacitance,按库电容单位转法拉。
    • 实例输入/输出 pin 的简单标量 max_transition,缺失时用库级 default_max_transition,按时间单位转秒;包括已支持 FF 的 CLK/D/Q。

    # 相同原始 timing:严格库报告4项超限,放宽声明的库为Met node tools/check-pin-limits.cjs --range-policy reject examples/pin-limits.lib examples/pin-limits-netlist.json examples/pin-limits.sdc node tools/check-pin-limits.cjs --range-policy reject examples/pin-limits-met.lib examples/pin-limits-netlist.json examples/pin-limits.sdc # 自编映射设计使用现有真实Sky130子集;保留原Extrapolate诊断 node tools/check-pin-limits.cjs examples/sky130-demo.lib examples/pin-limits-real-netlist.json examples/pin-limits-real.sdc

    严格例的源输出负载是 wire0.25pF + 后级输入0.25/0.5pF + alias外部负载0.5pF,得到rise1pF/fall1.25pF;上限1pF,rise等于上限仍满足。加上三项 transition 超限,共4项。两套声明的完整原 timing 一样且 setup Met,所有 NLDM 坐标在网格内。实库例负载0.2pF高于声明0.181284pF,也超过实际 timing 网格,所以使用原外推策略;还报告 Rise slew 超限,共3项,不作为网格内证明或新精度验证。

    返回 PinLimitAnalysis { timing, pin_limits }。pin_limits.checks 是 owned 的完整规则/pin/edge列表,按实例、库pin次序、输出电容/transition、Rise/Fall排列。每项含原始 instance/cell/library_pin、原转义报告 pin、edge/kind/unit、actual_si、可选 limit_si/margin_si,以及声明来源、属性名、解码后的值文本和问题。margin = limit - actual,严格 actual > limit 才超限。输出电容使用原网表全负载;Clamp 仅作用查表坐标,不改变这里报告的物理负载。未知数据 arrival 不妨碍已有 slew/load 检查。

    每项 status含义
    Satisfied / Exceeded有可表示的非负 SI 上限,分别为满足/超限
    NotSpecified没有适用声明;不补0
    InvalidLimit已存在但无效、转换不可表示或形式不受支持;bound/margin省略,原timing保留

    显式 pin 声明(含0或无效值)优先于库默认,不因无效而偷偷回退。原解析/分析已经拒绝的输入仍给原错误;旧分析接受的负上限等元数据由新报告标记 InvalidLimit,原 API 接受行为保持。没有库默认电容的推断。复杂/分组形式会明确标记不支持。

    总计按规则/pin/edge记录为 checked_rules、violated_rules、unspecified_rules、invalid_rules。JSON 总状态优先 Violated,其次 InvalidLimits,再是 NoDeclaredLimits,否则 Met;Met只表示所有适用且已声明的支持规则满足,不保证每个pin有上限或签核通过。typed 总状态构造名为 LimitsMet / LimitsViolated / InvalidLimits / NoDeclaredLimits,避免影响旧 SetupSummary 的名字;JSON名称仍为 Met/Violated。

    公共核心/JS analyze_pin_limits_json(library, netlist, sdc, range_policy) 接收四个 String,最后一项明确为 extrapolate / reject / clamp,输出 moonbit.sta.pin-limits.v1,含完整原 result 与 pin_limits。文件工具只读三个 UTF-8文件,--range-policy 默认 extrapolate,库/网表允许单首 BOM,SDC保持原文。有效报告始终 ok:true;checker退出码0 Met、3 Violated、4 InvalidLimits/NoDeclaredLimits、2参数/编码/IO/原分析/输出错误,stdout失败覆盖为2。--help无须构建。

    不检查端口/SDC设计规则覆盖、最小值、fanout、动态/table上限或其他pin角色;不重算 slew/load、改变时序科学模型或声称 OpenSTA 等价。examples/pin_limit_receiver 与 tools/ci-pin-limits.py 分别执行公开 typed 包和任意三文件接收链,按 examples/pin-limit-cases.json 的完整冻结行核对结果;属于自编集成验证。

    #把成功分析完整保存到新文件

    需要保留 CI 报告时,可直接保存完整的原分析 JSON。目标必须是新路径,父目录须已存在:

    moon build --target js --release node tools/save-analysis.cjs examples/save-analysis.lib examples/save-analysis-request.json report.json

    save-analysis.cjs 读取原有 Liberty/请求两个UTF-8文件,调用同一个公开 analyze_json,将完整成功报告的原 UTF-8 字节加 LF 保存到指定文件。请求中的范围策略、周期预算和setup摘要保持原样;负 slack 或未知 slack 的合法成功分析也可保存、退出0。它不增加输入/报告格式,不改变原时序模型或其他CLI。

    文件先写入同目录中专属的临时名称,刷盘并关闭后,通过硬链接原子创建目标名称,再清理自己的临时名称。已有目标、目录或输入文件都不会被覆盖;并发保存同一路径也只有一个进程能成功。没有覆盖/force模式、自动创建目录或复制覆盖回退;不支持硬链接的文件系统明确失败。这里保证进程级完整文件可见性,不保证断电后的目录持久性。

    分析错误保留原错误JSON stdout、退出2,不创建目标。参数/编码/输入IO/缺少构建/文件发布错误写stderr、退出2;发布前的写入/刷盘/关闭/链接失败不会把部分数据变成目标文件。发布后的临时清理或stdout失败可能退出2,但完整目标仍保留,stderr会说明已经提交的文件;不会假装回滚而删掉它。成功时stdout仍为完整原报告,退出0。

    两个输入沿用原严格UTF-8/单首BOM处理,路径按调用者cwd解释,源文件不改写;--help无需构建。普通 sta.cjs stdout/重定向用法保持原合同。新命令适合显式创建一份报告文件,调用者仍需保管它并核查下游接收。

    examples/save-analysis-cases.json 保存实现文件入口前由原CLI产生的5份完整字节预期;python3 tools/ci-save-analysis.py 用27次实际进程核对文件、stdout、错误和并发结果。部分写入/刷盘/关闭/链接/清理失败均为明确标注的受控故障,不是实测磁盘耗尽;初始重定向证据和故障残留均保留。测试只复用已构建的MoonBit核心,不重做物理参考或setup比较。它们是自编集成验证,范围见 CI-PLAN.md。

    #按不同端点定位 setup 修复顺序

    已有成功报告可直接查询最需要检查的不同 pin,每个 pin 只占一个名额:

    node tools/prioritize-setup.cjs --max-endpoints 2 examples/setup-priority-report.json # 默认选至多10个不同 pin;0仍给完整覆盖和省略数量 node tools/prioritize-setup.cjs examples/setup-priority-report.json

    例程完整原报告的 slow 裕量约为−1ns,fast/partial 的已知裕量约为1.75ns,另有3个未知沿。限额2选 slow 再选 fast,不会让同一个 pin 的 Rise/Fall 占满两个名额。输入源是既有 moonbit.sta.v1 成功报告;查询不运行时序、不保存文件,也不改变原分析和检查退出规则。

    MoonBit 调用 report.prioritize_setup_endpoints(max_endpoints=2),返回 SetupEndpointPriorities;省略参数为10。JSON/API入口是 prioritize_setup_json(report_text, max_endpoints),输出 moonbit.sta.setup-priority.v1。每个精确 pin 选最小已知 slack,沿间同值保留最早原始行;不同 pin 同值按第一次出现的顺序。按最差已知 slack 从小到大选至多 N 个不同端点。缺失/null slack 保持未知,带部分未知沿的 pin 保留已知最差值和未知数量;全部未知的 pin 在 unranked_endpoints 完整列出,不占 N,原顺序保持。

    每项含 pin、first_source_index、endpoint_edges、known_edges、unknown_edges;已知项再含 worst_source_index、worst_edge、worst_slack_seconds。索引是原 STAResult.endpoints 的0-based位置,调用者可据此取回完整原端点与路径。结果另含明确的 unit:"s"、限额、总端点/沿、已知/未知沿、可排序/不可排序/已选/省略可排序端点数量。原数组/路径不变,返回数组可独立修改。不按名称解码/规范化,不用 epsilon 或差值算术排序。

    typed限额为非负 Int,0合法;JSON/JS参数必须是0..2147483647的有限整数,CLI使用该范围内的十进制数字。所有源行都会检查,包括限额外的重复/空 pin、非法 edge 或非有限 slack。JSON只消费 pin/edge/slack 视图,忽略未使用字段/扩展;不验证这些字段之外的路径或物理来源。空数据及负/未知裕量都可成功查询、退出0,不能据此认定setup合规。坏报告/参数/编码/IO/build/stdout退出2;结构化报告错误保留 ok:false JSON,主机错误写stderr。严格UTF-8、单首BOM、调用者cwd/Unicode路径和无需构建的独立 --help 齐备。

    examples/setup-priority-cases.json 中35份完整排序/覆盖/错误预期在实现前冻结;独立公开包消费者用11组typed结果取回原完整端点/路径。python3 tools/ci-setup-priority.py 用45个真实进程核对文件/API/消费者/错误边界,包括7次直接JSON设置调用、原分析字节兼容及分发例程。它们是自编集成证据,不是外部采用、路径枚举或新的时序参考。原示例可用 setup-priority.lib 和 setup-priority-request.json 重新生成;本地验证不重复历史科学批次,范围见 CI-PLAN.md。

    #比较既有 setup 报告的相对退步

    两个设计都为 Met,候选的 slack 仍可能相对基线变差。比较门禁直接读取既有成功的 moonbit.sta.v1 分析报告,不增加输入格式,不重新执行时序:

    moon build --target js --release # 两份原始报告均为Met;相对退步0.25ns,退出3 node tools/compare-setup.cjs examples/setup-baseline.json examples/setup-candidate.json # 显式允许损失0.5ns,单位为秒,退出0 node tools/compare-setup.cjs --max-slack-loss 5e-10 examples/setup-baseline.json examples/setup-candidate.json

    这两份文件在实现比较器前,由原 CLI 对新写的简单 BUF 样例各运行一次保存:1ns launch、2ns周期、0 output delay,基线/候选常量延迟分别0.25ns/0.5ns,Rise/Fall slack 分别0.75ns/0.5ns。原始 stdout 字节保留在文件中,模型/请求也随 examples/setup-comparison-*.lib、setup-comparison-request.json 提供。这是自编固定模型,不是新物理精度或签核证据。

    公共 compare_setup_results(baseline, candidate, max_slack_loss_seconds=0.0) 接受现有 STAResult,返回 owned 的 SetupComparison。只消费端点的原报告 pin、edge、slack;不解析、改名或规范化标识,Rise/Fall分开匹配。输出行按基线顺序,再追加仅在候选中出现的端点;两份输入和路径数组不改写。空/重复的端点身份和非有限 slack 会在新比较入口明确报错,原分析与解码入口不变。

    slack_delta_seconds = candidate - baseline,严格小于 -max_slack_loss_seconds 才算退步,等于容差时允许。逐行区分退步、改善、不变、允许的损失、单侧端点及单/双侧未知 slack;未知值不补零。两个有限 slack 的差值若超出 Double 表示范围,仍按确定的方向判定退步或改善,并省略无法表示的 delta;负向溢出的损失必然超过任何有限容差。报告含 SI 秒、阈值、两侧端点/沿数、匹配/可比较/退步/不完整计数和完整行列表。已知退步优先为 SetupRegressed;无已知退步但有集合变化、未知或没有可比较端点时为 SetupComparisonIncomplete;其余为 NoSetupRegression。两份空报告不作为通过。

    核心/JS compare_setup_json(baseline, candidate, max_slack_loss_seconds) 输出独立 moonbit.sta.setup-compare.v1、ok/comparison;输入/设置错误为 ok:false/error。输入必须是原 moonbit.sta.v1 成功报告;只验证消费的端点身份/slack视图,其余字段与扩展键忽略。未知 slack 可省略或为null。JS第三个参数是Number,阈值必须有限、非负;文件工具默认0,只读严格UTF-8,允许各单首BOM和调用者相对路径。退出0完整且无相对退步、3已知退步、4比较不完整、2参数/编码/IO/报告/设置/输出错误;--help无须构建。

    它不代替原 setup 合规检查:两份同样为负的 slack 也可能通过相对门禁。比较所需的设计、模型、约束及来源可比性由调用者控制,报告本身不足以证明这些条件;没有新GBA、路径排序、WNS/TNS近似、driver/环路/PPA或签核范围。

    examples/setup-comparison-cases.json 的30组完整独立预期覆盖严格/等值容差、原始报告、缺失与集合变化、输入顺序、极大有限数/溢出、错误与原始身份。examples/setup_comparison_receiver 独立编译后调用公开typed API;python3 tools/ci-setup-comparison.py 运行46个实际接收进程并保存完整输出/输入副本身份。typed接收器重建公开端点视图,忽略比较不消费的nodes/paths,不重新计算时序。它们是自编集成验证,非第三方采用;验证范围见 CI-PLAN.md。

    #时序设置前的标量引用预检

    已有 Netlist JSON 能被解码,但单元、pin 或 net 名称仍可能接错。独立预检仅需现有 Liberty 和网表,不要求 SDC、时间/电容单位、pin 电容或时序表:

    moon build --target js --release node tools/check-references.cjs examples/reference.lib examples/reference-netlist.json # 退出3,完整报告一次保留14项独立问题 node tools/check-references.cjs examples/reference.lib examples/reference-issues.json

    公共 typed check_netlist_references(library, netlist) 返回 NetlistReferenceReport,不因语义问题抛首错;issues 是 owned 的完整列表。检查非空/唯一 net 名、原有共享命名空间中的 port/instance 名、port/connection 的 net 是否声明、原始名的 cell/pin 是否存在、重复连接和每个直接建模的库 pin 是否已连接。沿用 Library.cell / Cell.pin 的精确首个匹配,不修改原名称或输入。未知 cell 只报告明确的 cell 问题,跳过无法确定的 pin/漏接推断,独立的重复连接和 net 问题仍保留。

    每项含稳定的 Ref… code、相对于独立 Netlist 根的 pointer、原始错误/预期 name;重复项另给 first_pointer。路径使用 ASCII schema 键和0-based数组下标,不把原始名称嵌入路径。漏接项指向该实例的 connections 数组,name 是缺少的库 pin。顺序为 nets、ports(身份后net)、gates(身份、cell、逐连接重复pin/未知pin/net、最后按库序列出漏接pin)。空名称不登记为可引用声明,重复项始终指向首次非空声明。

    报告含输入实体和连接记录数、matched_instances、matched_pin_connections、issue_count 与全部问题。matched pin 计数只表示记录中的库侧 pin 存在,包含重复记录及目标 net 未解析的记录。状态为 ReferencesResolved 或 ReferenceIssuesFound,scope=scalar_names_and_references。空设计解析为0计数、无问题。

    这项预检不检查 pin direction/role、驱动、环路、wire 电容数值、时序弧/顺序模型、全库 lint、层次或 bus 展开,也不运行图构建/GBA。所有直接建模的 pin 都按名称检查,包括 inout/缺 direction 的元数据。ReferencesResolved 仅表示此引用 profile;含环路或重复驱动的设计仍可能解析全部引用,后续 STA 保留原有校验。固定上游的引号非BMP解析限制仍按实际模型呈现,未修依赖或偷偷改名。

    核心/JS check_netlist_references_json(library, netlist) 返回 moonbit.sta.references.v1,语义结果为 ok:true 和 references;形状/解析错误为 ok:false/error/pointer,沿用原结构诊断文本和路径。JSON语法或Liberty解析失败没有语义位置,pointer:null。两文件工具使用严格 UTF-8、各单首 BOM、调用者 cwd,不重写源文件;退出0无引用问题、3有问题、2参数/编码/IO/解析/输出错误,--help无需构建。

    examples/reference-cases.json 的24份完整手定预期包含14项同时错误、原始Unicode名称、首个重复位置、真实Sky130 INV/DFF及范围控制;examples/reference_receiver 独立编译后调用公开 typed API。python3 tools/ci-references.py 启动37次实际接收进程,保存所有 stdout/stderr、退出码与实际输入副本哈希。均属自编集成验证;相关局部检查和完整必需CI见 CI-PLAN.md。

    #映射实例用量与声明面积

    只有 Liberty 和已映射标量 Netlist JSON,也可以先统计设计资源:

    moon build --target js --release node tools/cell-usage.cjs examples/cell-usage.lib examples/cell-usage-netlist.json

    示例不含时间/电容单位、时序表或 SDC;两个 BUF 的声明面积各为1.25,一个名为 DFF 的合成单元为2.5,结果为3个实例、2种已用单元、总面积5。库里未使用的面积100单元不计入。该合成 DFF 仅是单元名称;真实 Sky130 INV/NAND/DFF 的声明字段另在冻结案例中核对,不将这些计数样例当成完整连接/触发器验证。

    公共 typed 入口 analyze_cell_usage(library, netlist) 返回 CellUsageReport;直接接受现有 Library / Netlist,不需要 STAEngine、约束或 GBA。只要求实例名非空且唯一;不检查连接、pin 角色、驱动或图合法性。所有 flat gates 均计入,端口别名和未用库单元不增加实例;按现有 Library.cell 的精确原名、首个匹配绑定。instances 按输入次序保留 index/原始 instance/cell,cells 按首次使用次序给直方图与面积贡献;这些数组为 owned。

    每行面积状态为 KnownArea、MissingArea、InvalidArea 或 UnmappedCell,保留可用的解码 raw_area、数值和问题原因。数值来自公开 Cell.area;简单、有限、非负值有效,包括零;缺声明、负数、非数字或 complex/group 声明不猜值。程序构造的 Library 同样使用公开数值字段,源文本只提供声明解释。unit 固定为 liberty_declared_area,不转换成物理平方微米。

    known_area_subtotal 是各已知单元面积乘实例数后的有限小计;任一分组乘积或小计溢出则省略,并置 area_overflow。只有全部实例已映射且面积有效、聚合有限时,status=Complete 且给出 total_declared_area;否则为 Incomplete,省略总面积。空设计 Complete、总面积0。Complete 只说明面积覆盖,不证明连接正确、物理 PPA 或时序签核。

    核心与 JS analyze_cell_usage_json(library, netlist) 输出独立 moonbit.sta.cell-usage.v1,含 ok 和 usage(输入错误则为 error)。两文件工具使用严格 UTF-8,库和网表各允许单首 BOM,按调用者 cwd 解释路径,不重写源文件。退出0 Complete、4 Incomplete(含溢出)、2参数/编码/IO/解析/身份/输出错误;--help 无须构建。

    固定上游0.4.1会丢失引号单元名中的非BMP字符,例如 "BUF/~😀" 变为 BUF/~。本工具按实际 Library 模型绑定,不会偷偷修名;裸标识 BUF/~😀 保真。该上游限制保留在原样输入案例中,报告 UnmappedCell;未修解析器或更换依赖。

    examples/cell-usage-cases.json 固定21例的完整期望;初始20例的面积/计数预期保留,主例将同名单元改用合法裸标识,并额外保留原样引号输入的明确未映射期望。examples/cell_usage_receiver 通过独立包实际调用 typed API,python3 tools/ci-cell-usage.py 从其他 cwd 运行两文件接收,并保存实际测试副本和原始 stdout/stderr。它们是自编集成验证,不代表第三方采用。局部验证与必需的完整 CI 范围见 CI-PLAN.md。

    #受限 SDC profile

    这是逐行读取的数据 profile,不执行 Tcl。数值按库 time_unit 和 capacitive_load_unit 转成 SI。先创建一个真实输入端口时钟,-name 与正 -period 必填;可选 -waveform {0 T/2}。对象仅 [get_ports exact_name]、列表 {a b}、或 *(筛选适用输入/输出且不含 clock);时钟对象仅 [get_clocks exact_clock_name]。

    命令支持选项
    create_clock-name、-period、可选 -waveform
    set_input_delay / set_output_delay-clock 必填;-max、-rise、-fall
    set_input_transition-rise、-fall
    set_load输出端口外部总电容;可用 -rise、-fall 分别设置边沿负载;net wire cap 在 Netlist
    set_clock_transition-rise、-fall
    set_clock_latency共同 ideal latency,允许有限负值,无其他 flag
    set_clock_uncertainty-setup

    无边沿 flag 表示两沿;同字段重复命令覆盖,其他边沿保留。允许整行注释及空白后、分组外的行尾 # 注释;名称词中的 # 和选择器列表内的 # 保留为名称,例如 [get_ports {a#b}]、[get_ports {#data}]、[get_clocks core#clk]。含方括号的独立标量名称需放在花括号中,例如 [get_ports {data[0]}]、[get_ports {data[0] data[1]}];花括号内的方括号按名称字符保留,不作嵌套命令解释。此处没有向量声明、位展开或总线运算。这是受限 profile 的名称/注释规则,不执行完整 Tcl。允许空白,不允许变量、引号、续行、分号脚本和嵌套命令。未知命令/flag、-min、-add_delay、第二时钟、错误对象、空选择器、错误方向都拒绝;create_clock 在解析时检查真实输入端口与非空 plain name。未设置 clock slew 为 0 并按选定范围策略查询;实际例子显式给出 clock/input slew。

    例如,以下两条命令为输出端口 y 的上升沿和下降沿分别指定负载,数值采用 Liberty 库的电容单位:

    set_load -rise 0.02 [get_ports y] set_load -fall 0.03 [get_ports y]

    #SDC 源位置诊断与文件检查

    parse_sdc 继续抛出原 STAError。需要在较长文件中定位失败命令时,新增的 parse_sdc_with_diagnostics(text, library, netlist) 抛出 SdcDiagnostic(original_error, position),保留原错误类别、消息和优先级;合法输入得到相同 TimingConstraints。

    position 是失败命令的起点,不是坏 token 的精确范围。line、column 从 1 开始,offset 从 0 开始;列与 offset 都按原始 MoonBit/JavaScript String 的 UTF-16 code unit 计数。LF 开始新行,CRLF 占两个 offset 单位,tab 占一列,补充平面字符占两个单位,不按终端视觉宽度计算。行内分词/分组、未知命令/flag、数值、选择器及端口绑定错误均指向该命令;文本预算、库前置校验、缺少 clock 等没有具体失败命令的错误位置为 None。源文本不做换行、Unicode 或 BOM 归一化。

    独立文件消费者读取 Liberty、一个包含 ports/gates/nets 的独立网表 JSON 对象及原始 SDC 文件:

    moon build --target js --release node tools/check-sdc.cjs --help # 故意含不支持的 -min:退出 2,位置为 line6/column3/offset115 node tools/check-sdc.cjs examples/sky130-demo.lib examples/sdc-diagnostic-netlist.json examples/sdc-diagnostic-error.sdc

    输出采用独立 moonbit.sta.sdc.v1 JSON schema。有效约束退出 0 并返回 constraints;SDC/JSON/库错误退出 2 并返回原 error 和 position(无位置时为 null)。文件/编码/输出错误退出 2,诊断写入 stderr。输入须为合法 UTF-8;库和网表允许单个首 BOM,SDC 原文完整保留。--help 无需构建。JS 导出 check_sdc_json(library, netlist, sdc) 提供同一边界。

    此入口仅做已有受限 SDC 的解析和约束绑定,不执行时序分析、完整网表图校验或 Tcl;它的通过不代表完整 STA 能运行或时序满足。原 analyze_json、tools/sta.cjs 及其默认错误 JSON 保持原合同。

    #组合环诊断验证

    旧诊断把 Kahn 拓扑排序后所有剩余任务当作环成员,导致 loop→tail 中只有 loop 自环时仍报告 loop、tail。失败分支现用迭代强连通分量遍历标记实际有向环成员;正常图跳过该遍历。类型、输入、时序数学和已有 JSON/JS/CLI 不增加新格式或新拒绝。

    examples/cycle-diagnosis-cases.json 在修复前冻结21份完整图与前后预期:15个环图、3个正常图和3个先行错误控制。它包含全部环分量、环间非循环桥、跨分支SCC、多输出/去重、原始名称/顺序及128级下游链;正常报告和先行错误保留完整原字节。独立公开包消费者通过原STAEngine调用21例,并检查 setup、周期预算、pin电气检查、因果上下文、指定路径5个受影响typed方法;4个附加JSON入口也核对完整错误。python3 tools/ci-cycle-diagnosis.py 执行25个实际进程,保存实际输入副本、全部流和退出;这些是自编诊断回归,不增加科学参考或声称外部采用。

    #验证

    历史基线的 13 个 MoonBit 黑盒测试涵盖真实顺序路径、时钟/不确定度、SI 负载、反相边沿、unconstrained、寄存器反馈、真实组合环、结构/数值错误、SDC 拒绝/覆盖、JSON 错误和外推策略;JS、Wasm-GC 与 native 的实际结果见 VALIDATION.md。

    历史基线:独立 Ubuntu OpenSTA 2.0.17(2019 c018cb2 系列、官方 Ubuntu 二进制包)与 JS 导出消费者,在 8 个共享输入案例上比较 680 个 AT/slew/端点 required/slack 字段,实测最大绝对误差 0.000164685 ps,小于 1 ps 候选模型预算。三种组合图、线电容、正负 slack、真实 DFF 及四类路径均包含在内。此结果只属于这组固定库/图模型,不能外推任意 PDK/复杂寄生或所有商业电路。关键路径对照限已报告最坏端点/沿,未声称穷举所有路径。

    2026-10-28 深入修复新增 7 项回归,第 05 轮共 20 项,JS、Wasm-GC、native 均通过。新增 8 组真实 OpenSTA 对照比较 314 个数值字段,最大差约 0.000164146 ps;另核 16 条 DFF 路径求和、36 项时间/电容单位缩放关系,以及 arrival/slew 来源分离、负 setup/交换变量轴、负 latency、端口别名和半沿未约束。未约束沿的 required 按显式输出约束独立断言,OpenSTA 该沿不生成 clocked required。详见 VALIDATION.md。

    第 06 轮补齐缺省 timing_sense 的单调方向、单沿 timing group 与零 slew 来源。新增 6 项黑盒,第 06 轮 JS/Wasm-GC/native 各 26/26;新增 8 组真实消费者/OpenSTA 对照共 216 字段,最大差 0.000164685 ps。两项保守双沿控制和破损表错误路径一并核验;第 03/05 轮集合未重复运行或计数。

    第 07 轮修复多输出合法图被实例级依赖误判为组合环,并按输出依赖执行、完整记录每个 pin。新增 4 项回归,JS/Wasm-GC/native 各 30/30;4 组自编标量/1D 模型经实际 Node 消费者与 OpenSTA 对照 128 字段,最大差 0.000081062 ps,另有 8 项手算到达值检查。真实输出回路仍拒绝;表查找算法未改。

    第 08 轮修复报告名称拼接冲突,保留所有合法原始输入;新增 4 项回归,JS/Wasm-GC/native 各 34/34。4 组实际 Node 消费者检查唯一身份和路径/贡献引用,另核 6 项手算到达值及 82 项 DFF 重命名数值不变性;Unicode-only 控制 before 已通过。未改时序算术或重跑旧 OpenSTA 集合。

    第 09 轮增加周期预算和原生 Netlist JSON 往返兼容。第 09 轮 43 项黑盒在 JS/Wasm-GC/native 均通过;两套模型在预测下界±1ps与边界的 6 次实际 OpenSTA 重算比较 180 字段,最大差 0.000066543 ps,边界/符号和预算不随目标周期变化的断言通过。另以原生枚举 JSON 的 44 字段对照验证参考 writer 兼容。详见 VALIDATION.md 与 SOURCES.md。

    第 10 轮修复共同时间平移下的路径/slack/周期预算消减错误。新增 5 项回归,JS/Wasm-GC/native 各 48/48;6 个实际消费者输入在原样 before/after 对照,等价零偏移 OpenSTA 的 3 个目标周期比较 84 字段,并独立核 6 个大偏移 slack。公开 API 不变,原有限大数范围保留。

    第 11 轮修复有符号约束短和中的相消及中间溢出:新增 4 项黑盒和 1 项含 384 组独立有理数预期的白盒,JS/Wasm-GC/native 各 53/53(52 项黑盒+1 项白盒)。12 次实际 Node 消费覆盖 4 个原样 before/after 反例、相消/近相消下界±1ps、3 种真正最终溢出及真实 Sky130 DFF;60 个约束数值字段精确匹配一次舍入的有理数预期。该核对检查约束算术,不作为新增 NLDM/物理模型精度成绩。公开 API/Double 字段不变,历史 OpenSTA 集合未重跑。

    第 12 轮修复 SDC 选择器二次分词误把 # 当注释、静默截短名称的问题。新增 3 项回归在 JS/Wasm-GC/native 各 3/3;JS 的相关既有 SDC 4/4、名称 4/4。4 个原样 before/after Node 输入中,3 个反例修复,已有注释控制保持正确;20 个直连网表数值字段按独立 SI 手算通过。未执行本轮完整 root 套件,不把历史 53/53 宣称为新 56 项全套成绩。可运行 node tools/sta.cjs examples/sky130-demo.lib examples/hash-names.json 查看精确名称绑定。

    第 13 轮修复花括号内标量位名称的方括号被误判为嵌套命令。新增 2 项在 JS/Wasm-GC/native 各 2/2;JS 相关既有 SDC 4/4、上轮 hash 名称 3/3。3 组原样消费者位名场景按独立直连公式核 15 个数值字段,另 1 组真正嵌套命令保持拒绝。未重跑完整 root 或旧数值集合。可运行 node tools/sta.cjs examples/sky130-demo.lib examples/scalar-bit-names.json 查看标量位名称列表的精确绑定。

    第 14 轮为 CLI 文件入口有限审查,未发现新缺陷,运行时代码未改。4 次实际调用覆盖外部工作目录下的中文/空格/Unicode 相对路径、缺 Liberty 文件、缺请求文件和坏 JSON。成功报告与第 11 轮封存报告整体等价,输入字节 SHA 一致;3 个错误按既有输出/退出契约通过。仅更新入口说明与回执,未重复编译或执行无关的核心数值测试,四个实际 release 产物身份保持。

    第 15 轮先研究违例摘要与 SDC 位置诊断两个候选,选择实现可选 setup 摘要。新增 5 项在 JS/Wasm-GC/native 各 5/5,相关既有 JSON/周期预算 JSON 回归共 2/2;10 次实际消费者验证 7 个摘要场景的 56 项状态/计数/值字段检查,以及缺省/false/坏 flag。原 result 和 period_budget 与同输入拓展前逐字段一致。原 API 声明保留,新增 enum/struct/报告方法;未重跑完整 root、OpenSTA 或旧 I/O/数值集合。

    第 16 轮增加显式 CI setup 检查,核心 29 个公开声明与摘要/WNS 算法未改,普通 JSON/CLI 模式保留。13 次真实 CLI 调用验证退出 0/2/3/4、10 份完整输出等价、缺省/false 自动摘要、非法类型及 JSON、字面 flag 文件名与 Unicode/非零电容保真。只检查并构建新增 JS 适配层,未重跑第 15 轮已冻结的三端测试或旧消费者集合。

    第 19 轮在 Node/JS 输入边界补齐单个 UTF-8 BOM 兼容,不修改核心解析器或依赖版本。11 个新的编码场景通过,8 份完整输出与冻结报告/明确名称变换一致;包含普通与检查模式、库/请求组合、内部 U+FEFF 保真、部分覆盖及错误控制。root 29 声明和两个 JS 签名保留,只构建相关 JS 适配;旧核心/门禁/错误序列/大流式集合未重跑。

    第 20 轮增加显式请求 stdin 输入,沿用同一 JSON/UTF-8/检查链。14 个真实消费者通过,9 份完整报告与冻结输出一致;含分段 BOM/内部 U+FEFF、EOF、退出 0/2/3/4、坏输入和旧字面文件名控制。运行时代码只改 Node IO 入口,MoonBit 核心/接口与四个编译产物保持;未重跑旧数值集合。

    安装独立 OpenSTA 2.0.17 后,可复现仓库内自编例子(先按上述命令构建 JS):

    python3 tools/verify-opensta.py --sta /path/to/sta --request examples/four_paths.json

    结果和原始报告写到 _build/oracle/;该工具只做输入序列化、调用和逐字段比较,无 STA 参考算法副本。脚本适配已验证的 2.0.17 probing 接口;新版本需按其 API 调整,不能把报错/空报告当通过。

    完整本轮命令、首次失败、原始报告、c17 本地来源和差分详单在执行回执目录。c17 原文件分发条款未确认,因此没有随产品分发该图;其本地差分照实保留。代码/数据/参考许可详见 SOURCES.md、NOTICE 与 examples 中独立数据许可证。

    #GitHub Actions

    CI 工作流使用普通 Ubuntu 24.04 runner,固定 MoonBit 1.0.0-rc1+3c0520448、对应 core 及 Node 24.11.0。SDK/core 官方下载地址与 SHA256 在 tools/ci-toolchain.json,Actions 引用也固定到提交;版本门禁核对实际 moonc 不低于 1.0.0-rc1。

    工作流执行全目标 check、格式检查、JS/Wasm-GC/native 测试及 release 构建,再以 python3 tools/ci-consumers.py 启动真实 CLI 验证示例、普通/检查退出码、BOM stdin、输入错误及关闭报告接收端。另运行 python3 tools/ci-sdc-diagnostics.py、python3 tools/ci-netlist-diagnostics.py 和 python3 tools/ci-constraint-context.py,验证 SDC 命令起点、Netlist 语义路径、缺失 launch 的因果见证及真实文件/API 消费。位置、路径和常数弧 SI 预期独立手工确定,原状态、计数与裕量预期来自示例直连约束;失败会使 job 失败,报告保存在 _build/ci-*.json。这不替代完整时序签核或历史外部 OpenSTA 对照。

    另有 python3 tools/ci-cell-usage.py、python3 tools/ci-references.py、python3 tools/ci-setup-comparison.py、python3 tools/ci-save-analysis.py 与 python3 tools/ci-setup-priority.py 门禁,核对面积/计数、标量引用、setup相对比较、完整文件保存、不同端点优先级及对应错误/消费者边界。执行范围与历史科学对照的边界见 CI-PLAN.md。

    tools/bootstrap-ci.py只把官方 SDK 安装到显式指定的新目录并验证归档 SHA,不覆盖已有 SDK。CI 在 runner 临时目录安装;已有本机工具链可直接运行以上常规命令。

    NetlistJsonDiagnostic

    pub suberror NetlistJsonDiagnostic {
    NetlistJsonDiagnostic(STAError, String)
    } derive(
    Debug
    )

    Original structural decode error and a semantic JSON Pointer relative to the standalone Netlist root. Empty string is root; array indices are 0-based. Missing fields point to the intended child; non-object values to themselves. This is not a source character span. Unknown fields remain ignored.

    NetlistJsonDiagnostic::to_repr

    automatically derived

    STAError

    pub suberror STAError {
    InvalidInput(String)
    Unsupported(String)
    UnresolvedNet(String)
    MultipleDrivers(String)
    CombinationalLoopDetected(Array[String])
    MissingTimingArc(String, String, String)
    LibraryFailure(String)
    } derive(
    Debug
    )

    STAError::to_repr

    automatically derived

    SdcDiagnostic

    pub suberror SdcDiagnostic {
    SdcDiagnostic(STAError, SdcSourcePosition?)
    } derive(
    Debug
    )

    The original typed parser error and an optional command-start position. Text-budget, library-precondition and missing-clock errors have no position.

    SdcDiagnostic::to_repr

    automatically derived

    CellAreaState

    pub(all) enum CellAreaState {
    KnownArea
    MissingArea
    InvalidArea
    UnmappedCell
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    CellAreaState::equal

    automatically derived

    CellAreaState::not_equal

    fn CellAreaState::not_equal(x : CellAreaState, y : CellAreaState) -> Bool
    automatically derived

    CellAreaState::to_json

    automatically derived

    CellAreaState::to_repr

    automatically derived

    CellUsage

    pub(all) struct CellUsage {
    cell : String
    instance_count : Int
    area_state : CellAreaState
    declared_area : Double?
    raw_area : String?
    issue : String?
    area_overflow : Bool
    total_declared_area : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    One used cell, in first-use order. No missing area is replaced with zero.

    CellUsage::to_json

    automatically derived

    CellUsage::to_repr

    automatically derived

    CellUsageReport

    pub(all) struct CellUsageReport {
    status : CellUsageStatus
    unit : String
    library : String
    instance_count : Int
    mapped_instances : Int
    unmapped_instances : Int
    known_area_instances : Int
    missing_area_instances : Int
    invalid_area_instances : Int
    area_overflow : Bool
    known_area_subtotal : Double?
    total_declared_area : Double?
    cells : Array[CellUsage]
    instances : Array[InstanceUsage]
    } derive(
    Debug
    ,
    ToJson
    )

    Flat mapped-instance census, independent of timing/SDC. Area stays in raw Liberty declared units; Complete describes area coverage, not graph/signoff.

    CellUsageReport::to_json

    automatically derived

    CellUsageReport::to_repr

    automatically derived

    CellUsageStatus

    pub(all) enum CellUsageStatus {
    UsageComplete
    UsageIncomplete
    } derive(Eq,
    Debug
    )

    CellUsageStatus::equal

    automatically derived

    CellUsageStatus::not_equal

    fn CellUsageStatus::not_equal(x : CellUsageStatus, y : CellUsageStatus) -> Bool
    automatically derived

    CellUsageStatus::to_json

    CellUsageStatus::to_repr

    automatically derived

    Clock

    pub(all) struct Clock {
    name : String
    port : String
    period_seconds : Double
    rise_slew_seconds : Double
    fall_slew_seconds : Double
    latency_seconds : Double
    uncertainty_seconds : Double
    } derive(
    Debug
    ,
    ToJson
    )

    Clock::to_json

    automatically derived

    Clock::to_repr

    automatically derived

    Connection

    pub(all) struct Connection {
    pin : String
    net : String
    } derive(
    Debug
    ,
    ToJson
    )

    Connection::to_json

    automatically derived

    Connection::to_repr

    automatically derived

    ConstraintContextAnalysis

    pub(all) struct ConstraintContextAnalysis {
    timing : STAResult
    constraint_context : Array[EndpointConstraintContext]
    } derive(
    Debug
    ,
    ToJson
    )

    ConstraintContextAnalysis::to_json

    automatically derived

    ConstraintContextAnalysis::to_repr

    automatically derived

    ConstraintWitnessStep

    pub(all) struct ConstraintWitnessStep {
    pin : String
    edge : Edge
    arc : String
    delay_seconds : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    A causal step, not a timed arrival. Source has no delay; net delay is zero in the current model; timing arcs retain their evaluated delay in seconds.

    ConstraintWitnessStep::to_json

    automatically derived

    ConstraintWitnessStep::to_repr

    automatically derived

    Direction

    pub(all) enum Direction {
    Input
    Output
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Direction::equal

    fn Direction::equal(Direction, Direction) -> Bool
    automatically derived

    Direction::not_equal

    fn Direction::not_equal(x : Direction, y : Direction) -> Bool
    automatically derived

    Direction::to_json

    automatically derived

    Direction::to_repr

    automatically derived

    Edge

    Edge::equal

    fn Edge::equal(Edge, Edge) -> Bool
    automatically derived

    Edge::not_equal

    fn Edge::not_equal(x : Edge, y : Edge) -> Bool
    automatically derived

    Edge::to_json

    automatically derived

    Edge::to_repr

    automatically derived

    EndpointConstraintContext

    pub(all) struct EndpointConstraintContext {
    pin : String
    edge : Edge
    missing_output_delay_port : String?
    launch_witness : MissingLaunchWitness?
    } derive(
    Debug
    ,
    ToJson
    )

    Context for an existing endpoint edge with unknown slack. This supplies at most one launch witness, not an enumeration or certificate of path coverage.

    EndpointConstraintContext::to_json

    automatically derived

    EndpointConstraintContext::to_repr

    automatically derived

    EndpointPeriodBound

    pub(all) struct EndpointPeriodBound {
    pin : String
    edge : Edge
    bound_seconds : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    EndpointPeriodBound::to_json

    automatically derived

    EndpointPeriodBound::to_repr

    automatically derived

    EndpointTiming

    pub(all) struct EndpointTiming {
    pin : String
    edge : Edge
    arrival_seconds : Double?
    required_seconds : Double?
    slack_seconds : Double?
    setup_seconds : Double?
    path : Array[PathStep]
    } derive(
    Debug
    ,
    ToJson
    )

    EndpointTiming::to_json

    automatically derived

    EndpointTiming::to_repr

    automatically derived

    GateInstance

    pub(all) struct GateInstance {
    name : String
    cell : String
    connections : Array[Connection]
    } derive(
    Debug
    ,
    ToJson
    )

    GateInstance::to_json

    automatically derived

    GateInstance::to_repr

    automatically derived

    InstanceUsage

    pub(all) struct InstanceUsage {
    index : Int
    instance : String
    cell : String
    area_state : CellAreaState
    declared_area : Double?
    raw_area : String?
    issue : String?
    } derive(
    Debug
    ,
    ToJson
    )

    One declared instance, in input order. Names are raw, without pin escaping.

    InstanceUsage::to_json

    automatically derived

    InstanceUsage::to_repr

    automatically derived

    MissingLaunchKind

    pub(all) enum MissingLaunchKind {
    MissingInputDelay
    IdealClockNoDataArrival
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    MissingLaunchKind::equal

    automatically derived

    MissingLaunchKind::not_equal

    fn MissingLaunchKind::not_equal(x : MissingLaunchKind, y : MissingLaunchKind) -> Bool
    automatically derived

    MissingLaunchKind::to_json

    automatically derived

    MissingLaunchKind::to_repr

    automatically derived

    MissingLaunchWitness

    pub(all) struct MissingLaunchWitness {
    kind : MissingLaunchKind
    port : String
    pin : String
    edge : Edge
    path : Array[ConstraintWitnessStep]
    } derive(
    Debug
    ,
    ToJson
    )

    One missing launch that reaches the endpoint through accepted timing arcs. port is the raw constraint target; pin uses the existing report identity.

    MissingLaunchWitness::to_json

    automatically derived

    MissingLaunchWitness::to_repr

    automatically derived

    Net

    pub(all) struct Net {
    name : String
    wire_cap_farads : Double
    } derive(
    Debug
    ,
    ToJson
    )

    Net::to_json

    automatically derived

    Net::to_repr

    automatically derived

    Netlist

    pub(all) struct Netlist {
    ports : Array[Port]
    gates : Array[GateInstance]
    nets : Array[Net]
    } derive(
    Debug
    ,
    ToJson
    )

    Netlist::to_json

    automatically derived

    Netlist::to_repr

    automatically derived

    NetlistReferenceIssue

    pub(all) struct NetlistReferenceIssue {
    code : ReferenceIssueCode
    pointer : String
    name : String
    first_pointer : String?
    } derive(
    Debug
    ,
    ToJson
    )

    A semantic JSON Pointer plus raw offending/expected name. For a duplicate, first_pointer identifies the first declaration; missing pin points at the gate's connections array. This is not a source-character position.

    NetlistReferenceIssue::to_json

    automatically derived

    NetlistReferenceIssue::to_repr

    automatically derived

    NetlistReferenceReport

    pub(all) struct NetlistReferenceReport {
    status : ReferenceCheckStatus
    scope : String
    library : String
    port_count : Int
    instance_count : Int
    net_count : Int
    connection_count : Int
    matched_instances : Int
    matched_pin_connections : Int
    issue_count : Int
    issues : Array[NetlistReferenceIssue]
    } derive(
    Debug
    ,
    ToJson
    )

    Only the named scalar-reference profile: no drivers, cycles, pin direction, numeric ranges, hierarchy, sequential/timing readiness or graph signoff. matched_pin_connections counts records matching a library pin, including duplicates and connections whose net target is unresolved.

    NetlistReferenceReport::to_json

    automatically derived

    NetlistReferenceReport::to_repr

    automatically derived

    NodeTiming

    pub(all) struct NodeTiming {
    pin : String
    edge : Edge
    arrival_seconds : Double?
    slew_seconds : Double
    load_farads : Double
    path : Array[PathStep]
    slew_contributor : String
    } derive(
    Debug
    ,
    ToJson
    )

    NodeTiming::to_json

    automatically derived

    NodeTiming::to_repr

    automatically derived

    PathCapture

    pub(all) enum PathCapture {
    OutputPort(String, Edge)
    RegisterD(String, String, Edge)
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Exact raw names. RegisterD must identify a supported ff's real D pin.

    PathCapture::equal

    fn PathCapture::equal(PathCapture, PathCapture) -> Bool
    automatically derived

    PathCapture::not_equal

    fn PathCapture::not_equal(x : PathCapture, y : PathCapture) -> Bool
    automatically derived

    PathCapture::to_json

    automatically derived

    PathCapture::to_repr

    automatically derived

    PathLaunch

    pub(all) enum PathLaunch {
    InputPort(String, Edge)
    RegisterQ(String, String, Edge)
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Exact raw names. RegisterQ must identify a supported ff's real Q pin.

    PathLaunch::equal

    fn PathLaunch::equal(PathLaunch, PathLaunch) -> Bool
    automatically derived

    PathLaunch::not_equal

    fn PathLaunch::not_equal(x : PathLaunch, y : PathLaunch) -> Bool
    automatically derived

    PathLaunch::to_json

    automatically derived

    PathLaunch::to_repr

    automatically derived

    PathQueriesAnalysis

    pub(all) struct PathQueriesAnalysis {
    timing : STAResult
    path_queries : Array[QueriedPath]
    } derive(
    Debug
    ,
    ToJson
    )

    Several exact path queries over one full-design timing analysis. Results retain input order and each returned path is independently owned.

    PathQueriesAnalysis::to_json

    automatically derived

    PathQueriesAnalysis::to_repr

    automatically derived

    PathQuery

    pub(all) struct PathQuery {
    launch : PathLaunch
    capture : PathCapture
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    PathQuery::equal

    fn PathQuery::equal(PathQuery, PathQuery) -> Bool
    automatically derived

    PathQuery::not_equal

    fn PathQuery::not_equal(x : PathQuery, y : PathQuery) -> Bool
    automatically derived

    PathQuery::to_json

    automatically derived

    PathQuery::to_repr

    automatically derived

    PathQueryAnalysis

    pub(all) struct PathQueryAnalysis {
    timing : STAResult
    path_query : QueriedPath
    } derive(
    Debug
    ,
    ToJson
    )

    PathQueryAnalysis::to_json

    automatically derived

    PathQueryAnalysis::to_repr

    automatically derived

    PathQueryStatus

    pub(all) enum PathQueryStatus {
    Found
    NoPath
    UnconstrainedLaunch
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    PathQueryStatus::equal

    automatically derived

    PathQueryStatus::not_equal

    fn PathQueryStatus::not_equal(x : PathQueryStatus, y : PathQueryStatus) -> Bool
    automatically derived

    PathQueryStatus::to_json

    automatically derived

    PathQueryStatus::to_repr

    automatically derived

    PathStep

    pub(all) struct PathStep {
    pin : String
    edge : Edge
    delay_seconds : Double
    arrival_seconds : Double
    arc : String
    } derive(
    Debug
    ,
    ToJson
    )

    PathStep::to_json

    automatically derived

    PathStep::to_repr

    automatically derived

    PeriodAnalysis

    pub(all) struct PeriodAnalysis {
    timing : STAResult
    budget : PeriodBudget
    } derive(
    Debug
    ,
    ToJson
    )

    PeriodAnalysis::to_json

    automatically derived

    PeriodAnalysis::to_repr

    automatically derived

    PeriodBudget

    pub(all) struct PeriodBudget {
    status : PeriodBudgetStatus
    constrained_endpoint_edges : Int
    unconstrained_endpoint_edges : Int
    endpoint_bounds : Array[EndpointPeriodBound]
    minimum_period_seconds : Double?
    maximum_frequency_hz : Double?
    limiting_endpoints : Array[EndpointPeriodBound]
    } derive(
    Debug
    ,
    ToJson
    )

    PeriodBudget::to_json

    automatically derived

    PeriodBudget::to_repr

    automatically derived

    PeriodBudgetStatus

    pub(all) enum PeriodBudgetStatus {
    Complete
    Partial
    Unconstrained
    NoPositiveLimit
    FrequencyOverflow
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    PeriodBudgetStatus::equal

    automatically derived

    PeriodBudgetStatus::not_equal

    automatically derived

    PeriodBudgetStatus::to_json

    automatically derived

    PeriodBudgetStatus::to_repr

    automatically derived

    PinLimitAnalysis

    pub(all) struct PinLimitAnalysis {
    timing : STAResult
    pin_limits : PinLimitReport
    } derive(
    Debug
    ,
    ToJson
    )

    PinLimitAnalysis::to_json

    automatically derived

    PinLimitAnalysis::to_repr

    automatically derived

    PinLimitCheck

    pub(all) struct PinLimitCheck {
    instance : String
    cell : String
    library_pin : String
    pin : String
    edge : Edge
    kind : PinLimitKind
    unit : String
    actual_si : Double
    status : PinLimitState
    source : PinLimitSource?
    source_attribute : String?
    raw_limit : String?
    limit_si : Double?
    margin_si : Double?
    issue : String?
    } derive(
    Debug
    ,
    ToJson
    )

    One rule/pin/edge. SI units are seconds or farads as named by unit. Invalid/missing bounds never become zero; actuals retain original GBA values.

    PinLimitCheck::to_json

    automatically derived

    PinLimitCheck::to_repr

    automatically derived

    PinLimitKind

    pub(all) enum PinLimitKind {
    MaxCapacitance
    MaxTransition
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    PinLimitKind::equal

    automatically derived

    PinLimitKind::not_equal

    fn PinLimitKind::not_equal(x : PinLimitKind, y : PinLimitKind) -> Bool
    automatically derived

    PinLimitKind::to_json

    automatically derived

    PinLimitKind::to_repr

    automatically derived

    PinLimitReport

    pub(all) struct PinLimitReport {
    status : PinLimitReportStatus
    checked_rules : Int
    violated_rules : Int
    unspecified_rules : Int
    invalid_rules : Int
    checks : Array[PinLimitCheck]
    } derive(
    Debug
    ,
    ToJson
    )

    Counts are rule/pin/edge records, not unique pins. Met describes applicable declared supported bounds; unspecified pins are not a coverage certificate.

    PinLimitReport::to_json

    automatically derived

    PinLimitReport::to_repr

    automatically derived

    PinLimitReportStatus

    pub(all) enum PinLimitReportStatus {
    LimitsMet
    LimitsViolated
    InvalidLimits
    NoDeclaredLimits
    } derive(Eq,
    Debug
    )

    PinLimitReportStatus::equal

    automatically derived

    PinLimitReportStatus::not_equal

    automatically derived

    PinLimitReportStatus::to_json

    Unique typed constructors preserve existing unqualified SetupSummary names.

    PinLimitReportStatus::to_repr

    automatically derived

    PinLimitSource

    pub(all) enum PinLimitSource {
    PinAttribute
    LibraryDefault
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    PinLimitSource::equal

    automatically derived

    PinLimitSource::not_equal

    fn PinLimitSource::not_equal(x : PinLimitSource, y : PinLimitSource) -> Bool
    automatically derived

    PinLimitSource::to_json

    automatically derived

    PinLimitSource::to_repr

    automatically derived

    PinLimitState

    pub(all) enum PinLimitState {
    Satisfied
    Exceeded
    NotSpecified
    InvalidLimit
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    PinLimitState::equal

    automatically derived

    PinLimitState::not_equal

    fn PinLimitState::not_equal(x : PinLimitState, y : PinLimitState) -> Bool
    automatically derived

    PinLimitState::to_json

    automatically derived

    PinLimitState::to_repr

    automatically derived

    Port

    pub(all) struct Port {
    name : String
    net : String
    direction : Direction
    } derive(
    Debug
    ,
    ToJson
    )

    Port::to_json

    automatically derived

    Port::to_repr

    automatically derived

    PortValue

    pub(all) struct PortValue {
    port : String
    rise : Double?
    fall : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    PortValue::to_json

    automatically derived

    PortValue::to_repr

    automatically derived

    QueriedPath

    pub(all) struct QueriedPath {
    status : PathQueryStatus
    launch_pin : String
    launch_edge : Edge
    capture_pin : String
    capture_edge : Edge
    queried_arrival_seconds : Double?
    required_seconds : Double?
    queried_slack_seconds : Double?
    path : Array[PathStep]
    } derive(
    Debug
    ,
    ToJson
    )

    Selected-source GBA path, not isolated-path slew analysis or global WNS. Non-Found results have an empty owned path and no numerical query values.

    QueriedPath::to_json

    automatically derived

    QueriedPath::to_repr

    automatically derived

    ReferenceCheckStatus

    pub(all) enum ReferenceCheckStatus {
    ReferencesResolved
    ReferenceIssuesFound
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    ReferenceCheckStatus::equal

    automatically derived

    ReferenceCheckStatus::not_equal

    automatically derived

    ReferenceCheckStatus::to_json

    automatically derived

    ReferenceCheckStatus::to_repr

    automatically derived

    ReferenceIssueCode

    pub(all) enum ReferenceIssueCode {
    RefEmptyNetName
    RefDuplicateNetName
    RefEmptyPortName
    RefDuplicatePortName
    RefEmptyInstanceName
    RefDuplicateInstanceName
    RefUnknownCell
    RefDuplicateConnectionPin
    RefUnknownPin
    RefMissingPin
    RefUnresolvedNet
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    ReferenceIssueCode::equal

    automatically derived

    ReferenceIssueCode::not_equal

    automatically derived

    ReferenceIssueCode::to_json

    automatically derived

    ReferenceIssueCode::to_repr

    automatically derived

    STAEngine

    STAEngine::run_period_analysis

    fn STAEngine::run_period_analysis(self : STAEngine) -> PeriodAnalysis raise STAError

    Analyze timing and the period bound while all non-period constraints stay fixed. A global frequency is reported only when every endpoint edge is constrained.

    STAEngine::run_pin_limit_analysis

    fn STAEngine::run_pin_limit_analysis(self : STAEngine) -> PinLimitAnalysis raise STAError

    Run original setup once, then compare its full-design pin slew/output load with supported declared Liberty bounds. Original setup errors are unchanged.

    STAEngine::run_setup_analysis

    fn STAEngine::run_setup_analysis(self : STAEngine) -> STAResult raise STAError

    STAEngine::run_setup_path_queries

    fn STAEngine::run_setup_path_queries(self : STAEngine, queries : Array[PathQuery]) -> PathQueriesAnalysis raise STAError

    Evaluate up to 1024 exact launch/capture queries against one setup pass. The same path model and per-query validation order as the single-query API apply. A bad query fails the entire batch at its first input index.

    STAEngine::run_setup_path_query

    fn STAEngine::run_setup_path_query(self : STAEngine, query : PathQuery) -> PathQueryAnalysis raise STAError

    One exact launch/capture-edge query under the original full-design GBA slew and load. Original setup errors precede point validation; launch precedes capture validation, then NoPath precedes UnconstrainedLaunch. No D-to-Q edge.

    STAEngine::run_setup_with_constraint_context

    fn STAEngine::run_setup_with_constraint_context(self : STAEngine) -> ConstraintContextAnalysis raise STAError

    Run setup once, adding causal context only for the report's unknown-slack endpoint edges. Known alternate arrivals retain the original coverage rule. The first accepted missing launch is a witness, not an exhaustive path check.

    STAResult

    pub(all) struct STAResult {
    nodes : Array[NodeTiming]
    endpoints : Array[EndpointTiming]
    worst_slack_seconds : Double?
    diagnostics : Array[String]
    topological_order : Array[String]
    } derive(
    Debug
    ,
    ToJson
    )

    STAResult::prioritize_setup_endpoints

    fn STAResult::prioritize_setup_endpoints(self : STAResult, max_endpoints? : Int) -> SetupEndpointPriorities raise STAError

    Select distinct exact pins by their worst known slack; ties retain first source pin/edge order. Unknown coverage remains explicit and is never zero. This reads only endpoint pin/edge/slack; the caller retains original paths.

    STAResult::setup_summary

    fn STAResult::setup_summary(self : STAResult) -> SetupSummary raise STAError

    Summarize the endpoint slacks already in this report, without rerunning STA. Violated includes known violations in a report that also has unknown edges. Publicly constructed reports must have nonempty, unique pin/edge identities.

    STAResult::to_json

    automatically derived

    STAResult::to_repr

    automatically derived

    SdcSourcePosition

    pub(all) struct SdcSourcePosition {
    line : Int
    column : Int
    offset : Int
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Start of a failing restricted-SDC command, not the exact bad token. Line/column are 1-based; column/offset count UTF-16 code units. Offset is 0-based in the original String. LF starts a new line, CRLF contributes two offset units, and a tab contributes one column unit.

    SdcSourcePosition::equal

    automatically derived

    SdcSourcePosition::not_equal

    fn SdcSourcePosition::not_equal(x : SdcSourcePosition, y : SdcSourcePosition) -> Bool
    automatically derived

    SdcSourcePosition::to_json

    automatically derived

    SdcSourcePosition::to_repr

    automatically derived

    SetupChangeStatus

    pub(all) enum SetupChangeStatus {
    SetupDeltaRegressed
    SetupDeltaImproved
    SetupDeltaUnchanged
    SetupDeltaTolerated
    SetupDeltaBaselineOnly
    SetupDeltaCandidateOnly
    SetupDeltaBaselineUnknown
    SetupDeltaCandidateUnknown
    SetupDeltaBothUnknown
    SetupDeltaOverflow
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    SetupChangeStatus::equal

    automatically derived

    SetupChangeStatus::not_equal

    fn SetupChangeStatus::not_equal(x : SetupChangeStatus, y : SetupChangeStatus) -> Bool
    automatically derived

    SetupChangeStatus::to_json

    automatically derived

    SetupChangeStatus::to_repr

    automatically derived

    SetupComparison

    pub(all) struct SetupComparison {
    status : SetupComparisonStatus
    unit : String
    max_slack_loss_seconds : Double
    baseline_endpoint_edges : Int
    candidate_endpoint_edges : Int
    matched_endpoint_edges : Int
    compared_endpoint_edges : Int
    regressed_endpoint_edges : Int
    incomplete_endpoint_edges : Int
    rows : Array[SetupSlackChange]
    } derive(
    Debug
    ,
    ToJson
    )

    Relative setup-slack preservation only, not absolute setup compliance or proof of matching model/constraints. Rows follow baseline then added order.

    SetupComparison::to_json

    automatically derived

    SetupComparison::to_repr

    automatically derived

    SetupComparisonStatus

    pub(all) enum SetupComparisonStatus {
    NoSetupRegression
    SetupRegressed
    SetupComparisonIncomplete
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    SetupComparisonStatus::equal

    automatically derived

    SetupComparisonStatus::not_equal

    automatically derived

    SetupComparisonStatus::to_json

    automatically derived

    SetupComparisonStatus::to_repr

    automatically derived

    SetupEndpointPriorities

    pub(all) struct SetupEndpointPriorities {
    unit : String
    max_endpoints : Int
    endpoint_count : Int
    endpoint_edges : Int
    known_endpoint_edges : Int
    unknown_endpoint_edges : Int
    rankable_endpoints : Int
    unrankable_endpoints : Int
    selected_endpoints : Int
    omitted_rankable_endpoints : Int
    rows : Array[SetupEndpointPriority]
    unranked_endpoints : Array[SetupEndpointPriority]
    } derive(
    Debug
    ,
    ToJson
    )

    A bounded priority query, not a setup pass or an enumeration of timing paths. All-unknown pins remain visible even when the known selection limit is zero.

    SetupEndpointPriorities::to_json

    automatically derived

    SetupEndpointPriorities::to_repr

    automatically derived

    SetupEndpointPriority

    pub(all) struct SetupEndpointPriority {
    pin : String
    first_source_index : Int
    endpoint_edges : Int
    known_edges : Int
    unknown_edges : Int
    worst_source_index : Int?
    worst_edge : Edge?
    worst_slack_seconds : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    One exact pin, with its worst known source edge and explicit unknown edges. Source indices refer to the unchanged original STAResult.endpoints array.

    SetupEndpointPriority::to_json

    automatically derived

    SetupEndpointPriority::to_repr

    automatically derived

    SetupSlackChange

    pub(all) struct SetupSlackChange {
    pin : String
    edge : Edge
    status : SetupChangeStatus
    baseline_slack_seconds : Double?
    candidate_slack_seconds : Double?
    slack_delta_seconds : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    Exact existing report pin/edge identity. Unknown/nonrepresentable values are omitted rather than invented as zero. Delta is candidate minus baseline.

    SetupSlackChange::to_json

    automatically derived

    SetupSlackChange::to_repr

    automatically derived

    SetupSummary

    pub(all) struct SetupSummary {
    status : SetupSummaryStatus
    endpoint_count : Int
    constrained_endpoint_edges : Int
    unconstrained_endpoint_edges : Int
    violating_endpoint_edges : Int
    violating_endpoints : Int
    worst_slack_seconds : Double?
    worst_negative_slack_seconds : Double?
    } derive(
    Debug
    ,
    ToJson
    )

    SetupSummary::to_json

    automatically derived

    SetupSummary::to_repr

    automatically derived

    SetupSummaryStatus

    pub(all) enum SetupSummaryStatus {
    Met
    Violated
    PartialCoverage
    NoCoverage
    NoEndpoints
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    SetupSummaryStatus::equal

    automatically derived

    SetupSummaryStatus::not_equal

    automatically derived

    SetupSummaryStatus::to_json

    automatically derived

    SetupSummaryStatus::to_repr

    automatically derived

    TimingConstraints

    pub(all) struct TimingConstraints {
    clock : Clock
    input_delays : Array[PortValue]
    output_delays : Array[PortValue]
    input_slews : Array[PortValue]
    output_loads : Array[PortValue]
    } derive(
    Debug
    ,
    ToJson
    )

    TimingConstraints::to_json

    automatically derived

    TimingConstraints::to_repr

    automatically derived

    analyze_cell_usage

    fn analyze_cell_usage(library :
    Library
    , netlist : Netlist) -> CellUsageReport raise STAError

    Count every flat gate, even disconnected/unused outputs. Only instance identity is checked here; connections, pins and timing models are not checked. Returned arrays are owned and do not borrow/mutate the library or netlist.

    analyze_cell_usage_json

    fn analyze_cell_usage_json(liberty_text : String, netlist_text : String) -> String

    Existing Liberty and Netlist JSON texts, with no SDC or timing requirement.

    analyze_constraint_context_json

    fn analyze_constraint_context_json(liberty_text : String, netlist_text : String, sdc_text : String) -> String

    Three-text context boundary using the default Extrapolate setup policy. It explains existing unknown endpoint edges; it does not run period analysis or turn successful analysis into a constraint-completeness certificate.

    analyze_json

    fn analyze_json(liberty_text : String, request_text : String) -> String

    Host-friendly JSON boundary. The request contains netlist, sdc, and optional range_policy (extrapolate/reject/clamp). Times in the result are seconds.

    analyze_path_queries_json

    fn analyze_path_queries_json(liberty_text : String, netlist_text : String, sdc_text : String, queries_text : String) -> String

    A JSON object with a queries array and optional range_policy. Each array item has the same from/to shape as the single-query JSON entry point.

    analyze_path_query_json

    fn analyze_path_query_json(liberty_text : String, netlist_text : String, sdc_text : String, query_text : String) -> String

    Four decoded texts. Old analysis schemas and flags are unchanged.

    analyze_pin_limits_json

    fn analyze_pin_limits_json(liberty_text : String, netlist_text : String, sdc_text : String, range_policy : String) -> String

    Existing three input texts and an explicit existing NLDM policy token.

    check_netlist_json

    fn check_netlist_json(text : String) -> String

    Standalone structural JSON-file boundary, separate from analysis and SDC. Syntax errors have null pointer; a decoded wrong root has empty-string root.

    check_netlist_references

    fn check_netlist_references(library :
    Library
    , netlist : Netlist) -> NetlistReferenceReport

    Return all independent scalar name/reference findings without timing/SDC. Uses original first-match Library.cell/Cell.pin resolution, checks every directly modeled library pin, and returns an owned issue list. Unknown cells suppress unknowable pin/missing-pin findings; other checks still proceed.

    check_netlist_references_json

    fn check_netlist_references_json(liberty_text : String, netlist_text : String) -> String

    Existing structural diagnostic decoder followed by standalone reference checks. Findings are ok:true reports; parsing/IO is a different boundary.

    check_sdc_json

    fn check_sdc_json(liberty_text : String, netlist_text : String, sdc_text : String) -> String

    Check a standalone netlist JSON object and verbatim restricted SDC text. This parses/binds constraints; it does not run STA or validate the full graph. The separate schema leaves analyze_json's error/output contract unchanged.

    compare_setup_json

    fn compare_setup_json(baseline_text : String, candidate_text : String, max_slack_loss_seconds : Double) -> String

    Original successful moonbit.sta.v1 reports and an explicit SI loss budget.

    compare_setup_results

    fn compare_setup_results(baseline : STAResult, candidate : STAResult, max_slack_loss_seconds? : Double) -> SetupComparison raise STAError

    Compare existing endpoint slacks without rerunning either analysis. Exact pin/edge identities must be nonempty/unique and known slacks finite. A loss equal to the nonnegative SI threshold is allowed. Any unmatched/unknown or overflowing row prevents a passing certificate; a known regression wins.

    netlist_from_json

    fn netlist_from_json(j :
    Json
    ) -> Netlist raise STAError

    netlist_from_json_with_diagnostics

    fn netlist_from_json_with_diagnostics(value :
    Json
    ) -> Netlist raise NetlistJsonDiagnostic

    Decode exactly the same structure and values as netlist_from_json, with the first error's semantic pointer. Field read order is preserved: ports before gates before nets; direction before port name/net; gate connections (pin before net) before name/cell; net capacitance before name. Arrays ascend. Does not validate a complete timing graph or change numeric acceptance.

    netlist_from_yosys_json

    fn netlist_from_yosys_json(value :
    Json
    , module_name : String) -> Netlist raise STAError

    Import one flat, mapped, scalar module from Yosys write_json output. A repeated integer bit ID always names the same zero-wire-capacitance net. Top-level port and cell/pin names are preserved for Liberty and SDC binding. The caller can run check_netlist_references before timing analysis.

    parse_sdc

    fn parse_sdc(text : String, library :
    Library
    , netlist : Netlist) -> TimingConstraints raise STAError

    Parse the documented single-clock SDC data profile. This does not evaluate Tcl. Numeric command units are taken from the supplied Liberty library.

    parse_sdc_with_diagnostics

    fn parse_sdc_with_diagnostics(text : String, library :
    Library
    , netlist : Netlist) -> TimingConstraints raise SdcDiagnostic

    Parse the same profile as parse_sdc, retaining the original error inside a source diagnostic. Source is not normalized, including Unicode and CRLF.

    prioritize_setup_json

    fn prioritize_setup_json(report_text : String, max_endpoints : Double) -> String

    Consume the original success-report endpoint view, without running timing. A Double limit lets the JS boundary reject fractional/nonfinite values before conversion to MoonBit Int; the typed API accepts a nonnegative Int directly.