Class: RubyHDL::High::RefIndex

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

Overview

Describes a SW implementation of an index 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, idx) ⇒ RefIndex

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



2611
2612
2613
2614
2615
2616
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2611

def initialize(type,base,idx)
  super(type)
  @base = base.to_expr
  @idx = idx.to_expr
  @npow = 2 ** @idx.type.width
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



2607
2608
2609
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2607

def base
  @base
end

Instance Method Details

#final_baseObject

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



2619
2620
2621
2622
2623
2624
2625
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2619

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

#rangeObject

Get the access range.



2655
2656
2657
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2655

def range
  return @idx..@idx
end

#to_cObject

Convert to C code.



2665
2666
2667
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2665

def to_c
  return "#{@base.to_c}[(#{@idx.to_c}) % #{@npow}]"
end

#to_python(l = "") ⇒ Object

Convert to Python code.



2670
2671
2672
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2670

def to_python(l = "")
  return "#{@base.to_python}[(#{@idx.to_python}) % #{@npow}]"
end

#to_rubyObject

Convert to Ruby code.



2660
2661
2662
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2660

def to_ruby
  return "#{@base.to_ruby}[(#{@idx.to_ruby}) % #{@npow}]"
end

#to_tf(l = "") ⇒ Object

Convert to TensorFlow code.



2675
2676
2677
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2675

def to_tf(l = "")
  return "#{@base.to_tf}[#{@idx.to_tf} % #{@npow}]"
end