Class: Range

Inherits:
Object
  • Object
show all
Includes:
SEnumerable
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/std/sequencer.rb

Overview

Extends the range class to support to_low

Instance Method Summary collapse

Instance Method Details

#heach(&ruby_block) ⇒ Object

Iterates over the range as hardware.

Returns an enumerator if no ruby block is given.



5233
5234
5235
5236
5237
5238
5239
5240
5241
# File 'lib/HDLRuby/hruby_high.rb', line 5233

def heach(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:heach) unless ruby_block
    # Order the bounds to be able to iterate.
    first,last = self.first, self.last
    first,last = first > last ? [last,first] : [first,last]
    # Iterate.
    (first..last).each(&ruby_block)
end

#seach(&ruby_block) ⇒ Object

HW iteration on each element.



1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
# File 'lib/HDLRuby/std/sequencer.rb', line 1988

def seach(&ruby_block)
    # Create the iteration type.
    # if self.first < 0 || self.last < 0 then
    #     fw = self.first.is_a?(Numeric) ? self.first.abs.width :
    #          self.first.width
    #     lw = self.last.is_a?(Numeric) ? self.last.abs.width :
    #          self.last.width
    #     typ = signed[[fw,lw].max]
    # else
    #     typ = bit[[self.first.width,self.last.width].max]
    # end
    # Create the iteration type: selection of the larger HDLRuby type
    # between first and last. If one of first and last is a Numeric,
    # priority to the non Numeric one.
    if (self.last.is_a?(Numeric)) then
        typ = self.first.to_expr.type
    elsif (self.first.is_a?(Numeric)) then
        typ = self.last.to_expr.type
    else
        typ = self.first.type.width > self.last.type.width ? 
            self.first.type : self.last.type
    end
    # Create the hardware iterator.
    this = self
    size = this.size ? this.size : this.last - this.first + 1
    # size = size.to_expr
    # if size.respond_to?(:cast) then
    #     size = size.cast(typ)
    # else
    #     size = size.as(typ)
    # end
    size = size.to_expr.as(typ)
    # hw_enum = SEnumeratorBase.new(signed[32],size) do |idx|
    hw_enum = SEnumeratorBase.new(typ,size) do |idx|
        # idx.as(typ) + this.first
        idx.as(typ) + this.first.to_expr.as(typ)
    end
    # Is there a ruby block?
    if(ruby_block) then
        # Yes, apply it.
        return hw_enum.seach(&ruby_block)
    else
        # No, return the resulting enumerator.
        return hw_enum
    end
end

#to_lowObject

Convert the first and last to HDLRuby::Low



5222
5223
5224
5225
5226
5227
5228
# File 'lib/HDLRuby/hruby_high.rb', line 5222

def to_low
    first = self.first
    first = first.respond_to?(:to_low) ? first.to_low : first
    last = self.last
    last = last.respond_to?(:to_low) ? last.to_low : last
    return (first..last)
end