Skip to main content

jeff/
reader.rs

1//! View of jeff data.
2//!
3//! Programs are composed of a top-level [`Module`] that contains a list of [`Function`]s.
4
5mod function;
6mod metadata;
7mod module;
8mod op;
9mod region;
10mod string_table;
11pub mod value;
12
13pub mod optype;
14
15pub use function::{Function, FunctionDeclaration, FunctionDefinition, FunctionId};
16pub use metadata::{HasMetadata, Metadata};
17pub use module::Module;
18pub use op::Operation;
19pub use region::Region;
20pub use value::{FunctionIOValue, ValueId, ValueTable, WireValue};
21
22use derive_more::derive::{Display, Error, From};
23
24/// Structure that can return a read-only view of a jeff file.
25pub trait ReadJeff {
26    /// Returns a read-only reference to the capnp jeff module.
27    fn module(&self) -> Module<'_>;
28}
29
30/// Errors that can occur when accessing a jeff program.
31#[derive(Debug, Display, From, Error)]
32#[non_exhaustive]
33pub enum ReadError {
34    /// String index into the module's string table was out of bounds.
35    #[display("{context} string value has index {idx}, but only {count} entries are available")]
36    StringOutOfBounds {
37        /// The context in which the error occurred.
38        context: &'static str,
39        /// The requested index into the module's `strings`.
40        idx: u32,
41        /// The total number of entries in the module's `strings`.
42        count: usize,
43    },
44    /// The encoded string had a non-utf8 name.
45    #[display("{context} string value with index {idx} was not valid utf8.")]
46    StringNotUtf8 {
47        /// The context in which the error occurred.
48        context: &'static str,
49        /// The index of the metadata name.
50        idx: u32,
51        /// The utf8 error
52        source: core::str::Utf8Error,
53    },
54    /// Value index into the function's value table was out of bounds.
55    #[display("Function value has index {idx}, but only {count} entries are available")]
56    ValueOutOfBounds {
57        /// The requested index into the function values.
58        idx: u32,
59        /// The total number of entries in the function values.
60        count: usize,
61    },
62}