Class: RubyHDL::High::Transmit

Inherits:
Object
  • Object
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

Constructor Details

#initialize(left, right) ⇒ Transmit

Create a new transmit statement with left value +left+ and right value +right+.



2128
2129
2130
2131
2132
2133
2134
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2128

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.



2124
2125
2126
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2124

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



2124
2125
2126
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2124

def right
  @right
end

Instance Method Details

#to_cObject

Convert to C code.



2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2169

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.



2137
2138
2139
2140
2141
2142
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2137

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.



2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2145

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