commands: create a dedicated commands directory
This commit is contained in:
70
commands/compiler.ts
Normal file
70
commands/compiler.ts
Normal 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])
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user