Merge pull request #1602 from niklasnisbeth/ice40-init-vals-warning
[yosys.git] / kernel / register.h
1 /* -*- c++ -*-
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 #include "kernel/yosys.h"
21
22 #ifndef REGISTER_H
23 #define REGISTER_H
24
25 YOSYS_NAMESPACE_BEGIN
26
27 struct Pass
28 {
29 std::string pass_name, short_help;
30 Pass(std::string name, std::string short_help = "** document me **");
31 virtual ~Pass();
32
33 virtual void help();
34 virtual void clear_flags();
35 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) = 0;
36
37 int call_counter;
38 int64_t runtime_ns;
39
40 struct pre_post_exec_state_t {
41 Pass *parent_pass;
42 int64_t begin_ns;
43 };
44
45 pre_post_exec_state_t pre_execute();
46 void post_execute(pre_post_exec_state_t state);
47
48 void cmd_log_args(const std::vector<std::string> &args);
49 void cmd_error(const std::vector<std::string> &args, size_t argidx, std::string msg);
50 void extra_args(std::vector<std::string> args, size_t argidx, RTLIL::Design *design, bool select = true);
51
52 static void call(RTLIL::Design *design, std::string command);
53 static void call(RTLIL::Design *design, std::vector<std::string> args);
54
55 static void call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::string command);
56 static void call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::vector<std::string> args);
57
58 static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command);
59 static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::vector<std::string> args);
60
61 Pass *next_queued_pass;
62 virtual void run_register();
63 static void init_register();
64 static void done_register();
65
66 virtual void on_register();
67 virtual void on_shutdown();
68 };
69
70 struct ScriptPass : Pass
71 {
72 bool block_active, help_mode;
73 RTLIL::Design *active_design;
74 std::string active_run_from, active_run_to;
75
76 ScriptPass(std::string name, std::string short_help = "** document me **") : Pass(name, short_help) { }
77
78 virtual void script() = 0;
79
80 bool check_label(std::string label, std::string info = std::string());
81 void run(std::string command, std::string info = std::string());
82 void run_script(RTLIL::Design *design, std::string run_from = std::string(), std::string run_to = std::string());
83 void help_script();
84 };
85
86 struct Frontend : Pass
87 {
88 // for reading of here documents
89 static FILE *current_script_file;
90 static std::string last_here_document;
91
92 std::string frontend_name;
93 Frontend(std::string name, std::string short_help = "** document me **");
94 void run_register() YS_OVERRIDE;
95 ~Frontend() YS_OVERRIDE;
96 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE YS_FINAL;
97 virtual void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
98
99 static std::vector<std::string> next_args;
100 void extra_args(std::istream *&f, std::string &filename, std::vector<std::string> args, size_t argidx, bool bin_input = false);
101
102 static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command);
103 static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::vector<std::string> args);
104 };
105
106 struct Backend : Pass
107 {
108 std::string backend_name;
109 Backend(std::string name, std::string short_help = "** document me **");
110 void run_register() YS_OVERRIDE;
111 ~Backend() YS_OVERRIDE;
112 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE YS_FINAL;
113 virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
114
115 void extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx, bool bin_output = false);
116
117 static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command);
118 static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args);
119 };
120
121 // implemented in passes/cmds/select.cc
122 extern void handle_extra_select_args(Pass *pass, std::vector<std::string> args, size_t argidx, size_t args_size, RTLIL::Design *design);
123 extern RTLIL::Selection eval_select_args(const vector<string> &args, RTLIL::Design *design);
124 extern void eval_select_op(vector<RTLIL::Selection> &work, const string &op, RTLIL::Design *design);
125
126 extern std::map<std::string, Pass*> pass_register;
127 extern std::map<std::string, Frontend*> frontend_register;
128 extern std::map<std::string, Backend*> backend_register;
129
130 YOSYS_NAMESPACE_END
131
132 #endif