-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (66 loc) · 1.59 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
// TODO
// Don't immediately create the output file
// Handle errors
// Count lines and columns for errors
// Validate function names
import (
"bytes"
"flag"
)
var loop_number int
var global_funcs []string
var func_contents []*bytes.Buffer
var target string
var address_reg string
func check(e error) {
if e != nil {
panic(e)
}
}
func nTrue(b ...bool) int {
n := 0
for _, v := range b {
if v {
n++
}
}
return n
}
func main() {
var size int
var output string
var raw, flat, functional bool
flag.IntVar(&size, "buffer_size", 8192, "size of the buffer in a pure Brainfuck program")
flag.StringVar(&target, "target", "elf32", "build target type")
flag.StringVar(&output, "o", "out.asm", "output file")
flag.BoolVar(&raw, "raw", false, "these files are a whole raw program")
flag.BoolVar(&flat, "flat", false, "these files are functions named by the file name")
flag.BoolVar(&functional, "functional", false, "these files have functions")
flag.Parse()
files := flag.Args()
if len(files) == 0 {
println("You need to specify one or more files to compile.")
}
if nTrue(raw, flat, functional) > 1 {
println("Arguments 'raw', 'flat', and 'functional' are mutually exclusive.")
return
}
var parse_mode int = 2
if raw {
parse_mode = 0
} else if flat {
parse_mode = 1
} else if functional {
parse_mode = 2
}
if target == "elf32" {
address_reg = "edi"
build_linux(size, 32, files, output, nil, parse_mode)
} else if target == "elf64" {
address_reg = "rdi"
build_linux(size, 64, files, output, nil, parse_mode)
} else {
println("Handle invalid target")
}
}