# Verilog conversion to write results to a file?

**URL:** <https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372>\
**Category:** Support\
**Created:** [April 2, 2019, 8:18am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372 "2019-04-02T08:18:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 2, 2019, 8:18am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/1 "2019-04-02T08:18:56Z")

</div>

Dear All,  
Is there an easy way to insert a macro inside the myhdl code to generate a verilog conversion to generate data logs to a file.  
Like:  
Myhdl Verilog  
f = open(“log.txt”,“w+”) $fopen(“log.txt”,“w”);  
f.write(…) $fwrite(…);  
f.close() $fclose(‘log.txt’);  
Thanks  
Dan

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [April 2, 2019, 9:16am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/2 "2019-04-02T09:16:22Z")

</div>

Hi,  
What kind of information would you like to log ?  
Nicolas

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 2, 2019, 10:10pm UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/3 "2019-04-02T22:10:41Z")

</div>

Hi Nicolas,

Like a read/write data sequence in case of not expected returned data.

Rgds,

Dan

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [April 3, 2019, 6:45am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/4 "2019-04-03T06:45:00Z")

</div>

In your first message, you talk about conversion but in your last message its seems you talk about simulation.  
Can you clarify ?

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 3, 2019, 7:07am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/5 "2019-04-03T07:07:51Z")

</div>

OK let say I don’t need to generate synthesisable verilog for the part that is doing the logging. A want to create a test-bench verilog which logs results. I this more clear ?

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 3, 2019, 9:46am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/7 "2019-04-03T09:46:54Z")

</div>

May be but this is a long shot. May be using the ‘verilog\_code’ feature can be a quick fix, but so far I didn’t succeed to figure it out. Did someone face the same need ?

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [April 3, 2019, 12:38pm UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/9 "2019-04-03T12:38:16Z")

</div>

> [@Dani](#):
>
> A want to create a test-bench verilog which logs results. I this more clear ?

If I understand you correctly : From MyHDL, you want to generate a verilog testbench. This verilog test bench, which is simulated with verilog tools, generates log files containing simulation data.  
Is this correct ?

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 3, 2019, 10:59pm UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/10 "2019-04-03T22:59:07Z")

</div>

Dear DrPi,

Yes correct. So if somebody has an example on how to use ‘verilog\_code’ to insert the instruction I need I would take if. If not I will add some marker and do it in post processing.

I am surprised that nobody need this kind of feature.

Rgds, Dan

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [April 4, 2019, 7:13am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/11 "2019-04-04T07:13:45Z")

</div>

The _standard_ way is to simulate with MyHDL (you can easily generate log files). When you’re done with your design, you use co-simulation to check the converted design matches the MyHDL design.  
But maybe I’m wrong on your needs.

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 4, 2019, 9:09am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/12 "2019-04-04T09:09:35Z")

</div>

What means standard way ? I guess lots of people here are doing FPGA. We have are doing something with mixed signals in this case you need a way to simulate low level registers access and … .

This is just to answer your curiosity ( take care it killed the cat 🙂 ).

Seems nobody has a simple proposal even with ‘verilog\_code’ :(.

Rgds, Dan

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [April 4, 2019, 10:06am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/13 "2019-04-04T10:06:38Z")

</div>

This is not just a matter of curiosity.  
There are two options when someone has a request :

- Stupidly answer the question
- Understand the need to give a smart answer.

The purpose of my questions is to understand the need.

My stupid answer is : No, it’s not possible.

My smart answer is :  
MyHDL is very good at simulation since you can push the limits very far.  
You need mixed signal simulation. Why not try with MyHDL ?

You could call [ngspice library](http://ngspice.sourceforge.net/shared.html) API from MyHDL for the analogue part. [PySpice](https://pypi.org/project/PySpice/) does this perfectly.  
This is just an idea. I have not tested it.

Regards,  
Nicolas

---

<div class="post-metadata">

**Author:** ![Dani](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Dani](https://discourse.myhdl.org/u/Dani)\
**Post date:** [April 4, 2019, 11:57am UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/14 "2019-04-04T11:57:12Z")

</div>

Dear Nicolas,

The mixed signal flow is running ( what you suggest works we tried it several years ago 🙂 ).

This is not what we do and we do use myhdl which is very handy to generate the test-bench verilog, it does a fine job in doing all the heavy lifting for us. The only touch we would need is to have the test-bench verilog write to a file.

Any way will do it in post-processing ( open, write, close file ).

Thanks for your support.

Rgds, Dan

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [April 4, 2019, 12:24pm UTC](https://discourse.myhdl.org/t/verilog-conversion-to-write-results-to-a-file/372/15 "2019-04-04T12:24:47Z")

</div>

> [@Dani](#):
>
> The mixed signal flow is running ( what you suggest works we tried it several years ago 🙂 ).

That’s good news 🙂  
Don’t hesitate to share your workflow with other MyHDL users 😉

Regards,  
Nicolas
