Skip to content

Commit 51b7b9f

Browse files
committed
Remove dependencies on driver from trans et al. by moving various
structs out from driver and into other places.
1 parent 19b489e commit 51b7b9f

File tree

16 files changed

+171
-195
lines changed

16 files changed

+171
-195
lines changed

src/librustc/middle/ty.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ pub const INITIAL_DISCRIMINANT_VALUE: Disr = 0;
9292

9393
// Data types
9494

95+
/// The complete set of all analyses described in this module. This is
96+
/// produced by the driver and fed to trans and later passes.
97+
pub struct CrateAnalysis<'tcx> {
98+
pub exp_map2: middle::resolve::ExportMap2,
99+
pub exported_items: middle::privacy::ExportedItems,
100+
pub public_items: middle::privacy::PublicItems,
101+
pub ty_cx: ty::ctxt<'tcx>,
102+
pub reachable: NodeSet,
103+
pub name: String,
104+
}
105+
95106
#[deriving(PartialEq, Eq, Hash)]
96107
pub struct field<'tcx> {
97108
pub name: ast::Name,

src/librustc/session/config.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,59 @@ pub struct Options {
114114
pub alt_std_name: Option<String>
115115
}
116116

117+
pub enum Input {
118+
/// Load source from file
119+
File(Path),
120+
/// The string is the source
121+
Str(String)
122+
}
123+
124+
impl Input {
125+
pub fn filestem(&self) -> String {
126+
match *self {
127+
Input::File(ref ifile) => ifile.filestem_str().unwrap().to_string(),
128+
Input::Str(_) => "rust_out".to_string(),
129+
}
130+
}
131+
}
132+
133+
#[deriving(Clone)]
134+
pub struct OutputFilenames {
135+
pub out_directory: Path,
136+
pub out_filestem: String,
137+
pub single_output_file: Option<Path>,
138+
pub extra: String,
139+
}
140+
141+
impl OutputFilenames {
142+
pub fn path(&self, flavor: OutputType) -> Path {
143+
match self.single_output_file {
144+
Some(ref path) => return path.clone(),
145+
None => {}
146+
}
147+
self.temp_path(flavor)
148+
}
149+
150+
pub fn temp_path(&self, flavor: OutputType) -> Path {
151+
let base = self.out_directory.join(self.filestem());
152+
match flavor {
153+
OutputTypeBitcode => base.with_extension("bc"),
154+
OutputTypeAssembly => base.with_extension("s"),
155+
OutputTypeLlvmAssembly => base.with_extension("ll"),
156+
OutputTypeObject => base.with_extension("o"),
157+
OutputTypeExe => base,
158+
}
159+
}
160+
161+
pub fn with_extension(&self, extension: &str) -> Path {
162+
self.out_directory.join(self.filestem()).with_extension(extension)
163+
}
164+
165+
pub fn filestem(&self) -> String {
166+
format!("{}{}", self.out_filestem, self.extra)
167+
}
168+
}
169+
117170
pub fn host_triple() -> &'static str {
118171
// Get the host triple out of the build environment. This ensures that our
119172
// idea of the host triple is the same as for the set of libraries we've

src/librustc_trans/back/link.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ use super::archive;
1313
use super::rpath;
1414
use super::rpath::RPathConfig;
1515
use super::svh::Svh;
16-
use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput};
1716
use session::config;
1817
use session::config::NoDebugInfo;
19-
use session::config::{OutputTypeBitcode, OutputTypeExe, OutputTypeObject};
18+
use session::config::{OutputFilenames, Input, OutputTypeBitcode, OutputTypeExe, OutputTypeObject};
2019
use session::Session;
2120
use metadata::common::LinkMeta;
2221
use metadata::{encoder, cstore, filesearch, csearch, creader};
23-
use trans::context::CrateContext;
24-
use trans::common::gensym_name;
22+
use trans::{CrateContext, CrateTranslation, gensym_name};
2523
use middle::ty::{mod, Ty};
2624
use util::common::time;
2725
use util::ppaux;
@@ -156,7 +154,7 @@ pub fn find_crate_name(sess: Option<&Session>,
156154
if let Some((attr, s)) = attr_crate_name {
157155
return validate(s.get().to_string(), Some(attr.span));
158156
}
159-
if let FileInput(ref path) = *input {
157+
if let Input::File(ref path) = *input {
160158
if let Some(s) = path.filestem_str() {
161159
return validate(s.to_string(), None);
162160
}

src/librustc_trans/back/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
use back::lto;
1212
use back::link::{get_cc_prog, remove};
13-
use driver::driver::{CrateTranslation, ModuleTranslation, OutputFilenames};
14-
use session::config::{NoDebugInfo, Passes, SomePasses, AllPasses};
13+
use session::config::{OutputFilenames, NoDebugInfo, Passes, SomePasses, AllPasses};
1514
use session::Session;
1615
use session::config;
1716
use llvm;
1817
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
1918
use llvm::SMDiagnosticRef;
19+
use trans::{CrateTranslation, ModuleTranslation};
2020
use util::common::time;
2121
use syntax::codemap;
2222
use syntax::diagnostic;

src/librustc_trans/driver/driver.rs

Lines changed: 15 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub use self::Input::*;
12-
1311
use back::link;
1412
use back::write;
1513
use session::Session;
16-
use session::config;
14+
use session::config::{mod, Input, OutputFilenames};
1715
use lint;
18-
use llvm::{ContextRef, ModuleRef};
19-
use metadata::common::LinkMeta;
2016
use metadata::creader;
2117
use middle::{stability, ty, reachable};
2218
use middle::dependency_format;
@@ -28,7 +24,6 @@ use rustc::typeck;
2824
use trans;
2925

3026
use util::common::time;
31-
use util::nodemap::{NodeSet};
3227

3328
use serialize::{json, Encodable};
3429

@@ -114,36 +109,19 @@ pub fn anon_src() -> String {
114109
pub fn source_name(input: &Input) -> String {
115110
match *input {
116111
// FIXME (#9639): This needs to handle non-utf8 paths
117-
FileInput(ref ifile) => ifile.as_str().unwrap().to_string(),
118-
StrInput(_) => anon_src()
119-
}
120-
}
121-
122-
pub enum Input {
123-
/// Load source from file
124-
FileInput(Path),
125-
/// The string is the source
126-
StrInput(String)
127-
}
128-
129-
impl Input {
130-
fn filestem(&self) -> String {
131-
match *self {
132-
FileInput(ref ifile) => ifile.filestem_str().unwrap().to_string(),
133-
StrInput(_) => "rust_out".to_string(),
134-
}
112+
Input::File(ref ifile) => ifile.as_str().unwrap().to_string(),
113+
Input::Str(_) => anon_src()
135114
}
136115
}
137116

138-
139117
pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
140118
-> ast::Crate {
141119
let krate = time(sess.time_passes(), "parsing", (), |_| {
142120
match *input {
143-
FileInput(ref file) => {
121+
Input::File(ref file) => {
144122
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
145123
}
146-
StrInput(ref src) => {
124+
Input::Str(ref src) => {
147125
parse::parse_crate_from_source_str(anon_src().to_string(),
148126
src.to_string(),
149127
cfg.clone(),
@@ -343,23 +321,13 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session,
343321
map
344322
}
345323

346-
pub struct CrateAnalysis<'tcx> {
347-
pub exp_map2: middle::resolve::ExportMap2,
348-
pub exported_items: middle::privacy::ExportedItems,
349-
pub public_items: middle::privacy::PublicItems,
350-
pub ty_cx: ty::ctxt<'tcx>,
351-
pub reachable: NodeSet,
352-
pub name: String,
353-
}
354-
355-
356324
/// Run the resolution, typechecking, region checking and other
357325
/// miscellaneous analysis passes on the crate. Return various
358326
/// structures carrying the results of the analysis.
359327
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
360328
ast_map: ast_map::Map<'tcx>,
361329
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
362-
name: String) -> CrateAnalysis<'tcx> {
330+
name: String) -> ty::CrateAnalysis<'tcx> {
363331
let time_passes = sess.time_passes();
364332
let krate = ast_map.krate();
365333

@@ -474,7 +442,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
474442
time(time_passes, "lint checking", (), |_|
475443
lint::check_crate(&ty_cx, &exported_items));
476444

477-
CrateAnalysis {
445+
ty::CrateAnalysis {
478446
exp_map2: exp_map2,
479447
ty_cx: ty_cx,
480448
exported_items: exported_items,
@@ -486,7 +454,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
486454

487455
pub fn phase_save_analysis(sess: &Session,
488456
krate: &ast::Crate,
489-
analysis: &CrateAnalysis,
457+
analysis: &ty::CrateAnalysis,
490458
odir: &Option<Path>) {
491459
if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 {
492460
return;
@@ -495,39 +463,24 @@ pub fn phase_save_analysis(sess: &Session,
495463
save::process_crate(sess, krate, analysis, odir));
496464
}
497465

498-
pub struct ModuleTranslation {
499-
pub llcx: ContextRef,
500-
pub llmod: ModuleRef,
501-
}
502-
503-
pub struct CrateTranslation {
504-
pub modules: Vec<ModuleTranslation>,
505-
pub metadata_module: ModuleTranslation,
506-
pub link: LinkMeta,
507-
pub metadata: Vec<u8>,
508-
pub reachable: Vec<String>,
509-
pub crate_formats: dependency_format::Dependencies,
510-
pub no_builtins: bool,
511-
}
512-
513466
/// Run the translation phase to LLVM, after which the AST and analysis can
514467
/// be discarded.
515-
pub fn phase_4_translate_to_llvm<'tcx>(analysis: CrateAnalysis<'tcx>)
516-
-> (ty::ctxt<'tcx>, CrateTranslation) {
468+
pub fn phase_4_translate_to_llvm<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
469+
-> (ty::ctxt<'tcx>, trans::CrateTranslation) {
517470
let time_passes = analysis.ty_cx.sess.time_passes();
518471

519472
time(time_passes, "resolving dependency formats", (), |_|
520473
dependency_format::calculate(&analysis.ty_cx));
521474

522475
// Option dance to work around the lack of stack once closures.
523476
time(time_passes, "translation", analysis, |analysis|
524-
trans::base::trans_crate(analysis))
477+
trans::trans_crate(analysis))
525478
}
526479

527480
/// Run LLVM itself, producing a bitcode file, assembly file or object file
528481
/// as a side effect.
529482
pub fn phase_5_run_llvm_passes(sess: &Session,
530-
trans: &CrateTranslation,
483+
trans: &trans::CrateTranslation,
531484
outputs: &OutputFilenames) {
532485
if sess.opts.cg.no_integrated_as {
533486
let output_type = config::OutputTypeAssembly;
@@ -555,7 +508,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
555508
/// Run the linker on any artifacts that resulted from the LLVM run.
556509
/// This should produce either a finished executable or library.
557510
pub fn phase_6_link_output(sess: &Session,
558-
trans: &CrateTranslation,
511+
trans: &trans::CrateTranslation,
559512
outputs: &OutputFilenames) {
560513
let old_path = os::getenv("PATH").unwrap_or_else(||String::new());
561514
let mut new_path = sess.host_filesearch().get_tools_search_paths();
@@ -640,8 +593,8 @@ fn write_out_deps(sess: &Session,
640593
// Use default filename: crate source filename with extension replaced
641594
// by ".d"
642595
(true, None) => match *input {
643-
FileInput(..) => outputs.with_extension("d"),
644-
StrInput(..) => {
596+
Input::File(..) => outputs.with_extension("d"),
597+
Input::Str(..) => {
645598
sess.warn("can not write --dep-info without a filename \
646599
when compiling stdin.");
647600
return
@@ -752,43 +705,6 @@ pub fn collect_crate_metadata(session: &Session,
752705
session.opts.cg.metadata.clone()
753706
}
754707

755-
#[deriving(Clone)]
756-
pub struct OutputFilenames {
757-
pub out_directory: Path,
758-
pub out_filestem: String,
759-
pub single_output_file: Option<Path>,
760-
extra: String,
761-
}
762-
763-
impl OutputFilenames {
764-
pub fn path(&self, flavor: config::OutputType) -> Path {
765-
match self.single_output_file {
766-
Some(ref path) => return path.clone(),
767-
None => {}
768-
}
769-
self.temp_path(flavor)
770-
}
771-
772-
pub fn temp_path(&self, flavor: config::OutputType) -> Path {
773-
let base = self.out_directory.join(self.filestem());
774-
match flavor {
775-
config::OutputTypeBitcode => base.with_extension("bc"),
776-
config::OutputTypeAssembly => base.with_extension("s"),
777-
config::OutputTypeLlvmAssembly => base.with_extension("ll"),
778-
config::OutputTypeObject => base.with_extension("o"),
779-
config::OutputTypeExe => base,
780-
}
781-
}
782-
783-
pub fn with_extension(&self, extension: &str) -> Path {
784-
self.out_directory.join(self.filestem()).with_extension(extension)
785-
}
786-
787-
fn filestem(&self) -> String {
788-
format!("{}{}", self.out_filestem, self.extra)
789-
}
790-
}
791-
792708
pub fn build_output_filenames(input: &Input,
793709
odir: &Option<Path>,
794710
ofile: &Option<Path>,

src/librustc_trans/driver/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
pub use syntax::diagnostic;
1212

1313
use back::link;
14-
use driver::driver::{Input, FileInput, StrInput};
1514
use session::{config, Session, build_session};
15+
use session::config::Input;
1616
use lint::Lint;
1717
use lint;
1818
use metadata;
@@ -89,9 +89,9 @@ fn run_compiler(args: &[String]) {
8989
if ifile == "-" {
9090
let contents = io::stdin().read_to_end().unwrap();
9191
let src = String::from_utf8(contents).unwrap();
92-
(StrInput(src), None)
92+
(Input::Str(src), None)
9393
} else {
94-
(FileInput(Path::new(ifile)), Some(Path::new(ifile)))
94+
(Input::File(Path::new(ifile)), Some(Path::new(ifile)))
9595
}
9696
}
9797
_ => early_error("multiple input filenames provided")
@@ -116,11 +116,11 @@ fn run_compiler(args: &[String]) {
116116
let r = matches.opt_strs("Z");
117117
if r.contains(&("ls".to_string())) {
118118
match input {
119-
FileInput(ref ifile) => {
119+
Input::File(ref ifile) => {
120120
let mut stdout = io::stdout();
121121
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
122122
}
123-
StrInput(_) => {
123+
Input::Str(_) => {
124124
early_error("can not list metadata for stdin");
125125
}
126126
}
@@ -411,12 +411,12 @@ fn print_crate_info(sess: &Session,
411411
fn parse_crate_attrs(sess: &Session, input: &Input) ->
412412
Vec<ast::Attribute> {
413413
let result = match *input {
414-
FileInput(ref ifile) => {
414+
Input::File(ref ifile) => {
415415
parse::parse_crate_attrs_from_file(ifile,
416416
Vec::new(),
417417
&sess.parse_sess)
418418
}
419-
StrInput(ref src) => {
419+
Input::Str(ref src) => {
420420
parse::parse_crate_attrs_from_source_str(
421421
driver::anon_src().to_string(),
422422
src.to_string(),

0 commit comments

Comments
 (0)