PyHDI / veriloggen

Veriloggen: A Mixed-Paradigm Hardware Construction Framework
Apache License 2.0
306 stars 58 forks source link

Better Documentation/Tutorials #19

Open xd009642 opened 5 years ago

xd009642 commented 5 years ago

So the examples are useful for somethings but say if I want to have nested if statements or make something that generates this verilog:

reg signed [width:0] x [0:width-1];
always @(posedge clock) begin
    x[0] <= 0
end

I've found myself doing a lot of trial and error, reading the source and scouring the existing examples trying to find something that would use these constructs (it's not always obvious from the example names).

Also, both these issues are still unresolved for me. I'm trying to write a coregen script to generate a cordic IP block.

xd009642 commented 5 years ago

I've figured out the issues I currently had. One thing I've failed to figure out how to do is an expression like so:

input wire  signed [(12-1):0] i_xval;
...
wire    signed [(15-1):0]   e_xval;
assign  e_xval = { {i_xval[(12-1)]}, i_xval, {(3-1){1'b0}} };
LucasBraganca commented 5 years ago

Hi, this would be something like this:

from veriloggen import *

def make_module():
  m = Module('xval')
  i_xval = m.Input('i_xval',12,signed=True)
  e_xval = m.Wire('e_xval',15,signed=True)
  e_xval.assign(Cat(i_xval[11],i_xval,Repeat(Int(0,1,2),2)))

  return m

print(make_module().to_verilog())
xd009642 commented 5 years ago

That fixed my issue thanks! Is there any appetite for improving the veriloggen docs, and maybe having HTML docs hosted somewhere? Whenever I run into an issue I normally spend time going through tests and examples looking for anything that solves it and then going through the actual code which is less than ideal.

shtaxxx commented 5 years ago

HTML docs hosted somewhere

I should prepare such documents ...

xd009642 commented 5 years ago

I've not published any python projects myself that have required docs but pydoc should be able to generate docs from doc comments on classes and methods. It's just a case of doc comments for existing code

Nic30 commented 5 years ago

@shtaxxx I am using Sphinx code generator together with readthedocs.io https://github.com/Nic30/hwtLib/blob/master/docs/conf.py

https://hwtlib.readthedocs.io/en/latest/?badge=latest

I was relatively good and it usually works however you may have to fix some code style of doc in your code. Sphinx can also generate PDF/epub/... and readthedocs.io also supports any files.