|
1 | 1 | //! Verification of MIPS MSA intrinsics
|
2 |
| -#![feature(try_trait)] |
3 | 2 | #![allow(bad_style, unused)]
|
4 | 3 |
|
5 | 4 | // This file is obtained from
|
@@ -139,47 +138,53 @@ struct MsaIntrinsic {
|
139 | 138 | instruction: String,
|
140 | 139 | }
|
141 | 140 |
|
| 141 | +struct NoneError; |
| 142 | + |
142 | 143 | impl std::convert::TryFrom<&'static str> for MsaIntrinsic {
|
143 | 144 | // The intrinsics are just C function declarations of the form:
|
144 | 145 | // $ret_ty __builtin_${fn_id}($($arg_ty),*);
|
145 |
| - type Error = std::option::NoneError; |
| 146 | + type Error = NoneError; |
146 | 147 | fn try_from(line: &'static str) -> Result<Self, Self::Error> {
|
147 |
| - let first_whitespace = line.find(char::is_whitespace)?; |
148 |
| - let ret_ty = &line[0..first_whitespace]; |
149 |
| - let ret_ty = MsaTy::from(ret_ty); |
| 148 | + return inner(line).ok_or(NoneError); |
150 | 149 |
|
151 |
| - let first_parentheses = line.find('(')?; |
152 |
| - assert!(first_parentheses > first_whitespace); |
153 |
| - let id = &line[first_whitespace + 1..first_parentheses].trim(); |
154 |
| - assert!(id.starts_with("__builtin")); |
155 |
| - let mut id_str = "_".to_string(); |
156 |
| - id_str += &id[9..]; |
157 |
| - let id = id_str; |
| 150 | + fn inner(line: &'static str) -> Option<MsaIntrinsic> { |
| 151 | + let first_whitespace = line.find(char::is_whitespace)?; |
| 152 | + let ret_ty = &line[0..first_whitespace]; |
| 153 | + let ret_ty = MsaTy::from(ret_ty); |
158 | 154 |
|
159 |
| - let mut arg_tys = Vec::new(); |
| 155 | + let first_parentheses = line.find('(')?; |
| 156 | + assert!(first_parentheses > first_whitespace); |
| 157 | + let id = &line[first_whitespace + 1..first_parentheses].trim(); |
| 158 | + assert!(id.starts_with("__builtin")); |
| 159 | + let mut id_str = "_".to_string(); |
| 160 | + id_str += &id[9..]; |
| 161 | + let id = id_str; |
160 | 162 |
|
161 |
| - let last_parentheses = line.find(')')?; |
162 |
| - for arg in (&line[first_parentheses + 1..last_parentheses]).split(',') { |
163 |
| - let arg = arg.trim(); |
164 |
| - arg_tys.push(MsaTy::from(arg)); |
165 |
| - } |
| 163 | + let mut arg_tys = Vec::new(); |
166 | 164 |
|
167 |
| - // The instruction is the intrinsic name without the __msa_ prefix. |
168 |
| - let instruction = &id[6..]; |
169 |
| - let mut instruction = instruction.to_string(); |
170 |
| - // With all underscores but the first one replaced with a `.` |
171 |
| - if let Some(first_underscore) = instruction.find('_') { |
172 |
| - let postfix = instruction[first_underscore + 1..].replace('_', "."); |
173 |
| - instruction = instruction[0..=first_underscore].to_string(); |
174 |
| - instruction += &postfix; |
175 |
| - } |
| 165 | + let last_parentheses = line.find(')')?; |
| 166 | + for arg in (&line[first_parentheses + 1..last_parentheses]).split(',') { |
| 167 | + let arg = arg.trim(); |
| 168 | + arg_tys.push(MsaTy::from(arg)); |
| 169 | + } |
176 | 170 |
|
177 |
| - Ok(MsaIntrinsic { |
178 |
| - id, |
179 |
| - ret_ty, |
180 |
| - arg_tys, |
181 |
| - instruction, |
182 |
| - }) |
| 171 | + // The instruction is the intrinsic name without the __msa_ prefix. |
| 172 | + let instruction = &id[6..]; |
| 173 | + let mut instruction = instruction.to_string(); |
| 174 | + // With all underscores but the first one replaced with a `.` |
| 175 | + if let Some(first_underscore) = instruction.find('_') { |
| 176 | + let postfix = instruction[first_underscore + 1..].replace('_', "."); |
| 177 | + instruction = instruction[0..=first_underscore].to_string(); |
| 178 | + instruction += &postfix; |
| 179 | + } |
| 180 | + |
| 181 | + Some(MsaIntrinsic { |
| 182 | + id, |
| 183 | + ret_ty, |
| 184 | + arg_tys, |
| 185 | + instruction, |
| 186 | + }) |
| 187 | + } |
183 | 188 | }
|
184 | 189 | }
|
185 | 190 |
|
|
0 commit comments