Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add missing arithmetic operations on constants (ruby-llvm/ruby-llvm#10).

  • Loading branch information...
commit 969a04427ef133424d174294334d7f5cbb583a40 1 parent e69d2db
whitequark whitequark authored
Showing with 81 additions and 24 deletions.
  1. +81 −24 lib/llvm/core/value.rb
105 lib/llvm/core/value.rb
View
@@ -290,29 +290,69 @@ def -@
self.class.from_ptr(C.const_neg(self))
end
- # Boolean negation.
- def ~@
- self.class.from_ptr(C.const_not(self))
+ alias neg -@
+
+ # "No signed wrap" negation.
+ def nsw_neg
+ self.class.from_ptr(C.const_nsw_neg(self))
end
- alias not ~
+ # "No unsigned wrap" negation.
+ def nuw_neg
+ self.class.from_ptr(C.const_nuw_neg(self))
+ end
# Addition.
def +(rhs)
self.class.from_ptr(C.const_add(self, rhs))
end
- # "No signed wrap" addition. See
- # http://llvm.org/docs/LangRef.html#i_add for discusison.
+ alias add +
+
+ # "No signed wrap" addition.
def nsw_add(rhs)
self.class.from_ptr(C.const_nsw_add(self, rhs))
end
+ # "No unsigned wrap" addition.
+ def nuw_add(rhs)
+ self.class.from_ptr(C.const_nuw_add(self, rhs))
+ end
+
+ # Subtraction.
+ def -(rhs)
+ self.class.from_ptr(C.const_sub(self, rhs))
+ end
+
+ alias sub -
+
+ # "No signed wrap" subtraction.
+ def nsw_sub(rhs)
+ self.class.from_ptr(C.const_nsw_sub(self, rhs))
+ end
+
+ # "No unsigned wrap" subtraction.
+ def nuw_sub(rhs)
+ self.class.from_ptr(C.const_nuw_sub(self, rhs))
+ end
+
# Multiplication.
def *(rhs)
self.class.from_ptr(C.const_mul(self, rhs))
end
+ alias mul *
+
+ # "No signed wrap" multiplication.
+ def nsw_mul(rhs)
+ self.class.from_ptr(C.const_nsw_mul(self, rhs))
+ end
+
+ # "No unsigned wrap" multiplication.
+ def nuw_mul(rhs)
+ self.class.from_ptr(C.const_nuw_mul(self, rhs))
+ end
+
# Unsigned division.
def udiv(rhs)
self.class.from_ptr(C.const_u_div(self, rhs))
@@ -333,51 +373,68 @@ def rem(rhs)
self.class.from_ptr(C.const_s_rem(self, rhs))
end
+ # Boolean negation.
+ def ~@
+ self.class.from_ptr(C.const_not(self))
+ end
+
+ alias not ~
+
# Integer AND.
- def and(rhs)
+ def &(rhs)
self.class.from_ptr(C.const_and(self, rhs))
end
+ alias and &
+
# Integer OR.
- def or(rhs)
+ def |(rhs)
self.class.from_ptr(C.const_or(self, rhs))
end
+ alias or |
+
# Integer XOR.
- def xor(rhs)
+ def ^(rhs)
self.class.from_ptr(C.const_xor(self, rhs))
end
- # 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
- def icmp(pred, rhs)
- self.class.from_ptr(C.const_i_cmp(pred, self, rhs))
- end
+ alias xor ^
# Shift left.
def <<(bits)
self.class.from_ptr(C.const_shl(self, bits))
end
+ alias shl <<
+
# Shift right.
def >>(bits)
self.class.from_ptr(C.const_l_shr(self, bits))
end
+ alias shr >>
+
# Arithmatic shift right.
def ashr(bits)
self.class.from_ptr(C.const_a_shr(self, bits))
end
+
+ # 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
+ def icmp(pred, rhs)
+ self.class.from_ptr(C.const_i_cmp(pred, self, rhs))
+ end
end
def LLVM.const_missing(const)
Please sign in to comment.
Something went wrong with that request. Please try again.