Class: RubyHDL::High::RefRange

Inherits:
Ref show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of an range reference.

Instance Attribute Summary collapse

Attributes inherited from Expression

#type

Instance Method Summary collapse

Methods inherited from Ref

#to_ref

Methods inherited from Expression

#<=, #[], #heach, #mux, #sdownto, #seach, #stimes, #supto, #to_expr, #to_value

Methods included from HEnumerable

#hall?, #hany?, #hchain, #hchunk, #hchunk_while, #hcompact, #hcount, #hcycle, #hdrop, #hdrop_while, #heach_cons, #heach_entry, #heach_range, #heach_slice, #heach_with_index, #heach_with_object, #hfind, #hfind_index, #hfirst, #hflat_map, #hgrep, #hgrep_v, #hgroup_by, #hinclude?, #hinject, #hlazy, #hmap, #hmax, #hmax_by, #hmin, #hmin_by, #hminmax, #hminmax_by, #hnone?, #hone?, #hpartition, #hreduce, #hreject, #hreverse_each, #hselect, #hslice_after, #hslice_before, #hslice_when, #hsort, #hsort_by, #hsum, #htake, #htake_while, #htally, #hto_a, #hto_h, #huniq, #hzip

Constructor Details

#initialize(type, base, rng) ⇒ RefRange

Create a new index reference with +type+ data type +base+ base reference and +rng+ range.



2687
2688
2689
2690
2691
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2687

def initialize(type,base,rng)
  super(type)
  @base = base.to_ref
  @rng = (rng.first.to_expr)..(rng.last.to_expr)
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



2683
2684
2685
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2683

def base
  @base
end

Instance Method Details

#final_baseObject

Get the final base object of the binary if it is an [] operator.



2699
2700
2701
2702
2703
2704
2705
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2699

def final_base
  if @base.is_a?(Ref) then
    return @base.final_base
  else
    return @base
  end
end

#rangeObject

Get the access range.



2694
2695
2696
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2694

def range
  return @rng.first..@rng.last
end

#to_cObject

Convert to C code.



2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2741

def to_c
  if @base.type.base.is_a?(TypeVector) then
    raise "Range access not supported yet for arrays."
  else
    # Compute the writing and clearing masks
    smask = (1.to_value<<(@rng.first+1-@rng.last))-1
    cmask = ~(smask << @rng.last)
    # Get the final base.
    if @base.is_a?(Ref) then
      base = @base.final_base.to_c
    else
      base = @base.to_c
    end
    # Generate the ruby code.
    return "(#{base} & #{cmask.to_c}) >> (#{@rng.last.to_c})"
  end
end

#to_python(l = "") ⇒ Object

Convert to Python code.



2760
2761
2762
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2760

def to_python(l = "")
  return "#{@base.to_python}[#{@rng.last.to_python}:#{(@rng.first+1).to_python}]"
end

#to_rubyObject

Convert to Ruby code.



2735
2736
2737
2738
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2735

def to_ruby
  # return "#{@base.to_ruby}[#{@rng.first.to_ruby}..#{@rng.last.to_ruby}]"
  return "#{@base.to_ruby}[#{@rng.last.to_ruby}..#{@rng.first.to_ruby}]"
end

#to_tf(l = "") ⇒ Object

Convert to TensorFlow code.



2765
2766
2767
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2765

def to_tf(l = "")
  return "#{@base.to_tf}[#{@rng.last.to_tf}:#{(@rng.first+1).to_tf}]"
end