More work on parser

This commit is contained in:
Pierre Krieger 2016-01-31 14:58:44 +01:00
parent b2e63f2e3a
commit f75a0d668f
2 changed files with 7 additions and 1 deletions

View File

@ -120,7 +120,11 @@ fn type_from_id(doc: &parse::Spirv, searched: u32) -> String {
}, },
&parse::Instruction::TypeArray { result_id, type_id, length_id } if result_id == searched => { &parse::Instruction::TypeArray { result_id, type_id, length_id } if result_id == searched => {
let t = type_from_id(doc, type_id); let t = type_from_id(doc, type_id);
return format!("[{}; {}]", t, length_id); // FIXME: let len = doc.instructions.iter().filter_map(|e| {
match e { &parse::Instruction::Constant { result_id, ref data, .. } if result_id == length_id => Some(data.clone()), _ => None }
}).next().expect("failed to find array length");
let len = len.iter().rev().fold(0u64, |a, &b| (a << 32) | b as u64);
return format!("[{}; {}]", t, len); // FIXME:
}, },
&parse::Instruction::TypeRuntimeArray { result_id, type_id } if result_id == searched => { &parse::Instruction::TypeRuntimeArray { result_id, type_id } if result_id == searched => {
let t = type_from_id(doc, type_id); let t = type_from_id(doc, type_id);

View File

@ -97,6 +97,7 @@ pub enum Instruction {
TypeStruct { result_id: u32, member_types: Vec<u32> }, TypeStruct { result_id: u32, member_types: Vec<u32> },
TypeOpaque { result_id: u32, name: String }, TypeOpaque { result_id: u32, name: String },
TypePointer { result_id: u32, storage_class: StorageClass, type_id: u32 }, TypePointer { result_id: u32, storage_class: StorageClass, type_id: u32 },
Constant { result_type_id: u32, result_id: u32, data: Vec<u32> },
FunctionEnd, FunctionEnd,
Variable { result_type_id: u32, result_id: u32, storage_class: StorageClass, initializer: Option<u32> }, Variable { result_type_id: u32, result_id: u32, storage_class: StorageClass, initializer: Option<u32> },
Label { result_id: u32 }, Label { result_id: u32 },
@ -162,6 +163,7 @@ fn decode_instruction(opcode: u16, operands: &[u32]) -> Result<Instruction, Pars
30 => Instruction::TypeStruct { result_id: operands[0], member_types: operands[1..].to_owned() }, 30 => Instruction::TypeStruct { result_id: operands[0], member_types: operands[1..].to_owned() },
31 => Instruction::TypeOpaque { result_id: operands[0], name: parse_string(&operands[1..]).0 }, 31 => Instruction::TypeOpaque { result_id: operands[0], name: parse_string(&operands[1..]).0 },
32 => Instruction::TypePointer { result_id: operands[0], storage_class: try!(StorageClass::from_num(operands[1])), type_id: operands[2] }, 32 => Instruction::TypePointer { result_id: operands[0], storage_class: try!(StorageClass::from_num(operands[1])), type_id: operands[2] },
43 => Instruction::Constant { result_type_id: operands[0], result_id: operands[1], data: operands[2..].to_owned() },
56 => Instruction::FunctionEnd, 56 => Instruction::FunctionEnd,
59 => Instruction::Variable { 59 => Instruction::Variable {
result_type_id: operands[0], result_id: operands[1], result_type_id: operands[0], result_id: operands[1],