@@ -33,6 +33,12 @@ pub(crate) enum LocalPlacement {
33
33
Var ( u32 ) ,
34
34
}
35
35
impl CLRMethod {
36
+ pub ( crate ) fn get_type_of_local ( & self , local : u32 ) ->& VariableType {
37
+ match self . local_id_placement ( local) {
38
+ LocalPlacement :: Arg ( index) =>& self . sig . inputs [ index as usize ] ,
39
+ LocalPlacement :: Var ( index) =>& self . locals [ index as usize ] ,
40
+ }
41
+ }
36
42
pub ( crate ) fn extend_ops ( & mut self , ops : & [ BaseIR ] ) {
37
43
self . ops . extend ( ops. iter ( ) . map ( |ref_op| ref_op. clone ( ) ) )
38
44
}
@@ -188,35 +194,6 @@ impl CLRMethod {
188
194
LocalPlacement :: Var ( var_id) => BaseIR :: LDLoc ( var_id) ,
189
195
} )
190
196
}
191
- fn store ( & mut self , place : Place ) {
192
- if place. projection . is_empty ( ) {
193
- let local: u32 = place. local . into ( ) ;
194
- self . ops . push ( match self . local_id_placement ( local) {
195
- LocalPlacement :: Arg ( arg_id) => BaseIR :: STArg ( arg_id) ,
196
- LocalPlacement :: Var ( var_id) => BaseIR :: STLoc ( var_id) ,
197
- } )
198
- } else {
199
- // First, travel trough almost every element besides the last one!
200
- if place. projection . len ( ) > 1 {
201
- panic ! ( "Unhandled Non-trivial store!" ) ;
202
- for _projection_mod in & place. projection [ ..( place. projection . len ( ) - 1 ) ] { }
203
- }
204
- // The value or address of the last one should be on top of the stack.
205
- let last = place. projection [ place. projection . len ( ) - 1 ] ;
206
- match last {
207
- PlaceElem :: Deref => {
208
- let local: u32 = place. local . into ( ) ;
209
- self . ops . push ( match self . local_id_placement ( local) {
210
- LocalPlacement :: Arg ( arg_id) => BaseIR :: LDArg ( arg_id) ,
211
- LocalPlacement :: Var ( var_id) => BaseIR :: LDLoc ( var_id) ,
212
- } ) ;
213
- //TODO: use type info!
214
- self . ops . push ( BaseIR :: STIInd ( 4 ) ) ;
215
- }
216
- _ => todo ! ( "Unhandled placement!" ) ,
217
- }
218
- }
219
- }
220
197
fn process_constant ( & mut self , constant : ConstantKind ) {
221
198
match constant {
222
199
ConstantKind :: Val ( value, r#type) => match value {
@@ -246,89 +223,6 @@ impl CLRMethod {
246
223
}
247
224
}
248
225
}
249
- fn convert ( & mut self , src : & VariableType , dest : & VariableType ) {
250
- match ( src, dest) {
251
- (
252
- VariableType :: F32
253
- | VariableType :: I8
254
- | VariableType :: I16
255
- | VariableType :: I32
256
- | VariableType :: U8
257
- | VariableType :: U16
258
- | VariableType :: U32 ,
259
- VariableType :: I32 ,
260
- ) => self . ops . push ( BaseIR :: ConvI32 ) ,
261
- (
262
- VariableType :: F64
263
- | VariableType :: I64
264
- | VariableType :: U64
265
- | VariableType :: ISize
266
- | VariableType :: USize ,
267
- VariableType :: I32 ,
268
- ) => self . ops . push ( BaseIR :: ConvI32Checked ) ,
269
- ( VariableType :: F32 , VariableType :: I8 ) => self . ops . push ( BaseIR :: ConvI8 ) ,
270
- ( VariableType :: I32 , VariableType :: F32 ) => self . ops . push ( BaseIR :: ConvF32 ) ,
271
- _ => todo ! ( "Can't convert type {src:?} to {dest:?}" ) ,
272
- }
273
- }
274
- // Makes so the top of the stack is the value of RValue
275
- fn process_rvalue < ' ctx > (
276
- & mut self ,
277
- rvalue : & Rvalue < ' ctx > ,
278
- body : & Body < ' ctx > ,
279
- tyctx : & TyCtxt < ' ctx > ,
280
- ) {
281
- match rvalue {
282
- Rvalue :: Use ( operand) => self . process_operand ( operand) ,
283
- Rvalue :: BinaryOp ( binop, operands) => {
284
- let ( a, b) : ( _ , _ ) = ( & operands. 0 , & operands. 1 ) ;
285
- self . process_operand ( a) ;
286
- self . process_operand ( b) ;
287
- self . ops . push ( match binop {
288
- BinOp :: Add => BaseIR :: Add ,
289
- BinOp :: Sub => BaseIR :: Sub ,
290
- BinOp :: Mul => BaseIR :: Mul ,
291
- BinOp :: Shl => BaseIR :: Shl ,
292
- BinOp :: Shr => BaseIR :: Shr ,
293
- BinOp :: Eq => BaseIR :: Eq ,
294
- BinOp :: Ne => BaseIR :: NEq ,
295
- BinOp :: Gt => BaseIR :: Gt ,
296
- BinOp :: Rem => BaseIR :: Rem ,
297
- BinOp :: BitXor => BaseIR :: Xor ,
298
- BinOp :: BitOr => BaseIR :: Or ,
299
- BinOp :: BitAnd => BaseIR :: And ,
300
- BinOp :: Div => BaseIR :: Div ,
301
- _ => todo ! ( "Unknown binop:{binop:?}" ) ,
302
- } ) ;
303
- }
304
- Rvalue :: Cast (
305
- CastKind :: IntToInt
306
- | CastKind :: FloatToFloat
307
- | CastKind :: FloatToInt
308
- | CastKind :: IntToFloat ,
309
- operand,
310
- target,
311
- ) => {
312
- self . process_operand ( operand) ;
313
- self . convert (
314
- & VariableType :: from_ty ( operand. ty ( body, * tyctx) ) ,
315
- & VariableType :: from_ty ( * target) ,
316
- ) ;
317
- }
318
- Rvalue :: Aggregate ( kind, operands) => {
319
- match kind. as_ref ( ) {
320
- AggregateKind :: Adt ( def_id, variant_idx, subst_ref, utai, fidx) => {
321
- //let (def_id,variant_idx,subst_ref,utai,fidx) = *adt;
322
- panic ! ( "def_id:{def_id:?},variant_idx:{variant_idx:?},subst_ref:{subst_ref:?},utai:{utai:?},fidx:{fidx:?}" ) ;
323
- }
324
- _ => todo ! (
325
- "Can't yet handle the aggregate of kind {kind:?} and operands:{operands:?}"
326
- ) ,
327
- }
328
- }
329
- _ => todo ! ( "Can't yet handle a rvalue of type {rvalue:?}" ) ,
330
- }
331
- }
332
226
pub ( crate ) fn add_statement < ' ctx > (
333
227
& mut self ,
334
228
statement : & Statement < ' ctx > ,
@@ -339,12 +233,8 @@ impl CLRMethod {
339
233
match & statement. kind {
340
234
StatementKind :: Assign ( asign_box) => {
341
235
let ( place, rvalue) = ( asign_box. 0 , & asign_box. 1 ) ;
342
- //self.process_rvalue(rvalue, body, tyctx);
343
236
let rvalue = RValue :: from_rvalue ( rvalue, body, tyctx, self ) ;
344
- //self.ops.extend(rvalue.get_ops().iter().map(|op|op.clone()));
345
237
AsigmentTarget :: from_placement ( place, & self ) . finalize ( rvalue, self ) ;
346
- //self.store(place);
347
- //panic!("place:{place:?},rvalue:{rvalue:?}");
348
238
}
349
239
StatementKind :: StorageLive ( local) => {
350
240
self . var_live ( ( * local) . into ( ) ) ;
0 commit comments