Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add missing indirectbr instruction (ruby-llvm/ruby-llvm#10).

  • Loading branch information...
commit e69d2db7334512a6bd6abd5dd9710d24af4fee55 1 parent 2a7b342
@whitequark whitequark authored
Showing with 25 additions and 4 deletions.
  1. +14 −4 lib/llvm/core/builder.rb
  2. +11 −0 lib/llvm/core/value.rb
View
18 lib/llvm/core/builder.rb
@@ -79,7 +79,7 @@ def aggregate_ret(*vals)
end
# Unconditional branching (i.e. goto)
- # @param [LLVM::BasicBlock] block Where to jump
+ # @param [LLVM::BasicBlock] block Where to jump
# @return [LLVM::Instruction]
# @LLVMinst br
def br(block)
@@ -88,10 +88,20 @@ def br(block)
C.build_br(self, block))
end
+ # Indirect branching (i.e. computed goto)
+ # @param [LLVM::BasicBlock] addr Where to jump
+ # @param [Integer] num_dests Number of possible destinations to be added
+ # @return [LLVM::Instruction]
+ # @LLVMinst indirectbr
+ def ibr(addr, num_dests)
+ IndirectBr.from_ptr(
+ C.build_indirect_br(self, addr, num_dests))
+ end
+
# Conditional branching (i.e. if)
- # @param [LLVM::Value] cond The condition
- # @param [LLVM::BasicBlock] iftrue Where to jump if condition is true
- # @param [LLVM::BasicBlock] iffalse Where to jump if condition is false
+ # @param [LLVM::Value] cond The condition
+ # @param [LLVM::BasicBlock] iftrue Where to jump if condition is true
+ # @param [LLVM::BasicBlock] iffalse Where to jump if condition is false
# @return [LLVM::Instruction]
# @LLVMinst br
def cond(cond, iftrue, iffalse)
View
11 lib/llvm/core/value.rb
@@ -789,4 +789,15 @@ def add_case(val, block)
C.add_case(self, val, block)
end
end
+
+
+ # @private
+ class IndirectBr < Instruction
+ # Adds a basic block reference as a destination for this indirect branch.
+ def add_dest(dest)
+ C.add_destination(self, dest)
+ end
+
+ alias :<< :add_dest
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.