-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (52 loc) · 1.47 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
package main
import (
"flag"
"fmt"
"log"
"github.com/cmanny/aarch/architecture"
"github.com/cmanny/aarch/architecture/comp"
"github.com/cmanny/aarch/architecture/ins"
"github.com/cmanny/aarch/web"
)
/**
In the main function we create the highest level parts of the system and
connect them together. The assembler may be used to compile the written
programs into bytecode which may then be placed into the memory component.
Then, the processor can be run from an arbitrary chosen instruction pointer.
The web frontend may also be enabled allowing the state of all components and
channels to be automatically visualised by JS library.
**/
func main() {
fileNamePtr := flag.String("prog", "fib.gp", "file to assemble and run")
runWebPtr := flag.Bool("web", true, "bool to run web front end")
flag.Parse()
/* Init top level components */
cycle := make(chan int, 0)
/* Architectural components */
is := &ins.InstructionSet{}
is.Init()
mem := &comp.Memory{}
mem.Init()
p := &architecture.Processor{}
p.Init(is, mem, cycle)
as := &ins.Assembler{}
as.Init(is)
/* Visualisation components */
serv := &server.Server{}
serv.Init("8080", cycle)
/* Begin */
bytes, err := as.AssembleFile(*fileNamePtr)
fmt.Println(bytes)
if err != nil {
log.Fatal(err)
}
/* Fill memory with compilde bytes */
mem.Fill(bytes, 0)
p.SetIP(0)
p.Debug(true)
p.Run()
if *runWebPtr {
fmt.Println("Runnin' web")
serv.Run()
}
}