1
1
// This file contains many unnecesary morphize calls.
2
2
use crate :: cil_op:: { CILOp , FieldDescriptor } ;
3
- use crate :: r#type:: DotnetTypeRef ;
3
+ use crate :: r#type:: { DotnetTypeRef , Type } ;
4
4
use crate :: utilis:: field_name;
5
5
use rustc_middle:: mir:: { Place , PlaceElem } ;
6
6
use rustc_middle:: ty:: { Instance , IntTy , Ty , TyCtxt , TyKind , UintTy } ;
@@ -25,11 +25,22 @@ fn pointed_type(ty: PlaceTy) -> Ty {
25
25
fn body_ty_is_by_adress ( last_ty : & Ty ) -> bool {
26
26
match * last_ty. kind ( ) {
27
27
TyKind :: Int ( _) => false ,
28
+ TyKind :: Float ( _) => false ,
28
29
TyKind :: Uint ( _) => false ,
29
30
TyKind :: Adt ( _, _) => true ,
31
+ TyKind :: Array ( _, _) => true ,
32
+
30
33
TyKind :: Ref ( _region, _inner, _mut) => false ,
31
34
TyKind :: RawPtr ( _) => false ,
32
- _ => todo ! ( "TODO: body_ty_is_by_adress does not support type {last_ty:?}" ) ,
35
+ TyKind :: Bool => false ,
36
+ TyKind :: Char => false ,
37
+ //TODO: check if slices are handled propely
38
+ TyKind :: Slice ( _) => true ,
39
+ TyKind :: Str => true ,
40
+ _ => todo ! (
41
+ "TODO: body_ty_is_by_adress does not support type {last_ty:?} kind:{kind:?}" ,
42
+ kind = last_ty. kind( )
43
+ ) ,
33
44
}
34
45
}
35
46
fn local_get ( local : usize , method : & rustc_middle:: mir:: Body ) -> CILOp {
@@ -119,6 +130,33 @@ fn place_elem_get<'a>(
119
130
//todo!("Can't get fields of enum variants yet!");
120
131
}
121
132
} ,
133
+ PlaceElem :: Index ( index) => {
134
+ let mut ops = vec ! [ crate :: place:: local_adress(
135
+ index. as_usize( ) ,
136
+ ctx. optimized_mir( method_instance. def_id( ) ) ,
137
+ ) ] ;
138
+ let curr_ty = curr_type. as_ty ( ) . expect ( "Can't index into enum!" ) ;
139
+ let tpe = Type :: from_ty ( curr_ty, ctx) ;
140
+ let class = if let Type :: DotnetType ( dotnet) = & tpe {
141
+ dotnet
142
+ } else {
143
+ panic ! ( "Can't index into type {tpe:?}" ) ;
144
+ } ;
145
+ let index_ty = Type :: USize ;
146
+ let element_ty = crate :: r#type:: element_type ( curr_ty) ;
147
+
148
+ let signature = crate :: function_sig:: FnSig :: new (
149
+ & [ tpe. clone ( ) , index_ty] ,
150
+ & Type :: from_ty ( element_ty, ctx) ,
151
+ ) ;
152
+ ops. push ( CILOp :: Call ( crate :: cil_op:: CallSite :: boxed (
153
+ Some ( class. as_ref ( ) . clone ( ) ) ,
154
+ "get_Item" . into ( ) ,
155
+ signature,
156
+ false ,
157
+ ) ) ) ;
158
+ ops
159
+ }
122
160
_ => todo ! ( "Can't handle porojection {place_elem:?} in get" ) ,
123
161
}
124
162
}
@@ -228,6 +266,46 @@ fn place_elem_body<'ctx>(
228
266
let variant_type = PlaceTy :: EnumVariant ( curr_type, variant. as_u32 ( ) ) ;
229
267
( variant_type, vec ! [ CILOp :: LDFieldAdress ( field_desc) ] )
230
268
}
269
+ PlaceElem :: Index ( index) => {
270
+ let mut ops = vec ! [ crate :: place:: local_adress(
271
+ index. as_usize( ) ,
272
+ tyctx. optimized_mir( method_instance. def_id( ) ) ,
273
+ ) ] ;
274
+ let curr_ty = curr_type. as_ty ( ) . expect ( "Can't index into enum!" ) ;
275
+ let tpe = Type :: from_ty ( curr_ty, tyctx) ;
276
+ let class = if let Type :: DotnetType ( dotnet) = & tpe {
277
+ dotnet
278
+ } else {
279
+ panic ! ( "Can't index into type {tpe:?}" ) ;
280
+ } ;
281
+ let index_ty = Type :: USize ;
282
+ let element_ty = crate :: r#type:: element_type ( curr_ty) ;
283
+ if body_ty_is_by_adress ( & element_ty) {
284
+ let signature = crate :: function_sig:: FnSig :: new (
285
+ & [ tpe. clone ( ) , index_ty] ,
286
+ & Type :: Ptr ( Box :: new ( Type :: from_ty ( element_ty, tyctx) ) ) ,
287
+ ) ;
288
+ ops. push ( CILOp :: Call ( crate :: cil_op:: CallSite :: boxed (
289
+ Some ( class. as_ref ( ) . clone ( ) ) ,
290
+ "get_Adress" . into ( ) ,
291
+ signature,
292
+ false ,
293
+ ) ) ) ;
294
+ ( element_ty. into ( ) , ops)
295
+ } else {
296
+ let signature = crate :: function_sig:: FnSig :: new (
297
+ & [ tpe. clone ( ) , index_ty] ,
298
+ & Type :: from_ty ( element_ty, tyctx) ,
299
+ ) ;
300
+ ops. push ( CILOp :: Call ( crate :: cil_op:: CallSite :: boxed (
301
+ Some ( class. as_ref ( ) . clone ( ) ) ,
302
+ "get_Item" . into ( ) ,
303
+ signature,
304
+ false ,
305
+ ) ) ) ;
306
+ ( element_ty. into ( ) , ops)
307
+ }
308
+ }
231
309
_ => todo ! ( "Can't handle porojection {place_elem:?} in body" ) ,
232
310
}
233
311
}
0 commit comments