Class: RLTK::CG::ConstantInteger Abstract
- Inherits:
-
ConstantNumber
- Object
- Value
- User
- Constant
- ConstantNumber
- RLTK::CG::ConstantInteger
- Includes:
- AbstractClass
- Defined in:
- lib/rltk/cg/value.rb
Overview
All integer constants inherit from this class.
Instance Attribute Summary collapse
-
#signed ⇒ Boolean
readonly
If the integer is signed or not.
Attributes included from BindingClass
Instance Method Summary collapse
-
#%(rhs) ⇒ ConstantInteger
Modulo this value by another value.
-
#*(rhs) ⇒ ConstantInteger
Multiply this value with another value.
-
#+(rhs) ⇒ ConstantInteger
Add this value with another value.
-
#-(rhs) ⇒ ConstantInteger
Subtract a value from this value.
-
#-@ ⇒ ConstantInteger
Negate this value.
-
#/(rhs) ⇒ ConstantInteger
Divide this value by another value.
-
#and(rhs) ⇒ ConstantInteger
Bitwise AND this value with another.
-
#ashr(bits) ⇒ ConstantInteger
(also: #>>)
Arithmetic right shift.
-
#cast(type, signed = true) ⇒ ConstantNumber
Cast this constant integer to another number type.
-
#cmp(pred, rhs) ⇒ Int1
Compare this value to another value.
-
#extact_sdiv(rhs) ⇒ ConstantInteger
Divide this value by another value.
-
#initialize(overloaded0 = nil, overloaded1 = nil, size = nil) ⇒ ConstantInteger
constructor
The constructor for ConstantInteger’s various sub-classes.
-
#lshr(bits) ⇒ ConstantInteger
Logical right shift.
-
#not ⇒ ConstantInteger
Bitwise NOT this value.
-
#nsw_add(rhs) ⇒ ConstantInteger
Add this value with another value.
-
#nsw_mul(rhs) ⇒ ConstantInteger
Multiply this value with another value.
-
#nsw_neg ⇒ ConstantInteger
Negate this value.
-
#nsw_sub(rhs) ⇒ ConstantInteger
Subtract a value from this value.
-
#nuw_add(rhs) ⇒ ConstantInteger
Add this value with another value.
-
#nuw_mul(rhs) ⇒ ConstantInteger
Multiply this value with another value.
-
#nuw_neg ⇒ ConstantInteger
Negate this value.
-
#nuw_sub(rhs) ⇒ ConstantInteger
Subtract a value from this value.
-
#or(rhs) ⇒ ConstantInteger
Bitwise OR this value with another.
-
#shift(dir, bits, mode = :arithmetic) ⇒ ConstantInteger
A wrapper method around the #shift_left and #shift_right methods.
-
#shift_left(bits) ⇒ ConstantInteger
(also: #shl, #<<)
Shift the value left a specific number of bits.
-
#shift_right(bits, mode = :arithmetic) ⇒ ConstantInteger
Shift the value right a specific number of bits.
-
#to_f(type) ⇒ ConstantReal
Convert this integer to a float.
-
#udiv(rhs) ⇒ ConstantInteger
Divide this value by another value.
-
#urem(rhs) ⇒ ConstantInteger
Modulo this value by another value.
-
#value(extension = :sign) ⇒ Integer
Get the value of this constant as a signed or unsigned long long.
-
#xor(rhs) ⇒ ConstantInteger
Bitwise XOR this value with another.
Methods included from AbstractClass
Methods inherited from ConstantNumber
Methods inherited from Constant
#bitcast_to, #get_element_ptr, #get_element_ptr_in_bounds
Methods inherited from User
Methods inherited from Value
#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast
Methods included from BindingClass
Constructor Details
#initialize(overloaded0 = nil, overloaded1 = nil, size = nil) ⇒ ConstantInteger
The constructor for ConstantInteger’s various sub-classes. This constructor is a bit complicated due to having two overloaded parameters, but once you see the valid combinations it is a bit simpler.
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/rltk/cg/value.rb', line 566 def initialize(overloaded0 = nil, overloaded1 = nil, size = nil) @ptr = case overloaded0 when FFI::Pointer overloaded0 when Integer @signed = overloaded1 or true Bindings.const_int(self.type, overloaded0, @signed.to_i) when String base = overloaded1 or 10 if size Bindings.const_int_of_string_and_size(self.type, overloaded0, size, base) else Bindings.const_int_of_string(self.type, overloaded0, base) end else @signed = true Bindings.const_all_ones(self.type) end end |
Instance Attribute Details
#signed ⇒ Boolean (readonly)
Returns If the integer is signed or not.
547 548 549 |
# File 'lib/rltk/cg/value.rb', line 547 def signed @signed end |
Instance Method Details
#%(rhs) ⇒ ConstantInteger
Modulo this value by another value. Uses signed modulo.
725 726 727 |
# File 'lib/rltk/cg/value.rb', line 725 def %(rhs) self.class.new(Bindings.const_s_rem(@ptr, rhs)) end |
#*(rhs) ⇒ ConstantInteger
Multiply this value with another value.
665 666 667 |
# File 'lib/rltk/cg/value.rb', line 665 def *(rhs) self.class.new(Bindings.const_mul(@ptr, rhs)) end |
#+(rhs) ⇒ ConstantInteger
Add this value with another value.
603 604 605 |
# File 'lib/rltk/cg/value.rb', line 603 def +(rhs) self.class.new(Bindings.const_add(@ptr, rhs)) end |
#-(rhs) ⇒ ConstantInteger
Subtract a value from this value.
634 635 636 |
# File 'lib/rltk/cg/value.rb', line 634 def -(rhs) self.class.new(Bindings.const_sub(@ptr, rhs)) end |
#-@ ⇒ ConstantInteger
Negate this value.
743 744 745 |
# File 'lib/rltk/cg/value.rb', line 743 def -@ self.class.new(Bindings.const_neg(@ptr)) end |
#/(rhs) ⇒ ConstantInteger
Divide this value by another value. Uses signed division.
696 697 698 |
# File 'lib/rltk/cg/value.rb', line 696 def /(rhs) self.class.new(Bindings.const_s_div(@ptr, rhs)) end |
#and(rhs) ⇒ ConstantInteger
Bitwise AND this value with another.
828 829 830 |
# File 'lib/rltk/cg/value.rb', line 828 def and(rhs) self.class.new(Bindings.const_and(@ptr, rhs)) end |
#ashr(bits) ⇒ ConstantInteger Also known as: >>
Arithmetic right shift.
809 810 811 |
# File 'lib/rltk/cg/value.rb', line 809 def ashr(bits) self.class.new(Bindings.const_a_shr(@ptr, bits)) end |
#cast(type, signed = true) ⇒ ConstantNumber
Cast this constant integer to another number type.
867 868 869 |
# File 'lib/rltk/cg/value.rb', line 867 def cast(type, signed = true) type.value_class.new(Bindings.const_int_cast(@ptr, check_cg_type(type, NumberType), signed.to_i)) end |
#cmp(pred, rhs) ⇒ Int1
Compare this value to another value.
879 880 881 |
# File 'lib/rltk/cg/value.rb', line 879 def cmp(pred, rhs) Int1.new(Bindings.const_i_cmp(pred, @ptr, rhs)) end |
#extact_sdiv(rhs) ⇒ ConstantInteger
Divide this value by another value. Uses exact signed division.
705 706 707 |
# File 'lib/rltk/cg/value.rb', line 705 def extact_sdiv(rhs) self.class.new(Bindings.const_extact_s_div(@ptr, rhs)) end |
#lshr(bits) ⇒ ConstantInteger
Logical right shift.
819 820 821 |
# File 'lib/rltk/cg/value.rb', line 819 def lshr(bits) self.class.new(Bindings.const_l_shr(@ptr, bits)) end |
#not ⇒ ConstantInteger
Bitwise NOT this value.
853 854 855 |
# File 'lib/rltk/cg/value.rb', line 853 def not self.class.new(Bindings.const_not(@ptr)) end |
#nsw_add(rhs) ⇒ ConstantInteger
Add this value with another value. Performs no signed wrap addition.
613 614 615 |
# File 'lib/rltk/cg/value.rb', line 613 def nsw_add(rhs) self.class.new(Bindings.const_nsw_add(@ptr, rhs)) end |
#nsw_mul(rhs) ⇒ ConstantInteger
Multiply this value with another value. Perform no signed wrap multiplication.
675 676 677 |
# File 'lib/rltk/cg/value.rb', line 675 def nsw_mul(rhs) self.class.new(Bindings.const_nsw_mul(@ptr, rhs)) end |
#nsw_neg ⇒ ConstantInteger
Negate this value. Uses no signed wrap negation.
750 751 752 |
# File 'lib/rltk/cg/value.rb', line 750 def nsw_neg self.class.new(Bindings.const_nsw_neg(@ptr)) end |
#nsw_sub(rhs) ⇒ ConstantInteger
Subtract a value from this value. Performs no signed wrap subtraction.
644 645 646 |
# File 'lib/rltk/cg/value.rb', line 644 def nsw_sub(rhs) self.class.new(Bindings.const_nsw_sub(@ptr, rhs)) end |
#nuw_add(rhs) ⇒ ConstantInteger
Add this value with another value. Performs no unsigned wrap addition.
623 624 625 |
# File 'lib/rltk/cg/value.rb', line 623 def nuw_add(rhs) self.class.new(Bindings.const_nuw_add(@ptr, rhs)) end |
#nuw_mul(rhs) ⇒ ConstantInteger
Multiply this value with another value. Perform no unsigned wrap multiplication.
685 686 687 |
# File 'lib/rltk/cg/value.rb', line 685 def nuw_mul(rhs) self.class.new(Bindings.const_nuw_mul(@ptr, rhs)) end |
#nuw_neg ⇒ ConstantInteger
Negate this value. Uses no unsigned wrap negation.
757 758 759 |
# File 'lib/rltk/cg/value.rb', line 757 def nuw_neg self.class.new(Bindings.const_nuw_neg(@ptr)) end |
#nuw_sub(rhs) ⇒ ConstantInteger
Subtract a value from this value. Performs no unsigned wrap subtraction.
654 655 656 |
# File 'lib/rltk/cg/value.rb', line 654 def nuw_sub(rhs) self.class.new(Bindings.const_nuw_sub(@ptr, rhs)) end |
#or(rhs) ⇒ ConstantInteger
Bitwise OR this value with another.
837 838 839 |
# File 'lib/rltk/cg/value.rb', line 837 def or(rhs) self.class.new(Bindings.const_or(@ptr, rhs)) end |
#shift(dir, bits, mode = :arithmetic) ⇒ ConstantInteger
A wrapper method around the #shift_left and #shift_right methods.
773 774 775 776 777 778 |
# File 'lib/rltk/cg/value.rb', line 773 def shift(dir, bits, mode = :arithmetic) case dir when :left then shift_left(bits) when :right then shift_right(bits, mode) end end |
#shift_left(bits) ⇒ ConstantInteger Also known as: shl, <<
Shift the value left a specific number of bits.
785 786 787 |
# File 'lib/rltk/cg/value.rb', line 785 def shift_left(bits) self.class.new(Bindings.const_shl(@ptr, bits)) end |
#shift_right(bits, mode = :arithmetic) ⇒ ConstantInteger
Shift the value right a specific number of bits.
797 798 799 800 801 802 |
# File 'lib/rltk/cg/value.rb', line 797 def shift_right(bits, mode = :arithmetic) case mode when :arithmetic then ashr(bits) when :logical then lshr(bits) end end |
#to_f(type) ⇒ ConstantReal
Convert this integer to a float.
888 889 890 |
# File 'lib/rltk/cg/value.rb', line 888 def to_f(type) type.value_class.new(Bindings.send(@signed ? :const_si_to_fp : :const_ui_to_fp, @ptr, check_cg_type(type, FloatingPointType))) end |
#udiv(rhs) ⇒ ConstantInteger
Divide this value by another value. Uses unsigned division.
714 715 716 |
# File 'lib/rltk/cg/value.rb', line 714 def udiv(rhs) self.class.new(Bindings.const_u_div(@ptr, rhs)) end |
#urem(rhs) ⇒ ConstantInteger
Modulo this value by another value. Uses unsigned modulo.
734 735 736 |
# File 'lib/rltk/cg/value.rb', line 734 def urem(rhs) self.class.new(Bindings.const_u_rem(@ptr, rhs)) end |
#value(extension = :sign) ⇒ Integer
Get the value of this constant as a signed or unsigned long long.
897 898 899 900 901 902 |
# File 'lib/rltk/cg/value.rb', line 897 def value(extension = :sign) case extension when :sign then Bindings.const_int_get_s_ext_value(@ptr) when :zero then Bindings.const_int_get_z_ext_value(@ptr) end end |
#xor(rhs) ⇒ ConstantInteger
Bitwise XOR this value with another.
846 847 848 |
# File 'lib/rltk/cg/value.rb', line 846 def xor(rhs) self.class.new(Bindings.const_xor(@ptr, rhs)) end |