runtime.MakeSmallMap
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
import (
|
import (
|
||||||
"github.com/goplus/llgo/internal/runtime/c"
|
"github.com/goplus/llgo/internal/runtime/c"
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := map[int]int{23: 100, 7: 29}
|
a := map[int]int{23: 100, 7: 29}
|
||||||
c.Printf(c.Str("Hello %d\n"), a[23])
|
_ = a
|
||||||
|
// c.Printf(c.Str("Hello %d\n"), a[23])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
; ModuleID = 'main'
|
||||||
|
source_filename = "main"
|
||||||
|
|
||||||
|
@"main.init$guard" = global ptr null
|
||||||
|
|
||||||
|
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 void @main() {
|
||||||
|
_llgo_0:
|
||||||
|
call void @main.init()
|
||||||
|
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
|
||||||
|
|||||||
@@ -489,6 +489,10 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
|||||||
elseb := fn.Block(succs[1].Index)
|
elseb := fn.Block(succs[1].Index)
|
||||||
b.If(cond, thenb, elseb)
|
b.If(cond, thenb, elseb)
|
||||||
case *ssa.MapUpdate:
|
case *ssa.MapUpdate:
|
||||||
|
m := p.compileValue(b, v.Map)
|
||||||
|
key := p.compileValue(b, v.Key)
|
||||||
|
val := p.compileValue(b, v.Value)
|
||||||
|
b.MapUpdate(m, key, val)
|
||||||
case *ssa.Panic:
|
case *ssa.Panic:
|
||||||
arg := p.compileValue(b, v.X).Do()
|
arg := p.compileValue(b, v.X).Do()
|
||||||
b.Panic(arg)
|
b.Panic(arg)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func testCompile(t *testing.T, src, expected string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFromTestrt(t *testing.T) {
|
func TestFromTestrt(t *testing.T) {
|
||||||
cltest.FromDir(t, "map", "./_testrt", true)
|
cltest.FromDir(t, "", "./_testrt", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromTestdata(t *testing.T) {
|
func TestFromTestdata(t *testing.T) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ source_filename = "github.com/goplus/llgo/internal/runtime"
|
|||||||
%"github.com/goplus/llgo/internal/runtime.itab" = type { ptr, ptr, i32, [4 x i8], [1 x i64] }
|
%"github.com/goplus/llgo/internal/runtime.itab" = type { ptr, ptr, i32, [4 x i8], [1 x i64] }
|
||||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||||
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, ptr, ptr, i32, i32 }
|
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, ptr, ptr, i32, i32 }
|
||||||
|
%"github.com/goplus/llgo/internal/runtime.hmap" = type { i64, i8, i8, i16, i32, ptr, ptr, i64, ptr }
|
||||||
|
|
||||||
@"github.com/goplus/llgo/internal/runtime.TyAny" = global ptr null
|
@"github.com/goplus/llgo/internal/runtime.TyAny" = global ptr null
|
||||||
@"github.com/goplus/llgo/internal/runtime.basicTypes" = global ptr null
|
@"github.com/goplus/llgo/internal/runtime.basicTypes" = global ptr null
|
||||||
@@ -201,6 +202,12 @@ _llgo_0:
|
|||||||
ret %"github.com/goplus/llgo/internal/runtime.iface" %12
|
ret %"github.com/goplus/llgo/internal/runtime.iface" %12
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.makemap_small"()
|
||||||
|
ret ptr %0
|
||||||
|
}
|
||||||
|
|
||||||
define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %0, i64 %1, i64 %2) {
|
define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %0, i64 %1, i64 %2) {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
%3 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||||
@@ -287,6 +294,12 @@ _llgo_0:
|
|||||||
ret ptr %1
|
ret ptr %1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @"github.com/goplus/llgo/internal/runtime.fastrand"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = call i32 @rand()
|
||||||
|
ret i32 %0
|
||||||
|
}
|
||||||
|
|
||||||
define void @"github.com/goplus/llgo/internal/runtime.init"() {
|
define void @"github.com/goplus/llgo/internal/runtime.init"() {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
%0 = load i1, ptr @"github.com/goplus/llgo/internal/runtime.init$guard", align 1
|
%0 = load i1, ptr @"github.com/goplus/llgo/internal/runtime.init$guard", align 1
|
||||||
@@ -354,8 +367,25 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i1 @"github.com/goplus/llgo/internal/runtime.isEmpty"(i8 %0) {
|
||||||
|
_llgo_0:
|
||||||
|
%1 = icmp ule i8 %0, 1
|
||||||
|
ret i1 %1
|
||||||
|
}
|
||||||
|
|
||||||
|
define ptr @"github.com/goplus/llgo/internal/runtime.makemap_small"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||||
|
%1 = call i32 @"github.com/goplus/llgo/internal/runtime.fastrand"()
|
||||||
|
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.hmap", ptr %0, i32 0, i32 4
|
||||||
|
store i32 %1, ptr %2, align 4
|
||||||
|
ret ptr %0
|
||||||
|
}
|
||||||
|
|
||||||
declare ptr @malloc(i64)
|
declare ptr @malloc(i64)
|
||||||
|
|
||||||
declare ptr @memcpy(ptr, ptr, i64)
|
declare ptr @memcpy(ptr, ptr, i64)
|
||||||
|
|
||||||
|
declare i32 @rand()
|
||||||
|
|
||||||
declare void @"github.com/goplus/llgo/internal/abi.init"()
|
declare void @"github.com/goplus/llgo/internal/abi.init"()
|
||||||
|
|||||||
@@ -139,7 +139,8 @@ func (b Builder) MapUpdate(m, k, v Expr) {
|
|||||||
if debugInstr {
|
if debugInstr {
|
||||||
log.Printf("MapUpdate %v[%v] = %v\n", m.impl, k.impl, v.impl)
|
log.Printf("MapUpdate %v[%v] = %v\n", m.impl, k.impl, v.impl)
|
||||||
}
|
}
|
||||||
panic("todo")
|
// TODO(xsw)
|
||||||
|
// panic("todo")
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user