Skip to content

Commit 92802c8

Browse files
committed
Emit \hdlname attribute.
This attribute is used by consumers such as CXXRTL and prjunnamed in order to build an accurate depiction of hierarchy post-flattening (even in presence of modules whose names have dots in them).
1 parent a55de5b commit 92802c8

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/slang_frontend.cc

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
19721972
for (auto chunk : latch_driven.chunks()) {
19731973
RTLIL::SigSpec en = netlist.canvas->addWire(netlist.new_id(), chunk.bitwidth());
19741974
RTLIL::SigSpec staging = netlist.canvas->addWire(netlist.new_id(), chunk.bitwidth());
1975-
1975+
19761976
for (int i = 0; i < chunk.bitwidth(); i++) {
19771977
RTLIL::Cell *cell = netlist.canvas->addDlatch(netlist.new_id(), en[i],
19781978
staging[i], netlist.convert_static(chunk[i]), true);
@@ -2230,6 +2230,7 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
22302230
// blackboxes get special handling no matter the hierarchy mode
22312231
if (sym.isModule() && netlist.is_blackbox(sym.body.getDefinition())) {
22322232
RTLIL::Cell *cell = netlist.canvas->addCell(netlist.id(sym), RTLIL::escape_id(std::string(sym.body.name)));
2233+
cell->set_string_attribute(RTLIL::ID::hdlname, netlist.hdlname(sym));
22332234

22342235
for (auto *conn : sym.getPortConnections()) {
22352236
switch (conn->port.kind) {
@@ -2341,6 +2342,7 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
23412342
auto [submodule, inserted] = queue.get_or_emplace(ref_body, netlist, *ref_body->parentInstance);
23422343

23432344
RTLIL::Cell *cell = netlist.canvas->addCell(netlist.id(sym), module_type_id(*ref_body));
2345+
cell->set_string_attribute(RTLIL::ID::hdlname, netlist.hdlname(sym));
23442346
for (auto *conn : sym.getPortConnections()) {
23452347
slang::SourceLocation loc;
23462348
if (auto expr = conn->getExpression())
@@ -2560,6 +2562,7 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
25602562

25612563
if (netlist.is_inferred_memory(sym)) {
25622564
RTLIL::Memory *m = new RTLIL::Memory;
2565+
m->set_string_attribute(RTLIL::ID::hdlname, netlist.hdlname(sym));
25632566
transfer_attrs(sym, m);
25642567
m->name = netlist.id(sym);
25652568
m->width = sym.getType().getArrayElementType()->getBitstreamWidth();
@@ -2625,6 +2628,7 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
26252628
if (netlist.is_inferred_memory(sym)) {
26262629
RTLIL::IdString id = netlist.id(sym);
26272630
RTLIL::Memory *m = netlist.canvas->memories.at(id);
2631+
m->set_string_attribute(RTLIL::ID::hdlname, netlist.hdlname(sym));
26282632
RTLIL::Cell *meminit = netlist.canvas->addCell(netlist.new_id(), ID($meminit_v2));
26292633
int abits = 32;
26302634
ast_invariant(sym, m->width * m->size == const_.size());
@@ -2691,7 +2695,8 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
26912695
}
26922696

26932697
RTLIL::Cell *cell = netlist.canvas->addCell(netlist.id(sym),
2694-
id(sym.definitionName));
2698+
id(sym.definitionName));
2699+
cell->set_string_attribute(RTLIL::ID::hdlname, netlist.hdlname(sym));
26952700
transfer_attrs(sym, cell);
26962701

26972702
auto port_names = sym.getPortNames();
@@ -2906,14 +2911,15 @@ struct PopulateNetlist : public TimingPatternInterpretor, public ast::ASTVisitor
29062911
};
29072912

29082913
static void build_hierpath2(NetlistContext &netlist,
2909-
std::ostringstream &s, const ast::Scope *scope)
2914+
std::ostringstream &s, const ast::Scope *scope,
2915+
const std::string &sep = ".")
29102916
{
29112917
if (!scope ||
29122918
static_cast<const ast::Scope *>(&netlist.realm) == scope)
29132919
return;
29142920

29152921
if (netlist.scopes_remap.count(scope)) {
2916-
s << netlist.scopes_remap.at(scope) << ".";
2922+
s << netlist.scopes_remap.at(scope) << sep;
29172923
return;
29182924
}
29192925

@@ -2925,17 +2931,17 @@ static void build_hierpath2(NetlistContext &netlist,
29252931
symbol = symbol->as<ast::CheckerInstanceBodySymbol>().parentInstance;
29262932

29272933
if (auto parent = symbol->getParentScope())
2928-
build_hierpath2(netlist, s, parent);
2934+
build_hierpath2(netlist, s, parent, sep);
29292935

29302936
if (symbol->kind == ast::SymbolKind::GenerateBlockArray) {
29312937
auto &array = symbol->as<ast::GenerateBlockArraySymbol>();
29322938
s << array.getExternalName();
29332939
} else if (symbol->kind == ast::SymbolKind::GenerateBlock) {
29342940
auto &block = symbol->as<ast::GenerateBlockSymbol>();
29352941
if (auto index = block.arrayIndex) {
2936-
s << "[" << index->toString(slang::LiteralBase::Decimal, false) << "].";
2942+
s << "[" << index->toString(slang::LiteralBase::Decimal, false) << "]" << sep;
29372943
} else {
2938-
s << block.getExternalName() << ".";
2944+
s << block.getExternalName() << sep;
29392945
}
29402946
} else if (symbol->kind == ast::SymbolKind::Instance ||
29412947
symbol->kind == ast::SymbolKind::CheckerInstance) {
@@ -2950,13 +2956,13 @@ static void build_hierpath2(NetlistContext &netlist,
29502956
s << "[" << ((int) inst.arrayPath[i]) + dimensions[i].lower() << "]";
29512957
}
29522958

2953-
s << ".";
2959+
s << sep;
29542960
} else if (symbol->kind == ast::SymbolKind::InstanceArray) {
29552961
s << symbol->name;
29562962
} else if (!symbol->name.empty()) {
2957-
s << symbol->name << ".";
2963+
s << symbol->name << sep;
29582964
} else if (symbol->kind == ast::SymbolKind::StatementBlock) {
2959-
s << "$" << (int) symbol->getIndex() << ".";
2965+
s << "$" << (int) symbol->getIndex() << sep;
29602966
}
29612967
}
29622968

@@ -3041,10 +3047,11 @@ std::string hierpath_relative_to(const ast::Scope *relative_to, const ast::Scope
30413047
return path.str();
30423048
}
30433049

3044-
RTLIL::IdString NetlistContext::id(const ast::Symbol &symbol)
3050+
std::string build_hiername(NetlistContext &netlist, const ast::Symbol &symbol,
3051+
const std::string &sep)
30453052
{
30463053
std::ostringstream path;
3047-
build_hierpath2(*this, path, symbol.getParentScope());
3054+
build_hierpath2(netlist, path, symbol.getParentScope(), sep);
30483055
path << symbol.name;
30493056

30503057
if (symbol.kind == ast::SymbolKind::Instance ||
@@ -3058,12 +3065,23 @@ RTLIL::IdString NetlistContext::id(const ast::Symbol &symbol)
30583065
}
30593066
}
30603067

3061-
return RTLIL::escape_id(path.str());
3068+
return path.str();
3069+
}
3070+
3071+
RTLIL::IdString NetlistContext::id(const ast::Symbol &symbol)
3072+
{
3073+
return RTLIL::escape_id(build_hiername(*this, symbol, "."));
3074+
}
3075+
3076+
std::string NetlistContext::hdlname(const ast::Symbol &symbol)
3077+
{
3078+
return build_hiername(*this, symbol, " ");
30623079
}
30633080

30643081
RTLIL::Wire *NetlistContext::add_wire(const ast::ValueSymbol &symbol)
30653082
{
30663083
auto w = canvas->addWire(id(symbol), symbol.getType().getBitstreamWidth());
3084+
w->set_string_attribute(RTLIL::ID::hdlname, hdlname(symbol));
30673085
wire_cache[&symbol] = w;
30683086
transfer_attrs(symbol, w);
30693087
return w;

src/slang_frontend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ struct NetlistContext : RTLILBuilder, public DiagnosticIssuer {
452452

453453
// Returns an ID string to use in the netlist to represent the given symbol.
454454
RTLIL::IdString id(const ast::Symbol &sym);
455+
std::string hdlname(const ast::Symbol &sym);
455456

456457
RTLIL::Wire *add_wire(const ast::ValueSymbol &sym);
457458
RTLIL::Wire *wire(const ast::Symbol &sym);

0 commit comments

Comments
 (0)