From 8094248810c235772507f66e94809f02f3c6944e Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Tue, 18 Jun 2024 02:02:20 +0800 Subject: [PATCH] spec: use SPEC interface --- spec.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spec.ts b/spec.ts index 3852a8e..e674343 100644 --- a/spec.ts +++ b/spec.ts @@ -1,4 +1,7 @@ import * as path from 'path'; +import * as fs from "fs"; +import { promisify } from "util"; +import { SW_AUTOVEC } from "./environment"; export interface SPECBench { objectNames: string[]; @@ -356,3 +359,40 @@ export function setenv(specdir: string): void { process.env.SPEC = specdir; process.env.PATH = `${path.join(specdir, 'bin')}${path.delimiter}${process.env.PATH}`; } + +export interface SPEC { + newConfig: (name: string, content: string) => Promise; + benchpath: (bench: SPECBench) => string; + exepath: (bench: SPECBench) => string; + buildpath: (bench: SPECBench) => string; + setenv: () => void; +} + +export function mkSPEC(specRoot: string): SPEC { + return { + newConfig: async (name: string, content: string) => { + await writeFile(path.join(specRoot, "config", name), content); + }, + benchpath: bench => benchpath(specRoot, bench), + exepath: bench => exepath(specRoot, bench), + buildpath: bench => buildpath(specRoot, bench), + setenv: () => setenv(specRoot), + }; +} + +export const defaultSPEC = mkSPEC(path.join(SW_AUTOVEC, "spec2017")); + +const specTemplate = fs.readFileSync("assets/specTemplate.cfg").toString("utf-8"); + +const writeFile = promisify(fs.writeFile); + +interface ConfigOptions { + gccdir: string; + optimize: string; +} + +export function renderConfig(options: ConfigOptions) { + return `# Rendered from TypeScript, do not edit!\n\n\n` + specTemplate + .replace("@@GCCDIR@@", options.gccdir) + .replace("@@OPTIMIZE@@", options.optimize); +}