forked from markkurossi/mpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.go
56 lines (49 loc) · 1.28 KB
/
dot.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
//
// Copyright (c) 2019-2023 Markku Rossi
//
// All rights reserved.
//
package circuit
import (
"fmt"
"io"
)
// Dot creates graphviz dot output of the circuit.
func (c *Circuit) Dot(out io.Writer) {
fmt.Fprintf(out, "digraph circuit\n{\n")
fmt.Fprintf(out, " overlap=scale;\n")
fmt.Fprintf(out, " node\t[fontname=\"Helvetica\"];\n")
fmt.Fprintf(out, " {\n node [shape=plaintext];\n")
for w := 0; w < c.NumWires; w++ {
fmt.Fprintf(out, " w%d\t[label=\"%d\"];\n", w, w)
}
fmt.Fprintf(out, " }\n")
fmt.Fprintf(out, " {\n node [shape=box];\n")
for idx, gate := range c.Gates {
fmt.Fprintf(out, " g%d\t[label=\"%s\"];\n", idx, gate.Op)
}
fmt.Fprintf(out, " }\n")
if true {
fmt.Fprintf(out, " { rank=same")
var numInputs int
for _, input := range c.Inputs {
numInputs += int(input.Type.Bits)
}
for w := 0; w < numInputs; w++ {
fmt.Fprintf(out, "; w%d", w)
}
fmt.Fprintf(out, ";}\n")
fmt.Fprintf(out, " { rank=same")
for w := 0; w < c.Outputs.Size(); w++ {
fmt.Fprintf(out, "; w%d", c.NumWires-w-1)
}
fmt.Fprintf(out, ";}\n")
}
for idx, gate := range c.Gates {
for _, i := range gate.Inputs() {
fmt.Fprintf(out, " w%d -> g%d;\n", i, idx)
}
fmt.Fprintf(out, " g%d -> w%d;\n", idx, gate.Output)
}
fmt.Fprintf(out, "}\n")
}