ssa: Lookup
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
*/
|
||||
|
||||
func main() {
|
||||
a := map[int]int{23: 100, 7: 29}
|
||||
_ = a
|
||||
// c.Printf(c.Str("Hello %d\n"), a[23])
|
||||
c.Printf(c.Str("Hello %d\n"), a[23])
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@0 = private unnamed_addr constant [10 x i8] c"Hello %d\0A\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -21,9 +22,12 @@ _llgo_0:
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
|
||||
%1 = call i32 (ptr, ...) @printf(ptr @0, <null operand!>)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
@@ -520,8 +520,12 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
|
||||
return p.compileValue(b, n.X)
|
||||
}
|
||||
}
|
||||
panic(fmt.Errorf("todo addr of %v", e))
|
||||
panic(fmt.Errorf("todo: addr of %v", e))
|
||||
})
|
||||
case *ssa.Lookup:
|
||||
x := p.compileValue(b, v.X)
|
||||
idx := p.compileValue(b, v.Index)
|
||||
ret = b.Lookup(x, idx, v.CommaOk)
|
||||
case *ssa.Slice:
|
||||
vx := v.X
|
||||
if _, ok := p.isVArgs(vx); ok { // varargs: this is a varargs slice
|
||||
|
||||
20
ssa/expr.go
20
ssa/expr.go
@@ -654,6 +654,26 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) Expr) Expr {
|
||||
return b.Load(buf)
|
||||
}
|
||||
|
||||
// The Lookup instruction yields element Index of collection map X.
|
||||
// Index is the appropriate key type.
|
||||
//
|
||||
// If CommaOk, the result is a 2-tuple of the value above and a
|
||||
// boolean indicating the result of a map membership test for the key.
|
||||
// The components of the tuple are accessed using Extract.
|
||||
//
|
||||
// Example printed form:
|
||||
//
|
||||
// t2 = t0[t1]
|
||||
// t5 = t3[t4],ok
|
||||
func (b Builder) Lookup(x, key Expr, commaOk bool) (ret Expr) {
|
||||
if debugInstr {
|
||||
log.Printf("Lookup %v, %v, %v\n", x.impl, key.impl, commaOk)
|
||||
}
|
||||
// TODO(xsw)
|
||||
// panic("todo")
|
||||
return
|
||||
}
|
||||
|
||||
// The Slice instruction yields a slice of an existing string, slice
|
||||
// or *array X between optional integer bounds Low and High.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user