Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
5091cdcb
wa
项目概览
wa-lang
/
wa
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
5091cdcb
编写于
7月 25, 2022
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
开始支持slice
上级
9c08cd98
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
6 deletion
+56
-6
internal/backends/compiler_c/cir/ctypes/rich_type.go
internal/backends/compiler_c/cir/ctypes/rich_type.go
+1
-1
internal/backends/compiler_c/compile_func.go
internal/backends/compiler_c/compile_func.go
+55
-5
未找到文件。
internal/backends/compiler_c/cir/ctypes/rich_type.go
浏览文件 @
5091cdcb
...
...
@@ -123,7 +123,7 @@ func (t *Array) String() string {
}
func
(
t
*
Array
)
CIRString
()
string
{
return
"
std::a
rray<"
+
t
.
elem
.
CIRString
()
+
", "
+
strconv
.
Itoa
(
int
(
t
.
len
))
+
">"
return
"
$wartc::A
rray<"
+
t
.
elem
.
CIRString
()
+
", "
+
strconv
.
Itoa
(
int
(
t
.
len
))
+
">"
}
func
(
t
*
Array
)
Name
()
string
{
...
...
internal/backends/compiler_c/compile_func.go
浏览文件 @
5091cdcb
...
...
@@ -239,7 +239,7 @@ func (g *functionGenerator) genValue(v ssa.Value) cir.Expr {
return
g
.
genIndexAddr
(
v
)
case
*
ssa
.
Slice
:
return
g
.
genSlice
(
v
)
}
logger
.
Fatalf
(
"Todo: %v, type: %T"
,
v
,
v
)
...
...
@@ -394,11 +394,10 @@ func (g *functionGenerator) genField(inst *ssa.Field) cir.Expr {
}
func
(
g
*
functionGenerator
)
genIndexAddr
(
inst
*
ssa
.
IndexAddr
)
cir
.
Expr
{
println
(
g
.
getValue
(
inst
.
Index
))
x
:=
g
.
getValue
(
inst
.
X
)
switch
t
:=
x
.
Type
()
.
(
type
)
{
case
*
ctypes
.
Array
:
return
cir
.
NewRawExpr
(
"&"
+
x
.
CIRString
()
+
".a
t("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
")"
,
ctypes
.
NewPointerType
(
t
.
GetElem
()))
return
cir
.
NewRawExpr
(
x
.
CIRString
()
+
".A
t("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
")"
,
ctypes
.
NewPointerType
(
t
.
GetElem
()))
case
*
ctypes
.
Slice
:
return
cir
.
NewRawExpr
(
"{ "
+
x
.
CIRString
()
+
".At("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
"), "
+
x
.
CIRString
()
+
".GetBlock() }"
,
ctypes
.
NewRefType
(
t
.
GetElem
()))
...
...
@@ -406,9 +405,10 @@ func (g *functionGenerator) genIndexAddr(inst *ssa.IndexAddr) cir.Expr {
case
*
ctypes
.
PointerType
:
switch
t
:=
t
.
Base
.
(
type
)
{
case
*
ctypes
.
Array
:
return
cir
.
NewRawExpr
(
"&"
+
x
.
CIRString
()
+
"->a
t("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
")"
,
ctypes
.
NewPointerType
(
t
.
GetElem
()))
return
cir
.
NewRawExpr
(
x
.
CIRString
()
+
"->A
t("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
")"
,
ctypes
.
NewPointerType
(
t
.
GetElem
()))
case
*
ctypes
.
Slice
:
logger
.
Fatal
(
"a bug here?"
)
return
cir
.
NewRawExpr
(
"{ "
+
x
.
CIRString
()
+
"->At("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
"), "
+
x
.
CIRString
()
+
".GetBlock() }"
,
ctypes
.
NewRefType
(
t
.
GetElem
()))
default
:
...
...
@@ -418,9 +418,10 @@ func (g *functionGenerator) genIndexAddr(inst *ssa.IndexAddr) cir.Expr {
case
*
ctypes
.
RefType
:
switch
t
:=
t
.
Base
.
(
type
)
{
case
*
ctypes
.
Array
:
return
cir
.
NewRawExpr
(
"{
&"
+
x
.
CIRString
()
+
".GetRaw()->a
t("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
"), "
+
x
.
CIRString
()
+
".GetBlock() }"
,
ctypes
.
NewRefType
(
t
.
GetElem
()))
return
cir
.
NewRawExpr
(
"{
"
+
x
.
CIRString
()
+
".GetRaw()->A
t("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
"), "
+
x
.
CIRString
()
+
".GetBlock() }"
,
ctypes
.
NewRefType
(
t
.
GetElem
()))
case
*
ctypes
.
Slice
:
logger
.
Fatal
(
"a bug here?"
)
return
cir
.
NewRawExpr
(
"{ "
+
x
.
CIRString
()
+
".GetRaw()->At("
+
g
.
getValue
(
inst
.
Index
)
.
CIRString
()
+
"), "
+
x
.
CIRString
()
+
".GetBlock() }"
,
ctypes
.
NewRefType
(
t
.
GetElem
()))
}
...
...
@@ -431,6 +432,55 @@ func (g *functionGenerator) genIndexAddr(inst *ssa.IndexAddr) cir.Expr {
return
nil
}
func
(
g
*
functionGenerator
)
genSlice
(
inst
*
ssa
.
Slice
)
cir
.
Expr
{
x
:=
g
.
getValue
(
inst
.
X
)
switch
t
:=
x
.
Type
()
.
(
type
)
{
case
*
ctypes
.
Array
:
logger
.
Fatal
(
"Shouldn't have ctypes.Array here!"
)
case
*
ctypes
.
Slice
:
logger
.
Fatalf
(
"Todo: genSlice(), %T %s"
,
x
.
Type
(),
inst
)
case
*
ctypes
.
RefType
:
switch
t
:=
t
.
Base
.
(
type
)
{
case
*
ctypes
.
Array
:
var
low
,
high
cir
.
Expr
if
inst
.
Low
!=
nil
{
low
=
g
.
getValue
(
inst
.
Low
)
}
else
{
low
=
cconstant
.
NewInt
(
ctypes
.
Int64
,
0
)
}
if
inst
.
High
!=
nil
{
high
=
g
.
getValue
(
inst
.
High
)
}
else
{
high
=
cir
.
NewRawExpr
(
x
.
CIRString
()
+
".GetRaw()->Size()"
,
ctypes
.
Uint64
)
}
array_len
:=
cir
.
NewSubExpr
(
high
,
low
)
array_cap
:=
cir
.
NewSubExpr
(
cir
.
NewRawExpr
(
x
.
CIRString
()
+
".GetRaw()->Size()"
,
ctypes
.
Uint64
),
low
)
s
:=
"{ "
s
+=
x
.
CIRString
()
+
".GetRaw()->At("
s
+=
low
.
CIRString
()
+
"), "
s
+=
x
.
CIRString
()
+
".GetBlock(), "
s
+=
array_len
.
CIRString
()
+
", "
s
+=
array_cap
.
CIRString
()
+
" }"
return
cir
.
NewRawExpr
(
s
,
ctypes
.
NewSlice
(
t
.
GetElem
()))
case
*
ctypes
.
Slice
:
logger
.
Printf
(
"Todo: genSlice(), range check: %s
\n
"
,
inst
)
default
:
logger
.
Fatalf
(
"Todo: genSlice(), %T %s"
,
x
.
Type
(),
inst
)
}
default
:
logger
.
Fatalf
(
"Todo: genSlice(), %T %s"
,
x
.
Type
(),
inst
)
}
return
nil
}
func
(
g
*
functionGenerator
)
genBuiltin
(
call
*
ssa
.
CallCommon
)
cir
.
Expr
{
switch
call
.
Value
.
Name
()
{
case
"print"
,
"println"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录