148 lines
3.8 KiB
TypeScript
148 lines
3.8 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 === undefined ? [] : fn(opt)
|
|
}
|
|
|
|
const optFlag = (flag: string, opt: string | undefined) => undefList(opt, opt => [flag, opt])
|
|
|
|
/**
|
|
* Generate a switch flag, like "--rebuild", "--nobuild"
|
|
*/
|
|
const optSwitch = (flag: string, opt: boolean | undefined) => undefList(opt, opt => opt ? [flag] : [])
|
|
|
|
|
|
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]))
|
|
]
|
|
}
|
|
|
|
|
|
/**
|
|
* CLI options used for llvm-extract executable.
|
|
*/
|
|
export interface ExtractOptions {
|
|
/**
|
|
* Functions to extract.
|
|
*/
|
|
func?: string[];
|
|
|
|
/**
|
|
* Basic block specifiers.
|
|
*/
|
|
bb?: string[];
|
|
|
|
output?: string;
|
|
|
|
/**
|
|
* Input file name. If unspecified, llvm-extract reads from stdin
|
|
*/
|
|
input?: string;
|
|
|
|
asm?: boolean;
|
|
}
|
|
|
|
export function extractCommand(options: ExtractOptions): string[] {
|
|
return [
|
|
...undefList(options.func, func => func.flatMap(name => ["--func", name])),
|
|
...undefList(options.bb, bb => bb.flatMap(name => ["--bb", name])),
|
|
...optFlag("-o", options.output),
|
|
...optSwitch("-S", options.asm),
|
|
...undefList(options.input, input => [input])
|
|
];
|
|
}
|
|
|
|
|
|
}
|