llvm_bitstream/error.rs
1//! Errors for `llvm-bitstream`.
2
3use llvm_bitcursor::error::Error as CursorError;
4use llvm_support::bitcodes::{AbbrevOpEnc, BlockInfoCode};
5use num_enum::TryFromPrimitiveError;
6use thiserror::Error as ThisError;
7
8/// All possible errors that can occur while parsing a bitstream.
9#[derive(Debug, ThisError)]
10pub enum Error {
11 /// The underlying bitstream has no more data to parse.
12 #[error("bitstream has been exhausted")]
13 Exhausted,
14 /// The underlying [`BitCursor`](llvm_bitcursor::BitCursor) returned an error
15 /// that we couldn't specialize.
16 #[error("underlying bitcursor error")]
17 Cursor(#[from] CursorError),
18 /// We couldn't parse the wrapper structure or other data that precedes the actual bitstream.
19 #[error("couldn't parse bitstream container: {0}")]
20 BadContainer(String),
21 /// A record in the `BLOCKINFO` block has a code that we don't know.
22 /// `BLOCKINFO` must be fully interpreted in order to correctly parse the remainder of
23 /// the bitstream, so this is a hard error.
24 #[error("bad record code for BLOCKINFO block")]
25 BadBlockInfoCode(#[from] TryFromPrimitiveError<BlockInfoCode>),
26 /// An operand in a `DEFINE_ABBREV` definition has a code that we don't know.
27 /// This indicates either a malformed bitstream or a new operand format that
28 /// we don't yet support, so it's a hard error.
29 #[error("bad operand code for DEFINE_ABBREV operand")]
30 BadAbbrevOpEnc(#[from] TryFromPrimitiveError<AbbrevOpEnc>),
31 /// A generic error occurred while parsing the bitstream.
32 #[error("error while parsing stream: {0}")]
33 StreamParse(String),
34 /// An error occurred while interpreting a `DEFINE_ABBREV` record.
35 #[error("error while parsing abbrev record: {0}")]
36 AbbrevParse(String),
37 /// An error occurred while mapping an abbreviated record back to its abbreviation definition.
38 #[error("unknown abbreviation for ID: {0}")]
39 BadAbbrev(u64),
40 /// An error occurred during block scope entrance or exit.
41 #[error("error while parsing block scope: {0}")]
42 BadScope(String),
43}