Class: RubyHDL::High::Binary
- Inherits:
-
Expression
- Object
- Expression
- RubyHDL::High::Binary
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes the software implementation of an binary operation.
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(type, operator, left, right) ⇒ Binary
constructor
Create a new binary operation with +type+ data type, operator +operator+ and operands +left+ and +right+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
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+.
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1953 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_c ⇒ Object
Convert to C code.
1978 1979 1980 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1978 def to_c return C_OPERATOR[@operator] % [ @left.to_c, @right.to_c ] end |
#to_ruby ⇒ Object
Convert to Ruby code.
1971 1972 1973 1974 1975 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1971 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 |