class RLTK::CG::ConstantInteger

All integer constants inherit from this class.

@abstract

Attributes

signed[R]

@return [Boolean] If the integer is signed or not.

Public Class Methods

new(overloaded0 = nil, overloaded1 = nil, size = nil) click to toggle source

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.

@example Constant (signed) integer from Ruby Integer:

Int32.new(128)

@example Constant (signed) base 8 integer from Ruby String:

Int32.new('72', 8)

@example Constant integer of all 1s:

Int32.new

@param [FFI::Pointer, Integer, String, nil] overloaded0 Pointer to a ConstantInteger, value, or string representing value. @param [Boolean, Integer] overloaded1 Signed or unsigned (when overloaded0 is Integer) or base used to

decode string value.

@param [Integer] size Optional length of string to use.

# File lib/rltk/cg/value.rb, line 574
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

Public Instance Methods

%(rhs) click to toggle source

Modulo this value by another value. Uses signed modulo.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 733
def %(rhs)
        self.class.new(Bindings.const_s_rem(@ptr, rhs))
end
*(rhs) click to toggle source

Multiply this value with another value.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 673
def *(rhs)
        self.class.new(Bindings.const_mul(@ptr, rhs))
end
+(rhs) click to toggle source

Add this value with another value.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 611
def +(rhs)
        self.class.new(Bindings.const_add(@ptr, rhs))
end
-(rhs) click to toggle source

Subtract a value from this value.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 642
def -(rhs)
        self.class.new(Bindings.const_sub(@ptr, rhs))
end
-@() click to toggle source

Negate this value.

@return [ConstantInteger] Instance of the same class

# File lib/rltk/cg/value.rb, line 751
def -@
        self.class.new(Bindings.const_neg(@ptr))
end
/(rhs) click to toggle source

Divide this value by another value. Uses signed division.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 704
def /(rhs)
        self.class.new(Bindings.const_s_div(@ptr, rhs))
end
<<(bits)
Alias for: shift_left
>>(bits)
Alias for: ashr
and(rhs) click to toggle source

Bitwise AND this value with another.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 836
def and(rhs)
        self.class.new(Bindings.const_and(@ptr, rhs))
end
ashr(bits) click to toggle source

Arithmetic right shift.

@param [Integer] bits Number of bits to shift.

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 817
def ashr(bits)
        self.class.new(Bindings.const_a_shr(@ptr, bits))
end
Also aliased as: >>
cast(type, signed = true) click to toggle source

Cast this constant integer to another number type.

@param [NumberType] type Desired type to cast to. @param [Boolean] signed Is the value signed or not.

@return [ConstantNumber] This value as as the given type.

# File lib/rltk/cg/value.rb, line 875
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) click to toggle source

Compare this value to another value.

@see Bindings.enum_int_predicate

@param [Symbol] pred An integer predicate. @param [ConstantInteger] rhs Value to compare to.

@return [Int1] Value used to represent a Boolean value.

# File lib/rltk/cg/value.rb, line 887
def cmp(pred, rhs)
        Int1.new(Bindings.const_i_cmp(pred, @ptr, rhs))
end
extact_sdiv(rhs) click to toggle source

Divide this value by another value. Uses exact signed division.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 713
def extact_sdiv(rhs)
        self.class.new(Bindings.const_extact_s_div(@ptr, rhs))
end
lshr(bits) click to toggle source

Logical right shift.

@param [Integer] bits Number of bits to shift.

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 827
def lshr(bits)
        self.class.new(Bindings.const_l_shr(@ptr, bits))
end
not() click to toggle source

Bitwise NOT this value.

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 861
def not
        self.class.new(Bindings.const_not(@ptr))
end
nsw_add(rhs) click to toggle source

Add this value with another value. Performs no signed wrap addition.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 621
def nsw_add(rhs)
        self.class.new(Bindings.const_nsw_add(@ptr, rhs))
end
nsw_mul(rhs) click to toggle source

Multiply this value with another value. Perform no signed wrap multiplication.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 683
def nsw_mul(rhs)
        self.class.new(Bindings.const_nsw_mul(@ptr, rhs))
end
nsw_neg() click to toggle source

Negate this value. Uses no signed wrap negation.

@return [ConstantInteger] Instance of the same class

# File lib/rltk/cg/value.rb, line 758
def nsw_neg
        self.class.new(Bindings.const_nsw_neg(@ptr))
end
nsw_sub(rhs) click to toggle source

Subtract a value from this value. Performs no signed wrap subtraction.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 652
def nsw_sub(rhs)
        self.class.new(Bindings.const_nsw_sub(@ptr, rhs))
end
nuw_add(rhs) click to toggle source

Add this value with another value. Performs no unsigned wrap addition.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 631
def nuw_add(rhs)
        self.class.new(Bindings.const_nuw_add(@ptr, rhs))
end
nuw_mul(rhs) click to toggle source

Multiply this value with another value. Perform no unsigned wrap multiplication.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 693
def nuw_mul(rhs)
        self.class.new(Bindings.const_nuw_mul(@ptr, rhs))
end
nuw_neg() click to toggle source

Negate this value. Uses no unsigned wrap negation.

@return [ConstantInteger] Instance of the same class

# File lib/rltk/cg/value.rb, line 765
def nuw_neg
        self.class.new(Bindings.const_nuw_neg(@ptr))
end
nuw_sub(rhs) click to toggle source

Subtract a value from this value. Performs no unsigned wrap subtraction.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 662
def nuw_sub(rhs)
        self.class.new(Bindings.const_nuw_sub(@ptr, rhs))
end
or(rhs) click to toggle source

Bitwise OR this value with another.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 845
def or(rhs)
        self.class.new(Bindings.const_or(@ptr, rhs))
end
shift(dir, bits, mode = :arithmetic) click to toggle source

A wrapper method around the {#shift_left} and {#shift_right} methods.

@param [:left, :right] dir The direction to shift. @param [Integer] bits Number of bits to shift. @param [:arithmetic, :logical] mode Shift mode for right shifts.

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 781
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) click to toggle source

Shift the value left a specific number of bits.

@param [Integer] bits Number of bits to shift.

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 793
def shift_left(bits)
        self.class.new(Bindings.const_shl(@ptr, bits))
end
Also aliased as: shl, <<
shift_right(bits, mode = :arithmetic) click to toggle source

Shift the value right a specific number of bits.

@param [Integer] bits Number of bits to shift. @param [:arithmetic, :logical] mode Shift mode.

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 805
def shift_right(bits, mode = :arithmetic)
        case mode
        when :arithmetic     then ashr(bits)
        when :logical                then lshr(bits)
        end
end
shl(bits)
Alias for: shift_left
to_f(type) click to toggle source

Convert this integer to a float.

@param [RealType] type Type of float to convert to.

@return [ConstantReal] This value as a floating point value of the given type.

# File lib/rltk/cg/value.rb, line 896
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) click to toggle source

Divide this value by another value. Uses unsigned division.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 722
def udiv(rhs)
        self.class.new(Bindings.const_u_div(@ptr, rhs))
end
urem(rhs) click to toggle source

Modulo this value by another value. Uses unsigned modulo.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 742
def urem(rhs)
        self.class.new(Bindings.const_u_rem(@ptr, rhs))
end
value(extension = :sign) click to toggle source

Get the value of this constant as a signed or unsigned long long.

@param [:sign, :zero] extension Extension method.

@return [Integer]

# File lib/rltk/cg/value.rb, line 905
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) click to toggle source

Bitwise XOR this value with another.

@param [ConstantInteger] rhs

@return [ConstantInteger] Instance of the same class.

# File lib/rltk/cg/value.rb, line 854
def xor(rhs)
        self.class.new(Bindings.const_xor(@ptr, rhs))
end