-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SystemVerilog: delay expansion of string literals
This delays the expansion of string literals to preserve these in property descriptions.
- Loading branch information
Showing
4 changed files
with
76 additions
and
12 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
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <algorithm> | ||
#include <cstdlib> | ||
#include <iomanip> | ||
#include <sstream> | ||
|
||
/*******************************************************************\ | ||
|
@@ -350,7 +351,10 @@ expr2verilogt::convert_function_call(const function_call_exprt &src) | |
else | ||
dest+=", "; | ||
|
||
dest += convert_rec(op).s; | ||
if(op.id() == ID_type) | ||
dest += convert(op.type()); | ||
else | ||
dest += convert_rec(op).s; | ||
} | ||
|
||
dest+=")"; | ||
|
@@ -1208,6 +1212,54 @@ expr2verilogt::resultt expr2verilogt::convert_constant( | |
ieee_float.from_expr(tmp); | ||
return {precedence, ieee_float.to_ansi_c_string()}; | ||
} | ||
else if(type.id() == ID_string) | ||
{ | ||
dest = '"'; | ||
|
||
for(auto &ch : id2string(src.get_value())) | ||
{ | ||
// Follows Table Table 5-1 in 1800-2017. | ||
switch(ch) | ||
{ | ||
case '\n': | ||
dest += "\\n"; | ||
break; | ||
case '\t': | ||
dest += "\\t"; | ||
break; | ||
case '\\': | ||
dest += "\\\\"; | ||
break; | ||
case '"': | ||
dest += "\\\""; | ||
break; | ||
case '\v': | ||
dest += "\\v"; | ||
break; | ||
case '\f': | ||
dest += "\\f"; | ||
break; | ||
case '\a': | ||
dest += "\\a"; | ||
break; | ||
default: | ||
if( | ||
(unsigned(ch) >= ' ' && unsigned(ch) <= 126) || | ||
(unsigned(ch) >= 128 && unsigned(ch) <= 254)) | ||
{ | ||
dest += ch; | ||
} | ||
else | ||
{ | ||
std::ostringstream oss; | ||
oss << "\\x" << std::setw(2) << std::setfill('0') << std::hex << ch; | ||
dest += oss.str(); | ||
} | ||
} | ||
} | ||
|
||
dest += '"'; | ||
} | ||
else | ||
return convert_norep(src, precedence); | ||
|
||
|
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/ieee_float.h> | ||
|
||
#include "aval_bval_encoding.h" | ||
#include "convert_literals.h" | ||
#include "verilog_bits.h" | ||
#include "verilog_expr.h" | ||
|
||
|
@@ -182,12 +183,14 @@ exprt verilog_lowering(exprt expr) | |
|
||
if(expr.id() == ID_constant) | ||
{ | ||
auto &constant_expr = to_constant_expr(expr); | ||
|
||
if( | ||
expr.type().id() == ID_verilog_unsignedbv || | ||
expr.type().id() == ID_verilog_signedbv) | ||
{ | ||
// encode into aval/bval | ||
return lower_to_aval_bval(to_constant_expr(expr)); | ||
return lower_to_aval_bval(constant_expr); | ||
} | ||
else if( | ||
expr.type().id() == ID_verilog_real || | ||
|
@@ -198,6 +201,12 @@ exprt verilog_lowering(exprt expr) | |
// no need to change value | ||
expr.type() = lower_verilog_real_types(expr.type()); | ||
} | ||
else if(expr.type().id() == ID_string) | ||
{ | ||
auto result = convert_string_literal(constant_expr.get_value()); | ||
result.add_source_location() = expr.source_location(); | ||
expr = std::move(result); | ||
} | ||
|
||
return expr; | ||
} | ||
|
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