From 78bcfe28f2d01cd19087b0a29871742a729e4e49 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 18 Mar 2011 16:22:59 -0700 Subject: rustc: Create global variable constants during the collection phase --- src/comp/middle/trans.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/comp/middle') diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 718f152b..657af5a1 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)) { -- cgit v1.2.3