MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_data_value

Method parse_data_value

cranelift/reader/src/parser.rs:2631–2660  ·  view source on GitHub ↗

Parse a data value; e.g. `42`, `4.2`, `true`. data-value-list ::= [data-value {"," data-value-list}]

(&mut self, ty: Type)

Source from the content-addressed store, hash-verified

2629 ///
2630 /// data-value-list ::= [data-value {"," data-value-list}]
2631 fn parse_data_value(&mut self, ty: Type) -> ParseResult<DataValue> {
2632 let dv = match ty {
2633 I8 => DataValue::from(self.match_imm8("expected a i8")?),
2634 I16 => DataValue::from(self.match_imm16("expected an i16")?),
2635 I32 => DataValue::from(self.match_imm32("expected an i32")?),
2636 I64 => DataValue::from(Into::<i64>::into(self.match_imm64("expected an i64")?)),
2637 I128 => DataValue::from(self.match_imm128("expected an i128")?),
2638 F16 => DataValue::from(self.match_ieee16("expected an f16")?),
2639 F32 => DataValue::from(self.match_ieee32("expected an f32")?),
2640 F64 => DataValue::from(self.match_ieee64("expected an f64")?),
2641 F128 => DataValue::from(self.match_ieee128("expected an f128")?),
2642 _ if (ty.is_vector() || ty.is_dynamic_vector()) => {
2643 let as_vec = self.match_uimm128(ty)?.into_vec();
2644 let slice = as_vec.as_slice();
2645 match slice.len() {
2646 16 => DataValue::V128(slice.try_into().unwrap()),
2647 8 => DataValue::V64(slice.try_into().unwrap()),
2648 4 => DataValue::V32(slice.try_into().unwrap()),
2649 2 => DataValue::V16(slice.try_into().unwrap()),
2650 _ => {
2651 return Err(
2652 self.error("vectors larger than 128 bits are not currently supported")
2653 );
2654 }
2655 }
2656 }
2657 _ => return Err(self.error(&format!("don't know how to parse data values of: {ty}"))),
2658 };
2659 Ok(dv)
2660 }
2661
2662 // Parse the operands following the instruction opcode.
2663 // This depends on the format of the opcode.

Callers 2

parse_data_value_listMethod · 0.80
parseFunction · 0.80

Calls 15

fromFunction · 0.85
OkFunction · 0.85
match_imm8Method · 0.80
match_imm16Method · 0.80
match_imm32Method · 0.80
match_imm64Method · 0.80
match_imm128Method · 0.80
match_ieee16Method · 0.80
match_ieee32Method · 0.80
match_ieee64Method · 0.80
match_ieee128Method · 0.80
is_dynamic_vectorMethod · 0.80

Tested by

no test coverage detected