Class: RubyHDL::High::Binary

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

Overview

Describes the software implementation of an binary operation.

Instance Attribute Summary

Attributes inherited from Expression

#type

Instance Method Summary collapse

Methods inherited from Expression

#<=, #[], #mux, #sdownto, #seach, #stimes, #supto, #to_expr, #to_value

Constructor Details

#initialize(type, operator, left, right) ⇒ Binary

Create a new binary operation with +type+ data type, operator +operator+ and operands +left+ and +right+.



1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1885

def initialize(type,operator,left,right)
  super(type)
  @operator = operator.to_sym
  @left = left.to_expr
  @right = right.to_expr
  # Compute the mask for fixing the bit width.
  @mask = (2 ** @type.width)-1
  # Compute xor mask for handling the sign.
  # Make it as a string so that no addition computation is required
  # if no sign is required.
  @sign_fix = ""
  if type.signed? then
    @sign_fix = " ^ #{2**(@type.width-1)}"
  end
end

Instance Method Details

#to_cObject

Convert to C code.



1909
1910
1911
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1909

def to_c
  return C_OPERATOR[@operator] % [ @left.to_c, @right.to_c ]
end

#to_rubyObject

Convert to Ruby code.



1902
1903
1904
1905
1906
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1902

def to_ruby
  # return RUBY_OPERATOR[@operator] % [ @left.to_ruby, @right.to_ruby ]
  return RUBY_OPERATOR[@operator] % 
    { l: @left.to_ruby, r: @right.to_ruby, m: @mask, s: @sign_fix }
end