Skip to content

Commit 9db8244

Browse files
authored
Merge pull request #584 from diffblue/big_endian
Verilog: little_endian -> big_endian
2 parents 89aceb5 + 2a28a48 commit 9db8244

File tree

7 files changed

+43
-40
lines changed

7 files changed

+43
-40
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
enum2.sv
33

4-
^file .* line 4: assignment to enum requires enum of the same type, but got signed \[0:31\]$
4+
^file .* line 4: assignment to enum requires enum of the same type, but got signed \[31:0\]$
55
^EXIT=2$
66
^SIGNAL=0$
77
--

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ IREP_ID_ONE(sva_overlapped_implication)
4646
IREP_ID_ONE(sva_non_overlapped_implication)
4747
IREP_ID_ONE(module_instance)
4848
IREP_ID_TWO(C_offset, #offset)
49-
IREP_ID_TWO(C_little_endian, #little_endian)
49+
IREP_ID_TWO(C_big_endian, #big_endian)
5050
IREP_ID_ONE(ports)
5151
IREP_ID_ONE(inst)
5252
IREP_ID_ONE(Verilog)

src/trans-netlist/trans_trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static std::string vcd_suffix(
647647
left_bound = offset;
648648
right_bound = left_bound+width-1;
649649

650-
if(type.get_bool(ID_C_little_endian))
650+
if(!type.get_bool(ID_C_big_endian))
651651
std::swap(left_bound, right_bound);
652652

653653
return "["+integer2string(left_bound)+":"+integer2string(right_bound)+"]";

src/verilog/expr2verilog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ std::string expr2verilogt::convert(const typet &type)
13611361
else if(type.id()==ID_unsignedbv || type.id()==ID_signedbv)
13621362
{
13631363
unsigned width=to_bitvector_type(type).get_width();
1364-
bool little_endian=type.get_bool(ID_C_little_endian);
1364+
bool big_endian = type.get_bool(ID_C_big_endian);
13651365
unsigned offset=atoi(type.get(ID_C_offset).c_str());
13661366

13671367
if(width!=0)
@@ -1373,18 +1373,18 @@ std::string expr2verilogt::convert(const typet &type)
13731373
dest="signed ";
13741374

13751375
dest+='[';
1376-
1377-
if(little_endian)
1376+
1377+
if(big_endian)
13781378
{
1379-
dest+=std::to_string(offset+width-1);
1380-
dest+=":";
13811379
dest+=std::to_string(offset);
1380+
dest += ":";
1381+
dest += std::to_string(offset + width - 1);
13821382
}
13831383
else
13841384
{
1385-
dest+=std::to_string(offset);
1386-
dest+=":";
13871385
dest+=std::to_string(offset+width-1);
1386+
dest += ":";
1387+
dest += std::to_string(offset);
13881388
}
13891389

13901390
dest+="]";

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,24 @@ constant_exprt verilog_typecheck_exprt::left(const exprt &expr)
483483
type.id() == ID_bool)
484484
{
485485
auto offset = type.get_int(ID_C_offset);
486-
if(type.get_bool(ID_C_little_endian))
487-
return offset + get_width(type) - 1;
488-
else
486+
if(type.get_bool(ID_C_big_endian))
489487
return offset;
488+
else
489+
return offset + get_width(type) - 1;
490490
}
491491
else if(type.id() == ID_array)
492492
{
493493
auto offset = numeric_cast_v<mp_integer>(
494494
to_constant_expr(static_cast<const exprt &>(type.find(ID_offset))));
495-
if(type.get_bool(ID_C_little_endian))
495+
if(type.get_bool(ID_C_big_endian))
496+
return offset;
497+
else
498+
{
496499
return offset +
497500
numeric_cast_v<mp_integer>(
498501
to_constant_expr(to_array_type(type).size())) -
499502
1;
500-
else
501-
return offset;
503+
}
502504
}
503505
else
504506
return 0;
@@ -531,22 +533,24 @@ constant_exprt verilog_typecheck_exprt::right(const exprt &expr)
531533
type.id() == ID_bool)
532534
{
533535
auto offset = type.get_int(ID_C_offset);
534-
if(type.get_bool(ID_C_little_endian))
535-
return offset;
536-
else
536+
if(type.get_bool(ID_C_big_endian))
537537
return offset + get_width(type) - 1;
538+
else
539+
return offset;
538540
}
539541
else if(type.id() == ID_array)
540542
{
541543
auto offset = numeric_cast_v<mp_integer>(
542544
to_constant_expr(static_cast<const exprt &>(type.find(ID_offset))));
543-
if(type.get_bool(ID_C_little_endian))
544-
return offset;
545-
else
545+
if(type.get_bool(ID_C_big_endian))
546+
{
546547
return offset +
547548
numeric_cast_v<mp_integer>(
548549
to_constant_expr(to_array_type(type).size())) -
549550
1;
551+
}
552+
else
553+
return offset;
550554
}
551555
else
552556
return 0;
@@ -576,10 +580,10 @@ constant_exprt verilog_typecheck_exprt::increment(const exprt &expr)
576580
type.id() == ID_verilog_unsignedbv || type.id() == ID_verilog_signedbv ||
577581
type.id() == ID_array)
578582
{
579-
if(type.get_bool(ID_C_little_endian))
580-
return 1;
581-
else
583+
if(type.get_bool(ID_C_big_endian))
582584
return -1;
585+
else
586+
return 1;
583587
}
584588
else
585589
return -1;
@@ -1330,9 +1334,8 @@ exprt verilog_typecheck_exprt::convert_constant(constant_exprt expr)
13301334
expr.type()=verilog_signedbv_typet(bits);
13311335
else
13321336
expr.type()=verilog_unsignedbv_typet(bits);
1333-
1337+
13341338
expr.set(ID_value, fvalue);
1335-
expr.set(ID_C_little_endian, true);
13361339
}
13371340
else
13381341
{
@@ -1351,7 +1354,6 @@ exprt verilog_typecheck_exprt::convert_constant(constant_exprt expr)
13511354
expr.type()=unsignedbv_typet(bits);
13521355

13531356
expr.set(ID_value, integer2bvrep(int_value, bits));
1354-
expr.set(ID_C_little_endian, true);
13551357
}
13561358

13571359
return std::move(expr);

src/verilog/verilog_typecheck_type.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ array_typet verilog_typecheck_exprt::convert_unpacked_array_type(
3939
const exprt &size_expr = static_cast<const exprt &>(src.find(ID_size));
4040

4141
mp_integer size, offset;
42-
bool little_endian;
42+
bool big_endian;
4343

4444
if(range_expr.is_not_nil())
4545
{
4646
// these may be negative
4747
mp_integer msb, lsb;
4848
convert_range(range_expr, msb, lsb);
49-
little_endian = (lsb <= msb);
50-
size = (little_endian ? msb - lsb : lsb - msb) + 1;
51-
offset = little_endian ? lsb : msb;
49+
big_endian = (lsb > msb);
50+
size = (big_endian ? lsb - msb : msb - lsb) + 1;
51+
DATA_INVARIANT(size >= 0, "array size must not be negative");
52+
offset = big_endian ? msb : lsb;
5253
}
5354
else if(size_expr.is_not_nil())
5455
{
55-
little_endian = true;
56+
big_endian = false;
5657
size = convert_integer_constant_expression(size_expr);
5758
offset = 0;
5859
if(size < 0)
@@ -73,7 +74,7 @@ array_typet verilog_typecheck_exprt::convert_unpacked_array_type(
7374
const exprt final_size_expr = from_integer(size, integer_typet());
7475
auto result = array_typet{element_type, final_size_expr};
7576
result.set(ID_offset, from_integer(offset, integer_typet()));
76-
result.set(ID_C_little_endian, little_endian);
77+
result.set(ID_C_big_endian, big_endian);
7778

7879
return result;
7980
}
@@ -182,11 +183,11 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
182183
mp_integer msb, lsb;
183184
convert_range(range, msb, lsb);
184185

185-
bool little_endian=(lsb<=msb);
186+
bool big_endian = (lsb > msb);
187+
188+
mp_integer width = (big_endian ? lsb - msb : msb - lsb) + 1;
189+
mp_integer offset = big_endian ? msb : lsb;
186190

187-
mp_integer width=(little_endian?msb-lsb:lsb-msb)+1;
188-
mp_integer offset=little_endian?lsb:msb;
189-
190191
// let's look at the subtype
191192
const auto subtype =
192193
static_cast<const typet &>(src).has_subtype()
@@ -204,7 +205,7 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
204205

205206
dest.add_source_location() = source_location;
206207
dest.set_width(width.to_ulong());
207-
dest.set(ID_C_little_endian, little_endian);
208+
dest.set(ID_C_big_endian, big_endian);
208209
dest.set(ID_C_offset, integer2string(offset));
209210

210211
return std::move(dest).with_source_location(source_location);

src/vhdl/expr2vhdl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ std::string expr2vhdlt::convert(const typet &type)
745745
else if(type.id()==ID_unsignedbv || type.id()==ID_signedbv)
746746
{
747747
unsigned width=to_bitvector_type(type).get_width();
748-
bool little_endian=type.get_bool(ID_C_little_endian);
748+
bool little_endian = type.get_bool(ID_C_big_endian);
749749
unsigned offset=atoi(type.get(ID_C_offset).c_str());
750750

751751
if(width!=0)

0 commit comments

Comments
 (0)