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

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

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::mr::{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, 2), 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]);
}

Methods

impl<'c, 'd> Parser<'c, 'd>
[src]

[src]

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

[src]

Does the parsing.