Class: LLVM::ConstantInt

Inherits:
Constant show all
Extended by:
Gem::Deprecate
Defined in:
lib/llvm/core/value.rb

Instance Attribute Summary

Attributes included from PointerIdentity

#ptr

Instance Method Summary collapse

Methods inherited from Constant

#bitcast_to, #gep, #int_to_ptr, null, null_ptr, poison, #ptr_to_int, undef

Methods inherited from User

#operands

Methods inherited from Value

#add_attribute, #allocated_type, #allocated_type?, #constant?, #dump, from_ptr, from_ptr_kind, #gep_source_element_type, #gep_source_element_type?, #global_parent, #kind, #name, #name=, #null?, #poison?, #remove_attribute, to_ptr, #to_s, type, #type, #undef?

Methods included from PointerIdentity

#==, #eql?, #hash, #to_ptr

Instance Method Details

#&(rhs) ⇒ Object Also known as: and

Integer AND. was: self.class.from_ptr(C.const_and(self, rhs))



570
571
572
573
# File 'lib/llvm/core/value.rb', line 570

def &(rhs)
  width = [type.width, rhs.type.width].max
  LLVM::Type.integer(width).from_i(to_i & rhs.to_i)
end

#*(rhs) ⇒ Object Also known as: mul

Multiplication. : (ConstantInt) -> ConstantInt



511
512
513
514
515
516
# File 'lib/llvm/core/value.rb', line 511

def *(rhs)
  width = [type.width, rhs.type.width].max
  product = to_i * rhs.to_i
  modulo = product % (2**width)
  LLVM::Type.integer(width).from_i(modulo, false)
end

#+(rhs) ⇒ Object Also known as: add

Addition. : (ConstantInt) -> ConstantInt



471
472
473
# File 'lib/llvm/core/value.rb', line 471

def +(rhs)
  self.class.from_ptr(C.const_add(self, rhs))
end

#-(rhs) ⇒ Object Also known as: sub

Subtraction. : (ConstantInt) -> ConstantInt



491
492
493
# File 'lib/llvm/core/value.rb', line 491

def -(rhs)
  self.class.from_ptr(C.const_sub(self, rhs))
end

#-@Object Also known as: neg

Negation. : -> ConstantInt



447
448
449
# File 'lib/llvm/core/value.rb', line 447

def -@
  self.class.from_ptr(C.const_neg(self))
end

#/(rhs) ⇒ Object

Signed division. : (ConstantInt) -> ConstantInt



541
542
543
544
# File 'lib/llvm/core/value.rb', line 541

def /(rhs)
  width = [type.width, rhs.type.width].max
  LLVM::Type.integer(width).from_i(to_si / rhs.to_si, true)
end

#<<(bits) ⇒ Object Also known as: shl

Shift left.



593
594
595
596
# File 'lib/llvm/core/value.rb', line 593

def <<(bits)
  width = [type.width, bits.type.width].max
  LLVM::Type.integer(width).from_i(to_i << bits.to_i)
end

#^(rhs) ⇒ Object Also known as: xor

Integer XOR.



586
587
588
# File 'lib/llvm/core/value.rb', line 586

def ^(rhs)
  self.class.from_ptr(C.const_xor(self, rhs))
end

#ashr(bits) ⇒ Object

Arithmatic shift right.



610
611
612
613
# File 'lib/llvm/core/value.rb', line 610

def ashr(bits)
  width = [type.width, bits.type.width].max
  LLVM::Type.integer(width).from_i(to_i >> bits.to_i)
end

#icmp(_pred, _rhs) ⇒ Object

Integer comparison using the predicate specified via the first parameter. Predicate can be any of:

:eq  - equal to
:ne  - not equal to
:ugt - unsigned greater than
:uge - unsigned greater than or equal to
:ult - unsigned less than
:ule - unsigned less than or equal to
:sgt - signed greater than
:sge - signed greater than or equal to
:slt - signed less than
:sle - signed less than or equal to

Raises:



627
628
629
# File 'lib/llvm/core/value.rb', line 627

def icmp(_pred, _rhs)
  raise DeprecationError
end

#lshr(bits) ⇒ Object Also known as: shr, >>

Shift right.



601
602
603
604
# File 'lib/llvm/core/value.rb', line 601

def lshr(bits)
  width = [type.width, bits.type.width].max
  LLVM::Type.integer(width).from_i(to_ui >> bits.to_i)
end

#nsw_add(rhs) ⇒ Object

“No signed wrap” addition. : (ConstantInt) -> ConstantInt



479
480
481
# File 'lib/llvm/core/value.rb', line 479

def nsw_add(rhs)
  self.class.from_ptr(C.const_nsw_add(self, rhs))
end

#nsw_mul(rhs) ⇒ Object

“No signed wrap” multiplication. : (ConstantInt) -> ConstantInt



522
523
524
# File 'lib/llvm/core/value.rb', line 522

def nsw_mul(rhs)
  mul(rhs)
end

#nsw_negObject

“No signed wrap” negation. : -> ConstantInt



455
456
457
# File 'lib/llvm/core/value.rb', line 455

def nsw_neg
  self.class.from_ptr(C.const_nsw_neg(self))
end

#nsw_sub(rhs) ⇒ Object

“No signed wrap” subtraction. : (ConstantInt) -> ConstantInt



499
500
501
# File 'lib/llvm/core/value.rb', line 499

def nsw_sub(rhs)
  self.class.from_ptr(C.const_nsw_sub(self, rhs))
end

#nuw_add(rhs) ⇒ Object

“No unsigned wrap” addition. : (ConstantInt) -> ConstantInt



485
486
487
# File 'lib/llvm/core/value.rb', line 485

def nuw_add(rhs)
  self.class.from_ptr(C.const_nuw_add(self, rhs))
end

#nuw_mul(rhs) ⇒ Object

“No unsigned wrap” multiplication. : (ConstantInt) -> ConstantInt



528
529
530
# File 'lib/llvm/core/value.rb', line 528

def nuw_mul(rhs)
  mul(rhs)
end

#nuw_negObject

Deprecated.

“No unsigned wrap” negation. : -> ConstantInt



462
463
464
465
466
# File 'lib/llvm/core/value.rb', line 462

def nuw_neg
  # :nocov:
  self.class.from_ptr(C.const_nuw_neg(self))
  # :nocov:
end

#nuw_sub(rhs) ⇒ Object

“No unsigned wrap” subtraction. : (ConstantInt) -> ConstantInt



505
506
507
# File 'lib/llvm/core/value.rb', line 505

def nuw_sub(rhs)
  self.class.from_ptr(C.const_nuw_sub(self, rhs))
end

#rem(rhs) ⇒ Object

Signed remainder. : (ConstantInt) -> ConstantInt



555
556
557
558
# File 'lib/llvm/core/value.rb', line 555

def rem(rhs)
  width = [type.width, rhs.type.width].max
  LLVM::Type.integer(width).from_i(to_si % rhs.to_si, true)
end

#sext(type) ⇒ Object Also known as: ext

constant sext was: self.class.from_ptr(C.const_s_ext(self, type))



647
648
649
# File 'lib/llvm/core/value.rb', line 647

def sext(type)
  type.from_i(to_si)
end

#to_f(type) ⇒ Object

LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); was: self.class.from_ptr(C.const_si_to_fp(self, type))



660
661
662
# File 'lib/llvm/core/value.rb', line 660

def to_f(type)
  type.from_f(to_i.to_f)
end

#to_i(signed = true) ⇒ Object

const_int_get_sext_value const_int_get_zext_value only return long long, 64-bits beyond 64-bits parse the string value into a ruby integer TODO: overflow behavior is not the same on these arms, signed is ignored above 64-bits



675
676
677
678
679
680
681
# File 'lib/llvm/core/value.rb', line 675

def to_i(signed = true)
  if type.width <= 64
    to_i_i64(signed)
  else
    to_s.split.last.to_i
  end
end

#to_siObject



635
636
637
# File 'lib/llvm/core/value.rb', line 635

def to_si
  to_i(true)
end

#to_uiObject



631
632
633
# File 'lib/llvm/core/value.rb', line 631

def to_ui
  to_i(false)
end

#trunc(type) ⇒ Object

constant trunc was: self.class.from_ptr(C.const_trunc(self, type))



654
655
656
# File 'lib/llvm/core/value.rb', line 654

def trunc(type)
  type.from_i(to_i)
end

#udiv(rhs) ⇒ Object

Unsigned division. : (ConstantInt) -> ConstantInt



534
535
536
537
# File 'lib/llvm/core/value.rb', line 534

def udiv(rhs)
  width = [type.width, rhs.type.width].max
  LLVM::Type.integer(width).from_i(to_ui / rhs.to_ui, false)
end

#urem(rhs) ⇒ Object

Unsigned remainder. : (ConstantInt) -> ConstantInt



548
549
550
551
# File 'lib/llvm/core/value.rb', line 548

def urem(rhs)
  width = [type.width, rhs.type.width].max
  LLVM::Type.integer(width).from_i(to_ui % rhs.to_ui, false)
end

#zext(type) ⇒ Object

constant zext was: self.class.from_ptr(C.const_z_ext(self, type))



641
642
643
# File 'lib/llvm/core/value.rb', line 641

def zext(type)
  type.from_i(to_ui)
end

#|(rhs) ⇒ Object Also known as: or

Integer OR.



578
579
580
581
# File 'lib/llvm/core/value.rb', line 578

def |(rhs)
  width = [type.width, rhs.type.width].max
  LLVM::Type.integer(width).from_i(to_i | rhs.to_i)
end

#~Object Also known as: not

Boolean negation. : -> ConstantInt



562
563
564
# File 'lib/llvm/core/value.rb', line 562

def ~
  self.class.from_ptr(C.const_not(self))
end