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+.
2200 2201 2202 2203 2204 2205 2206 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2200 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.
2196 2197 2198 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2196 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
2196 2197 2198 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2196 def right @right end |
Instance Method Details
#to_c ⇒ Object
Convert to C code.
2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2241 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.
2209 2210 2211 2212 2213 2214 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2209 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.
2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2217 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 |