-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
74 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,80 +28,6 @@ Author: Daniel Kroening, [email protected] | |
|
||
/*******************************************************************\ | ||
Function: verilog_typecheckt::array_type | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
array_typet verilog_typecheckt::array_type( | ||
const irept &src, | ||
const typet &element_type) | ||
{ | ||
// int whatnot[x:y]; | ||
// 'src' is yet to be converted, but 'element_type' is already converted. | ||
PRECONDITION(src.id() == ID_verilog_unpacked_array); | ||
|
||
// Unpacked arrays may have a range [x:y], | ||
// or a size [s], equivalent to [0:s-1] | ||
const exprt &range_expr = static_cast<const exprt &>(src.find(ID_range)); | ||
const exprt &size_expr = static_cast<const exprt &>(src.find(ID_size)); | ||
|
||
mp_integer size, offset; | ||
bool little_endian; | ||
|
||
if(range_expr.is_not_nil()) | ||
{ | ||
// these may be negative | ||
mp_integer msb, lsb; | ||
convert_range(range_expr, msb, lsb); | ||
little_endian = (lsb <= msb); | ||
size = (little_endian ? msb - lsb : lsb - msb) + 1; | ||
offset = little_endian ? lsb : msb; | ||
} | ||
else if(size_expr.is_not_nil()) | ||
{ | ||
little_endian = true; | ||
size = convert_integer_constant_expression(size_expr); | ||
offset = 0; | ||
if(size < 0) | ||
{ | ||
throw errort().with_location(size_expr.find_source_location()) | ||
<< "array size must be nonnegative"; | ||
} | ||
} | ||
else | ||
{ | ||
throw errort() << "array must have range or size"; | ||
} | ||
|
||
const typet src_subtype = | ||
static_cast<const typet &>(src).has_subtype() | ||
? static_cast<const type_with_subtypet &>(src).subtype() | ||
: typet(ID_nil); | ||
|
||
typet array_subtype; | ||
|
||
// may need to go recursive | ||
if(src_subtype.is_nil()) | ||
array_subtype=element_type; | ||
else | ||
array_subtype=array_type(src_subtype, element_type); | ||
|
||
const exprt final_size_expr = from_integer(size, integer_typet()); | ||
array_typet result(array_subtype, final_size_expr); | ||
result.set(ID_offset, from_integer(offset, integer_typet())); | ||
result.set(ID_C_little_endian, little_endian); | ||
|
||
return result; | ||
} | ||
|
||
/*******************************************************************\ | ||
Function: verilog_typecheckt::typecheck_port_connection | ||
Inputs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,79 @@ Author: Daniel Kroening, [email protected] | |
|
||
/*******************************************************************\ | ||
Function: verilog_typecheck_exprt::array_type | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
array_typet | ||
verilog_typecheck_exprt::array_type(const irept &src, const typet &element_type) | ||
{ | ||
// int whatnot[x:y]; | ||
// 'src' is yet to be converted, but 'element_type' is already converted. | ||
PRECONDITION(src.id() == ID_verilog_unpacked_array); | ||
|
||
// Unpacked arrays may have a range [x:y], | ||
// or a size [s], equivalent to [0:s-1] | ||
const exprt &range_expr = static_cast<const exprt &>(src.find(ID_range)); | ||
const exprt &size_expr = static_cast<const exprt &>(src.find(ID_size)); | ||
|
||
mp_integer size, offset; | ||
bool little_endian; | ||
|
||
if(range_expr.is_not_nil()) | ||
{ | ||
// these may be negative | ||
mp_integer msb, lsb; | ||
convert_range(range_expr, msb, lsb); | ||
little_endian = (lsb <= msb); | ||
size = (little_endian ? msb - lsb : lsb - msb) + 1; | ||
offset = little_endian ? lsb : msb; | ||
} | ||
else if(size_expr.is_not_nil()) | ||
{ | ||
little_endian = true; | ||
size = convert_integer_constant_expression(size_expr); | ||
offset = 0; | ||
if(size < 0) | ||
{ | ||
throw errort().with_location(size_expr.find_source_location()) | ||
<< "array size must be nonnegative"; | ||
} | ||
} | ||
else | ||
{ | ||
throw errort() << "array must have range or size"; | ||
} | ||
|
||
const typet src_subtype = | ||
static_cast<const typet &>(src).has_subtype() | ||
? static_cast<const type_with_subtypet &>(src).subtype() | ||
: typet(ID_nil); | ||
|
||
typet array_subtype; | ||
|
||
// may need to go recursive | ||
if(src_subtype.is_nil()) | ||
array_subtype = element_type; | ||
else | ||
array_subtype = array_type(src_subtype, element_type); | ||
|
||
const exprt final_size_expr = from_integer(size, integer_typet()); | ||
array_typet result(array_subtype, final_size_expr); | ||
result.set(ID_offset, from_integer(offset, integer_typet())); | ||
result.set(ID_C_little_endian, little_endian); | ||
|
||
return result; | ||
} | ||
|
||
/*******************************************************************\ | ||
Function: verilog_typecheck_exprt::convert_type | ||
Inputs: | ||
|