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)



2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
# File 'lib/HDLRuby/std/sequencer.rb', line 2022

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.



2017
2018
2019
# File 'lib/HDLRuby/std/sequencer.rb', line 2017

def index
  @index
end

#resultObject (readonly)

Returns the value of attribute result.



2016
2017
2018
# File 'lib/HDLRuby/std/sequencer.rb', line 2016

def result
  @result
end

#sizeObject (readonly)

Returns the value of attribute size.



2014
2015
2016
# File 'lib/HDLRuby/std/sequencer.rb', line 2014

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



2015
2016
2017
# File 'lib/HDLRuby/std/sequencer.rb', line 2015

def type
  @type
end

Instance Method Details

#access(idx) ⇒ Object

Generates the access at +idx+



2058
2059
2060
# File 'lib/HDLRuby/std/sequencer.rb', line 2058

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

#cloneObject

Clones the enumerator.



2053
2054
2055
# File 'lib/HDLRuby/std/sequencer.rb', line 2053

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

#snextObject

Get the next element.



2069
2070
2071
2072
2073
2074
# File 'lib/HDLRuby/std/sequencer.rb', line 2069

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.



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

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)


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

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

#speekObject

View the next element without advancing the iteration.



2063
2064
2065
2066
# File 'lib/HDLRuby/std/sequencer.rb', line 2063

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

#srewindObject

Restart the iteration.



2094
2095
2096
2097
# File 'lib/HDLRuby/std/sequencer.rb', line 2094

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