Files
scriptc/packages/compiler/test/llvm-lib-dispatch.test.ts
Chris Tate 7b007e03ef feat(compiler): bootstrap the LLVM emitter natively
- Run the production LLVM backend natively and reproduce its output across compiler generations.
- Replace unchecked emitter contexts with explicit shared state and callback hosts.
- Preserve NaN in serialized IR and respect optional record storage during spreads.
2026-09-27 22:29:24 -05:00

59 lines
1.8 KiB
TypeScript

import { expect, test } from "vitest";
import { emitLlvmModule } from "../src/backend/llvm/emitter.js";
import {
DYN,
NETSOCKET_T,
STRING,
VOID,
type IrExpr,
type IrLibFn,
type IrModule,
type IrType,
} from "../src/ir/ir.js";
import { validateModule } from "../src/ir/validate.js";
const loc = { file: "llvm-lib-dispatch.ts", start: 0, end: 0 };
const str = (value: string): IrExpr => ({ kind: "strLit", value, type: STRING, loc });
const dyn = (): IrExpr => ({ kind: "dynFrom", value: str("value"), type: DYN, loc });
function libCallModule(fn: IrLibFn, args: IrExpr[], type: IrType): IrModule {
return {
irVersion: 13,
sourceFile: loc.file,
entry: "__main",
functions: [{
name: "__main",
params: [],
returnType: VOID,
locals: [],
body: [{
kind: "exprStmt",
expr: { kind: "libCall", fn, args, type, loc },
loc,
}],
loc,
}],
};
}
test.each([
["fs.mkdtempChk", "scr_fs_mkdtemp_chk", 2],
["fs.readFileChk", "scr_fs_read_file_chk", 3],
["fs.opendirChk", "scr_fs_opendir_chk", 2],
["fs.watchFileChk", "scr_fs_watch_file_chk", 2],
["fs.lchmodChk", "scr_fs_lchmod_chk", 3],
["fs.readChk", "scr_fs_read_chk", 5],
["fs.streamOptsChk", "scr_fs_stream_opts_chk", 2],
] as const)("LLVM routes %s through filesystem validation emission", (fn, sym, dynArgs) => {
const mod = libCallModule(fn, [...Array.from({ length: dynArgs }, dyn), str("fence")], VOID);
expect(validateModule(mod)).toEqual([]);
expect(emitLlvmModule(mod)).toContain(`call void @${sym}(`);
});
test("LLVM routes net.connectOptsChk through network validation emission", () => {
const mod = libCallModule("net.connectOptsChk", [dyn(), str("fence")], NETSOCKET_T);
expect(validateModule(mod)).toEqual([]);
expect(emitLlvmModule(mod)).toContain("call void @scr_net_connect_opts_chk(");
});