blob: 9f29ac61dc17977e0f2c5b61082503266d93ba49 [file] [log] [blame]
Peter Collingbournead9841e2014-11-27 00:06:42 +00001//===- 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
14package irgen
15
16import (
Peter Collingbourne56109b72015-01-13 20:45:08 +000017 "llvm.org/llgo/third_party/gotools/go/types"
Peter Collingbournead9841e2014-11-27 00:06:42 +000018 "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.
Peter Collingbournecac32592015-04-05 23:31:49 +000023func (fr *frame) createCall(fn *govalue, chain llvm.Value, argValues []*govalue) []*govalue {
Peter Collingbournead9841e2014-11-27 00:06:42 +000024 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() {
Peter Collingbournecac32592015-04-05 23:31:49 +000033 results = typinfo.call(fr.types.ctx, fr.allocaBuilder, fr.builder, fn.value, chain, args)
Peter Collingbournead9841e2014-11-27 00:06:42 +000034 } else {
35 contbb := llvm.AddBasicBlock(fr.function, "")
Peter Collingbournecac32592015-04-05 23:31:49 +000036 results = typinfo.invoke(fr.types.ctx, fr.allocaBuilder, fr.builder, fn.value, chain, args, contbb, fr.unwindBlock)
Peter Collingbournead9841e2014-11-27 00:06:42 +000037 }
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}