Skip to content

Commit

Permalink
Fork edif pass
Browse files Browse the repository at this point in the history
This allows us to use latest yosys. The upstream edif pass introduced
changes which are incompatible with SystemVerilog.

Signed-off-by: Tomasz Gorochowik <[email protected]>
  • Loading branch information
tgorochowik committed Sep 29, 2023
1 parent 66cf5de commit 5e1a7cc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
3 changes: 3 additions & 0 deletions frontends/systemverilog/uhdm_common_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "uhdm_common_frontend.h"
#include "edif.h"

namespace systemverilog_plugin
{
Expand All @@ -30,6 +31,8 @@ static void set_line_num(int) {}
/* Stub for AST::process */
static int get_line_num(void) { return 1; }

UhdmCommonFrontend::UhdmCommonFrontend(std::string name, std::string short_help) : Frontend(name, short_help) { register_synlig_edif_backend(); }

void UhdmCommonFrontend::print_read_options()
{
log(" -noassert\n");
Expand Down
2 changes: 1 addition & 1 deletion frontends/systemverilog/uhdm_common_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static inline ObjT *make_new_object_with_optional_extra_true_arg(ArgN &&...arg_n
struct UhdmCommonFrontend : public ::Yosys::Frontend {
UhdmAstShared shared;
std::vector<std::string> args;
UhdmCommonFrontend(std::string name, std::string short_help) : Frontend(name, short_help) {}
UhdmCommonFrontend(std::string name, std::string short_help);
virtual void print_read_options();
virtual void help() = 0;
virtual ::Yosys::AST::AstNode *parse(std::string filename) = 0;
Expand Down
29 changes: 22 additions & 7 deletions third_party/yosys_mod/edif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#include "kernel/sigtools.h"
#include <string>

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
namespace systemverilog_plugin
{

using namespace ::Yosys;

#define EDIF_DEF(_id) edif_names(RTLIL::unescape_id(_id), true).c_str()
#define EDIF_DEFR(_id, _ren, _bl, _br) edif_names(RTLIL::unescape_id(_id), true, _ren, _bl, _br).c_str()
Expand Down Expand Up @@ -86,8 +88,8 @@ struct EdifNames {
}
};

struct EdifBackend : public Backend {
EdifBackend() : Backend("edif", "write design to EDIF netlist file") {}
struct SynligEdifBackend : public Backend {
SynligEdifBackend() : Backend("edif", "write design to EDIF netlist file") {}
void help() override
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
Expand Down Expand Up @@ -129,7 +131,7 @@ struct EdifBackend : public Backend {
}
void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
{
log_header(design, "Executing EDIF backend.\n");
log_header(design, "Executing Synlig EDIF backend.\n");
std::string top_module_name;
bool port_rename = false;
bool attr_properties = false;
Expand Down Expand Up @@ -598,6 +600,19 @@ struct EdifBackend : public Backend {

*f << stringf(")\n");
}
} EdifBackend;
};

SynligEdifBackend *seb = NULL;

void register_synlig_edif_backend()
{
if (seb == NULL) {
backend_register.erase("edif");

This comment has been minimized.

Copy link
@hzeller

hzeller Oct 29, 2023

Collaborator

This crashes with an initilization order fiasco when the module is linked to yosys at compile time.

Invoking anything on backend_register is problematic as this variable is declared extern, so it might or might not be initialized at this point. Is there a way to do this safely ?

pass_register.erase("edif");
pass_register.erase("write_edif");
seb = new SynligEdifBackend;
seb->init_register();
}
}

PRIVATE_NAMESPACE_END
} // namespace systemverilog_plugin
4 changes: 4 additions & 0 deletions third_party/yosys_mod/edif.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace systemverilog_plugin
{
void register_synlig_edif_backend();
}

0 comments on commit 5e1a7cc

Please sign in to comment.