diff options
author | John Hodge <tpg@ucc.asn.au> | 2018-01-21 16:25:41 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2018-01-21 16:25:41 +0800 |
commit | 7932cf76d7e783ea76a9b117f33ca45d07db26af (patch) | |
tree | f770cb3531adaf88295bfe4fd37789ecd510c394 /src | |
parent | f6222e86fcb11093dc3e6d758b59e74fa6801a5a (diff) | |
download | mrust-7932cf76d7e783ea76a9b117f33ca45d07db26af.tar.gz |
Main - Add very crude depfile support
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/crate.hpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 64 | ||||
-rw-r--r-- | src/parse/root.cpp | 1 |
3 files changed, 45 insertions, 22 deletions
diff --git a/src/ast/crate.hpp b/src/ast/crate.hpp index b8d7be16..d6628901 100644 --- a/src/ast/crate.hpp +++ b/src/ast/crate.hpp @@ -51,6 +51,8 @@ public: bool m_test_harness = false; ::std::vector<TestDesc> m_tests; + //::std::vector<::std::string> m_extra_files; + // Procedural macros! ::std::vector<ProcMacroDef> m_proc_macros; diff --git a/src/main.cpp b/src/main.cpp index a07cddd2..7fa5e765 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,6 +162,8 @@ struct ProgramParams ::std::string output_dir = ""; ::std::string target = DEFAULT_TARGET_NAME; + ::std::string emit_depfile; + ::AST::Crate::Type crate_type = ::AST::Crate::Type::Unknown; ::std::string crate_name; ::std::string crate_name_suffix; @@ -177,7 +179,6 @@ struct ProgramParams ::std::set< ::std::string> features; - struct { bool disable_mir_optimisations = false; bool full_validate = false; @@ -336,17 +337,6 @@ int main(int argc, char *argv[]) DEBUG("params.outfile = " << params.outfile); } - //if( params.emit_depfile != "" ) - //{ - // ::std::ofstream of { params.emit_depfile }; - // of << params.outfile << ":"; - // // - Iterate all loaded files. - // for(const auto& srcfile : params.source_files) { - // of << " " << srcfile; - // } - // // - Iterate all loaded crates - //} - // XXX: Dump crate before resolve CompilePhaseV("Dump Expanded", [&]() { Dump_Rust( FMT(params.outfile << "_0a_exp.rs").c_str(), crate ); @@ -413,6 +403,38 @@ int main(int argc, char *argv[]) } }); + if( params.emit_depfile != "" ) + { + ::std::ofstream of { params.emit_depfile }; + of << params.outfile << ":"; + // - Iterate all loaded files for modules + struct H { + ::std::ofstream& of; + H(::std::ofstream& of): of(of) {} + void visit_module(::AST::Module& mod) { + if( mod.m_file_info.path != "!" && mod.m_file_info.path.back() != '/' ) { + of << " " << mod.m_file_info.path; + } + // TODO: Should we check anon modules? + //for(auto& amod : mod.anon_mods()) { + // this->visit_module(*amod); + //} + for(auto& i : mod.items()) { + if(i.data.is_Module()) { + this->visit_module(i.data.as_Module()); + } + } + } + }; + H(of).visit_module(crate.m_root_module); + // - Iterate all loaded crates files + for(const auto& ec : crate.m_extern_crates) + { + of << " " << ec.second.m_filename; + } + // - Iterate all extra files (include! and friends) + } + // Resolve names to be absolute names (include references to the relevant struct/global/function) // - This does name checking on types and free functions. // - Resolves all identifiers/paths to references @@ -745,11 +767,8 @@ ProgramParams::ProgramParams(int argc, char *argv[]) } auto get_optval = [&]() { if( eq_pos == ::std::string::npos ) { - if( i == argc - 1 ) { - ::std::cerr << "Flag -Z " << optname << " requires an argument" << ::std::endl; - exit(1); - } - optval = argv[++i]; + ::std::cerr << "Flag -Z " << optname << " requires an argument" << ::std::endl; + exit(1); } }; //auto no_optval = [&]() { @@ -763,6 +782,10 @@ ProgramParams::ProgramParams(int argc, char *argv[]) get_optval(); this->codegen.emit_build_command = optval; } + else if( optname == "emit-depfile" ) { + get_optval(); + this->emit_depfile = optval; + } else { ::std::cerr << "Unknown codegen option: '" << optname << "'" << ::std::endl; exit(1); @@ -788,11 +811,8 @@ ProgramParams::ProgramParams(int argc, char *argv[]) } auto get_optval = [&]() { if( eq_pos == ::std::string::npos ) { - if( i == argc - 1 ) { - ::std::cerr << "Flag -Z " << optname << " requires an argument" << ::std::endl; - exit(1); - } - optval = argv[++i]; + ::std::cerr << "Flag -Z " << optname << " requires an argument" << ::std::endl; + exit(1); } }; auto no_optval = [&]() { diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 5b724e1a..da61f4aa 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -1925,6 +1925,7 @@ AST::Crate Parse_Crate(::std::string mainfile) AST::Crate crate; + //crate.root_module().m_file_info.file_path = mainfile; crate.root_module().m_file_info.path = mainpath; crate.root_module().m_file_info.controls_dir = true; |