-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (34 loc) · 821 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
package main
import (
"assembler/cmd"
"fmt"
"log"
"os"
"strings"
)
func main() {
if len(os.Args) == 1 {
panic("you must provide a .asm file")
}
asmFile := os.Args[1]
bx, err := os.ReadFile(asmFile)
if err != nil {
panic("error while reading the input file, " + err.Error() + "\n")
}
out, err := os.Create(strings.TrimSuffix(asmFile, ".asm") + ".hack")
if err != nil {
panic("error while creating the output file, " + err.Error() + "\n")
}
fmt.Println(string(bx))
/*
lexer needs a newline at the very end of the input.
so i am appending it at the end.
i don't want to fix it.
this is not a bug. this is a feature. i think...
*/
n, err := cmd.Assemble(string(bx)+"\n", out)
if err != nil {
panic("an error occured, " + err.Error() + "\n")
}
log.Printf("[✓] Wrote %d bytes\n", n)
}