94 lines
2.0 KiB
TypeScript
94 lines
2.0 KiB
TypeScript
import { optFlag, optMultiFlag, optSwitch, undefList } from "./common";
|
|
|
|
export interface GeneralOptions {
|
|
output?: string
|
|
|
|
sysroot?: 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"]
|
|
}
|
|
}),
|
|
...optFlag("--sysroot", options.sysroot),
|
|
]
|
|
}
|
|
|
|
interface LinkerOptions {
|
|
/**
|
|
* Directory searched for "-l"
|
|
*/
|
|
searchDirs?: string[];
|
|
|
|
/**
|
|
* -l libraries.
|
|
* Static library dependecies must be sorted in topologic order.
|
|
*/
|
|
libraries?: string[];
|
|
}
|
|
|
|
export function linkerCommand(options: LinkerOptions) {
|
|
return [
|
|
...optMultiFlag("-L", options.searchDirs),
|
|
...optMultiFlag("-l", options.libraries),
|
|
]
|
|
}
|
|
|
|
export interface PreprocessorOptions {
|
|
includeDirs?: string[];
|
|
}
|
|
|
|
export function preprocessorCommand(options: PreprocessorOptions) {
|
|
return [
|
|
...optMultiFlag("-I", options.includeDirs),
|
|
]
|
|
}
|
|
|
|
|
|
/**
|
|
* 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 [
|
|
...optMultiFlag("--func", options.func),
|
|
...optMultiFlag("--bb", options.bb),
|
|
...optFlag("-o", options.output),
|
|
...optSwitch("-S", options.asm),
|
|
...undefList(options.input, input => [input])
|
|
];
|
|
}
|