Skip to content

Commit

Permalink
Preserve escaped names
Browse files Browse the repository at this point in the history
  • Loading branch information
alaindargelas committed Mar 5, 2024
1 parent 8aec6cf commit 9d64d8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
38 changes: 26 additions & 12 deletions openfpga/src/fpga_verilog/verilog_testbench_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ void print_verilog_testbench_fpga_instance(
fp << std::endl;
}

std::string escapeNames(const std::string& original) {
std::string result = original;
if (result.find("$") != std::string::npos) {
result = "\\" + result + " ";
}
return result;
}

/********************************************************************
* Instanciate the input benchmark module
*******************************************************************/
Expand Down Expand Up @@ -224,17 +232,18 @@ void print_verilog_testbench_benchmark_instance(
fp << "~";
}

fp << bus_group.pin_name(pin);
std::string escapedName = bus_group.pin_name(pin);

/* For clock ports, skip postfix */
if (clock_port_names.end() == std::find(clock_port_names.begin(),
clock_port_names.end(),
port_names[iport])) {
fp << input_port_postfix;
escapedName += input_port_postfix;
} else if (include_clock_port_postfix) {
fp << input_port_postfix;
escapedName += input_port_postfix;
}

escapedName = escapeNames(escapedName);
fp << escapedName;
pin_counter++;
}
fp << "}";
Expand All @@ -249,16 +258,17 @@ void print_verilog_testbench_benchmark_instance(
pin_constraints.net_default_value(port_names[iport])) {
fp << "~";
}

fp << port_names[iport];
std::string escapedName = port_names[iport];
/* For clock ports, skip postfix */
if (clock_port_names.end() == std::find(clock_port_names.begin(),
clock_port_names.end(),
port_names[iport])) {
fp << input_port_postfix;
escapedName += input_port_postfix;
} else if (include_clock_port_postfix) {
fp << input_port_postfix;
escapedName += input_port_postfix;
}
escapedName = escapeNames(escapedName);
fp << escapedName;
}

if (true == use_explicit_port_map) {
Expand Down Expand Up @@ -286,12 +296,16 @@ void print_verilog_testbench_benchmark_instance(
if (0 < pin_counter) {
fp << ", ";
}
fp << bus_group.pin_name(pin) << output_port_postfix;
std::string escapedName = bus_group.pin_name(pin) + output_port_postfix;
escapedName = escapeNames(escapedName);
fp << escapedName;
pin_counter++;
}
fp << "}";
} else {
fp << port_names[iport] << output_port_postfix;
std::string escapedName = port_names[iport] + output_port_postfix;
escapedName = escapeNames(escapedName);
fp << escapedName;
}
if (true == use_explicit_port_map) {
fp << ")";
Expand Down Expand Up @@ -867,7 +881,7 @@ void print_verilog_testbench_random_stimuli(

/* TODO: find the clock inputs will be initialized later */
if (AtomBlockType::INPAD == atom_ctx.nlist.block_type(atom_blk)) {
fp << "\t\t" << block_name + input_port_postfix << " <= 1'b0;"
fp << "\t\t" << escapeNames(block_name + input_port_postfix) << " <= 1'b0;"
<< std::endl;
}
}
Expand Down Expand Up @@ -951,7 +965,7 @@ void print_verilog_testbench_random_stimuli(

/* TODO: find the clock inputs will be initialized later */
if (AtomBlockType::INPAD == atom_ctx.nlist.block_type(atom_blk)) {
fp << "\t\t" << block_name + input_port_postfix << " <= $random;"
fp << "\t\t" << escapeNames(block_name + input_port_postfix) << " <= $random;"
<< std::endl;
}
}
Expand Down
4 changes: 2 additions & 2 deletions openfpga/src/fpga_verilog/verilog_writer_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,10 @@ std::string generate_verilog_port(
} else if ((1 == port_info.get_width())) {
size_str = "[" + std::to_string(port_info.get_lsb()) + "]";
}
verilog_line = port_info.get_name() + size_str;
verilog_line = escapeNames(port_info.get_name()) + size_str;
} else {
verilog_line = VERILOG_PORT_TYPE_STRING[verilog_port_type];
verilog_line += " " + size_str + " " + port_info.get_name();
verilog_line += " " + size_str + " " + escapeNames(port_info.get_name());
}

return verilog_line;
Expand Down
2 changes: 2 additions & 0 deletions openfpga/src/fpga_verilog/verilog_writer_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ void print_verilog_netlist_include_header_file(
const char* subckt_dir, const char* header_file_name,
const bool& include_time_stamp);

std::string escapeNames(const std::string& name);

} /* end namespace openfpga */

#endif

0 comments on commit 9d64d8e

Please sign in to comment.