diff options
author | Clifford Wolf <clifford@clifford.at> | 2013-05-02 15:27:01 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2013-05-02 15:27:01 +0200 |
commit | 595db0d7b963f8ce11321efeb87767bc9ee2fc4a (patch) | |
tree | 8f01f7a09bec6c3c69a1e661174654960751e56f /kernel | |
parent | 97f783e668015065069fa2b2f85e4cbe518abc26 (diff) | |
download | yosys-595db0d7b963f8ce11321efeb87767bc9ee2fc4a.tar.gz yosys-595db0d7b963f8ce11321efeb87767bc9ee2fc4a.tar.bz2 yosys-595db0d7b963f8ce11321efeb87767bc9ee2fc4a.zip |
Added tcl "yosys -import" command
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/driver.cc | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc index f06c784d8..3de16e724 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -278,6 +278,11 @@ struct TclPass : public Pass { log("This command executes the tcl commands in the specified file.\n"); log("Use 'yosys cmd' to run the yosys command 'cmd' from tcl.\n"); log("\n"); + log("The tcl command 'yosys -import' can be used to import all yosys\n"); + log("commands directly as tcl commands to the tcl shell. The yosys\n"); + log("command 'proc' is wrapped using the tcl command 'procs' in order\n"); + log("to avoid a name collision with the tcl builting command 'proc'.\n"); + log("\n"); } virtual void execute(std::vector<std::string> args, RTLIL::Design *design) { if (args.size() < 2) @@ -289,11 +294,33 @@ struct TclPass : public Pass { } } TclPass; -static int tcl_yosys_cmd(ClientData, Tcl_Interp*, int argc, const char *argv[]) +static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) { std::vector<std::string> args; for (int i = 1; i < argc; i++) args.push_back(argv[i]); + + if (args.size() >= 1 && args[0] == "-import") { + for (auto &it : REGISTER_INTERN::pass_register) { + std::string tcl_command_name = it.first; + if (tcl_command_name == "proc") + tcl_command_name = "procs"; + Tcl_CmdInfo info; + if (Tcl_GetCommandInfo(interp, tcl_command_name.c_str(), &info) != 0) { + log("[TCL: yosys -import] Command name collision: found pre-existing command `%s' -> skip.\n", it.first.c_str()); + } else { + std::string tcl_script = stringf("proc %s args { yosys %s {*}$args }", tcl_command_name.c_str(), it.first.c_str()); + Tcl_Eval(interp, tcl_script.c_str()); + } + } + return TCL_OK; + } + + if (args.size() == 1) { + Pass::call(yosys_tcl_design, args[0]); + return TCL_OK; + } + Pass::call(yosys_tcl_design, args); return TCL_OK; } @@ -397,8 +424,7 @@ int main(int argc, char **argv) fprintf(stderr, " execute the commands in the script file\n"); fprintf(stderr, "\n"); fprintf(stderr, " -c tcl_scriptfile\n"); - fprintf(stderr, " execute the commands in the tcl script file\n"); - fprintf(stderr, " (use 'yosys cmd' to run the yosys command 'cmd' from tcl)\n"); + fprintf(stderr, " execute the commands in the tcl script file (see 'help tcl' for details)\n"); fprintf(stderr, "\n"); fprintf(stderr, " -p command\n"); fprintf(stderr, " execute the commands\n"); |