+
+void dump_ir_graph_ext(ir_graph_dump_func func, ir_graph *graph,
+ const char *suffix)
+{
+ const char *dump_name = get_irg_dump_name(graph);
+ char *file_name;
+ FILE *out;
+
+ if (!ir_should_dump(dump_name))
+ return;
+
+ add_dump_path();
+
+ add_string_escaped(dump_name);
+ obstack_printf(&obst, "-%02u", graph->dump_nr++);
+
+ if (suffix != NULL) {
+ if (suffix[0] != '.')
+ obstack_1grow(&obst, '-');
+ add_string_escaped(suffix);
+ }
+ obstack_1grow(&obst, '\0');
+
+ file_name = (char*)obstack_finish(&obst);
+ /* xvcg expects only <CR> so we need "b"inary mode (for win32) */
+ out = fopen(file_name, "wb");
+ obstack_free(&obst, file_name);
+
+ if (out == NULL) {
+ fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
+ return;
+ }
+
+ func(out, graph);
+ fclose(out);
+}
+
+void dump_ir_prog_ext(ir_prog_dump_func func, const char *suffix)
+{
+ char *file_name;
+ FILE *out;
+
+ add_dump_path();
+
+ obstack_printf(&obst, "%02u", irp->dump_nr++);
+ if (suffix != NULL) {
+ if (suffix[0] != '.')
+ obstack_1grow(&obst, '-');
+ add_string_escaped(suffix);
+ }
+ obstack_1grow(&obst, '\0');
+
+ file_name = (char*)obstack_finish(&obst);
+ out = fopen(file_name, "wb");
+ obstack_free(&obst, file_name);
+
+ if (out == NULL) {
+ fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
+ return;
+ }
+ func(out);
+ fclose(out);
+}
+
+void dump_ir_graph(ir_graph *graph, const char *suffix)
+{
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "%s.vcg", suffix);
+ dump_ir_graph_ext(dump_ir_graph_file, graph, buf);
+}
+
+void dump_all_ir_graphs(const char *suffix)
+{
+ size_t i, n_irgs = get_irp_n_irgs();
+
+ for (i = 0; i < n_irgs; ++i) {
+ ir_graph *irg = get_irp_irg(i);
+ dump_ir_graph(irg, suffix);
+ }
+}
+
+typedef struct pass_t {
+ ir_prog_pass_t pass;
+ char suffix[1];
+} pass_t;
+
+/**
+ * Wrapper around dump_all_ir_graphs().
+ */
+static int dump_all_ir_graphs_wrapper(ir_prog *irp, void *context)
+{
+ pass_t *pass = (pass_t*)context;
+
+ (void)irp;
+ dump_all_ir_graphs(pass->suffix);
+ return 0;
+}
+
+ir_prog_pass_t *dump_all_ir_graph_pass(const char *name, const char *suffix)
+{
+ size_t len = strlen(suffix) + 1;
+ pass_t *pass = XMALLOCF(pass_t, suffix, len);
+ ir_prog_pass_t *res = def_prog_pass_constructor(
+ &pass->pass, name ? name : "dump_all_graphs", dump_all_ir_graphs_wrapper);
+
+ /* this pass does not change anything, so neither dump nor verify is needed. */
+ res->dump_irprog = ir_prog_no_dump;
+ res->verify_irprog = ir_prog_no_verify;
+
+ memcpy(pass->suffix, suffix, len);
+
+ return res;
+}