-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
69 lines (57 loc) · 1.03 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
package main
import (
"flag"
"fmt"
"os"
"github.com/c-bata/go-prompt"
)
const (
keyX86 = "x86"
keyX64 = "x64"
key8086 = "8086"
)
var machineMap = map[string]machine{}
type machine interface {
displayRegisters()
displayStack()
execute(string) error
}
var ma machine
func main() {
//machineName := keyX64
//machineName := keyX86
var arch = flag.String("a", "x64", "x86/x64/8086")
flag.Parse()
ma = getMachine(*arch)
if ma == nil {
fmt.Println("unsupported arch, please use x86 or x64")
os.Exit(0)
}
ma.displayRegisters()
ma.displayStack()
p := prompt.New(myExecutor, completer, prompt.OptionPrefix(*arch+">> "))
p.Run()
}
func getMachine(arch string) machine {
var ma machine
switch arch {
case keyX86:
ma = initX86()
case keyX64:
ma = initX64()
case key8086:
fallthrough
default:
fmt.Println("invalid arch type")
return nil
}
return ma
}
func myExecutor(cmd string) {
if cmd == "quit" || cmd == "exit" || cmd == "q" {
os.Exit(0)
}
ma.execute(cmd)
ma.displayRegisters()
ma.displayStack()
}