Skip to content

Commit 975fb1e

Browse files
committed
Verilog: move array_type method into verilog_typecheck_exprt
This moves the verilog_typecheckt::array_type method to verilog_typecheck_exprt, together with the other type conversion methods.
1 parent de6e7e7 commit 975fb1e

File tree

4 files changed

+74
-78
lines changed

4 files changed

+74
-78
lines changed

src/verilog/verilog_typecheck.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -28,80 +28,6 @@ Author: Daniel Kroening, [email protected]
2828

2929
/*******************************************************************\
3030
31-
Function: verilog_typecheckt::array_type
32-
33-
Inputs:
34-
35-
Outputs:
36-
37-
Purpose:
38-
39-
\*******************************************************************/
40-
41-
array_typet verilog_typecheckt::array_type(
42-
const irept &src,
43-
const typet &element_type)
44-
{
45-
// int whatnot[x:y];
46-
// 'src' is yet to be converted, but 'element_type' is already converted.
47-
PRECONDITION(src.id() == ID_verilog_unpacked_array);
48-
49-
// Unpacked arrays may have a range [x:y],
50-
// or a size [s], equivalent to [0:s-1]
51-
const exprt &range_expr = static_cast<const exprt &>(src.find(ID_range));
52-
const exprt &size_expr = static_cast<const exprt &>(src.find(ID_size));
53-
54-
mp_integer size, offset;
55-
bool little_endian;
56-
57-
if(range_expr.is_not_nil())
58-
{
59-
// these may be negative
60-
mp_integer msb, lsb;
61-
convert_range(range_expr, msb, lsb);
62-
little_endian = (lsb <= msb);
63-
size = (little_endian ? msb - lsb : lsb - msb) + 1;
64-
offset = little_endian ? lsb : msb;
65-
}
66-
else if(size_expr.is_not_nil())
67-
{
68-
little_endian = true;
69-
size = convert_integer_constant_expression(size_expr);
70-
offset = 0;
71-
if(size < 0)
72-
{
73-
throw errort().with_location(size_expr.find_source_location())
74-
<< "array size must be nonnegative";
75-
}
76-
}
77-
else
78-
{
79-
throw errort() << "array must have range or size";
80-
}
81-
82-
const typet src_subtype =
83-
static_cast<const typet &>(src).has_subtype()
84-
? static_cast<const type_with_subtypet &>(src).subtype()
85-
: typet(ID_nil);
86-
87-
typet array_subtype;
88-
89-
// may need to go recursive
90-
if(src_subtype.is_nil())
91-
array_subtype=element_type;
92-
else
93-
array_subtype=array_type(src_subtype, element_type);
94-
95-
const exprt final_size_expr = from_integer(size, integer_typet());
96-
array_typet result(array_subtype, final_size_expr);
97-
result.set(ID_offset, from_integer(offset, integer_typet()));
98-
result.set(ID_C_little_endian, little_endian);
99-
100-
return result;
101-
}
102-
103-
/*******************************************************************\
104-
10531
Function: verilog_typecheckt::typecheck_port_connection
10632
10733
Inputs:

src/verilog/verilog_typecheck.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ class verilog_typecheckt:
125125
void interface_generate_block(const class verilog_generate_blockt &);
126126
void interface_statement(const class verilog_statementt &);
127127

128-
array_typet array_type(
129-
const irept &src,
130-
const typet &element_type);
131-
132128
// type checking
133129

134130
typedef enum { A_CONTINUOUS, A_BLOCKING, A_NON_BLOCKING } vassignt;

src/verilog/verilog_typecheck_expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class verilog_typecheck_exprt:public verilog_typecheck_baset
6464

6565
typet convert_type(const typet &);
6666
typet convert_enum(const class verilog_enum_typet &);
67+
array_typet array_type(const irept &src, const typet &element_type);
6768

6869
void convert_range(
6970
const exprt &range,

src/verilog/verilog_typecheck_type.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,79 @@ Author: Daniel Kroening, [email protected]
1616

1717
/*******************************************************************\
1818
19+
Function: verilog_typecheck_exprt::array_type
20+
21+
Inputs:
22+
23+
Outputs:
24+
25+
Purpose:
26+
27+
\*******************************************************************/
28+
29+
array_typet
30+
verilog_typecheck_exprt::array_type(const irept &src, const typet &element_type)
31+
{
32+
// int whatnot[x:y];
33+
// 'src' is yet to be converted, but 'element_type' is already converted.
34+
PRECONDITION(src.id() == ID_verilog_unpacked_array);
35+
36+
// Unpacked arrays may have a range [x:y],
37+
// or a size [s], equivalent to [0:s-1]
38+
const exprt &range_expr = static_cast<const exprt &>(src.find(ID_range));
39+
const exprt &size_expr = static_cast<const exprt &>(src.find(ID_size));
40+
41+
mp_integer size, offset;
42+
bool little_endian;
43+
44+
if(range_expr.is_not_nil())
45+
{
46+
// these may be negative
47+
mp_integer msb, lsb;
48+
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;
52+
}
53+
else if(size_expr.is_not_nil())
54+
{
55+
little_endian = true;
56+
size = convert_integer_constant_expression(size_expr);
57+
offset = 0;
58+
if(size < 0)
59+
{
60+
throw errort().with_location(size_expr.find_source_location())
61+
<< "array size must be nonnegative";
62+
}
63+
}
64+
else
65+
{
66+
throw errort() << "array must have range or size";
67+
}
68+
69+
const typet src_subtype =
70+
static_cast<const typet &>(src).has_subtype()
71+
? static_cast<const type_with_subtypet &>(src).subtype()
72+
: typet(ID_nil);
73+
74+
typet array_subtype;
75+
76+
// may need to go recursive
77+
if(src_subtype.is_nil())
78+
array_subtype = element_type;
79+
else
80+
array_subtype = array_type(src_subtype, element_type);
81+
82+
const exprt final_size_expr = from_integer(size, integer_typet());
83+
array_typet result(array_subtype, final_size_expr);
84+
result.set(ID_offset, from_integer(offset, integer_typet()));
85+
result.set(ID_C_little_endian, little_endian);
86+
87+
return result;
88+
}
89+
90+
/*******************************************************************\
91+
1992
Function: verilog_typecheck_exprt::convert_type
2093
2194
Inputs:

0 commit comments

Comments
 (0)