Generates an instruction(`iconst`/`fconst`/etc...) to introduce a constant value
(&mut self, builder: &mut FunctionBuilder, ty: Type)
| 1401 | |
| 1402 | /// Generates an instruction(`iconst`/`fconst`/etc...) to introduce a constant value |
| 1403 | fn generate_const(&mut self, builder: &mut FunctionBuilder, ty: Type) -> Result<Value> { |
| 1404 | Ok(match self.u.datavalue(ty)? { |
| 1405 | DataValue::I8(i) => builder.ins().iconst(ty, i as u8 as i64), |
| 1406 | DataValue::I16(i) => builder.ins().iconst(ty, i as u16 as i64), |
| 1407 | DataValue::I32(i) => builder.ins().iconst(ty, i as u32 as i64), |
| 1408 | DataValue::I64(i) => builder.ins().iconst(ty, i), |
| 1409 | DataValue::I128(i) => { |
| 1410 | let hi = builder.ins().iconst(I64, (i >> 64) as i64); |
| 1411 | let lo = builder.ins().iconst(I64, i as i64); |
| 1412 | builder.ins().iconcat(lo, hi) |
| 1413 | } |
| 1414 | DataValue::F16(f) => builder.ins().f16const(f), |
| 1415 | DataValue::F32(f) => builder.ins().f32const(f), |
| 1416 | DataValue::F64(f) => builder.ins().f64const(f), |
| 1417 | DataValue::F128(f) => { |
| 1418 | let handle = builder.func.dfg.constants.insert(f.into()); |
| 1419 | builder.ins().f128const(handle) |
| 1420 | } |
| 1421 | DataValue::V128(bytes) => { |
| 1422 | let data = bytes.to_vec().into(); |
| 1423 | let handle = builder.func.dfg.constants.insert(data); |
| 1424 | builder.ins().vconst(ty, handle) |
| 1425 | } |
| 1426 | _ => unimplemented!(), |
| 1427 | }) |
| 1428 | } |
| 1429 | |
| 1430 | /// Chooses a random block which can be targeted by a jump / branch. |
| 1431 | /// This means any block that is not the first block. |