-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 981 Bytes
/
main.go
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
package main
import (
"flag"
"fmt"
"os"
)
var (
batch = flag.Bool("b", false, "batch (non-interactive) mode")
optimized = flag.Bool("opt", true, "add some optimization passes")
printTokens = flag.Bool("tok", false, "print tokens")
printAst = flag.Bool("ast", false, "print abstract syntax tree")
printLLVMIR = flag.Bool("llvm", false, "print LLVM generated code")
)
func main() {
flag.Parse()
if *optimized {
Optimize()
}
lex := Lex()
tokens := lex.Tokens()
if *printTokens {
tokens = DumpTokens(lex.Tokens())
}
// add files for the lexer to lex
go func() {
// command line filenames
for _, fn := range flag.Args() {
f, err := os.Open(fn)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
lex.Add(f)
}
// stdin
if !*batch {
lex.Add(os.Stdin)
}
lex.Done()
}()
nodes := Parse(tokens)
nodesForExec := nodes
if *printAst {
nodesForExec = DumpTree(nodes)
}
Exec(nodesForExec, *printLLVMIR)
}