-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_hdl.go
114 lines (92 loc) · 2.28 KB
/
evaluate_hdl.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
package cpu
import (
"fmt"
"strings"
)
func (thisChip hdlChip) Evaluate(inputs map[string]FheType, stack string) map[string]FheType {
return thisChip.evaluate(inputs, stack)
}
func (thisChip hdlChip) evaluate(inputs map[string]FheType, stack string) map[string]FheType {
newStack := stack + ">" + thisChip.name
if verbose {
fmt.Printf("\r %-64s", newStack)
}
for key := range thisChip.wires {
thisChip.wires[key] = FheType{IsNil: true}
}
for key, value := range inputs {
thisChip.wires[key] = value
}
for idx := range thisChip.subChips {
thisChip.subChips[idx].dead = false
}
for _, subChip := range thisChip.subChips {
if !subChip.stateful {
continue
}
subInputs := make(map[string]FheType)
// for key := range subChip.chipIO.inputs {
// subInputs[key] = -1
// }
for childWire, parentWire := range subChip.childParentWiresIn {
subInputs[childWire] = thisChip.wires[parentWire]
}
subOutputs := subChip.evaluatableChip.evaluate(subInputs, newStack)
for childWire, parentWire := range subChip.childParentWiresOut {
thisChip.wires[parentWire] = subOutputs[childWire]
}
}
for {
for idx, subChip := range thisChip.subChips {
if subChip.dead {
continue
}
subInputs := make(map[string]FheType)
ready := true
for childWire, parentWire := range subChip.childParentWiresIn {
parentValue := thisChip.wires[parentWire]
if !parentValue.IsNil {
subInputs[childWire] = parentValue
} else {
ready = false
break
}
}
if !ready {
continue
}
subOutputs := subChip.evaluatableChip.evaluate(subInputs, newStack)
for childWire, parentWire := range subChip.childParentWiresOut {
thisChip.wires[parentWire] = subOutputs[childWire]
}
thisChip.subChips[idx].dead = true
}
done := true
if thisChip.stateful {
for key := range thisChip.chipIO.outputs {
if thisChip.wires[key].IsNil {
done = false
break
}
}
} else {
for _, value := range thisChip.wires {
if value.IsNil {
done = false
break
}
}
}
if done {
break
}
}
outputs := make(map[string]FheType)
for key := range thisChip.chipIO.outputs {
outputs[key] = thisChip.wires[key]
}
if stack == "#" && verbose {
fmt.Print("\r" + strings.Repeat(" ", 64) + "\r")
}
return outputs
}