I just finished making all the connections between the new RHDL 'frontend' and the RHDL backend simulation code and the following design with both behavioral elements (the AndGate and Invert), structural elements (NandGate) and hierarchy is working:
require 'RHDL'
include RHDL
AndGate = model {
inputs a, b
outputs out
define_behavior {
out <= a & b
}
}
Invert = model {
inputs a
outputs not_a
define_behavior{
not_a <= a.inv
}
}
NandGate = model {
inputs aa, bb
outputs a_nand_b
init {
a_and_b = Signal(Bit())
andg = AndGate.new(aa,bb,a_and_b)
Invert.new(a_and_b, a_nand_b)
}
}
require 'Simulator'
include Simulator
a = Signal(Bit.new('1'))
b = Signal(Bit.new('1'))
out = Signal(Bit.new )
nand = NandGate.new(a,b, out)
step { puts "a=#{a}, b=#{b}, out=#{out}"}
a <= '0'
step { puts "a=#{a}, b=#{b}, out=#{out}"}
That's a lot nicer than it was in the old version of RHDL. The thing that really bugs me now looking at this code is that you've got to both require and include RHDL:
require 'RHDL'
include RHDL
...and the same for Simulator. That's probably another thing that the user shouldn't need to wonder about. I think it's time to do some redefinition of the kernel::include method... I should gemify RHDL and do a release of the new version in the next few days.