Files
work-ts/commands.ts

107 lines
2.7 KiB
TypeScript

/**
* Command CLI generation
*/
/**
* Constructs a systemd-run command array.
* @param unit The systemd unit to run.
* @param workingDirectory The working directory for the systemd-run command.
* Defaults to the current working directory.
* @returns An array representing the systemd-run command.
*/
export function systemdRun(unit: string, workingDirectory: string = process.cwd()): string[] {
return [
'systemd-run',
'--user',
`--working-directory=${workingDirectory}`,
'--unit',
unit
];
}
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]))
]
}
}