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.
2127 2128 2129 2130 2131 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2127 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.
2123 2124 2125 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2123 def base @base end |
Instance Method Details
#final_base ⇒ Object
Get the final base object of the binary if it is an [] operator.
2139 2140 2141 2142 2143 2144 2145 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2139 def final_base if @base.is_a?(Ref) then return @base.final_base else return @base end end |
#range ⇒ Object
Get the access range.
2134 2135 2136 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2134 def range return @rng.first..@rng.last end |
#to_c ⇒ Object
Convert to C code.
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2181 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_ruby ⇒ Object
Convert to Ruby code.
2175 2176 2177 2178 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2175 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 |