|
14 | 14 | */
|
15 | 15 | // See https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md
|
16 | 16 |
|
17 |
| -use std::mem::transmute; |
18 | 17 | use std::result;
|
19 | 18 |
|
20 | 19 | type Result<T> = result::Result<T, &'static str>;
|
@@ -251,6 +250,20 @@ pub struct RelocEntry {
|
251 | 250 | addend: Option<u32>,
|
252 | 251 | }
|
253 | 252 |
|
| 253 | +/// An IEEE binary32 immediate floating point value, represented as a u32 |
| 254 | +/// containing the bitpattern. |
| 255 | +/// |
| 256 | +/// All bit patterns are allowed. |
| 257 | +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 258 | +pub struct Ieee32(u32); |
| 259 | + |
| 260 | +/// An IEEE binary64 immediate floating point value, represented as a u64 |
| 261 | +/// containing the bitpattern. |
| 262 | +/// |
| 263 | +/// All bit patterns are allowed. |
| 264 | +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 265 | +pub struct Ieee64(u64); |
| 266 | + |
254 | 267 | /// Instructions as defined at https://webassembly.github.io/spec/binary/instructions.html
|
255 | 268 | #[derive(Debug)]
|
256 | 269 | pub enum Operator {
|
@@ -301,8 +314,8 @@ pub enum Operator {
|
301 | 314 | GrowMemory { reserved: u32 },
|
302 | 315 | I32Const { value: i32 },
|
303 | 316 | I64Const { value: i64 },
|
304 |
| - F32Const { value: f32 }, |
305 |
| - F64Const { value: f64 }, |
| 317 | + F32Const { value: Ieee32 }, |
| 318 | + F64Const { value: Ieee64 }, |
306 | 319 | I32Eqz,
|
307 | 320 | I32Eq,
|
308 | 321 | I32Ne,
|
@@ -616,14 +629,14 @@ impl<'a> BinaryReader<'a> {
|
616 | 629 | Ok((result << ashift) >> ashift)
|
617 | 630 | }
|
618 | 631 |
|
619 |
| - pub fn read_f32(&mut self) -> Result<f32> { |
| 632 | + pub fn read_f32(&mut self) -> Result<Ieee32> { |
620 | 633 | let value = self.read_u32()?;
|
621 |
| - Ok(unsafe { transmute::<u32, f32>(value) }) |
| 634 | + Ok(Ieee32(value)) |
622 | 635 | }
|
623 | 636 |
|
624 |
| - pub fn read_f64(&mut self) -> Result<f64> { |
| 637 | + pub fn read_f64(&mut self) -> Result<Ieee64> { |
625 | 638 | let value = self.read_u64()?;
|
626 |
| - Ok(unsafe { transmute::<u64, f64>(value) }) |
| 639 | + Ok(Ieee64(value)) |
627 | 640 | }
|
628 | 641 |
|
629 | 642 | pub fn read_string(&mut self) -> Result<&'a [u8]> {
|
|
0 commit comments