check types.Struct isClosure
This commit is contained in:
@@ -21,8 +21,8 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
|
|||||||
br i1 %8, label %_llgo_2, label %_llgo_3
|
br i1 %8, label %_llgo_2, label %_llgo_3
|
||||||
|
|
||||||
_llgo_2: ; preds = %_llgo_1
|
_llgo_2: ; preds = %_llgo_1
|
||||||
%9 = extractvalue { i32 ()*, ptr } %1, 0
|
%9 = extractvalue { ptr, ptr } %1, 0
|
||||||
%10 = call i32 ()* %9()
|
%10 = call addrspace(37) { ptr, ptr } %1()
|
||||||
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
|
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
|
||||||
%12 = getelementptr inbounds i32, ptr %11, i64 %7
|
%12 = getelementptr inbounds i32, ptr %11, i64 %7
|
||||||
store ptr %10, ptr %12, align 8
|
store ptr %10, ptr %12, align 8
|
||||||
@@ -1041,7 +1041,7 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
|
|||||||
if name == "" {
|
if name == "" {
|
||||||
name = "closure"
|
name = "closure"
|
||||||
}
|
}
|
||||||
fmt.Fprint(&b, "Call ", fn.raw.Type, " ", name)
|
fmt.Fprint(&b, "Call ", fn.kind, " ", fn.raw.Type, " ", name)
|
||||||
sep := ": "
|
sep := ": "
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
fmt.Fprint(&b, sep, arg.impl)
|
fmt.Fprint(&b, sep, arg.impl)
|
||||||
|
|||||||
21
ssa/type.go
21
ssa/type.go
@@ -236,7 +236,8 @@ func (p Program) toType(raw types.Type) Type {
|
|||||||
case *types.Map:
|
case *types.Map:
|
||||||
return &aType{p.rtMap(), typ, vkInvalid}
|
return &aType{p.rtMap(), typ, vkInvalid}
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
return &aType{p.toLLVMStruct(t), typ, vkInvalid}
|
ll, kind := p.toLLVMStruct(t)
|
||||||
|
return &aType{ll, typ, kind}
|
||||||
case *types.Named:
|
case *types.Named:
|
||||||
return p.toNamed(t)
|
return p.toNamed(t)
|
||||||
case *types.Signature: // represents a C function pointer in raw type
|
case *types.Signature: // represents a C function pointer in raw type
|
||||||
@@ -256,9 +257,23 @@ func (p Program) toLLVMNamedStruct(name string, raw *types.Struct) llvm.Type {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Program) toLLVMStruct(raw *types.Struct) llvm.Type {
|
func (p Program) toLLVMStruct(raw *types.Struct) (ret llvm.Type, kind valueKind) {
|
||||||
fields := p.toLLVMFields(raw)
|
fields := p.toLLVMFields(raw)
|
||||||
return p.ctx.StructType(fields, false)
|
ret = p.ctx.StructType(fields, false)
|
||||||
|
if isClosure(raw) {
|
||||||
|
kind = vkClosure
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func isClosure(raw *types.Struct) bool {
|
||||||
|
n := raw.NumFields()
|
||||||
|
if n == 2 {
|
||||||
|
if _, ok := raw.Field(0).Type().(*types.Signature); ok {
|
||||||
|
return raw.Field(1).Type() == types.Typ[types.UnsafePointer]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Program) toLLVMFields(raw *types.Struct) (fields []llvm.Type) {
|
func (p Program) toLLVMFields(raw *types.Struct) (fields []llvm.Type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user