summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-01-11 21:47:01 +0800
committerJohn Hodge <tpg@mutabah.net>2017-01-11 21:47:01 +0800
commit9204a6b3958a56a6624b4752047ed941f54ab5cc (patch)
tree8cba811f2e7fc812dffa1eb44ef97938b63ba02e /src
parentd8e1c31c2158f60ce19a09723904ab0b71f7c27a (diff)
downloadmrust-9204a6b3958a56a6624b4752047ed941f54ab5cc.tar.gz
HIR - Static link_name (partial support)
Diffstat (limited to 'src')
-rw-r--r--src/hir/dump.cpp2
-rw-r--r--src/hir/from_ast.cpp7
-rw-r--r--src/trans/codegen_c.cpp4
3 files changed, 13 insertions, 0 deletions
diff --git a/src/hir/dump.cpp b/src/hir/dump.cpp
index 4d9380d8..f00efcd5 100644
--- a/src/hir/dump.cpp
+++ b/src/hir/dump.cpp
@@ -238,6 +238,8 @@ namespace {
}
void visit_static(::HIR::ItemPath p, ::HIR::Static& item) override
{
+ if( item.m_linkage.name != "" )
+ m_os << indent() << "#[link_name=\"" << item.m_linkage.name << "\"]\n";
if( item.m_value )
{
m_os << indent() << "static " << p.get_name() << ": " << item.m_type << " = " << item.m_value_res << ";\n";
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 927239ff..834b0e95 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1224,6 +1224,13 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
}));
else {
::HIR::Linkage linkage;
+
+ // If there's no code, demangle the name (TODO: By ABI) and set linkage.
+ if( linkage.name == "" && ! e.value().is_valid() )
+ {
+ linkage.name = item.name;
+ }
+
_add_mod_val_item(mod, item.name, item.is_pub, ::HIR::ValueItem::make_Static(::HIR::Static {
mv$(linkage),
(e.s_class() == ::AST::Static::MUT),
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index 2d2eca27..65c64c3e 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -618,6 +618,10 @@ namespace {
auto type = params.monomorph(m_resolve, item.m_type);
m_of << "extern ";
emit_ctype( type, FMT_CB(ss, ss << Trans_Mangle(p);) );
+ if( item.m_linkage.name != "" )
+ {
+ m_of << " asm(\"" << item.m_linkage.name << "\")";
+ }
m_of << ";";
m_of << "\t// static " << p << " : " << type;
m_of << "\n";