use llvm_bitcursor::error::Error as CursorError;
use llvm_support::bitcodes::{AbbrevOpEnc, BlockInfoCode};
use num_enum::TryFromPrimitiveError;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("bitstream has been exhausted")]
Exhausted,
#[error("underlying bitcursor error")]
Cursor(#[from] CursorError),
#[error("couldn't parse bitstream container: {0}")]
BadContainer(String),
#[error("bad record code for BLOCKINFO block")]
BadBlockInfoCode(#[from] TryFromPrimitiveError<BlockInfoCode>),
#[error("bad operand code for DEFINE_ABBREV operand")]
BadAbbrevOpEnc(#[from] TryFromPrimitiveError<AbbrevOpEnc>),
#[error("error while parsing stream: {0}")]
StreamParse(String),
#[error("error while parsing abbrev record: {0}")]
AbbrevParse(String),
#[error("unknown abbreviation for ID: {0}")]
BadAbbrev(u64),
#[error("error while parsing block scope: {0}")]
BadScope(String),
}