summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-01-02 15:07:55 +0800
committerJohn Hodge <tpg@mutabah.net>2017-01-02 15:07:55 +0800
commit23ec796fe6f24368bb6c25c3506b6196254e2887 (patch)
treea8c31840f84b6694a4805ea2b6f15fe388af3cbc
parent41862469faf6891d3d9e3a4f2f2aa6a7d5f53193 (diff)
downloadmrust-23ec796fe6f24368bb6c25c3506b6196254e2887.tar.gz
Codegen C - Prototype definitions for statics
-rw-r--r--src/trans/codegen.cpp17
-rw-r--r--src/trans/codegen_c.cpp14
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 };