pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, r: &Repr<'tcx>, discr: Disr,
                             vals: &[ValueRef]) -> ValueRef {
    match *r {
        CEnum(ity, min, max) => {
            assert_eq!(vals.len(), 0);
            assert_discr_in_range(ity, min, max, discr);
            C_integral(ll_inttype(ccx, ity), discr.0, true)
        }
        General(ity, ref cases) => {
            let case = &cases[discr.0 as usize];
            let (max_sz, _) = union_size_and_align(&cases[..]);
            let lldiscr = C_integral(ll_inttype(ccx, ity), discr.0 as u64, true);
            let mut f = vec![lldiscr];
            f.extend_from_slice(vals);
            let mut contents = build_const_struct(ccx, case, &f[..]);
            contents.extend_from_slice(&[padding(ccx, max_sz - case.size)]);
            C_struct(ccx, &contents[..], false)
        }
        UntaggedUnion(ref un) => {
            assert_eq!(discr, Disr(0));
            let contents = build_const_union(ccx, un, vals[0]);
            C_struct(ccx, &contents, un.packed)
        }
        Univariant(ref st) => {
            assert_eq!(discr, Disr(0));
            let contents = build_const_struct(ccx, st, vals);
            C_struct(ccx, &contents[..], st.packed)
        }
        RawNullablePointer { nndiscr, nnty, .. } => {
            if discr == nndiscr {
                assert_eq!(vals.len(), 1);
                vals[0]
            } else {
                C_null(type_of::sizing_type_of(ccx, nnty))
            }
        }
        StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
            if discr == nndiscr {
                C_struct(ccx, &build_const_struct(ccx,
                                                 nonnull,
                                                 vals),
                         false)
            } else {
                let vals = nonnull.fields.iter().map(|&ty| {
                    // Always use null even if it's not the `discrfield`th
                    // field; see #8506.
                    C_null(type_of::sizing_type_of(ccx, ty))
                }).collect::<Vec<ValueRef>>();
                C_struct(ccx, &build_const_struct(ccx,
                                                 nonnull,
                                                 &vals[..]),
                         false)
            }
        }
    }
}
/// Construct a constant value, suitable for initializing a
/// GlobalVariable, given a case and constant values for its fields.
/// Note that this may have a different LLVM type (and different
/// alignment!) from the representation's `type_of`, so it needs a
/// pointer cast before use.
///
/// The LLVM type system does not directly support unions, and only
/// pointers can be bitcast, so a constant (and, by extension, the
/// GlobalVariable initialized by it) will have a type that can vary
/// depending on which case of an enum it is.
///
/// To understand the alignment situation, consider `enum E { V64(u64),
/// V32(u32, u32) }` on Windows.  The type has 8-byte alignment to
/// accommodate the u64, but `V32(x, y)` would have LLVM type `{i32,
/// i32, i32}`, which is 4-byte aligned.
///
/// Currently the returned value has the same size as the type, but
/// this could be changed in the future to avoid allocating unnecessary
/// space after values of shorter-than-maximum cases.
Construct a constant value, suitable for initializing a
GlobalVariable, given a case and constant values for its fields.
Note that this may have a different LLVM type (and different
alignment!) from the representation's `type_of`, so it needs a
pointer cast before use.

The LLVM type system does not directly support unions, and only
pointers can be bitcast, so a constant (and, by extension, the
GlobalVariable initialized by it) will have a type that can vary
depending on which case of an enum it is.

To understand the alignment situation, consider `enum E { V64(u64),
V32(u32, u32) }` on Windows.  The type has 8-byte alignment to
accommodate the u64, but `V32(x, y)` would have LLVM type `{i32,
i32, i32}`, which is 4-byte aligned.

Currently the returned value has the same size as the type, but
this could be changed in the future to avoid allocating unnecessary
space after values of shorter-than-maximum cases.
Construct a constant value suitable for initializing a GlobalVariable given a case and constant values for its fields . Note that this may have a different LLVM type ( and different alignment! ) from the representation ' s ` type_of ` so it needs a pointer cast before use . The LLVM type system does not directly support unions and only pointers can be bitcast so a constant ( and by extension the GlobalVariable initialized by it ) will have a type that can vary depending on which case of an enum it is . To understand the alignment situation consider ` enum E { V64 ( u64 ) V32 ( u32 u32 ) } ` on Windows . The type has 8 - byte alignment to accommodate the u64 but ` V32 ( x y ) ` would have LLVM type ` { i32 i32 i32 } ` which is 4 - byte aligned . Currently the returned value has the same size as the type but this could be changed in the future to avoid allocating unnecessary space after values of shorter - than - maximum cases .
pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, r: &Repr<'tcx>, discr: Disr,
                             vals: &[ValueRef]) -> ValueRef {
    match *r {
        CEnum(ity, min, max) => {
            assert_eq!(vals.len(), 0);
            assert_discr_in_range(ity, min, max, discr);
            C_integral(ll_inttype(ccx, ity), discr.0, true)
        }
        General(ity, ref cases) => {
            let case = &cases[discr.0 as usize];
            let (max_sz, _) = union_size_and_align(&cases[..]);
            let lldiscr = C_integral(ll_inttype(ccx, ity), discr.0 as u64, true);
            let mut f = vec![lldiscr];
            f.extend_from_slice(vals);
            let mut contents = build_const_struct(ccx, case, &f[..]);
            contents.extend_from_slice(&[padding(ccx, max_sz - case.size)]);
            C_struct(ccx, &contents[..], false)
        }
        UntaggedUnion(ref un) => {
            assert_eq!(discr, Disr(0));
            let contents = build_const_union(ccx, un, vals[0]);
            C_struct(ccx, &contents, un.packed)
        }
        Univariant(ref st) => {
            assert_eq!(discr, Disr(0));
            let contents = build_const_struct(ccx, st, vals);
            C_struct(ccx, &contents[..], st.packed)
        }
        RawNullablePointer { nndiscr, nnty, .. } => {
            if discr == nndiscr {
                assert_eq!(vals.len(), 1);
                vals[0]
            } else {
                C_null(type_of::sizing_type_of(ccx, nnty))
            }
        }
        StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
            if discr == nndiscr {
                C_struct(ccx, &build_const_struct(ccx,
                                                 nonnull,
                                                 vals),
                         false)
            } else {
                let vals = nonnull.fields.iter().map(|&ty| {
                    // Always use null even if it's not the `discrfield`th
                    // field; see #8506.
                    C_null(type_of::sizing_type_of(ccx, ty))
                }).collect::<Vec<ValueRef>>();
                C_struct(ccx, &build_const_struct(ccx,
                                                 nonnull,
                                                 &vals[..]),
                         false)
            }
        }
    }
}
pub fn trans_const < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > , r : & Repr < ' tcx > , discr : Disr , vals : & [ ValueRef ] ) -> ValueRef { match * r { CEnum ( ity , min , max ) => { assert_eq ! ( vals len ( ) 0 ) ; assert_discr_in_range ( ity , min , max , discr ) ; C_integral ( ll_inttype ( ccx , ity ) , discr . 0 , true ) } General ( ity , ref cases ) => { let case = & cases [ discr . 0 as usize ] ; let ( max_sz , _ ) = union_size_and_align ( & cases [ .. ] ) ; let lldiscr = C_integral ( ll_inttype ( ccx , ity ) , discr . 0 as u64 , true ) ; let mut f = vec ! [ lldiscr ] ; f . extend_from_slice ( vals ) ; let mut contents = build_const_struct ( ccx , case , & f [ .. ] ) ; contents . extend_from_slice ( & [ padding ( ccx , max_sz - case . size ) ] ) ; C_struct ( ccx , & contents [ .. ] , false ) } UntaggedUnion ( ref un ) => { assert_eq ! ( discr Disr ( 0 ) ) ; let contents = build_const_union ( ccx , un , vals [ 0 ] ) ; C_struct ( ccx , & contents , un . packed ) } Univariant ( ref st ) => { assert_eq ! ( discr Disr ( 0 ) ) ; let contents = build_const_struct ( ccx , st , vals ) ; C_struct ( ccx , & contents [ .. ] , st . packed ) } RawNullablePointer { nndiscr , nnty , .. } => { if discr == nndiscr { assert_eq ! ( vals len ( ) 1 ) ; vals [ 0 ] } else { C_null ( type_of :: sizing_type_of ( ccx , nnty ) ) } } StructWrappedNullablePointer { ref nonnull , nndiscr , .. } => { if discr == nndiscr { C_struct ( ccx , & build_const_struct ( ccx , nonnull , vals ) , false ) } else { let vals = nonnull . fields . iter ( ) . map ( | & ty | { // Always use null even if it's not the `discrfield`th // field; see #8506. C_null ( type_of :: sizing_type_of ( ccx , ty ) ) } ) . collect :: < Vec < ValueRef > > ( ) ; C_struct ( ccx , & build_const_struct ( ccx , nonnull , & vals [ .. ] ) , false ) } } } }
Construct a constant value, suitable for initializing a
GlobalVariable, given a case and constant values for its fields.
Construct a constant value suitable for initializing a GlobalVariable given a case and constant values for its fields .
ccx
&CrateContext<'a, 'tcx>
r
&Repr<'tcx>
discr
Disr
vals
&[ValueRef]
ccx
&CrateContext<'a, 'tcx>
r
&Repr<'tcx>
discr
Disr
vals
&[ValueRef]