-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
85 lines (68 loc) · 2.21 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
77
78
79
80
81
82
83
84
85
package main
import (
"flag"
"fmt"
"github.com/marlls1989/arv/memory"
"github.com/marlls1989/arv/processor"
"gopkg.in/yaml.v2"
"log"
"os"
"runtime"
"sync/atomic"
)
func main() {
sizePtr := flag.Int64("memsize", -1, "Truncate memory file to `size` in kbytes")
nProcs := flag.Int("jobs", runtime.NumCPU(), "Number of concurent execution `threads`")
memfile := flag.String("memfile", "", "Memory dump `file name` containing the binary file name")
memdebug := flag.Bool("memdebug", false, "Logs memory writes to stderr")
coreedebug := flag.Bool("coredebug", false, "Logs instructions flow to stderr")
statsfile := flag.String("statsfile", "stats.yaml", "Record execution statistics to file")
flag.Parse()
// Initialize the runtime for best using the available cores
runtime.GOMAXPROCS(*nProcs)
if *memfile == "" {
fmt.Fprintln(os.Stderr, "Required parameter -memfile not defined")
os.Exit(-1)
}
file, err := os.OpenFile(*memfile, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
log.Print("Memdump file opened")
defer file.Close()
if *sizePtr >= 0 {
file.Truncate((*sizePtr) * 1024)
log.Printf("Memdump file truncated to %dkb", *sizePtr)
}
mem, err := memory.MemoryArrayFromFile(file)
mem.Debug = *memdebug
if err != nil {
log.Fatal(err)
}
log.Print("Memory model created from file")
proc := processor.ConstructProcessor(mem)
log.Print("Processor model instantiated")
proc.Debug = *coreedebug
proc.Start()
log.Print("Simulation started")
<-mem.EndSimulation
proc.Stop()
log.Print("Finishing Simulation")
file, err = os.OpenFile(*statsfile, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Printf("Could not open statsfile %s, %v", *statsfile, err)
} else {
defer file.Close()
stats, err := yaml.Marshal(&proc.Stats)
if err == nil {
file.Write(stats)
log.Printf("Execution statistics written to file %s", *statsfile)
}
}
if err != nil {
log.Printf("Decoded: %v instructions", atomic.LoadUint64(&proc.Stats.Decoded))
log.Printf("Inserted: %v bubbles", atomic.LoadUint64(&proc.Stats.Bubbles))
log.Printf("Retired: %v instructions", atomic.LoadUint64(&proc.Stats.Retired))
log.Printf("Cancelled: %v instructions", atomic.LoadUint64(&proc.Stats.Cancelled))
}
}