spec: allow using gcc for SPEC compiler

This commit is contained in:
2025-04-17 15:56:36 +08:00
parent 621ae0e7fb
commit 64bcd0915e
3 changed files with 91 additions and 26 deletions

View File

@@ -4,9 +4,9 @@ import { promisify } from "util";
import { ChildProcessByStdio } from 'child_process';
import { Readable, Writable } from 'stream';
import { createInterface } from 'readline';
import { projectRoot } from '../environment/index.js';
import { SPECBenchData, benchpath, exepath, buildpath } from './benchData.js';
import specTemplate from '../../assets/specTemplate.cfg';
import assert from 'assert';
@@ -60,20 +60,64 @@ export function mkBench(spec: SPEC, bench: SPECBenchData): Bench {
const writeFile = promisify(fs.writeFile);
export interface ConfigOptions {
gccdir: string;
prefix: string;
optimize: string[];
ldflags: string[];
sysroot: string;
compiler: "llvm" | "gcc";
}
export function renderConfig(options: ConfigOptions) {
return `# Rendered from TypeScript ${new Date().toLocaleString()}, do not edit!\n\n\n` + specTemplate
.replace("@@GCCDIR@@", options.gccdir)
.replace("@@OPTIMIZE@@", options.optimize.join(' '))
.replace("@@LDFLAGS@@", options.ldflags.join(' '))
.replace("@@SYSROOT@@", options.sysroot);
}
// Pure function to get compiler names based on the compiler type
const getCompilerNames = (compiler: ConfigOptions["compiler"]) =>
({
llvm: { CXX: "clang++", CC: "clang", FC: "flang" },
gcc: { CXX: "g++", CC: "gcc", FC: "gfortran" },
}[compiler]);
// Pure function to get compiler directory structure
const getCompilerDir = (compiler: ConfigOptions["compiler"]) =>
compiler === "llvm" ? ["bin"] : ["usr", "bin"];
// Helper function to resolve paths for compilers
const resolveCompilerPaths = (
prefix: string,
compiler: ConfigOptions["compiler"],
compilerNames: ReturnType<typeof getCompilerNames>
) => ({
CC: path.resolve(prefix, ...getCompilerDir(compiler), compilerNames.CC),
CXX: path.resolve(prefix, ...getCompilerDir(compiler), compilerNames.CXX),
FC: path.resolve(prefix, ...getCompilerDir(compiler), compilerNames.FC),
});
// Helper function to generate library paths for LLVM
const getLlvmLibs = (prefix: string) =>
[
"pgmath",
"flangrti",
"flang",
].map(lib => path.resolve(prefix, "lib", `lib${lib}.a`)).concat(["-lompstub"]);
// Pure function to render configuration
export const renderConfig = (options: ConfigOptions): string => {
const compilerNames = getCompilerNames(options.compiler);
const compilerPaths = resolveCompilerPaths(options.prefix, options.compiler, compilerNames);
const libs =
options.compiler === "llvm"
? getLlvmLibs(options.prefix)
: [];
return `# Rendered from TypeScript ${new Date().toLocaleString()}, do not edit!\n\n\n` +
specTemplate
.replace("@@OPTIMIZE@@", options.optimize.join(" "))
.replace("@@LDFLAGS@@", options.ldflags.join(" "))
.replace("@@SYSROOT@@", options.sysroot)
.replace("@@CompilerCC@@", compilerPaths.CC)
.replace("@@CompilerCXX@@", compilerPaths.CXX)
.replace("@@CompilerFC@@", compilerPaths.FC)
.replace("@@LIBS@@", libs.join(" "))
;
};
export interface SPECResult {
outputFiles: { [key: string]: string[], };