git.haldean.org ubik / a34e3dc
add labels to plugs for debugging Haldean Brown 4 years ago
3 changed file(s) with 51 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
6969 struct ubik_value *head;
7070
7171 /* All elements of this struct are only used for implementing
72 * ubik_port_dump(). */
72 * ubik_port_dump() or other debugging facilities. */
7373 struct {
7474 char *name;
7575 } debug;
7777 enum ubik_port_type type;
7878 };
7979
80 /* All elements of this struct are only used for implementing
81 * ubik_port_dump() or other debugging facilities. */
82 struct ubik_plug_debug
83 {
84 char *name;
85 };
86
8087 struct ubik_plug
8188 {
8289 ubik_port_transformer func;
8390 struct ubik_port *dst;
91 struct ubik_plug_debug debug;
8492 };
8593
8694 /* Requests that a port update its head, notifying its listeners if
9098
9199 /* Requests that a plug-pair be attached to a port. This handles all of
92100 * the initialization of the plug relationship, notifying the new sink
93 * of any available information in the source. */
101 * of any available information in the source. Debug informationi is
102 * optional; to skip debug info attachment, pass NULL. A pointer is used
103 * to make the parameter optional; debug information will be copied out
104 * of the passed object, if non-null. The provided pointer does not need
105 * to live past the end of the call to ubik_port_attach. */
94106 no_ignore ubik_error
95107 ubik_port_attach(
96108 struct ubik_port *source,
97109 struct ubik_port *sink,
98 ubik_port_transformer func);
110 ubik_port_transformer func,
111 struct ubik_plug_debug *debug);
99112
100113 /* Frees all memory associated with the port. This clears all
101114 * plugs whose source is this port, but it does not clear plugs whose
8484 ubik_port_attach(
8585 struct ubik_port *source,
8686 struct ubik_port *sink,
87 ubik_port_transformer func)
87 ubik_port_transformer func,
88 struct ubik_plug_debug *d)
8889 {
8990 struct ubik_plug *plug;
9091 size_t i;
105106 return ubik_raise(ERR_NO_MEMORY, "couldn't allocate plug");
106107 plug->dst = sink;
107108 plug->func = func;
109 if (d != NULL)
110 plug->debug = *d;
108111
109112 err = ubik_vector_append(&source->plugs, plug);
110113 if (err != OK)
142145 struct ubik_port *p;
143146 struct ubik_plug *plug;
144147
145 ubik_fprintf(s, "digraph {\n");
148 ubik_fprintf(s, "digraph {\n rankdir=LR;\n");
146149 for (i = 0; i < n; i++)
147150 {
148151 p = ports[i];
150153 * parsed as a malformed number by graphviz. */
151154 ubik_fprintf(s, " n%p [", (void *) p);
152155 if (p->type & UBIK_PORT_SOURCE)
153 ubik_fprintf(s, "shape=box");
156 ubik_fprintf(s, "shape=box, style=bold");
154157 else if (p->type & UBIK_PORT_SINK)
155 ubik_fprintf(s, "shape=trapezium");
158 ubik_fprintf(s, "shape=box, style=solid");
156159 else
157160 ubik_fprintf(s, "shape=octagon");
158
159 if (p->type & UBIK_PORT_SINK)
160 ubik_fprintf(s, ", style=bold");
161 else
162 ubik_fprintf(s, ", style=solid");
163161
164162 if (p->debug.name != NULL)
165163 ubik_fprintf(s, ", label=\"%s\"", p->debug.name);
171169 for (j = 0; j < p->plugs.n; j++)
172170 {
173171 plug = p->plugs.elems[j];
174 ubik_fprintf(s, " n%p -> n%p",
172 ubik_fprintf(s, " n%p -> n%p [",
175173 (void *) p, (void *) plug->dst);
176174 if (plug->func != NULL)
177 ubik_fprintf(s, " [style=dashed]");
178 ubik_fprintf(s, "\n");
175 ubik_fprintf(s, "style=dashed");
176 else
177 ubik_fprintf(s, "style=solid");
178 if (plug->debug.name != NULL)
179 ubik_fprintf(s, ", label=\"%s\"",
180 plug->debug.name);
181 else
182 ubik_fprintf(s, ", label=\"\"");
183 ubik_fprintf(s, ", fontsize=8]\n");
179184 }
180185 }
181186 ubik_fprintf(s, "}\n");
6666 .sink = sink,
6767 };
6868 sunk = NULL;
69 assert(ubik_port_attach(&p1, &p2, NULL) == OK);
69 assert(ubik_port_attach(&p1, &p2, NULL, NULL) == OK);
7070 assert(p2.head == &sentinel);
7171 assert(sunk == &sentinel);
7272 ubik_port_free(&p1);
8686 .sink = sink,
8787 };
8888 sunk = NULL;
89 assert(ubik_port_attach(&p1, &p2, NULL) == OK);
89 assert(ubik_port_attach(&p1, &p2, NULL, NULL) == OK);
9090 assert(ubik_port_poll(&p1) == OK);
9191 assert(p2.head == &sentinel);
9292 assert(sunk == &sentinel);
108108 };
109109 ubik_error err;
110110
111 assert(ubik_port_attach(&p1, &p2, NULL) == OK);
111 assert(ubik_port_attach(&p1, &p2, NULL, NULL) == OK);
112112 err = ubik_port_poll(&p1);
113113 assert(err != OK);
114114 assert(err->error_code == ERR_PRESENT);
151151 };
152152 struct ubik_port *ps[] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8 };
153153 struct ubik_stream out;
154 struct ubik_plug_debug d;
154155
155 assert(ubik_port_attach(&p1, &p2, NULL) == OK);
156 assert(ubik_port_attach(&p1, &p4, &xform) == OK);
157 assert(ubik_port_attach(&p3, &p2, NULL) == OK);
158 assert(ubik_port_attach(&p1, &p5, NULL) == OK);
159 assert(ubik_port_attach(&p5, &p6, NULL) == OK);
160 assert(ubik_port_attach(&p4, &p5, NULL) == OK);
161 assert(ubik_port_attach(&p2, &p7, &xform) == OK);
162 assert(ubik_port_attach(&p5, &p7, NULL) == OK);
163 assert(ubik_port_attach(&p8, &p7, NULL) == OK);
156 assert(ubik_port_attach(&p1, &p2, NULL, NULL) == OK);
157 d.name = "concatenate";
158 assert(ubik_port_attach(&p1, &p4, &xform, &d) == OK);
159 d.name = "reduce-running-sum";
160 assert(ubik_port_attach(&p3, &p2, NULL, &d) == OK);
161 assert(ubik_port_attach(&p1, &p5, NULL, NULL) == OK);
162 d.name = "assert";
163 assert(ubik_port_attach(&p5, &p6, NULL, &d) == OK);
164 d.name = "flip";
165 assert(ubik_port_attach(&p4, &p5, NULL, &d) == OK);
166 assert(ubik_port_attach(&p2, &p7, &xform, NULL) == OK);
167 assert(ubik_port_attach(&p5, &p7, NULL, NULL) == OK);
168 d.name = "gen";
169 assert(ubik_port_attach(&p8, &p7, NULL, &d) == OK);
164170 assert(ubik_stream_wfile(&out, "/tmp/ubik-test-unit-port.dot") == OK);
165171
166172 ubik_port_dump(&out, ps, sizeof(ps) / sizeof(ps[0]));