Files
scriptc/tests/fixtures/self-hosting/serialize.ts
Chris Tate eb7be34d9a perf: reduce compiler work and reuse CI native builds
- Reduce frontend, runtime, and linking overhead for native builds.
- Add compact compiler artifacts and reproducible build timing benchmarks.
- Reuse native CI packages and consolidate self-hosting validation.
2026-09-30 11:08:13 -05:00

25 lines
1003 B
TypeScript

import { readFileSync } from "node:fs";
import { deserializeModule, serializeModule } from "../../../packages/compiler/src/ir/serialize.js";
import { validateModule } from "../../../packages/compiler/src/ir/validate.js";
try {
const mod = deserializeModule(readFileSync(process.argv[2]!, "utf8"));
const errors = validateModule(mod);
if (errors.length > 0) {
console.log(JSON.stringify(errors));
process.exitCode = 1;
} else {
// Introduce a native NaN before serialization, independently of the
// input document's sentinel decoding.
if (process.argv[3] === "nan") {
const statement = mod.functions[0]!.body[0];
if (statement?.kind === "exprStmt" && statement.expr.kind === "numLit") statement.expr.value = NaN;
}
console.log(serializeModule(mod, process.argv[3] === "compact"));
}
} catch (error) {
if (error instanceof Error) console.log(error.name + ": " + error.message);
else console.log("unexpected thrown value");
process.exitCode = 1;
}