ssa: fix named func call
This commit is contained in:
15
cl/_testgo/closure/in.go
Normal file
15
cl/_testgo/closure/in.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type T func(n int)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var env string = "env"
|
||||||
|
var v1 T = func(i int) {
|
||||||
|
println("func", i)
|
||||||
|
}
|
||||||
|
var v2 T = func(i int) {
|
||||||
|
println("closure", i, env)
|
||||||
|
}
|
||||||
|
v1(100)
|
||||||
|
v2(200)
|
||||||
|
}
|
||||||
115
cl/_testgo/closure/out.ll
Normal file
115
cl/_testgo/closure/out.ll
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
; ModuleID = 'main'
|
||||||
|
source_filename = "main"
|
||||||
|
|
||||||
|
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||||
|
|
||||||
|
@"main.init$guard" = global i1 false, align 1
|
||||||
|
@__llgo_argc = global i32 0, align 4
|
||||||
|
@__llgo_argv = global ptr null, align 8
|
||||||
|
@0 = private unnamed_addr constant [3 x i8] c"env", align 1
|
||||||
|
@1 = private unnamed_addr constant [4 x i8] c"func", align 1
|
||||||
|
@2 = private unnamed_addr constant [7 x i8] c"closure", align 1
|
||||||
|
|
||||||
|
define void @main.init() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = load i1, ptr @"main.init$guard", align 1
|
||||||
|
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
store i1 true, ptr @"main.init$guard", align 1
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define i32 @main(i32 %0, ptr %1) {
|
||||||
|
_llgo_0:
|
||||||
|
store i32 %0, ptr @__llgo_argc, align 4
|
||||||
|
store ptr %1, ptr @__llgo_argv, align 8
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||||
|
call void @main.init()
|
||||||
|
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||||
|
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
|
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
|
||||||
|
store ptr @0, ptr %4, align 8
|
||||||
|
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
|
||||||
|
store i64 3, ptr %5, align 4
|
||||||
|
%6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
|
||||||
|
store %"github.com/goplus/llgo/internal/runtime.String" %6, ptr %2, align 8
|
||||||
|
%7 = alloca { ptr, ptr }, align 8
|
||||||
|
%8 = getelementptr inbounds { ptr, ptr }, ptr %7, i32 0, i32 0
|
||||||
|
store ptr @"__llgo_stub.main.main$1", ptr %8, align 8
|
||||||
|
%9 = getelementptr inbounds { ptr, ptr }, ptr %7, i32 0, i32 1
|
||||||
|
store ptr null, ptr %9, align 8
|
||||||
|
%10 = load { ptr, ptr }, ptr %7, align 8
|
||||||
|
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||||
|
%12 = getelementptr inbounds { ptr }, ptr %11, i32 0, i32 0
|
||||||
|
store ptr %2, ptr %12, align 8
|
||||||
|
%13 = alloca { ptr, ptr }, align 8
|
||||||
|
%14 = getelementptr inbounds { ptr, ptr }, ptr %13, i32 0, i32 0
|
||||||
|
store ptr @"main.main$2", ptr %14, align 8
|
||||||
|
%15 = getelementptr inbounds { ptr, ptr }, ptr %13, i32 0, i32 1
|
||||||
|
store ptr %11, ptr %15, align 8
|
||||||
|
%16 = load { ptr, ptr }, ptr %13, align 8
|
||||||
|
%17 = extractvalue { ptr, ptr } %10, 1
|
||||||
|
%18 = extractvalue { ptr, ptr } %10, 0
|
||||||
|
call void %18(ptr %17, i64 100)
|
||||||
|
%19 = extractvalue { ptr, ptr } %16, 1
|
||||||
|
%20 = extractvalue { ptr, ptr } %16, 0
|
||||||
|
call void %20(ptr %19, i64 200)
|
||||||
|
ret i32 0
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @"main.main$1"(i64 %0) {
|
||||||
|
_llgo_0:
|
||||||
|
%1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
|
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 0
|
||||||
|
store ptr @1, ptr %2, align 8
|
||||||
|
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 1
|
||||||
|
store i64 4, ptr %3, align 4
|
||||||
|
%4 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %1, align 8
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %0)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @"main.main$2"(ptr %0, i64 %1) {
|
||||||
|
_llgo_0:
|
||||||
|
%2 = load { ptr }, ptr %0, align 8
|
||||||
|
%3 = extractvalue { ptr } %2, 0
|
||||||
|
%4 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
|
||||||
|
%5 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
|
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 0
|
||||||
|
store ptr @2, ptr %6, align 8
|
||||||
|
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 1
|
||||||
|
store i64 7, ptr %7, align 4
|
||||||
|
%8 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %5, align 8
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %8)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %1)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||||
|
|
||||||
|
define linkonce void @"__llgo_stub.main.main$1"(ptr %0, i64 %1) {
|
||||||
|
_llgo_0:
|
||||||
|
tail call void @"main.main$1"(i64 %1)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||||
10
ssa/expr.go
10
ssa/expr.go
@@ -689,12 +689,14 @@ func (b Builder) ChangeType(t Type, x Expr) (ret Expr) {
|
|||||||
log.Printf("ChangeType %v, %v\n", t.RawType(), x.impl)
|
log.Printf("ChangeType %v, %v\n", t.RawType(), x.impl)
|
||||||
}
|
}
|
||||||
typ := t.raw.Type
|
typ := t.raw.Type
|
||||||
switch typ.(type) {
|
switch t.kind {
|
||||||
|
case vkClosure:
|
||||||
|
ret.impl = checkExpr(x, typ.Underlying(), b).impl
|
||||||
default:
|
default:
|
||||||
ret.impl = llvm.CreateBitCast(b.impl, x.impl, t.ll)
|
ret.impl = x.impl
|
||||||
ret.Type = b.Prog.rawType(typ)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
ret.Type = t
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Convert instruction yields the conversion of value X to type
|
// The Convert instruction yields the conversion of value X to type
|
||||||
|
|||||||
@@ -486,7 +486,11 @@ func (p Program) toNamed(raw *types.Named) Type {
|
|||||||
switch t := raw.Underlying().(type) {
|
switch t := raw.Underlying().(type) {
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
name := p.llvmNameOf(raw)
|
name := p.llvmNameOf(raw)
|
||||||
return &aType{p.toLLVMNamedStruct(name, t), rawType{raw}, vkStruct}
|
kind := vkStruct
|
||||||
|
if isClosure(t) {
|
||||||
|
kind = vkClosure
|
||||||
|
}
|
||||||
|
return &aType{p.toLLVMNamedStruct(name, t), rawType{raw}, kind}
|
||||||
default:
|
default:
|
||||||
typ := p.rawType(t)
|
typ := p.rawType(t)
|
||||||
return &aType{typ.ll, rawType{raw}, typ.kind}
|
return &aType{typ.ll, rawType{raw}, typ.kind}
|
||||||
|
|||||||
Reference in New Issue
Block a user