Skip to content

Instantly share code, notes, and snippets.

@hgomersall
Created May 30, 2016 19:34
Show Gist options
  • Save hgomersall/bd7530aa56831c28a73f688d9bb23279 to your computer and use it in GitHub Desktop.
Save hgomersall/bd7530aa56831c28a73f688d9bb23279 to your computer and use it in GitHub Desktop.
from myhdl import *
import myhdl
class Interface(object):
def __init__(self):
self.bar = Signal(intbv(0)[4:])
@block
def block1(out_interface, foo):
@always_comb
def assign_output():
out_interface.bar.next = foo.bar
block1.vhdl_code = '''
$foo_bar
${foo.bar}
${foo_bar}
${out_interface.bar}
'''
out_interface.bar.driven = True
foo.bar.read = True
return assign_output
@block
def block2(data_out, foo_bar):
@always_comb
def assign_output():
data_out.next = foo_bar
return assign_output
@block
def top(data_out, foo_bar, foo, out_interface):
return block2(data_out, foo_bar), block1(out_interface, foo)
@block
def top2(out_interface, foo):
return block1(out_interface, foo)
data_out = Signal(intbv(0)[8:])
foo_bar = Signal(intbv(10)[8:])
foo = Interface()
interface_out = Interface()
foo_inst = top(data_out, foo_bar, foo, interface_out)
#foo_inst = top2(interface_out, foo)
foo_inst.convert(hdl='VHDL')
@hgomersall
Copy link
Author

An example of problems with naming of interface objects in vhdl_code blocks.

This myhdl branch will build the above, converting the foo.bar symbol to the correct one, avoiding the name conflict and referencing the correct object.

It is necessary to remove foo.bar from vhdl_code to get it to work with master, in which case the names in the resultant vhdl_file will be wrong.

(the vhdl is nonsense, its just an example of the name conflict problem)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment