Re: [myhdl-list] Two slightly awkward things about the MyHDL syntax
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2010-07-21 08:41:13
|
Angel Ezquerra wrote: > > On Wed, Jul 14, 2010 at 5:44 PM, Christopher Felton <cf...@uc... > <mailto:cf...@uc...>> wrote: > > > This is currently support use the function instances(). Example > return instances(). It will return all generators in the module. > Adding new generators will not require updating the return list. > > > That is awesome! I did not know that! Thank you for this tip! It > basically removes one of my may complaints about MyHDL! :-D > > I think that I have not seen this used in the examples that I've > studied, although perhaps I missed it. It is certainly not used in many > of the examples. Since this is a very convenient way to work I think > that this should be used in the examples so that it becomes the default > way to return the instances defined in a block. To implement instances(), you need a fair amount of "magic". Therefore, it has both the advantages of magic (convenience) and its disadvantages: - it may make things less generic, potentially creating problems down the road - it may make it more difficult for newbies to understand what's going on A very common use case is to just return a single tuple of instances as the last line. In such cases, using instances() is probably just fine. However, sooner or later you'll need more complex cases, and MyHDL's mechanism makes it straigthforward to do so. For example, setting up a list of instances dynamically. Or returning a different list of instances depending on conditions, like here: http://www.myhdl.org/doku.php/cookbook:bitonic In such cases, I think it's much clearer to return the instances explicitly. Just the other day, someone was confused by instances() and I recommended him to throw it out to understand what was going on. Therefore: I consider instances() very advanced usage, only to be used when one understands very clearly how MyHDL works. Therefore, not for newbies, and not the first thing documented in the manual. Personally, I tend not to use it. I regard the return statement as an "export declaraton" or a summary of the module. Jan -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a HDL: http://www.myhdl.org VHDL development, the modern way: http://www.sigasi.com Analog design automation: http://www.mephisto-da.com World-class digital design: http://www.easics.com |