yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
copy.cc
Go to the documentation of this file.
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 
26 
27 struct CopyPass : public Pass {
28  CopyPass() : Pass("copy", "copy modules in the design") { }
29  virtual void help()
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  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
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 
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: copy.cc:39
void add(RTLIL::Module *module)
Definition: rtlil.cc:259
static std::string escape_id(std::string str)
Definition: rtlil.h:251
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
RTLIL::IdString name
Definition: rtlil.h:599
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
Definition: register.h:27
void log_cmd_error(const char *format,...)
Definition: log.cc:211
CopyPass()
Definition: copy.cc:28
RTLIL::Module * module(RTLIL::IdString name)
Definition: rtlil.cc:254
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
virtual void help()
Definition: copy.cc:29
Definition: copy.cc:27
void log(const char *format,...)
Definition: log.cc:180
CopyPass CopyPass
virtual RTLIL::Module * clone() const
Definition: rtlil.cc:1061