runtime: MakeAnyString
This commit is contained in:
@@ -245,14 +245,12 @@ func (p *context) isVArgs(vx ssa.Value) (ret []llssa.Expr, ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p *context) checkVArgs(v *ssa.Alloc, t types.Type) bool {
|
||||
func (p *context) checkVArgs(v *ssa.Alloc, t *types.Pointer) bool {
|
||||
if v.Comment == "varargs" { // this is a varargs allocation
|
||||
if t, ok := t.(*types.Pointer); ok {
|
||||
if arr, ok := t.Elem().(*types.Array); ok {
|
||||
if isAny(arr.Elem()) {
|
||||
p.vargs[v] = make([]llssa.Expr, arr.Len())
|
||||
return true
|
||||
}
|
||||
if arr, ok := t.Elem().(*types.Array); ok {
|
||||
if isAny(arr.Elem()) {
|
||||
p.vargs[v] = make([]llssa.Expr, arr.Len())
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,11 +320,11 @@ func (p *context) compileInstrAndValue(b llssa.Builder, iv instrAndValue) (ret l
|
||||
}
|
||||
panic("todo")
|
||||
case *ssa.Alloc:
|
||||
t := v.Type()
|
||||
t := v.Type().(*types.Pointer)
|
||||
if p.checkVArgs(v, t) { // varargs: this is a varargs allocation
|
||||
return
|
||||
}
|
||||
ret = b.Alloc(p.prog.Type(t), v.Heap)
|
||||
ret = b.Alloc(t, v.Heap)
|
||||
case *ssa.MakeInterface:
|
||||
const (
|
||||
delayExpr = true // varargs: don't need to convert an expr to any
|
||||
|
||||
@@ -37,6 +37,13 @@ func MakeAnyInt(typ *Type, data uintptr) Interface {
|
||||
}
|
||||
}
|
||||
|
||||
func MakeAnyString(data string) Interface {
|
||||
return Interface{
|
||||
tab: &itab{inter: TyAny, _type: Basic(abi.String), hash: 0, fun: [1]uintptr{0}},
|
||||
data: unsafe.Pointer(&data),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeAny(typ *Type, data unsafe.Pointer) Interface {
|
||||
return Interface{
|
||||
tab: &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}},
|
||||
|
||||
@@ -47,6 +47,7 @@ var (
|
||||
abi.Float64: basicType(abi.Float64),
|
||||
abi.Complex64: basicType(abi.Complex64),
|
||||
abi.Complex128: basicType(abi.Complex128),
|
||||
abi.String: basicType(abi.String),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -68,6 +69,7 @@ var (
|
||||
abi.Float64: 8,
|
||||
abi.Complex64: 8,
|
||||
abi.Complex128: 16,
|
||||
abi.String: unsafe.Sizeof(String{}),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
18
ssa/expr.go
18
ssa/expr.go
@@ -403,20 +403,21 @@ func (b Builder) IndexAddr(x, idx Expr) Expr {
|
||||
//
|
||||
// t0 = local int
|
||||
// t1 = new int
|
||||
func (b Builder) Alloc(t Type, heap bool) (ret Expr) {
|
||||
func (b Builder) Alloc(t *types.Pointer, heap bool) (ret Expr) {
|
||||
if debugInstr {
|
||||
log.Printf("Alloc %v, %v\n", t.t, heap)
|
||||
log.Printf("Alloc %v, %v\n", t, heap)
|
||||
}
|
||||
telem := b.prog.Elem(t)
|
||||
prog := b.prog
|
||||
telem := t.Elem()
|
||||
if heap {
|
||||
ret.impl = llvm.CreateAlloca(b.impl, telem.ll)
|
||||
ret.impl = llvm.CreateAlloca(b.impl, prog.Type(telem).ll)
|
||||
} else {
|
||||
pkg := b.fn.pkg
|
||||
size := unsafe.Sizeof(t.t)
|
||||
ret = b.Call(pkg.rtFunc("Alloc"), b.prog.Val(size))
|
||||
size := unsafe.Sizeof(telem)
|
||||
ret = b.Call(pkg.rtFunc("Alloc"), prog.Val(size))
|
||||
}
|
||||
// TODO(xsw): zero-initialize
|
||||
ret.Type = t
|
||||
ret.Type = prog.Type(t)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -535,6 +536,9 @@ func (b Builder) MakeInterface(inter types.Type, x Expr, mayDelay bool) (ret Exp
|
||||
case vkSigned, vkUnsigned, vkFloat:
|
||||
fn := pkg.rtFunc("MakeAnyInt")
|
||||
return b.InlineCall(fn, x)
|
||||
case vkString:
|
||||
fn := pkg.rtFunc("MakeAnyString")
|
||||
return b.InlineCall(fn, x)
|
||||
}
|
||||
panic("todo")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user