2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief HTML dumper for PBQP.
10 * @author Sebastian Buchwald
14 #include "adt/array.h"
17 #include "pbqp_edge_t.h"
18 #include "pbqp_node_t.h"
20 #include "html_dumper.h"
23 /* Caution: Due to static buffer use only once per statement */
24 static const char *cost2a(num const cost)
28 if (cost == INF_COSTS) return "inf";
30 sprintf(buf, "%u", cost);
32 sprintf(buf, "%10lld", cost);
38 static void dump_vector(FILE *f, vector_t *vec)
41 unsigned len = vec->len;
43 fprintf(f, "<span class=\"vector\">( ");
45 for (index = 0; index < len; ++index) {
46 #if KAPS_ENABLE_VECTOR_NAMES
47 fprintf(f, "<span title=\"%s\">%s</span> ",
48 vec->entries[index].name, cost2a(vec->entries[index].data));
50 fprintf(f, "%s ", cost2a(vec->entries[index].data));
53 fprintf(f, " )</span>\n");
56 static void dump_matrix(FILE *f, pbqp_matrix_t *mat)
59 num *p = mat->entries;
61 assert(mat->cols > 0);
62 assert(mat->rows > 0);
63 fprintf(f, "\t\\begin{pmatrix}\n");
64 for (row = 0; row < mat->rows; ++row) {
65 fprintf(f, "\t %s", cost2a(*p++));
67 for (col = 1; col < mat->cols; ++col) {
68 fprintf(f, "& %s", cost2a(*p++));
72 fprintf(f, "\t\\end{pmatrix}\n");
75 void pbqp_dump_edge(FILE *file, pbqp_edge_t *edge)
77 fputs("<tex>\n", file);
78 fprintf(file, "\t\\overline\n{C}_{%u,%u}=\n",
79 edge->src->index, edge->tgt->index);
80 dump_matrix(file, edge->costs);
81 fputs("</tex><br>", file);
84 static void dump_edge_costs(pbqp_t *pbqp)
88 fputs("<p>", pbqp->dump_file);
89 for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
90 pbqp_node_t *src_node = get_node(pbqp, src_index);
97 len = ARR_LEN(src_node->edges);
98 for (edge_index = 0; edge_index < len; ++edge_index) {
99 pbqp_edge_t *edge = src_node->edges[edge_index];
100 unsigned tgt_index = edge->tgt->index;
101 if (src_index < tgt_index) {
102 pbqp_dump_edge(pbqp->dump_file, edge);
106 fputs("</p>", pbqp->dump_file);
109 void pbqp_dump_node(FILE *file, pbqp_node_t *node)
112 fprintf(file, "\tc<sub>%u</sub> = ", node->index);
113 dump_vector(file, node->costs);
114 fputs("<br>\n", file);
118 static void dump_node_costs(pbqp_t *pbqp)
122 /* dump node costs */
123 fputs("<p>", pbqp->dump_file);
124 for (index = 0; index < pbqp->num_nodes; ++index) {
125 pbqp_dump_node(pbqp->dump_file, get_node(pbqp, index));
127 fputs("</p>", pbqp->dump_file);
130 void pbqp_dump_section(FILE *f, int level, const char *txt)
132 fprintf(f, "<h%d>%s</h%d>\n", level, txt, level);
135 void pbqp_dump_graph(pbqp_t *pbqp)
139 fputs("<p>\n<graph>\n\tgraph input {\n", pbqp->dump_file);
140 for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
141 pbqp_node_t *node = get_node(pbqp, src_index);
142 if (node && !node_is_reduced(node)) {
143 fprintf(pbqp->dump_file, "\t n%u;\n", src_index);
147 for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
148 pbqp_node_t *node = get_node(pbqp, src_index);
155 if (node_is_reduced(node))
158 len = ARR_LEN(node->edges);
159 for (edge_index = 0; edge_index < len; ++edge_index) {
160 pbqp_node_t *tgt_node = node->edges[edge_index]->tgt;
161 unsigned tgt_index = tgt_node->index;
163 if (node_is_reduced(tgt_node))
166 if (src_index < tgt_index) {
167 fprintf(pbqp->dump_file, "\t n%u -- n%u;\n", src_index,
172 fputs("\t}\n</graph>\n</p>\n", pbqp->dump_file);
175 void pbqp_dump_input(pbqp_t *pbqp)
177 pbqp_dump_section(pbqp->dump_file, 1, "1. PBQP Problem");
178 pbqp_dump_section(pbqp->dump_file, 2, "1.1 Topology");
179 pbqp_dump_graph(pbqp);
180 pbqp_dump_section(pbqp->dump_file, 2, "1.2 Cost Vectors");
181 dump_node_costs(pbqp);
182 pbqp_dump_section(pbqp->dump_file, 2, "1.3 Cost Matrices");
183 dump_edge_costs(pbqp);
186 void pbqp_dump_simplifyedge(pbqp_t *pbqp, pbqp_edge_t *edge)
188 pbqp_dump_node(pbqp->dump_file, edge->src);
189 pbqp_dump_edge(pbqp->dump_file, edge);
190 pbqp_dump_node(pbqp->dump_file, edge->tgt);