Class: LLVM::ConstantInt

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

Instance Method Summary collapse

Methods inherited from Constant

#bitcast_to, #gep, 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))



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

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.



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

def *(rhs)
  self.class.from_ptr(C.const_mul(self, rhs))
end

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

Addition.



450
451
452
# File 'lib/llvm/core/value.rb', line 450

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

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

Subtraction.



467
468
469
# File 'lib/llvm/core/value.rb', line 467

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

#-@Object Also known as: neg

Negation.



429
430
431
# File 'lib/llvm/core/value.rb', line 429

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

#/(rhs) ⇒ Object

Signed division.



507
508
509
510
# File 'lib/llvm/core/value.rb', line 507

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.



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

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.



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

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

#ashr(bits) ⇒ Object

Arithmatic shift right.



573
574
575
576
# File 'lib/llvm/core/value.rb', line 573

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:



590
591
592
# File 'lib/llvm/core/value.rb', line 590

def icmp(_pred, _rhs)
  raise DeprecationError
end

#int_to_ptr(type = LLVM.Pointer) ⇒ Object

Conversion to pointer.



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

def int_to_ptr(type = LLVM.Pointer)
  ConstantExpr.from_ptr(C.const_int_to_ptr(self, type))
end

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

Shift right.



564
565
566
567
# File 'lib/llvm/core/value.rb', line 564

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.



457
458
459
# File 'lib/llvm/core/value.rb', line 457

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

#nsw_mul(rhs) ⇒ Object

“No signed wrap” multiplication.



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

def nsw_mul(rhs)
  self.class.from_ptr(C.const_nsw_mul(self, rhs))
end

#nsw_negObject

“No signed wrap” negation.



436
437
438
# File 'lib/llvm/core/value.rb', line 436

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

#nsw_sub(rhs) ⇒ Object

“No signed wrap” subtraction.



474
475
476
# File 'lib/llvm/core/value.rb', line 474

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

#nuw_add(rhs) ⇒ Object

“No unsigned wrap” addition.



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

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

#nuw_mul(rhs) ⇒ Object

“No unsigned wrap” multiplication.



496
497
498
# File 'lib/llvm/core/value.rb', line 496

def nuw_mul(rhs)
  self.class.from_ptr(C.const_nuw_mul(self, rhs))
end

#nuw_negObject

Deprecated.

“No unsigned wrap” negation.



442
443
444
445
446
# File 'lib/llvm/core/value.rb', line 442

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

#nuw_sub(rhs) ⇒ Object

“No unsigned wrap” subtraction.



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

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

#rem(rhs) ⇒ Object

Signed remainder.



519
520
521
522
# File 'lib/llvm/core/value.rb', line 519

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))



615
616
617
# File 'lib/llvm/core/value.rb', line 615

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))



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

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



643
644
645
646
647
648
649
# File 'lib/llvm/core/value.rb', line 643

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

#to_siObject



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

def to_si
  to_i(true)
end

#to_uiObject



599
600
601
# File 'lib/llvm/core/value.rb', line 599

def to_ui
  to_i(false)
end

#trunc(type) ⇒ Object

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



622
623
624
# File 'lib/llvm/core/value.rb', line 622

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

#udiv(rhs) ⇒ Object

Unsigned division.



501
502
503
504
# File 'lib/llvm/core/value.rb', line 501

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.



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

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))



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

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

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

Integer OR.



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_i | rhs.to_i)
end

#~@Object

Boolean negation.



525
526
527
# File 'lib/llvm/core/value.rb', line 525

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