提交 0b184028 编写于 作者: chai2010's avatar chai2010

Merge branch 'master' of gitee.com:wa-lang/wa

......@@ -76,17 +76,17 @@ func (g *functionGenerator) getValue(i ssa.Value) valueWrap {
val, _ := constant.Uint64Val(v.Value)
return valueWrap{value: wir.NewConst(strconv.Itoa(int(val)), g.module.U8)}
case types.Int8:
val, _ := constant.Int64Val(v.Value)
return valueWrap{value: wir.NewConst(strconv.Itoa(int(val)), g.module.I8)}
//case types.Int8:
// val, _ := constant.Int64Val(v.Value)
// return valueWrap{value: wir.NewConst(strconv.Itoa(int(val)), g.module.I8)}
case types.Uint16:
val, _ := constant.Uint64Val(v.Value)
return valueWrap{value: wir.NewConst(strconv.Itoa(int(val)), g.module.U16)}
case types.Int16:
val, _ := constant.Int64Val(v.Value)
return valueWrap{value: wir.NewConst(strconv.Itoa(int(val)), g.module.I16)}
//case types.Int16:
// val, _ := constant.Int64Val(v.Value)
// return valueWrap{value: wir.NewConst(strconv.Itoa(int(val)), g.module.I16)}
case types.Uint32, types.Uintptr:
val, _ := constant.Uint64Val(v.Value)
......@@ -624,8 +624,7 @@ func (g *functionGenerator) genBuiltin(call *ssa.CallCommon) (insts []wat.Inst,
insts = append(insts, wat.NewInstCall("$runtime.waPrintRune"))
}
if avt.Equal(g.module.U8) || avt.Equal(g.module.I8) ||
avt.Equal(g.module.U16) || avt.Equal(g.module.I16) ||
if avt.Equal(g.module.U8) || avt.Equal(g.module.U16) ||
avt.Equal(g.module.I32) || avt.Equal(g.module.U32) {
insts = append(insts, av.EmitPush()...)
insts = append(insts, wat.NewInstCall("$runtime.waPrintI32"))
......
......@@ -74,14 +74,14 @@ func (tLib *typeLib) compile(from types.Type) wir.ValueType {
case types.Float64:
newType = tLib.module.F64
case types.Int8:
newType = tLib.module.I8
//case types.Int8:
// newType = tLib.module.I8
case types.Uint8:
newType = tLib.module.U8
case types.Int16:
newType = tLib.module.I16
//case types.Int16:
// newType = tLib.module.I16
case types.Uint16:
newType = tLib.module.U16
......
......@@ -71,18 +71,45 @@ func (m *Module) EmitBinOp(x, y Value, op wat.OpCode) (insts []wat.Inst, ret_typ
} else {
insts = append(insts, wat.NewInstAdd(toWatType(rtype)))
}
if rtype.Equal(m.U8) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "255"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
} else if rtype.Equal(m.U16) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "65535"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
}
ret_type = rtype
case wat.OpCodeSub:
insts = append(insts, x.EmitPush()...)
insts = append(insts, y.EmitPush()...)
insts = append(insts, wat.NewInstSub(toWatType(rtype)))
if rtype.Equal(m.U8) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "255"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
} else if rtype.Equal(m.U16) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "65535"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
}
ret_type = rtype
case wat.OpCodeMul:
insts = append(insts, x.EmitPush()...)
insts = append(insts, y.EmitPush()...)
insts = append(insts, wat.NewInstMul(toWatType(rtype)))
if rtype.Equal(m.U8) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "255"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
} else if rtype.Equal(m.U16) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "65535"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
}
ret_type = rtype
case wat.OpCodeQuo:
......@@ -158,6 +185,15 @@ func (m *Module) EmitBinOp(x, y Value, op wat.OpCode) (insts []wat.Inst, ret_typ
insts = append(insts, y.EmitPush()...)
}
insts = append(insts, wat.NewInstShl(toWatType(rtype)))
if rtype.Equal(m.U8) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "255"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
} else if rtype.Equal(m.U16) {
insts = append(insts, wat.NewInstConst(wat.I32{}, "65535"))
insts = append(insts, wat.NewInstAnd(wat.I32{}))
}
ret_type = rtype
case wat.OpCodeShr:
......@@ -468,27 +504,27 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
xt := x.Type()
switch {
case typ.Equal(m.I8):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
break
/*case typ.Equal(m.I8):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
break
case xt.Equal(m.I64), xt.Equal(m.U64):
insts = append(insts, wat.NewInstConvert_i32_wrap_i64())
case xt.Equal(m.I64), xt.Equal(m.U64):
insts = append(insts, wat.NewInstConvert_i32_wrap_i64())
case xt.Equal(m.F32):
insts = append(insts, wat.NewInstConvert_i32_trunc_f32_s())
case xt.Equal(m.F32):
insts = append(insts, wat.NewInstConvert_i32_trunc_f32_s())
case xt.Equal(m.F64):
insts = append(insts, wat.NewInstConvert_i32_trunc_f64_s())
}
return
case xt.Equal(m.F64):
insts = append(insts, wat.NewInstConvert_i32_trunc_f64_s())
}
return */
case typ.Equal(m.U8):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE): //Todo: xt.Equal(m.I8), xt.Equal(m.I16)
break
case xt.Equal(m.I64), xt.Equal(m.U64):
......@@ -504,27 +540,27 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
insts = append(insts, wat.NewInstAnd(wat.I32{}))
return
case typ.Equal(m.I16):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
break
/*case typ.Equal(m.I16):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
break
case xt.Equal(m.I64), xt.Equal(m.U64):
insts = append(insts, wat.NewInstConvert_i32_wrap_i64())
case xt.Equal(m.I64), xt.Equal(m.U64):
insts = append(insts, wat.NewInstConvert_i32_wrap_i64())
case xt.Equal(m.F32):
insts = append(insts, wat.NewInstConvert_i32_trunc_f32_s())
case xt.Equal(m.F32):
insts = append(insts, wat.NewInstConvert_i32_trunc_f32_s())
case xt.Equal(m.F64):
insts = append(insts, wat.NewInstConvert_i32_trunc_f64_s())
}
return
case xt.Equal(m.F64):
insts = append(insts, wat.NewInstConvert_i32_trunc_f64_s())
}
return */
case typ.Equal(m.U16):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE): //Todo:xt.Equal(m.I8), xt.Equal(m.I16)
break
case xt.Equal(m.I64), xt.Equal(m.U64):
......@@ -543,7 +579,7 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
case typ.Equal(m.I32), typ.Equal(m.U32), typ.Equal(m.RUNE):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.U8), xt.Equal(m.I16), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE):
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.I32), xt.Equal(m.U32), xt.Equal(m.RUNE): //Todo:xt.Equal(m.I8), xt.Equal(m.I16),
break
case xt.Equal(m.I64), xt.Equal(m.U64):
......@@ -560,7 +596,7 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
case typ.Equal(m.I64):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.I16), xt.Equal(m.I32):
case xt.Equal(m.I32): //Todo: xt.Equal(m.I8), xt.Equal(m.I16)
insts = append(insts, wat.NewInstConvert_i64_extend_i32_s())
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.U32), xt.Equal(m.RUNE):
......@@ -580,7 +616,7 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
case typ.Equal(m.U64):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.I16), xt.Equal(m.I32):
case xt.Equal(m.I32): //Todo: xt.Equal(m.I8), xt.Equal(m.I16)
insts = append(insts, wat.NewInstConvert_i64_extend_i32_u())
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.U32), xt.Equal(m.RUNE):
......@@ -600,7 +636,7 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
case typ.Equal(m.F32):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.I16), xt.Equal(m.I32):
case xt.Equal(m.I32): //Todo: xt.Equal(m.I8), xt.Equal(m.I16)
insts = append(insts, wat.NewInstConvert_f32_convert_i32_s())
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.U32):
......@@ -620,7 +656,7 @@ func (m *Module) EmitGenConvert(x Value, typ ValueType) (insts []wat.Inst) {
case typ.Equal(m.F64):
insts = append(insts, x.EmitPush()...)
switch {
case xt.Equal(m.I8), xt.Equal(m.I16), xt.Equal(m.I32):
case xt.Equal(m.I32): //Todo: xt.Equal(m.I8), xt.Equal(m.I16)
insts = append(insts, wat.NewInstConvert_f64_convert_i32_s())
case xt.Equal(m.U8), xt.Equal(m.U16), xt.Equal(m.U32):
......
......@@ -18,7 +18,7 @@ type fnSigWrap struct {
Module:
**************************************/
type Module struct {
VOID, RUNE, I8, U8, I16, U16, I32, U32, UPTR, I64, U64, F32, F64, STRING, BYTES ValueType
VOID, RUNE, U8, U16, I32, U32, UPTR, I64, U64, F32, F64, STRING, BYTES ValueType
types_map map[string]ValueType
usedConcreteTypes []ValueType
......@@ -54,9 +54,9 @@ func NewModule() *Module {
m.VOID = &tVoid{}
m.RUNE = &tRune{}
m.I8 = &tI8{}
//m.I8 = &tI8{}
m.U8 = &tU8{}
m.I16 = &tI16{}
//m.I16 = &tI16{}
m.U16 = &tU16{}
m.I32 = &tI32{}
m.U32 = &tU32{}
......@@ -69,9 +69,9 @@ func NewModule() *Module {
m.types_map = make(map[string]ValueType)
m.addValueType(m.VOID)
m.addValueType(m.RUNE)
m.addValueType(m.I8)
//m.addValueType(m.I8)
m.addValueType(m.U8)
m.addValueType(m.I16)
//m.addValueType(m.I16)
m.addValueType(m.U16)
m.addValueType(m.I32)
m.addValueType(m.U32)
......
......@@ -38,7 +38,7 @@ const (
func toWatType(t ValueType) wat.ValueType {
switch t.(type) {
case *tI32, *tRune, *tI8, *tI16:
case *tI32, *tRune: //Todo: *tI8, *tI16*
return wat.I32{}
case *tU32, *tU8, *tU16:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册