Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a87e81b9
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a87e81b9
编写于
10月 01, 2010
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support refcount-drop and conditional free in rustc.
上级
d07f7533
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
10 deletion
+48
-10
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+48
-10
未找到文件。
src/comp/middle/trans.rs
浏览文件 @
a87e81b9
...
...
@@ -51,7 +51,7 @@ fn next(str prefix) -> str {
type
terminator
=
fn
(
@
fn_ctxt
cx
,
builder
build
);
tag
cleanup
{
clean
(
fn
(
@
block_ctxt
cx
));
clean
(
fn
(
@
block_ctxt
cx
)
->
@
block_ctxt
);
}
state
type
block_ctxt
=
rec
(
BasicBlockRef
llbb
,
...
...
@@ -138,12 +138,22 @@ fn T_task() -> TypeRef {
));
}
fn
T_str
()
->
TypeRef
{
fn
T_array
(
TypeRef
t
,
uint
n
)
->
TypeRef
{
ret
llvm
.LLVMArrayType
(
t
,
n
);
}
fn
T_vec
(
TypeRef
t
,
uint
n
)
->
TypeRef
{
ret
T_struct
(
vec
(
T_int
(),
// Refcount
T_int
()
// Lie about the remainder
T_int
(),
// Alloc
T_int
(),
// Fill
T_array
(
t
,
n
)
// Body elements
));
}
fn
T_str
(
uint
n
)
->
TypeRef
{
ret
T_vec
(
T_i8
(),
n
);
}
fn
T_crate
()
->
TypeRef
{
ret
T_struct
(
vec
(
T_int
(),
// ptrdiff_t image_base_off
T_int
(),
// uintptr_t self_addr
...
...
@@ -279,8 +289,28 @@ fn build_non_gc_free(@block_ctxt cx, ValueRef v) {
C_int
(
0
)));
}
fn
drop_str
(
@
block_ctxt
cx
,
ValueRef
v
)
{
build_non_gc_free
(
cx
,
v
);
fn
decr_refcnt_and_if_zero
(
@
block_ctxt
cx
,
ValueRef
box_ptr
,
fn
(
@
block_ctxt
cx
)
inner
)
->
@
block_ctxt
{
auto
rc_ptr
=
cx
.build
.GEP
(
box_ptr
,
vec
(
C_int
(
0
),
C_int
(
abi
.box_rc_field_refcnt
)));
auto
rc
=
cx
.build
.Load
(
rc_ptr
);
rc
=
cx
.build
.Sub
(
rc
,
C_int
(
1
));
cx
.build
.Store
(
rc
,
rc_ptr
);
auto
test
=
cx
.build
.ICmp
(
lib
.llvm.LLVMIntEQ
,
C_int
(
0
),
rc
);
auto
next_cx
=
new_block_ctxt
(
cx
.fcx
,
cx
.term
);
// We terminate the then-block ourselves here with a Br, so
// the terminator we pass in to the inner call is the no-op.
auto
then_term
=
terminate_no_op
;
auto
then_cx
=
new_block_ctxt
(
cx
.fcx
,
then_term
);
inner
(
then_cx
);
then_cx
.build
.Br
(
next_cx
.llbb
);
cx
.build
.CondBr
(
test
,
then_cx
.llbb
,
next_cx
.llbb
);
ret
next_cx
;
}
fn
drop_str
(
@
block_ctxt
cx
,
ValueRef
v
)
->
@
block_ctxt
{
ret
decr_refcnt_and_if_zero
(
cx
,
v
,
bind
build_non_gc_free
(
_
,
v
));
}
fn
trans_lit
(
@
block_ctxt
cx
,
&
ast
.lit
lit
)
->
ValueRef
{
...
...
@@ -302,7 +332,7 @@ fn trans_lit(@block_ctxt cx, &ast.lit lit) -> ValueRef {
auto
v
=
trans_upcall
(
cx
,
"upcall_new_str"
,
vec
(
p2i
(
C_str
(
cx
.fcx.tcx
,
s
)),
C_int
(
len
)));
v
=
cx
.build
.IntToPtr
(
v
,
T_ptr
(
T_str
()));
v
=
cx
.build
.IntToPtr
(
v
,
T_ptr
(
T_str
(
len
as
uint
)));
cx
.cleanups
+=
vec
(
clean
(
bind
drop_str
(
_
,
v
)));
ret
v
;
}
...
...
@@ -466,10 +496,18 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) {
}
}
fn
default_terminate
(
@
fn_ctxt
cx
,
builder
build
)
{
fn
terminate_ret_void
(
@
fn_ctxt
cx
,
builder
build
)
{
build
.RetVoid
();
}
fn
terminate_branch_to
(
@
fn_ctxt
cx
,
builder
build
,
BasicBlockRef
bb
)
{
build
.Br
(
bb
);
}
fn
terminate_no_op
(
@
fn_ctxt
cx
,
builder
build
)
{
}
fn
new_builder
(
BasicBlockRef
llbb
)
->
builder
{
let
BuilderRef
llbuild
=
llvm
.LLVMCreateBuilder
();
llvm
.LLVMPositionBuilderAtEnd
(
llbuild
,
llbb
);
...
...
@@ -496,7 +534,7 @@ fn trans_block(@fn_ctxt cx, &ast.block b, terminator term) {
for
(
cleanup
c
in
bcx
.cleanups
)
{
alt
(
c
)
{
case
(
clean
(
?
cfn
))
{
cfn
(
bcx
);
bcx
=
cfn
(
bcx
);
}
}
}
...
...
@@ -527,7 +565,7 @@ fn trans_fn(@trans_ctxt cx, &ast._fn f) {
let
vec
[
TypeRef
]
args
=
vec
();
auto
fcx
=
new_fn_ctxt
(
cx
,
cx
.path
,
out
,
args
);
auto
term
=
default_terminate
;
auto
term
=
terminate_ret_void
;
trans_block
(
fcx
,
f
.body
,
term
);
}
...
...
@@ -558,7 +596,7 @@ fn p2i(ValueRef v) -> ValueRef {
fn
trans_exit_task_glue
(
@
trans_ctxt
cx
)
{
let
vec
[
TypeRef
]
T_args
=
vec
();
let
vec
[
ValueRef
]
V_args
=
vec
();
auto
term
=
default_terminate
;
auto
term
=
terminate_ret_void
;
auto
llfn
=
cx
.glues.exit_task_glue
;
let
ValueRef
lloutptr
=
C_null
(
T_int
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录