2 * Copyright 2011 Leiden University. All rights reserved.
7 #include "adg2dot_options.h"
9 /* Add a connection from the element called "id" to the input port
10 * "port" provided it reads from the variable "name".
12 void add_connections_in(FILE *out
, __isl_keep isl_id
*id
, const char *name
,
17 for (int j
= 0; j
< port
->domain
->filters
.size(); ++j
) {
18 name2
= isl_pw_multi_aff_get_tuple_name(
19 port
->domain
->filters
[j
]->access
, isl_dim_out
);
22 fprintf(out
, "\t%s -> %s;\n",
23 isl_id_get_name(id
), isl_id_get_name(port
->name
));
28 /* Add a connection from the element called "id" to the output port
29 * "port" provided it reads from the variable "name".
31 void add_connections_out(FILE *out
, __isl_keep isl_id
*id
, const char *name
,
36 for (int i
= 0; i
< port
->vars
.size(); ++i
) {
37 name2
= isl_pw_multi_aff_get_tuple_name(
38 port
->vars
[i
]->access
, isl_dim_out
);
41 fprintf(out
, "\t%s -> %s;\n",
42 isl_id_get_name(id
), isl_id_get_name(port
->name
));
47 /* Add a connection from the element called "id" to "gate" provided
48 * it reads from the variable "name".
50 void add_connections(FILE *out
, __isl_keep isl_id
*id
, const char *name
,
55 for (int j
= 0; j
< gate
->domain
->filters
.size(); ++j
) {
56 name2
= isl_pw_multi_aff_get_tuple_name(
57 gate
->domain
->filters
[j
]->access
, isl_dim_out
);
60 fprintf(out
, "\t%s -> %s;\n",
61 isl_id_get_name(id
), isl_id_get_name(gate
->name
));
65 name2
= isl_pw_multi_aff_get_tuple_name(gate
->in
->access
, isl_dim_out
);
68 fprintf(out
, "\t%s -> %s;\n",
69 isl_id_get_name(id
), isl_id_get_name(gate
->name
));
72 /* Add connections from the element called "id" to "fn" provided
73 * it reads from the variable "name".
75 void add_connections(FILE *out
, __isl_keep isl_id
*id
, const char *name
,
76 __isl_keep isl_id
*node_id
, adg_function
*fn
)
80 for (int i
= 0; i
< fn
->in
.size(); ++i
) {
81 name2
= isl_pw_multi_aff_get_tuple_name(fn
->in
[i
]->var
->access
,
85 fprintf(out
, "\t%s -> %s;\n",
86 isl_id_get_name(id
), isl_id_get_name(node_id
));
89 for (int i
= 0; i
< fn
->domain
->filters
.size(); ++i
) {
90 name2
= isl_pw_multi_aff_get_tuple_name(
91 fn
->domain
->filters
[i
]->access
, isl_dim_out
);
94 fprintf(out
, "\t%s -> %s;\n",
95 isl_id_get_name(id
), isl_id_get_name(node_id
));
100 /* Add connections from the element called "id" to elements of "node" that
101 * refer to the variable "name".
103 void add_connections(FILE *out
, __isl_keep isl_id
*id
, const char *name
,
106 for (int k
= 0; k
< node
->input_ports
.size(); ++k
)
107 add_connections_in(out
, id
, name
, node
->input_ports
[k
]);
108 for (int j
= 0; j
< node
->gates
.size(); ++j
)
109 add_connections(out
, id
, name
, node
->gates
[j
]);
110 add_connections(out
, id
, name
, node
->name
, node
->function
);
111 for (int k
= 0; k
< node
->output_ports
.size(); ++k
)
112 add_connections_out(out
, id
, name
, node
->output_ports
[k
]);
115 /* Add connections from "port" to elements of "node" that refer to the
118 void add_connections(FILE *out
, adg_port
*port
, adg_node
*node
)
120 for (int i
= 0; i
< port
->vars
.size(); ++i
) {
122 name
= isl_pw_multi_aff_get_tuple_name(
123 port
->vars
[i
]->access
, isl_dim_out
);
124 add_connections(out
, port
->name
, name
, node
);
128 /* Add connections from "fn" to elements of "node" that refer to the
131 void add_connections(FILE *out
, adg_function
*fn
, adg_node
*node
)
133 for (int i
= 0; i
< fn
->out
.size(); ++i
) {
135 name
= isl_pw_multi_aff_get_tuple_name(
136 fn
->out
[i
]->var
->access
, isl_dim_out
);
137 add_connections(out
, node
->name
, name
, node
);
139 for (int i
= 0; i
< fn
->ctrl
.size(); ++i
) {
141 name
= isl_id_get_name(fn
->ctrl
[i
]->name
);
142 add_connections(out
, node
->name
, name
, node
);
146 void print(FILE *out
, adg_node
*node
)
148 fprintf(out
, "subgraph cluster_%s {\n", isl_id_get_name(node
->name
));
150 fprintf(out
, "\t%s [label = \"%s\"];\n",
151 isl_id_get_name(node
->name
),
152 isl_id_get_name(node
->function
->name
));
154 fprintf(out
, "%s;\n", isl_id_get_name(node
->name
));
155 for (int j
= 0; j
< node
->input_ports
.size(); ++j
) {
156 adg_port
*port
= node
->input_ports
[j
];
157 fprintf(out
, "\t%s [label = \"%s\"];\n",
158 isl_id_get_name(port
->name
),
159 isl_pw_multi_aff_get_tuple_name(
160 port
->vars
[0]->access
, isl_dim_out
));
161 add_connections(out
, port
, node
);
163 for (int j
= 0; j
< node
->gates
.size(); ++j
) {
164 adg_gate
*gate
= node
->gates
[j
];
165 fprintf(out
, "\t%s [label = \"%s\"];\n",
166 isl_id_get_name(gate
->name
),
167 isl_pw_multi_aff_get_tuple_name(gate
->out
->access
,
169 fprintf(out
, "\t%s -> %s;\n",
170 isl_id_get_name(gate
->name
),
171 isl_id_get_name(node
->name
));
173 for (int j
= 0; j
< node
->output_ports
.size(); ++j
) {
174 adg_port
*port
= node
->output_ports
[j
];
175 fprintf(out
, "\t%s [label = \"%s\"];\n",
176 isl_id_get_name(port
->name
),
177 isl_pw_multi_aff_get_tuple_name(
178 port
->vars
[0]->access
, isl_dim_out
));
180 add_connections(out
, node
->function
, node
);
184 void print(adg
*graph
, FILE *out
)
186 fprintf(out
, "digraph dummy {\n");
187 for (int i
= 0; i
< graph
->nodes
.size(); ++i
)
188 print(out
, graph
->nodes
[i
]);
189 for (int i
= 0; i
< graph
->edges
.size(); ++i
) {
190 adg_edge
*edge
= graph
->edges
[i
];
191 fprintf(out
, "%s -> %s [label = \"%s\"];\n",
192 isl_id_get_name(edge
->from_port_name
),
193 isl_id_get_name(edge
->to_port_name
),
194 isl_id_get_name(edge
->name
));
199 static void set_output_name(isl_ctx
*ctx
, struct options
*options
)
202 const char *suffix
= ".dot";
204 if (!options
->input
|| !strcmp(options
->input
, "-"))
209 len
= strlen(options
->input
);
210 if (len
> 5 && !strcmp(options
->input
+ len
- 5, ".yaml"))
212 options
->output
= isl_alloc_array(ctx
, char, len
+ strlen(suffix
) + 1);
213 assert(options
->output
);
214 strncpy(options
->output
, options
->input
, len
);
215 strcpy(options
->output
+ len
, suffix
);
218 int main(int argc
, char *argv
[])
221 struct options
*options
= options_new_with_defaults();
223 FILE *in
= stdin
, *out
= stdout
;
225 ctx
= isl_ctx_alloc();
226 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
228 set_output_name(ctx
, options
);
230 if (options
->input
&& strcmp(options
->input
, "-")) {
231 in
= fopen(options
->input
, "r");
234 if (options
->output
&& strcmp(options
->output
, "-")) {
235 out
= fopen(options
->output
, "w");
239 graph
= adg_parse(ctx
, in
);