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+.
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_c ⇒ Object
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_ruby ⇒ Object
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 |