42 log(
" vhdl2verilog [options] <vhdl-file>..\n");
44 log(
"This command reads VHDL source files using the 'vhdl2verilog' tool and the\n");
45 log(
"Yosys Verilog frontend.\n");
47 log(
" -out <out_file>\n");
48 log(
" do not import the vhdl2verilog output. instead write it to the\n");
49 log(
" specified file.\n");
51 log(
" -vhdl2verilog_dir <directory>\n");
52 log(
" do use the specified vhdl2verilog installation. this is the directory\n");
53 log(
" that contains the setup_env.sh file. when this option is not present,\n");
54 log(
" it is assumed that vhdl2verilog is in the PATH environment variable.\n");
56 log(
" -top <top-entity-name>\n");
57 log(
" The name of the top entity. This option is mandatory.\n");
59 log(
"The following options are passed as-is to vhdl2verilog:\n");
61 log(
" -arch <architecture_name>\n");
62 log(
" -unroll_generate\n");
63 log(
" -nogenericeval\n");
64 log(
" -nouniquify\n");
66 log(
" -suppress <list>\n");
69 log(
" -mapfile <file>\n");
71 log(
"vhdl2verilog can be obtained from:\n");
72 log(
"http://www.edautils.com/vhdl2verilog.html\n");
77 log_header(
"Executing VHDL2VERILOG (importing VHDL designs using vhdl2verilog).\n");
80 std::string out_file, top_entity;
81 std::string vhdl2verilog_dir;
82 std::string extra_opts;
85 for (argidx = 1; argidx < args.size(); argidx++) {
86 if (args[argidx] ==
"-out" && argidx+1 < args.size()) {
87 out_file = args[++argidx];
90 if (args[argidx] ==
"-top" && argidx+1 < args.size()) {
91 top_entity = args[++argidx];
94 if (args[argidx] ==
"-vhdl2verilog_dir" && argidx+1 < args.size()) {
95 vhdl2verilog_dir = args[++argidx];
98 if ((args[argidx] ==
"-arch" || args[argidx] ==
"-suppress" || args[argidx] ==
"-mapfile") && argidx+1 < args.size()) {
99 if (args[argidx] ==
"-mapfile" && !args[argidx+1].empty() && args[argidx+1][0] !=
'/') {
101 if (!getcwd(pwd,
sizeof(pwd))) {
105 args[argidx+1] = pwd + (
"/" + args[argidx+1]);
107 extra_opts += std::string(
" ") + args[argidx];
108 extra_opts += std::string(
" '") + args[++argidx] + std::string(
"'");
111 if (args[argidx] ==
"-unroll_generate" || args[argidx] ==
"-nogenericeval" || args[argidx] ==
"-nouniquify" ||
112 args[argidx] ==
"-oldparser" || args[argidx] ==
"-quiet" || args[argidx] ==
"-nobanner") {
113 extra_opts += std::string(
" ") + args[argidx];
119 if (argidx == args.size())
120 cmd_error(args, argidx,
"Missing filenames.");
121 if (args[argidx].substr(0, 1) ==
"-")
122 cmd_error(args, argidx,
"Unknown option.");
123 if (top_entity.empty())
126 std::string tempdir_name =
make_temp_dir(
"/tmp/yosys-vhdl2verilog-XXXXXX");
127 log(
"Using temp directory %s.\n", tempdir_name.c_str());
129 if (!out_file.empty() && out_file[0] !=
'/') {
131 if (!getcwd(pwd,
sizeof(pwd))) {
135 out_file = pwd + (
"/" + out_file);
138 FILE *f = fopen(
stringf(
"%s/files.list", tempdir_name.c_str()).c_str(),
"wt");
139 while (argidx < args.size()) {
140 std::string file = args[argidx++];
143 if (file[0] !=
'/') {
145 if (!getcwd(pwd,
sizeof(pwd))) {
149 file = pwd + (
"/" + file);
151 fprintf(f,
"%s\n", file.c_str());
152 log(
"Adding '%s' to the file list.\n", file.c_str());
156 std::string command =
"exec 2>&1; ";
157 if (!vhdl2verilog_dir.empty())
158 command +=
stringf(
"cd '%s'; . ./setup_env.sh; ", vhdl2verilog_dir.c_str());
159 command +=
stringf(
"cd '%s'; vhdl2verilog -out '%s' -filelist files.list -top '%s'%s", tempdir_name.c_str(),
160 out_file.empty() ?
"vhdl2verilog_output.v" : out_file.c_str(), top_entity.c_str(), extra_opts.c_str());
162 log(
"Running '%s'..\n", command.c_str());
164 int ret =
run_command(command, [](
const std::string &
line) {
log(
"%s", line.c_str()); });
166 log_error(
"Execution of command \"%s\" failed: return code %d.\n", command.c_str(), ret);
168 if (out_file.empty()) {
170 ff.open(
stringf(
"%s/vhdl2verilog_output.v", tempdir_name.c_str()).c_str());
172 log_error(
"Can't open vhdl2verilog output file `vhdl2verilog_output.v'.\n");
176 log_header(
"Removing temp directory `%s':\n", tempdir_name.c_str());
void cmd_error(const std::vector< std::string > &args, size_t argidx, std::string msg)
std::string stringf(const char *fmt,...)
void remove_directory(std::string dirname)
void log_header(const char *format,...)
#define YOSYS_NAMESPACE_END
static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command)
void log_error(const char *format,...)
int run_command(const std::string &command, std::function< void(const std::string &)> process_line)
Vhdl2verilogPass Vhdl2verilogPass
std::string make_temp_dir(std::string template_str)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
void log_cmd_error(const char *format,...)
#define YOSYS_NAMESPACE_BEGIN
void log(const char *format,...)