Invoke invokes the function f with the specified arguments. If an exception is thrown while calling f, then cleanup will be called before rethrowing the exception.
(f *Function, cleanup func(), args ...*Value)
| 78 | // If an exception is thrown while calling f, then cleanup will be called before |
| 79 | // rethrowing the exception. |
| 80 | func (b *Builder) Invoke(f *Function, cleanup func(), args ...*Value) *Value { |
| 81 | fn, sig, name := f.llvm, f.Type.Signature, f.Name |
| 82 | |
| 83 | l := b.callArgs(sig, name, args) |
| 84 | |
| 85 | then := b.m.ctx.AddBasicBlock(b.function.llvm, fmt.Sprintf("%v_nothrow", name)) |
| 86 | throw := b.m.ctx.AddBasicBlock(b.function.llvm, fmt.Sprintf("%v_catch", name)) |
| 87 | |
| 88 | if sig.Result == b.m.Types.Void { |
| 89 | name = "" |
| 90 | } |
| 91 | |
| 92 | res := b.val(sig.Result, b.llvm.CreateInvoke(fn, l, then, throw, name)) |
| 93 | |
| 94 | b.function.llvm.SetPersonality(b.m.exceptions.personalityFn.llvm) |
| 95 | |
| 96 | b.block(throw, llvm.BasicBlock{}, func() { |
| 97 | lp := b.llvm.CreateLandingPad(b.m.exceptions.exceptionTy.llvmTy(), 0, "cleanup") |
| 98 | lp.SetCleanup(true) |
| 99 | cleanup() |
| 100 | b.llvm.CreateResume(lp) |
| 101 | }) |
| 102 | |
| 103 | b.setInsertPointAtEnd(then) |
| 104 | |
| 105 | return res |
| 106 | } |
| 107 | |
| 108 | // Throw throws an exception with the given value. |
| 109 | func (b *Builder) Throw(v *Value) { |
nothing calls this directly
no test coverage detected