Class: RubyHDL::High::Transmit

Inherits:
Statement show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of a transmit statement.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#leftObject (readonly)

Returns the value of attribute left.



2196
2197
2198
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2196

def left
  @left
end

#rightObject (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_cObject

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_exprObject

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_rubyObject

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