-
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.
This adds 1800 2017 22.13 `__FILE__ and `__LINE__ to the Verilog preprocessor.
- Loading branch information
Showing
5 changed files
with
83 additions
and
45 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
file1.v | ||
--preprocess | ||
^ "file1\.v", 4\);$ | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^PREPROCESSING FAILED$ |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module main; | ||
|
||
initial $display("Internal error: null handle at %s, line %d.", | ||
`__FILE__, `__LINE__); | ||
|
||
endmodule |
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 |
---|---|---|
|
@@ -27,6 +27,59 @@ Author: Daniel Kroening, [email protected] | |
#include <iomanip> | ||
#include <sstream> | ||
|
||
std::string verilog_string_literal(const std::string &src) | ||
{ | ||
std::string dest; | ||
|
||
dest = '"'; | ||
|
||
for(auto &ch : src) | ||
{ | ||
// 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 += '"'; | ||
|
||
return dest; | ||
} | ||
|
||
/*******************************************************************\ | ||
Function: expr2verilogt::convert_if | ||
|
@@ -1214,51 +1267,7 @@ expr2verilogt::resultt expr2verilogt::convert_constant( | |
} | ||
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 += '"'; | ||
dest = verilog_string_literal(id2string(src.get_value())); | ||
} | ||
else if(type.id() == ID_verilog_chandle || type.id() == ID_verilog_event) | ||
{ | ||
|
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 |
---|---|---|
|
@@ -10,3 +10,5 @@ Author: Daniel Kroening, [email protected] | |
|
||
std::string expr2verilog(const exprt &, const namespacet &); | ||
std::string type2verilog(const typet &, const namespacet &); | ||
|
||
std::string verilog_string_literal(const std::string &); |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/config.h> | ||
#include <util/unicode.h> | ||
|
||
#include "expr2verilog.h" | ||
#include "verilog_preprocessor_error.h" | ||
|
||
#include <filesystem> | ||
|
@@ -672,6 +673,18 @@ void verilog_preprocessort::directive() | |
break; | ||
} | ||
} | ||
else if(text == "__FILE__") | ||
{ | ||
// 1800 2017 22.13 | ||
// String literal | ||
out << verilog_string_literal(context().filename_as_string()); | ||
} | ||
else if(text == "__LINE__") | ||
{ | ||
// 1800 2017 22.13 | ||
// decimal number | ||
out << tokenizer().line_no(); | ||
} | ||
else | ||
{ | ||
// check defines | ||
|