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_python(l = "") ⇒ Object
Convert to Python code.
-
#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+.
2326 2327 2328 2329 2330 2331 2332 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2326 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.
2322 2323 2324 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2322 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
2322 2323 2324 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2322 def right @right end |
Instance Method Details
#to_c ⇒ Object
Convert to C code.
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2367 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.
2335 2336 2337 2338 2339 2340 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2335 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_python(l = "") ⇒ Object
Convert to Python code.
2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2389 def to_python(l = "") 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_python return "#{l}try:\n#{l} #{base}\n" + "#{l}except NameError:\n#{l} #{base} = []\n" + "#{l}#{@left.to_python} = #{@right.to_python}" 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 "#{l}#{base} &= #{cmask.to_python}\n" + "#{l}#{base} |= (((#{@right.to_python} & #{smask.to_python}) << (#{rng.last.to_python})))" end else return "#{l}#{@left.to_python} = #{@right.to_python}" end end |
#to_ruby ⇒ Object
Convert to Ruby code.
2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2343 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 |