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)
| 901 | // thunk is declared, not defined: it will be defined by the interface lowering |
| 902 | // pass. |
| 903 | func (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 |
no test coverage detected