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

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

Constructor Details

#initialize(type, base, rng) ⇒ RefRange

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



2119
2120
2121
2122
2123
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2119

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.



2115
2116
2117
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2115

def base
  @base
end

Instance Method Details

#final_baseObject

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



2131
2132
2133
2134
2135
2136
2137
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2131

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

#rangeObject

Get the access range.



2126
2127
2128
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2126

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

#to_cObject

Convert to C code.



2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2173

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.
    base = @base.final_base.to_c
    # Generate the ruby code.
    return "(#{base} & #{cmask.to_c}) >> (#{@rng.last.to_c})"
  end
end

#to_rubyObject

Convert to Ruby code.



2167
2168
2169
2170
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2167

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