Added stackmap<> container
[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
37 #ifndef YOSYS_H
38 #define YOSYS_H
39
40 #include <map>
41 #include <set>
42 #include <vector>
43 #include <string>
44 #include <algorithm>
45 #include <functional>
46 #include <initializer_list>
47
48 #include <stdarg.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <stdio.h>
52
53 #define PRIVATE_NAMESPACE_BEGIN namespace {
54 #define PRIVATE_NAMESPACE_END }
55
56 #if 0
57 # define YOSYS_NAMESPACE_BEGIN namespace Yosys {
58 # define YOSYS_NAMESPACE_END }
59 # define YOSYS_NAMESPACE_PREFIX Yosys::
60 # define USING_YOSYS_NAMESPACE using namespace Yosys;
61 #else
62 # define YOSYS_NAMESPACE_BEGIN
63 # define YOSYS_NAMESPACE_END
64 # define YOSYS_NAMESPACE_PREFIX
65 # define USING_YOSYS_NAMESPACE
66 #endif
67
68 #if __cplusplus >= 201103L
69 # define OVERRIDE override
70 # define FINAL final
71 #else
72 # define OVERRIDE
73 # define FINAL
74 #endif
75
76 YOSYS_NAMESPACE_BEGIN
77
78 namespace RTLIL {
79 struct IdString;
80 struct SigSpec;
81 struct Wire;
82 struct Cell;
83 }
84
85 std::string stringf(const char *fmt, ...);
86 std::string vstringf(const char *fmt, va_list ap);
87 template<typename T> int SIZE(const T &obj) { return obj.size(); }
88 int SIZE(RTLIL::Wire *wire);
89
90 YOSYS_NAMESPACE_END
91
92 #include "kernel/log.h"
93 #include "kernel/rtlil.h"
94 #include "kernel/register.h"
95 #include "kernel/compatibility.h"
96
97 YOSYS_NAMESPACE_BEGIN
98
99 void yosys_setup();
100 void yosys_shutdown();
101
102 #ifdef YOSYS_ENABLE_TCL
103 #include <tcl.h>
104 Tcl_Interp *yosys_get_tcl_interp();
105 #endif
106
107 extern int autoidx;
108 extern RTLIL::Design *yosys_design;
109
110 RTLIL::IdString new_id(std::string file, int line, std::string func);
111
112 #define NEW_ID \
113 YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
114
115 #define ID(_str) \
116 ([]() { static YOSYS_NAMESPACE_PREFIX RTLIL::IdString _id(_str); return _id; })()
117
118 RTLIL::Design *yosys_get_design();
119 std::string proc_self_dirname();
120 std::string proc_share_dirname();
121 const char *create_prompt(RTLIL::Design *design, int recursion_counter);
122
123 void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label);
124 void run_pass(std::string command, RTLIL::Design *design);
125 void run_backend(std::string filename, std::string command, RTLIL::Design *design);
126 void shell(RTLIL::Design *design);
127
128 // from kernel/version_*.o (cc source generated from Makefile)
129 extern const char *yosys_version_str;
130
131 // from passes/cmds/design.cc
132 extern std::map<std::string, RTLIL::Design*> saved_designs;
133 extern std::vector<RTLIL::Design*> pushed_designs;
134
135 YOSYS_NAMESPACE_END
136
137 #endif