Cerata
A library to generate structural hardware designs
dot.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <memory>
18 #include <vector>
19 #include <string>
20 #include <sstream>
21 #include <utility>
22 
23 #include "cerata/output.h"
24 #include "cerata/graph.h"
25 #include "cerata/dot/style.h"
26 
28 namespace cerata::dot {
29 
31 struct Grapher {
35  std::vector<Edge *> drawn_edges = {};
36  Grapher() : Grapher(Style::normal()) {}
38  explicit Grapher(Style style) : style(std::move(style)) {}
40  std::string GenEdges(const Graph &graph, int level = 0);
42  std::string GenNode(const Node &n, int level = 0);
44  std::string GenNodes(const Graph &graph, Node::NodeID id, int level = 0, bool no_group = false);
46  std::string GenGraph(const Graph &graph, int level = 0);
48  std::string GenFile(const Graph &graph, const std::string &path);
50  static std::string GenExpr(const Node &exp, const std::string &prefix = "", int level = 0);
51 };
52 
54 std::string NodeName(const Node &node, const std::string &suffix = "");
55 
58  public:
60  explicit DOTOutputGenerator(std::string root_dir, std::vector<OutputSpec> graphs = {})
61  : OutputGenerator(std::move(root_dir), std::move(graphs)) {}
63  void Generate() override;
65  std::string subdir() override { return "dot"; }
66 };
67 
68 } // namespace cerata::dot
cerata::dot::DOTOutputGenerator::subdir
std::string subdir() override
Returns the subdirectory used by this OutputGenerator.
Definition: dot.h:65
cerata::dot::Grapher
Dot graph output generator.
Definition: dot.h:31
cerata::dot::Grapher::GenFile
std::string GenFile(const Graph &graph, const std::string &path)
Generate a DOT file.
Definition: dot.cc:310
cerata::dot::DOTOutputGenerator::Generate
void Generate() override
Generate the DOT graphs.
Definition: dot.cc:29
cerata::Graph
A graph representing a hardware structure.
Definition: graph.h:37
cerata::dot::Grapher::GenExpr
static std::string GenExpr(const Node &exp, const std::string &prefix="", int level=0)
Generate expressions.
Definition: dot.cc:318
cerata::dot::Grapher::Grapher
Grapher(Style style)
Grapher constructor.
Definition: dot.h:38
cerata::dot::Grapher::GenNode
std::string GenNode(const Node &n, int level=0)
Generate a node.
cerata::dot::DOTOutputGenerator
OutputGenerator for DOT graphs.
Definition: dot.h:57
cerata::OutputGenerator
Abstract class to generate language specific output from Graphs.
Definition: output.h:38
cerata::Node
A node.
Definition: node.h:42
cerata::dot::Grapher::style
Style style
The style.
Definition: dot.h:33
cerata::dot::Grapher::GenNodes
std::string GenNodes(const Graph &graph, Node::NodeID id, int level=0, bool no_group=false)
Generate nodes.
cerata::dot::Grapher::GenEdges
std::string GenEdges(const Graph &graph, int level=0)
Generate edges.
Definition: dot.cc:46
cerata::Node::NodeID
NodeID
Node type IDs with different properties.
Definition: node.h:45
cerata::dot
Contains everything related to the DOT back-end.
Definition: dot.cc:27
cerata::dot::DOTOutputGenerator::DOTOutputGenerator
DOTOutputGenerator(std::string root_dir, std::vector< OutputSpec > graphs={})
DOTOutputGenerator constructor.
Definition: dot.h:60
cerata::dot::Grapher::GenGraph
std::string GenGraph(const Graph &graph, int level=0)
Generate a graph.
Definition: dot.cc:255
cerata::dot::Style
Dot style configuration.
Definition: style.h:121
cerata::OutputGenerator::OutputGenerator
OutputGenerator(std::string root_dir, std::vector< OutputSpec > outputs={})
Construct an OutputGenerator.
Definition: output.cc:23
cerata::dot::NodeName
std::string NodeName(const Node &node, const std::string &suffix)
Return the DOT name of a node.
Definition: dot.cc:351
cerata::dot::Grapher::drawn_edges
std::vector< Edge * > drawn_edges
Edges that were already drawn.
Definition: dot.h:35