Improved readline tab completion
[yosys.git] / kernel / register.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 #ifndef REGISTER_H
21 #define REGISTER_H
22
23 #include "kernel/rtlil.h"
24 #include <stdio.h>
25 #include <string>
26 #include <vector>
27 #include <map>
28
29 #ifdef YOSYS_ENABLE_TCL
30 #include <tcl.h>
31 extern Tcl_Interp *yosys_get_tcl_interp();
32 #endif
33
34 // implemented in driver.cc
35 extern RTLIL::Design *yosys_get_design();
36 std::string rewrite_yosys_exe(std::string exe);
37
38 struct Pass
39 {
40 std::string pass_name, short_help;
41 Pass(std::string name, std::string short_help = "** document me **");
42 virtual void run_register();
43 virtual ~Pass();
44 virtual void help();
45 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) = 0;
46
47 void cmd_log_args(const std::vector<std::string> &args);
48 void cmd_error(const std::vector<std::string> &args, size_t argidx, std::string msg);
49 void extra_args(std::vector<std::string> args, size_t argidx, RTLIL::Design *design, bool select = true);
50
51 static void call(RTLIL::Design *design, std::string command);
52 static void call(RTLIL::Design *design, std::vector<std::string> args);
53
54 static void init_register();
55 static void done_register();
56 };
57
58 struct Frontend : Pass
59 {
60 std::string frontend_name;
61 Frontend(std::string name, std::string short_help = "** document me **");
62 virtual void run_register();
63 virtual ~Frontend();
64 virtual void execute(std::vector<std::string> args, RTLIL::Design *design);
65 virtual void execute(FILE *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
66
67 static std::vector<std::string> next_args;
68 void extra_args(FILE *&f, std::string &filename, std::vector<std::string> args, size_t argidx);
69
70 static void frontend_call(RTLIL::Design *design, FILE *f, std::string filename, std::string command);
71 static void frontend_call(RTLIL::Design *design, FILE *f, std::string filename, std::vector<std::string> args);
72 };
73
74 struct Backend : Pass
75 {
76 std::string backend_name;
77 Backend(std::string name, std::string short_help = "** document me **");
78 virtual void run_register();
79 virtual ~Backend();
80 virtual void execute(std::vector<std::string> args, RTLIL::Design *design);
81 virtual void execute(FILE *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
82
83 void extra_args(FILE *&f, std::string &filename, std::vector<std::string> args, size_t argidx);
84
85 static void backend_call(RTLIL::Design *design, FILE *f, std::string filename, std::string command);
86 static void backend_call(RTLIL::Design *design, FILE *f, std::string filename, std::vector<std::string> args);
87 };
88
89 // implemented in passes/cmds/select.cc
90 extern void handle_extra_select_args(Pass *pass, std::vector<std::string> args, size_t argidx, size_t args_size, RTLIL::Design *design);
91
92 namespace REGISTER_INTERN {
93 extern int raw_register_count;
94 extern bool raw_register_done;
95 extern Pass *raw_register_array[];
96 extern std::map<std::string, Pass*> pass_register;
97 extern std::map<std::string, Frontend*> frontend_register;
98 extern std::map<std::string, Backend*> backend_register;
99 }
100
101 #endif