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.



2221
2222
2223
2224
2225
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2221

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.



2217
2218
2219
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2217

def base
  @base
end

Instance Method Details

#final_baseObject

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



2233
2234
2235
2236
2237
2238
2239
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2233

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

#rangeObject

Get the access range.



2228
2229
2230
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2228

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

#to_cObject

Convert to C code.



2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2275

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.



2294
2295
2296
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2294

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

#to_rubyObject

Convert to Ruby code.



2269
2270
2271
2272
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2269

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