Merge pull request #3041 from YosysHQ/mmicko/module_attr
[yosys.git] / frontends / rtlil / rtlil_frontend.cc
1 /*
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 * A very simple and straightforward frontend for the RTLIL text
21 * representation.
22 *
23 */
24
25 #include "rtlil_frontend.h"
26 #include "kernel/register.h"
27 #include "kernel/log.h"
28
29 void rtlil_frontend_yyerror(char const *s)
30 {
31 YOSYS_NAMESPACE_PREFIX log_error("Parser error in line %d: %s\n", rtlil_frontend_yyget_lineno(), s);
32 }
33
34 YOSYS_NAMESPACE_BEGIN
35
36 struct RTLILFrontend : public Frontend {
37 RTLILFrontend() : Frontend("rtlil", "read modules from RTLIL file") { }
38 void help() override
39 {
40 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
41 log("\n");
42 log(" read_rtlil [filename]\n");
43 log("\n");
44 log("Load modules from an RTLIL file to the current design. (RTLIL is a text\n");
45 log("representation of a design in yosys's internal format.)\n");
46 log("\n");
47 log(" -nooverwrite\n");
48 log(" ignore re-definitions of modules. (the default behavior is to\n");
49 log(" create an error message if the existing module is not a blackbox\n");
50 log(" module, and overwrite the existing module if it is a blackbox module.)\n");
51 log("\n");
52 log(" -overwrite\n");
53 log(" overwrite existing modules with the same name\n");
54 log("\n");
55 log(" -lib\n");
56 log(" only create empty blackbox modules\n");
57 log("\n");
58 }
59 void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
60 {
61 RTLIL_FRONTEND::flag_nooverwrite = false;
62 RTLIL_FRONTEND::flag_overwrite = false;
63 RTLIL_FRONTEND::flag_lib = false;
64
65 log_header(design, "Executing RTLIL frontend.\n");
66
67 size_t argidx;
68 for (argidx = 1; argidx < args.size(); argidx++) {
69 std::string arg = args[argidx];
70 if (arg == "-nooverwrite") {
71 RTLIL_FRONTEND::flag_nooverwrite = true;
72 RTLIL_FRONTEND::flag_overwrite = false;
73 continue;
74 }
75 if (arg == "-overwrite") {
76 RTLIL_FRONTEND::flag_nooverwrite = false;
77 RTLIL_FRONTEND::flag_overwrite = true;
78 continue;
79 }
80 if (arg == "-lib") {
81 RTLIL_FRONTEND::flag_lib = true;
82 continue;
83 }
84 break;
85 }
86 extra_args(f, filename, args, argidx);
87
88 log("Input filename: %s\n", filename.c_str());
89
90 RTLIL_FRONTEND::lexin = f;
91 RTLIL_FRONTEND::current_design = design;
92 rtlil_frontend_yydebug = false;
93 rtlil_frontend_yyrestart(NULL);
94 rtlil_frontend_yyparse();
95 rtlil_frontend_yylex_destroy();
96 }
97 } RTLILFrontend;
98
99 struct IlangFrontend : public Frontend {
100 IlangFrontend() : Frontend("ilang", "(deprecated) alias of read_rtlil") { }
101 void help() override
102 {
103 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
104 log("\n");
105 log("See `help read_rtlil`.\n");
106 log("\n");
107 }
108 void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
109 {
110 RTLILFrontend.execute(f, filename, args, design);
111 }
112 } IlangFrontend;
113
114 YOSYS_NAMESPACE_END
115