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



1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1939

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
  # puts "@type=#{@type} name=#{@type.name} @type.width=#{@type.width} @mask=#{@mask}"
  # 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.



1964
1965
1966
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1964

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

#to_rubyObject

Convert to Ruby code.



1957
1958
1959
1960
1961
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1957

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