Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
ad1a12c9
wa
项目概览
wa-lang
/
wa
10 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ad1a12c9
编写于
6月 19, 2023
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
屏蔽i8、i16类型
上级
38243912
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
86 addition
and
51 deletion
+86
-51
internal/backends/compiler_wat/compile_func.go
internal/backends/compiler_wat/compile_func.go
+7
-8
internal/backends/compiler_wat/compile_type.go
internal/backends/compiler_wat/compile_type.go
+4
-4
internal/backends/compiler_wat/wir/instruction_emitter.go
internal/backends/compiler_wat/wir/instruction_emitter.go
+69
-33
internal/backends/compiler_wat/wir/module.go
internal/backends/compiler_wat/wir/module.go
+5
-5
internal/backends/compiler_wat/wir/value_type.go
internal/backends/compiler_wat/wir/value_type.go
+1
-1
未找到文件。
internal/backends/compiler_wat/compile_func.go
浏览文件 @
ad1a12c9
...
...
@@ -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"
))
...
...
internal/backends/compiler_wat/compile_type.go
浏览文件 @
ad1a12c9
...
...
@@ -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
...
...
internal/backends/compiler_wat/wir/instruction_emitter.go
浏览文件 @
ad1a12c9
...
...
@@ -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
.
I
8
),
xt
.
Equal
(
m
.
I16
),
xt
.
Equal
(
m
.
I32
)
:
case
xt
.
Equal
(
m
.
I
32
)
:
//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
.
I
8
),
xt
.
Equal
(
m
.
I16
),
xt
.
Equal
(
m
.
I32
)
:
case
xt
.
Equal
(
m
.
I
32
)
:
//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
.
I
8
),
xt
.
Equal
(
m
.
I16
),
xt
.
Equal
(
m
.
I32
)
:
case
xt
.
Equal
(
m
.
I
32
)
:
//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
.
I
8
),
xt
.
Equal
(
m
.
I16
),
xt
.
Equal
(
m
.
I32
)
:
case
xt
.
Equal
(
m
.
I
32
)
:
//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
)
:
...
...
internal/backends/compiler_wat/wir/module.go
浏览文件 @
ad1a12c9
...
...
@@ -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
)
...
...
internal/backends/compiler_wat/wir/value_type.go
浏览文件 @
ad1a12c9
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录