write_verilog escaped bus port name "input [7:0] \in[0] ;"
This commit is contained in:
parent
7af69066df
commit
74e287a7eb
|
|
@ -43,6 +43,7 @@ void
|
||||||
parseBusName(const char *name,
|
parseBusName(const char *name,
|
||||||
const char brkt_left,
|
const char brkt_left,
|
||||||
const char brkt_right,
|
const char brkt_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &index)
|
int &index)
|
||||||
{
|
{
|
||||||
|
|
@ -55,6 +56,7 @@ void
|
||||||
parseBusName(const char *name,
|
parseBusName(const char *name,
|
||||||
const char *brkts_left,
|
const char *brkts_left,
|
||||||
const char *brkts_right,
|
const char *brkts_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &index)
|
int &index)
|
||||||
{
|
{
|
||||||
|
|
@ -81,6 +83,7 @@ void
|
||||||
parseBusRange(const char *name,
|
parseBusRange(const char *name,
|
||||||
const char brkt_left,
|
const char brkt_left,
|
||||||
const char brkt_right,
|
const char brkt_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &from,
|
int &from,
|
||||||
int &to)
|
int &to)
|
||||||
|
|
@ -94,6 +97,7 @@ void
|
||||||
parseBusRange(const char *name,
|
parseBusRange(const char *name,
|
||||||
const char *brkts_left,
|
const char *brkts_left,
|
||||||
const char *brkts_right,
|
const char *brkts_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &from,
|
int &from,
|
||||||
int &to)
|
int &to)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ isBusName(const char *name,
|
||||||
|
|
||||||
// Parse name as a bus.
|
// Parse name as a bus.
|
||||||
// signal
|
// signal
|
||||||
// bus_name = 0
|
// bus_name = nullptr
|
||||||
// bus[bit]
|
// bus[bit]
|
||||||
// bus_name = "bus"
|
// bus_name = "bus"
|
||||||
// index = bit
|
// index = bit
|
||||||
|
|
@ -36,6 +36,7 @@ void
|
||||||
parseBusName(const char *name,
|
parseBusName(const char *name,
|
||||||
const char brkt_left,
|
const char brkt_left,
|
||||||
const char brkt_right,
|
const char brkt_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &index);
|
int &index);
|
||||||
// Allow multiple different left/right bus brackets.
|
// Allow multiple different left/right bus brackets.
|
||||||
|
|
@ -43,6 +44,7 @@ void
|
||||||
parseBusName(const char *name,
|
parseBusName(const char *name,
|
||||||
const char *brkts_left,
|
const char *brkts_left,
|
||||||
const char *brkts_right,
|
const char *brkts_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &index);
|
int &index);
|
||||||
|
|
||||||
|
|
@ -53,6 +55,7 @@ void
|
||||||
parseBusRange(const char *name,
|
parseBusRange(const char *name,
|
||||||
const char brkt_left,
|
const char brkt_left,
|
||||||
const char brkt_right,
|
const char brkt_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &from,
|
int &from,
|
||||||
int &to);
|
int &to);
|
||||||
|
|
@ -62,6 +65,7 @@ void
|
||||||
parseBusRange(const char *name,
|
parseBusRange(const char *name,
|
||||||
const char *brkts_left,
|
const char *brkts_left,
|
||||||
const char *brkts_right,
|
const char *brkts_right,
|
||||||
|
// Return values.
|
||||||
char *&bus_name,
|
char *&bus_name,
|
||||||
int &from,
|
int &from,
|
||||||
int &to);
|
int &to);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "Machine.hh"
|
#include "Machine.hh"
|
||||||
#include "StringUtil.hh"
|
#include "StringUtil.hh"
|
||||||
|
#include "ParseBus.hh"
|
||||||
#include "VerilogNamespace.hh"
|
#include "VerilogNamespace.hh"
|
||||||
|
|
||||||
namespace sta {
|
namespace sta {
|
||||||
|
|
@ -25,21 +26,29 @@ const char *
|
||||||
instanceVerilogName(const char *sta_name,
|
instanceVerilogName(const char *sta_name,
|
||||||
const char escape)
|
const char escape)
|
||||||
{
|
{
|
||||||
return staToVerilog(sta_name, true, escape);
|
return staToVerilog(sta_name, escape);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
netVerilogName(const char *sta_name,
|
netVerilogName(const char *sta_name,
|
||||||
const char escape)
|
const char escape)
|
||||||
{
|
{
|
||||||
return staToVerilog(sta_name, false, escape);
|
char *bus_name;
|
||||||
|
int index;
|
||||||
|
parseBusName(sta_name, '[', ']', bus_name, index);
|
||||||
|
if (bus_name)
|
||||||
|
return stringPrintTmp("%s[%d]",
|
||||||
|
staToVerilog(bus_name, escape),
|
||||||
|
index);
|
||||||
|
else
|
||||||
|
return staToVerilog(sta_name, escape);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
portVerilogName(const char *sta_name,
|
portVerilogName(const char *sta_name,
|
||||||
const char escape)
|
const char escape)
|
||||||
{
|
{
|
||||||
return staToVerilog(sta_name, false, escape);
|
return staToVerilog(sta_name, escape);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append ch to str at insert. Resize str if necessary.
|
// Append ch to str at insert. Resize str if necessary.
|
||||||
|
|
@ -63,7 +72,6 @@ vstringAppend(char *&str,
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
staToVerilog(const char *sta_name,
|
staToVerilog(const char *sta_name,
|
||||||
bool escape_brkts,
|
|
||||||
const char escape)
|
const char escape)
|
||||||
{
|
{
|
||||||
const char bus_brkt_left = '[';
|
const char bus_brkt_left = '[';
|
||||||
|
|
@ -93,7 +101,7 @@ staToVerilog(const char *sta_name,
|
||||||
else {
|
else {
|
||||||
bool is_brkt = (ch == bus_brkt_left || ch == bus_brkt_right);
|
bool is_brkt = (ch == bus_brkt_left || ch == bus_brkt_right);
|
||||||
if ((!(isalnum(ch) || ch == '_') && !is_brkt)
|
if ((!(isalnum(ch) || ch == '_') && !is_brkt)
|
||||||
|| (is_brkt && escape_brkts))
|
|| is_brkt)
|
||||||
escaped = true;
|
escaped = true;
|
||||||
vstringAppend(verilog_name, verilog_name_end, v, ch);
|
vstringAppend(verilog_name, verilog_name_end, v, ch);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ namespace sta {
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
staToVerilog(const char *sta_name,
|
staToVerilog(const char *sta_name,
|
||||||
bool escape_brkts,
|
|
||||||
const char escape);
|
const char escape);
|
||||||
const char *
|
const char *
|
||||||
verilogToSta(const char *verilog_name);
|
verilogToSta(const char *verilog_name);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,10 @@ void
|
||||||
write_verilog_cmd(const char *filename,
|
write_verilog_cmd(const char *filename,
|
||||||
bool sort)
|
bool sort)
|
||||||
{
|
{
|
||||||
Network *network = cmdNetwork();
|
// This does NOT want the SDC (cmd) network because it wants
|
||||||
|
// to see the sta internal names.
|
||||||
|
Sta *sta = Sta::sta();
|
||||||
|
Network *network = sta->network();
|
||||||
writeVerilog(filename, sort, network);
|
writeVerilog(filename, sort, network);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1721,8 +1721,9 @@ VerilogReader::linkNetwork(const char *top_cell_name,
|
||||||
bool make_black_boxes,
|
bool make_black_boxes,
|
||||||
Report *report)
|
Report *report)
|
||||||
{
|
{
|
||||||
|
if (library_) {
|
||||||
Cell *top_cell = network_->findCell(library_, top_cell_name);
|
Cell *top_cell = network_->findCell(library_, top_cell_name);
|
||||||
VerilogModule *module = verilog_reader->module(top_cell);
|
VerilogModule *module = this->module(top_cell);
|
||||||
if (module) {
|
if (module) {
|
||||||
// Seed the recursion for expansion with the top level instance.
|
// Seed the recursion for expansion with the top level instance.
|
||||||
Instance *top_instance = network_->makeInstance(top_cell, "", nullptr);
|
Instance *top_instance = network_->makeInstance(top_cell, "", nullptr);
|
||||||
|
|
@ -1758,6 +1759,11 @@ VerilogReader::linkNetwork(const char *top_cell_name,
|
||||||
report->error("%s is not a verilog module.\n", top_cell_name);
|
report->error("%s is not a verilog module.\n", top_cell_name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
report->error("%s is not a verilog module.\n", top_cell_name);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -1848,7 +1854,7 @@ VerilogReader::makeModuleInstNetwork(VerilogModuleInst *mod_inst,
|
||||||
parent_module, parent_bindings, is_leaf);
|
parent_module, parent_bindings, is_leaf);
|
||||||
}
|
}
|
||||||
if (!is_leaf) {
|
if (!is_leaf) {
|
||||||
VerilogModule *module = verilog_reader->module(cell);
|
VerilogModule *module = this->module(cell);
|
||||||
makeModuleInstBody(module, inst, &bindings, make_black_boxes);
|
makeModuleInstBody(module, inst, &bindings, make_black_boxes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ writeVerilog(const char *filename,
|
||||||
bool sort,
|
bool sort,
|
||||||
Network *network)
|
Network *network)
|
||||||
{
|
{
|
||||||
|
if (network->topInstance()) {
|
||||||
FILE *stream = fopen(filename, "w");
|
FILE *stream = fopen(filename, "w");
|
||||||
if (stream) {
|
if (stream) {
|
||||||
VerilogWriter writer(filename, sort, stream, network);
|
VerilogWriter writer(filename, sort, stream, network);
|
||||||
|
|
@ -74,6 +75,7 @@ writeVerilog(const char *filename,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw FileNotWritable(filename);
|
throw FileNotWritable(filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VerilogWriter::VerilogWriter(const char *filename,
|
VerilogWriter::VerilogWriter(const char *filename,
|
||||||
|
|
@ -117,8 +119,8 @@ VerilogWriter::writePorts(Cell *cell)
|
||||||
Port *port = port_iter->next();
|
Port *port = port_iter->next();
|
||||||
if (!first)
|
if (!first)
|
||||||
fprintf(stream_, ",\n ");
|
fprintf(stream_, ",\n ");
|
||||||
fprintf(stream_, "%s",
|
fprintf(stream_, "%s", portVerilogName(network_->name(port),
|
||||||
network_->name(port));
|
network_->pathEscape()));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
delete port_iter;
|
delete port_iter;
|
||||||
|
|
@ -132,23 +134,23 @@ VerilogWriter::writePortDcls(Cell *cell)
|
||||||
while (port_iter->hasNext()) {
|
while (port_iter->hasNext()) {
|
||||||
Port *port = port_iter->next();
|
Port *port = port_iter->next();
|
||||||
PortDirection *dir = network_->direction(port);
|
PortDirection *dir = network_->direction(port);
|
||||||
if (dir) {
|
const char *port_name = portVerilogName(network_->name(port),
|
||||||
fprintf(stream_, " %s",
|
network_->pathEscape());
|
||||||
verilogPortDir(dir));
|
const char *vtype = verilogPortDir(dir);
|
||||||
|
if (vtype) {
|
||||||
|
fprintf(stream_, " %s", vtype);
|
||||||
if (network_->isBus(port))
|
if (network_->isBus(port))
|
||||||
fprintf(stream_, " [%d:%d]",
|
fprintf(stream_, " [%d:%d]",
|
||||||
network_->fromIndex(port),
|
network_->fromIndex(port),
|
||||||
network_->toIndex(port));
|
network_->toIndex(port));
|
||||||
fprintf(stream_, " %s;\n",
|
fprintf(stream_, " %s;\n", port_name);
|
||||||
network_->name(port));
|
|
||||||
if (dir->isTristate()) {
|
if (dir->isTristate()) {
|
||||||
fprintf(stream_, " tri");
|
fprintf(stream_, " tri");
|
||||||
if (network_->isBus(port))
|
if (network_->isBus(port))
|
||||||
fprintf(stream_, " [%d:%d]",
|
fprintf(stream_, " [%d:%d]",
|
||||||
network_->fromIndex(port),
|
network_->fromIndex(port),
|
||||||
network_->toIndex(port));
|
network_->toIndex(port));
|
||||||
fprintf(stream_, " %s;\n",
|
fprintf(stream_, " %s;\n", port_name);
|
||||||
network_->name(port));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +228,8 @@ VerilogWriter::writeInstPin(Instance *inst,
|
||||||
const char *net_vname = netVerilogName(net_name, network_->pathEscape());
|
const char *net_vname = netVerilogName(net_name, network_->pathEscape());
|
||||||
if (!first_port)
|
if (!first_port)
|
||||||
fprintf(stream_, ",\n ");
|
fprintf(stream_, ",\n ");
|
||||||
const char *port_name = network_->name(port);
|
const char *port_name = portVerilogName(network_->name(port),
|
||||||
|
network_->pathEscape());
|
||||||
fprintf(stream_, ".%s(%s)",
|
fprintf(stream_, ".%s(%s)",
|
||||||
port_name,
|
port_name,
|
||||||
net_vname);
|
net_vname);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue