Method: Range#seach

Defined in:
lib/HDLRuby/std/sequencer.rb

#seach(&ruby_block) ⇒ Object

HW iteration on each element.



2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
# File 'lib/HDLRuby/std/sequencer.rb', line 2208

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