diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-02-25 12:07:12 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-02-25 12:07:12 +0800 |
commit | 8068936c1900453fdcbb74c34ed228519ac4e06b (patch) | |
tree | 2e0847a2b7a0378f49153e035bf8f7ca135ab4ce /src/trans/codegen_c.cpp | |
parent | cb04e0ba3611deff03566eb035b2c35b4b8890f9 (diff) | |
download | mrust-8068936c1900453fdcbb74c34ed228519ac4e06b.tar.gz |
MIR Gen - Use MIR::Param (and associated changes)
Diffstat (limited to 'src/trans/codegen_c.cpp')
-rw-r--r-- | src/trans/codegen_c.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index b74589c2..5e365ceb 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -2467,25 +2467,17 @@ namespace { const ::HIR::Literal& get_literal_for_const(const ::HIR::Path& path, ::HIR::TypeRef& ty) { - TU_MATCHA( (path.m_data), (pe), - (Generic, - if( pe.m_params.m_types.size() > 0 ) - MIR_TODO(*m_mir_res, "get_literal_for_const - Paths with generics " << path); - const auto& c = m_crate.get_constant_by_path(Span(), pe.m_path); - ty = c.m_type.clone(); - return c.m_value_res; - ), - (UfcsUnknown, - MIR_BUG(*m_mir_res, "get_literal_for_const - UfcsUnknown " << path); - ), - (UfcsKnown, - MIR_TODO(*m_mir_res, "get_literal_for_const - UfcsKnown " << path); - ), - (UfcsInherent, - MIR_TODO(*m_mir_res, "get_literal_for_const - UfcsInherent " << path); - ) - ) - throw ""; + MonomorphState params; + auto v = m_resolve.get_value(m_mir_res->sp, path, params); + if( const auto* e = v.opt_Constant() ) + { + ty = params.monomorph(m_mir_res->sp, (*e)->m_type); + return (*e)->m_value_res; + } + else + { + MIR_BUG(*m_mir_res, "get_literal_for_const - Not a constant - " << path); + } } void assign_from_literal(::std::function<void()> emit_dst, const ::HIR::TypeRef& ty, const ::HIR::Literal& lit) @@ -2861,11 +2853,12 @@ namespace { ), (Const, // TODO: This should have been eliminated? + // NOTE: GCC hack - statement expressions ::HIR::TypeRef ty; const auto& lit = get_literal_for_const(c.p, ty); - m_of << "({"; emit_ctype(ty, FMT_CB(ss, ss<<"v";)); m_of << ";"; + m_of << "({"; emit_ctype(ty, FMT_CB(ss, ss<<"v";)); m_of << "; "; assign_from_literal([&](){ m_of << "v"; }, ty, lit); - m_of << "v})"; + m_of << "; v;})"; ), (ItemAddr, TU_MATCHA( (c.m_data), (pe), |