-
Notifications
You must be signed in to change notification settings - Fork 1
/
llbrew.go
65 lines (53 loc) · 1.49 KB
/
llbrew.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
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"log"
"os"
"github.com/rj45/llbrew/arch"
"github.com/rj45/llbrew/compile"
)
func main() {
log.SetFlags(0)
log.SetOutput(os.Stderr)
var optz = flag.Bool("Oz", false, "Optimize for min size")
var opts = flag.Bool("Os", false, "Optimize for size")
var opt0 = flag.Bool("O0", false, "Disable all optimizations")
var opt1 = flag.Bool("O1", false, "Minimal speed optimizations")
var opt2 = flag.Bool("O2", false, "Maximal speed optimizations")
var outfile = flag.String("o", "-", "Output assembly file")
var llfile = flag.String("ll", "", "Dump optimized llvm IR to file")
var irfile = flag.String("ir", "", "Dump pre-optimized llir2asm IR to file")
var dumpssa = flag.String("dumpssa", "", "Dump ssa.html for specified function")
var binfile = flag.String("bin", "", "Output binary using customasm")
var run = flag.Bool("run", false, "Run the program using the target emulator")
var trace = flag.Bool("trace", false, "Run the program in the emulator with tracing turned on")
flag.Parse()
arch.SetArch("rj32")
c := compile.Compiler{}
c.OptSize = 1
c.OptSpeed = 1
if *opts {
c.OptSize = 1
} else if *optz {
c.OptSize = 2
}
if *opt0 {
c.OptSpeed = 0
c.OptSize = 0
} else if *opt1 {
c.OptSpeed = 1
} else if *opt2 {
c.OptSpeed = 2
}
c.DumpLL = *llfile
c.DumpIR = *irfile
c.DumpSSA = *dumpssa
c.OutFile = *outfile
c.BinFile = *binfile
c.Run = *run
c.RunTrace = *trace
err := c.Compile(flag.Args()[0])
if err != nil {
log.Fatal(err)
}
}