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



1935
1936
1937
1938
1939
1940
1941
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1935

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.



1931
1932
1933
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1931

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



1931
1932
1933
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1931

def right
  @right
end

Instance Method Details

#to_exprObject

Convert to expression: transforms the transmit to a comparison.



1944
1945
1946
1947
1948
1949
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1944

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.



1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1952

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
      # # Compute the final access range.
      # rng = @left.final_range
      # 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