commands: create a dedicated commands directory

This commit is contained in:
2024-06-17 15:22:36 +08:00
parent fb6a75cb27
commit ca6dafa5f9
6 changed files with 248 additions and 151 deletions

70
commands/compiler.ts Normal file
View File

@@ -0,0 +1,70 @@
import { optFlag, optSwitch, undefList } from "./common";
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])
];
}