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.



2105
2106
2107
2108
2109
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2105

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.



2101
2102
2103
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2101

def base
  @base
end

Instance Method Details

#final_baseObject

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



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

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

#rangeObject

Get the access range.



2112
2113
2114
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2112

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

#to_cObject

Convert to C code.



2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2158

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.



2153
2154
2155
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2153

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