Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f5787ed8
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,发现更多精彩内容 >>
提交
f5787ed8
编写于
9月 27, 2010
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Translate exit-task glue such that rustc's output programs exit properly.
上级
a2f4d908
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
17 deletion
+71
-17
src/comp/back/abi.rs
src/comp/back/abi.rs
+4
-0
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+67
-17
未找到文件。
src/comp/back/abi.rs
浏览文件 @
f5787ed8
...
...
@@ -48,6 +48,10 @@ fn yield_glue_name() -> str {
ret
"rust_yield_glue"
;
}
fn
exit_task_glue_name
()
->
str
{
ret
"rust_exit_task_glue"
;
}
//
// Local Variables:
// mode: rust
...
...
src/comp/middle/trans.rs
浏览文件 @
f5787ed8
...
...
@@ -25,6 +25,7 @@
type
glue_fns
=
rec
(
ValueRef
activate_glue
,
ValueRef
yield_glue
,
ValueRef
exit_task_glue
,
vec
[
ValueRef
]
upcall_glues
);
type
trans_ctxt
=
rec
(
session
.session
sess
,
...
...
@@ -240,32 +241,48 @@ fn new_builder(BasicBlockRef llbb) -> builder {
ret
builder
(
llbuild
);
}
fn
trans_block
(
@
fn_ctxt
cx
,
&
ast
.block
b
,
terminator
term
)
{
fn
new_block_ctxt
(
@
fn_ctxt
cx
,
terminator
term
)
->
@
block_ctxt
{
let
BasicBlockRef
llbb
=
llvm
.LLVMAppendBasicBlock
(
cx
.llfn
,
_
str
.buf
(
""
));
auto
bcx
=
@
rec
(
llbb
=
llbb
,
build
=
new_builder
(
llbb
),
term
=
term
,
fcx
=
cx
);
ret
@
rec
(
llbb
=
llbb
,
build
=
new_builder
(
llbb
),
term
=
term
,
fcx
=
cx
);
}
fn
trans_block
(
@
fn_ctxt
cx
,
&
ast
.block
b
,
terminator
term
)
{
auto
bcx
=
(
new_block_ctxt
(
cx
,
term
));
for
(
@
ast
.stmt
s
in
b
)
{
trans_stmt
(
bcx
,
*
s
);
}
bcx
.term
(
cx
,
bcx
.build
);
}
fn
trans_fn
(
@
trans_ctxt
cx
,
&
ast
._fn
f
)
{
let
vec
[
TypeRef
]
args
=
vec
(
T_ptr
(
T_int
()),
// outptr.
T_taskptr
()
// taskptr
fn
new_fn_ctxt
(
@
trans_ctxt
cx
,
str
name
,
TypeRef
T_out
,
vec
[
TypeRef
]
T_explicit_args
)
->
@
fn_ctxt
{
let
vec
[
TypeRef
]
args
=
vec
(
T_ptr
(
T_out
),
// outptr.
T_taskptr
()
// taskptr
);
let
ValueRef
llfn
=
decl_cdecl_fn
(
cx
.llmod
,
cx
.path
,
args
,
T_nil
());
args
+=
T_explicit_args
;
let
ValueRef
llfn
=
decl_cdecl_fn
(
cx
.llmod
,
name
,
args
,
T_nil
());
cx
.fns
.insert
(
cx
.path
,
llfn
);
let
ValueRef
lloutptr
=
llvm
.LLVMGetParam
(
llfn
,
0u
);
let
ValueRef
lltaskptr
=
llvm
.LLVMGetParam
(
llfn
,
1u
);
auto
fcx
=
@
rec
(
llfn
=
llfn
,
lloutptr
=
lloutptr
,
lltaskptr
=
lltaskptr
,
tcx
=
cx
);
ret
@
rec
(
llfn
=
llfn
,
lloutptr
=
lloutptr
,
lltaskptr
=
lltaskptr
,
tcx
=
cx
);
}
fn
trans_fn
(
@
trans_ctxt
cx
,
&
ast
._fn
f
)
{
let
TypeRef
out
=
T_int
();
let
vec
[
TypeRef
]
args
=
vec
();
auto
fcx
=
new_fn_ctxt
(
cx
,
cx
.path
,
out
,
args
);
auto
term
=
default_terminate
;
trans_block
(
fcx
,
f
.body
,
term
);
}
...
...
@@ -292,6 +309,24 @@ fn p2i(ValueRef v) -> ValueRef {
ret
llvm
.LLVMConstPtrToInt
(
v
,
T_int
());
}
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
llfn
=
cx
.glues.exit_task_glue
;
let
ValueRef
lloutptr
=
C_null
(
T_int
());
let
ValueRef
lltaskptr
=
llvm
.LLVMGetParam
(
llfn
,
0u
);
auto
fcx
=
@
rec
(
llfn
=
llfn
,
lloutptr
=
lloutptr
,
lltaskptr
=
lltaskptr
,
tcx
=
cx
);
auto
bcx
=
new_block_ctxt
(
fcx
,
term
);
trans_upcall
(
bcx
,
"upcall_exit"
,
V_args
);
bcx
.term
(
fcx
,
bcx
.build
);
}
fn
crate_constant
(
@
trans_ctxt
cx
)
->
ValueRef
{
let
ValueRef
crate_ptr
=
...
...
@@ -306,9 +341,8 @@ fn crate_constant(@trans_ctxt cx) -> ValueRef {
let
ValueRef
yield_glue_off
=
llvm
.LLVMConstSub
(
p2i
(
cx
.glues.yield_glue
),
crate_addr
);
// FIXME: we aren't generating the exit-task glue yet.
// llvm.LLVMConstSub(p2i(cx.glues.exit_task_glue), crate_addr);
let
ValueRef
exit_task_glue_off
=
C_null
(
T_int
());
let
ValueRef
exit_task_glue_off
=
llvm
.LLVMConstSub
(
p2i
(
cx
.glues.exit_task_glue
),
crate_addr
);
let
ValueRef
crate_val
=
C_struct
(
vec
(
C_null
(
T_int
()),
// ptrdiff_t image_base_off
...
...
@@ -373,6 +407,22 @@ fn trans_crate(session.session sess, ast.crate crate) {
auto
glues
=
@
rec
(
activate_glue
=
decl_glue
(
llmod
,
abi
.activate_glue_name
()),
yield_glue
=
decl_glue
(
llmod
,
abi
.yield_glue_name
()),
/*
* Note: the signature passed to decl_cdecl_fn here
* looks unusual because it is. It corresponds neither
* to an upcall signature nor a normal rust-ABI
* signature. In fact it is a fake signature, that
* exists solely to acquire the task pointer as an
* argument to the upcall. It so happens that the
* runtime sets up the task pointer as the sole incoming
* argument to the frame that we return into when
* returning to the exit task glue. So this is the
* signature required to retrieve it.
*/
exit_task_glue
=
decl_cdecl_fn
(
llmod
,
abi
.exit_task_glue_name
(),
vec
(
T_taskptr
()),
T_nil
()),
upcall_glues
=
_
vec
.init_fn
[
ValueRef
](
bind
decl_upcall
(
llmod
,
_
),
abi
.n_upcall_glues
as
uint
));
...
...
@@ -385,7 +435,7 @@ fn trans_crate(session.session sess, ast.crate crate) {
path
=
"_rust"
);
trans_mod
(
cx
,
crate
.module
);
trans_exit_task_glue
(
cx
);
trans_main_fn
(
cx
,
crate_constant
(
cx
));
llvm
.LLVMWriteBitcodeToFile
(
llmod
,
_
str
.buf
(
"rust_out.bc"
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录