-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
executable file
·96 lines (94 loc) · 3.22 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/env node
import { writeFileSync } from 'fs';
import yargs from 'yargs/yargs';
import runShell from './tools/shell.js';
import compileFile from './tools/file.js';
yargs(process.argv.slice(2))
.parserConfiguration({
'boolean-negation': false,
})
.scriptName('phc')
.usage('$0 <command> [args]')
.option('verbose', {
describe: 'include verbose output',
type: 'boolean',
default: false,
alias: 'v',
})
.command(['shell [options]', '*'], 'run interactive shell',
yargs =>
yargs.options({
'lex': {
describe: 'debug lexer tokens',
type: 'boolean',
default: false,
alias: 'l' },
}),
argv =>
runShell(argv.lex, argv.verbose))
.command('file <name> [options]', 'compile a file to WAT',
yargs => yargs
.positional('name', {
describe: 'name of the file to open',
type: 'string',
})
.options({
'track-time': {
describe: 'track time spent compiling',
type: 'boolean',
default: true,
alias: 't',
},
'fast' : {
describe: 'skip validation and pretty-print steps',
type: 'boolean',
},
'folding' : {
describe: 'use folding/s-expr WAT syntax',
type: 'boolean',
},
'optimize' : {
describe: '1 to use additional internal optimizations, 2 to use binaryen optimizer',
type: 'number',
alias: 'O',
default: 0,
},
'stack-size' : {
describe: '(advanced) 64bit aligned size in bytes of the references stack section of LM for the runtime',
type: 'number',
default: 1024000,
},
'nursery-size' : {
describe: '(advanced) 64bit aligned size in bytes of the nusery section of LM for the runtime',
type: 'number',
default: 524288,
},
'output' : {
describe: 'output to a specific file instead of stdout',
type: 'string',
alias: 'o',
},
'no-rt' : {
describe: '(advanced) do not include boilerplate code which might be required for program to run',
type: 'boolean',
},
}),
async argv => {
const ret = await compileFile(
argv.name,
argv['track-time'],
argv.fast,
argv.folding,
argv.optimize,
argv['stack-size'],
argv['nursery-size'],
argv['no-rt'],
);
if (!argv['output'])
return console.log(ret);
if (ret)
writeFileSync(argv['output'], ret);
},
)
// .help()
.argv;