aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/reflect/makefunc.go
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2015-01-16 14:58:53 -0800
committerIan Lance Taylor <ian@gcc.gnu.org>2015-01-16 22:58:53 +0000
commit38bf819a5f995ae4621496df2324d68b9e24900f (patch)
treec90d2bfba44756e26640c50ad1389375693ef832 /libgo/go/reflect/makefunc.go
parent21cb351825d45c42e9e5148715a2fd2051cf4ed1 (diff)
downloadgcc-38bf819a5f995ae4621496df2324d68b9e24900f.zip
gcc-38bf819a5f995ae4621496df2324d68b9e24900f.tar.gz
gcc-38bf819a5f995ae4621496df2324d68b9e24900f.tar.bz2
compiler, reflect, runtime: Use static chain for closures.
Change from using __go_set_closure to passing the closure value in the static chain field. Uses new backend support for setting the closure chain in a call from C via __builtin_call_with_static_chain. Uses new support in libffi for Go closures. The old architecture specific support for reflect.MakeFunc is removed, replaced by the libffi support. All work done by Richard Henderson. * go-gcc.cc (Gcc_backend::call_expression): Add chain_expr argument. (Gcc_backend::static_chain_variable): New method. From-SVN: r219776
Diffstat (limited to 'libgo/go/reflect/makefunc.go')
-rw-r--r--libgo/go/reflect/makefunc.go61
1 files changed, 11 insertions, 50 deletions
diff --git a/libgo/go/reflect/makefunc.go b/libgo/go/reflect/makefunc.go
index 276be26..71aadfb 100644
--- a/libgo/go/reflect/makefunc.go
+++ b/libgo/go/reflect/makefunc.go
@@ -7,25 +7,24 @@
package reflect
import (
- "runtime"
"unsafe"
)
// makeFuncImpl is the closure value implementing the function
// returned by MakeFunc.
type makeFuncImpl struct {
- code uintptr
- typ *funcType
- fn func([]Value) []Value
+ // These first three words are layed out like ffi_go_closure.
+ code uintptr
+ ffi_cif unsafe.Pointer
+ ffi_fun func(unsafe.Pointer, unsafe.Pointer)
+
+ typ *funcType
+ fn func([]Value) []Value
// For gccgo we use the same entry point for functions and for
// method values.
method int
rcvr Value
-
- // When using FFI, hold onto the FFI closure for the garbage
- // collector.
- ffi *ffiData
}
// MakeFunc returns a new function of the given Type
@@ -58,37 +57,17 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
t := typ.common()
ftyp := (*funcType)(unsafe.Pointer(t))
- var code uintptr
- var ffi *ffiData
- switch runtime.GOARCH {
- case "amd64", "386", "s390", "s390x":
- // Indirect Go func value (dummy) to obtain actual
- // code address. (A Go func value is a pointer to a C
- // function pointer. http://golang.org/s/go11func.)
- dummy := makeFuncStub
- code = **(**uintptr)(unsafe.Pointer(&dummy))
- default:
- code, ffi = makeFuncFFI(ftyp, fn)
- }
-
impl := &makeFuncImpl{
- code: code,
typ: ftyp,
fn: fn,
method: -1,
- ffi: ffi,
}
+ makeFuncFFI(ftyp, impl)
+
return Value{t, unsafe.Pointer(&impl), flag(Func) | flagIndir}
}
-// makeFuncStub is an assembly function that is the code half of
-// the function returned from MakeFunc. It expects a *callReflectFunc
-// as its context register, and its job is to invoke callReflect(ctxt, frame)
-// where ctxt is the context register and frame is a pointer to the first
-// word in the passed-in argument frame.
-func makeFuncStub()
-
// makeMethodValue converts v from the rcvr+method index representation
// of a method value to an actual method func value, which is
// basically the receiver value with a special bit set, into a true
@@ -123,16 +102,7 @@ func makeMethodValue(op string, v Value) Value {
rcvr: rcvr,
}
- switch runtime.GOARCH {
- case "amd64", "386":
- // Indirect Go func value (dummy) to obtain actual
- // code address. (A Go func value is a pointer to a C
- // function pointer. http://golang.org/s/go11func.)
- dummy := makeFuncStub
- fv.code = **(**uintptr)(unsafe.Pointer(&dummy))
- default:
- fv.code, fv.ffi = makeFuncFFI(ftyp, fv.call)
- }
+ makeFuncFFI(ftyp, fv)
return Value{ft, unsafe.Pointer(&fv), v.flag&flagRO | flag(Func) | flagIndir}
}
@@ -158,16 +128,7 @@ func makeValueMethod(v Value) Value {
rcvr: v,
}
- switch runtime.GOARCH {
- case "amd64", "386", "s390", "s390x":
- // Indirect Go func value (dummy) to obtain actual
- // code address. (A Go func value is a pointer to a C
- // function pointer. http://golang.org/s/go11func.)
- dummy := makeFuncStub
- impl.code = **(**uintptr)(unsafe.Pointer(&dummy))
- default:
- impl.code, impl.ffi = makeFuncFFI(ftyp, impl.call)
- }
+ makeFuncFFI(ftyp, impl)
return Value{t, unsafe.Pointer(&impl), v.flag&flagRO | flag(Func) | flagIndir}
}