about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-03-18 16:22:59 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-03-18 16:24:01 -0700
commit78bcfe28f2d01cd19087b0a29871742a729e4e49 (patch)
tree7d43f82c401270054d31b46e7a398ca92988bab3 /src
parent37cc67fbfe9a7ebb7795f05713f1c08513ea19ba (diff)
downloadrust-78bcfe28f2d01cd19087b0a29871742a729e4e49.tar.gz
rust-78bcfe28f2d01cd19087b0a29871742a729e4e49.zip
rustc: Create global variable constants during the collection phase
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 718f152beff..657af5a1861 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -5277,19 +5277,12 @@ fn trans_const(@crate_ctxt cx, @ast.expr e,
                &ast.def_id cid, &ast.ann ann) {
     auto t = node_ann_type(cx, ann);
     auto v = trans_const_expr(cx, e);
-    if (ty.type_is_scalar(t)) {
-        // The scalars come back as 1st class LLVM vals
-        // which we have to stick into global constants.
-        auto g = llvm.LLVMAddGlobal(cx.llmod, val_ty(v),
-                                    _str.buf(cx.names.next(cx.path)));
-        llvm.LLVMSetInitializer(g, v);
-        llvm.LLVMSetGlobalConstant(g, True);
-        llvm.LLVMSetLinkage(g, lib.llvm.LLVMPrivateLinkage
-                            as llvm.Linkage);
-        cx.consts.insert(cid, g);
-    } else {
-        cx.consts.insert(cid, v);
-    }
+
+    // The scalars come back as 1st class LLVM vals
+    // which we have to stick into global constants.
+    auto g = cx.consts.get(cid);
+    llvm.LLVMSetInitializer(g, v);
+    llvm.LLVMSetGlobalConstant(g, True);
 }
 
 fn trans_item(@crate_ctxt cx, &ast.item item) {
@@ -5488,8 +5481,14 @@ fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
 fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
 
     alt (i.node) {
-        case (ast.item_const(?name, _, _, ?cid, _)) {
+        case (ast.item_const(?name, _, _, ?cid, ?ann)) {
+            auto typ = node_ann_type(cx, ann);
+            auto g = llvm.LLVMAddGlobal(cx.llmod, type_of(cx, typ),
+                                        _str.buf(cx.names.next(name)));
+            llvm.LLVMSetLinkage(g, lib.llvm.LLVMPrivateLinkage
+                                as llvm.Linkage);
             cx.items.insert(cid, i);
+            cx.consts.insert(cid, g);
         }
 
         case (ast.item_mod(?name, ?m, ?mid)) {