Class: RubyHDL::High::Transmit
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a transmit statement.
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(left, right) ⇒ Transmit
constructor
Create a new transmit statement with left value +left+ and right value +right+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_expr ⇒ Object
Convert to expression: transforms the transmit to a comparison.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Methods inherited from Statement
#each_statement, #each_statement_deep
Constructor Details
#initialize(left, right) ⇒ Transmit
Create a new transmit statement with left value +left+ and right value +right+.
2215 2216 2217 2218 2219 2220 2221 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2215 def initialize(left,right) @left = left.to_expr @right = right.to_expr # Add the transmit to the top SW block. # (It will be removed after if it was actually a comparison). RubyHDL::High.top_sblock << self end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
2211 2212 2213 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2211 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
2211 2212 2213 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2211 def right @right end |
Instance Method Details
#to_c ⇒ Object
Convert to C code.
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2256 def to_c if (@left.is_a?(RefIndex) or @left.is_a?(RefRange)) then if @left.base.type.base.is_a?(TypeVector) then return "#{@left.to_c} = #{@right.to_c}" else # Get the access range. rng = @left.range # 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 = left.final_base.to_c # Generate the ruby code. return "#{base} &= #{cmask.to_c}; " + "#{base} |= (((#{@right.to_c} & #{smask.to_c}) << (#{rng.last.to_c})))" end else return "#{@left.to_c} = #{@right.to_c};" end end |
#to_expr ⇒ Object
Convert to expression: transforms the transmit to a comparison.
2224 2225 2226 2227 2228 2229 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2224 def to_expr # Remove the transmit from the top SW block. RubyHDL::High.top_sblock.delete(self) # And convert it to a comparison. return Binary.new(@left.type,@left,@right) end |
#to_ruby ⇒ Object
Convert to Ruby code.
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2232 def to_ruby if (@left.is_a?(RefIndex) or @left.is_a?(RefRange)) then if @left.base.type.base.is_a?(TypeVector) then # Assign inside array. base = @left.final_base.to_ruby return "#{base} ||= []; #{@left.to_ruby} = #{@right.to_ruby}" else # Get the access range. rng = @left.range # 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 = left.final_base.to_ruby # Generate the ruby code. return "#{base} &= #{cmask.to_ruby}; " + "#{base} |= (((#{@right.to_ruby} & #{smask.to_ruby}) << (#{rng.last.to_ruby})))" end else return "#{@left.to_ruby} = #{@right.to_ruby}" end end |