Class: RubyHDL::High::RefRange
- Inherits:
-
Ref
- Object
- Expression
- Ref
- RubyHDL::High::RefRange
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of an range reference.
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Attributes inherited from Expression
Instance Method Summary collapse
-
#final_base ⇒ Object
Get the final base object of the binary if it is an [] operator.
-
#initialize(type, base, rng) ⇒ RefRange
constructor
Create a new index reference with +type+ data type +base+ base reference and +rng+ range.
-
#range ⇒ Object
Get the access range.
-
#to_c ⇒ Object
Convert to C code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Methods inherited from 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.
1997 1998 1999 2000 2001 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1997 def initialize(type,base,rng) super(type) @base = base.to_ref @rng = (rng.first.to_expr)..(rng.last.to_expr) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
1993 1994 1995 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1993 def base @base end |
Instance Method Details
#final_base ⇒ Object
Get the final base object of the binary if it is an [] operator.
2009 2010 2011 2012 2013 2014 2015 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2009 def final_base if @base.is_a?(Ref) then return @base.final_base else return @base end end |
#range ⇒ Object
Get the access range.
2004 2005 2006 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2004 def range return @rng.first..@rng.last end |
#to_c ⇒ Object
Convert to C code.
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2050 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_ruby ⇒ Object
Convert to Ruby code.
2045 2046 2047 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2045 def to_ruby return "#{@base.to_ruby}[#{@rng.first.to_ruby}..#{@rng.last.to_ruby}]" end |