commands: move compiler.extractCommand -> commands.ts
This commit is contained in:
43
commands.ts
43
commands.ts
@@ -21,11 +21,17 @@ export function systemdRun(unit: string, workingDirectory: string = process.cwd(
|
||||
}
|
||||
|
||||
function undefList<T, U>(opt: T | undefined, fn: (opt: T) => U) {
|
||||
return opt ? fn(opt) : []
|
||||
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 {
|
||||
@@ -103,4 +109,39 @@ export module CompilerCommands {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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])
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
40
compiler.ts
40
compiler.ts
@@ -4,6 +4,7 @@ import path from "path"
|
||||
|
||||
// FIXME: these imports basically looks ugly.
|
||||
import { LLVM_EXTRACT, PREFIX, SYSROOT_PREFIX, FLANG } from "./environment";
|
||||
import { CompilerCommands } from "./commands";
|
||||
|
||||
|
||||
/**
|
||||
@@ -32,48 +33,13 @@ export function functionList(module: string) {
|
||||
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
|
||||
*/
|
||||
export async function extract(options: ExtractOptions) {
|
||||
export async function extract(options: CompilerCommands.ExtractOptions) {
|
||||
let process = child_process.spawn(
|
||||
LLVM_EXTRACT,
|
||||
extractCommand(options),
|
||||
CompilerCommands.extractCommand(options),
|
||||
{ stdio: "inherit" }
|
||||
)
|
||||
const exitcode = await new Promise((resolve, reject) => { process.on('close', resolve) })
|
||||
|
||||
Reference in New Issue
Block a user