mirror of
https://github.com/verilator/verilator.git
synced 2026-09-02 10:48:27 +02:00
clang-format remaining sources. No functional change.
This commit is contained in:
+89
-95
@@ -34,13 +34,17 @@ int V3Graph::debug() { return std::max(V3Error::debugDefault(), s_debug); }
|
||||
// Vertices
|
||||
|
||||
V3GraphVertex::V3GraphVertex(V3Graph* graphp, const V3GraphVertex& old)
|
||||
: m_fanout(old.m_fanout), m_color(old.m_color), m_rank(old.m_rank) {
|
||||
: m_fanout(old.m_fanout)
|
||||
, m_color(old.m_color)
|
||||
, m_rank(old.m_rank) {
|
||||
m_userp = NULL;
|
||||
verticesPushBack(graphp);
|
||||
}
|
||||
|
||||
V3GraphVertex::V3GraphVertex(V3Graph* graphp)
|
||||
: m_fanout(0), m_color(0), m_rank(0) {
|
||||
: m_fanout(0)
|
||||
, m_color(0)
|
||||
, m_rank(0) {
|
||||
m_userp = NULL;
|
||||
verticesPushBack(graphp);
|
||||
}
|
||||
@@ -68,13 +72,13 @@ void V3GraphVertex::unlinkDelete(V3Graph* graphp) {
|
||||
// Unlink from vertex list
|
||||
m_vertices.unlink(graphp->m_vertices, this);
|
||||
// Delete
|
||||
delete this; //this=NULL;
|
||||
delete this; // this=NULL;
|
||||
}
|
||||
|
||||
void V3GraphVertex::rerouteEdges(V3Graph* graphp) {
|
||||
// Make new edges for each from/to pair
|
||||
for (V3GraphEdge* iedgep = inBeginp(); iedgep; iedgep=iedgep->inNextp()) {
|
||||
for (V3GraphEdge* oedgep = outBeginp(); oedgep; oedgep=oedgep->outNextp()) {
|
||||
for (V3GraphEdge* iedgep = inBeginp(); iedgep; iedgep = iedgep->inNextp()) {
|
||||
for (V3GraphEdge* oedgep = outBeginp(); oedgep; oedgep = oedgep->outNextp()) {
|
||||
new V3GraphEdge(graphp, iedgep->fromp(), oedgep->top(),
|
||||
std::min(iedgep->weight(), oedgep->weight()),
|
||||
iedgep->cutable() && oedgep->cutable());
|
||||
@@ -84,13 +88,8 @@ void V3GraphVertex::rerouteEdges(V3Graph* graphp) {
|
||||
unlinkEdges(graphp);
|
||||
}
|
||||
|
||||
bool V3GraphVertex::inSize1() const {
|
||||
return !inEmpty() && inBeginp()->inNextp()==NULL;
|
||||
}
|
||||
|
||||
bool V3GraphVertex::outSize1() const {
|
||||
return !outEmpty() && outBeginp()->outNextp()==NULL;
|
||||
}
|
||||
bool V3GraphVertex::inSize1() const { return !inEmpty() && !inBeginp()->inNextp(); }
|
||||
bool V3GraphVertex::outSize1() const { return !outEmpty() && !outBeginp()->outNextp(); }
|
||||
|
||||
uint32_t V3GraphVertex::inHash() const {
|
||||
// We want the same hash ignoring the order of edges.
|
||||
@@ -98,7 +97,7 @@ uint32_t V3GraphVertex::inHash() const {
|
||||
// However with XOR multiple edges to the same source will cancel out,
|
||||
// so we use ADD. (Generally call this only after removing duplicates though)
|
||||
uint32_t hash = 0;
|
||||
for (V3GraphEdge* edgep = this->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
for (V3GraphEdge* edgep = this->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||
hash += cvtToHash(edgep->fromp());
|
||||
}
|
||||
return hash;
|
||||
@@ -106,14 +105,13 @@ uint32_t V3GraphVertex::inHash() const {
|
||||
|
||||
uint32_t V3GraphVertex::outHash() const {
|
||||
uint32_t hash = 0;
|
||||
for (V3GraphEdge* edgep = this->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
for (V3GraphEdge* edgep = this->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
hash += cvtToHash(edgep->top());
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
V3GraphEdge* V3GraphVertex::findConnectingEdgep(GraphWay way,
|
||||
const V3GraphVertex* waywardp) {
|
||||
V3GraphEdge* V3GraphVertex::findConnectingEdgep(GraphWay way, const V3GraphVertex* waywardp) {
|
||||
// O(edges) linear search. Searches search both nodes' edge lists in
|
||||
// parallel. The lists probably aren't _both_ huge, so this is
|
||||
// unlikely to blow up even on fairly nasty graphs.
|
||||
@@ -131,10 +129,10 @@ V3GraphEdge* V3GraphVertex::findConnectingEdgep(GraphWay way,
|
||||
|
||||
void V3GraphVertex::v3errorEnd(std::ostringstream& str) const {
|
||||
std::ostringstream nsstr;
|
||||
nsstr<<str.str();
|
||||
nsstr << str.str();
|
||||
if (debug()) {
|
||||
nsstr<<endl;
|
||||
nsstr<<"-vertex: "<<this<<endl;
|
||||
nsstr << endl;
|
||||
nsstr << "-vertex: " << this << endl;
|
||||
}
|
||||
if (!fileline()) {
|
||||
V3Error::v3errorEnd(nsstr);
|
||||
@@ -143,14 +141,16 @@ void V3GraphVertex::v3errorEnd(std::ostringstream& str) const {
|
||||
}
|
||||
}
|
||||
void V3GraphVertex::v3errorEndFatal(std::ostringstream& str) const {
|
||||
v3errorEnd(str); assert(0); VL_UNREACHABLE
|
||||
v3errorEnd(str);
|
||||
assert(0);
|
||||
VL_UNREACHABLE
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, V3GraphVertex* vertexp) {
|
||||
os<<" VERTEX="<<vertexp->name();
|
||||
if (vertexp->rank()) os<<" r"<<vertexp->rank();
|
||||
if (vertexp->fanout()!=0.0) os<<" f"<<vertexp->fanout();
|
||||
if (vertexp->color()) os<<" c"<<vertexp->color();
|
||||
os << " VERTEX=" << vertexp->name();
|
||||
if (vertexp->rank()) os << " r" << vertexp->rank();
|
||||
if (vertexp->fanout() != 0.0) os << " f" << vertexp->fanout();
|
||||
if (vertexp->color()) os << " c" << vertexp->color();
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -158,8 +158,7 @@ std::ostream& operator<<(std::ostream& os, V3GraphVertex* vertexp) {
|
||||
//######################################################################
|
||||
// Edges
|
||||
|
||||
void V3GraphEdge::init(V3Graph* graphp,
|
||||
V3GraphVertex* fromp, V3GraphVertex* top, int weight,
|
||||
void V3GraphEdge::init(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top, int weight,
|
||||
bool cutable) {
|
||||
UASSERT(fromp, "Null from pointer");
|
||||
UASSERT(top, "Null to pointer");
|
||||
@@ -174,7 +173,7 @@ void V3GraphEdge::init(V3Graph* graphp,
|
||||
}
|
||||
|
||||
V3GraphEdge* V3GraphEdge::relinkFromp(V3GraphVertex* newFromp) {
|
||||
V3GraphEdge *oldNxt = outNextp();
|
||||
V3GraphEdge* oldNxt = outNextp();
|
||||
m_outs.unlink(m_fromp->m_outs, this);
|
||||
m_fromp = newFromp;
|
||||
outPushBack();
|
||||
@@ -187,7 +186,7 @@ void V3GraphEdge::unlinkDelete() {
|
||||
// Unlink to side
|
||||
m_ins.unlink(m_top->m_ins, this);
|
||||
// Delete
|
||||
delete this; //this=NULL;
|
||||
delete this; // this=NULL;
|
||||
}
|
||||
|
||||
void V3GraphEdge::outPushBack() {
|
||||
@@ -210,14 +209,12 @@ V3Graph::V3Graph() {
|
||||
verticesUnlink();
|
||||
}
|
||||
|
||||
V3Graph::~V3Graph() {
|
||||
clear();
|
||||
}
|
||||
V3Graph::~V3Graph() { clear(); }
|
||||
|
||||
void V3Graph::clear() {
|
||||
// Empty it of all points, as if making a new object
|
||||
// Delete the old edges
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; /*BELOW*/) {
|
||||
V3GraphEdge* nextp = edgep->outNextp();
|
||||
VL_DO_DANGLING(delete edgep, edgep);
|
||||
@@ -241,7 +238,7 @@ void V3Graph::userClearVertices() {
|
||||
// the graph pointer given a vertex.) For now we don't call this often, and
|
||||
// the extra code on each read of user() would probably slow things
|
||||
// down more than help.
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
vertexp->user(0);
|
||||
vertexp->userp(NULL); // Its a union, but might be different size than user()
|
||||
}
|
||||
@@ -249,8 +246,8 @@ void V3Graph::userClearVertices() {
|
||||
|
||||
void V3Graph::userClearEdges() {
|
||||
// Clear user() in all of tree
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
edgep->user(0);
|
||||
edgep->userp(NULL); // Its a union, but might be different size than user()
|
||||
}
|
||||
@@ -259,7 +256,7 @@ void V3Graph::userClearEdges() {
|
||||
|
||||
void V3Graph::clearColors() {
|
||||
// Reset colors
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
vertexp->m_color = 0;
|
||||
}
|
||||
}
|
||||
@@ -268,72 +265,70 @@ void V3Graph::clearColors() {
|
||||
// Dumping
|
||||
|
||||
void V3Graph::loopsMessageCb(V3GraphVertex* vertexp) {
|
||||
vertexp->v3fatalSrc("Loops detected in graph: "<<vertexp);
|
||||
vertexp->v3fatalSrc("Loops detected in graph: " << vertexp);
|
||||
}
|
||||
|
||||
void V3Graph::loopsVertexCb(V3GraphVertex* vertexp) {
|
||||
// Needed here as V3GraphVertex<< isn't defined until later in header
|
||||
if (debug()) std::cerr<<"-Info-Loop: "<<cvtToHex(vertexp)<<" "<<vertexp<<endl;
|
||||
if (debug()) std::cerr << "-Info-Loop: " << cvtToHex(vertexp) << " " << vertexp << endl;
|
||||
}
|
||||
|
||||
void V3Graph::dump(std::ostream& os) {
|
||||
// This generates a file used by graphviz, https://www.graphviz.org
|
||||
os<<" Graph:\n";
|
||||
os << " Graph:\n";
|
||||
// Print vertices
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
os<<"\tNode: "<<vertexp->name();
|
||||
if (vertexp->color()) os<<" color="<<vertexp->color();
|
||||
os<<endl;
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
os << "\tNode: " << vertexp->name();
|
||||
if (vertexp->color()) os << " color=" << vertexp->color();
|
||||
os << endl;
|
||||
// Print edges
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||
dumpEdge(os, vertexp, edgep);
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
dumpEdge(os, vertexp, edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void V3Graph::dumpEdge(std::ostream& os, V3GraphVertex* vertexp, V3GraphEdge* edgep) {
|
||||
if (edgep->weight()
|
||||
&& (edgep->fromp() == vertexp
|
||||
|| edgep->top() == vertexp)) {
|
||||
os<<"\t\t";
|
||||
if (edgep->fromp() == vertexp) os << "-> "<<edgep->top()->name();
|
||||
if (edgep->top() == vertexp) os << "<- "<<edgep->fromp()->name();
|
||||
if (edgep->cutable()) os<<" [CUTABLE]";
|
||||
os<<endl;
|
||||
if (edgep->weight() && (edgep->fromp() == vertexp || edgep->top() == vertexp)) {
|
||||
os << "\t\t";
|
||||
if (edgep->fromp() == vertexp) os << "-> " << edgep->top()->name();
|
||||
if (edgep->top() == vertexp) os << "<- " << edgep->fromp()->name();
|
||||
if (edgep->cutable()) os << " [CUTABLE]";
|
||||
os << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void V3Graph::dumpDotFilePrefixed(const string& nameComment, bool colorAsSubgraph) const {
|
||||
if (v3Global.opt.dumpTree()) {
|
||||
dumpDotFile(v3Global.debugFilename(nameComment)+".dot", colorAsSubgraph);
|
||||
dumpDotFile(v3Global.debugFilename(nameComment) + ".dot", colorAsSubgraph);
|
||||
}
|
||||
}
|
||||
|
||||
//! Variant of dumpDotFilePrefixed without --dump option check
|
||||
void V3Graph::dumpDotFilePrefixedAlways(const string& nameComment, bool colorAsSubgraph) const {
|
||||
dumpDotFile(v3Global.debugFilename(nameComment)+".dot", colorAsSubgraph);
|
||||
dumpDotFile(v3Global.debugFilename(nameComment) + ".dot", colorAsSubgraph);
|
||||
}
|
||||
|
||||
void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
|
||||
// This generates a file used by graphviz, https://www.graphviz.org
|
||||
// "hardcoded" parameters:
|
||||
const vl_unique_ptr<std::ofstream> logp (V3File::new_ofstream(filename));
|
||||
if (logp->fail()) v3fatal("Can't write "<<filename);
|
||||
const vl_unique_ptr<std::ofstream> logp(V3File::new_ofstream(filename));
|
||||
if (logp->fail()) v3fatal("Can't write " << filename);
|
||||
|
||||
// Header
|
||||
*logp<<"digraph v3graph {\n";
|
||||
*logp<<"\tgraph\t[label=\""<<filename<<"\",\n";
|
||||
*logp<<"\t\t labelloc=t, labeljust=l,\n";
|
||||
*logp<<"\t\t //size="<<"\"7.5,10\","<<"\n";
|
||||
*logp<<"\t\t rankdir="<<dotRankDir()<<"];\n";
|
||||
*logp << "digraph v3graph {\n";
|
||||
*logp << "\tgraph\t[label=\"" << filename << "\",\n";
|
||||
*logp << "\t\t labelloc=t, labeljust=l,\n";
|
||||
*logp << "\t\t //size=\"7.5,10\",\n";
|
||||
*logp << "\t\t rankdir=" << dotRankDir() << "];\n";
|
||||
|
||||
// List of all possible subgraphs
|
||||
typedef std::multimap<string,V3GraphVertex*> SubgraphMmap;
|
||||
typedef std::multimap<string, V3GraphVertex*> SubgraphMmap;
|
||||
SubgraphMmap subgraphs;
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
string vertexSubgraph
|
||||
= (colorAsSubgraph && vertexp->color()) ? cvtToStr(vertexp->color()) : "";
|
||||
subgraphs.insert(make_pair(vertexSubgraph, vertexp));
|
||||
@@ -341,7 +336,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
|
||||
|
||||
// We use a map here, as we don't want to corrupt anything (userp) in the graph,
|
||||
// and we don't care if this is slow.
|
||||
std::map<V3GraphVertex*,int> numMap;
|
||||
std::map<V3GraphVertex*, int> numMap;
|
||||
|
||||
// Print vertices
|
||||
int n = 0;
|
||||
@@ -351,42 +346,41 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
|
||||
V3GraphVertex* vertexp = it->second;
|
||||
numMap[vertexp] = n;
|
||||
if (subgr != vertexSubgraph) {
|
||||
if (subgr!="") *logp<<"\t};\n";
|
||||
if (subgr != "") *logp << "\t};\n";
|
||||
subgr = vertexSubgraph;
|
||||
if (subgr!="") *logp<<"\tsubgraph cluster_"<<subgr<<" {\n";
|
||||
if (subgr != "") *logp << "\tsubgraph cluster_" << subgr << " {\n";
|
||||
}
|
||||
if (subgr!="") *logp<<"\t";
|
||||
*logp<<"\tn"<<vertexp->dotName()<<(n++)
|
||||
<<"\t[fontsize=8 "
|
||||
<<"label=\""<<(vertexp->name()!="" ? vertexp->name() : "\\N");
|
||||
if (vertexp->rank()) *logp<<" r"<<vertexp->rank();
|
||||
if (vertexp->fanout()!=0.0) *logp<<" f"<<vertexp->fanout();
|
||||
if (vertexp->color()) *logp<<"\\n c"<<vertexp->color();
|
||||
*logp<<"\"";
|
||||
*logp<<", color="<<vertexp->dotColor();
|
||||
if (vertexp->dotStyle()!="") *logp<<", style="<<vertexp->dotStyle();
|
||||
if (vertexp->dotShape()!="") *logp<<", shape="<<vertexp->dotShape();
|
||||
*logp<<"];\n";
|
||||
if (subgr != "") *logp << "\t";
|
||||
*logp << "\tn" << vertexp->dotName() << (n++) << "\t[fontsize=8 "
|
||||
<< "label=\"" << (vertexp->name() != "" ? vertexp->name() : "\\N");
|
||||
if (vertexp->rank()) *logp << " r" << vertexp->rank();
|
||||
if (vertexp->fanout() != 0.0) *logp << " f" << vertexp->fanout();
|
||||
if (vertexp->color()) *logp << "\\n c" << vertexp->color();
|
||||
*logp << "\"";
|
||||
*logp << ", color=" << vertexp->dotColor();
|
||||
if (vertexp->dotStyle() != "") *logp << ", style=" << vertexp->dotStyle();
|
||||
if (vertexp->dotShape() != "") *logp << ", shape=" << vertexp->dotShape();
|
||||
*logp << "];\n";
|
||||
}
|
||||
if (subgr!="") *logp<<"\t};\n";
|
||||
if (subgr != "") *logp << "\t};\n";
|
||||
|
||||
// Print edges
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
if (edgep->weight()) {
|
||||
int fromVnum = numMap[edgep->fromp()];
|
||||
int toVnum = numMap[edgep->top()];
|
||||
*logp<<"\tn"<<edgep->fromp()->dotName()<<fromVnum
|
||||
<<" -> n"<<edgep->top()->dotName()<<toVnum
|
||||
<<" ["
|
||||
//<<"fontsize=8 label=\""<<(edgep->name()!="" ? edgep->name() : "\\E")<<"\""
|
||||
<<"fontsize=8 label=\""
|
||||
<<(edgep->dotLabel()!="" ? edgep->dotLabel() : "")<<"\""
|
||||
<<" weight="<<edgep->weight()
|
||||
<<" color="<<edgep->dotColor();
|
||||
if (edgep->dotStyle()!="") *logp<<" style="<<edgep->dotStyle();
|
||||
//if (edgep->cutable()) { *logp<<",constraint=false"; } // to rank without following edges
|
||||
*logp<<"];\n";
|
||||
int toVnum = numMap[edgep->top()];
|
||||
*logp << "\tn" << edgep->fromp()->dotName() << fromVnum << " -> n"
|
||||
<< edgep->top()->dotName() << toVnum
|
||||
<< " ["
|
||||
//<<"fontsize=8 label=\""<<(edgep->name()!="" ? edgep->name() : "\\E")<<"\""
|
||||
<< "fontsize=8 label=\""
|
||||
<< (edgep->dotLabel() != "" ? edgep->dotLabel() : "") << "\""
|
||||
<< " weight=" << edgep->weight() << " color=" << edgep->dotColor();
|
||||
if (edgep->dotStyle() != "") *logp << " style=" << edgep->dotStyle();
|
||||
// if (edgep->cutable()) { *logp<<",constraint=false"; } // to rank without
|
||||
// following edges
|
||||
*logp << "];\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,5 +390,5 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
|
||||
*logp << "}\n";
|
||||
logp->close();
|
||||
|
||||
cout << "dot -Tpdf -o ~/a.pdf "<<filename<<endl;
|
||||
cout << "dot -Tpdf -o ~/a.pdf " << filename << endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user