From 23ec796fe6f24368bb6c25c3506b6196254e2887 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 2 Jan 2017 15:07:55 +0800 Subject: Codegen C - Prototype definitions for statics --- src/trans/codegen.cpp | 17 ++++++++++++++--- src/trans/codegen_c.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src') 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,15 +63,26 @@ 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 }; -- cgit v1.2.3