treewide: refactor some constants to environment.ts
This commit is contained in:
95
commands.ts
95
commands.ts
@@ -20,16 +20,87 @@ export function systemdRun(unit: string, workingDirectory: string = process.cwd(
|
||||
];
|
||||
}
|
||||
|
||||
export function runcpu(workload: string = 'test'): string[] {
|
||||
return [
|
||||
"runcpu",
|
||||
"-c",
|
||||
"clang-O2",
|
||||
"-i",
|
||||
workload,
|
||||
"pop2_s",
|
||||
"--action",
|
||||
"run",
|
||||
"--nobuild",
|
||||
];
|
||||
function undefList<T, U>(opt: T | undefined, fn: (opt: T) => U) {
|
||||
return opt ? fn(opt) : []
|
||||
}
|
||||
|
||||
const optFlag = (flag: string, opt: string | undefined) => undefList(opt, opt => [flag, opt])
|
||||
|
||||
export module SPECCommands {
|
||||
|
||||
interface SPECOptions {
|
||||
/**
|
||||
* Config file, used for compiling flags, compiler versions, etc.
|
||||
*/
|
||||
config?: string
|
||||
|
||||
/**
|
||||
* SPEC workload scale for each benchmark
|
||||
*/
|
||||
workload?: "test" | "train" | "ref"
|
||||
|
||||
/**
|
||||
* Selected benchmarks
|
||||
*/
|
||||
benchmarks?: string[]
|
||||
|
||||
buildType?: "nobuild" | "rebuild" | "plain",
|
||||
}
|
||||
|
||||
export function runcpuOptions(o: SPECOptions): string[] {
|
||||
return [
|
||||
...optFlag("-c", o.config),
|
||||
...optFlag("-i", o.workload),
|
||||
...undefList(o.buildType, opt => {
|
||||
switch (opt) {
|
||||
case "nobuild":
|
||||
return ["--nobuild"]
|
||||
case "rebuild":
|
||||
return ["--rebuild"]
|
||||
case "plain":
|
||||
return []
|
||||
}
|
||||
}),
|
||||
...undefList(o.benchmarks, bench => bench)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export module CompilerCommands {
|
||||
|
||||
export interface GeneralOptions {
|
||||
output?: string;
|
||||
|
||||
outputKind?: "exe" | "object" | "assembly" | "preprocessed"
|
||||
}
|
||||
|
||||
export function generalCommand(options: GeneralOptions) {
|
||||
return [
|
||||
...optFlag("-o", options.output),
|
||||
...undefList(options.outputKind, (opt) => {
|
||||
switch (opt) {
|
||||
case "object":
|
||||
return ["-c"]
|
||||
case "exe":
|
||||
return []
|
||||
case "assembly":
|
||||
return ["-S"]
|
||||
case "preprocessed":
|
||||
return ["-E"]
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
export interface PreprocessorOptions {
|
||||
includeDirs?: string[];
|
||||
}
|
||||
|
||||
export function preprocessorCommand(options: PreprocessorOptions) {
|
||||
return [
|
||||
...undefList(options.includeDirs, dirs => dirs.flatMap(name => ["-I", name]))
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
48
compiler.ts
48
compiler.ts
@@ -2,21 +2,8 @@ import child_process from "child_process"
|
||||
import { PlatformPath } from "path"
|
||||
import path from "path"
|
||||
|
||||
const PREFIX = "/home/lyc/workspace/sw-autovec/swllvm-13.0.0-vect0919/local/installed/85e4fed0c9e4cd4ab8bce89f307127ccbad31294"
|
||||
const PREFIXBIN = path.join(PREFIX, "bin")
|
||||
const LLVM_EXTRACT = path.join(PREFIXBIN, "llvm-extract")
|
||||
|
||||
const SYSROOT_PREFIX = "/usr/sw/standard-830-6b-test"
|
||||
|
||||
const CXX = path.join(PREFIXBIN, "clang++")
|
||||
const CC = path.join(PREFIXBIN, "clang")
|
||||
const FC = path.join(PREFIXBIN, "flang")
|
||||
|
||||
const SYSROOT_COMMAND = [
|
||||
"--sysroot",
|
||||
SYSROOT_PREFIX,
|
||||
]
|
||||
|
||||
// FIXME: these imports basically looks ugly.
|
||||
import { LLVM_EXTRACT, PREFIX, SYSROOT_PREFIX, FLANG } from "./environment";
|
||||
|
||||
|
||||
/**
|
||||
@@ -93,35 +80,6 @@ export async function extract(options: ExtractOptions) {
|
||||
return exitcode
|
||||
}
|
||||
|
||||
export interface GeneralOptions {
|
||||
output?: string;
|
||||
|
||||
outputKind?: "exe" | "object" | "assembly" | "preprocessed"
|
||||
}
|
||||
|
||||
export function generalCommand(options: GeneralOptions) {
|
||||
return [
|
||||
...(options.output ? ["-o", options.output] : []),
|
||||
...(options.outputKind ? {
|
||||
exe: [],
|
||||
object: ["-c"],
|
||||
assembly: ["-S"],
|
||||
preprocessed: ["-E"]
|
||||
}[options.outputKind] : [])
|
||||
]
|
||||
}
|
||||
|
||||
export interface PreprocessorOptions {
|
||||
includeDirs?: string[];
|
||||
}
|
||||
|
||||
export function preprocessorCommand(options: PreprocessorOptions) {
|
||||
return [
|
||||
...((options.includeDirs ?? []).flatMap(name => ["-I", name]))
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Links objects into an executable using specified environment variables and paths.
|
||||
@@ -140,7 +98,7 @@ export async function link(objects: string[], exe: string) {
|
||||
|
||||
// Construct link command
|
||||
const linkcmd = [
|
||||
FC,
|
||||
FLANG,
|
||||
...objects,
|
||||
"-L", path.join(PREFIX, 'lib'),
|
||||
// TODO: Implement rpath logic here if needed
|
||||
|
||||
22
environment.ts
Normal file
22
environment.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import path from "path"
|
||||
|
||||
export const HOME = path.join("/home", "lyc")
|
||||
|
||||
export const SW_AUTOVEC = path.join(HOME, "workspace", "sw-autovec")
|
||||
|
||||
export const LLVM_SRC = path.join(SW_AUTOVEC, "swllvm-13.0.0-vect0919")
|
||||
export const LLVM_INSTALL = path.join(LLVM_SRC, "local", "installed")
|
||||
|
||||
/// Default toolchain version used in SPEC2017
|
||||
export const PREFIX = path.join(LLVM_SRC, "85e4fed0c9e4cd4ab8bce89f307127ccbad31294")
|
||||
export const PREFIXBIN = path.join(PREFIX, "bin")
|
||||
export const LLVM_EXTRACT = path.join(PREFIXBIN, "llvm-extract")
|
||||
|
||||
|
||||
export const SPEC = path.join(SW_AUTOVEC, "spec2017")
|
||||
|
||||
export const CXX = path.join(PREFIXBIN, "clang++")
|
||||
export const CC = path.join(PREFIXBIN, "clang")
|
||||
export const FLANG = path.join(PREFIXBIN, "flang")
|
||||
|
||||
export const SYSROOT_PREFIX = "/usr/sw/standard-830-6b-test"
|
||||
Reference in New Issue
Block a user