gcc config
[prop.git] / prop-src / visualize.pcc
blobfa8f032a4554185e8c73edbbca54589e49ccf34b
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file implements the datatype definitions layout generator
4 //  for visualizing datatype definitions using vcg.
5 //
6 //////////////////////////////////////////////////////////////////////////////
8 #include <stdarg.h>
9 #include <iostream>
10 #include <string.h>
11 #include "options.h"
12 #include "compiler.h"
13 #include "visualize.h"
15 //////////////////////////////////////////////////////////////////////////////
17 //  Constructor and destructor for class PropVisualizer
19 //////////////////////////////////////////////////////////////////////////////
20 PropVisualizer::PropVisualizer()
21    : label_text(text_buffer,sizeof(text_buffer))
22      { set_stream(label_text); }
24 PropVisualizer::~PropVisualizer() {}
26 va_list PropVisualizer::printer(char fmt, va_list arg)
27 {  bug("%LPropVisualizer::printer %%%c",(int)fmt);
28    return arg;
31 //////////////////////////////////////////////////////////////////////////////
33 //  Method to make a label 
35 //////////////////////////////////////////////////////////////////////////////
36 void PropVisualizer::add_label(const char * fmt, ...)
37 {  va_list arg;
38    va_start (arg,fmt);
39    outv(fmt,arg);
40    va_end(arg);
43 //////////////////////////////////////////////////////////////////////////////
45 //  Method to make a label.
47 //////////////////////////////////////////////////////////////////////////////
48 void PropVisualizer::make_label() 
49 {  label_text << ends;
51    label(text_buffer);
53    // reset buffer
54    label_text.rdbuf()->seekpos(0);
57 //////////////////////////////////////////////////////////////////////////////
59 //  This method takes a stream and prints out all the definitions
60 //  currently processed as Graph Description Language (GDL). 
62 //////////////////////////////////////////////////////////////////////////////
63 void Compiler::print_definitions_as_GDL()
64 {  PropVisualizer v;
66    const char * G = "Program definitions";
68    v . begin_graph(G);
70    ///////////////////////////////////////////////////////////////////////////
71    //
72    //  Specify the layout format 
73    //
74    ///////////////////////////////////////////////////////////////////////////
75    v . label(G)                          // the name of the graph
76      . display_edge_labels(true)         // display labels on edges
77      . xspace(40)                        // x distance between nodes
78      . yspace(40)                        // y distance between nodes
79      . layoutalgorithm(VCG::minbackward) // minimize back edges
80      . color(VCG::lightblue)             // default color
81    ; 
83    ///////////////////////////////////////////////////////////////////////////
84    //
85    // Layout datatype definitions
86    //
87    ///////////////////////////////////////////////////////////////////////////
88    v . visualize_datatype_definitions();
90    ///////////////////////////////////////////////////////////////////////////
91    //
92    // Layout type definitions
93    //
94    ///////////////////////////////////////////////////////////////////////////
96    ///////////////////////////////////////////////////////////////////////////
97    //
98    // Layout graph type definitions
99    //
100    ///////////////////////////////////////////////////////////////////////////
102    ///////////////////////////////////////////////////////////////////////////
103    //
104    // Finish constructing the graph and print out the entire GDL 
105    //
106    ///////////////////////////////////////////////////////////////////////////
107    v . end_graph(G);
110    ///////////////////////////////////////////////////////////////////////////
111    //
112    // Finally output the graph
113    //
114    ///////////////////////////////////////////////////////////////////////////
115    {  char vcg_file[256];
116       strcpy(vcg_file, options.file_prefix);
117       strcat(vcg_file, "vcg");
118       std::ostream * F = open_output_file(vcg_file);
119       msg("[Writing vcg output to %s]\n",vcg_file);
120       v . print_GDL_on(*F);
121       delete F;
122    }