@@ -76,6 +76,38 @@ fn create_const_adt_from_bytes<'ctx>(
76
76
creator_ops. push ( CILOp :: FreeTMPLocal ) ;
77
77
creator_ops
78
78
}
79
+ AdtKind :: Union => {
80
+ let curr_offset = 0 ;
81
+ let cil_ty = crate :: utilis:: monomorphize ( & method_instance, ty, tyctx) ;
82
+ let cil_ty = tycache. type_from_cache ( cil_ty, tyctx, Some ( method_instance) ) ;
83
+ let dotnet_ty = cil_ty. as_dotnet ( ) . expect ( "ADT must be a value type!" ) ;
84
+ let mut creator_ops = vec ! [ CILOp :: NewTMPLocal ( cil_ty. clone( ) . into( ) ) ] ;
85
+ for field in adt_def. all_fields ( ) {
86
+ let ftype = field. ty ( tyctx, subst) ;
87
+ let sizeof = crate :: utilis:: compiletime_sizeof ( ftype, tyctx) ;
88
+ let field_bytes = & bytes[ curr_offset..( curr_offset + sizeof) ] ;
89
+ let field_ops =
90
+ create_const_from_slice ( ftype, tyctx, field_bytes, method_instance, tycache) ;
91
+ creator_ops. push ( CILOp :: LoadAddresOfTMPLocal ) ;
92
+ creator_ops. extend ( field_ops) ;
93
+ let cil_ftype =
94
+ tycache. type_from_cache ( field. ty ( tyctx, subst) , tyctx, Some ( method_instance) ) ;
95
+ let name = field. name . to_string ( ) ;
96
+ let name = crate :: r#type:: escape_field_name ( & name) ;
97
+ creator_ops. push ( CILOp :: STField ( crate :: cil:: FieldDescriptor :: boxed (
98
+ dotnet_ty. clone ( ) ,
99
+ cil_ftype,
100
+ name,
101
+ ) ) ) ;
102
+ rustc_middle:: ty:: print:: with_no_trimmed_paths! { println!(
103
+ "Const field {name} of type {ftype} with bytes {field_bytes:?}" ,
104
+ name = field. name
105
+ ) } ;
106
+ }
107
+ creator_ops. push ( CILOp :: LoadTMPLocal ) ;
108
+ creator_ops. push ( CILOp :: FreeTMPLocal ) ;
109
+ creator_ops
110
+ }
79
111
AdtKind :: Enum => {
80
112
let variant_size = crate :: utilis:: enum_tag_size ( adt_def. variants ( ) . len ( ) as u64 ) ;
81
113
// This will need to be mutable in order to handle enum fields.
@@ -487,6 +519,31 @@ fn load_const_scalar<'ctx>(
487
519
CILOp :: FreeTMPLocal ,
488
520
]
489
521
}
522
+ AdtKind :: Struct => {
523
+ //assert!(adt_def.size() < 16);
524
+ let low = ( scalar_u128 & u128:: from ( u64:: MAX ) ) as u64 ;
525
+ let high = ( scalar_u128 << 64 ) as u64 ;
526
+ let low = i64:: from_ne_bytes ( low. to_ne_bytes ( ) ) ;
527
+ let high = i64:: from_ne_bytes ( high. to_ne_bytes ( ) ) ;
528
+ let i128_class = DotnetTypeRef :: new ( Some ( "System.Runtime" ) , "System.Int128" ) ;
529
+ let ctor_sig =
530
+ crate :: function_sig:: FnSig :: new ( & [ Type :: U64 , Type :: U64 ] , & Type :: Void ) ;
531
+ vec ! [
532
+ CILOp :: LdcI64 ( high) ,
533
+ CILOp :: LdcI64 ( low) ,
534
+ CILOp :: NewObj ( CallSite :: boxed(
535
+ Some ( i128_class) ,
536
+ ".ctor" . into( ) ,
537
+ ctor_sig,
538
+ true ,
539
+ ) ) ,
540
+ CILOp :: NewTMPLocal ( Type :: I128 . into( ) ) ,
541
+ CILOp :: SetTMPLocal ,
542
+ CILOp :: LoadAddresOfTMPLocal ,
543
+ CILOp :: LdObj ( tpe. into( ) ) ,
544
+ CILOp :: FreeTMPLocal ,
545
+ ]
546
+ }
490
547
_ => todo ! ( "Can't load const ADT scalars of type {scalar_type:?}" ) ,
491
548
} ,
492
549
TyKind :: Char => {
@@ -536,11 +593,11 @@ pub fn load_const_int(value: u128, int_type: &IntTy) -> Vec<CILOp> {
536
593
let low = i64:: from_ne_bytes ( low. to_ne_bytes ( ) ) ;
537
594
let high = i64:: from_ne_bytes ( high. to_ne_bytes ( ) ) ;
538
595
let i128_class = DotnetTypeRef :: new ( Some ( "System.Runtime" ) , "System.Int128" ) ;
539
- let ctor_sig = crate :: function_sig:: FnSig :: new ( & [ Type :: U64 , Type :: U64 ] , & Type :: I128 ) ;
596
+ let ctor_sig = crate :: function_sig:: FnSig :: new ( & [ Type :: U64 , Type :: U64 ] , & Type :: Void ) ;
540
597
vec ! [
541
598
CILOp :: LdcI64 ( high) ,
542
599
CILOp :: LdcI64 ( low) ,
543
- CILOp :: Call ( CallSite :: boxed(
600
+ CILOp :: NewObj ( CallSite :: boxed(
544
601
Some ( i128_class) ,
545
602
".ctor" . into( ) ,
546
603
ctor_sig,
@@ -578,11 +635,11 @@ pub fn load_const_uint(value: u128, int_type: &UintTy) -> Vec<CILOp> {
578
635
let low = i64:: from_ne_bytes ( low. to_ne_bytes ( ) ) ;
579
636
let high = i64:: from_ne_bytes ( high. to_ne_bytes ( ) ) ;
580
637
let i128_class = DotnetTypeRef :: new ( Some ( "System.Runtime" ) , "System.UInt128" ) ;
581
- let ctor_sig = crate :: function_sig:: FnSig :: new ( & [ Type :: U64 , Type :: U64 ] , & Type :: U128 ) ;
638
+ let ctor_sig = crate :: function_sig:: FnSig :: new ( & [ Type :: U64 , Type :: U64 ] , & Type :: Void ) ;
582
639
vec ! [
583
640
CILOp :: LdcI64 ( high) ,
584
641
CILOp :: LdcI64 ( low) ,
585
- CILOp :: Call ( CallSite :: boxed(
642
+ CILOp :: NewObj ( CallSite :: boxed(
586
643
Some ( i128_class) ,
587
644
".ctor" . into( ) ,
588
645
ctor_sig,
0 commit comments