yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
synth.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/celltypes.h"
22 #include "kernel/rtlil.h"
23 #include "kernel/log.h"
24 
27 
28 bool check_label(bool &active, std::string run_from, std::string run_to, std::string label)
29 {
30  if (!run_from.empty() && run_from == run_to) {
31  active = (label == run_from);
32  } else {
33  if (label == run_from)
34  active = true;
35  if (label == run_to)
36  active = false;
37  }
38  return active;
39 }
40 
41 struct SynthPass : public Pass {
42  SynthPass() : Pass("synth", "generic synthesis script") { }
43  virtual void help()
44  {
45  // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
46  log("\n");
47  log(" synth [options]\n");
48  log("\n");
49  log("This command runs the default synthesis script. This command does not operate\n");
50  log("on partly selected designs.\n");
51  log("\n");
52  log(" -top <module>\n");
53  log(" use the specified module as top module (default='top')\n");
54  log("\n");
55  log(" -run <from_label>[:<to_label>]\n");
56  log(" only run the commands between the labels (see below). an empty\n");
57  log(" from label is synonymous to 'begin', and empty to label is\n");
58  log(" synonymous to the end of the command list.\n");
59  log("\n");
60  log("\n");
61  log("The following commands are executed by this synthesis command:\n");
62  log("\n");
63  log(" begin:\n");
64  log(" hierarchy -check [-top <top>]\n");
65  log("\n");
66  log(" coarse:\n");
67  log(" proc\n");
68  log(" opt\n");
69  log(" wreduce\n");
70  log(" alumacc\n");
71  log(" share\n");
72  log(" opt\n");
73  log(" fsm\n");
74  log(" opt -fast\n");
75  log(" memory -nomap\n");
76  log(" opt_clean\n");
77  log("\n");
78  log(" fine:\n");
79  log(" opt -fast -full\n");
80  log(" memory_map\n");
81  log(" opt -full\n");
82  log(" techmap\n");
83  log(" opt -fast\n");
84  #ifdef YOSYS_ENABLE_ABC
85  log("\n");
86  log(" abc:\n");
87  log(" abc -fast\n");
88  log(" opt -fast\n");
89  #endif
90  log("\n");
91  }
92  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
93  {
94  std::string top_module;
95  std::string run_from, run_to;
96 
97  size_t argidx;
98  for (argidx = 1; argidx < args.size(); argidx++)
99  {
100  if (args[argidx] == "-top" && argidx+1 < args.size()) {
101  top_module = args[++argidx];
102  continue;
103  }
104  if (args[argidx] == "-run" && argidx+1 < args.size()) {
105  size_t pos = args[argidx+1].find(':');
106  if (pos == std::string::npos) {
107  run_from = args[++argidx];
108  run_to = args[argidx];
109  } else {
110  run_from = args[++argidx].substr(0, pos);
111  run_to = args[argidx].substr(pos+1);
112  }
113  continue;
114  }
115  break;
116  }
117  extra_args(args, argidx, design);
118 
119  if (!design->full_selection())
120  log_cmd_error("This comannd only operates on fully selected designs!\n");
121 
122  bool active = run_from.empty();
123 
124  log_header("Executing SYNTH pass.\n");
125  log_push();
126 
127  if (check_label(active, run_from, run_to, "begin"))
128  {
129  if (top_module.empty())
130  Pass::call(design, stringf("hierarchy -check"));
131  else
132  Pass::call(design, stringf("hierarchy -check -top %s", top_module.c_str()));
133  }
134 
135  if (check_label(active, run_from, run_to, "coarse"))
136  {
137  Pass::call(design, "proc");
138  Pass::call(design, "opt");
139  Pass::call(design, "wreduce");
140  Pass::call(design, "alumacc");
141  Pass::call(design, "share");
142  Pass::call(design, "opt");
143  Pass::call(design, "fsm");
144  Pass::call(design, "opt -fast");
145  Pass::call(design, "memory -nomap");
146  Pass::call(design, "opt_clean");
147  }
148 
149  if (check_label(active, run_from, run_to, "fine"))
150  {
151  Pass::call(design, "opt -fast -full");
152  Pass::call(design, "memory_map");
153  Pass::call(design, "opt -full");
154  Pass::call(design, "techmap");
155  Pass::call(design, "opt -fast");
156  }
157 
158  #ifdef YOSYS_ENABLE_ABC
159  if (check_label(active, run_from, run_to, "abc"))
160  {
161  Pass::call(design, "abc -fast");
162  Pass::call(design, "opt -fast");
163  }
164  #endif
165 
166  log_pop();
167  }
168 } SynthPass;
169 
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
void log_header(const char *format,...)
Definition: log.cc:188
void log_pop()
Definition: log.cc:237
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool check_label(bool &active, std::string run_from, std::string run_to, std::string label)
Definition: synth.cc:28
bool full_selection() const
Definition: rtlil.h:547
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
Definition: register.h:27
void log_cmd_error(const char *format,...)
Definition: log.cc:211
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: synth.cc:92
SynthPass SynthPass
void log(const char *format,...)
Definition: log.cc:180
void log_push()
Definition: log.cc:232
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
Definition: register.cc:128
SynthPass()
Definition: synth.cc:42
static void call(RTLIL::Design *design, std::string command)
Definition: register.cc:146
virtual void help()
Definition: synth.cc:43