1 /******************************************************************************
2 * Copyright (c) 2017-2018, Texas Instruments Incorporated - http://www.ti.com/
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Texas Instruments Incorporated nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 *****************************************************************************/
28 #pragma once
30 #include <cstdint>
31 #include "tidl_create_params.h"
33 #include <boost/graph/graphviz.hpp>
34 #include <boost/graph/adjacency_list.hpp>
35 #include <boost/graph/subgraph.hpp>
37 using boost::adjacency_list;
38 using boost::property;
39 using boost::subgraph;
40 using boost::get_property;
41 using boost::add_vertex;
42 using boost::add_edge;
43 using boost::edge_index_t;
44 using boost::edge_attribute_t;
45 using boost::vertex_attribute_t;
46 using boost::vertex_attribute;
47 using boost::graph_name_t;
48 using boost::graph_name;
49 using boost::graph_graph_attribute_t;
50 using boost::graph_graph_attribute;
51 using boost::graph_vertex_attribute_t;
52 using boost::graph_vertex_attribute;
53 using boost::graph_edge_attribute_t;
54 using boost::graph_edge_attribute;
55 using boost::vecS;
57 using GraphvizAttributes = std::map<std::string, std::string>;
61 // Boost graph with notes and edges annotated with Dot properties.
62 // These properties are used by the write_graphviz function.
63 //
64 // From https://www.boost.org/doc/libs/1_55_0/libs/graph/doc/subgraph.html
65 // When creating a subgraph, the underlying graph type is required to have
66 // vertex_index and edge_index internal properties. Add an edge index property
67 // to the adjacency list. We do not need to add a vertex index property
68 // because it is built in to the adjacency_list.
69 using Graph =
70 subgraph<
71 adjacency_list<vecS, vecS, boost::directedS,
72 property<vertex_attribute_t, GraphvizAttributes>,
73 property<edge_index_t,int,property<edge_attribute_t, GraphvizAttributes>>,
74 property<graph_name_t, std::string,
75 property<graph_graph_attribute_t, GraphvizAttributes,
76 property<graph_vertex_attribute_t, GraphvizAttributes,
77 property<graph_edge_attribute_t, GraphvizAttributes>
78 >>>
79 >>;
81 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
83 class DotGraph
84 {
85 public:
86 DotGraph(const sTIDL_Network_t& net);
87 ~DotGraph() {}
89 void Write(const std::string& filename) const;
91 private:
92 void AddVertices();
93 void AddEdges();
94 void AddMetaData();
95 void AddVertexProperties(Vertex& V, Graph* g, const sTIDL_Layer_t& layer,
96 int index);
98 Graph graph_m;
99 const sTIDL_Network_t& net_m;
100 };
102 extern const char* TIDL_LayerString[];