Move out Void from the type enum

This commit is contained in:
Dzmitry Malyshau 2020-03-03 14:09:41 -05:00
parent 4a9f838208
commit a9c476d58d
4 changed files with 19 additions and 23 deletions

View File

@ -452,9 +452,6 @@ impl<W: Write> Writer<W> {
for (token, ty) in module.types.iter() {
let name = ty.name.or_index(token);
match ty.inner {
crate::TypeInner::Void => {
write!(self.out, "typedef void {}", name)?;
},
crate::TypeInner::Scalar { kind, .. } => {
write!(self.out, "typedef {} {}", scalar_kind_string(kind), name)?;
},
@ -600,7 +597,13 @@ impl<W: Write> Writer<W> {
writeln!(self.out, "{} {} {}(", em_str, output_name, fun_name)?;
writeln!(self.out, "\t{} {} [[stage_in]],", input_name, NAME_INPUT)?;
} else {
let result_type_name = module.types[fun.return_type].name.or_index(fun.return_type);
let result_type_name = match fun.return_type {
Some(type_id) => module.types[type_id].name.or_index(type_id),
None => Name {
class: "",
source: NameSource::Custom { name: "void", prefix: false },
},
};
writeln!(self.out, "{} {}(", result_type_name, fun_name)?;
for (index, &ty) in fun.parameter_types.iter().enumerate() {
let name = Name::from(ParameterIndex(index));

View File

@ -12,7 +12,7 @@ TODO: would be nice to find ways that avoid looking up as much
use crate::{
storage::{Storage, Token},
FastHashMap,
FastHashMap, FastHashSet,
};
use std::convert::TryInto;
@ -233,6 +233,7 @@ pub struct Parser<I> {
future_member_decor: FastHashMap<(spirv::Word, MemberIndex), Decoration>,
lookup_member_type_id: FastHashMap<(spirv::Word, MemberIndex), spirv::Word>,
lookup_type: FastHashMap<spirv::Word, LookupType>,
lookup_void_type: FastHashSet<spirv::Word>,
lookup_constant: FastHashMap<spirv::Word, LookupConstant>,
lookup_variable: FastHashMap<spirv::Word, LookupVariable>,
lookup_expression: FastHashMap<spirv::Word, LookupExpression>,
@ -251,6 +252,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
future_member_decor: FastHashMap::default(),
lookup_member_type_id: FastHashMap::default(),
lookup_type: FastHashMap::default(),
lookup_void_type: FastHashSet::default(),
lookup_constant: FastHashMap::default(),
lookup_variable: FastHashMap::default(),
lookup_expression: FastHashMap::default(),
@ -842,16 +844,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
self.switch(ModuleState::Type, inst.op)?;
inst.expect(2)?;
let id = self.next()?;
let inner = crate::TypeInner::Void;
self.lookup_type.insert(id, LookupType {
token: module.types.append(crate::Type {
name: self.future_decor
.remove(&id)
.and_then(|dec| dec.name),
inner,
}),
base_id: None,
});
self.lookup_void_type.insert(id);
}
Op::TypeInt => {
self.switch(ModuleState::Type, inst.op)?;
@ -1272,7 +1265,11 @@ impl<I: Iterator<Item = u32>> Parser<I> {
control: spirv::FunctionControl::from_bits(fun_control)
.ok_or(Error::UnsupportedFunctionControl(fun_control))?,
parameter_types: Vec::with_capacity(ft.parameter_type_ids.len()),
return_type: self.lookup_type.lookup(result_type)?.token,
return_type: if self.lookup_void_type.contains(&result_type) {
None
} else {
Some(self.lookup_type.lookup(result_type)?.token)
},
expressions: self.make_expression_storage(),
body: Vec::new(),
}

View File

@ -179,12 +179,9 @@ impl Parser {
control: spirv::FunctionControl::empty(),
parameter_types: Vec::new(),
return_type: if function_type_decl.as_rule() == Rule::type_decl {
self.parse_type_decl(function_type_decl, &mut module.types)?
Some(self.parse_type_decl(function_type_decl, &mut module.types)?)
} else {
module.types.append(crate::Type {
name: None,
inner: crate::TypeInner::Void,
})
None
},
expressions: Storage::new(),
body: Vec::new(),

View File

@ -72,7 +72,6 @@ pub struct Type {
#[derive(Debug, PartialEq)]
pub enum TypeInner {
Void,
Scalar { kind: ScalarKind, width: Bytes },
Vector { size: VectorSize, kind: ScalarKind, width: Bytes },
Matrix { columns: VectorSize, rows: VectorSize, kind: ScalarKind, width: Bytes },
@ -172,7 +171,7 @@ pub struct Function {
pub name: Option<String>,
pub control: spirv::FunctionControl,
pub parameter_types: Vec<Token<Type>>,
pub return_type: Token<Type>,
pub return_type: Option<Token<Type>>,
pub expressions: Storage<Expression>,
pub body: Block,
}