Added new CodingReadme file (replaces CodingStyle and CHECKLISTS)
[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 #define PRIVATE_NAMESPACE_BEGIN namespace {
62 #define PRIVATE_NAMESPACE_END }
63
64 #if 0
65 # define YOSYS_NAMESPACE_BEGIN namespace Yosys {
66 # define YOSYS_NAMESPACE_END }
67 # define YOSYS_NAMESPACE_PREFIX Yosys::
68 # define USING_YOSYS_NAMESPACE using namespace Yosys;
69 #else
70 # define YOSYS_NAMESPACE_BEGIN
71 # define YOSYS_NAMESPACE_END
72 # define YOSYS_NAMESPACE_PREFIX
73 # define USING_YOSYS_NAMESPACE
74 #endif
75
76 #if __cplusplus >= 201103L
77 # define OVERRIDE override
78 # define FINAL final
79 #else
80 # define OVERRIDE
81 # define FINAL
82 #endif
83
84 YOSYS_NAMESPACE_BEGIN
85
86 namespace RTLIL {
87 struct IdString;
88 struct SigSpec;
89 struct Wire;
90 struct Cell;
91 }
92
93 std::string stringf(const char *fmt, ...);
94 std::string vstringf(const char *fmt, va_list ap);
95 template<typename T> int SIZE(const T &obj) { return obj.size(); }
96 int SIZE(RTLIL::Wire *wire);
97
98 YOSYS_NAMESPACE_END
99
100 #include "kernel/log.h"
101 #include "kernel/rtlil.h"
102 #include "kernel/register.h"
103
104 YOSYS_NAMESPACE_BEGIN
105
106 void yosys_setup();
107 void yosys_shutdown();
108
109 #ifdef YOSYS_ENABLE_TCL
110 #include <tcl.h>
111 Tcl_Interp *yosys_get_tcl_interp();
112 #endif
113
114 extern int autoidx;
115 extern RTLIL::Design *yosys_design;
116
117 RTLIL::IdString new_id(std::string file, int line, std::string func);
118
119 #define NEW_ID \
120 YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
121
122 #define ID(_str) \
123 ([]() { static YOSYS_NAMESPACE_PREFIX RTLIL::IdString _id(_str); return _id; })()
124
125 RTLIL::Design *yosys_get_design();
126 std::string proc_self_dirname();
127 std::string proc_share_dirname();
128 const char *create_prompt(RTLIL::Design *design, int recursion_counter);
129
130 void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label);
131 void run_pass(std::string command, RTLIL::Design *design);
132 void run_backend(std::string filename, std::string command, RTLIL::Design *design);
133 void shell(RTLIL::Design *design);
134
135 // from kernel/version_*.o (cc source generated from Makefile)
136 extern const char *yosys_version_str;
137
138 // from passes/cmds/design.cc
139 extern std::map<std::string, RTLIL::Design*> saved_designs;
140 extern std::vector<RTLIL::Design*> pushed_designs;
141
142 // from passes/cmds/pluginc.cc
143 extern std::map<std::string, void*> loaded_plugins;
144 extern std::map<std::string, std::string> loaded_plugin_aliases;
145 void load_plugin(std::string filename, std::vector<std::string> aliases);
146
147 YOSYS_NAMESPACE_END
148
149 #endif