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



2797
2798
2799
2800
2801
2802
2803
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2797

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.



2793
2794
2795
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2793

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



2793
2794
2795
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2793

def right
  @right
end

Instance Method Details

#to_cObject

Convert to C code.



2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2838

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.



2806
2807
2808
2809
2810
2811
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2806

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_python(l = "") ⇒ Object

Convert to Python code.



2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2860

def to_python(l = "")
  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_python
      return "#{l}try:\n#{l}  #{base}\n" + 
        "#{l}except NameError:\n#{l}  #{base} = []\n" +
        "#{l}#{@left.to_python} = #{@right.to_python}"
    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 "#{l}#{base} &= #{cmask.to_python}\n" +
        "#{l}#{base} |= (((#{@right.to_python} & #{smask.to_python}) << (#{rng.last.to_python})))"
    end
  else
    return "#{l}#{@left.to_python} = #{@right.to_python}"
  end
end

#to_rubyObject

Convert to Ruby code.



2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2814

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

#to_tf(l = "") ⇒ Object

Convert to TensorFlow code.



2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2886

def to_tf(l = "")
  righttf = @right.to_tf
  # Right value must be a tf object.
  righttf = "tf.constant(#{righttf})" if righttf.to_i.to_s == righttf
  # Generate the transmit.
  if (@left.is_a?(RefIndex) or @left.is_a?(RefRange)) then
    if @left.base.type.base.is_a?(TypeVector) then
      # Assign inside array.
      return "#{l}#{@left.to_tf} = #{righttf}"
    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 "#{l}#{base} = tf.bitwise.bitwise_and(#{base},#{cmask.to_tf})\n" +
        "#{l}#{base} = tf.bitwise.bitwise_or(#{base},(tf.bitwise.bitwise_left_shift(tf.bitwise.bitwise_and(#{righttf},#{smask.to_tf}),(#{rng.last.to_tf}))))"
    end
  else
    return "#{l}#{@left.to_tf} = #{righttf}"
  end
end