dump_variables/
dump_variables.rs

1extern crate spirv_utils;
2
3use std::env;
4
5use spirv_utils::{desc, instruction};
6
7fn main() {
8    let mut args = env::args_os();
9    args.next();
10
11    let filename = args.next();
12
13    let module = if let Some(filename) = filename {
14        spirv_utils::RawModule::load_module(filename).unwrap()
15    } else {
16        spirv_utils::RawModule::load_module("examples/vert.spv").unwrap()
17    };
18
19    for inst in module.instructions() {
20        if let instruction::Instruction::Variable { result_id, storage_class, .. } = *inst {
21            if let Some(name) = get_name(&module, result_id.into()) {
22                println!("Variable {: <15} {:?}", name, storage_class);
23            }
24        }
25    }
26}
27
28fn get_name<'a>(module: &'a spirv_utils::RawModule, id: desc::Id) -> Option<&'a str> {
29    module.uses(id).filter_map(|inst| {
30        if let instruction::Instruction::Name { ref name, .. } = *inst {
31            Some(&name[..])
32        } else {
33            None
34        }
35    }).next()
36}