-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 943 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
package main
import (
"flag"
"fmt"
"github.com/dnsge/orange/asm"
"os"
)
var (
executableFlag = flag.Bool("executable", false, "Compile to executable")
)
func main() {
flag.Parse()
args := flag.Args()
if len(args) != 2 {
_, _ = fmt.Fprintf(os.Stderr, "usage: %s [input file] [output file]\n", os.Args[0])
os.Exit(1)
return
}
inputFile, err := os.Open(args[0])
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed to open input file: %v\n", err)
os.Exit(1)
return
}
defer inputFile.Close()
outputFile, err := os.Create(args[1])
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed to open output file: %v\n", err)
os.Exit(1)
return
}
defer outputFile.Close()
if *executableFlag {
err = asm.AssembleExecutable(inputFile, outputFile)
} else {
err = asm.AssembleObjectFile(inputFile, outputFile)
}
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
return
}
}