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+.



2075
2076
2077
2078
2079
2080
2081
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2075

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.



2071
2072
2073
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2071

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



2071
2072
2073
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2071

def right
  @right
end

Instance Method Details

#to_cObject

Convert to C code.



2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2116

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.



2084
2085
2086
2087
2088
2089
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2084

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.



2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2092

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