spec: simplify specTemplate options, provide a lower interface
This commit is contained in:
@@ -31,10 +31,6 @@ intspeed,fpspeed:
|
|||||||
#------- Compilers ------------------------------------------------------------
|
#------- Compilers ------------------------------------------------------------
|
||||||
default:
|
default:
|
||||||
# EDIT: the directory where your compiler is installed
|
# EDIT: the directory where your compiler is installed
|
||||||
%ifndef %{gcc_dir}
|
|
||||||
#% define gcc_dir /SW/compilers/GCC/Linux/x86_64/gcc-6.3.0
|
|
||||||
% define sysroot_dir @@SYSROOT@@
|
|
||||||
%endif
|
|
||||||
LDFLAGS = @@LDFLAGS@@
|
LDFLAGS = @@LDFLAGS@@
|
||||||
|
|
||||||
LIBS = @@LIBS@@
|
LIBS = @@LIBS@@
|
||||||
|
|||||||
@@ -60,62 +60,26 @@ export function mkBench(spec: SPEC, bench: SPECBenchData): Bench {
|
|||||||
const writeFile = promisify(fs.writeFile);
|
const writeFile = promisify(fs.writeFile);
|
||||||
|
|
||||||
export interface ConfigOptions {
|
export interface ConfigOptions {
|
||||||
prefix: string;
|
|
||||||
optimize: string[];
|
optimize: string[];
|
||||||
ldflags: string[];
|
ldflags: string[];
|
||||||
sysroot: string;
|
libs: string[];
|
||||||
compiler: "llvm" | "gcc";
|
compilerPaths: {
|
||||||
|
CXX: string,
|
||||||
|
CC: string,
|
||||||
|
FC: string,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
// Pure function to render configuration
|
||||||
export const renderConfig = (options: ConfigOptions): string => {
|
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` +
|
return `# Rendered from TypeScript ${new Date().toLocaleString()}, do not edit!\n\n\n` +
|
||||||
specTemplate
|
specTemplate
|
||||||
.replace("@@OPTIMIZE@@", options.optimize.join(" "))
|
.replace("@@OPTIMIZE@@", options.optimize.join(" "))
|
||||||
.replace("@@LDFLAGS@@", options.ldflags.join(" "))
|
.replace("@@LDFLAGS@@", options.ldflags.join(" "))
|
||||||
.replace("@@SYSROOT@@", options.sysroot)
|
.replace("@@CompilerCC@@", options.compilerPaths.CC)
|
||||||
.replace("@@CompilerCC@@", compilerPaths.CC)
|
.replace("@@CompilerCXX@@", options.compilerPaths.CXX)
|
||||||
.replace("@@CompilerCXX@@", compilerPaths.CXX)
|
.replace("@@CompilerFC@@", options.compilerPaths.FC)
|
||||||
.replace("@@CompilerFC@@", compilerPaths.FC)
|
.replace("@@LIBS@@", options.libs.join(" "))
|
||||||
.replace("@@LIBS@@", libs.join(" "))
|
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,26 @@ export function gccToolchain(prefix: string) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ToolchainSuite = "llvm" | "gcc";
|
||||||
|
|
||||||
|
export function toolchain(prefix: string, suite: ToolchainSuite) {
|
||||||
|
if (suite === "llvm") {
|
||||||
|
return llvmToolchain(prefix);
|
||||||
|
} else if (suite === "gcc") {
|
||||||
|
return gccToolchain(prefix);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Invalid toolchain suite: "${suite}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cflangLibs(prefix: string) {
|
||||||
|
return [
|
||||||
|
"pgmath",
|
||||||
|
"flang",
|
||||||
|
"flangrti",
|
||||||
|
].map(lib => path.resolve(prefix, "lib", `lib${lib}.a`)).concat(["-lompstub"]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Give an LLVM toolchain, and a desired IR, a list of function names.
|
* Give an LLVM toolchain, and a desired IR, a list of function names.
|
||||||
* Generate a function that takes vFnPath and sFnPath, used for path calculation.
|
* Generate a function that takes vFnPath and sFnPath, used for path calculation.
|
||||||
|
|||||||
Reference in New Issue
Block a user