[−][src]Struct rspirv::binary::Parser
The SPIR-V binary parser.
Takes in a vector of bytes and a consumer, this parser will invoke the consume methods on the consumer for the module header and each instruction parsed.
Different from the Decoder
,
this parser is high-level; it has knowlege of the SPIR-V grammar.
It will parse instructions according to SPIR-V grammar.
Examples
extern crate rspirv; extern crate spirv_headers as spirv; use spirv::{AddressingModel, MemoryModel}; use rspirv::binary::Parser; use rspirv::dr::{Loader, Operand}; fn main() { let bin = vec![ // Magic number. Version number: 1.0. 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, // Generator number: 0. Bound: 0. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved word: 0. 0x00, 0x00, 0x00, 0x00, // OpMemoryModel. Logical. 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // GLSL450. 0x01, 0x00, 0x00, 0x00]; let mut loader = Loader::new(); // You can use your own consumer here. { let p = Parser::new(&bin, &mut loader); p.parse().unwrap(); } let module = loader.module(); assert_eq!((1, 0), module.header.unwrap().version()); let m = module.memory_model.as_ref().unwrap(); assert_eq!(Operand::AddressingModel(AddressingModel::Logical), m.operands[0]); assert_eq!(Operand::MemoryModel(MemoryModel::GLSL450), m.operands[1]); }
Implementations
impl<'c, 'd> Parser<'c, 'd>
[src]
pub fn new(binary: &'d [u8], consumer: &'c mut dyn Consumer) -> Self
[src]
Creates a new parser to parse the given binary
and send the module
header and instructions to the given consumer
.
pub fn parse(self) -> Result<()>
[src]
Does the parsing.
Auto Trait Implementations
impl<'c, 'd> !RefUnwindSafe for Parser<'c, 'd>
impl<'c, 'd> !Send for Parser<'c, 'd>
impl<'c, 'd> !Sync for Parser<'c, 'd>
impl<'c, 'd> Unpin for Parser<'c, 'd>
impl<'c, 'd> !UnwindSafe for Parser<'c, 'd>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,