-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcg_print.h
89 lines (76 loc) · 2.28 KB
/
vcg_print.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* -*- Mode: C++ -*- */
/** \file vcg_print.h
* Printing the type hierarchy in VCG tool syntax for flop AND cheap.
*/
#ifndef _VCG_PRINT_H
#define _VCG_PRINT_H
#include <fstream>
/** Return true if \a i is a proper type, not a leaf type. */
inline bool local_is_proper_type(type_t i) {
#ifdef FLOP
return (leaftypeparent[i] == -1);
#else
return ! is_leaftype(i);
#endif
}
/** Return the number of all types */
inline type_t local_ntypes() {
#ifdef FLOP
return types.number();
#else
return nstatictypes;
#endif
}
/** Return the type name of type \a i */
inline const char * local_typename(type_t i) {
#ifdef FLOP
return types.name(i).c_str();
#else
return type_name(i);
#endif
}
/** \brief Print the name of a type in VCG syntax (e.g. escape double quotes)
*/
inline void vcg_print_type_name(ofstream &out, type_t i) {
const char *name = local_typename(i);
if (name[0] == '"') out << "\"_" << name + 1 ;
else out << '"' << name << "\" ";
}
/** Print a hierarchy node in VCG syntax */
void vcg_print_node(ofstream &out, type_t i) {
out << "node: { title: " ; vcg_print_type_name(out, i);
if (! local_is_proper_type(i)) out << " bordercolor: blue ";
out << "}" << endl;
}
/** Print a hierarchy edge in VCG syntax */
void vcg_print_edge(ofstream &out, type_t from, type_t to) {
out << "edge: { sourcename: " ; vcg_print_type_name(out, from) ;
out << " targetname: " ; vcg_print_type_name(out, to) ;
out << "}" << endl;
}
/** Print hierarchy in VCG syntax.
* (http://rw4.cs.uni-sb.de/users/sander/html/gsvcg1.html)
*/
void vcg_print_hierarchy(const char *filename, bool with_leaftypes) {
ofstream out(filename);
out << "graph: { orientation: left_to_right xspace: 10" << endl;
// print all nodes
for(type_t i = 0; i < local_ntypes(); ++i)
if (with_leaftypes || local_is_proper_type(i))
vcg_print_node(out, i);
// print all edges
for(type_t i = 0; i < local_ntypes(); ++i) {
if (local_is_proper_type(i)) {
const list< type_t > &supers = immediate_supertypes(i);
for(list< type_t >::const_iterator it = supers.begin()
; it != supers.end(); ++it) {
vcg_print_edge(out, *it, i);
}
} else {
if(with_leaftypes)
vcg_print_edge(out, leaftypeparent[i - first_leaftype], i);
}
}
out << "}" << endl;
}
#endif