github.com/axw/llgo@v0.0.0-20160805011314-95b5fe4dca20/irgen/call.go (about) 1 //===- call.go - IR generation for calls ----------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements IR generation for calls. 11 // 12 //===----------------------------------------------------------------------===// 13 14 package irgen 15 16 import ( 17 "llvm.org/llgo/third_party/gotools/go/types" 18 "llvm.org/llvm/bindings/go/llvm" 19 ) 20 21 // createCall emits the code for a function call, 22 // taking into account receivers, and panic/defer. 23 func (fr *frame) createCall(fn *govalue, chain llvm.Value, argValues []*govalue) []*govalue { 24 fntyp := fn.Type().Underlying().(*types.Signature) 25 typinfo := fr.types.getSignatureInfo(fntyp) 26 27 args := make([]llvm.Value, len(argValues)) 28 for i, arg := range argValues { 29 args[i] = arg.value 30 } 31 var results []llvm.Value 32 if fr.unwindBlock.IsNil() { 33 results = typinfo.call(fr.types.ctx, fr.allocaBuilder, fr.builder, fn.value, chain, args) 34 } else { 35 contbb := llvm.AddBasicBlock(fr.function, "") 36 results = typinfo.invoke(fr.types.ctx, fr.allocaBuilder, fr.builder, fn.value, chain, args, contbb, fr.unwindBlock) 37 } 38 39 resultValues := make([]*govalue, len(results)) 40 for i, res := range results { 41 resultValues[i] = newValue(res, fntyp.Results().At(i).Type()) 42 } 43 return resultValues 44 }