Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/rspirv2-types/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::binary::DecodeError;
use crate::binary::{DecodeError, WordWriter};
use crate::inst::InstEncoding;
use crate::vec::InstVec;
use crate::{Word, cast_words_to_ne_bytes};
Expand Down Expand Up @@ -225,6 +225,23 @@ impl<ISA: InstEncoding> Module<ISA> {
Err(e) => Err(e),
}
}

/// Write this module including the header to a [`WordWriter`]
pub fn write_words(&self, writer: &mut impl WordWriter) {
if let Some(header) = self.header {
writer.write_iter(header.to_array());
}
writer.write_iter(self.inst.as_words().iter().copied());
}

/// Write this module including the header to a [`std::io::Write`], which could be a [`std::fs::File`]
pub fn write_bytes(&self, writer: &mut impl std::io::Write) -> std::io::Result<()> {
if let Some(header) = self.header {
writer.write_all(cast_words_to_ne_bytes(&header.to_array()))?;
}
writer.write_all(cast_words_to_ne_bytes(self.inst.as_words()))?;
Ok(())
}
}

impl<ISA: InstEncoding> Deref for Module<ISA> {
Expand Down
Loading