Merge pull request #3310 from robinsonb5-PRs/master
[yosys.git] / kernel / register.h
1 /* -*- c++ -*-
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
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 bool experimental_flag = false;
40
41 void experimental() {
42 experimental_flag = true;
43 }
44
45 struct pre_post_exec_state_t {
46 Pass *parent_pass;
47 int64_t begin_ns;
48 };
49
50 pre_post_exec_state_t pre_execute();
51 void post_execute(pre_post_exec_state_t state);
52
53 void cmd_log_args(const std::vector<std::string> &args);
54 void cmd_error(const std::vector<std::string> &args, size_t argidx, std::string msg);
55 void extra_args(std::vector<std::string> args, size_t argidx, RTLIL::Design *design, bool select = true);
56
57 static void call(RTLIL::Design *design, std::string command);
58 static void call(RTLIL::Design *design, std::vector<std::string> args);
59
60 static void call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::string command);
61 static void call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::vector<std::string> args);
62
63 static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command);
64 static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::vector<std::string> args);
65
66 Pass *next_queued_pass;
67 virtual void run_register();
68 static void init_register();
69 static void done_register();
70
71 virtual void on_register();
72 virtual void on_shutdown();
73 };
74
75 struct ScriptPass : Pass
76 {
77 bool block_active, help_mode;
78 RTLIL::Design *active_design;
79 std::string active_run_from, active_run_to;
80
81 ScriptPass(std::string name, std::string short_help = "** document me **") : Pass(name, short_help) { }
82
83 virtual void script() = 0;
84
85 bool check_label(std::string label, std::string info = std::string());
86 void run(std::string command, std::string info = std::string());
87 void run_nocheck(std::string command, std::string info = std::string());
88 void run_script(RTLIL::Design *design, std::string run_from = std::string(), std::string run_to = std::string());
89 void help_script();
90 };
91
92 struct Frontend : Pass
93 {
94 // for reading of here documents
95 static FILE *current_script_file;
96 static std::string last_here_document;
97
98 std::string frontend_name;
99 Frontend(std::string name, std::string short_help = "** document me **");
100 void run_register() override;
101 ~Frontend() override;
102 void execute(std::vector<std::string> args, RTLIL::Design *design) override final;
103 virtual void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
104
105 static std::vector<std::string> next_args;
106 void extra_args(std::istream *&f, std::string &filename, std::vector<std::string> args, size_t argidx, bool bin_input = false);
107
108 static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command);
109 static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::vector<std::string> args);
110 };
111
112 struct Backend : Pass
113 {
114 std::string backend_name;
115 Backend(std::string name, std::string short_help = "** document me **");
116 void run_register() override;
117 ~Backend() override;
118 void execute(std::vector<std::string> args, RTLIL::Design *design) override final;
119 virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
120
121 void extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx, bool bin_output = false);
122
123 static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command);
124 static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args);
125 };
126
127 // implemented in passes/cmds/select.cc
128 extern void handle_extra_select_args(Pass *pass, const std::vector<std::string> &args, size_t argidx, size_t args_size, RTLIL::Design *design);
129 extern RTLIL::Selection eval_select_args(const vector<string> &args, RTLIL::Design *design);
130 extern void eval_select_op(vector<RTLIL::Selection> &work, const string &op, RTLIL::Design *design);
131
132 extern std::map<std::string, Pass*> pass_register;
133 extern std::map<std::string, Frontend*> frontend_register;
134 extern std::map<std::string, Backend*> backend_register;
135
136 YOSYS_NAMESPACE_END
137
138 #endif