Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
44c18438
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,发现更多精彩内容 >>
提交
44c18438
编写于
9月 16, 2017
作者:
B
bjorn3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add TransCrate trait
上级
89af6d5c
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
337 addition
and
50 deletion
+337
-50
src/Cargo.lock
src/Cargo.lock
+12
-0
src/librustc_driver/Cargo.toml
src/librustc_driver/Cargo.toml
+1
-0
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+19
-24
src/librustc_driver/lib.rs
src/librustc_driver/lib.rs
+115
-25
src/librustc_driver/test.rs
src/librustc_driver/test.rs
+1
-1
src/librustc_trans/Cargo.toml
src/librustc_trans/Cargo.toml
+1
-0
src/librustc_trans/lib.rs
src/librustc_trans/lib.rs
+55
-0
src/librustc_trans_traits/Cargo.toml
src/librustc_trans_traits/Cargo.toml
+17
-0
src/librustc_trans_traits/lib.rs
src/librustc_trans_traits/lib.rs
+116
-0
未找到文件。
src/Cargo.lock
浏览文件 @
44c18438
...
@@ -1575,6 +1575,7 @@ dependencies = [
...
@@ -1575,6 +1575,7 @@ dependencies = [
"rustc_resolve 0.0.0",
"rustc_resolve 0.0.0",
"rustc_save_analysis 0.0.0",
"rustc_save_analysis 0.0.0",
"rustc_trans 0.0.0",
"rustc_trans 0.0.0",
"rustc_trans_traits 0.0.0",
"rustc_trans_utils 0.0.0",
"rustc_trans_utils 0.0.0",
"rustc_typeck 0.0.0",
"rustc_typeck 0.0.0",
"serialize 0.0.0",
"serialize 0.0.0",
...
@@ -1769,12 +1770,23 @@ dependencies = [
...
@@ -1769,12 +1770,23 @@ dependencies = [
"rustc_incremental 0.0.0",
"rustc_incremental 0.0.0",
"rustc_llvm 0.0.0",
"rustc_llvm 0.0.0",
"rustc_platform_intrinsics 0.0.0",
"rustc_platform_intrinsics 0.0.0",
"rustc_trans_traits 0.0.0",
"rustc_trans_utils 0.0.0",
"rustc_trans_utils 0.0.0",
"serialize 0.0.0",
"serialize 0.0.0",
"syntax 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
"syntax_pos 0.0.0",
]
]
[[package]]
name = "rustc_trans_traits"
version = "0.0.0"
dependencies = [
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc_back 0.0.0",
"rustc_incremental 0.0.0",
]
[[package]]
[[package]]
name = "rustc_trans_utils"
name = "rustc_trans_utils"
version = "0.0.0"
version = "0.0.0"
...
...
src/librustc_driver/Cargo.toml
浏览文件 @
44c18438
...
@@ -33,6 +33,7 @@ rustc_resolve = { path = "../librustc_resolve" }
...
@@ -33,6 +33,7 @@ rustc_resolve = { path = "../librustc_resolve" }
rustc_save_analysis
=
{
path
=
"../librustc_save_analysis"
}
rustc_save_analysis
=
{
path
=
"../librustc_save_analysis"
}
rustc_trans
=
{
path
=
"../librustc_trans"
,
optional
=
true
}
rustc_trans
=
{
path
=
"../librustc_trans"
,
optional
=
true
}
rustc_trans_utils
=
{
path
=
"../librustc_trans_utils"
}
rustc_trans_utils
=
{
path
=
"../librustc_trans_utils"
}
rustc_trans_traits
=
{
path
=
"../librustc_trans_traits"
}
rustc_typeck
=
{
path
=
"../librustc_typeck"
}
rustc_typeck
=
{
path
=
"../librustc_typeck"
}
serialize
=
{
path
=
"../libserialize"
}
serialize
=
{
path
=
"../libserialize"
}
syntax
=
{
path
=
"../libsyntax"
}
syntax
=
{
path
=
"../libsyntax"
}
...
...
src/librustc_driver/driver.rs
浏览文件 @
44c18438
...
@@ -34,8 +34,8 @@
...
@@ -34,8 +34,8 @@
use
rustc_resolve
::{
MakeGlobMap
,
Resolver
};
use
rustc_resolve
::{
MakeGlobMap
,
Resolver
};
use
rustc_metadata
::
creader
::
CrateLoader
;
use
rustc_metadata
::
creader
::
CrateLoader
;
use
rustc_metadata
::
cstore
::{
self
,
CStore
};
use
rustc_metadata
::
cstore
::{
self
,
CStore
};
use
rustc_trans
::
back
::
write
;
use
rustc_trans
as
trans
;
use
rustc_trans
as
trans
;
use
rustc_trans_traits
::
TransCrate
;
use
rustc_typeck
as
typeck
;
use
rustc_typeck
as
typeck
;
use
rustc_privacy
;
use
rustc_privacy
;
use
rustc_plugin
::
registry
::
Registry
;
use
rustc_plugin
::
registry
::
Registry
;
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
use
rustc_passes
::{
ast_validation
,
no_asm
,
loops
,
consts
,
static_recursion
,
hir_stats
};
use
rustc_passes
::{
ast_validation
,
no_asm
,
loops
,
consts
,
static_recursion
,
hir_stats
};
use
rustc_const_eval
::{
self
,
check_match
};
use
rustc_const_eval
::{
self
,
check_match
};
use
super
::
Compilation
;
use
super
::
Compilation
;
use
::
DefaultTransCrate
;
use
serialize
::
json
;
use
serialize
::
json
;
...
@@ -76,7 +77,6 @@ pub fn compile_input(sess: &Session,
...
@@ -76,7 +77,6 @@ pub fn compile_input(sess: &Session,
output
:
&
Option
<
PathBuf
>
,
output
:
&
Option
<
PathBuf
>
,
addl_plugins
:
Option
<
Vec
<
String
>>
,
addl_plugins
:
Option
<
Vec
<
String
>>
,
control
:
&
CompileController
)
->
CompileResult
{
control
:
&
CompileController
)
->
CompileResult
{
use
rustc_trans
::
back
::
write
::
OngoingCrateTranslation
;
use
rustc
::
session
::
config
::
CrateType
;
use
rustc
::
session
::
config
::
CrateType
;
macro_rules!
controller_entry_point
{
macro_rules!
controller_entry_point
{
...
@@ -122,7 +122,7 @@ pub fn compile_input(sess: &Session,
...
@@ -122,7 +122,7 @@ pub fn compile_input(sess: &Session,
// We need nested scopes here, because the intermediate results can keep
// We need nested scopes here, because the intermediate results can keep
// large chunks of memory alive and we want to free them as soon as
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
// possible to keep the peak memory usage low
let
(
outputs
,
trans
,
dep_graph
)
:
(
OutputFilenames
,
OngoingCrateTranslation
,
DepGraph
)
=
{
let
(
outputs
,
trans
,
dep_graph
)
=
{
let
krate
=
match
phase_1_parse_input
(
control
,
sess
,
input
)
{
let
krate
=
match
phase_1_parse_input
(
control
,
sess
,
input
)
{
Ok
(
krate
)
=>
krate
,
Ok
(
krate
)
=>
krate
,
Err
(
mut
parse_error
)
=>
{
Err
(
mut
parse_error
)
=>
{
...
@@ -251,7 +251,7 @@ pub fn compile_input(sess: &Session,
...
@@ -251,7 +251,7 @@ pub fn compile_input(sess: &Session,
tcx
.print_debug_stats
();
tcx
.print_debug_stats
();
}
}
let
trans
=
phase_4_translate_to_llvm
(
tcx
,
rx
);
let
trans
=
phase_4_translate_to_llvm
::
<
DefaultTransCrate
>
(
tcx
,
rx
);
if
log_enabled!
(::
log
::
LogLevel
::
Info
)
{
if
log_enabled!
(::
log
::
LogLevel
::
Info
)
{
println!
(
"Post-trans"
);
println!
(
"Post-trans"
);
...
@@ -285,7 +285,7 @@ pub fn compile_input(sess: &Session,
...
@@ -285,7 +285,7 @@ pub fn compile_input(sess: &Session,
sess
.code_stats
.borrow
()
.print_type_sizes
();
sess
.code_stats
.borrow
()
.print_type_sizes
();
}
}
let
(
phase5_result
,
trans
)
=
phase_5_run_llvm_passes
(
sess
,
&
dep_graph
,
trans
);
let
(
phase5_result
,
trans
)
=
phase_5_run_llvm_passes
::
<
DefaultTransCrate
>
(
sess
,
&
dep_graph
,
trans
);
controller_entry_point!
(
after_llvm
,
controller_entry_point!
(
after_llvm
,
sess
,
sess
,
...
@@ -293,7 +293,7 @@ pub fn compile_input(sess: &Session,
...
@@ -293,7 +293,7 @@ pub fn compile_input(sess: &Session,
phase5_result
);
phase5_result
);
phase5_result
?
;
phase5_result
?
;
phase_6_link_output
(
sess
,
&
trans
,
&
outputs
);
phase_6_link_output
::
<
DefaultTransCrate
>
(
sess
,
&
trans
,
&
outputs
);
// Now that we won't touch anything in the incremental compilation directory
// Now that we won't touch anything in the incremental compilation directory
// any more, we can finalize it (which involves renaming it)
// any more, we can finalize it (which involves renaming it)
...
@@ -972,7 +972,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
...
@@ -972,7 +972,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
mir
::
provide
(
&
mut
local_providers
);
mir
::
provide
(
&
mut
local_providers
);
reachable
::
provide
(
&
mut
local_providers
);
reachable
::
provide
(
&
mut
local_providers
);
rustc_privacy
::
provide
(
&
mut
local_providers
);
rustc_privacy
::
provide
(
&
mut
local_providers
);
trans
::
provide_local
(
&
mut
local_providers
);
DefaultTransCrate
::
provide_local
(
&
mut
local_providers
);
typeck
::
provide
(
&
mut
local_providers
);
typeck
::
provide
(
&
mut
local_providers
);
ty
::
provide
(
&
mut
local_providers
);
ty
::
provide
(
&
mut
local_providers
);
traits
::
provide
(
&
mut
local_providers
);
traits
::
provide
(
&
mut
local_providers
);
...
@@ -984,7 +984,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
...
@@ -984,7 +984,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
let
mut
extern_providers
=
ty
::
maps
::
Providers
::
default
();
let
mut
extern_providers
=
ty
::
maps
::
Providers
::
default
();
cstore
::
provide
(
&
mut
extern_providers
);
cstore
::
provide
(
&
mut
extern_providers
);
trans
::
provide_extern
(
&
mut
extern_providers
);
DefaultTransCrate
::
provide_extern
(
&
mut
extern_providers
);
ty
::
provide_extern
(
&
mut
extern_providers
);
ty
::
provide_extern
(
&
mut
extern_providers
);
traits
::
provide_extern
(
&
mut
extern_providers
);
traits
::
provide_extern
(
&
mut
extern_providers
);
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
...
@@ -1130,9 +1130,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
...
@@ -1130,9 +1130,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
/// Run the translation phase to LLVM, after which the AST and analysis can
/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
/// be discarded.
pub
fn
phase_4_translate_to_llvm
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
pub
fn
phase_4_translate_to_llvm
<
'a
,
'tcx
,
T
:
TransCrate
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
rx
:
mpsc
::
Receiver
<
Box
<
Any
+
Send
>>
)
rx
:
mpsc
::
Receiver
<
Box
<
Any
+
Send
>>
)
->
write
::
OngoingCrateTranslation
{
->
<
T
as
TransCrate
>
::
OngoingCrateTranslation
{
let
time_passes
=
tcx
.sess
.time_passes
();
let
time_passes
=
tcx
.sess
.time_passes
();
time
(
time_passes
,
time
(
time_passes
,
...
@@ -1141,9 +1141,8 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
...
@@ -1141,9 +1141,8 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
translation
=
let
translation
=
time
(
time_passes
,
"translation"
,
move
||
{
time
(
time_passes
,
"translation"
,
move
||
{
trans
::
trans_crate
(
tcx
,
rx
)
T
::
trans_crate
(
tcx
,
rx
)
});
});
if
tcx
.sess
.profile_queries
()
{
if
tcx
.sess
.profile_queries
()
{
profile
::
dump
(
"profile_queries"
.to_string
())
profile
::
dump
(
"profile_queries"
.to_string
())
}
}
...
@@ -1153,15 +1152,14 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
...
@@ -1153,15 +1152,14 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// Run LLVM itself, producing a bitcode file, assembly file or object file
/// Run LLVM itself, producing a bitcode file, assembly file or object file
/// as a side effect.
/// as a side effect.
#[cfg(feature=
"llvm"
)]
pub
fn
phase_5_run_llvm_passes
<
T
:
TransCrate
>
(
sess
:
&
Session
,
pub
fn
phase_5_run_llvm_passes
(
sess
:
&
Session
,
dep_graph
:
&
DepGraph
,
dep_graph
:
&
DepGraph
,
trans
:
write
::
OngoingCrateTranslation
)
trans
:
<
T
as
TransCrate
>
::
OngoingCrateTranslation
)
->
(
CompileResult
,
trans
::
CrateTranslation
)
{
->
(
CompileResult
,
<
T
as
TransCrate
>
::
TranslatedCrate
)
{
let
trans
=
trans
.join
(
sess
,
dep_graph
);
let
trans
=
T
::
join_trans
(
trans
,
sess
,
dep_graph
);
if
sess
.opts.debugging_opts.incremental_info
{
if
sess
.opts.debugging_opts.incremental_info
{
write
::
dump_incremental_data
(
&
trans
);
T
::
dump_incremental_data
(
&
trans
);
}
}
time
(
sess
.time_passes
(),
time
(
sess
.time_passes
(),
...
@@ -1174,14 +1172,11 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
...
@@ -1174,14 +1172,11 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
/// Run the linker on any artifacts that resulted from the LLVM run.
/// Run the linker on any artifacts that resulted from the LLVM run.
/// This should produce either a finished executable or library.
/// This should produce either a finished executable or library.
#[cfg(feature=
"llvm"
)]
#[cfg(feature=
"llvm"
)]
pub
fn
phase_6_link_output
(
sess
:
&
Session
,
pub
fn
phase_6_link_output
<
T
:
TransCrate
>
(
sess
:
&
Session
,
trans
:
&
trans
::
CrateTranslation
,
trans
:
&
<
T
as
TransCrate
>
::
TranslatedCrate
,
outputs
:
&
OutputFilenames
)
{
outputs
:
&
OutputFilenames
)
{
time
(
sess
.time_passes
(),
"linking"
,
||
{
time
(
sess
.time_passes
(),
"linking"
,
||
{
::
rustc_trans
::
back
::
link
::
link_binary
(
sess
,
T
::
link_binary
(
sess
,
trans
,
outputs
)
trans
,
outputs
,
&
trans
.crate_name
.as_str
())
});
});
}
}
...
...
src/librustc_driver/lib.rs
浏览文件 @
44c18438
...
@@ -25,9 +25,7 @@
...
@@ -25,9 +25,7 @@
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_diagnostic_macros)]
#![feature(set_stdio)]
#![feature(set_stdio)]
#[cfg(not(feature=
"llvm"
))]
extern
crate
ar
;
extern
crate
ar
;
#[cfg(not(feature=
"llvm"
))]
extern
crate
flate2
;
extern
crate
flate2
;
extern
crate
arena
;
extern
crate
arena
;
extern
crate
getopts
;
extern
crate
getopts
;
...
@@ -54,6 +52,7 @@
...
@@ -54,6 +52,7 @@
#[cfg(feature=
"llvm"
)]
#[cfg(feature=
"llvm"
)]
extern
crate
rustc_trans
;
extern
crate
rustc_trans
;
extern
crate
rustc_trans_utils
;
extern
crate
rustc_trans_utils
;
extern
crate
rustc_trans_traits
;
extern
crate
rustc_typeck
;
extern
crate
rustc_typeck
;
extern
crate
serialize
;
extern
crate
serialize
;
#[macro_use]
#[macro_use]
...
@@ -79,6 +78,7 @@
...
@@ -79,6 +78,7 @@
use
rustc_metadata
::
locator
;
use
rustc_metadata
::
locator
;
use
rustc_metadata
::
cstore
::
CStore
;
use
rustc_metadata
::
cstore
::
CStore
;
use
rustc
::
util
::
common
::{
time
,
ErrorReported
};
use
rustc
::
util
::
common
::{
time
,
ErrorReported
};
use
rustc_trans_traits
::
TransCrate
;
use
serialize
::
json
::
ToJson
;
use
serialize
::
json
::
ToJson
;
...
@@ -155,11 +155,10 @@ pub fn run<F>(run_compiler: F) -> isize
...
@@ -155,11 +155,10 @@ pub fn run<F>(run_compiler: F) -> isize
}
}
#[cfg(not(feature=
"llvm"
))]
#[cfg(not(feature=
"llvm"
))]
pub
use
no_llvm_metadata_loader
::
NoLLvmMetadataLoader
as
MetadataLoader
;
pub
use
trans_metadata_only
::
MetadataOnlyTransCrate
as
DefaultTransCrate
;
#[cfg(feature=
"llvm"
)]
#[cfg(feature=
"llvm"
)]
pub
use
rustc_trans
::
Llvm
MetadataLoader
as
MetadataLoader
;
pub
use
rustc_trans
::
Llvm
TransCrate
as
DefaultTransCrate
;
#[cfg(not(feature=
"llvm"
))]
mod
no_llvm_metadata_loader
{
mod
no_llvm_metadata_loader
{
extern
crate
owning_ref
;
extern
crate
owning_ref
;
...
@@ -172,9 +171,9 @@ mod no_llvm_metadata_loader {
...
@@ -172,9 +171,9 @@ mod no_llvm_metadata_loader {
use
ar
::
Archive
;
use
ar
::
Archive
;
use
self
::
owning_ref
::{
OwningRef
,
ErasedBoxRef
};
use
self
::
owning_ref
::{
OwningRef
,
ErasedBoxRef
};
pub
struct
NoL
L
vmMetadataLoader
;
pub
struct
NoL
l
vmMetadataLoader
;
impl
MetadataLoaderTrait
for
NoL
L
vmMetadataLoader
{
impl
MetadataLoaderTrait
for
NoL
l
vmMetadataLoader
{
fn
get_rlib_metadata
(
fn
get_rlib_metadata
(
&
self
,
&
self
,
_
:
&
Target
,
_
:
&
Target
,
...
@@ -210,40 +209,131 @@ fn get_dylib_metadata(&self,
...
@@ -210,40 +209,131 @@ fn get_dylib_metadata(&self,
}
}
}
}
#[cfg(not(feature=
"llvm"
))]
mod
trans_metadata_only
{
mod
rustc_trans
{
use
std
::
io
::
prelude
::
*
;
use
syntax_pos
::
symbol
::
Symbol
;
use
std
::
io
::
Cursor
;
use
std
::
fs
::
File
;
use
ar
::{
Builder
,
Header
};
use
flate2
::
Compression
;
use
flate2
::
write
::
DeflateEncoder
;
use
syntax
::
symbol
::
Symbol
;
use
rustc
::
hir
::
def_id
::
LOCAL_CRATE
;
use
rustc
::
session
::
Session
;
use
rustc
::
session
::
Session
;
use
rustc
::
session
::
config
::{
PrintRequest
,
OutputFilenames
};
use
rustc
::
session
::
config
::{
OutputFilenames
,
CrateType
};
use
rustc
::
ty
::{
TyCtxt
,
CrateAnalysis
};
use
rustc
::
ty
::{
TyCtxt
,
CrateAnalysis
};
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc
::
middle
::
cstore
::{
MetadataLoader
,
EncodedMetadata
};
use
rustc
::
dep_graph
::
DepGraph
;
use
rustc_incremental
::
IncrementalHashesMap
;
use
rustc_incremental
::
IncrementalHashesMap
;
use
rustc_trans_utils
::
find_exported_symbols
;
use
rustc_trans_utils
::
link
::{
out_filename
,
build_link_meta
};
use
rustc_trans_traits
::
TransCrate
;
#[allow(dead_code)]
pub
struct
MetadataOnlyTransCrate
;
pub
struct
OngoingCrateTranslation
{
metadata
:
EncodedMetadata
,
metadata_version
:
Vec
<
u8
>
,
crate_name
:
Symbol
,
}
pub
struct
TranslatedCrate
(
OngoingCrateTranslation
);
impl
MetadataOnlyTransCrate
{
#[allow(dead_code)]
pub
fn
new
(
/*_sess: &Session*/
)
->
Self
{
MetadataOnlyTransCrate
}
}
impl
TransCrate
for
MetadataOnlyTransCrate
{
type
MetadataLoader
=
::
no_llvm_metadata_loader
::
NoLlvmMetadataLoader
;
type
OngoingCrateTranslation
=
OngoingCrateTranslation
;
type
TranslatedCrate
=
TranslatedCrate
;
fn
metadata_loader
()
->
Box
<
MetadataLoader
>
{
box
::
no_llvm_metadata_loader
::
NoLlvmMetadataLoader
}
fn
provide
(
_
providers
:
&
mut
Providers
)
{}
fn
trans_crate
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
analysis
:
CrateAnalysis
,
incr_hashes_map
:
IncrementalHashesMap
,
_
output_filenames
:
&
OutputFilenames
)
->
Self
::
OngoingCrateTranslation
{
let
link_meta
=
build_link_meta
(
&
incr_hashes_map
);
let
exported_symbols
=
find_exported_symbols
(
tcx
,
&
analysis
.reachable
);
let
(
metadata
,
_
hashes
)
=
tcx
.encode_metadata
(
&
link_meta
,
&
exported_symbols
);
OngoingCrateTranslation
{
metadata
:
metadata
,
metadata_version
:
tcx
.metadata_encoding_version
()
.to_vec
(),
crate_name
:
tcx
.crate_name
(
LOCAL_CRATE
),
}
}
use
self
::
back
::
write
::
OngoingCrateTranslation
;
fn
join_trans
(
trans
:
Self
::
OngoingCrateTranslation
,
_
sess
:
&
Session
,
_
dep_graph
:
&
DepGraph
,
)
->
Self
::
TranslatedCrate
{
TranslatedCrate
(
trans
)
}
fn
link_binary
(
sess
:
&
Session
,
trans
:
&
Self
::
TranslatedCrate
,
outputs
:
&
OutputFilenames
)
{
for
&
crate_type
in
sess
.opts.crate_types
.iter
()
{
if
crate_type
!=
CrateType
::
CrateTypeRlib
&&
crate_type
!=
CrateType
::
CrateTypeDylib
{
continue
;
}
let
output_name
=
out_filename
(
sess
,
crate_type
,
&
outputs
,
&
trans
.0
.crate_name
.as_str
());
let
mut
compressed
=
trans
.0
.metadata_version
.clone
();
let
metadata
=
if
crate_type
==
CrateType
::
CrateTypeDylib
{
DeflateEncoder
::
new
(
&
mut
compressed
,
Compression
::
Fast
)
.write_all
(
&
trans
.0
.metadata.raw_data
)
.unwrap
();
&
compressed
}
else
{
&
trans
.0
.metadata.raw_data
};
let
mut
builder
=
Builder
::
new
(
File
::
create
(
&
output_name
)
.unwrap
());
let
header
=
Header
::
new
(
"rust.metadata.bin"
.to_string
(),
metadata
.len
()
as
u64
);
builder
.append
(
&
header
,
Cursor
::
new
(
metadata
))
.unwrap
();
}
}
fn
dump_incremental_data
(
_
trans
:
&
Self
::
TranslatedCrate
)
{}
}
}
#[cfg(not(feature=
"llvm"
))]
mod
rustc_trans
{
use
syntax_pos
::
symbol
::
Symbol
;
use
rustc
::
session
::
Session
;
use
rustc
::
session
::
config
::
PrintRequest
;
pub
use
trans_metadata_only
::
MetadataOnlyTransCrate
as
LlvmTransCrate
;
pub
fn
init
(
_
sess
:
&
Session
)
{}
pub
fn
init
(
_
sess
:
&
Session
)
{}
pub
fn
enable_llvm_debug
()
{}
pub
fn
enable_llvm_debug
()
{}
pub
fn
provide
(
_
providers
:
&
mut
Providers
)
{}
pub
fn
print_version
()
{}
pub
fn
print_version
()
{}
pub
fn
print_passes
()
{}
pub
fn
print_passes
()
{}
pub
fn
print
(
_
req
:
PrintRequest
,
_
sess
:
&
Session
)
{}
pub
fn
print
(
_
req
:
PrintRequest
,
_
sess
:
&
Session
)
{}
pub
fn
target_features
(
_
sess
:
&
Session
)
->
Vec
<
Symbol
>
{
vec!
[]
}
pub
fn
target_features
(
_
sess
:
&
Session
)
->
Vec
<
Symbol
>
{
vec!
[]
}
pub
fn
trans_crate
<
'a
,
'tcx
>
(
_
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
_
analysis
:
CrateAnalysis
,
_
incr_hashes_map
:
IncrementalHashesMap
,
_
output_filenames
:
&
OutputFilenames
)
->
OngoingCrateTranslation
{
OngoingCrateTranslation
(())
}
pub
struct
CrateTranslation
(());
pub
struct
CrateTranslation
(());
pub
mod
back
{
pub
mod
back
{
pub
mod
write
{
pub
mod
write
{
pub
struct
OngoingCrateTranslation
(
pub
(
in
::
rustc_trans
)
());
pub
const
RELOC_MODEL_ARGS
:
[(
&
'static
str
,
());
0
]
=
[];
pub
const
RELOC_MODEL_ARGS
:
[(
&
'static
str
,
());
0
]
=
[];
pub
const
CODE_GEN_MODEL_ARGS
:
[(
&
'static
str
,
());
0
]
=
[];
pub
const
CODE_GEN_MODEL_ARGS
:
[(
&
'static
str
,
());
0
]
=
[];
}
}
...
@@ -297,7 +387,7 @@ pub fn run_compiler<'a>(args: &[String],
...
@@ -297,7 +387,7 @@ pub fn run_compiler<'a>(args: &[String],
},
},
};
};
let
cstore
=
Rc
::
new
(
CStore
::
new
(
box
::
MetadataLoader
));
let
cstore
=
Rc
::
new
(
CStore
::
new
(
DefaultTransCrate
::
metadata_loader
()
));
let
loader
=
file_loader
.unwrap_or
(
box
RealFileLoader
);
let
loader
=
file_loader
.unwrap_or
(
box
RealFileLoader
);
let
codemap
=
Rc
::
new
(
CodeMap
::
with_file_loader
(
loader
,
sopts
.file_path_mapping
()));
let
codemap
=
Rc
::
new
(
CodeMap
::
with_file_loader
(
loader
,
sopts
.file_path_mapping
()));
...
...
src/librustc_driver/test.rs
浏览文件 @
44c18438
...
@@ -105,7 +105,7 @@ fn test_env<F>(source_string: &str,
...
@@ -105,7 +105,7 @@ fn test_env<F>(source_string: &str,
options
.unstable_features
=
UnstableFeatures
::
Allow
;
options
.unstable_features
=
UnstableFeatures
::
Allow
;
let
diagnostic_handler
=
errors
::
Handler
::
with_emitter
(
true
,
false
,
emitter
);
let
diagnostic_handler
=
errors
::
Handler
::
with_emitter
(
true
,
false
,
emitter
);
let
cstore
=
Rc
::
new
(
CStore
::
new
(
box
::
MetadataLoader
));
let
cstore
=
Rc
::
new
(
CStore
::
new
(
DefaultTransCrate
::
metadata_loader
()
));
let
sess
=
session
::
build_session_
(
options
,
let
sess
=
session
::
build_session_
(
options
,
None
,
None
,
diagnostic_handler
,
diagnostic_handler
,
...
...
src/librustc_trans/Cargo.toml
浏览文件 @
44c18438
...
@@ -27,6 +27,7 @@ rustc_incremental = { path = "../librustc_incremental" }
...
@@ -27,6 +27,7 @@ rustc_incremental = { path = "../librustc_incremental" }
rustc_llvm
=
{
path
=
"../librustc_llvm"
}
rustc_llvm
=
{
path
=
"../librustc_llvm"
}
rustc_platform_intrinsics
=
{
path
=
"../librustc_platform_intrinsics"
}
rustc_platform_intrinsics
=
{
path
=
"../librustc_platform_intrinsics"
}
rustc_trans_utils
=
{
path
=
"../librustc_trans_utils"
}
rustc_trans_utils
=
{
path
=
"../librustc_trans_utils"
}
rustc_trans_traits
=
{
path
=
"../librustc_trans_traits"
}
serialize
=
{
path
=
"../libserialize"
}
serialize
=
{
path
=
"../libserialize"
}
syntax
=
{
path
=
"../libsyntax"
}
syntax
=
{
path
=
"../libsyntax"
}
syntax_pos
=
{
path
=
"../libsyntax_pos"
}
syntax_pos
=
{
path
=
"../libsyntax_pos"
}
...
...
src/librustc_trans/lib.rs
浏览文件 @
44c18438
...
@@ -50,6 +50,7 @@
...
@@ -50,6 +50,7 @@
extern
crate
rustc_llvm
as
llvm
;
extern
crate
rustc_llvm
as
llvm
;
extern
crate
rustc_platform_intrinsics
as
intrinsics
;
extern
crate
rustc_platform_intrinsics
as
intrinsics
;
extern
crate
rustc_const_math
;
extern
crate
rustc_const_math
;
extern
crate
rustc_trans_traits
;
extern
crate
rustc_trans_utils
;
extern
crate
rustc_trans_utils
;
extern
crate
rustc_demangle
;
extern
crate
rustc_demangle
;
extern
crate
jobserver
;
extern
crate
jobserver
;
...
@@ -138,6 +139,60 @@ pub mod back {
...
@@ -138,6 +139,60 @@ pub mod back {
mod
type_of
;
mod
type_of
;
mod
value
;
mod
value
;
use
rustc
::
ty
::{
self
,
TyCtxt
,
CrateAnalysis
};
use
rustc
::
session
::
Session
;
use
rustc
::
session
::
config
::
OutputFilenames
;
use
rustc
::
middle
::
cstore
::
MetadataLoader
;
use
rustc
::
dep_graph
::
DepGraph
;
use
rustc_incremental
::
IncrementalHashesMap
;
pub
struct
LlvmTransCrate
(());
impl
LlvmTransCrate
{
pub
fn
new
()
->
Self
{
LlvmTransCrate
(())
}
}
impl
rustc_trans_traits
::
TransCrate
for
LlvmTransCrate
{
type
MetadataLoader
=
metadata
::
LlvmMetadataLoader
;
type
OngoingCrateTranslation
=
back
::
write
::
OngoingCrateTranslation
;
type
TranslatedCrate
=
CrateTranslation
;
fn
metadata_loader
()
->
Box
<
MetadataLoader
>
{
box
metadata
::
LlvmMetadataLoader
}
fn
provide
(
providers
:
&
mut
ty
::
maps
::
Providers
)
{
back
::
symbol_names
::
provide
(
providers
);
}
fn
trans_crate
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
analysis
:
CrateAnalysis
,
incr_hashes_map
:
IncrementalHashesMap
,
output_filenames
:
&
OutputFilenames
)
->
Self
::
OngoingCrateTranslation
{
base
::
trans_crate
(
tcx
,
analysis
,
incr_hashes_map
,
output_filenames
)
}
fn
join_trans
(
trans
:
Self
::
OngoingCrateTranslation
,
sess
:
&
Session
,
dep_graph
:
&
DepGraph
)
->
Self
::
TranslatedCrate
{
trans
.join
(
sess
,
dep_graph
)
}
fn
link_binary
(
sess
:
&
Session
,
trans
:
&
Self
::
TranslatedCrate
,
outputs
:
&
OutputFilenames
)
{
back
::
link
::
link_binary
(
sess
,
trans
,
outputs
,
&
trans
.crate_name
.as_str
());
}
fn
dump_incremental_data
(
trans
:
&
Self
::
TranslatedCrate
)
{
back
::
write
::
dump_incremental_data
(
trans
);
}
}
pub
struct
ModuleTranslation
{
pub
struct
ModuleTranslation
{
/// The name of the module. When the crate may be saved between
/// The name of the module. When the crate may be saved between
/// compilations, incremental compilation requires that name be
/// compilations, incremental compilation requires that name be
...
...
src/librustc_trans_traits/Cargo.toml
0 → 100644
浏览文件 @
44c18438
[package]
authors
=
[
"The Rust Project Developers"
]
name
=
"rustc_trans_traits"
version
=
"0.0.0"
[lib]
name
=
"rustc_trans_traits"
path
=
"lib.rs"
crate-type
=
["dylib"]
test
=
false
[dependencies]
owning_ref
=
"0.3.3"
rustc
=
{
path
=
"../librustc"
}
rustc_back
=
{
path
=
"../librustc_back"
}
rustc_incremental
=
{
path
=
"../librustc_incremental"
}
src/librustc_trans_traits/lib.rs
0 → 100644
浏览文件 @
44c18438
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! The Rust compiler.
//!
//! # Note
//!
//! This API is completely unstable and subject to change.
#![doc(html_logo_url
=
"https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png"
,
html_favicon_url
=
"https://doc.rust-lang.org/favicon.ico"
,
html_root_url
=
"https://doc.rust-lang.org/nightly/"
)]
#![deny(warnings)]
#![feature(box_syntax)]
extern
crate
owning_ref
;
#[macro_use]
extern
crate
rustc
;
extern
crate
rustc_back
;
extern
crate
rustc_incremental
;
use
std
::
path
::
Path
;
use
owning_ref
::
ErasedBoxRef
;
use
rustc
::
session
::
Session
;
use
rustc
::
session
::
config
::
OutputFilenames
;
use
rustc
::
ty
::{
TyCtxt
,
CrateAnalysis
};
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc
::
middle
::
cstore
::
MetadataLoader
as
MetadataLoaderTrait
;
use
rustc
::
dep_graph
::
DepGraph
;
use
rustc_back
::
target
::
Target
;
use
rustc_incremental
::
IncrementalHashesMap
;
pub
trait
TransCrate
{
type
MetadataLoader
:
MetadataLoaderTrait
;
type
OngoingCrateTranslation
;
type
TranslatedCrate
;
fn
metadata_loader
()
->
Box
<
MetadataLoaderTrait
>
;
fn
provide
(
_
providers
:
&
mut
Providers
);
fn
trans_crate
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
analysis
:
CrateAnalysis
,
incr_hashes_map
:
IncrementalHashesMap
,
output_filenames
:
&
OutputFilenames
)
->
Self
::
OngoingCrateTranslation
;
fn
join_trans
(
trans
:
Self
::
OngoingCrateTranslation
,
sess
:
&
Session
,
dep_graph
:
&
DepGraph
)
->
Self
::
TranslatedCrate
;
fn
link_binary
(
sess
:
&
Session
,
trans
:
&
Self
::
TranslatedCrate
,
outputs
:
&
OutputFilenames
);
fn
dump_incremental_data
(
trans
:
&
Self
::
TranslatedCrate
);
}
pub
struct
DummyTransCrate
;
impl
TransCrate
for
DummyTransCrate
{
type
MetadataLoader
=
DummyMetadataLoader
;
type
OngoingCrateTranslation
=
();
type
TranslatedCrate
=
();
fn
metadata_loader
()
->
Box
<
MetadataLoaderTrait
>
{
box
DummyMetadataLoader
(())
}
fn
provide
(
_
providers
:
&
mut
Providers
)
{
bug!
(
"DummyTransCrate::provide"
);
}
fn
trans_crate
<
'a
,
'tcx
>
(
_
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
_
analysis
:
CrateAnalysis
,
_
incr_hashes_map
:
IncrementalHashesMap
,
_
output_filenames
:
&
OutputFilenames
)
->
Self
::
OngoingCrateTranslation
{
bug!
(
"DummyTransCrate::trans_crate"
);
}
fn
join_trans
(
_
trans
:
Self
::
OngoingCrateTranslation
,
_
sess
:
&
Session
,
_
dep_graph
:
&
DepGraph
)
->
Self
::
TranslatedCrate
{
bug!
(
"DummyTransCrate::join_trans"
);
}
fn
link_binary
(
_
sess
:
&
Session
,
_
trans
:
&
Self
::
TranslatedCrate
,
_
outputs
:
&
OutputFilenames
)
{
bug!
(
"DummyTransCrate::link_binary"
);
}
fn
dump_incremental_data
(
_
trans
:
&
Self
::
TranslatedCrate
)
{
bug!
(
"DummyTransCrate::dump_incremental_data"
);
}
}
pub
struct
DummyMetadataLoader
(());
impl
MetadataLoaderTrait
for
DummyMetadataLoader
{
fn
get_rlib_metadata
(
&
self
,
_
target
:
&
Target
,
_
filename
:
&
Path
)
->
Result
<
ErasedBoxRef
<
[
u8
]
>
,
String
>
{
bug!
(
"DummyMetadataLoader::get_rlib_metadata"
);
}
fn
get_dylib_metadata
(
&
self
,
_
target
:
&
Target
,
_
filename
:
&
Path
)
->
Result
<
ErasedBoxRef
<
[
u8
]
>
,
String
>
{
bug!
(
"DummyMetadataLoader::get_dylib_metadata"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录