User guide
18-17
DirectC Interface
Converting Strings
There are no *true* strings in Verilog and a string literal, like
"some_text," is just a notation for vectors of bits, based on the same
principle as binary, octal, decimal, hexadecimal numbers. So there
is a need for a conversion between the two representations of
"strings": the C-style representation (which actually is a pointer to the
sequence of bytes terminated with null byte) and the Verilog vector
encoding a string.
DirectC comes with the vc_ConvertToString() routine that you can
use to convert a Verilog string to a C string. Its syntax is as follows:
void vc_ConvertTo String(vec32 *, int, char *)
There are scenarios in which a string is created on the Verilog side
and is passed to C code and therefore has to be converted from
Verilog representation to C representation. Consider the following
example:
extern void WriteReport(string result_code, .... /* other
stuff */);
Example of valid call:
WriteReport("Passes", ....);
Example of incorrect code:
reg [100*8:1] message;
.
.
.
message = "Failed";
.
.
.
WriteReport(message, ....);