diff options
-rw-r--r-- | src/trans/codegen.cpp | 17 | ||||
-rw-r--r-- | src/trans/codegen_c.cpp | 14 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/trans/codegen.cpp b/src/trans/codegen.cpp index 3cb49887..5be07199 100644 --- a/src/trans/codegen.cpp +++ b/src/trans/codegen.cpp @@ -63,16 +63,27 @@ void Trans_Codegen(const ::std::string& outfile, const ::HIR::Crate& crate, cons // 3. Emit statics for(const auto& ent : list.m_statics) { - DEBUG("STATIC " << ent.first); + DEBUG("STATIC proto " << ent.first); assert(ent.second->ptr); const auto& stat = *ent.second->ptr; - if( stat.m_value_res.is_Invalid() ) + if( ! stat.m_value_res.is_Invalid() ) { - codegen->emit_static_ext(ent.first, stat, ent.second->pp); + codegen->emit_static_proto(ent.first, stat, ent.second->pp); } else { + codegen->emit_static_ext(ent.first, stat, ent.second->pp); + } + } + for(const auto& ent : list.m_statics) + { + DEBUG("STATIC " << ent.first); + assert(ent.second->ptr); + const auto& stat = *ent.second->ptr; + + if( ! stat.m_value_res.is_Invalid() ) + { codegen->emit_static_local(ent.first, stat, ent.second->pp); } } diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index faa18521..86d4c839 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -529,6 +529,20 @@ namespace { m_mir_res = nullptr; } + void emit_static_proto(const ::HIR::Path& p, const ::HIR::Static& item, const Trans_Params& params) override + { + ::MIR::TypeResolve top_mir_res { sp, m_resolve, FMT_CB(ss, ss << "static " << p;), ::HIR::TypeRef(), {}, *(::MIR::Function*)nullptr }; + m_mir_res = &top_mir_res; + + TRACE_FUNCTION_F(p); + auto type = params.monomorph(m_resolve, item.m_type); + emit_ctype( type, FMT_CB(ss, ss << Trans_Mangle(p);) ); + m_of << ";"; + m_of << "\t// static " << p << " : " << type; + m_of << "\n"; + + m_mir_res = nullptr; + } void emit_static_local(const ::HIR::Path& p, const ::HIR::Static& item, const Trans_Params& params) override { ::MIR::TypeResolve top_mir_res { sp, m_resolve, FMT_CB(ss, ss << "static " << p;), ::HIR::TypeRef(), {}, *(::MIR::Function*)nullptr }; |