Struct rspirv::binary::Parser[][src]

pub struct Parser<'c, 'd> { /* fields omitted */ }
Expand description

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

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

Creates a new parser to parse the given binary and send the module header and instructions to the given consumer.

Does the parsing.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.