Match and consume a u8 immediate. This is used for lane numbers in SIMD vectors.
(&mut self, err_msg: &str)
| 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> { |
no test coverage detected