yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
yosys.h
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 
21 // *** NOTE TO THE READER ***
22 //
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! ;)
25 //
26 // If you want to know how the design is represented by Yosys in the memory,
27 // you should read "kernel/rtlil.h".
28 //
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".
32 //
33 // This header is very boring. It just defines some general things that
34 // belong nowhere else and includes the interesting headers.
35 //
36 // Find more information in the "CodingReadme" file.
37 
38 
39 #ifndef YOSYS_H
40 #define YOSYS_H
41 
42 #include <map>
43 #include <set>
44 #include <vector>
45 #include <string>
46 #include <algorithm>
47 #include <functional>
48 #include <initializer_list>
49 
50 #include <sstream>
51 #include <fstream>
52 #include <istream>
53 #include <ostream>
54 #include <iostream>
55 
56 #include <stdarg.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <stdint.h>
60 #include <stdio.h>
61 
62 #ifndef _YOSYS_
63 # error It looks like you are trying to build Yosys without the config defines set. \
64  When building Yosys with a custom make system, make sure you set all the \
65  defines the Yosys Makefile would set for your build configuration.
66 #endif
67 
68 #ifdef YOSYS_ENABLE_TCL
69 # include <tcl.h>
70 #endif
71 
72 #ifdef _WIN32
73 # undef NOMINMAX
74 # define NOMINMAX 1
75 # undef YY_NO_UNISTD_H
76 # define YY_NO_UNISTD_H 1
77 
78 # include <windows.h>
79 # include <io.h>
80 # include <direct.h>
81 
82 # define strtok_r strtok_s
83 # define strdup _strdup
84 # define snprintf _snprintf
85 # define getcwd _getcwd
86 # define mkdir _mkdir
87 # define popen _popen
88 # define pclose _pclose
89 # define PATH_MAX MAX_PATH
90 
91 # ifndef __MINGW32__
92 # define isatty _isatty
93 # define fileno _fileno
94 # endif
95 #endif
96 
97 #define PRIVATE_NAMESPACE_BEGIN namespace {
98 #define PRIVATE_NAMESPACE_END }
99 #define YOSYS_NAMESPACE_BEGIN namespace Yosys {
100 #define YOSYS_NAMESPACE_END }
101 #define YOSYS_NAMESPACE_PREFIX Yosys::
102 #define USING_YOSYS_NAMESPACE using namespace Yosys;
103 
104 #if __cplusplus >= 201103L
105 # define YS_OVERRIDE override
106 # define YS_FINAL final
107 #else
108 # define YS_OVERRIDE
109 # define YS_FINAL
110 #endif
111 
112 #if defined(__GNUC__) || defined(__clang__)
113 # define YS_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
114 # define YS_NORETURN
115 #elif defined(_MSC_VER)
116 # define YS_ATTRIBUTE(...)
117 # define YS_NORETURN __declspec(noreturn)
118 #else
119 # define YS_ATTRIBUTE(...)
120 # define YS_NORETURN
121 #endif
122 
124 
125 namespace RTLIL {
126  struct IdString;
127  struct SigSpec;
128  struct Wire;
129  struct Cell;
130 }
131 
132 std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
133 std::string vstringf(const char *fmt, va_list ap);
134 int readsome(std::istream &f, char *s, int n);
135 std::string next_token(std::string &text, const char *sep);
136 bool patmatch(const char *pattern, const char *string);
137 int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
138 std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
139 std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
140 bool check_file_exists(std::string filename, bool is_exec = false);
141 void remove_directory(std::string dirname);
142 
143 template<typename T> int GetSize(const T &obj) { return obj.size(); }
144 int GetSize(RTLIL::Wire *wire);
145 
147 
148 #include "kernel/log.h"
149 #include "kernel/rtlil.h"
150 #include "kernel/register.h"
151 
153 
154 void yosys_setup();
155 void yosys_shutdown();
156 
157 #ifdef YOSYS_ENABLE_TCL
158 Tcl_Interp *yosys_get_tcl_interp();
159 #endif
160 
161 extern int autoidx;
163 
164 RTLIL::IdString new_id(std::string file, int line, std::string func);
165 
166 #define NEW_ID \
167  YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
168 
169 #define ID(_str) \
170  ([]() { static YOSYS_NAMESPACE_PREFIX RTLIL::IdString _id(_str); return _id; })()
171 
173 std::string proc_self_dirname();
174 std::string proc_share_dirname();
175 const char *create_prompt(RTLIL::Design *design, int recursion_counter);
176 
177 void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label);
178 void run_pass(std::string command, RTLIL::Design *design);
179 void run_backend(std::string filename, std::string command, RTLIL::Design *design);
180 void shell(RTLIL::Design *design);
181 
182 // from kernel/version_*.o (cc source generated from Makefile)
183 extern const char *yosys_version_str;
184 
185 // from passes/cmds/design.cc
186 extern std::map<std::string, RTLIL::Design*> saved_designs;
187 extern std::vector<RTLIL::Design*> pushed_designs;
188 
189 // from passes/cmds/pluginc.cc
190 extern std::map<std::string, void*> loaded_plugins;
191 extern std::map<std::string, std::string> loaded_plugin_aliases;
192 void load_plugin(std::string filename, std::vector<std::string> aliases);
193 
195 
196 #endif
const char * yosys_version_str
YOSYS_NAMESPACE_END YOSYS_NAMESPACE_BEGIN void yosys_setup()
Definition: yosys.cc:339
void run_backend(std::string filename, std::string command, RTLIL::Design *design)
Definition: yosys.cc:703
RTLIL::Design * yosys_get_design()
Definition: yosys.cc:395
void shell(RTLIL::Design *design)
Definition: yosys.cc:812
int GetSize(const T &obj)
Definition: yosys.h:143
#define YOSYS_NAMESPACE_END
Definition: yosys.h:100
void yosys_shutdown()
Definition: yosys.cc:346
void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label)
Definition: yosys.cc:603
int readsome(std::istream &f, char *s, int n)
Definition: yosys.cc:100
RTLIL::Design * yosys_design
Definition: yosys.cc:52
tuple n
Definition: fsm/generate.py:59
int run_command(const std::string &command, std::function< void(const std::string &)> process_line=std::function< void(const std::string &)>())
Definition: yosys.cc:195
const char * create_prompt(RTLIL::Design *design, int recursion_counter)
Definition: yosys.cc:400
std::string make_temp_file(std::string template_str="/tmp/yosys_XXXXXX")
Definition: yosys.cc:224
std::map< std::string, RTLIL::Design * > saved_designs
Definition: design.cc:27
int autoidx
Definition: yosys.cc:51
std::string proc_self_dirname()
std::string std::string vstringf(const char *fmt, va_list ap)
Definition: yosys.cc:70
#define YS_ATTRIBUTE(...)
Definition: yosys.h:119
RTLIL::IdString new_id(std::string file, int line, std::string func)
Definition: yosys.cc:378
bool patmatch(const char *pattern, const char *string)
Definition: yosys.cc:144
void remove_directory(std::string dirname)
Definition: yosys.cc:308
std::string make_temp_dir(std::string template_str="/tmp/yosys_XXXXXX")
Definition: yosys.cc:273
std::vector< RTLIL::Design * > pushed_designs
Definition: design.cc:28
std::map< std::string, std::string > loaded_plugin_aliases
Definition: plugin.cc:29
#define YOSYS_NAMESPACE_BEGIN
Definition: yosys.h:99
void load_plugin(std::string filename, std::vector< std::string > aliases)
Definition: plugin.cc:49
bool check_file_exists(std::string filename, bool is_exec=false)
Definition: yosys.cc:302
void run_pass(std::string command, RTLIL::Design *design)
Definition: yosys.cc:696
std::string proc_share_dirname()
Definition: yosys.cc:543
std::string next_token(std::string &text, const char *sep)
Definition: yosys.cc:116
std::string stringf(const char *fmt,...) YS_ATTRIBUTE(format(printf
std::map< std::string, void * > loaded_plugins
Definition: plugin.cc:28