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

Method match_uimm8

cranelift/reader/src/parser.rs:770–786  ·  view source on GitHub ↗

Match and consume a u8 immediate. This is used for lane numbers in SIMD vectors.

(&mut self, err_msg: &str)

Source from the content-addressed store, hash-verified

768 // Match and consume a u8 immediate.
769 // This is used for lane numbers in SIMD vectors.
770 fn match_uimm8(&mut self, err_msg: &str) -> ParseResult<u8> {
771 if let Some(Token::Integer(text)) = self.token() {
772 self.consume();
773 // Lexer just gives us raw text that looks like an integer.
774 if let Some(num) = text.strip_prefix("0x") {
775 // Parse it as a u8 in hexadecimal form.
776 u8::from_str_radix(num, 16)
777 .map_err(|_| self.error("unable to parse u8 as a hexadecimal immediate"))
778 } else {
779 // Parse it as a u8 to check for overflow and other issues.
780 text.parse()
781 .map_err(|_| self.error("expected u8 decimal immediate"))
782 }
783 } else {
784 err!(self.loc, err_msg)
785 }
786 }
787
788 // Match and consume an i8 immediate.
789 fn match_imm8(&mut self, err_msg: &str) -> ParseResult<i8> {

Callers 2

parse_inst_operandsMethod · 0.80
parse_as_uimm8Function · 0.80

Calls 4

tokenMethod · 0.80
consumeMethod · 0.45
errorMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected