mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
refactor(msl-out): extract puts_local helper
-- Co-authored-by: Liam Murphy <liampm32@gmail.com> Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
This commit is contained in:
parent
dbb36cc556
commit
7cf3e2f3cc
@ -929,6 +929,45 @@ impl<W: Write> Writer<W> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Writes the local variables of the given function.
|
||||||
|
fn put_locals(&mut self, context: &ExpressionContext) -> BackendResult {
|
||||||
|
for (name_key, ty, init) in context
|
||||||
|
.function
|
||||||
|
.local_variables
|
||||||
|
.iter()
|
||||||
|
.map(|(local_handle, local)| {
|
||||||
|
let name_key = NameKey::local(context.origin, local_handle);
|
||||||
|
(name_key, local.ty, local.init)
|
||||||
|
})
|
||||||
|
{
|
||||||
|
let ty_name = TypeContext {
|
||||||
|
handle: ty,
|
||||||
|
gctx: context.module.to_ctx(),
|
||||||
|
names: &self.names,
|
||||||
|
access: crate::StorageAccess::empty(),
|
||||||
|
first_time: false,
|
||||||
|
};
|
||||||
|
write!(
|
||||||
|
self.out,
|
||||||
|
"{}{} {}",
|
||||||
|
back::INDENT,
|
||||||
|
ty_name,
|
||||||
|
self.names[&name_key]
|
||||||
|
)?;
|
||||||
|
match init {
|
||||||
|
Some(value) => {
|
||||||
|
write!(self.out, " = ")?;
|
||||||
|
self.put_expression(value, context, true)?;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
write!(self.out, " = {{}}")?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
writeln!(self.out, ";")?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn put_level_of_detail(
|
fn put_level_of_detail(
|
||||||
&mut self,
|
&mut self,
|
||||||
level: LevelOfDetail,
|
level: LevelOfDetail,
|
||||||
@ -5683,28 +5722,7 @@ template <typename A>
|
|||||||
result_struct: None,
|
result_struct: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (local_handle, local) in fun.local_variables.iter() {
|
self.put_locals(&context.expression)?;
|
||||||
let ty_name = TypeContext {
|
|
||||||
handle: local.ty,
|
|
||||||
gctx: module.to_ctx(),
|
|
||||||
names: &self.names,
|
|
||||||
access: crate::StorageAccess::empty(),
|
|
||||||
first_time: false,
|
|
||||||
};
|
|
||||||
let local_name = &self.names[&NameKey::FunctionLocal(fun_handle, local_handle)];
|
|
||||||
write!(self.out, "{}{} {}", back::INDENT, ty_name, local_name)?;
|
|
||||||
match local.init {
|
|
||||||
Some(value) => {
|
|
||||||
write!(self.out, " = ")?;
|
|
||||||
self.put_expression(value, &context.expression, true)?;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
write!(self.out, " = {{}}")?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
writeln!(self.out, ";")?;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.update_expressions_to_bake(fun, fun_info, &context.expression);
|
self.update_expressions_to_bake(fun, fun_info, &context.expression);
|
||||||
self.put_block(back::Level(1), &fun.body, &context)?;
|
self.put_block(back::Level(1), &fun.body, &context)?;
|
||||||
writeln!(self.out, "}}")?;
|
writeln!(self.out, "}}")?;
|
||||||
@ -6616,28 +6634,7 @@ template <typename A>
|
|||||||
|
|
||||||
// Finally, declare all the local variables that we need
|
// Finally, declare all the local variables that we need
|
||||||
//TODO: we can postpone this till the relevant expressions are emitted
|
//TODO: we can postpone this till the relevant expressions are emitted
|
||||||
for (local_handle, local) in fun.local_variables.iter() {
|
self.put_locals(&context.expression)?;
|
||||||
let name = &self.names[&NameKey::EntryPointLocal(ep_index as _, local_handle)];
|
|
||||||
let ty_name = TypeContext {
|
|
||||||
handle: local.ty,
|
|
||||||
gctx: module.to_ctx(),
|
|
||||||
names: &self.names,
|
|
||||||
access: crate::StorageAccess::empty(),
|
|
||||||
first_time: false,
|
|
||||||
};
|
|
||||||
write!(self.out, "{}{} {}", back::INDENT, ty_name, name)?;
|
|
||||||
match local.init {
|
|
||||||
Some(value) => {
|
|
||||||
write!(self.out, " = ")?;
|
|
||||||
self.put_expression(value, &context.expression, true)?;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
write!(self.out, " = {{}}")?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
writeln!(self.out, ";")?;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.update_expressions_to_bake(fun, fun_info, &context.expression);
|
self.update_expressions_to_bake(fun, fun_info, &context.expression);
|
||||||
self.put_block(back::Level(1), &fun.body, &context)?;
|
self.put_block(back::Level(1), &fun.body, &context)?;
|
||||||
writeln!(self.out, "}}")?;
|
writeln!(self.out, "}}")?;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user