提交 7cb70a8d 编写于 作者: 3 3dgen

修正[low:high:max]语法未处理max的问题

上级 baf0f798
......@@ -916,15 +916,18 @@ func (g *functionGenerator) genSlice(inst *ssa.Slice) ([]wat.Inst, wir.ValueType
}
x := g.getValue(inst.X)
var low, high wir.Value
var low, high, max wir.Value
if inst.Low != nil {
low = g.getValue(inst.Low).value
}
if inst.High != nil {
high = g.getValue(inst.High).value
}
if inst.Max != nil {
max = g.getValue(inst.Max).value
}
return g.module.EmitGenSlice(x.value, low, high)
return g.module.EmitGenSlice(x.value, low, high, max)
}
func (g *functionGenerator) genMakeSlice(inst *ssa.MakeSlice) ([]wat.Inst, wir.ValueType) {
......
......@@ -469,10 +469,10 @@ func (m *Module) EmitGenIndex(x, id Value) (insts []wat.Inst, ret_type ValueType
return
}
func (m *Module) EmitGenSlice(x, low, high Value) (insts []wat.Inst, ret_type ValueType) {
func (m *Module) EmitGenSlice(x, low, high, max Value) (insts []wat.Inst, ret_type ValueType) {
switch x := x.(type) {
case *aSlice:
insts = x.emitSub(low, high)
insts = x.emitSub(low, high, max)
ret_type = x.Type()
case *aString:
......@@ -483,12 +483,12 @@ func (m *Module) EmitGenSlice(x, low, high Value) (insts []wat.Inst, ret_type Va
switch btype := x.Type().(*Ref).Base.(type) {
case *Slice:
slt := m.GenValueType_Slice(btype.Base)
insts = slt.emitGenFromRefOfSlice(x, low, high)
insts = slt.emitGenFromRefOfSlice(x, low, high, max)
ret_type = slt
case *Array:
slt := m.GenValueType_Slice(btype.Base)
insts = slt.emitGenFromRefOfArray(x, low, high)
insts = slt.emitGenFromRefOfArray(x, low, high, max)
ret_type = slt
default:
......
......@@ -63,7 +63,7 @@ func (t *Slice) EmitLoadFromAddr(addr Value, offset int) []wat.Inst {
}
/*这个函数极其不优雅*/
func (t *Slice) emitGenFromRefOfSlice(x *aRef, low, high Value) (insts []wat.Inst) {
func (t *Slice) emitGenFromRefOfSlice(x *aRef, low, high, max Value) (insts []wat.Inst) {
//block
insts = append(insts, x.Extract("d").EmitPush()...)
insts = append(insts, wat.NewInstLoad(wat.U32{}, 0, 1))
......@@ -93,15 +93,19 @@ func (t *Slice) emitGenFromRefOfSlice(x *aRef, low, high Value) (insts []wat.Ins
insts = append(insts, wat.NewInstSub(wat.U32{}))
//cap:
insts = append(insts, x.Extract("d").EmitPush()...)
insts = append(insts, wat.NewInstLoad(wat.U32{}, 12, 1))
if max == nil {
insts = append(insts, x.Extract("d").EmitPush()...)
insts = append(insts, wat.NewInstLoad(wat.U32{}, 12, 1))
} else {
insts = append(insts, max.EmitPush()...)
}
insts = append(insts, low.EmitPush()...)
insts = append(insts, wat.NewInstSub(wat.U32{}))
return
}
func (t *Slice) emitGenFromRefOfArray(x *aRef, low, high Value) (insts []wat.Inst) {
func (t *Slice) emitGenFromRefOfArray(x *aRef, low, high, max Value) (insts []wat.Inst) {
//block
insts = append(insts, x.Extract("b").EmitPush()...)
......@@ -127,7 +131,11 @@ func (t *Slice) emitGenFromRefOfArray(x *aRef, low, high Value) (insts []wat.Ins
insts = append(insts, wat.NewInstSub(wat.U32{}))
//cap:
insts = append(insts, array_len.EmitPush()...)
if max == nil {
insts = append(insts, array_len.EmitPush()...)
} else {
insts = append(insts, max.EmitPush()...)
}
insts = append(insts, low.EmitPush()...)
insts = append(insts, wat.NewInstSub(wat.U32{}))
......@@ -517,7 +525,7 @@ func (v *aSlice) emitStoreToAddr(addr Value, offset int) []wat.Inst {
return v.aStruct.emitStoreToAddr(addr, offset)
}
func (v *aSlice) emitSub(low, high Value) (insts []wat.Inst) {
func (v *aSlice) emitSub(low, high, max Value) (insts []wat.Inst) {
//block
insts = append(insts, v.Extract("b").EmitPush()...)
......@@ -540,7 +548,11 @@ func (v *aSlice) emitSub(low, high Value) (insts []wat.Inst) {
insts = append(insts, wat.NewInstSub(wat.U32{}))
//cap:
insts = append(insts, v.Extract("c").EmitPush()...)
if max == nil {
insts = append(insts, v.Extract("c").EmitPush()...)
} else {
insts = append(insts, max.EmitPush()...)
}
insts = append(insts, low.EmitPush()...)
insts = append(insts, wat.NewInstSub(wat.U32{}))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册