4380a5b6962822c9ec6a0f8bcbb3b9540d7ae158
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.
21 // *** NOTE TO THE READER ***
23 // Maybe you have just opened this file in the hope to learn more about the
24 // Yosys API. Let me congratulate you on this great decision! ;)
26 // If you want to know how the design is represented by Yosys in the memory,
27 // you should read "kernel/rtlil.h".
29 // If you want to know how to register a command with Yosys, you could read
30 // "kernel/register.h", but it would be easier to just look at a simple
31 // example instead. A simple one would be "passes/cmds/log.cc".
33 // This header is very boring. It just defines some general things that
34 // belong nowhere else and includes the interesting headers.
36 // Find more information in the "CodingReadme" file.
49 #include <unordered_map>
50 #include <unordered_set>
51 #include <initializer_list>
72 # error It looks like you are trying to build Yosys without the config defines set. \
73 When building Yosys with a custom make system, make sure you set all the \
74 defines the Yosys Makefile would set for your build configuration.
77 #ifdef YOSYS_ENABLE_TCL
79 # ifdef YOSYS_MXE_HACKS
80 extern Tcl_Command
Tcl_CreateCommand(Tcl_Interp
*interp
, const char *cmdName
, Tcl_CmdProc
*proc
, ClientData clientData
, Tcl_CmdDeleteProc
*deleteProc
);
81 extern Tcl_Interp
*Tcl_CreateInterp(void);
82 extern void Tcl_DeleteInterp(Tcl_Interp
*interp
);
83 extern int Tcl_Eval(Tcl_Interp
*interp
, const char *script
);
84 extern int Tcl_EvalFile(Tcl_Interp
*interp
, const char *fileName
);
85 extern void Tcl_Finalize(void);
86 extern int Tcl_GetCommandInfo(Tcl_Interp
*interp
, const char *cmdName
, Tcl_CmdInfo
*infoPtr
);
87 extern const char *Tcl_GetStringResult(Tcl_Interp
*interp
);
94 # undef YY_NO_UNISTD_H
95 # define YY_NO_UNISTD_H 1
101 # define strtok_r strtok_s
102 # define strdup _strdup
103 # define snprintf _snprintf
104 # define getcwd _getcwd
105 # define mkdir _mkdir
106 # define popen _popen
107 # define pclose _pclose
110 # define PATH_MAX MAX_PATH
111 # define isatty _isatty
112 # define fileno _fileno
117 # define PATH_MAX 4096
120 #define PRIVATE_NAMESPACE_BEGIN namespace {
121 #define PRIVATE_NAMESPACE_END }
122 #define YOSYS_NAMESPACE_BEGIN namespace Yosys {
123 #define YOSYS_NAMESPACE_END }
124 #define YOSYS_NAMESPACE_PREFIX Yosys::
125 #define USING_YOSYS_NAMESPACE using namespace Yosys;
127 #if __cplusplus >= 201103L
128 # define YS_OVERRIDE override
129 # define YS_FINAL final
135 #if defined(__GNUC__) || defined(__clang__)
136 # define YS_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
138 #elif defined(_MSC_VER)
139 # define YS_ATTRIBUTE(...)
140 # define YS_NORETURN __declspec(noreturn)
142 # define YS_ATTRIBUTE(...)
146 YOSYS_NAMESPACE_BEGIN
148 // Note: All headers included in hashlib.h must be included
149 // outside of YOSYS_NAMESPACE before this or bad things will happen.
152 # include "kernel/hashlib.h"
154 # include "kernel/hashlib.h"
163 using std::make_tuple
;
164 using std::make_pair
;
169 // A primitive shared string implementation that does not
170 // move its .c_str() when the object is copied or moved.
172 std::shared_ptr
<string
> content
;
174 shared_str(string s
) { content
= std::shared_ptr
<string
>(new string(s
)); }
175 shared_str(const char *s
) { content
= std::shared_ptr
<string
>(new string(s
)); }
176 const char *c_str() const { return content
->c_str(); }
177 const string
&str() const { return *content
; }
178 bool operator==(const shared_str
&other
) const { return *content
== *other
.content
; }
179 unsigned int hash() const { return hashlib::hash_ops
<std::string
>::hash(*content
); }
182 using hashlib::mkhash
;
183 using hashlib::mkhash_init
;
184 using hashlib::mkhash_add
;
185 using hashlib::mkhash_xorshift
;
186 using hashlib::hash_ops
;
187 using hashlib::hash_cstr_ops
;
188 using hashlib::hash_ptr_ops
;
189 using hashlib::hash_obj_ops
;
191 using hashlib::idict
;
211 using RTLIL::IdString
;
214 using RTLIL::SigSpec
;
221 template<> struct hash_ops
<RTLIL::Wire
*> : hash_obj_ops
{};
222 template<> struct hash_ops
<RTLIL::Cell
*> : hash_obj_ops
{};
223 template<> struct hash_ops
<RTLIL::Module
*> : hash_obj_ops
{};
224 template<> struct hash_ops
<RTLIL::Design
*> : hash_obj_ops
{};
225 template<> struct hash_ops
<RTLIL::Monitor
*> : hash_obj_ops
{};
226 template<> struct hash_ops
<AST::AstNode
*> : hash_obj_ops
{};
228 template<> struct hash_ops
<const RTLIL::Wire
*> : hash_obj_ops
{};
229 template<> struct hash_ops
<const RTLIL::Cell
*> : hash_obj_ops
{};
230 template<> struct hash_ops
<const RTLIL::Module
*> : hash_obj_ops
{};
231 template<> struct hash_ops
<const RTLIL::Design
*> : hash_obj_ops
{};
232 template<> struct hash_ops
<const RTLIL::Monitor
*> : hash_obj_ops
{};
233 template<> struct hash_ops
<const AST::AstNode
*> : hash_obj_ops
{};
237 void memhasher_off();
240 extern bool memhasher_active
;
241 inline void memhasher() { if (memhasher_active
) memhasher_do(); }
244 int ceil_log2(int x
);
245 std::string
stringf(const char *fmt
, ...) YS_ATTRIBUTE(format(printf
, 1, 2));
246 std::string
vstringf(const char *fmt
, va_list ap
);
247 int readsome(std::istream
&f
, char *s
, int n
);
248 std::string
next_token(std::string
&text
, const char *sep
= " \t\r\n", bool long_strings
= false);
249 std::vector
<std::string
> split_tokens(const std::string
&text
, const char *sep
= " \t\r\n");
250 bool patmatch(const char *pattern
, const char *string
);
251 int run_command(const std::string
&command
, std::function
<void(const std::string
&)> process_line
= std::function
<void(const std::string
&)>());
252 std::string
make_temp_file(std::string template_str
= "/tmp/yosys_XXXXXX");
253 std::string
make_temp_dir(std::string template_str
= "/tmp/yosys_XXXXXX");
254 bool check_file_exists(std::string filename
, bool is_exec
= false);
255 bool is_absolute_path(std::string filename
);
256 void remove_directory(std::string dirname
);
258 template<typename T
> int GetSize(const T
&obj
) { return obj
.size(); }
259 int GetSize(RTLIL::Wire
*wire
);
262 extern int yosys_xtrace
;
266 #include "kernel/log.h"
267 #include "kernel/rtlil.h"
268 #include "kernel/register.h"
270 YOSYS_NAMESPACE_BEGIN
273 using RTLIL::SigChunk
;
277 template<> struct hash_ops
<RTLIL::State
> : hash_ops
<int> {};
281 void yosys_shutdown();
283 #ifdef YOSYS_ENABLE_TCL
284 Tcl_Interp
*yosys_get_tcl_interp();
287 extern RTLIL::Design
*yosys_design
;
289 RTLIL::IdString
new_id(std::string file
, int line
, std::string func
);
292 YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
295 ([]() { static YOSYS_NAMESPACE_PREFIX RTLIL::IdString _id(_str); return _id; })()
297 RTLIL::Design
*yosys_get_design();
298 std::string
proc_self_dirname();
299 std::string
proc_share_dirname();
300 const char *create_prompt(RTLIL::Design
*design
, int recursion_counter
);
301 std::vector
<std::string
> glob_filename(const std::string
&filename_pattern
);
302 void rewrite_filename(std::string
&filename
);
304 void run_pass(std::string command
, RTLIL::Design
*design
= nullptr);
305 void run_frontend(std::string filename
, std::string command
, std::string
*backend_command
, std::string
*from_to_label
= nullptr, RTLIL::Design
*design
= nullptr);
306 void run_frontend(std::string filename
, std::string command
, RTLIL::Design
*design
= nullptr);
307 void run_backend(std::string filename
, std::string command
, RTLIL::Design
*design
= nullptr);
308 void shell(RTLIL::Design
*design
);
310 // journal of all input and output files read (for "yosys -E")
311 extern std::set
<std::string
> yosys_input_files
, yosys_output_files
;
313 // from kernel/version_*.o (cc source generated from Makefile)
314 extern const char *yosys_version_str
;
316 // from passes/cmds/design.cc
317 extern std::map
<std::string
, RTLIL::Design
*> saved_designs
;
318 extern std::vector
<RTLIL::Design
*> pushed_designs
;
320 // from passes/cmds/pluginc.cc
321 extern std::map
<std::string
, void*> loaded_plugins
;
323 extern std::map
<std::string
, void*> loaded_python_plugins
;
325 extern std::map
<std::string
, std::string
> loaded_plugin_aliases
;
326 void load_plugin(std::string filename
, std::vector
<std::string
> aliases
);