2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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.
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.
20 #include "kernel/register.h"
21 #include "kernel/rtlil.h"
22 #include "kernel/log.h"
25 PRIVATE_NAMESPACE_BEGIN
27 struct CopyPass
: public Pass
{
28 CopyPass() : Pass("copy", "copy modules in the design") { }
29 void help() YS_OVERRIDE
31 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
33 log(" copy old_name new_name\n");
35 log("Copy the specified module. Note that selection patterns are not supported\n");
36 log("by this command.\n");
39 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
42 log_cmd_error("Invalid number of arguments!\n");
44 std::string src_name
= RTLIL::escape_id(args
[1]);
45 std::string trg_name
= RTLIL::escape_id(args
[2]);
47 if (design
->modules_
.count(src_name
) == 0)
48 log_cmd_error("Can't find source module %s.\n", src_name
.c_str());
50 if (design
->modules_
.count(trg_name
) != 0)
51 log_cmd_error("Target module name %s already exists.\n", trg_name
.c_str());
53 RTLIL::Module
*new_mod
= design
->module(src_name
)->clone();
54 new_mod
->name
= trg_name
;