-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (38 loc) · 877 Bytes
/
main.go
File metadata and controls
46 lines (38 loc) · 877 Bytes
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
package main
import (
"fmt"
"log"
"os"
"github.com/hum/lc3-vm/vm"
)
func main() {
// TODO:
// Add all of the logs into a debug mode instead
log.Println("starting LC-3 VM")
// Check input
args := os.Args[1:]
if len(args) == 0 {
fmt.Println("No file input specified. Quitting.")
os.Exit(0)
}
var filename string = args[0]
log.Printf("loading \"%s\" file into the memory", filename)
// Load image into the buffer
data, n, err := ReadObjFile(filename)
if err != nil || n <= 0 {
if err != nil {
panic(err)
}
// TODO:
// Better handling of the input in general
panic("read file has 0 size")
}
// Load the byte slice into the VM
vm.LoadByteSliceBuffer(data, n)
log.Printf("loaded %d bytes buffer into the memory", n)
if err := vm.Execute(); err != nil {
// Gracefully shutdown the vm
fmt.Errorf("vm error: %s", err)
os.Exit(0)
}
}