Univariant(ref st, _dro) => {
assert_eq!(discr, 0);
let contents = build_const_struct(ccx, st, vals);
- if st.packed {
- C_packed_struct(contents)
- } else {
- C_struct(contents)
- }
+ C_struct(contents, st.packed)
}
General(ref cases) => {
let case = &cases[discr];
let discr_ty = C_disr(ccx, discr);
let contents = build_const_struct(ccx, case,
~[discr_ty] + vals);
- C_struct(contents + &[padding(max_sz - case.size)])
+ C_struct(contents + &[padding(max_sz - case.size)], false)
}
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, _ } => {
if discr == nndiscr {
- C_struct(build_const_struct(ccx, nonnull, vals))
+ C_struct(build_const_struct(ccx, nonnull, vals), false)
} else {
assert_eq!(vals.len(), 0);
let vals = do nonnull.fields.iter().enumerate().map |(i, &ty)| {
let llty = type_of::sizing_type_of(ccx, ty);
if i == ptrfield { C_null(llty) } else { C_undef(llty) }
}.collect::<~[ValueRef]>();
- C_struct(build_const_struct(ccx, nonnull, vals))
+ C_struct(build_const_struct(ccx, nonnull, vals), false)
}
}
}
offset = target_offset;
}
let val = if is_undef(vals[i]) {
- let wrapped = C_struct([vals[i]]);
+ let wrapped = C_struct([vals[i]], false);
assert!(!is_undef(wrapped));
wrapped
} else {
let elt = C_struct([
C_estr_slice(ccx, *key),
v_ptr
- ]);
+ ], false);
elts.push(elt);
}
unsafe {
p2i(ccx, mod_map),
// byte size of the module map array, an entry consists of two integers
C_int(ccx, ((mod_count * mod_struct_size) as int))
- ]),
+ ], false),
C_struct([
p2i(ccx, vec_elements),
// byte size of the subcrates array, an entry consists of an integer
C_int(ccx, (subcrates.len() * llsize_of_alloc(ccx, ccx.int_type)) as int)
- ])
- ]));
+ ], false)
+ ], false));
}
}
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate));
- let llconst = C_struct([llmeta]);
+ let llconst = C_struct([llmeta], false);
let mut llglobal = do "rust_metadata".with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst).to_ref(), buf)
}
pub fn C_nil() -> ValueRef {
- return C_struct([]);
+ C_struct([], false)
}
pub fn C_bool(val: bool) -> ValueRef {
unsafe {
let len = s.len();
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), Type::i8p().to_ref());
- C_struct([cs, C_uint(cx, len)])
+ C_struct([cs, C_uint(cx, len)], false)
}
}
}
}
-pub fn C_struct(elts: &[ValueRef]) -> ValueRef {
+pub fn C_struct(elts: &[ValueRef], packed: bool) -> ValueRef {
unsafe {
do elts.as_imm_buf |ptr, len| {
- llvm::LLVMConstStructInContext(base::task_llcx(), ptr, len as c_uint, False)
- }
- }
-}
-
-pub fn C_packed_struct(elts: &[ValueRef]) -> ValueRef {
- unsafe {
- do elts.as_imm_buf |ptr, len| {
- llvm::LLVMConstStructInContext(base::task_llcx(), ptr, len as c_uint, True)
+ llvm::LLVMConstStructInContext(base::task_llcx(), ptr, len as c_uint, packed as Bool)
}
}
}
let (vs, inlineable) = vec::unzip(es.iter().map(|e| const_expr(cx, *e)));
// If the vector contains enums, an LLVM array won't work.
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
- C_struct(vs)
+ C_struct(vs, false)
} else {
C_array(llunitty, vs)
};
match adjustment {
None => { }
Some(@ty::AutoAddEnv(ty::re_static, ast::BorrowedSigil)) => {
- llconst = C_struct([llconst, C_null(Type::opaque_box(cx).ptr_to())])
+ llconst = C_struct([llconst, C_null(Type::opaque_box(cx).ptr_to())], false)
}
Some(@ty::AutoAddEnv(ref r, ref s)) => {
cx.sess.span_bug(e.span, format!("unexpected static function: \
match ty::get(ty).sty {
ty::ty_evec(_, ty::vstore_fixed(*)) => {
let size = machine::llsize_of(cx, val_ty(llconst));
- llconst = C_struct([llptr, size]);
+ llconst = C_struct([llptr, size], false);
}
_ => {}
}
llvm::LLVMSetGlobalConstant(gv, True);
SetLinkage(gv, PrivateLinkage);
let p = const_ptrcast(cx, gv, llunitty);
- (C_struct([p, sz]), false)
+ (C_struct([p, sz], false), false)
}
_ => cx.sess.span_bug(e.span, "bad const-slice expr")
}
};
let vs = vec::from_elem(n, const_expr(cx, elem).first());
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
- C_struct(vs)
+ C_struct(vs, false)
} else {
C_array(llunitty, vs)
};
components.push(ptr)
}
- let tbl = C_struct(components);
+ let tbl = C_struct(components, false);
let sym = token::gensym("vtable");
let vt_gvar = do format!("vtable{}", sym).with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)