| 170 | } |
| 171 | |
| 172 | Expect<void> FormChecker::checkInstr(const AST::Instruction &Instr) { |
| 173 | // Note: The instructions and their immediates have passed proposal |
| 174 | // configuration checking in the loader phase. |
| 175 | |
| 176 | // Helper lambda for checking whether the table index is valid. |
| 177 | auto checkTableIdx = [this](const uint32_t Idx) -> Expect<void> { |
| 178 | if (unlikely(Idx >= Tables.size())) { |
| 179 | return logOutOfRange(ErrCode::Value::InvalidTableIdx, |
| 180 | ErrInfo::IndexCategory::Table, Idx, |
| 181 | static_cast<uint32_t>(Tables.size())); |
| 182 | } |
| 183 | return {}; |
| 184 | }; |
| 185 | |
| 186 | // Helper lambda for checking whether the memory index is valid. |
| 187 | auto checkMemIdx = [this](const uint32_t Idx) -> Expect<void> { |
| 188 | if (unlikely(Idx >= Mems.size())) { |
| 189 | return logOutOfRange(ErrCode::Value::InvalidMemoryIdx, |
| 190 | ErrInfo::IndexCategory::Memory, Idx, |
| 191 | static_cast<uint32_t>(Mems.size())); |
| 192 | } |
| 193 | return {}; |
| 194 | }; |
| 195 | |
| 196 | // Helper lambda for checking whether the data index is valid. |
| 197 | auto checkDataIdx = [this](const uint32_t Idx) -> Expect<void> { |
| 198 | if (unlikely(Idx >= Datas.size())) { |
| 199 | return logOutOfRange(ErrCode::Value::InvalidDataIdx, |
| 200 | ErrInfo::IndexCategory::Data, Idx, |
| 201 | static_cast<uint32_t>(Datas.size())); |
| 202 | } |
| 203 | return {}; |
| 204 | }; |
| 205 | |
| 206 | // Helper lambda for checking whether the element index is valid. |
| 207 | auto checkElemIdx = [this](const uint32_t Idx) -> Expect<void> { |
| 208 | if (unlikely(Idx >= Elems.size())) { |
| 209 | return logOutOfRange(ErrCode::Value::InvalidElemIdx, |
| 210 | ErrInfo::IndexCategory::Element, Idx, |
| 211 | static_cast<uint32_t>(Elems.size())); |
| 212 | } |
| 213 | return {}; |
| 214 | }; |
| 215 | |
| 216 | // Helper lambda for checking whether the tag index is valid. |
| 217 | auto checkTagIdx = [this](const uint32_t Idx) -> Expect<void> { |
| 218 | if (unlikely(Idx >= Tags.size())) { |
| 219 | return logOutOfRange(ErrCode::Value::InvalidTagIdx, |
| 220 | ErrInfo::IndexCategory::Tag, Idx, |
| 221 | static_cast<uint32_t>(Tags.size())); |
| 222 | } |
| 223 | return {}; |
| 224 | }; |
| 225 | |
| 226 | // Helper lambda for checking the defined type. |
| 227 | auto checkDefinedType = |
| 228 | [this](uint32_t TIdx, TypeCode TC) -> Expect<const AST::CompositeType *> { |
| 229 | if (TIdx >= Types.size()) { |
nothing calls this directly
no test coverage detected