summaryrefslogtreecommitdiff
path: root/src/trans/enumerate.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-03-04 20:04:05 +0800
committerJohn Hodge <tpg@mutabah.net>2018-03-17 18:52:16 +0800
commitdcf1204a8bae3f15e875ffe9c861c38789f524fe (patch)
tree4405146ea56a7d409d59d0a9cf60fd0700bc28a2 /src/trans/enumerate.cpp
parent30659582e602d3b95fdf3ab390c49c67292ea48f (diff)
downloadmrust-dcf1204a8bae3f15e875ffe9c861c38789f524fe.tar.gz
Trans - Move monomorphisation from codegen pass to its own pass, and do a second inlining pass after monomorph.
Diffstat (limited to 'src/trans/enumerate.cpp')
-rw-r--r--src/trans/enumerate.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp
index 4c91f5f3..4a6e5767 100644
--- a/src/trans/enumerate.cpp
+++ b/src/trans/enumerate.cpp
@@ -332,6 +332,51 @@ TransList Trans_Enumerate_Public(::HIR::Crate& crate)
return rv;
}
+void Trans_Enumerate_Cleanup(const ::HIR::Crate& crate, TransList& list)
+{
+ EnumState state { crate };
+
+ // TODO: Get a list of "root" functions (e.g. main, public functions, things used by public generics) and re-enumerate based on that.
+
+ // Visit every function used
+ for(const auto& ent : list.m_functions)
+ {
+ if( ent.second->monomorphised.code )
+ {
+ Trans_Enumerate_FillFrom_MIR(state, *ent.second->monomorphised.code, {});
+ }
+ else if( ent.second->ptr->m_code.m_mir )
+ {
+ Trans_Enumerate_FillFrom_MIR(state, *ent.second->ptr->m_code.m_mir, {});
+ }
+ else
+ {
+ }
+ }
+
+ // Remove any item in `list.m_functions` that doesn't appear in `state.rv.m_functions`
+ for(auto it = list.m_functions.begin(); it != list.m_functions.end();)
+ {
+ auto it2 = state.rv.m_functions.find(it->first);
+ if( it2 == state.rv.m_functions.end() )
+ {
+ DEBUG("Remove " << it->first);
+ it = list.m_functions.erase(it);
+ }
+ else
+ {
+ DEBUG("Keep " << it->first);
+ ++ it;
+ }
+ }
+
+ // Sanity check: all items in `state.rv.m_functions` must exist in `list.m_functions`
+ for(const auto& e : state.rv.m_functions)
+ {
+ auto it = list.m_functions.find(e.first);
+ ASSERT_BUG(Span(), it != list.m_functions.end(), "Enumerate Error - New function appeared after monomorphisation - " << e.first);
+ }
+}
/// Common post-processing
void Trans_Enumerate_CommonPost_Run(EnumState& state)