Skip to content

Commit 0961b8d

Browse files
committed
Verilog: fix nested hierarchical identifiers
Hierarchical identifiers with more than one level now work.
1 parent b83e940 commit 0961b8d

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
hierarchical_identifiers1.v
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/verilog/hierarchical_identifiers1/test.desc

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/verilog/verilog_expr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ class hierarchical_identifier_exprt : public binary_exprt
3333
return item();
3434
}
3535

36+
const irep_idt &identifier() const
37+
{
38+
return get(ID_identifier);
39+
}
40+
41+
void identifier(irep_idt _identifier)
42+
{
43+
set(ID_identifier, _identifier);
44+
}
45+
3646
protected:
3747
using binary_exprt::op0;
3848
using binary_exprt::op1;

src/verilog/verilog_synthesis.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ void verilog_synthesist::expand_hierarchical_identifier(
256256
const irep_idt &rhs_identifier = expr.rhs().get_identifier();
257257

258258
// just patch together
259-
260-
std::string full_identifier=
261-
id2string(lhs_identifier)+"."+id2string(rhs_identifier);
262259

263-
// Note: may not yet be in symbol table, as the inst module
264-
// item may be later.
260+
irep_idt full_identifier =
261+
id2string(lhs_identifier) + '.' + id2string(rhs_identifier);
262+
263+
// Note: the instance copy may not yet be in symbol table,
264+
// as the inst module item may be later.
265265
// The type checker already checked that it's fine.
266266

267267
symbol_exprt new_symbol{full_identifier, expr.type()};

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,22 +791,27 @@ void verilog_typecheck_exprt::convert_hierarchical_identifier(
791791
{
792792
convert_expr(expr.lhs());
793793

794-
if(expr.lhs().id() != ID_symbol)
795-
{
796-
throw errort().with_location(expr.source_location())
797-
<< "expected symbol on lhs of `.'";
798-
}
794+
const irep_idt &lhs_identifier = [](const exprt &lhs) {
795+
if(lhs.id() == ID_symbol)
796+
return to_symbol_expr(lhs).get_identifier();
797+
else if(lhs.id() == ID_hierarchical_identifier)
798+
return to_hierarchical_identifier_expr(lhs).identifier();
799+
else
800+
{
801+
throw errort().with_location(lhs.source_location())
802+
<< "expected symbol or hierarchical identifier on lhs of `.'";
803+
}
804+
}(expr.lhs());
799805

800806
DATA_INVARIANT(expr.rhs().id() == ID_symbol, "expected symbol on rhs of `.'");
801807

802-
const irep_idt &lhs_identifier = to_symbol_expr(expr.lhs()).get_identifier();
803808
const irep_idt &rhs_identifier = expr.rhs().get_identifier();
804809

805810
irep_idt full_identifier;
806811

807812
if(expr.lhs().type().id() == ID_module_instance)
808813
{
809-
// figure out which module this is
814+
// figure out which module the lhs is
810815
const symbolt *module_instance_symbol;
811816
if(ns.lookup(lhs_identifier, module_instance_symbol))
812817
{
@@ -817,6 +822,7 @@ void verilog_typecheck_exprt::convert_hierarchical_identifier(
817822

818823
const irep_idt &module=module_instance_symbol->value.get(ID_module);
819824

825+
// the identifier in the module
820826
full_identifier=
821827
id2string(module)+"."+id2string(rhs_identifier);
822828

@@ -839,6 +845,9 @@ void verilog_typecheck_exprt::convert_hierarchical_identifier(
839845
<< "identifier `" << rhs_identifier << "' not found in module `"
840846
<< module_instance_symbol->pretty_name << "'";
841847
}
848+
849+
// We remember the identifier of the symbol.
850+
expr.identifier(full_identifier);
842851
}
843852
else if(expr.lhs().type().id() == ID_named_block)
844853
{

0 commit comments

Comments
 (0)