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())
121 if (
args[argidx].substr(0, 1) ==
"-")
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,...)
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)
std::string make_temp_dir(std::string template_str)
void log_cmd_error(const char *format,...)
void log(const char *format,...)