Skip to content

Commit

Permalink
Merge pull request Silimate#17 from alaindargelas/rtlil_dump
Browse files Browse the repository at this point in the history
RTLIL Module dump and hash
  • Loading branch information
akashlevy authored Nov 7, 2024
2 parents 37914ff + 43186b2 commit 0d57928
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "backends/rtlil/rtlil_backend.h"

#include <string.h>
#include <strstream>
#include <algorithm>
#include <optional>

Expand Down Expand Up @@ -2508,6 +2509,21 @@ void RTLIL::Module::swap_names(RTLIL::Wire *w1, RTLIL::Wire *w2)
wires_[w2->name] = w2;
}

// Returns the RTLIL dump of a module
std::string RTLIL::Module::rtlil_dump() {
// Sorting the module to have a canonical RTLIL
sort();
// Dumping the RTLIL in an in-memory stringstream
std::stringstream stream;
RTLIL_BACKEND::dump_module(stream, " ", this, design, false, true, false);
return stream.str();
}

// Returns a hash of the RTLIL dump
unsigned int RTLIL::Module::rtlil_hash() {
return hash_ops<std::string>::hash(rtlil_dump());
}

void RTLIL::Module::swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2)
{
log_assert(cells_[c1->name] == c1);
Expand Down
3 changes: 3 additions & 0 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,9 @@ struct RTLIL::Module : public RTLIL::AttrObject
RTLIL::SigSpec OriginalTag (RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const std::string &src = "");
RTLIL::SigSpec FutureFF (RTLIL::IdString name, const RTLIL::SigSpec &sig_e, const std::string &src = "");

std::string rtlil_dump();
unsigned int rtlil_hash();

#ifdef WITH_PYTHON
static std::map<unsigned int, RTLIL::Module*> *get_all_modules(void);
#endif
Expand Down

0 comments on commit 0d57928

Please sign in to comment.