Skip to content

Commit 5571ca9

Browse files
committed
Break out const_addr_of.
1 parent a347e9d commit 5571ca9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ pub fn const_vec(cx: @CrateContext, e: @ast::expr, es: &[@ast::expr])
9494
}
9595
}
9696

97+
fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
98+
unsafe {
99+
let gv = do str::as_c_str("const") |name| {
100+
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
101+
};
102+
llvm::LLVMSetInitializer(gv, cv);
103+
llvm::LLVMSetGlobalConstant(gv, True);
104+
gv
105+
}
106+
}
107+
97108
pub fn const_deref(cx: @CrateContext, v: ValueRef) -> ValueRef {
98109
unsafe {
99110
let v = match cx.const_globals.find(&(v as int)) {
@@ -355,13 +366,7 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
355366
}
356367
}
357368
ast::expr_addr_of(ast::m_imm, sub) => {
358-
let cv = const_expr(cx, sub);
359-
let gv = do str::as_c_str("const") |name| {
360-
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
361-
};
362-
llvm::LLVMSetInitializer(gv, cv);
363-
llvm::LLVMSetGlobalConstant(gv, True);
364-
gv
369+
const_addr_of(cx, const_expr(cx, sub))
365370
}
366371
ast::expr_tup(es) => {
367372
let ety = ty::expr_ty(cx.tcx, e);

0 commit comments

Comments
 (0)