This is definitely one I know the masses are waiting to find out how to do. 🙂
So you are simulating a verilog design with Verilator and you want to output part of your design data to a file in binary format. (Example you’re outputting an image.)
So lets say you want to do this:
fd=$fopen("somefile.dat", "wb");
$fwrite ( fd, "%c", data );
And you expect a file with binary data but instead you get a text file.
Well in Verilator you can embed c statements. So you can do this instead:
$c( "fwrite( (void*) &", data,", 1, 1, (FILE*)", fd, ");" );
There. Fixed.