compiler: add llvm-extract options
This commit is contained in:
47
compiler.ts
47
compiler.ts
@@ -45,20 +45,49 @@ export function functionList(module: string) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 [
|
||||||
|
...(options.func ?? []).flatMap(name => ["--func", name]),
|
||||||
|
...(options.bb ?? []).flatMap(name => ["--bb", name]),
|
||||||
|
...(options.output ? ["-o", options.output] : []),
|
||||||
|
...(options.asm ? ["-S"] : []),
|
||||||
|
...(options.input ? [options.input] : [])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract one function using llvm-extract
|
* Extract one function using llvm-extract
|
||||||
*/
|
*/
|
||||||
export async function extract(name: string, module: string, out: (a: string) => string) {
|
export async function extract(options: ExtractOptions) {
|
||||||
let process = child_process.spawn(
|
let process = child_process.spawn(
|
||||||
LLVM_EXTRACT, [
|
LLVM_EXTRACT,
|
||||||
"--func",
|
extractCommand(options),
|
||||||
name,
|
{ stdio: "inherit" }
|
||||||
"-S",
|
|
||||||
"-o",
|
|
||||||
out(name),
|
|
||||||
module
|
|
||||||
], { stdio: "inherit" }
|
|
||||||
)
|
)
|
||||||
const exitcode = await new Promise((resolve, reject) => { process.on('close', resolve) })
|
const exitcode = await new Promise((resolve, reject) => { process.on('close', resolve) })
|
||||||
return exitcode
|
return exitcode
|
||||||
|
|||||||
Reference in New Issue
Block a user