[naga spv-out] Make write_block and its types private.

Make `naga:🔙:spv::BlockContext::write_block` private to
`naga:🔙:spv::block`. Introduce a new `pub(super)` function,
`write_function_body`, for `Writer::write_function` to call.

Make `BlockExit` private to `naga:🔙:spv::block`.

Move `LoopContext` from `naga:🔙:spv` into
`naga:🔙:spv::block`, and make it private.
This commit is contained in:
Jim Blandy 2024-10-02 16:16:10 -07:00
parent c5a4b4ecc3
commit 04182c24ec
3 changed files with 27 additions and 18 deletions

View File

@ -4,8 +4,7 @@ Implementations for `BlockContext` methods.
use super::{
helpers, index::BoundsCheckResult, make_local, selection::Selection, Block, BlockContext,
Dimension, Error, Instruction, LocalType, LookupType, LoopContext, ResultMember, Writer,
WriterFlags,
Dimension, Error, Instruction, LocalType, LookupType, ResultMember, Writer, WriterFlags,
};
use crate::{arena::Handle, proc::TypeResolution, Statement};
use spirv::Word;
@ -39,7 +38,7 @@ enum ExpressionPointer {
}
/// The termination statement to be added to the end of the block
pub enum BlockExit {
enum BlockExit {
/// Generates an OpReturn (void return)
Return,
/// Generates an OpBranch to the specified block
@ -60,6 +59,12 @@ pub enum BlockExit {
},
}
#[derive(Clone, Copy, Default)]
struct LoopContext {
continuing_id: Option<Word>,
break_id: Option<Word>,
}
#[derive(Debug)]
pub(crate) struct DebugInfoInner<'a> {
pub source_code: &'a str,
@ -2060,7 +2065,7 @@ impl<'w> BlockContext<'w> {
}
}
pub(super) fn write_block(
fn write_block(
&mut self,
label_id: Word,
naga_block: &crate::Block,
@ -2721,4 +2726,20 @@ impl<'w> BlockContext<'w> {
self.function.consume(block, termination);
Ok(())
}
pub(super) fn write_function_body(
&mut self,
entry_id: Word,
debug_info: Option<&DebugInfoInner>,
) -> Result<(), Error> {
self.write_block(
entry_id,
&self.ir_function.body,
super::block::BlockExit::Return,
LoopContext::default(),
debug_info,
)?;
Ok(())
}
}

View File

@ -665,12 +665,6 @@ impl BlockContext<'_> {
}
}
#[derive(Clone, Copy, Default)]
struct LoopContext {
continuing_id: Option<Word>,
break_id: Option<Word>,
}
pub struct Writer {
physical_layout: PhysicalLayout,
logical_layout: LogicalLayout,

View File

@ -3,7 +3,7 @@ use super::{
helpers::{contains_builtin, global_needs_wrapper, map_storage_class},
make_local, Block, BlockContext, CachedConstant, CachedExpressions, DebugInfo,
EntryPointContext, Error, Function, FunctionArgument, GlobalVariable, IdGenerator, Instruction,
LocalType, LocalVariable, LogicalLayout, LookupFunctionType, LookupType, LoopContext, Options,
LocalType, LocalVariable, LogicalLayout, LookupFunctionType, LookupType, Options,
PhysicalLayout, PipelineOptions, ResultMember, Writer, WriterFlags, BITS_PER_BYTE,
};
use crate::{
@ -756,13 +756,7 @@ impl Writer {
next_id
};
context.write_block(
main_id,
&ir_function.body,
super::block::BlockExit::Return,
LoopContext::default(),
debug_info.as_ref(),
)?;
context.write_function_body(main_id, debug_info.as_ref())?;
// Consume the `BlockContext`, ending its borrows and letting the
// `Writer` steal back its cached expression table and temp_list.