39 #include <igraph/igraph.h>
47 const char *shape_of(
const Gate *gate )
70 std::string quoted(
const std::string &text )
72 std::string result =
"\"";
73 for(
const char character : text )
75 if( character ==
'"' || character ==
'\\' )
85 std::string number(
const double value )
88 const auto [end,
error] = std::to_chars( text, text +
sizeof( text ), value );
94 const std::string &pathname,
95 const std::optional<std::string> &x_key,
96 const std::optional<std::string> &y_key )
98 if( x_key.has_value() != y_key.has_value() )
100 return ERR(
"couldn't export clock tree to '" + pathname +
"': give both coordinate keys or none" );
103 std::ofstream dot_file( pathname );
106 return ERR(
"couldn't export clock tree to '" + pathname +
"'" );
109 dot_file <<
"digraph {\n"
110 <<
" comment=\"created by HAL plugin clock_tree_extractor\"\n"
111 <<
" node [color=black fontcolor=black]\n"
112 <<
" edge [color=black]\n";
114 const igraph_t *graph = clock_tree.
get_igraph();
115 const igraph_int_t vertex_count = igraph_vcount( graph );
118 std::vector<std::string> node_ids( vertex_count );
119 u32 gates_without_coordinates = 0;
121 for( igraph_int_t vertex = 0; vertex < vertex_count; vertex++ )
124 if(
object.is_error() )
126 return ERR_APPEND(
object.get_error(),
"couldn't export clock tree to '" + pathname +
"'" );
128 const auto [ptr,
type] =
object.get();
133 const Net *
net =
static_cast<const Net *
>( ptr );
134 node_ids[vertex] =
"net_" + std::to_string(
net->get_id() );
135 dot_file <<
" " << node_ids[vertex] <<
" [label=" << quoted(
net->get_name() ) <<
" shape=circle];\n";
139 const Gate *gate =
static_cast<const Gate *
>( ptr );
140 node_ids[vertex] = std::to_string( gate->
get_id() );
141 dot_file <<
" " << node_ids[vertex] <<
" [instance=" << quoted( gate->
get_name() )
142 <<
" type=" << quoted( gate->
get_type()->
get_name() ) <<
" shape=" << shape_of( gate );
147 dot_file <<
" label=\"¬ " << node_ids[vertex] <<
"\"";
151 dot_file <<
" label=\"Δ " << node_ids[vertex] <<
"\"";
155 std::optional<double>
x;
156 std::optional<double>
y;
157 if( x_key.has_value() )
168 if(
x.has_value() &&
y.has_value() )
170 dot_file <<
" x=" << number( *
x ) <<
" y=" << number( *
y );
174 gates_without_coordinates++;
181 const igraph_int_t edge_count = igraph_ecount( graph );
182 for( igraph_int_t edge = 0; edge < edge_count; edge++ )
186 igraph_edge( graph, edge, &from, &
to );
187 dot_file <<
" " << node_ids[from] <<
" -> " << node_ids[
to] <<
";\n";
194 return ERR(
"couldn't write clock tree to '" + pathname +
"'" );
197 if( x_key.has_value() && gates_without_coordinates > 0 )
200 "no valid coordinates in parameters '{}' and '{}' for {} gate(s)",
203 gates_without_coordinates );
i32 get_location_x() const
i32 get_location_y() const
GateType * get_type() const
const std::string & get_name() const
bool has_location() const
const std::string & get_name() const
const igraph_t * get_igraph() const
Result< std::pair< const void *, PtrType > > get_ptr_from_vertex(igraph_int_t vertex) const
#define log_warning(channel,...)
#define ERR_APPEND(prev_error, message)
bool is_delay(const Gate *gate)
bool is_mux(const Gate *gate)
bool is_inverter(const Gate *gate)
bool is_buffer(const Gate *gate)
bool is_pll(const Gate *gate)
std::optional< double > read_parameter_coordinate(const Gate *gate, const std::string &name)
Result< std::monostate > export_dot(const ClockTree &clock_tree, const std::string &pathname, const std::optional< std::string > &x_key=std::nullopt, const std::optional< std::string > &y_key=std::nullopt)
bool is_ff(const Gate *gate)
bool is_oscillator(const Gate *gate)