(
&mut self,
id_map: &mut FxHashMap<&'a str, Word>,
inst: &mut dr::Instruction,
kind: OperandKind,
tokens: &mut impl Iterator<Item = Token<'a, 'cx, 'tcx>>,
| 1038 | } |
| 1039 | |
| 1040 | fn parse_one_operand<'a>( |
| 1041 | &mut self, |
| 1042 | id_map: &mut FxHashMap<&'a str, Word>, |
| 1043 | inst: &mut dr::Instruction, |
| 1044 | kind: OperandKind, |
| 1045 | tokens: &mut impl Iterator<Item = Token<'a, 'cx, 'tcx>>, |
| 1046 | ) -> bool |
| 1047 | where |
| 1048 | 'cx: 'a, |
| 1049 | 'tcx: 'a, |
| 1050 | { |
| 1051 | let token = match tokens.next() { |
| 1052 | Some(tok) => tok, |
| 1053 | None => return false, |
| 1054 | }; |
| 1055 | let word = match token { |
| 1056 | Token::Word(word) => Some(word), |
| 1057 | Token::String(_) | Token::Placeholder(_, _) | Token::Typeof(_, _, _) => None, |
| 1058 | }; |
| 1059 | match (kind, word) { |
| 1060 | (OperandKind::IdResultType | OperandKind::IdResult, _) => { |
| 1061 | bug!("should be handled by parse_operands"); |
| 1062 | } |
| 1063 | (OperandKind::IdMemorySemantics, _) => { |
| 1064 | if let Some(id) = self.parse_id_in(id_map, token) { |
| 1065 | inst.operands.push(dr::Operand::IdMemorySemantics(id)); |
| 1066 | } |
| 1067 | } |
| 1068 | (OperandKind::IdScope, _) => { |
| 1069 | if let Some(id) = self.parse_id_in(id_map, token) { |
| 1070 | inst.operands.push(dr::Operand::IdScope(id)); |
| 1071 | } |
| 1072 | } |
| 1073 | (OperandKind::IdRef, _) => { |
| 1074 | if let Some(id) = self.parse_id_in(id_map, token) { |
| 1075 | inst.operands.push(dr::Operand::IdRef(id)); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | (OperandKind::LiteralInteger, Some(word)) => match word.parse() { |
| 1080 | Ok(v) => inst.operands.push(dr::Operand::LiteralInt32(v)), |
| 1081 | Err(e) => self.err(&format!("invalid integer: {e}")), |
| 1082 | }, |
| 1083 | (OperandKind::LiteralString, _) => { |
| 1084 | if let Token::String(value) = token { |
| 1085 | inst.operands.push(dr::Operand::LiteralString(value)); |
| 1086 | } |
| 1087 | } |
| 1088 | (OperandKind::LiteralContextDependentNumber, Some(word)) => { |
| 1089 | assert!(matches!(inst.class.opcode, Op::Constant | Op::SpecConstant)); |
| 1090 | let ty = inst.result_type.unwrap(); |
| 1091 | fn parse(ty: SpirvType<'_>, w: &str) -> Result<dr::Operand, String> { |
| 1092 | fn fmt(x: impl ToString) -> String { |
| 1093 | x.to_string() |
| 1094 | } |
| 1095 | Ok(match ty { |
| 1096 | SpirvType::Integer(8, false) => { |
| 1097 | dr::Operand::LiteralInt32(w.parse::<u8>().map_err(fmt)? as u32) |
no test coverage detected