Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 969a04427ef133424d174294334d7f5cbb583a40 1 parent e69d2db
Peter Zotov whitequark authored

Showing 1 changed file with 81 additions and 24 deletions. Show diff stats Hide diff stats

  1. +81 24 lib/llvm/core/value.rb
105 lib/llvm/core/value.rb
@@ -290,29 +290,69 @@ def -@
290 290 self.class.from_ptr(C.const_neg(self))
291 291 end
292 292
293   - # Boolean negation.
294   - def ~@
295   - self.class.from_ptr(C.const_not(self))
  293 + alias neg -@
  294 +
  295 + # "No signed wrap" negation.
  296 + def nsw_neg
  297 + self.class.from_ptr(C.const_nsw_neg(self))
296 298 end
297 299
298   - alias not ~
  300 + # "No unsigned wrap" negation.
  301 + def nuw_neg
  302 + self.class.from_ptr(C.const_nuw_neg(self))
  303 + end
299 304
300 305 # Addition.
301 306 def +(rhs)
302 307 self.class.from_ptr(C.const_add(self, rhs))
303 308 end
304 309
305   - # "No signed wrap" addition. See
306   - # http://llvm.org/docs/LangRef.html#i_add for discusison.
  310 + alias add +
  311 +
  312 + # "No signed wrap" addition.
307 313 def nsw_add(rhs)
308 314 self.class.from_ptr(C.const_nsw_add(self, rhs))
309 315 end
310 316
  317 + # "No unsigned wrap" addition.
  318 + def nuw_add(rhs)
  319 + self.class.from_ptr(C.const_nuw_add(self, rhs))
  320 + end
  321 +
  322 + # Subtraction.
  323 + def -(rhs)
  324 + self.class.from_ptr(C.const_sub(self, rhs))
  325 + end
  326 +
  327 + alias sub -
  328 +
  329 + # "No signed wrap" subtraction.
  330 + def nsw_sub(rhs)
  331 + self.class.from_ptr(C.const_nsw_sub(self, rhs))
  332 + end
  333 +
  334 + # "No unsigned wrap" subtraction.
  335 + def nuw_sub(rhs)
  336 + self.class.from_ptr(C.const_nuw_sub(self, rhs))
  337 + end
  338 +
311 339 # Multiplication.
312 340 def *(rhs)
313 341 self.class.from_ptr(C.const_mul(self, rhs))
314 342 end
315 343
  344 + alias mul *
  345 +
  346 + # "No signed wrap" multiplication.
  347 + def nsw_mul(rhs)
  348 + self.class.from_ptr(C.const_nsw_mul(self, rhs))
  349 + end
  350 +
  351 + # "No unsigned wrap" multiplication.
  352 + def nuw_mul(rhs)
  353 + self.class.from_ptr(C.const_nuw_mul(self, rhs))
  354 + end
  355 +
316 356 # Unsigned division.
317 357 def udiv(rhs)
318 358 self.class.from_ptr(C.const_u_div(self, rhs))
@@ -333,51 +373,68 @@ def rem(rhs)
333 373 self.class.from_ptr(C.const_s_rem(self, rhs))
334 374 end
335 375
  376 + # Boolean negation.
  377 + def ~@
  378 + self.class.from_ptr(C.const_not(self))
  379 + end
  380 +
  381 + alias not ~
  382 +
336 383 # Integer AND.
337   - def and(rhs)
  384 + def &(rhs)
338 385 self.class.from_ptr(C.const_and(self, rhs))
339 386 end
340 387
  388 + alias and &
  389 +
341 390 # Integer OR.
342   - def or(rhs)
  391 + def |(rhs)
343 392 self.class.from_ptr(C.const_or(self, rhs))
344 393 end
345 394
  395 + alias or |
  396 +
346 397 # Integer XOR.
347   - def xor(rhs)
  398 + def ^(rhs)
348 399 self.class.from_ptr(C.const_xor(self, rhs))
349 400 end
350 401
351   - # Integer comparison using the predicate specified via the first parameter.
352   - # Predicate can be any of:
353   - # :eq - equal to
354   - # :ne - not equal to
355   - # :ugt - unsigned greater than
356   - # :uge - unsigned greater than or equal to
357   - # :ult - unsigned less than
358   - # :ule - unsigned less than or equal to
359   - # :sgt - signed greater than
360   - # :sge - signed greater than or equal to
361   - # :slt - signed less than
362   - # :sle - signed less than or equal to
363   - def icmp(pred, rhs)
364   - self.class.from_ptr(C.const_i_cmp(pred, self, rhs))
365   - end
  402 + alias xor ^
366 403
367 404 # Shift left.
368 405 def <<(bits)
369 406 self.class.from_ptr(C.const_shl(self, bits))
370 407 end
371 408
  409 + alias shl <<
  410 +
372 411 # Shift right.
373 412 def >>(bits)
374 413 self.class.from_ptr(C.const_l_shr(self, bits))
375 414 end
376 415
  416 + alias shr >>
  417 +
377 418 # Arithmatic shift right.
378 419 def ashr(bits)
379 420 self.class.from_ptr(C.const_a_shr(self, bits))
380 421 end
  422 +
  423 + # Integer comparison using the predicate specified via the first parameter.
  424 + # Predicate can be any of:
  425 + # :eq - equal to
  426 + # :ne - not equal to
  427 + # :ugt - unsigned greater than
  428 + # :uge - unsigned greater than or equal to
  429 + # :ult - unsigned less than
  430 + # :ule - unsigned less than or equal to
  431 + # :sgt - signed greater than
  432 + # :sge - signed greater than or equal to
  433 + # :slt - signed less than
  434 + # :sle - signed less than or equal to
  435 + def icmp(pred, rhs)
  436 + self.class.from_ptr(C.const_i_cmp(pred, self, rhs))
  437 + end
381 438 end
382 439
383 440 def LLVM.const_missing(const)

0 comments on commit 969a044

Please sign in to comment.
Something went wrong with that request. Please try again.