yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hilomap.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 static std::string hicell_celltype, hicell_portname;
28 static std::string locell_celltype, locell_portname;
29 static bool singleton_mode;
30 
33 
35 {
36  for (auto &bit : sig) {
37  if (bit == RTLIL::State::S1 && !hicell_celltype.empty()) {
38  if (!singleton_mode || last_hi == RTLIL::State::Sm) {
39  last_hi = module->addWire(NEW_ID);
41  cell->setPort(RTLIL::escape_id(hicell_portname), last_hi);
42  }
43  bit = last_hi;
44  }
45  if (bit == RTLIL::State::S0 && !locell_celltype.empty()) {
46  if (!singleton_mode || last_lo == RTLIL::State::Sm) {
47  last_lo = module->addWire(NEW_ID);
49  cell->setPort(RTLIL::escape_id(locell_portname), last_lo);
50  }
51  bit = last_lo;
52  }
53  }
54 }
55 
56 struct HilomapPass : public Pass {
57  HilomapPass() : Pass("hilomap", "technology mapping of constant hi- and/or lo-drivers") { }
58  virtual void help()
59  {
60  log("\n");
61  log(" hilomap [options] [selection]\n");
62  log("\n");
63  log("Map constants to 'tielo' and 'tiehi' driver cells.\n");
64  log("\n");
65  log(" -hicell <celltype> <portname>\n");
66  log(" Replace constant hi bits with this cell.\n");
67  log("\n");
68  log(" -locell <celltype> <portname>\n");
69  log(" Replace constant lo bits with this cell.\n");
70  log("\n");
71  log(" -singleton\n");
72  log(" Create only one hi/lo cell and connect all constant bits\n");
73  log(" to that cell. Per default a separate cell is created for\n");
74  log(" each constant bit.\n");
75  log("\n");
76  }
77  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
78  {
79  log_header("Executing HILOMAP pass (mapping to constant drivers).\n");
80 
81  hicell_celltype = std::string();
82  hicell_portname = std::string();
83  locell_celltype = std::string();
84  locell_portname = std::string();
85  singleton_mode = false;
86 
87  size_t argidx;
88  for (argidx = 1; argidx < args.size(); argidx++)
89  {
90  if (args[argidx] == "-hicell" && argidx+2 < args.size()) {
91  hicell_celltype = args[++argidx];
92  hicell_portname = args[++argidx];
93  continue;
94  }
95  if (args[argidx] == "-locell" && argidx+2 < args.size()) {
96  locell_celltype = args[++argidx];
97  locell_portname = args[++argidx];
98  continue;
99  }
100  if (args[argidx] == "-singleton") {
101  singleton_mode = true;
102  continue;
103  }
104  break;
105  }
106  extra_args(args, argidx, design);
107 
108  for (auto &it : design->modules_)
109  {
110  module = it.second;
111 
112  if (!design->selected(module))
113  continue;
114 
115  last_hi = RTLIL::State::Sm;
116  last_lo = RTLIL::State::Sm;
117 
119  }
120  }
121 } HilomapPass;
122 
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN std::string hicell_portname
Definition: hilomap.cc:27
bool selected(T1 *module) const
Definition: rtlil.h:551
HilomapPass HilomapPass
static bool singleton_mode
Definition: hilomap.cc:29
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void log_header(const char *format,...)
Definition: log.cc:188
static RTLIL::SigBit last_lo
Definition: hilomap.cc:32
void rewrite_sigspecs(T functor)
Definition: rtlil.h:1166
HilomapPass()
Definition: hilomap.cc:57
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN std::string hicell_celltype
Definition: hilomap.cc:27
virtual void help()
Definition: hilomap.cc:58
static std::string locell_portname
Definition: hilomap.cc:28
static std::string escape_id(std::string str)
Definition: rtlil.h:251
static RTLIL::SigBit last_hi
Definition: hilomap.cc:32
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: hilomap.cc:77
void hilomap_worker(RTLIL::SigSpec &sig)
Definition: hilomap.cc:34
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
#define NEW_ID
Definition: yosys.h:166
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
Definition: register.h:27
static RTLIL::Module * module
Definition: hilomap.cc:31
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
void log(const char *format,...)
Definition: log.cc:180
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
Definition: register.cc:128
static std::string locell_celltype
Definition: hilomap.cc:28