Thread: [myhdl-list] New way of specifying user defined code, not working inside class
Brought to you by:
jandecaluwe
From: Wesley N. <we...@sk...> - 2012-01-19 11:51:52
|
Hi All, I have had to change the way my uesr-defined code was written to the new method, using <func>.verilog_code but I am having a problem using it inside a class. Here is the code: from myhdl import * class sw_reg: def __init__(self): #self.sw_reg_r_wrapper.__dict__['verilog_code'] = "verilog" #self.sw_reg_r_wrapper.verilog_code = "verilog" temp2 = 0 def sw_reg_wrapper(self, wb_clk_i): #======================== # TODO:Simulation Logic #======================== @always(wb_clk_i.posedge) def logic(): temp = 1 return logic sw_reg_r_wrapper.verilog_code = "verilog code blah blah" But when I call the toVerilog method, as below, it doesnt use the user-defined code (Note: this works when there is no class) #======================================= # For testing of conversion to verilog #======================================= def convert(): x = sw_reg_r() wb_clk_i = Signal(bool(0)) toVerilog(x.sw_reg_r_wrapper, wb_clk_i=wb_clk_i) if __name__ == "__main__": convert() I have tried adding the verilog_code explicitly to the dictionary associated with the function (See the commented lines in the __init__ function) but this doesnt work either. What am I doing wrong? Thanks for you time. Wesley |
From: Christopher F. <chr...@gm...> - 2012-01-19 12:24:31
|
On 1/19/12 5:51 AM, Wesley New wrote: > Hi All, > > I have had to change the way my uesr-defined code was written to the new > method, using <func>.verilog_code but I am having a problem using it > inside a class. > > Here is the code: > > from myhdl import * > > class sw_reg: > > def __init__(self): > #self.sw_reg_r_wrapper.__dict__['verilog_code'] = "verilog" > #self.sw_reg_r_wrapper.verilog_code = "verilog" > temp2 = 0 > > > def sw_reg_wrapper(self, wb_clk_i): > > #======================== > # TODO:Simulation Logic > #======================== > @always(wb_clk_i.posedge) > def logic(): > temp = 1 > > return logic > > sw_reg_r_wrapper.verilog_code = "verilog code blah blah" > > > But when I call the toVerilog method, as below, it doesnt use the > user-defined code (Note: this works when there is no class) > > #======================================= > # For testing of conversion to verilog > #======================================= > def convert(): > > x = sw_reg_r() > wb_clk_i = Signal(bool(0)) > > toVerilog(x.sw_reg_r_wrapper, wb_clk_i=wb_clk_i) > > > if __name__ == "__main__": > convert() > > I have tried adding the verilog_code explicitly to the dictionary > associated with the function (See the commented lines in the __init__ > function) but this doesnt work either. What am I doing wrong? > > Thanks for you time. > > Wesley > > > This is currently a known limitation, you cannot convert a class method directly because the convert does not recognize the first parameter, "self", and uses "self" as a port. The current work around, is to have a normal function that is converted and have the class method invoke the function (essentially pass all arguments except self). This is one of the items I was hoping to address in the MEP I proposed but finding adequate time to work on it is, lets say, difficult. Hope that helps, Chris |
From: Sébastien B. <seb...@mi...> - 2012-01-19 13:40:43
|
On 01/19/2012 01:23 PM, Christopher Felton wrote: > This is currently a known limitation, you cannot convert a class method > directly because the convert does not recognize the first parameter, > "self", and uses "self" as a port. If your design is synchronous, and if using classes is more important to you than integrated Python test benches (which are perfectly possible to do under Migen, but which no one has developed yet) you can use Migen FHDL, which supports signals in classes (and more perversions) just fine. https://github.com/milkymist/migen Sébastien |
From: Wesley N. <we...@sk...> - 2012-01-24 11:54:45
|
Thank you for the replies. To update on this issue I have confirmed that the method Chris suggested works. ie creating a function outside the class and passing that to the convert method. I am not comfortable with doing it this way as it is a bit of a hack, but until we can patch MyHDL it will have to do. Regards Wesley On Thu, Jan 19, 2012 at 3:35 PM, Sébastien Bourdeauducq < seb...@mi...> wrote: > On 01/19/2012 01:23 PM, Christopher Felton wrote: > > This is currently a known limitation, you cannot convert a class method > > directly because the convert does not recognize the first parameter, > > "self", and uses "self" as a port. > > If your design is synchronous, and if using classes is more important to > you than integrated Python test benches (which are perfectly possible to > do under Migen, but which no one has developed yet) you can use Migen > FHDL, which supports signals in classes (and more perversions) just fine. > > https://github.com/milkymist/migen > > Sébastien > > > ------------------------------------------------------------------------------ > Keep Your Developer Skills Current with LearnDevNow! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-d2d > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |