Skip to content

Commit 91a175f

Browse files
committed
Feature: Working on CLI options
1 parent 20464c9 commit 91a175f

4 files changed

Lines changed: 46 additions & 26 deletions

File tree

package-lock.json

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
"ssc": "./bin/ssc"
2020
},
2121
"devDependencies": {
22-
"@types/node": "10.12.2"
22+
"@types/node": "10.12.2",
23+
"commander": "^2.19.0"
2324
},
2425
"dependencies": {
25-
"typescript": "^3.1.1",
26-
"llvm-node": "github:MichaReiser/llvm-node#master"
26+
"llvm-node": "github:MichaReiser/llvm-node#master",
27+
"typescript": "^3.1.1"
2728
}
2829
}

packages/hello-world/package-lock.json

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@
22
import * as ts from 'typescript';
33
import * as path from 'path';
44
import * as llvm from 'llvm-node';
5+
import * as cli from "commander";
56

67
import {initializeLLVM, generateModuleFromProgram} from './backend/llvm';
78

9+
interface CommandLineArguments {
10+
args: string[];
11+
printIR?: boolean;
12+
}
13+
14+
function parseCommandLine(): CommandLineArguments {
15+
cli
16+
.version('next')
17+
.option('-ir, --printIR', 'Print IR')
18+
.parse(process.argv);
19+
20+
return cli as any as CommandLineArguments;
21+
}
22+
23+
const compilerOptions = parseCommandLine();
24+
825
const options = {
926
lib: [
1027
path.join(__dirname, '..', 'packages', 'runtime', 'lib.runtime.d.ts'),
@@ -44,4 +61,6 @@ const llvmModule = generateModuleFromProgram(program);
4461

4562
llvm.verifyModule(llvmModule);
4663

47-
console.log(llvmModule.print());
64+
if (compilerOptions.printIR) {
65+
console.log(llvmModule.print());
66+
}

0 commit comments

Comments
 (0)