Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
7f536c42
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 搜索 >>
提交
7f536c42
编写于
2月 19, 2023
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持 ssa.Index
上级
6b2266b2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
0 deletion
+90
-0
internal/backends/compiler_wat/compile_func.go
internal/backends/compiler_wat/compile_func.go
+10
-0
internal/backends/compiler_wat/wir/instruction_emitter.go
internal/backends/compiler_wat/wir/instruction_emitter.go
+17
-0
internal/backends/compiler_wat/wir/value_array.go
internal/backends/compiler_wat/wir/value_array.go
+63
-0
未找到文件。
internal/backends/compiler_wat/compile_func.go
浏览文件 @
7f536c42
...
...
@@ -360,6 +360,9 @@ func (g *functionGenerator) genValue(v ssa.Value) ([]wat.Inst, wir.ValueType) {
case
*
ssa
.
IndexAddr
:
return
g
.
genIndexAddr
(
v
)
case
*
ssa
.
Index
:
return
g
.
genIndex
(
v
)
case
*
ssa
.
Slice
:
return
g
.
genSlice
(
v
)
...
...
@@ -717,6 +720,13 @@ func (g *functionGenerator) genIndexAddr(inst *ssa.IndexAddr) ([]wat.Inst, wir.V
return
g
.
module
.
EmitGenIndexAddr
(
x
.
value
,
id
.
value
)
}
func
(
g
*
functionGenerator
)
genIndex
(
inst
*
ssa
.
Index
)
(
insts
[]
wat
.
Inst
,
ret_type
wir
.
ValueType
)
{
x
:=
g
.
getValue
(
inst
.
X
)
id
:=
g
.
getValue
(
inst
.
Index
)
return
g
.
module
.
EmitGenIndex
(
x
.
value
,
id
.
value
)
}
func
(
g
*
functionGenerator
)
genSlice
(
inst
*
ssa
.
Slice
)
([]
wat
.
Inst
,
wir
.
ValueType
)
{
if
inst
.
Parent
()
.
ForceRegister
()
{
logger
.
Fatal
(
"ssa.Slice is not available in ForceRegister-mode"
)
...
...
internal/backends/compiler_wat/wir/instruction_emitter.go
浏览文件 @
7f536c42
...
...
@@ -296,6 +296,23 @@ func (m *Module) EmitGenIndexAddr(x, id Value) (insts []wat.Inst, ret_type Value
return
}
func
(
m
*
Module
)
EmitGenIndex
(
x
,
id
Value
)
(
insts
[]
wat
.
Inst
,
ret_type
ValueType
)
{
if
!
id
.
Type
()
.
Equal
(
m
.
I32
)
{
panic
(
"index should be i32"
)
}
switch
x
:=
x
.
(
type
)
{
case
*
aArray
:
ret_type
=
x
.
Type
()
.
(
*
Array
)
.
Base
insts
=
append
(
insts
,
x
.
emitIndexOf
(
id
)
...
)
default
:
logger
.
Fatalf
(
"Todo: %T"
,
x
)
}
return
}
func
(
m
*
Module
)
EmitGenSlice
(
x
,
low
,
high
Value
)
(
insts
[]
wat
.
Inst
,
ret_type
ValueType
)
{
switch
x
:=
x
.
(
type
)
{
case
*
aSlice
:
...
...
internal/backends/compiler_wat/wir/value_array.go
浏览文件 @
7f536c42
...
...
@@ -51,6 +51,56 @@ func (t *Array) EmitLoadFromAddr(addr Value, offset int) (insts []wat.Inst) {
return
t
.
Struct
.
EmitLoadFromAddr
(
addr
,
offset
)
}
func
(
t
*
Array
)
genFunc_IndexOf
()
string
{
if
t
.
Capacity
==
0
{
return
""
}
fn_name
:=
"$"
+
t
.
Name
()
+
".$IndexOf"
if
currentModule
.
FindFunc
(
fn_name
)
!=
nil
{
return
fn_name
}
var
f
Function
f
.
InternalName
=
fn_name
x
:=
newValue_Array
(
"x"
,
ValueKindLocal
,
t
)
id
:=
newValue_Basic
(
"id"
,
ValueKindLocal
,
t
.
_u32
)
f
.
Params
=
append
(
f
.
Params
,
x
)
f
.
Params
=
append
(
f
.
Params
,
id
)
f
.
Results
=
append
(
f
.
Results
,
t
.
Base
)
ret
:=
NewLocal
(
"ret"
,
t
.
Base
)
f
.
Locals
=
append
(
f
.
Locals
,
ret
)
var
block_pre
wat
.
Inst
{
table
:=
make
([]
int
,
t
.
Capacity
+
1
)
for
i
:=
0
;
i
<
t
.
Capacity
;
i
++
{
table
[
i
]
=
i
}
table
[
t
.
Capacity
]
=
t
.
Capacity
-
1
block_sel
:=
wat
.
NewInstBlock
(
"block_sel"
)
block_sel
.
Insts
=
append
(
block_sel
.
Insts
,
id
.
EmitPush
()
...
)
block_sel
.
Insts
=
append
(
block_sel
.
Insts
,
wat
.
NewInstBrTable
(
table
))
block_pre
=
block_sel
}
for
i
:=
0
;
i
<
t
.
Capacity
;
i
++
{
block
:=
wat
.
NewInstBlock
(
"block"
+
strconv
.
Itoa
(
i
))
block
.
Insts
=
append
(
block
.
Insts
,
block_pre
)
block
.
Insts
=
append
(
block
.
Insts
,
x
.
Extract
(
"m"
+
strconv
.
Itoa
(
i
))
.
EmitPush
()
...
)
block
.
Insts
=
append
(
block
.
Insts
,
ret
.
EmitPop
()
...
)
block
.
Insts
=
append
(
block
.
Insts
,
wat
.
NewInstBr
(
"block"
+
strconv
.
Itoa
(
t
.
Capacity
-
1
)))
block_pre
=
block
}
f
.
Insts
=
append
(
f
.
Insts
,
block_pre
)
f
.
Insts
=
append
(
f
.
Insts
,
ret
.
EmitPush
()
...
)
currentModule
.
AddFunc
(
&
f
)
return
fn_name
}
/**************************************
aArray:
**************************************/
...
...
@@ -82,3 +132,16 @@ func (v *aArray) emitStoreToAddr(addr Value, offset int) (insts []wat.Inst) {
return
v
.
aStruct
.
emitStoreToAddr
(
addr
,
offset
)
}
func
(
v
*
aArray
)
emitIndexOf
(
id
Value
)
(
insts
[]
wat
.
Inst
)
{
fn_name
:=
v
.
typ
.
genFunc_IndexOf
()
if
len
(
fn_name
)
==
0
{
return
}
insts
=
append
(
insts
,
v
.
EmitPush
()
...
)
insts
=
append
(
insts
,
id
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstCall
(
fn_name
))
return
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录