@fraczak/k 7.0.2 → 7.2.0
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/CHANGELOG.md +75 -0
- package/DOCS/CODECS.md +37 -2
- package/DOCS/CODEC_ARCHITECTURE.md +12 -5
- package/DOCS/FILE_FORMATS.md +238 -15
- package/DOCS/POLYMORPHIC_IR.md +104 -0
- package/DOCS/REPL.md +11 -3
- package/DOCS/WEB_REPL_REQUIREMENTS.md +1 -1
- package/JOURNAL.md +288 -0
- package/README.md +12 -3
- package/Value.mjs +28 -3
- package/access-table.mjs +343 -0
- package/backend-api.mjs +23 -1
- package/backends/llvm/README.md +20 -21
- package/backends/llvm/bin/k-llvm-build.mjs +105 -32
- package/backends/llvm/bin/k-llvm-compile.mjs +63 -24
- package/backends/llvm/bin/k-llvm.mjs +292 -0
- package/backends/llvm/runtime/krt.c +8 -0
- package/backends/llvm/runtime/krt.h +1 -0
- package/backends/llvm/src/cli.mjs +95 -17
- package/backends/llvm/src/executable.mjs +128 -11
- package/backends/llvm/src/kvm2llvm.mjs +10 -5
- package/backends/llvm/src/llvm.mjs +121 -9
- package/backends/llvm/tests/integration.sh +11 -11
- package/backends/llvm/{bin → tests}/k-llvm-run.mjs +48 -22
- package/backends/llvm/tests/perf-support.mjs +24 -3
- package/backends/llvm/tests/test-llvm.mjs +22 -1
- package/backends/wasm/bin/k-wasm-compile.mjs +46 -20
- package/backends/wasm/bin/k-wasm-run.mjs +61 -20
- package/backends/wasm/bin/k-wasm.mjs +47 -13
- package/backends/wasm/src/cli.mjs +141 -19
- package/backends/wasm/src/wasm.mjs +130 -23
- package/browser/repl-browser.mjs +16 -5
- package/browser/tree-view.mjs +47 -8
- package/browser/vfs-data.mjs +6 -5
- package/codecs/README.md +1 -0
- package/codecs/djson.mjs +270 -0
- package/codecs/int.mjs +2 -1
- package/codecs/json.mjs +7 -2
- package/codecs/k-parse.mjs +36 -9
- package/codecs/k-print.mjs +26 -6
- package/codecs/runtime/codec-sdk.mjs +24 -6
- package/codecs/runtime/pattern-json.mjs +80 -1
- package/codecs/runtime/prefix-codec.mjs +629 -67
- package/codecs/runtime/show-value.mjs +93 -51
- package/codecs/runtime/unicode-string.mjs +29 -6
- package/codecs/show.mjs +24 -6
- package/codecs/utf16.mjs +2 -1
- package/k.mjs +56 -16
- package/kir.mjs +58 -19
- package/kvm.mjs +49 -12
- package/objects/compile.mjs +37 -23
- package/objects/decompile.mjs +40 -10
- package/objects/extract-aliases.mjs +44 -14
- package/objects/inspect.mjs +19 -14
- package/objects/validate.mjs +18 -11
- package/package.json +11 -3
- package/pkir.mjs +772 -0
- package/repl.mjs +92 -23
- package/scripts/build-repl-html.mjs +22 -3
- package/scripts/perf-ieee.mjs +264 -13
- package/scripts/perf-int.mjs +315 -22
- package/scripts/perf-multiplication.mjs +58 -7
- package/scripts/perf-poly.mjs +306 -24
- package/scripts/run-tests.mjs +3 -0
- package/tests/test-access-table.mjs +213 -0
- package/tests/test-codecs.mjs +168 -0
- package/tests/test-pkir.mjs +530 -0
- package/tests/test-polymorphic-tdd.mjs +196 -0
- package/tests/test-repl-html.mjs +16 -2
- package/tests/test-repl.mjs +63 -1
- package/backends/llvm/bin/k-llvm-jit.mjs +0 -160
package/scripts/perf-ieee.mjs
CHANGED
|
@@ -54,7 +54,7 @@ function printHelp() {
|
|
|
54
54
|
|
|
55
55
|
IEEE 754 Floating-Point Arithmetic Benchmark Harness.
|
|
56
56
|
Benchmarks add, sub, mul, and div on Examples/ieee.k across
|
|
57
|
-
Native JS, kVM interpreter, LLVM, and
|
|
57
|
+
Native JS, kVM interpreter, LLVM, Wasm, and PKIR backends.
|
|
58
58
|
|
|
59
59
|
Options:
|
|
60
60
|
--opt=<levels>, --opts=<levels>
|
|
@@ -65,16 +65,20 @@ Options:
|
|
|
65
65
|
Run full LLVM optimization sweep (-O0, -O1, -O2).
|
|
66
66
|
--wasm-in-process
|
|
67
67
|
Run WebAssembly in-process instead of persistent subprocess runner.
|
|
68
|
+
--pkir-only
|
|
69
|
+
Run only PKIR backend.
|
|
68
70
|
-h, --help
|
|
69
71
|
Show this help message and exit.
|
|
70
72
|
|
|
71
73
|
Environment Variables:
|
|
72
74
|
BACKENDS
|
|
73
|
-
Target backend to run: 'llvm' or '
|
|
75
|
+
Target backend to run: 'llvm', 'wasm', or 'pkir'.
|
|
74
76
|
LLVM_ONLY
|
|
75
77
|
Run only LLVM backend ('1' to enable).
|
|
76
78
|
WASM_ONLY
|
|
77
79
|
Run only WebAssembly backend ('1' to enable).
|
|
80
|
+
PKIR_ONLY
|
|
81
|
+
Run only PKIR backend ('1' to enable).
|
|
78
82
|
BACKENDS_ONLY
|
|
79
83
|
Skip JS and kVM interpreter baselines ('1' to enable).
|
|
80
84
|
VALUES
|
|
@@ -116,11 +120,52 @@ if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
|
116
120
|
|
|
117
121
|
// Backend selection
|
|
118
122
|
const backendsEnv = process.env.BACKENDS?.toLowerCase();
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
123
|
+
const backendsList = backendsEnv
|
|
124
|
+
? backendsEnv.split(",").map(s => s.trim())
|
|
125
|
+
: null;
|
|
126
|
+
const llvmPkirOnly = process.env.LLVM_PKIR_ONLY === "1"
|
|
127
|
+
|| (backendsList && backendsList.length === 1 &&
|
|
128
|
+
backendsList[0] === "llvm-pkir")
|
|
129
|
+
|| process.argv.includes("--llvm-pkir-only");
|
|
130
|
+
const pkirOnly = !llvmPkirOnly && (
|
|
131
|
+
process.env.PKIR_ONLY === "1"
|
|
132
|
+
|| (backendsList && backendsList.length === 1 &&
|
|
133
|
+
backendsList[0] === "pkir")
|
|
134
|
+
|| process.argv.includes("--pkir-only")
|
|
135
|
+
);
|
|
136
|
+
const llvmOnly = !pkirOnly && !llvmPkirOnly && (
|
|
137
|
+
process.env.LLVM_ONLY === "1"
|
|
138
|
+
|| (backendsList && backendsList.length === 1 &&
|
|
139
|
+
backendsList[0] === "llvm")
|
|
140
|
+
);
|
|
141
|
+
const wasmOnly = !pkirOnly && !llvmPkirOnly && !llvmOnly && (
|
|
142
|
+
process.env.WASM_ONLY === "1"
|
|
143
|
+
|| (backendsList && backendsList.length === 1 &&
|
|
144
|
+
backendsList[0] === "wasm")
|
|
145
|
+
);
|
|
146
|
+
const runLLVM = backendsList
|
|
147
|
+
? backendsList.includes("llvm")
|
|
148
|
+
: !wasmOnly && !pkirOnly && !llvmPkirOnly;
|
|
149
|
+
const runLLVMPKIR = backendsList
|
|
150
|
+
? backendsList.includes("llvm-pkir")
|
|
151
|
+
: !wasmOnly && !pkirOnly && !llvmOnly;
|
|
152
|
+
const runWasm = backendsList
|
|
153
|
+
? backendsList.includes("wasm")
|
|
154
|
+
: !llvmOnly && !pkirOnly && !llvmPkirOnly;
|
|
155
|
+
const runPKIR = backendsList
|
|
156
|
+
? backendsList.includes("pkir")
|
|
157
|
+
: !llvmOnly && !wasmOnly && !llvmPkirOnly;
|
|
158
|
+
const runBaselines = !process.env.BACKENDS_ONLY
|
|
159
|
+
&& (backendsList == null || backendsList.includes("kvm") ||
|
|
160
|
+
backendsList.includes("js"))
|
|
161
|
+
&& !llvmOnly && !wasmOnly && !pkirOnly && !llvmPkirOnly;
|
|
162
|
+
|
|
163
|
+
function llvmLaneNameStr() {
|
|
164
|
+
return llvmLaneName();
|
|
165
|
+
}
|
|
166
|
+
function llvmPkirLaneNameStr() {
|
|
167
|
+
return llvmLaneName().replace("LLVM", "LLVM-PKIR");
|
|
168
|
+
}
|
|
124
169
|
|
|
125
170
|
const ops = ["add", "sub", "mul", "div"];
|
|
126
171
|
const values = csvEnv("VALUES", "0.5,-4,0,Infinity,-Infinity,NaN");
|
|
@@ -172,6 +217,9 @@ function wasmLaneName() {
|
|
|
172
217
|
const mode = wasmPipe ? "persistent" : "in-process";
|
|
173
218
|
return `WebAssembly (${mode})`;
|
|
174
219
|
}
|
|
220
|
+
function pkirLaneName() {
|
|
221
|
+
return "PKIR (Wasm persistent)";
|
|
222
|
+
}
|
|
175
223
|
|
|
176
224
|
console.log("==> Initializing state and loading @fraczak/k/Examples/ieee.k");
|
|
177
225
|
const state = createState();
|
|
@@ -206,7 +254,8 @@ const perfKSource = generatePerfK(values);
|
|
|
206
254
|
await evaluateInput(perfKSource, state);
|
|
207
255
|
|
|
208
256
|
const ieeeRaw = fs.readFileSync(ieeePath, "utf8");
|
|
209
|
-
// Exclude trailing unassigned expression and comment block to ensure
|
|
257
|
+
// Exclude trailing unassigned expression and comment block to ensure
|
|
258
|
+
// clean parse.
|
|
210
259
|
const endIdx = ieeeRaw.indexOf("\n()\n");
|
|
211
260
|
const ieeeBase = endIdx !== -1 ? ieeeRaw.slice(0, endIdx) : ieeeRaw;
|
|
212
261
|
const fullSource = `${ieeeBase}\n${perfKSource}\nperf_ieee`;
|
|
@@ -249,7 +298,8 @@ if (runLLVM) {
|
|
|
249
298
|
cacheDir,
|
|
250
299
|
sourceLabel: "@fraczak/k/Examples/ieee.k#perf_ieee",
|
|
251
300
|
runtimeMode: llvmRuntimeMode,
|
|
252
|
-
clangOpt: opt
|
|
301
|
+
clangOpt: opt,
|
|
302
|
+
usePKIR: false
|
|
253
303
|
});
|
|
254
304
|
const singleCase = [{
|
|
255
305
|
op: "perf_ieee",
|
|
@@ -266,6 +316,37 @@ if (runLLVM) {
|
|
|
266
316
|
codes.load(state.codes);
|
|
267
317
|
}
|
|
268
318
|
|
|
319
|
+
// Setup LLVM-PKIR
|
|
320
|
+
const llvmPkirCasesByOpt = new Map();
|
|
321
|
+
if (runLLVMPKIR) {
|
|
322
|
+
for (const opt of llvmOptLevels) {
|
|
323
|
+
console.log(`==> Compiling LLVM-PKIR executable (${opt})...`);
|
|
324
|
+
const llvm = tryCompileCase({
|
|
325
|
+
object: relation.object,
|
|
326
|
+
relationName: relation.relationName,
|
|
327
|
+
relHash: relation.relHash,
|
|
328
|
+
inputPattern,
|
|
329
|
+
cacheDir,
|
|
330
|
+
sourceLabel: "@fraczak/k/Examples/ieee.k#perf_ieee",
|
|
331
|
+
runtimeMode: llvmRuntimeMode,
|
|
332
|
+
clangOpt: opt,
|
|
333
|
+
usePKIR: true
|
|
334
|
+
});
|
|
335
|
+
const singleCase = [{
|
|
336
|
+
op: "perf_ieee",
|
|
337
|
+
label: "params",
|
|
338
|
+
inputVal,
|
|
339
|
+
inputWire,
|
|
340
|
+
inputPattern,
|
|
341
|
+
expected,
|
|
342
|
+
llvm
|
|
343
|
+
}];
|
|
344
|
+
llvmPkirCasesByOpt.set(opt, singleCase);
|
|
345
|
+
printCompileFailures(singleCase);
|
|
346
|
+
}
|
|
347
|
+
codes.load(state.codes);
|
|
348
|
+
}
|
|
349
|
+
|
|
269
350
|
// Setup Wasm
|
|
270
351
|
let wasmExports = null;
|
|
271
352
|
let wasmPtrIn = null;
|
|
@@ -310,6 +391,28 @@ if (runWasm) {
|
|
|
310
391
|
}
|
|
311
392
|
}
|
|
312
393
|
|
|
394
|
+
// Setup PKIR
|
|
395
|
+
let pkirExePath = null;
|
|
396
|
+
let pkirCompileError = null;
|
|
397
|
+
if (runPKIR) {
|
|
398
|
+
console.log("==> Compiling PKIR executable (persistent runner)...");
|
|
399
|
+
try {
|
|
400
|
+
const pkirPath = path.join(cacheDir, "perf_ieee_pkir.wasm");
|
|
401
|
+
pkirExePath = path.join(cacheDir, "perf_ieee_pkir.exe");
|
|
402
|
+
const wasmBuf = await compileWasmArtifactFromObject(relation.object, {
|
|
403
|
+
entry: "__main__",
|
|
404
|
+
usePKIR: true
|
|
405
|
+
});
|
|
406
|
+
fs.writeFileSync(pkirPath, wasmBuf);
|
|
407
|
+
const runBin = fileURLToPath(import.meta.resolve("../backends/wasm/bin/k-wasm-run.mjs"));
|
|
408
|
+
fs.writeFileSync(pkirExePath, `#!/bin/sh\nexec node "${runBin}" "${pkirPath}" "$@"\n`, { mode: 0o755 });
|
|
409
|
+
} catch (error) {
|
|
410
|
+
pkirCompileError = error.stack || error.message || String(error);
|
|
411
|
+
console.log("PKIR compilation failed:");
|
|
412
|
+
console.log(pkirCompileError.split("\n").slice(0, 8).join("\n"));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
313
416
|
function printBenchmarkDescription() {
|
|
314
417
|
const lanes = [];
|
|
315
418
|
if (runBaselines) {
|
|
@@ -319,11 +422,28 @@ function printBenchmarkDescription() {
|
|
|
319
422
|
}
|
|
320
423
|
if (runLLVM) {
|
|
321
424
|
for (const opt of llvmOptLevels) {
|
|
322
|
-
const mode = llvmLaneName()
|
|
323
|
-
|
|
425
|
+
const mode = llvmLaneName()
|
|
426
|
+
.replace(/^LLVM Executable\s*\((.*)\)$/, "$1");
|
|
427
|
+
lanes.push(
|
|
428
|
+
llvmOptLevels.length > 1
|
|
429
|
+
? `LLVM ${opt} (${mode})`
|
|
430
|
+
: llvmLaneName()
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (runLLVMPKIR) {
|
|
435
|
+
for (const opt of llvmOptLevels) {
|
|
436
|
+
const mode = llvmLaneName()
|
|
437
|
+
.replace(/^LLVM Executable\s*\((.*)\)$/, "$1");
|
|
438
|
+
lanes.push(
|
|
439
|
+
llvmOptLevels.length > 1
|
|
440
|
+
? `LLVM-PKIR ${opt} (${mode})`
|
|
441
|
+
: llvmLaneName().replace("LLVM", "LLVM-PKIR")
|
|
442
|
+
);
|
|
324
443
|
}
|
|
325
444
|
}
|
|
326
445
|
if (runWasm) lanes.push(wasmLaneName());
|
|
446
|
+
if (runPKIR) lanes.push(pkirLaneName());
|
|
327
447
|
|
|
328
448
|
console.log("==> Benchmark description");
|
|
329
449
|
console.log(" source: @fraczak/k/Examples/ieee.k#perf_ieee (single program)");
|
|
@@ -336,6 +456,11 @@ function printBenchmarkDescription() {
|
|
|
336
456
|
console.log(` llvm clang opts: ${llvmOptLevels.join(", ")}`);
|
|
337
457
|
console.log(` llvm cache dir: ${cacheDir}`);
|
|
338
458
|
}
|
|
459
|
+
if (runLLVMPKIR) {
|
|
460
|
+
console.log(` llvm-pkir warmup iterations: ${llvmWarmupIterations}`);
|
|
461
|
+
console.log(` llvm-pkir runtime mode: ${llvmRuntimeMode}`);
|
|
462
|
+
console.log(` llvm-pkir clang opts: ${llvmOptLevels.join(", ")}`);
|
|
463
|
+
}
|
|
339
464
|
if (runWasm) {
|
|
340
465
|
console.log(` wasm runner mode: ${wasmPipe ? "persistent pipe" : "in-process"}`);
|
|
341
466
|
console.log(` wasm warmup iterations: ${wasmWarmupIterations}`);
|
|
@@ -343,6 +468,9 @@ function printBenchmarkDescription() {
|
|
|
343
468
|
console.log(` wasm arena reset: ${wasmReset ? "yes" : "no"}`);
|
|
344
469
|
}
|
|
345
470
|
}
|
|
471
|
+
if (runPKIR) {
|
|
472
|
+
console.log(` pkir warmup iterations: ${wasmWarmupIterations}`);
|
|
473
|
+
}
|
|
346
474
|
console.log(` iterations: ${iterations}`);
|
|
347
475
|
console.log(` benchmark lanes: ${lanes.join("; ")}`);
|
|
348
476
|
console.log(" conformance: all outputs are compared to native expected values");
|
|
@@ -403,6 +531,28 @@ if (runLLVM) {
|
|
|
403
531
|
}
|
|
404
532
|
}
|
|
405
533
|
|
|
534
|
+
// 2b. LLVM-PKIR lanes
|
|
535
|
+
const llvmPkirResults = new Map();
|
|
536
|
+
if (runLLVMPKIR) {
|
|
537
|
+
for (const opt of llvmOptLevels) {
|
|
538
|
+
const casesForOpt = llvmPkirCasesByOpt.get(opt);
|
|
539
|
+
const llvmRunner = createLLVMRunner(casesForOpt);
|
|
540
|
+
try {
|
|
541
|
+
if (llvmWarmupIterations > 0) {
|
|
542
|
+
console.log(`==> Warming LLVM-PKIR (${opt}) executable (${llvmWarmupIterations} iterations)...`);
|
|
543
|
+
await llvmRunner.run(llvmWarmupIterations);
|
|
544
|
+
}
|
|
545
|
+
console.log(`==> Running LLVM-PKIR (${opt}) (${iterations} iterations)...`);
|
|
546
|
+
const result = await llvmRunner.run(iterations);
|
|
547
|
+
llvmPkirResults.set(opt, result);
|
|
548
|
+
} catch (err) {
|
|
549
|
+
console.log(`==> LLVM-PKIR (${opt}) execution failed: ${err.message?.split("\n")[0]}`);
|
|
550
|
+
} finally {
|
|
551
|
+
llvmRunner.close();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
406
556
|
// 3. Wasm lane
|
|
407
557
|
let wasmResult = null;
|
|
408
558
|
if (runWasm) {
|
|
@@ -445,6 +595,28 @@ if (runWasm) {
|
|
|
445
595
|
}
|
|
446
596
|
}
|
|
447
597
|
|
|
598
|
+
// 4. PKIR lane
|
|
599
|
+
let pkirResult = null;
|
|
600
|
+
if (runPKIR) {
|
|
601
|
+
if (pkirExePath) {
|
|
602
|
+
const server = new PersistentExecutable(pkirExePath);
|
|
603
|
+
try {
|
|
604
|
+
if (wasmWarmupIterations > 0) {
|
|
605
|
+
console.log(`==> Warming PKIR (${wasmWarmupIterations} iterations)...`);
|
|
606
|
+
for (let i = 0; i < wasmWarmupIterations; i++) {
|
|
607
|
+
await server.request(inputWire);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
console.log(`==> Running PKIR (${iterations} iterations)...`);
|
|
611
|
+
pkirResult = await runTimedIterationsAsync(iterations, async () => {
|
|
612
|
+
await server.request(inputWire);
|
|
613
|
+
});
|
|
614
|
+
} finally {
|
|
615
|
+
server.close();
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
448
620
|
console.log("\n=================== IEEE BENCHMARK RESULTS ===================");
|
|
449
621
|
console.log(`Program calls per iteration: 1 (${totalOps} IEEE operations evaluated inside)`);
|
|
450
622
|
console.log(`Total requested program calls: ${iterations} (${iterations * totalOps} equivalent IEEE operations)`);
|
|
@@ -457,16 +629,38 @@ if (runBaselines) {
|
|
|
457
629
|
}
|
|
458
630
|
if (runLLVM) {
|
|
459
631
|
for (const opt of llvmOptLevels) {
|
|
632
|
+
const mode = llvmLaneName()
|
|
633
|
+
.replace(/^LLVM Executable\s*\((.*)\)$/, "$1");
|
|
460
634
|
const title = llvmOptLevels.length > 1
|
|
461
|
-
? `LLVM ${opt} (${
|
|
635
|
+
? `LLVM ${opt} (${mode})`
|
|
462
636
|
: llvmLaneName();
|
|
463
|
-
console.log(
|
|
637
|
+
console.log(
|
|
638
|
+
`${laneIndex++}. ${title.padEnd(29)} ` +
|
|
639
|
+
`${formatTiming(llvmResults.get(opt))}`
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (runLLVMPKIR) {
|
|
644
|
+
for (const opt of llvmOptLevels) {
|
|
645
|
+
const mode = llvmLaneName()
|
|
646
|
+
.replace(/^LLVM Executable\s*\((.*)\)$/, "$1");
|
|
647
|
+
const title = llvmOptLevels.length > 1
|
|
648
|
+
? `LLVM-PKIR ${opt} (${mode})`
|
|
649
|
+
: llvmLaneName().replace("LLVM", "LLVM-PKIR");
|
|
650
|
+
console.log(
|
|
651
|
+
`${laneIndex++}. ${title.padEnd(29)} ` +
|
|
652
|
+
`${formatTiming(llvmPkirResults.get(opt))}`
|
|
653
|
+
);
|
|
464
654
|
}
|
|
465
655
|
}
|
|
466
656
|
if (runWasm) {
|
|
467
657
|
const timingStr = wasmResult ? formatTiming(wasmResult) : "compile failed";
|
|
468
658
|
console.log(`${laneIndex++}. ${wasmLaneName().padEnd(29)} ${timingStr}`);
|
|
469
659
|
}
|
|
660
|
+
if (runPKIR) {
|
|
661
|
+
const timingStr = pkirResult ? formatTiming(pkirResult) : "compile failed";
|
|
662
|
+
console.log(`${laneIndex++}. ${pkirLaneName().padEnd(29)} ${timingStr}`);
|
|
663
|
+
}
|
|
470
664
|
console.log("==============================================================\n");
|
|
471
665
|
|
|
472
666
|
// Conformance Validation
|
|
@@ -504,6 +698,28 @@ if (runLLVM) {
|
|
|
504
698
|
}
|
|
505
699
|
}
|
|
506
700
|
|
|
701
|
+
if (runLLVMPKIR) {
|
|
702
|
+
for (const opt of llvmOptLevels) {
|
|
703
|
+
const casesForOpt = llvmPkirCasesByOpt.get(opt);
|
|
704
|
+
const tc = casesForOpt[0];
|
|
705
|
+
if (tc.llvm.status !== "ok") {
|
|
706
|
+
tc.llvmConformance = "compile-failed";
|
|
707
|
+
} else {
|
|
708
|
+
try {
|
|
709
|
+
const outputWire = await runExecutable(tc.llvm.exePath, tc.inputWire);
|
|
710
|
+
const actual = decodeWire(outputWire).value;
|
|
711
|
+
assert.deepEqual(toPlainObject(actual), toPlainObject(expected));
|
|
712
|
+
tc.llvmConformance = "ok";
|
|
713
|
+
} catch (error) {
|
|
714
|
+
tc.llvmConformance = "failed";
|
|
715
|
+
tc.llvm.error = error.stack || error.message || String(error);
|
|
716
|
+
console.log(`LLVM-PKIR (${opt}) conformance failure:`);
|
|
717
|
+
console.log(tc.llvm.error.split("\n").slice(0, 8).join("\n"));
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
507
723
|
let wasmOk = false;
|
|
508
724
|
if (runWasm) {
|
|
509
725
|
if (wasmPipe) {
|
|
@@ -540,6 +756,22 @@ if (runWasm) {
|
|
|
540
756
|
}
|
|
541
757
|
}
|
|
542
758
|
|
|
759
|
+
let pkirOk = false;
|
|
760
|
+
if (runPKIR) {
|
|
761
|
+
if (!pkirExePath) {
|
|
762
|
+
console.log("PKIR conformance failure: executable was not compiled");
|
|
763
|
+
} else {
|
|
764
|
+
try {
|
|
765
|
+
const outputWire = await runExecutable(pkirExePath, inputWire);
|
|
766
|
+
const actual = decodeWire(outputWire).value;
|
|
767
|
+
assert.deepEqual(toPlainObject(actual), toPlainObject(expected));
|
|
768
|
+
pkirOk = true;
|
|
769
|
+
} catch (error) {
|
|
770
|
+
console.log("PKIR conformance failure:", error.message || error);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
543
775
|
const validationSummary = [];
|
|
544
776
|
if (runBaselines && kvmOk) validationSummary.push(`kVM (all ${totalOps} ops)`);
|
|
545
777
|
if (runLLVM) {
|
|
@@ -549,9 +781,21 @@ if (runLLVM) {
|
|
|
549
781
|
validationSummary.push(`LLVM ${opt} (${tc.llvmConformance === "ok" ? `all ${totalOps} ops` : tc.llvmConformance})`);
|
|
550
782
|
}
|
|
551
783
|
}
|
|
784
|
+
if (runLLVMPKIR) {
|
|
785
|
+
for (const opt of llvmOptLevels) {
|
|
786
|
+
const casesForOpt = llvmPkirCasesByOpt.get(opt);
|
|
787
|
+
const tc = casesForOpt[0];
|
|
788
|
+
validationSummary.push(
|
|
789
|
+
`LLVM-PKIR ${opt} (${tc.llvmConformance === "ok" ? `all ${totalOps} ops` : tc.llvmConformance})`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
552
793
|
if (runWasm) {
|
|
553
794
|
validationSummary.push(`Wasm (${wasmOk ? `all ${totalOps} ops` : "failed"})`);
|
|
554
795
|
}
|
|
796
|
+
if (runPKIR) {
|
|
797
|
+
validationSummary.push(`PKIR (${pkirOk ? `all ${totalOps} ops` : "failed"})`);
|
|
798
|
+
}
|
|
555
799
|
|
|
556
800
|
console.log(`Conformance validation: ${validationSummary.join(", ")} match expected values.`);
|
|
557
801
|
if (runLLVM) {
|
|
@@ -560,4 +804,11 @@ if (runLLVM) {
|
|
|
560
804
|
if (shouldStrictFail(casesForOpt)) process.exitCode = 1;
|
|
561
805
|
}
|
|
562
806
|
}
|
|
807
|
+
if (runLLVMPKIR) {
|
|
808
|
+
for (const opt of llvmOptLevels) {
|
|
809
|
+
const casesForOpt = llvmPkirCasesByOpt.get(opt);
|
|
810
|
+
if (shouldStrictFail(casesForOpt)) process.exitCode = 1;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
563
813
|
if (runWasm && !wasmOk) process.exitCode = 1;
|
|
814
|
+
if (runPKIR && !pkirOk) process.exitCode = 1;
|