2014-11-27 08:06:42 +08:00
|
|
|
//===- call.go - IR generation for calls ----------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-11-27 08:06:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements IR generation for calls.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
package irgen
|
|
|
|
|
|
|
|
import (
|
2015-01-14 04:45:08 +08:00
|
|
|
"llvm.org/llgo/third_party/gotools/go/types"
|
2014-11-27 08:06:42 +08:00
|
|
|
"llvm.org/llvm/bindings/go/llvm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// createCall emits the code for a function call,
|
|
|
|
// taking into account receivers, and panic/defer.
|
2015-04-06 07:31:49 +08:00
|
|
|
func (fr *frame) createCall(fn *govalue, chain llvm.Value, argValues []*govalue) []*govalue {
|
2014-11-27 08:06:42 +08:00
|
|
|
fntyp := fn.Type().Underlying().(*types.Signature)
|
|
|
|
typinfo := fr.types.getSignatureInfo(fntyp)
|
|
|
|
|
|
|
|
args := make([]llvm.Value, len(argValues))
|
|
|
|
for i, arg := range argValues {
|
|
|
|
args[i] = arg.value
|
|
|
|
}
|
|
|
|
var results []llvm.Value
|
|
|
|
if fr.unwindBlock.IsNil() {
|
2015-04-06 07:31:49 +08:00
|
|
|
results = typinfo.call(fr.types.ctx, fr.allocaBuilder, fr.builder, fn.value, chain, args)
|
2014-11-27 08:06:42 +08:00
|
|
|
} else {
|
|
|
|
contbb := llvm.AddBasicBlock(fr.function, "")
|
2015-04-06 07:31:49 +08:00
|
|
|
results = typinfo.invoke(fr.types.ctx, fr.allocaBuilder, fr.builder, fn.value, chain, args, contbb, fr.unwindBlock)
|
2014-11-27 08:06:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resultValues := make([]*govalue, len(results))
|
|
|
|
for i, res := range results {
|
|
|
|
resultValues[i] = newValue(res, fntyp.Results().At(i).Type())
|
|
|
|
}
|
|
|
|
return resultValues
|
|
|
|
}
|