@celox-sim/celox 0.0.1 → 0.1.3

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.
@@ -0,0 +1,207 @@
1
+ /**
2
+ * NAPI helper utilities for the @celox-sim/celox TypeScript runtime.
3
+ *
4
+ * Provides reusable functions for:
5
+ * - Loading the native addon
6
+ * - Parsing NAPI layout JSON into SignalLayout
7
+ * - Building PortInfo from NAPI layout (auto-detect ports)
8
+ * - Wrapping NAPI handles with zero-copy direct operations
9
+ * - Creating bridge functions for Simulator.create() / Simulation.create()
10
+ */
11
+ // ---------------------------------------------------------------------------
12
+ // Native addon loading
13
+ // ---------------------------------------------------------------------------
14
+ import { createRequire } from "node:module";
15
+ /**
16
+ * Load the native NAPI addon.
17
+ *
18
+ * Resolution: `@celox-sim/celox-napi` package (works both in workspace dev
19
+ * and when installed from npm — napi-rs generated index.js handles platform
20
+ * detection). An explicit path can override this.
21
+ *
22
+ * @param addonPath Explicit path to the `.node` file (overrides auto-detection).
23
+ */
24
+ export function loadNativeAddon(addonPath) {
25
+ const require = createRequire(import.meta.url);
26
+ if (addonPath) {
27
+ return require(addonPath);
28
+ }
29
+ try {
30
+ return require("@celox-sim/celox-napi");
31
+ }
32
+ catch (e) {
33
+ throw new Error(`Failed to load NAPI addon from @celox-sim/celox-napi. ` +
34
+ `Build it with: pnpm run build:napi`, { cause: e });
35
+ }
36
+ }
37
+ /**
38
+ * Parse the NAPI layout JSON into SignalLayout records.
39
+ * Returns both the full layout (with type_kind for port detection) and
40
+ * the DUT-compatible layout (without type_kind).
41
+ */
42
+ export function parseNapiLayout(json) {
43
+ const raw = JSON.parse(json);
44
+ const signals = {};
45
+ const forDut = {};
46
+ for (const [name, r] of Object.entries(raw)) {
47
+ const sl = {
48
+ offset: r.offset,
49
+ width: r.width,
50
+ byteSize: r.byte_size > 0 ? r.byte_size : Math.ceil(r.width / 8),
51
+ is4state: r.is_4state,
52
+ direction: r.direction,
53
+ };
54
+ const entry = {
55
+ ...sl,
56
+ typeKind: r.type_kind,
57
+ };
58
+ if (r.array_dims && r.array_dims.length > 0) {
59
+ entry.arrayDims = r.array_dims;
60
+ }
61
+ signals[name] = entry;
62
+ forDut[name] = sl;
63
+ }
64
+ return { signals, forDut };
65
+ }
66
+ /**
67
+ * Build PortInfo records from the NAPI layout signals.
68
+ * This auto-detects port metadata so users don't need to hand-write ModuleDefinition.
69
+ */
70
+ export function buildPortsFromLayout(signals, _events) {
71
+ const ports = {};
72
+ for (const [name, sig] of Object.entries(signals)) {
73
+ const typeKind = sig.typeKind;
74
+ let portType;
75
+ switch (typeKind) {
76
+ case "clock":
77
+ portType = "clock";
78
+ break;
79
+ case "reset":
80
+ portType = "reset";
81
+ break;
82
+ case "bit":
83
+ portType = "bit";
84
+ break;
85
+ default:
86
+ portType = "logic";
87
+ break;
88
+ }
89
+ const port = {
90
+ direction: sig.direction,
91
+ type: portType,
92
+ width: sig.width,
93
+ is4state: sig.is4state,
94
+ };
95
+ if (sig.arrayDims && sig.arrayDims.length > 0) {
96
+ port.arrayDims = sig.arrayDims;
97
+ }
98
+ ports[name] = port;
99
+ }
100
+ return ports;
101
+ }
102
+ // ---------------------------------------------------------------------------
103
+ // Handle wrapping — zero-copy direct operations
104
+ // ---------------------------------------------------------------------------
105
+ /**
106
+ * Wrap a raw NAPI simulator handle with direct (zero-copy) operations.
107
+ * The buffer is shared between JS and Rust — no copies per tick.
108
+ */
109
+ export function wrapDirectSimulatorHandle(raw) {
110
+ return {
111
+ tick(eventId) {
112
+ raw.tick(eventId);
113
+ },
114
+ tickN(eventId, count) {
115
+ raw.tickN(eventId, count);
116
+ },
117
+ evalComb() {
118
+ raw.evalComb();
119
+ },
120
+ dump(timestamp) {
121
+ raw.dump(timestamp);
122
+ },
123
+ dispose() {
124
+ raw.dispose();
125
+ },
126
+ };
127
+ }
128
+ /**
129
+ * Wrap a raw NAPI simulation handle with direct (zero-copy) operations.
130
+ */
131
+ export function wrapDirectSimulationHandle(raw) {
132
+ return {
133
+ addClock(eventId, period, initialDelay) {
134
+ raw.addClock(eventId, period, initialDelay);
135
+ },
136
+ schedule(eventId, time, value) {
137
+ raw.schedule(eventId, time, value);
138
+ },
139
+ runUntil(endTime) {
140
+ raw.runUntil(endTime);
141
+ },
142
+ step() {
143
+ return raw.step();
144
+ },
145
+ time() {
146
+ return raw.time();
147
+ },
148
+ evalComb() {
149
+ raw.evalComb();
150
+ },
151
+ dump(timestamp) {
152
+ raw.dump(timestamp);
153
+ },
154
+ dispose() {
155
+ raw.dispose();
156
+ },
157
+ };
158
+ }
159
+ // ---------------------------------------------------------------------------
160
+ // Legacy layout parser (used by bridge helpers)
161
+ // ---------------------------------------------------------------------------
162
+ function parseLegacyLayout(json) {
163
+ const raw = JSON.parse(json);
164
+ const result = {};
165
+ for (const [name, r] of Object.entries(raw)) {
166
+ result[name] = {
167
+ offset: r.offset,
168
+ width: r.width,
169
+ byteSize: r.byte_size > 0 ? r.byte_size : Math.ceil(r.width / 8),
170
+ is4state: r.is_4state,
171
+ direction: r.direction,
172
+ };
173
+ }
174
+ return result;
175
+ }
176
+ // ---------------------------------------------------------------------------
177
+ // Simulator bridge (used by Simulator.create())
178
+ // ---------------------------------------------------------------------------
179
+ /**
180
+ * Create a `NativeCreateFn` from a raw NAPI addon, suitable for
181
+ * `Simulator.create(module, { __nativeCreate: ... })`.
182
+ */
183
+ export function createSimulatorBridge(addon) {
184
+ return (source, moduleName, _options) => {
185
+ const raw = new addon.NativeSimulatorHandle(source, moduleName);
186
+ const layout = parseLegacyLayout(raw.layoutJson);
187
+ const events = JSON.parse(raw.eventsJson);
188
+ const buf = raw.sharedMemory().buffer;
189
+ const handle = wrapDirectSimulatorHandle(raw);
190
+ return { buffer: buf, layout, events, handle };
191
+ };
192
+ }
193
+ /**
194
+ * Create a `NativeCreateSimulationFn` from a raw NAPI addon, suitable for
195
+ * `Simulation.create(module, { __nativeCreate: ... })`.
196
+ */
197
+ export function createSimulationBridge(addon) {
198
+ return (source, moduleName, _options) => {
199
+ const raw = new addon.NativeSimulationHandle(source, moduleName);
200
+ const layout = parseLegacyLayout(raw.layoutJson);
201
+ const events = JSON.parse(raw.eventsJson);
202
+ const buf = raw.sharedMemory().buffer;
203
+ const handle = wrapDirectSimulationHandle(raw);
204
+ return { buffer: buf, layout, events, handle };
205
+ };
206
+ }
207
+ //# sourceMappingURL=napi-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"napi-helpers.js","sourceRoot":"","sources":["../src/napi-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA8DH,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,SAAkB;IAChD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE/C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,OAAO,CAAC,SAAS,CAAiB,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,uBAAuB,CAAiB,CAAC;IAC1D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,wDAAwD;YACtD,oCAAoC,EACtC,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC;IACJ,CAAC;AACH,CAAC;AAgBD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAI1C,MAAM,GAAG,GAAoC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,OAAO,GAA8E,EAAE,CAAC;IAC9F,MAAM,MAAM,GAAiC,EAAE,CAAC;IAEhD,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,EAAE,GAAiB;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0,0 +1,111 @@
1
+ /**
2
+ * Time-based Simulation.
3
+ *
4
+ * Wraps a NativeSimulationHandle and provides a high-level TypeScript API
5
+ * for clock-driven simulation with automatic scheduling.
6
+ */
7
+ import type { CreateResult, ModuleDefinition, NativeSimulationHandle, SimulatorOptions } from "./types.js";
8
+ /**
9
+ * Placeholder for the NAPI binding's `createSimulation()`.
10
+ * Stream B will provide the real implementation.
11
+ * @internal
12
+ */
13
+ export type NativeCreateSimulationFn = (source: string, moduleName: string, options: SimulatorOptions) => CreateResult<NativeSimulationHandle>;
14
+ /**
15
+ * Register the NAPI binding at module load time.
16
+ * @internal
17
+ */
18
+ export declare function setNativeSimulationCreate(fn: NativeCreateSimulationFn): void;
19
+ export declare class Simulation<P = Record<string, unknown>> {
20
+ private readonly _handle;
21
+ private readonly _dut;
22
+ private readonly _events;
23
+ private readonly _state;
24
+ private _disposed;
25
+ private constructor();
26
+ /**
27
+ * Create a Simulation for the given module.
28
+ *
29
+ * ```ts
30
+ * import { Top } from "./generated/Top.js";
31
+ * const sim = Simulation.create(Top);
32
+ * sim.addClock("clk", { period: 10 });
33
+ * ```
34
+ */
35
+ static create<P>(module: ModuleDefinition<P>, options?: SimulatorOptions & {
36
+ __nativeCreate?: NativeCreateSimulationFn;
37
+ }): Simulation<P>;
38
+ /**
39
+ * Create a Simulation directly from Veryl source code.
40
+ *
41
+ * Automatically discovers ports from the NAPI layout — no
42
+ * `ModuleDefinition` needed.
43
+ *
44
+ * ```ts
45
+ * const sim = Simulation.fromSource<CounterPorts>(COUNTER_SOURCE, "Counter");
46
+ * sim.addClock("clk", { period: 10 });
47
+ * sim.runUntil(100);
48
+ * ```
49
+ */
50
+ static fromSource<P = Record<string, unknown>>(source: string, top: string, options?: SimulatorOptions & {
51
+ nativeAddonPath?: string;
52
+ }): Simulation<P>;
53
+ /**
54
+ * Create a Simulation from a Veryl project directory.
55
+ *
56
+ * Searches upward from `projectPath` for `Veryl.toml`, gathers all
57
+ * `.veryl` source files, and builds the simulation using the project's
58
+ * clock/reset settings.
59
+ *
60
+ * ```ts
61
+ * const sim = Simulation.fromProject<MyPorts>("./my-project", "Top");
62
+ * sim.addClock("clk", { period: 10 });
63
+ * ```
64
+ */
65
+ static fromProject<P = Record<string, unknown>>(projectPath: string, top: string, options?: SimulatorOptions & {
66
+ nativeAddonPath?: string;
67
+ }): Simulation<P>;
68
+ /** The DUT accessor object — read/write ports as plain properties. */
69
+ get dut(): P;
70
+ /**
71
+ * Register a periodic clock.
72
+ *
73
+ * @param name Clock event name (must match a `clock` port).
74
+ * @param opts `period` in time units; optional `initialDelay`.
75
+ */
76
+ addClock(name: string, opts: {
77
+ period: number;
78
+ initialDelay?: number;
79
+ }): void;
80
+ /**
81
+ * Schedule a one-shot value change for a signal.
82
+ *
83
+ * @param name Event/signal name.
84
+ * @param opts `time` — absolute time to apply; `value` — value to set.
85
+ */
86
+ schedule(name: string, opts: {
87
+ time: number;
88
+ value: number;
89
+ }): void;
90
+ /**
91
+ * Run the simulation until the given time.
92
+ * Processes all scheduled events up to and including `endTime`.
93
+ * evalComb is called internally; dirty is cleared on return.
94
+ */
95
+ runUntil(endTime: number): void;
96
+ /**
97
+ * Advance to the next scheduled event.
98
+ *
99
+ * @returns The time of the processed event, or `null` if no events remain.
100
+ */
101
+ step(): number | null;
102
+ /** Current simulation time. */
103
+ time(): number;
104
+ /** Write current signal values to VCD at the given timestamp. */
105
+ dump(timestamp: number): void;
106
+ /** Release native resources. */
107
+ dispose(): void;
108
+ private resolveEvent;
109
+ private ensureAlive;
110
+ }
111
+ //# sourceMappingURL=simulation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulation.d.ts","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AASpB;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAA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hB,sEAAsE;IACtE,IAAI,GAAG,IAAI,CAAC,CAEX;IAED;;;;;OAKG;IACH,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9C,IAAI;IAMP;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAMnE;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM/B;;;;OAIG;IACH,IAAI,IAAI,MAAM,GAAG,IAAI;IAOrB,+BAA+B;IAC/B,IAAI,IAAI,MAAM;IAKd,iEAAiE;IACjE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAK7B,gCAAgC;IAChC,OAAO,IAAI,IAAI;IAWf,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,WAAW;CAKpB"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Time-based Simulation.
3
+ *
4
+ * Wraps a NativeSimulationHandle and provides a high-level TypeScript API
5
+ * for clock-driven simulation with automatic scheduling.
6
+ */
7
+ import { createDut } from "./dut.js";
8
+ import { loadNativeAddon, parseNapiLayout, buildPortsFromLayout, wrapDirectSimulationHandle, } from "./napi-helpers.js";
9
+ let _nativeCreate;
10
+ /**
11
+ * Register the NAPI binding at module load time.
12
+ * @internal
13
+ */
14
+ export function setNativeSimulationCreate(fn) {
15
+ _nativeCreate = fn;
16
+ }
17
+ // ---------------------------------------------------------------------------
18
+ // Simulation
19
+ // ---------------------------------------------------------------------------
20
+ export class Simulation {
21
+ _handle;
22
+ _dut;
23
+ _events;
24
+ _state;
25
+ _disposed = false;
26
+ constructor(handle, dut, events, state) {
27
+ this._handle = handle;
28
+ this._dut = dut;
29
+ this._events = events;
30
+ this._state = state;
31
+ }
32
+ /**
33
+ * Create a Simulation for the given module.
34
+ *
35
+ * ```ts
36
+ * import { Top } from "./generated/Top.js";
37
+ * const sim = Simulation.create(Top);
38
+ * sim.addClock("clk", { period: 10 });
39
+ * ```
40
+ */
41
+ static create(module, options) {
42
+ // When the module was produced by the Vite plugin, delegate to fromProject()
43
+ if (module.projectPath && !options?.__nativeCreate) {
44
+ return Simulation.fromProject(module.projectPath, module.name, options);
45
+ }
46
+ const createFn = options?.__nativeCreate ?? _nativeCreate;
47
+ if (!createFn) {
48
+ throw new Error("Native simulator binding not loaded. " +
49
+ "Ensure @celox-sim/celox-napi is installed.");
50
+ }
51
+ const { fourState, vcd } = options ?? {};
52
+ const result = createFn(module.source, module.name, { fourState, vcd });
53
+ const state = { dirty: false };
54
+ const dut = createDut(result.buffer, result.layout, module.ports, result.handle, state);
55
+ return new Simulation(result.handle, dut, result.events, state);
56
+ }
57
+ /**
58
+ * Create a Simulation directly from Veryl source code.
59
+ *
60
+ * Automatically discovers ports from the NAPI layout — no
61
+ * `ModuleDefinition` needed.
62
+ *
63
+ * ```ts
64
+ * const sim = Simulation.fromSource<CounterPorts>(COUNTER_SOURCE, "Counter");
65
+ * sim.addClock("clk", { period: 10 });
66
+ * sim.runUntil(100);
67
+ * ```
68
+ */
69
+ static fromSource(source, top, options) {
70
+ const addon = loadNativeAddon(options?.nativeAddonPath);
71
+ const napiOpts = options?.fourState ? { fourState: options.fourState } : undefined;
72
+ const raw = new addon.NativeSimulationHandle(source, top, napiOpts);
73
+ const layout = parseNapiLayout(raw.layoutJson);
74
+ const events = JSON.parse(raw.eventsJson);
75
+ const ports = buildPortsFromLayout(layout.signals, events);
76
+ const buf = raw.sharedMemory().buffer;
77
+ const state = { dirty: false };
78
+ const handle = wrapDirectSimulationHandle(raw);
79
+ const dut = createDut(buf, layout.forDut, ports, handle, state);
80
+ return new Simulation(handle, dut, events, state);
81
+ }
82
+ /**
83
+ * Create a Simulation from a Veryl project directory.
84
+ *
85
+ * Searches upward from `projectPath` for `Veryl.toml`, gathers all
86
+ * `.veryl` source files, and builds the simulation using the project's
87
+ * clock/reset settings.
88
+ *
89
+ * ```ts
90
+ * const sim = Simulation.fromProject<MyPorts>("./my-project", "Top");
91
+ * sim.addClock("clk", { period: 10 });
92
+ * ```
93
+ */
94
+ static fromProject(projectPath, top, options) {
95
+ const addon = loadNativeAddon(options?.nativeAddonPath);
96
+ const napiOpts = options?.fourState ? { fourState: options.fourState } : undefined;
97
+ const raw = addon.NativeSimulationHandle.fromProject(projectPath, top, napiOpts);
98
+ const layout = parseNapiLayout(raw.layoutJson);
99
+ const events = JSON.parse(raw.eventsJson);
100
+ const ports = buildPortsFromLayout(layout.signals, events);
101
+ const buf = raw.sharedMemory().buffer;
102
+ const state = { dirty: false };
103
+ const handle = wrapDirectSimulationHandle(raw);
104
+ const dut = createDut(buf, layout.forDut, ports, handle, state);
105
+ return new Simulation(handle, dut, events, state);
106
+ }
107
+ /** The DUT accessor object — read/write ports as plain properties. */
108
+ get dut() {
109
+ return this._dut;
110
+ }
111
+ /**
112
+ * Register a periodic clock.
113
+ *
114
+ * @param name Clock event name (must match a `clock` port).
115
+ * @param opts `period` in time units; optional `initialDelay`.
116
+ */
117
+ addClock(name, opts) {
118
+ this.ensureAlive();
119
+ const eventId = this.resolveEvent(name);
120
+ this._handle.addClock(eventId, opts.period, opts.initialDelay ?? 0);
121
+ }
122
+ /**
123
+ * Schedule a one-shot value change for a signal.
124
+ *
125
+ * @param name Event/signal name.
126
+ * @param opts `time` — absolute time to apply; `value` — value to set.
127
+ */
128
+ schedule(name, opts) {
129
+ this.ensureAlive();
130
+ const eventId = this.resolveEvent(name);
131
+ this._handle.schedule(eventId, opts.time, opts.value);
132
+ }
133
+ /**
134
+ * Run the simulation until the given time.
135
+ * Processes all scheduled events up to and including `endTime`.
136
+ * evalComb is called internally; dirty is cleared on return.
137
+ */
138
+ runUntil(endTime) {
139
+ this.ensureAlive();
140
+ this._handle.runUntil(endTime);
141
+ this._state.dirty = false;
142
+ }
143
+ /**
144
+ * Advance to the next scheduled event.
145
+ *
146
+ * @returns The time of the processed event, or `null` if no events remain.
147
+ */
148
+ step() {
149
+ this.ensureAlive();
150
+ const t = this._handle.step();
151
+ this._state.dirty = false;
152
+ return t;
153
+ }
154
+ /** Current simulation time. */
155
+ time() {
156
+ this.ensureAlive();
157
+ return this._handle.time();
158
+ }
159
+ /** Write current signal values to VCD at the given timestamp. */
160
+ dump(timestamp) {
161
+ this.ensureAlive();
162
+ this._handle.dump(timestamp);
163
+ }
164
+ /** Release native resources. */
165
+ dispose() {
166
+ if (!this._disposed) {
167
+ this._disposed = true;
168
+ this._handle.dispose();
169
+ }
170
+ }
171
+ // -----------------------------------------------------------------------
172
+ // Internal
173
+ // -----------------------------------------------------------------------
174
+ resolveEvent(name) {
175
+ const id = this._events[name];
176
+ if (id === undefined) {
177
+ throw new Error(`Unknown event '${name}'. Available: ${Object.keys(this._events).join(", ")}`);
178
+ }
179
+ return id;
180
+ }
181
+ ensureAlive() {
182
+ if (this._disposed) {
183
+ throw new Error("Simulation has been disposed");
184
+ }
185
+ }
186
+ }
187
+ //# sourceMappingURL=simulation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulation.js","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAC;AACtD,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAa3B,IAAI,aAAmD,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,EAA4B;IACpE,aAAa,GAAG,EAAE,CAAC;AACrB,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,MAAM,OAAO,UAAU;IACJ,OAAO,CAAyB;IAChC,IAAI,CAAI;IACR,OAAO,CAAyB;IAChC,MAAM,CAAa;IAC5B,SAA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AI,EAAE,KAAK,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,kBAAkB,IAAI,iBAAiB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC9E,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,WAAW;QACjB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Event-based Simulator.
3
+ *
4
+ * Wraps a NativeSimulatorHandle and provides a high-level TypeScript API
5
+ * for manually controlling clock edges via `tick()`.
6
+ */
7
+ import type { CreateResult, EventHandle, ModuleDefinition, NativeSimulatorHandle, SimulatorOptions } from "./types.js";
8
+ /**
9
+ * Placeholder for the NAPI binding's `createSimulator()`.
10
+ * Stream B will provide the real implementation; until then tests can
11
+ * inject a mock via `Simulator.create()` options or by replacing this
12
+ * module.
13
+ * @internal
14
+ */
15
+ export type NativeCreateFn = (source: string, moduleName: string, options: SimulatorOptions) => CreateResult<NativeSimulatorHandle>;
16
+ /**
17
+ * Register the NAPI binding at module load time.
18
+ * Called once by the package entry point after loading the native addon.
19
+ * @internal
20
+ */
21
+ export declare function setNativeSimulatorCreate(fn: NativeCreateFn): void;
22
+ export declare class Simulator<P = Record<string, unknown>> {
23
+ private readonly _handle;
24
+ private readonly _dut;
25
+ private readonly _events;
26
+ private readonly _defaultEventId;
27
+ private readonly _state;
28
+ private _disposed;
29
+ private constructor();
30
+ /**
31
+ * Create a Simulator for the given module.
32
+ *
33
+ * ```ts
34
+ * import { Adder } from "./generated/Adder.js";
35
+ * const sim = Simulator.create(Adder);
36
+ * ```
37
+ */
38
+ static create<P>(module: ModuleDefinition<P>, options?: SimulatorOptions & {
39
+ /** Override for testing — inject a mock NAPI create function. */
40
+ __nativeCreate?: NativeCreateFn;
41
+ }): Simulator<P>;
42
+ /**
43
+ * Create a Simulator directly from Veryl source code.
44
+ *
45
+ * Automatically discovers ports from the NAPI layout — no
46
+ * `ModuleDefinition` needed.
47
+ *
48
+ * ```ts
49
+ * const sim = Simulator.fromSource<AdderPorts>(ADDER_SOURCE, "Adder");
50
+ * sim.dut.a = 100;
51
+ * sim.dut.b = 200;
52
+ * sim.tick();
53
+ * expect(sim.dut.sum).toBe(300);
54
+ * ```
55
+ */
56
+ static fromSource<P = Record<string, unknown>>(source: string, top: string, options?: SimulatorOptions & {
57
+ nativeAddonPath?: string;
58
+ }): Simulator<P>;
59
+ /**
60
+ * Create a Simulator from a Veryl project directory.
61
+ *
62
+ * Searches upward from `projectPath` for `Veryl.toml`, gathers all
63
+ * `.veryl` source files, and builds the simulator using the project's
64
+ * clock/reset settings.
65
+ *
66
+ * ```ts
67
+ * const sim = Simulator.fromProject<MyPorts>("./my-project", "Top");
68
+ * ```
69
+ */
70
+ static fromProject<P = Record<string, unknown>>(projectPath: string, top: string, options?: SimulatorOptions & {
71
+ nativeAddonPath?: string;
72
+ }): Simulator<P>;
73
+ /** The DUT accessor object — read/write ports as plain properties. */
74
+ get dut(): P;
75
+ /**
76
+ * Trigger a clock edge.
77
+ *
78
+ * @param event Optional event handle from `this.event()`.
79
+ * If omitted, ticks the first (default) event.
80
+ * @param count Number of ticks. Default: 1.
81
+ */
82
+ tick(event?: EventHandle | number, count?: number): void;
83
+ tick(count?: number): void;
84
+ /** Resolve an event name to a handle for use with `tick()`. */
85
+ event(name: string): EventHandle;
86
+ /** Write current signal values to VCD at the given timestamp. */
87
+ dump(timestamp: number): void;
88
+ /** Release native resources. */
89
+ dispose(): void;
90
+ private ensureAlive;
91
+ }
92
+ //# sourceMappingURL=simulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulator.d.ts","sourceRoot":"","sources":["../src/simulator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO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