runtime.Defer: remove proc
This commit is contained in:
10
c/c.go
10
c/c.go
@@ -76,11 +76,6 @@ func GoStringData(string) *Char
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
//go:linkname Remove C.remove
|
|
||||||
func Remove(path *Char) Int
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//go:linkname AllocaSigjmpBuf llgo.sigjmpbuf
|
//go:linkname AllocaSigjmpBuf llgo.sigjmpbuf
|
||||||
func AllocaSigjmpBuf() Pointer
|
func AllocaSigjmpBuf() Pointer
|
||||||
|
|
||||||
@@ -128,6 +123,11 @@ func Fflush(fp FilePtr) Int
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//go:linkname Remove C.remove
|
||||||
|
func Remove(path *Char) Int
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
//go:linkname Time C.time
|
//go:linkname Time C.time
|
||||||
func Time(*int32) int32
|
func Time(*int32) int32
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
source_filename = "main"
|
source_filename = "main"
|
||||||
|
|
||||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||||
%"github.com/goplus/llgo/internal/runtime.Defer" = type { { ptr, ptr }, i64, ptr, i64 }
|
%"github.com/goplus/llgo/internal/runtime.Defer" = type { i64, ptr, i64 }
|
||||||
|
|
||||||
@"main.init$guard" = global ptr null
|
@"main.init$guard" = global ptr null
|
||||||
@__llgo_argc = global ptr null
|
@__llgo_argc = global ptr null
|
||||||
@@ -39,72 +39,70 @@ define i32 @main(i32 %0, ptr %1) {
|
|||||||
_llgo_0:
|
_llgo_0:
|
||||||
%2 = load ptr, ptr @__llgo_defer, align 8
|
%2 = load ptr, ptr @__llgo_defer, align 8
|
||||||
%3 = call ptr @pthread_getspecific(ptr %2)
|
%3 = call ptr @pthread_getspecific(ptr %2)
|
||||||
%4 = alloca i8, i64 40, align 1
|
%4 = alloca i8, i64 24, align 1
|
||||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 0
|
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 0
|
||||||
store ptr null, ptr %5, align 8
|
store i64 0, ptr %5, align 4
|
||||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 1
|
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 1
|
||||||
store i64 0, ptr %6, align 4
|
store ptr %3, ptr %6, align 8
|
||||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 2
|
%7 = call i32 @pthread_setspecific(ptr %2, ptr %4)
|
||||||
store ptr %3, ptr %7, align 8
|
|
||||||
%8 = call i32 @pthread_setspecific(ptr %2, ptr %4)
|
|
||||||
store i32 %0, ptr @__llgo_argc, align 4
|
store i32 %0, ptr @__llgo_argc, align 4
|
||||||
store ptr %1, ptr @__llgo_argv, align 8
|
store ptr %1, ptr @__llgo_argv, align 8
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||||
call void @main.init()
|
call void @main.init()
|
||||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 1
|
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 0
|
||||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 3
|
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 2
|
||||||
%11 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i32 0, i32 0
|
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0
|
||||||
store ptr @0, ptr %12, align 8
|
store ptr @0, ptr %11, align 8
|
||||||
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i32 0, i32 1
|
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1
|
||||||
store i64 5, ptr %13, align 4
|
store i64 5, ptr %12, align 4
|
||||||
%14 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %11, align 8
|
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8
|
||||||
%15 = call i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %14)
|
%14 = call i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %13)
|
||||||
br i1 %15, label %_llgo_2, label %_llgo_3
|
br i1 %14, label %_llgo_2, label %_llgo_3
|
||||||
|
|
||||||
_llgo_1: ; No predecessors!
|
_llgo_1: ; No predecessors!
|
||||||
ret i32 0
|
ret i32 0
|
||||||
|
|
||||||
_llgo_2: ; preds = %_llgo_0
|
_llgo_2: ; preds = %_llgo_0
|
||||||
%16 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 0
|
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 0
|
||||||
store ptr @1, ptr %17, align 8
|
store ptr @1, ptr %16, align 8
|
||||||
%18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 1
|
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1
|
||||||
store i64 5, ptr %18, align 4
|
store i64 5, ptr %17, align 4
|
||||||
%19 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8
|
%18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
|
||||||
%20 = load i64, ptr %9, align 4
|
%19 = load i64, ptr %8, align 4
|
||||||
%21 = or i64 %20, 1
|
%20 = or i64 %19, 1
|
||||||
store i64 %21, ptr %9, align 4
|
store i64 %20, ptr %8, align 4
|
||||||
%22 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%21 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %22, i32 0, i32 0
|
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 0
|
||||||
store ptr @2, ptr %23, align 8
|
store ptr @2, ptr %22, align 8
|
||||||
%24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %22, i32 0, i32 1
|
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 1
|
||||||
store i64 3, ptr %24, align 4
|
store i64 3, ptr %23, align 4
|
||||||
%25 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %22, align 8
|
%24 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %21, align 8
|
||||||
%26 = load i64, ptr %9, align 4
|
%25 = load i64, ptr %8, align 4
|
||||||
%27 = or i64 %26, 2
|
%26 = or i64 %25, 2
|
||||||
store i64 %27, ptr %9, align 4
|
store i64 %26, ptr %8, align 4
|
||||||
store i64 0, ptr %10, align 4
|
store i64 0, ptr %9, align 4
|
||||||
br label %_llgo_4
|
br label %_llgo_4
|
||||||
|
|
||||||
_llgo_3: ; preds = %_llgo_0
|
_llgo_3: ; preds = %_llgo_0
|
||||||
%28 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%27 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %28, i32 0, i32 0
|
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %27, i32 0, i32 0
|
||||||
store ptr @3, ptr %29, align 8
|
store ptr @3, ptr %28, align 8
|
||||||
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %28, i32 0, i32 1
|
%29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %27, i32 0, i32 1
|
||||||
store i64 5, ptr %30, align 4
|
store i64 5, ptr %29, align 4
|
||||||
%31 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %28, align 8
|
%30 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %27, align 8
|
||||||
%32 = load i64, ptr %9, align 4
|
%31 = load i64, ptr %8, align 4
|
||||||
%33 = or i64 %32, 4
|
%32 = or i64 %31, 4
|
||||||
store i64 %33, ptr %9, align 4
|
store i64 %32, ptr %8, align 4
|
||||||
store i64 1, ptr %10, align 4
|
store i64 1, ptr %9, align 4
|
||||||
br label %_llgo_4
|
br label %_llgo_4
|
||||||
|
|
||||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||||
%34 = load i64, ptr %9, align 4
|
%33 = load i64, ptr %8, align 4
|
||||||
%35 = and i64 %34, 4
|
%34 = and i64 %33, 4
|
||||||
%36 = icmp ne i64 %35, 0
|
%35 = icmp ne i64 %34, 0
|
||||||
br i1 %36, label %_llgo_7, label %_llgo_8
|
br i1 %35, label %_llgo_7, label %_llgo_8
|
||||||
|
|
||||||
_llgo_5: ; preds = %_llgo_12
|
_llgo_5: ; preds = %_llgo_12
|
||||||
ret i32 0
|
ret i32 0
|
||||||
@@ -113,37 +111,37 @@ _llgo_6: ; preds = %_llgo_12
|
|||||||
ret i32 0
|
ret i32 0
|
||||||
|
|
||||||
_llgo_7: ; preds = %_llgo_4
|
_llgo_7: ; preds = %_llgo_4
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %31)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %30)
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_8
|
br label %_llgo_8
|
||||||
|
|
||||||
_llgo_8: ; preds = %_llgo_7, %_llgo_4
|
_llgo_8: ; preds = %_llgo_7, %_llgo_4
|
||||||
%37 = and i64 %34, 2
|
%36 = and i64 %33, 2
|
||||||
%38 = icmp ne i64 %37, 0
|
%37 = icmp ne i64 %36, 0
|
||||||
br i1 %38, label %_llgo_9, label %_llgo_10
|
br i1 %37, label %_llgo_9, label %_llgo_10
|
||||||
|
|
||||||
_llgo_9: ; preds = %_llgo_8
|
_llgo_9: ; preds = %_llgo_8
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %25)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %24)
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_10
|
br label %_llgo_10
|
||||||
|
|
||||||
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||||
%39 = and i64 %34, 1
|
%38 = and i64 %33, 1
|
||||||
%40 = icmp ne i64 %39, 0
|
%39 = icmp ne i64 %38, 0
|
||||||
br i1 %40, label %_llgo_11, label %_llgo_12
|
br i1 %39, label %_llgo_11, label %_llgo_12
|
||||||
|
|
||||||
_llgo_11: ; preds = %_llgo_10
|
_llgo_11: ; preds = %_llgo_10
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %19)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_12
|
br label %_llgo_12
|
||||||
|
|
||||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||||
call void @"main.main$1"()
|
call void @"main.main$1"()
|
||||||
%41 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, align 8
|
%40 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, align 8
|
||||||
%42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %41, 2
|
%41 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %40, 2
|
||||||
%43 = call i32 @pthread_setspecific(ptr %2, ptr %42)
|
%42 = call i32 @pthread_setspecific(ptr %2, i64 %41)
|
||||||
%44 = load i64, ptr %10, align 4
|
%43 = load i64, ptr %9, align 4
|
||||||
switch i64 %44, label %_llgo_5 [
|
switch i64 %43, label %_llgo_5 [
|
||||||
i64 1, label %_llgo_6
|
i64 1, label %_llgo_6
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,11 @@ func SmartDoFile(inFile string, pkgPath ...string) {
|
|||||||
}
|
}
|
||||||
outFile := dir + fname
|
outFile := dir + fname
|
||||||
|
|
||||||
|
b, err := os.ReadFile(outFile)
|
||||||
|
if err == nil && len(b) == 1 && b[0] == ';' {
|
||||||
|
return // skip to gen
|
||||||
|
}
|
||||||
|
|
||||||
if len(pkgPath) > 0 {
|
if len(pkgPath) > 0 {
|
||||||
Do(pkgPath[0], inFile, outFile)
|
Do(pkgPath[0], inFile, outFile)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -18,17 +18,7 @@ package runtime
|
|||||||
|
|
||||||
// Defer presents defer statements in a function.
|
// Defer presents defer statements in a function.
|
||||||
type Defer struct {
|
type Defer struct {
|
||||||
proc func(uintptr)
|
Bits uintptr
|
||||||
bits uintptr
|
Link *Defer
|
||||||
link *Defer
|
Rund int // index of RunDefers
|
||||||
rund int // index of RunDefers
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeferProc calls deferred statements.
|
|
||||||
func DeferProc(d *Defer) {
|
|
||||||
for d != nil {
|
|
||||||
d.proc(d.bits)
|
|
||||||
d = d.link
|
|
||||||
_ = d.rund
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
ssa/eh.go
14
ssa/eh.go
@@ -130,25 +130,23 @@ func (b Builder) getDefer() *aDefer {
|
|||||||
self := b.Func
|
self := b.Func
|
||||||
if self.defer_ == nil {
|
if self.defer_ == nil {
|
||||||
// TODO(xsw): if in pkg.init?
|
// TODO(xsw): if in pkg.init?
|
||||||
// 0: proc func(uintptr)
|
// 0: bits uintptr
|
||||||
// 1: bits uintptr
|
// 1: link *Defer
|
||||||
// 2: link *Defer
|
// 2: rund int
|
||||||
// 3: rund int
|
|
||||||
b.SetBlockEx(b.blk, AtStart, false)
|
b.SetBlockEx(b.blk, AtStart, false)
|
||||||
prog := b.Prog
|
prog := b.Prog
|
||||||
key := b.deferKey()
|
key := b.deferKey()
|
||||||
deferfn := prog.Null(prog.VoidPtr())
|
|
||||||
zero := prog.Val(uintptr(0))
|
zero := prog.Val(uintptr(0))
|
||||||
link := b.pthreadGetspecific(key)
|
link := b.pthreadGetspecific(key)
|
||||||
ptr := b.aggregateAlloca(prog.Defer(), deferfn.impl, zero.impl, link.impl)
|
ptr := b.aggregateAlloca(prog.Defer(), zero.impl, link.impl)
|
||||||
deferData := Expr{ptr, prog.DeferPtr()}
|
deferData := Expr{ptr, prog.DeferPtr()}
|
||||||
b.pthreadSetspecific(key, deferData)
|
b.pthreadSetspecific(key, deferData)
|
||||||
b.SetBlockEx(b.blk, AtEnd, false)
|
b.SetBlockEx(b.blk, AtEnd, false)
|
||||||
self.defer_ = &aDefer{
|
self.defer_ = &aDefer{
|
||||||
key: key,
|
key: key,
|
||||||
data: deferData,
|
data: deferData,
|
||||||
bitsPtr: b.FieldAddr(deferData, 1),
|
bitsPtr: b.FieldAddr(deferData, 0),
|
||||||
rundPtr: b.FieldAddr(deferData, 3),
|
rundPtr: b.FieldAddr(deferData, 2),
|
||||||
procBlk: self.MakeBlock(),
|
procBlk: self.MakeBlock(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user