Skip to content

Commit 608b8b4

Browse files
committed
Feature(compiler): Run llc by path from llvm-config
1 parent 9ace771 commit 608b8b4

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DiagnosticHostInstance from "./diagnostic.host";
1010
import UnsupportedError from "./backend/error/unsupported.error";
1111
import {existsSync, mkdirSync, unlinkSync} from "fs";
1212
import {execFileSync} from "child_process";
13+
import {executeLLCSync} from "./utils";
1314

1415
interface CommandLineArguments {
1516
args: string[];
@@ -73,7 +74,7 @@ try {
7374

7475
const optimizationLevel = `-O${cliOptions.optimizationLevel}`;
7576

76-
execFileSync('llc', [
77+
executeLLCSync([
7778
optimizationLevel,
7879
'-filetype=obj', path.join(outputPath, 'main.bc'),
7980
'-o', path.join(outputPath, 'main.o'),

src/utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import * as child_process from "child_process";
3+
import * as path from "path";
4+
5+
let llvmBinDir: string | undefined;
6+
7+
function getLLVMBinDirectory(): string {
8+
if (!llvmBinDir) {
9+
llvmBinDir = child_process.execFileSync('llvm-config', ["--bindir"]).toString().trim();
10+
}
11+
12+
return llvmBinDir;
13+
}
14+
15+
export function executeLLCSync(options: Array<any>) {
16+
child_process.execFileSync(
17+
path.join(getLLVMBinDirectory(), 'llc'),
18+
options
19+
)
20+
}

0 commit comments

Comments
 (0)