Class: HDLRuby::High::Std::SEnumeratorBase

Inherits:
SEnumerator
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer.rb

Overview

Describes a sequencer enumerator class that allows to generate HW iterations over HW or SW objects within sequencers. This is the base Enumerator that directly iterates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SEnumerator

#+, #seach, #seach_range, #seach_with_index, #seach_with_object, #with_index, #with_object

Methods included from SEnumerable

#sall?, #sany?, #schain, #schunk, #schunk_while, #scompact, #scount, #scycle, #sdrop, #sdrop_while, #seach_cons, #seach_entry, #seach_nexts, #seach_range, #seach_slice, #seach_with_index, #seach_with_object, #sfind, #sfind_index, #sfirst, #sflat_map, #sgrep, #sgrep_v, #sgroup_by, #sinclude?, #sinject, #slazy, #smap, #smax, #smax_by, #smin, #smin_by, #sminmax, #sminmax_by, #snone?, #sone?, #spartition, #sreject, #sreverse_each, #sselect, #sslice_after, #sslice_before, #sslice_when, #ssort, #ssort_by, #ssort_merge, #ssum, #stake, #stake_while, #stally, #sto_a, #sto_h, #suniq, #szip

Constructor Details

#initialize(typ, size = nil, &access) ⇒ SEnumeratorBase

Create a new sequencer for +size+ elements as +typ+ with an HW array-like accesser +access+. def initialize(typ,size,&access)



2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
# File 'lib/HDLRuby/std/sequencer.rb', line 2037

def initialize(typ,size = nil,&access)
    # Sets the size.
    @size = size
    # Sets the type.
    @type = typ
    # Sets the accesser.
    @access = access
    # Compute the index width (default: safe 32 bits).
    width = @size.respond_to?(:width) ? @size.width : 
            @size.respond_to?(:type) ? size.type.width : 32
    # puts "width=#{width}"
    # # Create the index and the iteration result.
    # Create the index (if relevant) and the iteration result.
    idx = nil
    result = nil
    # HDLRuby::High.cur_system.open do
    #     idx = [width].inner({
    #         HDLRuby.uniq_name("enum_idx") => 0 })
    #     result = typ.inner(HDLRuby.uniq_name("enum_res"))
    # end
    idx_required = @size ? true : false
    HDLRuby::High.cur_system.open do
        idx = [width].inner({
            HDLRuby.uniq_name("enum_idx") => 0 }) if idx_required
        result = typ.inner(HDLRuby.uniq_name("enum_res"))
    end
    @index = idx
    @result = result
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



2032
2033
2034
# File 'lib/HDLRuby/std/sequencer.rb', line 2032

def index
  @index
end

#resultObject (readonly)

Returns the value of attribute result.



2031
2032
2033
# File 'lib/HDLRuby/std/sequencer.rb', line 2031

def result
  @result
end

#sizeObject (readonly)

Returns the value of attribute size.



2029
2030
2031
# File 'lib/HDLRuby/std/sequencer.rb', line 2029

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



2030
2031
2032
# File 'lib/HDLRuby/std/sequencer.rb', line 2030

def type
  @type
end

Instance Method Details

#access(idx) ⇒ Object

Generates the access at +idx+



2073
2074
2075
# File 'lib/HDLRuby/std/sequencer.rb', line 2073

def access(idx)
    @access.call(idx)
end

#cloneObject

Clones the enumerator.



2068
2069
2070
# File 'lib/HDLRuby/std/sequencer.rb', line 2068

def clone
    return SEnumeratorBase.new(@type,@size,&@access)
end

#snextObject

Get the next element.



2084
2085
2086
2087
2088
2089
# File 'lib/HDLRuby/std/sequencer.rb', line 2084

def snext
    @result <= @access.call(@index)
    # @index <= @index + 1
    @index <= @index + 1 if @index
    return @result
end

#snext!(val) ⇒ Object

Set the next element, also return the access result so that it can be used as bidirectional transaction.



2099
2100
2101
2102
2103
2104
2105
2106
# File 'lib/HDLRuby/std/sequencer.rb', line 2099

def snext!(val)
    # @access.call(@index,val)
    # @index <= @index + 1
    # return val
    res = @access.call(@index,val)
    @index <= @index + 1 if @index
    return res
end

#snext?Boolean

Tell if there is a next element.

Returns:

  • (Boolean)


2092
2093
2094
2095
# File 'lib/HDLRuby/std/sequencer.rb', line 2092

def snext?
    # return @index < @size
    return @index ? @index < @size : true
end

#speekObject

View the next element without advancing the iteration.



2078
2079
2080
2081
# File 'lib/HDLRuby/std/sequencer.rb', line 2078

def speek
    @result <= @access.call(@index)
    return @result
end

#srewindObject

Restart the iteration.



2109
2110
2111
2112
# File 'lib/HDLRuby/std/sequencer.rb', line 2109

def srewind
    # @index <= 0
    @index <= 0 if @index
end