MCPcopy
hub / github.com/tinygo-org/tinygo / getInvokeFunction

Method getInvokeFunction

compiler/interface.go:903–922  ·  view source on GitHub ↗

getInvokeFunction returns the thunk to call the given interface method. The thunk is declared, not defined: it will be defined by the interface lowering pass.

(instr *ssa.CallCommon)

Source from the content-addressed store, hash-verified

901// thunk is declared, not defined: it will be defined by the interface lowering
902// pass.
903func (c *compilerContext) getInvokeFunction(instr *ssa.CallCommon) llvm.Value {
904 s, _ := getTypeCodeName(instr.Value.Type().Underlying())
905 fnName := s + "." + instr.Method.Name() + "$invoke"
906 llvmFn := c.mod.NamedFunction(fnName)
907 if llvmFn.IsNil() {
908 sig := instr.Method.Type().(*types.Signature)
909 var paramTuple []*types.Var
910 for i := 0; i < sig.Params().Len(); i++ {
911 paramTuple = append(paramTuple, sig.Params().At(i))
912 }
913 paramTuple = append(paramTuple, types.NewVar(token.NoPos, nil, "$typecode", types.Typ[types.UnsafePointer]))
914 llvmFnType := c.getLLVMFunctionType(types.NewSignature(sig.Recv(), types.NewTuple(paramTuple...), sig.Results(), false))
915 llvmFn = llvm.AddFunction(c.mod, fnName, llvmFnType)
916 c.addStandardDeclaredAttributes(llvmFn)
917 llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("tinygo-invoke", c.getMethodSignatureName(instr.Method)))
918 methods := c.getMethodsString(instr.Value.Type().Underlying().(*types.Interface))
919 llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("tinygo-methods", methods))
920 }
921 return llvmFn
922}
923
924// createInterfaceTypeAssert creates a call to a declared-but-not-defined
925// $typeassert function for the given interface. This function will be defined

Callers 3

createRunDefersMethod · 0.80
createFunctionCallMethod · 0.80
createGoMethod · 0.80

Calls 10

getLLVMFunctionTypeMethod · 0.95
getMethodsStringMethod · 0.95
getTypeCodeNameFunction · 0.85
IsNilMethod · 0.80
NameMethod · 0.65
LenMethod · 0.65
TypeMethod · 0.45
RecvMethod · 0.45

Tested by

no test coverage detected