-
Notifications
You must be signed in to change notification settings - Fork 0
/
signalTable.go
62 lines (53 loc) · 951 Bytes
/
signalTable.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
package main
import (
// "fmt"
"strconv"
"strings"
)
type item struct {
name string
typ string
width int
offset int
pointer int
}
type SignalTable struct {
elems map[string]*item
offset int
numtemp int
}
func NewItem(nm string, tp string, width int, ost int) *item {
return &item{
nm,
tp,
width,
ost,
0,
}
}
func NewSignalTable() *SignalTable {
return &SignalTable{
make(map[string]*item),
0,
0,
}
}
func (s *SignalTable) Enter(name string, tp string, width int) {
sub := strings.Split(name, ",")
for _, v := range sub {
s.elems[v] = NewItem(v, tp, width, s.offset)
s.offset += width
}
}
func (s *SignalTable) loopUp(name string) string {
if _, ok := s.elems[name]; ok {
return name
}
return ""
}
func (s *SignalTable) newTemp(tp string, width int) string {
name := "temp" + strconv.Itoa(s.numtemp)
s.elems[name] = NewItem(name, tp, width, s.offset)
s.offset += width
return name
}