Merge pull request #1412 from YosysHQ/eddie/equiv_opt_async2sync
[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
67 struct ScriptPass : Pass
68 {
69 bool block_active, help_mode;
70 RTLIL::Design *active_design;
71 std::string active_run_from, active_run_to;
72
73 ScriptPass(std::string name, std::string short_help = "** document me **") : Pass(name, short_help) { }
74
75 virtual void script() = 0;
76
77 bool check_label(std::string label, std::string info = std::string());
78 void run(std::string command, std::string info = std::string());
79 void run_script(RTLIL::Design *design, std::string run_from = std::string(), std::string run_to = std::string());
80 void help_script();
81 };
82
83 struct Frontend : Pass
84 {
85 // for reading of here documents
86 static FILE *current_script_file;
87 static std::string last_here_document;
88
89 std::string frontend_name;
90 Frontend(std::string name, std::string short_help = "** document me **");
91 void run_register() YS_OVERRIDE;
92 ~Frontend() YS_OVERRIDE;
93 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE YS_FINAL;
94 virtual void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
95
96 static std::vector<std::string> next_args;
97 void extra_args(std::istream *&f, std::string &filename, std::vector<std::string> args, size_t argidx);
98
99 static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command);
100 static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::vector<std::string> args);
101 };
102
103 struct Backend : Pass
104 {
105 std::string backend_name;
106 Backend(std::string name, std::string short_help = "** document me **");
107 void run_register() YS_OVERRIDE;
108 ~Backend() YS_OVERRIDE;
109 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE YS_FINAL;
110 virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
111
112 void extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx, bool bin_output = false);
113
114 static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command);
115 static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args);
116 };
117
118 // implemented in passes/cmds/select.cc
119 extern void handle_extra_select_args(Pass *pass, std::vector<std::string> args, size_t argidx, size_t args_size, RTLIL::Design *design);
120 extern RTLIL::Selection eval_select_args(const vector<string> &args, RTLIL::Design *design);
121 extern void eval_select_op(vector<RTLIL::Selection> &work, const string &op, RTLIL::Design *design);
122
123 extern std::map<std::string, Pass*> pass_register;
124 extern std::map<std::string, Frontend*> frontend_register;
125 extern std::map<std::string, Backend*> backend_register;
126
127 YOSYS_NAMESPACE_END
128
129 #endif