@celox-sim/celox 0.0.1 → 0.1.4
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.
- package/dist/dut.d.ts +35 -0
- package/dist/dut.d.ts.map +1 -0
- package/dist/dut.js +342 -0
- package/dist/dut.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/napi-bridge.d.ts +7 -0
- package/dist/napi-bridge.d.ts.map +1 -0
- package/dist/napi-bridge.js +7 -0
- package/dist/napi-bridge.js.map +1 -0
- package/dist/napi-helpers.d.ts +104 -0
- package/dist/napi-helpers.d.ts.map +1 -0
- package/dist/napi-helpers.js +207 -0
- package/dist/napi-helpers.js.map +1 -0
- package/dist/simulation.d.ts +111 -0
- package/dist/simulation.d.ts.map +1 -0
- package/dist/simulation.js +187 -0
- package/dist/simulation.js.map +1 -0
- package/dist/simulator.d.ts +92 -0
- package/dist/simulator.d.ts.map +1 -0
- package/dist/simulator.js +171 -0
- package/dist/simulator.js.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -7
- package/src/dut.test.ts +534 -0
- package/src/dut.ts +449 -0
- package/src/e2e.bench.ts +240 -0
- package/src/e2e.test.ts +965 -0
- package/src/index.ts +57 -0
- package/src/matchers.ts +154 -0
- package/src/napi-bridge.ts +13 -0
- package/src/napi-helpers.ts +326 -0
- package/src/simulation.test.ts +185 -0
- package/src/simulation.ts +273 -0
- package/src/simulator.test.ts +191 -0
- package/src/simulator.ts +266 -0
- package/src/types.ts +164 -0
- package/README.md +0 -45
|
@@ -0,0 +1,171 @@
|
|
|
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 { createDut } from "./dut.js";
|
|
8
|
+
import { loadNativeAddon, parseNapiLayout, buildPortsFromLayout, wrapDirectSimulatorHandle, } from "./napi-helpers.js";
|
|
9
|
+
let _nativeCreate;
|
|
10
|
+
/**
|
|
11
|
+
* Register the NAPI binding at module load time.
|
|
12
|
+
* Called once by the package entry point after loading the native addon.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function setNativeSimulatorCreate(fn) {
|
|
16
|
+
_nativeCreate = fn;
|
|
17
|
+
}
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Simulator
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
export class Simulator {
|
|
22
|
+
_handle;
|
|
23
|
+
_dut;
|
|
24
|
+
_events;
|
|
25
|
+
_defaultEventId;
|
|
26
|
+
_state;
|
|
27
|
+
_disposed = false;
|
|
28
|
+
constructor(handle, dut, events, state) {
|
|
29
|
+
this._handle = handle;
|
|
30
|
+
this._dut = dut;
|
|
31
|
+
this._events = events;
|
|
32
|
+
this._state = state;
|
|
33
|
+
const keys = Object.keys(events);
|
|
34
|
+
this._defaultEventId = keys.length > 0 ? events[keys[0]] : -1;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a Simulator for the given module.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { Adder } from "./generated/Adder.js";
|
|
41
|
+
* const sim = Simulator.create(Adder);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
static create(module, options) {
|
|
45
|
+
// When the module was produced by the Vite plugin, delegate to fromProject()
|
|
46
|
+
if (module.projectPath && !options?.__nativeCreate) {
|
|
47
|
+
return Simulator.fromProject(module.projectPath, module.name, options);
|
|
48
|
+
}
|
|
49
|
+
const createFn = options?.__nativeCreate ?? _nativeCreate;
|
|
50
|
+
if (!createFn) {
|
|
51
|
+
throw new Error("Native simulator binding not loaded. " +
|
|
52
|
+
"Ensure @celox-sim/celox-napi is installed.");
|
|
53
|
+
}
|
|
54
|
+
const { fourState, vcd } = options ?? {};
|
|
55
|
+
const result = createFn(module.source, module.name, { fourState, vcd });
|
|
56
|
+
const state = { dirty: false };
|
|
57
|
+
const dut = createDut(result.buffer, result.layout, module.ports, result.handle, state);
|
|
58
|
+
return new Simulator(result.handle, dut, result.events, state);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a Simulator directly from Veryl source code.
|
|
62
|
+
*
|
|
63
|
+
* Automatically discovers ports from the NAPI layout — no
|
|
64
|
+
* `ModuleDefinition` needed.
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* const sim = Simulator.fromSource<AdderPorts>(ADDER_SOURCE, "Adder");
|
|
68
|
+
* sim.dut.a = 100;
|
|
69
|
+
* sim.dut.b = 200;
|
|
70
|
+
* sim.tick();
|
|
71
|
+
* expect(sim.dut.sum).toBe(300);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
static fromSource(source, top, options) {
|
|
75
|
+
const addon = loadNativeAddon(options?.nativeAddonPath);
|
|
76
|
+
const napiOpts = options?.fourState ? { fourState: options.fourState } : undefined;
|
|
77
|
+
const raw = new addon.NativeSimulatorHandle(source, top, napiOpts);
|
|
78
|
+
const layout = parseNapiLayout(raw.layoutJson);
|
|
79
|
+
const events = JSON.parse(raw.eventsJson);
|
|
80
|
+
const ports = buildPortsFromLayout(layout.signals, events);
|
|
81
|
+
const buf = raw.sharedMemory().buffer;
|
|
82
|
+
const state = { dirty: false };
|
|
83
|
+
const handle = wrapDirectSimulatorHandle(raw);
|
|
84
|
+
const dut = createDut(buf, layout.forDut, ports, handle, state);
|
|
85
|
+
return new Simulator(handle, dut, events, state);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a Simulator from a Veryl project directory.
|
|
89
|
+
*
|
|
90
|
+
* Searches upward from `projectPath` for `Veryl.toml`, gathers all
|
|
91
|
+
* `.veryl` source files, and builds the simulator using the project's
|
|
92
|
+
* clock/reset settings.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* const sim = Simulator.fromProject<MyPorts>("./my-project", "Top");
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
static fromProject(projectPath, top, options) {
|
|
99
|
+
const addon = loadNativeAddon(options?.nativeAddonPath);
|
|
100
|
+
const napiOpts = options?.fourState ? { fourState: options.fourState } : undefined;
|
|
101
|
+
const raw = addon.NativeSimulatorHandle.fromProject(projectPath, top, napiOpts);
|
|
102
|
+
const layout = parseNapiLayout(raw.layoutJson);
|
|
103
|
+
const events = JSON.parse(raw.eventsJson);
|
|
104
|
+
const ports = buildPortsFromLayout(layout.signals, events);
|
|
105
|
+
const buf = raw.sharedMemory().buffer;
|
|
106
|
+
const state = { dirty: false };
|
|
107
|
+
const handle = wrapDirectSimulatorHandle(raw);
|
|
108
|
+
const dut = createDut(buf, layout.forDut, ports, handle, state);
|
|
109
|
+
return new Simulator(handle, dut, events, state);
|
|
110
|
+
}
|
|
111
|
+
/** The DUT accessor object — read/write ports as plain properties. */
|
|
112
|
+
get dut() {
|
|
113
|
+
return this._dut;
|
|
114
|
+
}
|
|
115
|
+
tick(eventOrCount, count) {
|
|
116
|
+
this.ensureAlive();
|
|
117
|
+
let eventId;
|
|
118
|
+
let ticks;
|
|
119
|
+
if (typeof eventOrCount === "object" && eventOrCount !== null) {
|
|
120
|
+
// tick(eventHandle, count?)
|
|
121
|
+
eventId = eventOrCount.id;
|
|
122
|
+
ticks = count ?? 1;
|
|
123
|
+
}
|
|
124
|
+
else if (typeof eventOrCount === "number") {
|
|
125
|
+
// tick(count) — default event
|
|
126
|
+
eventId = this._defaultEventId;
|
|
127
|
+
ticks = eventOrCount;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// tick() — default event, 1 tick
|
|
131
|
+
eventId = this._defaultEventId;
|
|
132
|
+
ticks = 1;
|
|
133
|
+
}
|
|
134
|
+
if (ticks === 1) {
|
|
135
|
+
this._handle.tick(eventId);
|
|
136
|
+
}
|
|
137
|
+
else if (ticks > 1) {
|
|
138
|
+
this._handle.tickN(eventId, ticks);
|
|
139
|
+
}
|
|
140
|
+
this._state.dirty = false;
|
|
141
|
+
}
|
|
142
|
+
/** Resolve an event name to a handle for use with `tick()`. */
|
|
143
|
+
event(name) {
|
|
144
|
+
const id = this._events[name];
|
|
145
|
+
if (id === undefined) {
|
|
146
|
+
throw new Error(`Unknown event '${name}'. Available: ${Object.keys(this._events).join(", ")}`);
|
|
147
|
+
}
|
|
148
|
+
return { name, id };
|
|
149
|
+
}
|
|
150
|
+
/** Write current signal values to VCD at the given timestamp. */
|
|
151
|
+
dump(timestamp) {
|
|
152
|
+
this.ensureAlive();
|
|
153
|
+
this._handle.dump(timestamp);
|
|
154
|
+
}
|
|
155
|
+
/** Release native resources. */
|
|
156
|
+
dispose() {
|
|
157
|
+
if (!this._disposed) {
|
|
158
|
+
this._disposed = true;
|
|
159
|
+
this._handle.dispose();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// -----------------------------------------------------------------------
|
|
163
|
+
// Internal
|
|
164
|
+
// -----------------------------------------------------------------------
|
|
165
|
+
ensureAlive() {
|
|
166
|
+
if (this._disposed) {
|
|
167
|
+
throw new Error("Simulator has been disposed");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=simulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulator.js","sourceRoot":"","sources":["../src/simulator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAC;AACtD,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAe3B,IAAI,aAAyC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,wBAAw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C,IAAI,CAAC,EAAE,CAC9E,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACtB,CAAC;IAED,iEAAiE;IACjE,IAAI,CAAC,SAAiB;QACpB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,gCAAgC;IAChC,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,WAAW;IACX,0EAA0E;IAElE,WAAW;QACjB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @celox-sim/celox — Core type definitions
|
|
3
|
+
*
|
|
4
|
+
* These types define the contract between:
|
|
5
|
+
* - Stream A (type generator): produces ModuleDefinition
|
|
6
|
+
* - Stream B (NAPI bindings): produces CreateResult / NativeHandles
|
|
7
|
+
* - Stream C (this package): consumes both
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A compiled module descriptor emitted by `celox-gen-ts`.
|
|
11
|
+
* The type parameter `Ports` carries the generated port interface
|
|
12
|
+
* (e.g. `AdderPorts`) so that `Simulator.create(Adder)` returns
|
|
13
|
+
* a correctly-typed DUT accessor.
|
|
14
|
+
*/
|
|
15
|
+
export interface ModuleDefinition<Ports = Record<string, unknown>> {
|
|
16
|
+
readonly __celox_module: true;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
readonly ports: Record<string, PortInfo>;
|
|
20
|
+
readonly events: string[];
|
|
21
|
+
/** Absolute path to the Veryl project directory (set by Vite plugin). */
|
|
22
|
+
readonly projectPath?: string;
|
|
23
|
+
/** Phantom field — never set at runtime. Carries the `Ports` type. */
|
|
24
|
+
readonly __ports?: Ports;
|
|
25
|
+
}
|
|
26
|
+
/** Metadata for a single port / interface member. */
|
|
27
|
+
export interface PortInfo {
|
|
28
|
+
readonly direction: "input" | "output" | "inout";
|
|
29
|
+
readonly type: "clock" | "reset" | "logic" | "bit";
|
|
30
|
+
readonly width: number;
|
|
31
|
+
readonly arrayDims?: readonly number[];
|
|
32
|
+
readonly is4state?: boolean;
|
|
33
|
+
/** Nested interface members (recursive). */
|
|
34
|
+
readonly interface?: Record<string, PortInfo>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Byte-level location of a signal inside the SharedArrayBuffer.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export interface SignalLayout {
|
|
41
|
+
/** Byte offset within the STABLE region. */
|
|
42
|
+
readonly offset: number;
|
|
43
|
+
/** Bit width of the signal. */
|
|
44
|
+
readonly width: number;
|
|
45
|
+
/** Number of bytes occupied (ceil(width/8)). */
|
|
46
|
+
readonly byteSize: number;
|
|
47
|
+
/** If true, an equal-sized mask follows immediately after the value. */
|
|
48
|
+
readonly is4state: boolean;
|
|
49
|
+
readonly direction: "input" | "output" | "inout";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Opaque handle returned by NAPI for event-based simulation.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export interface NativeSimulatorHandle {
|
|
56
|
+
tick(eventId: number): void;
|
|
57
|
+
tickN(eventId: number, count: number): void;
|
|
58
|
+
evalComb(): void;
|
|
59
|
+
dump(timestamp: number): void;
|
|
60
|
+
dispose(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Opaque handle returned by NAPI for time-based simulation.
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export interface NativeSimulationHandle {
|
|
67
|
+
addClock(eventId: number, period: number, initialDelay: number): void;
|
|
68
|
+
schedule(eventId: number, time: number, value: number): void;
|
|
69
|
+
runUntil(endTime: number): void;
|
|
70
|
+
step(): number | null;
|
|
71
|
+
time(): number;
|
|
72
|
+
evalComb(): void;
|
|
73
|
+
dump(timestamp: number): void;
|
|
74
|
+
dispose(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Union of both handle types for code that is handle-agnostic.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export type NativeHandle = NativeSimulatorHandle | NativeSimulationHandle;
|
|
81
|
+
/**
|
|
82
|
+
* Result returned by NAPI `create()`.
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export interface CreateResult<H extends NativeHandle = NativeHandle> {
|
|
86
|
+
/** The simulator's internal memory buffer shared zero-copy. */
|
|
87
|
+
readonly buffer: ArrayBuffer | SharedArrayBuffer;
|
|
88
|
+
/** Per-signal byte layout within `buffer`. */
|
|
89
|
+
readonly layout: Record<string, SignalLayout>;
|
|
90
|
+
/** Event name → internal event ID mapping. */
|
|
91
|
+
readonly events: Record<string, number>;
|
|
92
|
+
/** Native control handle. */
|
|
93
|
+
readonly handle: H;
|
|
94
|
+
}
|
|
95
|
+
export interface SimulatorOptions {
|
|
96
|
+
/** Enable 4-state (X/Z) simulation. Default: false. */
|
|
97
|
+
fourState?: boolean;
|
|
98
|
+
/** Path to write VCD waveform output. */
|
|
99
|
+
vcd?: string;
|
|
100
|
+
}
|
|
101
|
+
/** A resolved event reference for use with `tick()`. */
|
|
102
|
+
export interface EventHandle {
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly id: number;
|
|
105
|
+
}
|
|
106
|
+
/** Sentinel representing all-X. */
|
|
107
|
+
export declare const X: unique symbol;
|
|
108
|
+
/** A 4-state value with explicit bit-level mask. */
|
|
109
|
+
export interface FourStateValue {
|
|
110
|
+
readonly __fourState: true;
|
|
111
|
+
readonly value: number | bigint;
|
|
112
|
+
readonly mask: number | bigint;
|
|
113
|
+
}
|
|
114
|
+
/** Construct a 4-state value. Mask bits set to 1 indicate X. */
|
|
115
|
+
export declare function FourState(value: number | bigint, mask: number | bigint): FourStateValue;
|
|
116
|
+
export declare function isFourStateValue(v: unknown): v is FourStateValue;
|
|
117
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/D,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;CAC1B;AAED,qDAAqD;AACrD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,4CAA4C;IAC5C,QAAQ,CA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
|
2
|
+
* @celox-sim/celox — Core type definitions
|
|
3
|
+
*
|
|
4
|
+
* These types define the contract between:
|
|
5
|
+
* - Stream A (type generator): produces ModuleDefinition
|
|
6
|
+
* - Stream B (NAPI bindings): produces CreateResult / NativeHandles
|
|
7
|
+
* - Stream C (this package): consumes both
|
|
8
|
+
*/
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// 4-state helpers
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
/** Sentinel representing all-X. */
|
|
13
|
+
export const X = Symbol.for("veryl:X");
|
|
14
|
+
/** Construct a 4-state value. Mask bits set to 1 indicate X. */
|
|
15
|
+
export function FourState(value, mask) {
|
|
16
|
+
return { __fourState: true, value, mask };
|
|
17
|
+
}
|
|
18
|
+
export function isFourStateValue(v) {
|
|
19
|
+
return (typeof v === "object" &&
|
|
20
|
+
v !== null &&
|
|
21
|
+
v.__fourState === true);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgIH,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E,mCAAmC;AACnC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AASvC,gEAAgE;AAChE,MAAM,UAAU,SAAS,CACvB,KAAsB,EACtB,IAAqB;IAErB,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAU;IACzC,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACT,CAAoB,CAAC,WAAW,KAAK,IAAI,CAC3C,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celox-sim/celox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "TypeScript runtime for Celox HDL simulation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
5
18
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
"celox",
|
|
20
|
+
"hdl",
|
|
21
|
+
"simulator",
|
|
22
|
+
"testbench",
|
|
23
|
+
"hardware"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/celox-sim/celox",
|
|
28
|
+
"directory": "packages/celox"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@celox-sim/celox-napi": "0.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"vitest": ">=1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"vitest": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^25.3.2",
|
|
44
|
+
"typescript": "^5.7.0",
|
|
45
|
+
"vitest": "^3.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"bench": "vitest bench"
|
|
52
|
+
}
|
|
53
|
+
}
|