2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief HTML dumper for PBQP.
24 * @author Sebastian Buchwald
29 #include "adt/array.h"
32 #include "pbqp_edge_t.h"
33 #include "pbqp_node_t.h"
35 #include "html_dumper.h"
38 /* Caution: Due to static buffer use only once per statement */
39 static const char *cost2a(num const cost)
43 if (cost == INF_COSTS) return "inf";
45 sprintf(buf, "%u", cost);
47 sprintf(buf, "%10lld", cost);
53 static void dump_vector(FILE *f, vector_t *vec)
56 unsigned len = vec->len;
58 fprintf(f, "<span class=\"vector\">( ");
60 for (index = 0; index < len; ++index) {
61 #if KAPS_ENABLE_VECTOR_NAMES
62 fprintf(f, "<span title=\"%s\">%s</span> ",
63 vec->entries[index].name, cost2a(vec->entries[index].data));
65 fprintf(f, "%s ", cost2a(vec->entries[index].data));
68 fprintf(f, " )</span>\n");
71 static void dump_matrix(FILE *f, pbqp_matrix_t *mat)
74 num *p = mat->entries;
76 assert(mat->cols > 0);
77 assert(mat->rows > 0);
78 fprintf(f, "\t\\begin{pmatrix}\n");
79 for (row = 0; row < mat->rows; ++row) {
80 fprintf(f, "\t %s", cost2a(*p++));
82 for (col = 1; col < mat->cols; ++col) {
83 fprintf(f, "& %s", cost2a(*p++));
87 fprintf(f, "\t\\end{pmatrix}\n");
90 void dump_edge(FILE *file, pbqp_edge_t *edge)
92 fputs("<tex>\n", file);
93 fprintf(file, "\t\\overline\n{C}_{%u,%u}=\n",
94 edge->src->index, edge->tgt->index);
95 dump_matrix(file, edge->costs);
96 fputs("</tex><br>", file);
99 static void dump_edge_costs(pbqp_t *pbqp)
103 fputs("<p>", pbqp->dump_file);
104 for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
105 pbqp_node_t *src_node = get_node(pbqp, src_index);
112 len = ARR_LEN(src_node->edges);
113 for (edge_index = 0; edge_index < len; ++edge_index) {
114 pbqp_edge_t *edge = src_node->edges[edge_index];
115 unsigned tgt_index = edge->tgt->index;
116 if (src_index < tgt_index) {
117 dump_edge(pbqp->dump_file, edge);
121 fputs("</p>", pbqp->dump_file);
124 void dump_node(FILE *file, pbqp_node_t *node)
127 fprintf(file, "\tc<sub>%u</sub> = ", node->index);
128 dump_vector(file, node->costs);
129 fputs("<br>\n", file);
133 static void dump_node_costs(pbqp_t *pbqp)
137 /* dump node costs */
138 fputs("<p>", pbqp->dump_file);
139 for (index = 0; index < pbqp->num_nodes; ++index) {
140 dump_node(pbqp->dump_file, get_node(pbqp, index));
142 fputs("</p>", pbqp->dump_file);
145 void dump_section(FILE *f, int level, const char *txt)
147 fprintf(f, "<h%d>%s</h%d>\n", level, txt, level);
150 void pbqp_dump_graph(pbqp_t *pbqp)
154 fputs("<p>\n<graph>\n\tgraph input {\n", pbqp->dump_file);
155 for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
156 pbqp_node_t *node = get_node(pbqp, src_index);
157 if (node && !node_is_reduced(node)) {
158 fprintf(pbqp->dump_file, "\t n%u;\n", src_index);
162 for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
163 pbqp_node_t *node = get_node(pbqp, src_index);
170 if (node_is_reduced(node))
173 len = ARR_LEN(node->edges);
174 for (edge_index = 0; edge_index < len; ++edge_index) {
175 pbqp_node_t *tgt_node = node->edges[edge_index]->tgt;
176 unsigned tgt_index = tgt_node->index;
178 if (node_is_reduced(tgt_node))
181 if (src_index < tgt_index) {
182 fprintf(pbqp->dump_file, "\t n%u -- n%u;\n", src_index,
187 fputs("\t}\n</graph>\n</p>\n", pbqp->dump_file);
190 void pbqp_dump_input(pbqp_t *pbqp)
192 dump_section(pbqp->dump_file, 1, "1. PBQP Problem");
193 dump_section(pbqp->dump_file, 2, "1.1 Topology");
194 pbqp_dump_graph(pbqp);
195 dump_section(pbqp->dump_file, 2, "1.2 Cost Vectors");
196 dump_node_costs(pbqp);
197 dump_section(pbqp->dump_file, 2, "1.3 Cost Matrices");
198 dump_edge_costs(pbqp);
201 void dump_simplifyedge(pbqp_t *pbqp, pbqp_edge_t *edge)
203 dump_node(pbqp->dump_file, edge->src);
204 dump_edge(pbqp->dump_file, edge);
205 dump_node(pbqp->dump_file, edge->tgt);