-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
196 lines (162 loc) · 3.49 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package main
import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"github.com/fatih/color"
"github.com/go-p5/p5"
)
var (
path = ""
log_stats = true
vsim_writer io.WriteCloser
examine_in_process = false
var_to_examine = ""
current_entity = ""
total_vars = 0
)
var vhdl_vars []VHDL_VAR
type VHDL_VAR struct {
name string
value string
entity string
}
func printSig(col color.Attribute, sig, val string) {
color.Set(col)
fmt.Println(sig + " | " + val)
color.Unset()
}
func truthTable() {
fmt.Println("VLENGTH: ", len(vhdl_vars))
for i := 0; i < len(vhdl_vars); i++ {
switch vhdl_vars[i].value {
case "0":
printSig(color.FgRed, vhdl_vars[i].name, vhdl_vars[i].value)
break
case "1":
printSig(color.FgGreen, vhdl_vars[i].name, vhdl_vars[i].value)
break
default:
printSig(color.FgYellow, vhdl_vars[i].name, vhdl_vars[i].value)
break
}
}
}
func check(err error, where string) {
if err != nil {
color.Red("Something went wrong at ", where)
panic("Program stopping!")
}
}
func examine(arch string, v string) {
io.WriteString(vsim_writer, "examine /"+arch+"/"+v+"\n")
}
func examineAll() {
for i := 0; i < len(vhdl_vars); i++ {
examine(vhdl_vars[i].entity, vhdl_vars[i].name)
}
}
func ReadOutput(output chan string, rc io.ReadCloser) {
r := bufio.NewReader(rc)
for {
x, _ := r.ReadString('\n')
output <- string(x)
}
}
func vlib() {
vlib_out, err := exec.Command("cmd", "/C", "vlib work").Output()
check(err, "vlib work")
if log_stats {
fmt.Println(string(vlib_out))
color.Green("vlib done.")
}
}
func vcom() {
vcom_out, err := exec.Command("cmd", "/C", "vcom -work work -2002 -explicit -stats=none", path).Output()
check(err, "vcom")
if log_stats {
fmt.Println(string(vcom_out))
color.Green("vcom done.")
}
}
func startVsim() {
if log_stats {
color.Cyan("Starting vsim...")
}
vsim := exec.Command("cmd", "/C", "vsim -c work." + current_entity)
vsimIn, _ := vsim.StdinPipe()
vsimOut, _ := vsim.StdoutPipe()
vsim_writer = vsimIn
vsim.Start()
output := make(chan string)
defer close(output)
go ReadOutput(output, vsimOut)
for o := range output {
if len(o) > 0 {
if strings.Contains(o, "examine") {
examine_in_process = true
var_to_examine = strings.TrimSuffix(strings.Split(o, "/")[2], "\n")
}
if examine_in_process && o[0] == '#' {
examine_in_process = false
found := false
for i := 0; i < len(vhdl_vars); i++ {
if vhdl_vars[i].name == var_to_examine[:len(var_to_examine)-1] {
vhdl_vars[i].value = string(o[2])
found = true
}
}
if !found {
vhdl_vars = append(vhdl_vars, VHDL_VAR{name: var_to_examine, value: string(o[2])})
}
}
fmt.Println(o)
}
}
}
func stopVsim() {
color.Red("Stopping vsim!")
io.WriteString(vsim_writer, "exit\n")
}
func restartVsim() {
color.Red("Restarting vsim!")
//Reset values
vhdl_vars = nil
io.WriteString(vsim_writer, "restart\n")
}
func run() {
color.Red("Running!")
io.WriteString(vsim_writer, "run\n")
}
func compile() {
//Reset values
vhdl_vars = nil
//Make the lib at work
go vlib()
//vcom compile path
go vcom()
}
func main() {
color.Green("Starting Orus...")
path = os.Args[1]
//Analyze file
analyze()
//Hot reload file watching
go watch()
//Close program when user hits CTRL+C
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
color.Cyan("Closing Orus...")
os.Exit(1)
}()
compile()
go p5.Run(setup, draw)
startVsim()
}