From b380af9d6d49ad4a7a944eb02abd3fa222f383a3 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 6 Mar 2013 11:58:07 +0100 Subject: [PATCH] Added support for loadable modules (aka plugins) --- .gitignore | 2 ++ Makefile | 13 +++++++++---- kernel/driver.cc | 31 +++++++++++++++++++++++-------- yosys-config.in | 30 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 yosys-config.in diff --git a/.gitignore b/.gitignore index ed71c7845..1d44e72ac 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,7 @@ qtcreator.includes qtcreator.config qtcreator.creator qtcreator.creator.user +Makefile.conf filterlib yosys +yosys-config diff --git a/Makefile b/Makefile index 392d50f6b..f8ba724cd 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,13 @@ OBJS += libs/sha1/sha1.o OBJS += libs/subcircuit/subcircuit.o GENFILES = -TARGETS = yosys +TARGETS = yosys yosys-config all: top-all -CXXFLAGS = -Wall -Wextra -ggdb -I$(shell pwd) -MD -D_YOSYS_ -LDFLAGS = -LDLIBS = -lstdc++ -lreadline -lm +CXXFLAGS = -Wall -Wextra -ggdb -I"$(shell pwd)" -MD -D_YOSYS_ -fPIC +LDFLAGS = -rdynamic +LDLIBS = -lstdc++ -lreadline -lm -ldl -include Makefile.conf @@ -47,6 +47,10 @@ top-all: $(TARGETS) yosys: $(OBJS) $(CXX) -o yosys $(LDFLAGS) $(OBJS) $(LDLIBS) +yosys-config: yosys-config.in + sed 's,@CXX@,$(CXX),; s,@CXXFLAGS@,$(CXXFLAGS),; s,@LDFLAGS@,$(LDFLAGS),; s,@LDLIBS@,$(LDLIBS),;' < yosys-config.in > yosys-config + chmod +x yosys-config + test: yosys cd tests/simple && bash run-test.sh cd tests/hana && bash run-test.sh @@ -54,6 +58,7 @@ test: yosys install: yosys install yosys /usr/local/bin/yosys + install yosys-config /usr/local/bin/yosys-config clean: rm -f $(OBJS) $(GENFILES) $(TARGETS) diff --git a/kernel/driver.cc b/kernel/driver.cc index 8a5cb8223..8ba0283f4 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -26,6 +26,7 @@ #include "kernel/log.h" #include #include +#include static void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command) { @@ -224,21 +225,23 @@ int main(int argc, char **argv) std::string frontend_command = "auto"; std::string backend_command = "auto"; std::vector passes_commands; + std::vector loaded_modules; std::string output_filename = "-"; std::string scriptfile = ""; bool got_output_filename = false; - Pass::init_register(); - - RTLIL::Design *design = new RTLIL::Design; - design->selection_stack.push_back(RTLIL::Selection()); - log_push(); - int opt; - while ((opt = getopt(argc, argv, "f:b:o:p:l:qts:")) != -1) + while ((opt = getopt(argc, argv, "m:f:b:o:p:l:qts:")) != -1) { switch (opt) { + case 'm': + loaded_modules.push_back(dlopen(optarg, RTLD_LAZY|RTLD_GLOBAL)); + if (loaded_modules.back() == NULL) { + fprintf(stderr, "Can't load module `%s'!\n", optarg); + exit(1); + } + break; case 'f': frontend_command = optarg; break; @@ -271,7 +274,7 @@ int main(int argc, char **argv) default: fprintf(stderr, "\n"); fprintf(stderr, "Usage: %s [-q] [-t] [-l logfile] [-o ] [-f ] [-s ]\n", argv[0]); - fprintf(stderr, " %*s[-p [-p ..]] [-b ] [ [..]]\n", int(strlen(argv[0])+1), ""); + fprintf(stderr, " %*s[-p [-p ..]] [-b ] [-m ] [ [..]]\n", int(strlen(argv[0])+1), ""); fprintf(stderr, "\n"); fprintf(stderr, " -q\n"); fprintf(stderr, " quiet operation. only write error messages to console\n"); @@ -297,6 +300,9 @@ int main(int argc, char **argv) fprintf(stderr, " -p command\n"); fprintf(stderr, " execute the commands\n"); fprintf(stderr, "\n"); + fprintf(stderr, " -m module_file\n"); + fprintf(stderr, " load the specified module (aka plugin)\n"); + fprintf(stderr, "\n"); fprintf(stderr, "For more complex synthesis jobs it is recommended to use the read_* and write_*\n"); fprintf(stderr, "commands in a script file instead of specifying input and output files on the\n"); fprintf(stderr, "command line.\n"); @@ -334,6 +340,12 @@ int main(int argc, char **argv) log(" \\-----------------------------------------------------------------------------/\n"); log("\n"); + Pass::init_register(); + + RTLIL::Design *design = new RTLIL::Design; + design->selection_stack.push_back(RTLIL::Selection()); + log_push(); + if (optind == argc && passes_commands.size() == 0 && scriptfile.empty()) { if (!got_output_filename) backend_command = ""; @@ -365,6 +377,9 @@ int main(int argc, char **argv) Pass::done_register(); + for (auto mod : loaded_modules) + dlclose(mod); + return 0; } diff --git a/yosys-config.in b/yosys-config.in new file mode 100644 index 000000000..d67d881c3 --- /dev/null +++ b/yosys-config.in @@ -0,0 +1,30 @@ +#!/bin/sh + +help() { + { echo; echo "Usage: $0 { --cxx | --cxxflags | --ldflags | --ldlibs }"; } >&2 + exit 1 +} + +if [ $# -eq 0 ]; then + help +fi + +for opt; do + case "$opt" in + --cxx) + echo -n '@CXX@ ' ;; + --cxxflags) + echo -n '@CXXFLAGS@ ' ;; + --ldflags) + echo -n '@LDFLAGS@ ' ;; + --ldlibs) + echo -n '@LDLIBS@ ' ;; + --help|-\?) + help ;; + *) + echo -n "$opt " + esac +done +echo + +exit 0