@@ -954,6 +954,11 @@ exprt verilog_typecheck_exprt::convert_hierarchical_identifier(
954
954
<< " identifier `" << rhs_identifier << " ' not found in named block" ;
955
955
}
956
956
}
957
+ else if (
958
+ expr.lhs ().type ().id () == ID_struct || expr.lhs ().type ().id () == ID_union)
959
+ {
960
+ throw errort ().with_location (expr.source_location ()) << " TBD" ;
961
+ }
957
962
else
958
963
{
959
964
throw errort ().with_location (expr.source_location ())
@@ -1490,23 +1495,25 @@ void verilog_typecheck_exprt::implicit_typecast(
1490
1495
if (dest_type.id ()==irep_idt ())
1491
1496
return ;
1492
1497
1498
+ const typet &src_type = expr.type ();
1499
+
1493
1500
auto &verilog_dest_type = dest_type.get (ID_C_verilog_type);
1494
1501
if (verilog_dest_type == ID_verilog_enum)
1495
1502
{
1496
1503
// IEEE 1800-2017 6.19.3: "a variable of type enum cannot be directly
1497
1504
// assigned a value that lies outside the enumeration set unless an
1498
1505
// explicit cast is used"
1499
1506
if (
1500
- expr. type () .get (ID_C_verilog_type) != ID_verilog_enum ||
1501
- expr. type () .get (ID_C_identifier) != dest_type.get (ID_C_identifier))
1507
+ src_type .get (ID_C_verilog_type) != ID_verilog_enum ||
1508
+ src_type .get (ID_C_identifier) != dest_type.get (ID_C_identifier))
1502
1509
{
1503
1510
throw errort ().with_location (expr.source_location ())
1504
1511
<< " assignment to enum requires enum of the same type, but got "
1505
1512
<< to_string (expr.type ());
1506
1513
}
1507
1514
}
1508
1515
1509
- if (expr. type () ==dest_type)
1516
+ if (src_type ==dest_type)
1510
1517
return ;
1511
1518
1512
1519
if (dest_type.id () == ID_integer)
@@ -1527,15 +1534,15 @@ void verilog_typecheck_exprt::implicit_typecast(
1527
1534
}
1528
1535
1529
1536
if (
1530
- expr. type (). id () == ID_bool || expr. type () .id () == ID_unsignedbv ||
1531
- expr. type (). id () == ID_signedbv || expr. type () .id () == ID_integer)
1537
+ src_type. id () == ID_bool || src_type .id () == ID_unsignedbv ||
1538
+ src_type. id () == ID_signedbv || src_type .id () == ID_integer)
1532
1539
{
1533
1540
expr = typecast_exprt{expr, dest_type};
1534
1541
return ;
1535
1542
}
1536
1543
}
1537
1544
1538
- if (expr. type () .id () == ID_integer)
1545
+ if (src_type .id () == ID_integer)
1539
1546
{
1540
1547
// from integer to s.th. else
1541
1548
if (dest_type.id ()==ID_bool)
@@ -1558,19 +1565,20 @@ void verilog_typecheck_exprt::implicit_typecast(
1558
1565
return ;
1559
1566
}
1560
1567
}
1561
- else if (expr. type () .id ()==ID_bool ||
1562
- expr. type () .id ()==ID_unsignedbv ||
1563
- expr. type () .id ()==ID_signedbv ||
1564
- expr. type () .id ()==ID_verilog_unsignedbv ||
1565
- expr. type () .id ()==ID_verilog_signedbv)
1568
+ else if (src_type .id ()==ID_bool ||
1569
+ src_type .id ()==ID_unsignedbv ||
1570
+ src_type .id ()==ID_signedbv ||
1571
+ src_type .id ()==ID_verilog_unsignedbv ||
1572
+ src_type .id ()==ID_verilog_signedbv)
1566
1573
{
1574
+ // from bits to s.th. else
1567
1575
if (dest_type.id ()==ID_bool)
1568
1576
{
1569
1577
// do not use typecast here
1570
1578
// we actually only want the lowest bit
1571
1579
1572
1580
if (expr.is_constant () &&
1573
- expr. type () .id ()==ID_unsignedbv)
1581
+ src_type .id ()==ID_unsignedbv)
1574
1582
{
1575
1583
const std::string &value=expr.get_string (ID_value);
1576
1584
// least significant bit is last
@@ -1614,10 +1622,29 @@ void verilog_typecheck_exprt::implicit_typecast(
1614
1622
expr = typecast_exprt{expr, dest_type};
1615
1623
return ;
1616
1624
}
1625
+ else if (dest_type.id () == ID_struct)
1626
+ {
1627
+ // bit-vectors can be converted to packed structs
1628
+ expr = typecast_exprt{expr, dest_type};
1629
+ return ;
1630
+ }
1631
+ }
1632
+ else if (src_type.id () == ID_struct)
1633
+ {
1634
+ // packed structs can be converted to bits
1635
+ if (
1636
+ dest_type.id () == ID_bool || dest_type.id () == ID_unsignedbv ||
1637
+ dest_type.id () == ID_signedbv ||
1638
+ dest_type.id () == ID_verilog_unsignedbv ||
1639
+ dest_type.id () == ID_verilog_signedbv)
1640
+ {
1641
+ expr = typecast_exprt{expr, dest_type};
1642
+ return ;
1643
+ }
1617
1644
}
1618
1645
1619
1646
throw errort ().with_location (expr.source_location ())
1620
- << " failed to convert `" << to_string (expr. type () ) << " ' to `"
1647
+ << " failed to convert `" << to_string (src_type ) << " ' to `"
1621
1648
<< to_string (dest_type) << " '" ;
1622
1649
}
1623
1650
0 commit comments