Skip to content

Commit 28f70fc

Browse files
committed
runtime: add exportedFuncPtr
This function isn't used yet, but will be used for the "cores" scheduler for RISC-V.
1 parent a6ade83 commit 28f70fc

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

compiler/compiler.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,15 +1856,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c
18561856
//
18571857
// This is also where compiler intrinsics are implemented.
18581858
func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) {
1859-
var params []llvm.Value
1860-
for _, param := range instr.Args {
1861-
params = append(params, b.getValue(param, getPos(instr)))
1862-
}
1863-
1864-
// Try to call the function directly for trivially static calls.
1865-
var callee, context llvm.Value
1866-
var calleeType llvm.Type
1867-
exported := false
1859+
// See if this is an intrinsic function that is handled specially.
18681860
if fn := instr.StaticCallee(); fn != nil {
18691861
// Direct function call, either to a named or anonymous (directly
18701862
// applied) function call. If it is anonymous, it may be a closure.
@@ -1900,13 +1892,27 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
19001892
return llvm.ConstInt(b.ctx.Int8Type(), panicStrategy, false), nil
19011893
case name == "runtime/interrupt.New":
19021894
return b.createInterruptGlobal(instr)
1895+
case name == "runtime.exportedFuncPtr":
1896+
_, ptr := b.getFunction(instr.Args[0].(*ssa.Function))
1897+
return b.CreatePtrToInt(ptr, b.uintptrType, ""), nil
19031898
case name == "internal/abi.FuncPCABI0":
19041899
retval := b.createDarwinFuncPCABI0Call(instr)
19051900
if !retval.IsNil() {
19061901
return retval, nil
19071902
}
19081903
}
1904+
}
19091905

1906+
var params []llvm.Value
1907+
for _, param := range instr.Args {
1908+
params = append(params, b.getValue(param, getPos(instr)))
1909+
}
1910+
1911+
// Try to call the function directly for trivially static calls.
1912+
var callee, context llvm.Value
1913+
var calleeType llvm.Type
1914+
exported := false
1915+
if fn := instr.StaticCallee(); fn != nil {
19101916
calleeType, callee = b.getFunction(fn)
19111917
info := b.getFunctionInfo(fn)
19121918
if callee.IsNil() {

src/runtime/runtime.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func strlen(ptr unsafe.Pointer) uintptr
6363
//export malloc
6464
func malloc(size uintptr) unsafe.Pointer
6565

66+
// Return the address of an exported function.
67+
// This is mainly useful to pass a function pointer without extra context
68+
// parameter to C, for example.
69+
func exportedFuncPtr(fn func()) uintptr
70+
6671
// Compare two same-size buffers for equality.
6772
func memequal(x, y unsafe.Pointer, n uintptr) bool {
6873
for i := uintptr(0); i < n; i++ {

0 commit comments

Comments
 (0)