Skip to content

Commit cf00a16

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

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
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_typecheck_expr.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,20 @@ 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;
@@ -820,6 +825,8 @@ void verilog_typecheck_exprt::convert_hierarchical_identifier(
820825
full_identifier=
821826
id2string(module)+"."+id2string(rhs_identifier);
822827

828+
expr.identifier(full_identifier);
829+
823830
const symbolt *symbol;
824831
if(!ns.lookup(full_identifier, symbol))
825832
{

0 commit comments

Comments
 (0)