Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ac34068e
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,发现更多精彩内容 >>
提交
ac34068e
编写于
9月 24, 2018
作者:
D
Denis Merigoux
提交者:
Eduard-Mihai Burtescu
11月 16, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generalized base:maybe_create_entry_wrapper
上级
b14f3e54
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
24 deletion
+39
-24
src/librustc_codegen_llvm/base.rs
src/librustc_codegen_llvm/base.rs
+25
-24
src/librustc_codegen_llvm/context.rs
src/librustc_codegen_llvm/context.rs
+8
-0
src/librustc_codegen_llvm/debuginfo/mod.rs
src/librustc_codegen_llvm/debuginfo/mod.rs
+3
-0
src/librustc_codegen_llvm/interfaces/debuginfo.rs
src/librustc_codegen_llvm/interfaces/debuginfo.rs
+1
-0
src/librustc_codegen_llvm/interfaces/misc.rs
src/librustc_codegen_llvm/interfaces/misc.rs
+2
-0
未找到文件。
src/librustc_codegen_llvm/base.rs
浏览文件 @
ac34068e
...
...
@@ -30,7 +30,7 @@
use
abi
;
use
back
::
write
::{
self
,
OngoingCodegen
};
use
llvm
::{
self
,
get_param
}
;
use
llvm
;
use
metadata
;
use
rustc
::
dep_graph
::
cgu_reuse_tracker
::
CguReuse
;
use
rustc
::
hir
::
def_id
::{
CrateNum
,
DefId
,
LOCAL_CRATE
};
...
...
@@ -50,7 +50,6 @@
use
rustc_incremental
;
use
allocator
;
use
mir
::
place
::
PlaceRef
;
use
attributes
;
use
builder
::{
Builder
,
MemFlags
};
use
callee
;
use
rustc_mir
::
monomorphize
::
item
::
DefPathBasedNames
;
...
...
@@ -495,48 +494,50 @@ pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
/// Create the `main` function which will initialize the rust runtime and call
/// users main function.
fn
maybe_create_entry_wrapper
(
cx
:
&
CodegenCx
)
{
fn
maybe_create_entry_wrapper
<
'a
,
'tcx
:
'a
,
Bx
:
BuilderMethods
<
'a
,
'tcx
>>
(
cx
:
&
'a
Bx
::
CodegenCx
)
{
let
(
main_def_id
,
span
)
=
match
*
cx
.sess
()
.entry_fn
.borrow
()
{
Some
((
id
,
span
,
_
))
=>
{
(
cx
.tcx.hir
.local_def_id
(
id
),
span
)
(
cx
.tcx
()
.hir
.local_def_id
(
id
),
span
)
}
None
=>
return
,
};
let
instance
=
Instance
::
mono
(
cx
.tcx
,
main_def_id
);
let
instance
=
Instance
::
mono
(
cx
.tcx
()
,
main_def_id
);
if
!
cx
.codegen_unit
.contains_item
(
&
MonoItem
::
Fn
(
instance
))
{
if
!
cx
.codegen_unit
()
.contains_item
(
&
MonoItem
::
Fn
(
instance
))
{
// We want to create the wrapper in the same codegen unit as Rust's main
// function.
return
;
}
let
main_llfn
=
c
allee
::
get_fn
(
cx
,
instance
);
let
main_llfn
=
c
x
.get_fn
(
instance
);
let
et
=
cx
.sess
()
.entry_fn
.get
()
.map
(|
e
|
e
.2
);
match
et
{
Some
(
EntryFnType
::
Main
)
=>
create_entry_fn
(
cx
,
span
,
main_llfn
,
main_def_id
,
true
),
Some
(
EntryFnType
::
Start
)
=>
create_entry_fn
(
cx
,
span
,
main_llfn
,
main_def_id
,
false
),
Some
(
EntryFnType
::
Main
)
=>
create_entry_fn
::
<
Bx
>
(
cx
,
span
,
main_llfn
,
main_def_id
,
true
),
Some
(
EntryFnType
::
Start
)
=>
create_entry_fn
::
<
Bx
>
(
cx
,
span
,
main_llfn
,
main_def_id
,
false
),
None
=>
{}
// Do nothing.
}
fn
create_entry_fn
(
cx
:
&
CodegenCx
<
'll
,
'_
>
,
fn
create_entry_fn
<
'a
,
'tcx
:
'a
,
Bx
:
BuilderMethods
<
'a
,
'tcx
>>
(
cx
:
&
'a
Bx
::
CodegenCx
,
sp
:
Span
,
rust_main
:
&
'll
Value
,
rust_main
:
Bx
::
Value
,
rust_main_def_id
:
DefId
,
use_start_lang_item
:
bool
,
)
{
let
llfty
=
cx
.type_func
(
&
[
cx
.type_int
(),
cx
.type_ptr_to
(
cx
.type_i8p
())],
cx
.type_int
());
let
main_ret_ty
=
cx
.tcx
.fn_sig
(
rust_main_def_id
)
.output
();
let
main_ret_ty
=
cx
.tcx
()
.fn_sig
(
rust_main_def_id
)
.output
();
// Given that `main()` has no arguments,
// then its return type cannot have
// late-bound regions, since late-bound
// regions must appear in the argument
// listing.
let
main_ret_ty
=
cx
.tcx
.erase_regions
(
let
main_ret_ty
=
cx
.tcx
()
.erase_regions
(
&
main_ret_ty
.no_bound_vars
()
.unwrap
(),
);
...
...
@@ -551,25 +552,25 @@ fn create_entry_fn(
let
llfn
=
cx
.declare_cfn
(
"main"
,
llfty
);
// `main` should respect same config for frame pointer elimination as rest of code
attributes
::
set_frame_pointer_elimination
(
cx
,
llfn
);
attributes
::
apply_target_cpu_attr
(
cx
,
llfn
);
cx
.set_frame_pointer_elimination
(
llfn
);
cx
.apply_target_cpu_attr
(
llfn
);
let
bx
=
B
uilder
::
new_block
(
cx
,
llfn
,
"top"
);
let
bx
=
B
x
::
new_block
(
&
cx
,
llfn
,
"top"
);
debuginfo
::
gdb
::
insert_reference_to_gdb_debug_scripts_section_global
(
&
bx
);
bx
.insert_reference_to_gdb_debug_scripts_section_global
(
);
// Params from native main() used as args for rust start function
let
param_argc
=
get_param
(
llfn
,
0
);
let
param_argv
=
get_param
(
llfn
,
1
);
let
arg_argc
=
bx
.intcast
(
param_argc
,
cx
.
isize_ty
,
true
);
let
param_argc
=
cx
.
get_param
(
llfn
,
0
);
let
param_argv
=
cx
.
get_param
(
llfn
,
1
);
let
arg_argc
=
bx
.intcast
(
param_argc
,
cx
.
type_isize
()
,
true
);
let
arg_argv
=
param_argv
;
let
(
start_fn
,
args
)
=
if
use_start_lang_item
{
let
start_def_id
=
cx
.tcx
.require_lang_item
(
StartFnLangItem
);
let
start_def_id
=
cx
.tcx
()
.require_lang_item
(
StartFnLangItem
);
let
start_fn
=
callee
::
resolve_and_get_fn
(
cx
,
start_def_id
,
cx
.tcx
.intern_substs
(
&
[
main_ret_ty
.into
()]),
cx
.tcx
()
.intern_substs
(
&
[
main_ret_ty
.into
()]),
);
(
start_fn
,
vec!
[
bx
.pointercast
(
rust_main
,
cx
.type_ptr_to
(
cx
.type_i8p
())),
arg_argc
,
arg_argv
])
...
...
@@ -1112,7 +1113,7 @@ fn module_codegen<'a, 'tcx>(
// If this codegen unit contains the main function, also create the
// wrapper here
maybe_create_entry_wrapper
(
&
cx
);
maybe_create_entry_wrapper
::
<
Builder
<&
Value
>>
(
&
cx
);
// Run replace-all-uses-with for statics that need it
for
&
(
old_g
,
new_g
)
in
cx
.statics_to_rauw
.borrow
()
.iter
()
{
...
...
src/librustc_codegen_llvm/context.rs
浏览文件 @
ac34068e
...
...
@@ -425,6 +425,14 @@ fn stats(&self) -> &RefCell<Stats> {
fn
codegen_unit
(
&
self
)
->
&
Arc
<
CodegenUnit
<
'tcx
>>
{
&
self
.codegen_unit
}
fn
set_frame_pointer_elimination
(
&
self
,
llfn
:
&
'll
Value
)
{
attributes
::
set_frame_pointer_elimination
(
self
,
llfn
)
}
fn
apply_target_cpu_attr
(
&
self
,
llfn
:
&
'll
Value
)
{
attributes
::
apply_target_cpu_attr
(
self
,
llfn
)
}
}
impl
IntrinsicDeclarationMethods
<
'tcx
>
for
CodegenCx
<
'b
,
'tcx
>
{
...
...
src/librustc_codegen_llvm/debuginfo/mod.rs
浏览文件 @
ac34068e
...
...
@@ -279,6 +279,9 @@ fn set_source_location(
)
{
set_source_location
(
debug_context
,
&
self
,
scope
,
span
)
}
fn
insert_reference_to_gdb_debug_scripts_section_global
(
&
self
)
{
gdb
::
insert_reference_to_gdb_debug_scripts_section_global
(
self
)
}
}
impl
DebugInfoMethods
<
'tcx
>
for
CodegenCx
<
'll
,
'tcx
>
{
...
...
src/librustc_codegen_llvm/interfaces/debuginfo.rs
浏览文件 @
ac34068e
...
...
@@ -58,4 +58,5 @@ fn set_source_location(
scope
:
Option
<
Self
::
DIScope
>
,
span
:
Span
,
);
fn
insert_reference_to_gdb_debug_scripts_section_global
(
&
self
);
}
src/librustc_codegen_llvm/interfaces/misc.rs
浏览文件 @
ac34068e
...
...
@@ -31,4 +31,6 @@ fn vtables(
fn
sess
(
&
self
)
->
&
Session
;
fn
stats
(
&
self
)
->
&
RefCell
<
Stats
>
;
fn
codegen_unit
(
&
self
)
->
&
Arc
<
CodegenUnit
<
'tcx
>>
;
fn
set_frame_pointer_elimination
(
&
self
,
llfn
:
Self
::
Value
);
fn
apply_target_cpu_attr
(
&
self
,
llfn
:
Self
::
Value
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录