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_python(l = "") ⇒ Object
Convert to Python 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+.
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2026 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.
2051 2052 2053 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2051 def to_c return C_OPERATOR[@operator] % [ @left.to_c, @right.to_c ] end |
#to_python(l = "") ⇒ Object
Convert to Python code.
2056 2057 2058 2059 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2056 def to_python(l = "") return PYTHON_OPERATOR[@operator] % { l: @left.to_python, r: @right.to_python, m: @mask, s: @sign_fix } end |
#to_ruby ⇒ Object
Convert to Ruby code.
2044 2045 2046 2047 2048 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2044 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 |