Merge pull request #1085 from YosysHQ/eddie/shregmap_improve
[yosys.git] / passes / cmds / copy.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include "kernel/register.h"
21 #include "kernel/rtlil.h"
22 #include "kernel/log.h"
23
24 USING_YOSYS_NAMESPACE
25 PRIVATE_NAMESPACE_BEGIN
26
27 struct CopyPass : public Pass {
28 CopyPass() : Pass("copy", "copy modules in the design") { }
29 void help() YS_OVERRIDE
30 {
31 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
32 log("\n");
33 log(" copy old_name new_name\n");
34 log("\n");
35 log("Copy the specified module. Note that selection patterns are not supported\n");
36 log("by this command.\n");
37 log("\n");
38 }
39 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
40 {
41 if (args.size() != 3)
42 log_cmd_error("Invalid number of arguments!\n");
43
44 std::string src_name = RTLIL::escape_id(args[1]);
45 std::string trg_name = RTLIL::escape_id(args[2]);
46
47 if (design->modules_.count(src_name) == 0)
48 log_cmd_error("Can't find source module %s.\n", src_name.c_str());
49
50 if (design->modules_.count(trg_name) != 0)
51 log_cmd_error("Target module name %s already exists.\n", trg_name.c_str());
52
53 RTLIL::Module *new_mod = design->module(src_name)->clone();
54 new_mod->name = trg_name;
55 design->add(new_mod);
56 }
57 } CopyPass;
58
59 PRIVATE_NAMESPACE_END