Skip to content

Commit 86309ed

Browse files
committed
rustc: Write tag variant discriminants into the crate as integer constants
1 parent a172f5a commit 86309ed

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4609,12 +4609,26 @@ fn trans_constant(&@crate_ctxt cx, @ast.item it) -> @crate_ctxt {
46094609
auto n_variants = _vec.len[ast.variant](variants);
46104610
while (i < n_variants) {
46114611
auto variant = variants.(i);
4612+
4613+
auto discrim_val = C_int(i as int);
4614+
4615+
// FIXME: better name.
4616+
auto discrim_gvar = llvm.LLVMAddGlobal(cx.llmod, T_int(),
4617+
_str.buf("tag_discrim"));
4618+
4619+
// FIXME: Eventually we do want to export these, but we need
4620+
// to figure out what name they get first!
4621+
llvm.LLVMSetInitializer(discrim_gvar, discrim_val);
4622+
llvm.LLVMSetGlobalConstant(discrim_gvar, True);
4623+
llvm.LLVMSetLinkage(discrim_gvar, lib.llvm.LLVMPrivateLinkage
4624+
as llvm.Linkage);
4625+
46124626
if (_vec.len[ast.variant_arg](variant.args) == 0u) {
46134627
// Nullary tags become constants. (N-ary tags are treated
46144628
// as functions and generated later.)
46154629

46164630
auto union_val = C_zero_byte_arr(info.size as uint);
4617-
auto val = C_struct(vec(C_int(i as int), union_val));
4631+
auto val = C_struct(vec(discrim_val, union_val));
46184632

46194633
// FIXME: better name
46204634
auto gvar = llvm.LLVMAddGlobal(cx.llmod, val_ty(val),

0 commit comments

Comments
 (0)