mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-25 06:49:04 +00:00
runtime: add exportedFuncPtr
This function isn't used yet, but will be used for the "cores" scheduler for RISC-V.
This commit is contained in:
committed by
Ron Evans
parent
525c41bac9
commit
64a30424da
+15
-9
@@ -1856,15 +1856,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c
|
|||||||
//
|
//
|
||||||
// This is also where compiler intrinsics are implemented.
|
// This is also where compiler intrinsics are implemented.
|
||||||
func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) {
|
func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) {
|
||||||
var params []llvm.Value
|
// See if this is an intrinsic function that is handled specially.
|
||||||
for _, param := range instr.Args {
|
|
||||||
params = append(params, b.getValue(param, getPos(instr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to call the function directly for trivially static calls.
|
|
||||||
var callee, context llvm.Value
|
|
||||||
var calleeType llvm.Type
|
|
||||||
exported := false
|
|
||||||
if fn := instr.StaticCallee(); fn != nil {
|
if fn := instr.StaticCallee(); fn != nil {
|
||||||
// Direct function call, either to a named or anonymous (directly
|
// Direct function call, either to a named or anonymous (directly
|
||||||
// applied) function call. If it is anonymous, it may be a closure.
|
// 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)
|
|||||||
return llvm.ConstInt(b.ctx.Int8Type(), panicStrategy, false), nil
|
return llvm.ConstInt(b.ctx.Int8Type(), panicStrategy, false), nil
|
||||||
case name == "runtime/interrupt.New":
|
case name == "runtime/interrupt.New":
|
||||||
return b.createInterruptGlobal(instr)
|
return b.createInterruptGlobal(instr)
|
||||||
|
case name == "runtime.exportedFuncPtr":
|
||||||
|
_, ptr := b.getFunction(instr.Args[0].(*ssa.Function))
|
||||||
|
return b.CreatePtrToInt(ptr, b.uintptrType, ""), nil
|
||||||
case name == "internal/abi.FuncPCABI0":
|
case name == "internal/abi.FuncPCABI0":
|
||||||
retval := b.createDarwinFuncPCABI0Call(instr)
|
retval := b.createDarwinFuncPCABI0Call(instr)
|
||||||
if !retval.IsNil() {
|
if !retval.IsNil() {
|
||||||
return retval, nil
|
return retval, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []llvm.Value
|
||||||
|
for _, param := range instr.Args {
|
||||||
|
params = append(params, b.getValue(param, getPos(instr)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to call the function directly for trivially static calls.
|
||||||
|
var callee, context llvm.Value
|
||||||
|
var calleeType llvm.Type
|
||||||
|
exported := false
|
||||||
|
if fn := instr.StaticCallee(); fn != nil {
|
||||||
calleeType, callee = b.getFunction(fn)
|
calleeType, callee = b.getFunction(fn)
|
||||||
info := b.getFunctionInfo(fn)
|
info := b.getFunctionInfo(fn)
|
||||||
if callee.IsNil() {
|
if callee.IsNil() {
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ func strlen(ptr unsafe.Pointer) uintptr
|
|||||||
//export malloc
|
//export malloc
|
||||||
func malloc(size uintptr) unsafe.Pointer
|
func malloc(size uintptr) unsafe.Pointer
|
||||||
|
|
||||||
|
// Return the address of an exported function.
|
||||||
|
// This is mainly useful to pass a function pointer without extra context
|
||||||
|
// parameter to C, for example.
|
||||||
|
func exportedFuncPtr(fn func()) uintptr
|
||||||
|
|
||||||
// Compare two same-size buffers for equality.
|
// Compare two same-size buffers for equality.
|
||||||
func memequal(x, y unsafe.Pointer, n uintptr) bool {
|
func memequal(x, y unsafe.Pointer, n uintptr) bool {
|
||||||
for i := uintptr(0); i < n; i++ {
|
for i := uintptr(0); i < n; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user