Skip to content

Commit

Permalink
dlsym AST::process PoC
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
  • Loading branch information
tgorochowik committed Jan 26, 2024
1 parent 4d44533 commit 8c4e1ee
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions frontends/systemverilog/uhdm_common_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
*/

#include <dlfcn.h>

#include "uhdm_common_frontend.h"
#include "synlig_edif.h"

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

typedef int (*t_newproc)(RTLIL::Design*, AST::AstNode*, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool);
typedef int (*t_oldproc)(RTLIL::Design*, AST::AstNode*, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool);

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

void UhdmCommonFrontend::print_read_options()
Expand Down Expand Up @@ -151,7 +156,11 @@ void UhdmCommonFrontend::execute(std::istream *&f, std::string filename, std::ve
AST::AstNode *current_ast = parse(filename);

if (current_ast) {
AST::process(design, current_ast,
t_newproc newproc;
newproc = (t_newproc) dlsym(RTLD_DEFAULT, "_ZN5Yosys3AST7processEPNS_5RTLIL6DesignEPNS0_7AstNodeEbbbbbbbbbbbbbbbbbbbbb");
if (newproc != nullptr) {
log_header(design, "!!!!!!!!!!!!!!!!! Running with new Yosys\n");
newproc(design, current_ast,
false, // nodisplay (came with Yosys 0.37)
dump_ast1, //
dump_ast2, //
Expand All @@ -173,7 +182,42 @@ void UhdmCommonFrontend::execute(std::istream *&f, std::string filename, std::ve
false, // overwrite
defer, // defer
default_nettype_wire // autowire
);
);
delete current_ast;
return;
}

t_oldproc oldproc;
oldproc = (t_oldproc) dlsym(RTLD_DEFAULT, "_ZN5Yosys3AST7processEPNS_5RTLIL6DesignEPNS0_7AstNodeEbbbbbbbbbbbbbbbbbbbb");
if (oldproc != nullptr) {
log_header(design, "!!!!!!!!!!!!!!!!! Running with old Yosys\n");
oldproc(design, current_ast,
dump_ast1, //
dump_ast2, //
no_dump_ptr, //
dump_vlog1, //
dump_vlog2, //
dump_rtlil, //
false, // nolatches
false, // nomeminit
false, // nomem2reg
false, // mem2reg
false, // noblackbox
false, // lib
false, // nowb
false, // noopt
false, // icells
false, // pwires
dont_redefine, // nooverwrite
false, // overwrite
defer, // defer
default_nettype_wire // autowire
);
delete current_ast;
return;
}

log_header(design, "No AST::process function found, possibly another change in mainline yosys!");
delete current_ast;
}
}
Expand Down

4 comments on commit 8c4e1ee

@hzeller
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes a particular name-mangeling of the C++ names. Are these standardized ?

@tgorochowik
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be compatible across Linux compilers on x86 (both 32b and 64b). I cannot guarantee other OSes or architectures.
This is only a PoC, it might be good enough for now, but it's probably not universal. That's why I suggested extracting the mangled symbols at compile time if we want to go this route (as the yosys we're building against should be compiled at this point)

@tgorochowik
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. mangling is a convention, it's not guaranteed by the standard, but compilers tend to use common conventions so you can use clang compiled libs with gcc compiled apps etc

@hzeller
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd feel more comfortable if in the build process we generate a C macro which we then can use to #ifdef out the call with the nodisplay macro.
dlsym() also assumes some sort of dynamic linking I suppose which is also not necessarily what everyone is doing.

Please sign in to comment.