()
| 360 | |
| 361 | #[test] |
| 362 | fn replace_with_imm_method() { |
| 363 | // Replacing an instruction with a generated `*_imm` convenience method |
| 364 | // (here `icmp_imm`) must materialize its `iconst` immediately before the |
| 365 | // replaced instruction via `ReplaceBuilder::build_aux_inst`. |
| 366 | let mut func = Function::new(); |
| 367 | let block0 = func.dfg.make_block(); |
| 368 | let arg0 = func.dfg.append_block_param(block0, I32); |
| 369 | { |
| 370 | let mut pos = FuncCursor::new(&mut func); |
| 371 | pos.insert_block(block0); |
| 372 | // A placeholder `icmp` (also `i8`-typed) to be replaced. |
| 373 | pos.ins().icmp(IntCC::Equal, arg0, arg0); |
| 374 | } |
| 375 | |
| 376 | let inst = func.layout.last_inst(block0).unwrap(); |
| 377 | assert_eq!(func.dfg.insts[inst].opcode(), Opcode::Icmp); |
| 378 | |
| 379 | let result = func.replace(inst).icmp_imm(IntCC::Equal, arg0, 42); |
| 380 | |
| 381 | // The replaced instruction is still an `icmp`, now comparing against a |
| 382 | // freshly materialized constant. |
| 383 | assert_eq!(func.dfg.insts[inst].opcode(), Opcode::Icmp); |
| 384 | assert_eq!(func.dfg.value_type(result), I8); |
| 385 | |
| 386 | // An `iconst.i32 42` was inserted immediately before the replaced inst. |
| 387 | let iconst = func.layout.prev_inst(inst).unwrap(); |
| 388 | assert_eq!(func.dfg.insts[iconst].opcode(), Opcode::Iconst); |
| 389 | let iconst_result = func.dfg.first_result(iconst); |
| 390 | assert_eq!(func.dfg.value_type(iconst_result), I32); |
| 391 | assert_eq!(func.dfg.inst_args(inst), &[arg0, iconst_result]); |
| 392 | } |
| 393 | |
| 394 | #[test] |
| 395 | #[should_panic] |
nothing calls this directly
no test coverage detected