Various MXE build fixes
[yosys.git] / kernel / yosys.h
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 <stdio.h>
60
61 #ifndef _YOSYS_
62 # error It looks like you are trying to build Yosys with the config defines set. \
63 When building Yosys with a custom make system, make sure you set all the \
64 defines the Yosys Makefile would set for your build configuration.
65 #endif
66
67 #ifdef YOSYS_ENABLE_TCL
68 # include <tcl.h>
69 #endif
70
71 // a few platform specific things
72 #ifdef _WIN32
73 # ifndef NOMINMAX
74 # define NOMINMAX 1
75 # endif
76 # include <windows.h>
77 # include <stdint.h> // takes care of a number of typedefs
78 # include <io.h>
79 # include <direct.h>
80
81 // these are always a bit dangerous :-)
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 #endif
91
92
93 #define PRIVATE_NAMESPACE_BEGIN namespace {
94 #define PRIVATE_NAMESPACE_END }
95 #define YOSYS_NAMESPACE_BEGIN namespace Yosys {
96 #define YOSYS_NAMESPACE_END }
97 #define YOSYS_NAMESPACE_PREFIX Yosys::
98 #define USING_YOSYS_NAMESPACE using namespace Yosys;
99
100 #if __cplusplus >= 201103L
101 # define OVERRIDE override
102 # define FINAL final
103 #else
104 # define OVERRIDE
105 # define FINAL
106 #endif
107
108 #if !defined(__GNUC__) && !defined(__clang__)
109 # define __attribute__(...)
110 # define _NORETURN_ __declspec(noreturn)
111 #else
112 # define _NORETURN_
113 #endif
114
115 YOSYS_NAMESPACE_BEGIN
116
117 namespace RTLIL {
118 struct IdString;
119 struct SigSpec;
120 struct Wire;
121 struct Cell;
122 }
123
124 std::string stringf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
125 std::string vstringf(const char *fmt, va_list ap);
126 std::string next_token(std::string &text, const char *sep);
127 bool patmatch(const char *pattern, const char *string);
128 int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
129 std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
130 std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
131 bool check_file(std::string filename, bool is_exec = false);
132 void remove_directory(std::string dirname);
133
134 template<typename T> int GetSize(const T &obj) { return obj.size(); }
135 int GetSize(RTLIL::Wire *wire);
136
137 YOSYS_NAMESPACE_END
138
139 #include "kernel/log.h"
140 #include "kernel/rtlil.h"
141 #include "kernel/register.h"
142
143 YOSYS_NAMESPACE_BEGIN
144
145 void yosys_setup();
146 void yosys_shutdown();
147
148 #ifdef YOSYS_ENABLE_TCL
149 Tcl_Interp *yosys_get_tcl_interp();
150 #endif
151
152 extern int autoidx;
153 extern RTLIL::Design *yosys_design;
154
155 RTLIL::IdString new_id(std::string file, int line, std::string func);
156
157 #define NEW_ID \
158 YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
159
160 #define ID(_str) \
161 ([]() { static YOSYS_NAMESPACE_PREFIX RTLIL::IdString _id(_str); return _id; })()
162
163 RTLIL::Design *yosys_get_design();
164 std::string proc_self_dirname();
165 std::string proc_share_dirname();
166 const char *create_prompt(RTLIL::Design *design, int recursion_counter);
167
168 void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label);
169 void run_pass(std::string command, RTLIL::Design *design);
170 void run_backend(std::string filename, std::string command, RTLIL::Design *design);
171 void shell(RTLIL::Design *design);
172
173 // from kernel/version_*.o (cc source generated from Makefile)
174 extern const char *yosys_version_str;
175
176 // from passes/cmds/design.cc
177 extern std::map<std::string, RTLIL::Design*> saved_designs;
178 extern std::vector<RTLIL::Design*> pushed_designs;
179
180 // from passes/cmds/pluginc.cc
181 extern std::map<std::string, void*> loaded_plugins;
182 extern std::map<std::string, std::string> loaded_plugin_aliases;
183 void load_plugin(std::string filename, std::vector<std::string> aliases);
184
185 YOSYS_NAMESPACE_END
186
187 #endif