llvm_mapper/record/
mod.rs

1//! Structures for mapping from bitstream records to LLVM models.
2//!
3//! Depending on their importance or complexity, not every record is given a dedicated
4//! structure or mapping implementation. Simpler records are mapped inline within their
5//! blocks.
6
7pub mod alias;
8pub mod comdat;
9pub mod datalayout;
10pub mod function;
11
12use std::num::TryFromIntError;
13use std::string::FromUtf8Error;
14
15use thiserror::Error;
16
17pub use self::alias::*;
18pub use self::comdat::*;
19pub use self::datalayout::*;
20pub use self::function::*;
21use crate::block::StrtabError;
22
23/// Potential errors when trying to extract a string from a record.
24#[non_exhaustive]
25#[derive(Debug, Error)]
26pub enum RecordStringError {
27    /// The start index for the string is invalid.
28    #[error("impossible string index: {0} >= {1} (field count)")]
29    BadIndex(usize, usize),
30    /// A field in the record is too large to fit in a byte.
31    #[error("impossible character value in string: {0}")]
32    BadCharacter(#[from] TryFromIntError),
33    /// The string doesn't look like valid UTF-8.
34    #[error("invalid string encoding: {0}")]
35    BadEncoding(#[from] FromUtf8Error),
36}
37
38/// Potential errors when trying to extract a blob from a record.
39#[non_exhaustive]
40#[derive(Debug, Error)]
41pub enum RecordBlobError {
42    /// The start index for the blob is invalid.
43    #[error("impossible blob index: {0} >= {1} (field count)")]
44    BadIndex(usize, usize),
45    /// A field in the record is too large to fit in a byte.
46    #[error("impossible byte value in blob: {0}")]
47    BadByte(#[from] TryFromIntError),
48}
49
50/// Potential errors when mapping a single bitstream record.
51#[non_exhaustive]
52#[derive(Debug, Error)]
53pub enum RecordMapError {
54    /// Mapping a COMDAT record failed.
55    #[error("error while mapping COMDAT record: {0}")]
56    Comdat(#[from] ComdatError),
57
58    /// Parsing the datalayout specification failed.
59    #[error("error while parsing datalayout: {0}")]
60    DataLayout(#[from] DataLayoutError),
61
62    /// Mapping a function record failed.
63    #[error("error while mapping function record: {0}")]
64    Function(#[from] FunctionError),
65
66    /// We encountered a string we couldn't extract.
67    #[error("error while extracting string: {0}")]
68    BadRecordString(#[from] RecordStringError),
69}