pub struct ModuleEmitter {
pub words: Vec<u32>,
}
Fields§
§words: Vec<u32>
Output SPIR-V words.
Implementations§
Source§impl ModuleEmitter
impl ModuleEmitter
Sourcepub fn with_header(header: [u32; 5]) -> Self
pub fn with_header(header: [u32; 5]) -> Self
Examples found in repository?
examples/spv-read-write-roundtrip.rs (line 5)
1fn main() -> std::io::Result<()> {
2 match &std::env::args().collect::<Vec<_>>()[..] {
3 [_, in_file, out_file] => {
4 let parser = spirt::spv::read::ModuleParser::read_from_spv_file(in_file)?;
5 let mut emitter = spirt::spv::write::ModuleEmitter::with_header(parser.header);
6
7 {
8 // FIXME(eddyb) show more of the header.
9 let [_, v, ..] = parser.header;
10 eprintln!("SPIR-V {}.{} module:", v >> 16, (v >> 8) & 0xff);
11 }
12
13 for inst in parser {
14 let inst = inst.unwrap();
15
16 eprint!(" ");
17
18 if let Some(id) = inst.result_id {
19 eprint!("%{id}");
20 if let Some(type_id) = inst.result_type_id {
21 eprint!(": %{type_id}");
22 }
23 eprint!(" = ");
24 }
25
26 eprint!("{}", inst.opcode.name());
27 spirt::spv::print::inst_operands(
28 inst.opcode,
29 inst.imms.iter().copied(),
30 inst.ids.iter().map(|id| format!("%{id}")),
31 )
32 .for_each(|operand_parts| eprint!(" {}", operand_parts.concat_to_plain_text()));
33
34 eprintln!();
35
36 emitter.push_inst(&inst).unwrap();
37 }
38
39 emitter.write_to_spv_file(out_file)
40 }
41 args => {
42 eprintln!("Usage: {} IN OUT", args[0]);
43 std::process::exit(1);
44 }
45 }
46}
Sourcepub fn push_inst(&mut self, inst: &InstWithIds) -> Result<()>
pub fn push_inst(&mut self, inst: &InstWithIds) -> Result<()>
Examples found in repository?
examples/spv-read-write-roundtrip.rs (line 36)
1fn main() -> std::io::Result<()> {
2 match &std::env::args().collect::<Vec<_>>()[..] {
3 [_, in_file, out_file] => {
4 let parser = spirt::spv::read::ModuleParser::read_from_spv_file(in_file)?;
5 let mut emitter = spirt::spv::write::ModuleEmitter::with_header(parser.header);
6
7 {
8 // FIXME(eddyb) show more of the header.
9 let [_, v, ..] = parser.header;
10 eprintln!("SPIR-V {}.{} module:", v >> 16, (v >> 8) & 0xff);
11 }
12
13 for inst in parser {
14 let inst = inst.unwrap();
15
16 eprint!(" ");
17
18 if let Some(id) = inst.result_id {
19 eprint!("%{id}");
20 if let Some(type_id) = inst.result_type_id {
21 eprint!(": %{type_id}");
22 }
23 eprint!(" = ");
24 }
25
26 eprint!("{}", inst.opcode.name());
27 spirt::spv::print::inst_operands(
28 inst.opcode,
29 inst.imms.iter().copied(),
30 inst.ids.iter().map(|id| format!("%{id}")),
31 )
32 .for_each(|operand_parts| eprint!(" {}", operand_parts.concat_to_plain_text()));
33
34 eprintln!();
35
36 emitter.push_inst(&inst).unwrap();
37 }
38
39 emitter.write_to_spv_file(out_file)
40 }
41 args => {
42 eprintln!("Usage: {} IN OUT", args[0]);
43 std::process::exit(1);
44 }
45 }
46}
Sourcepub fn write_to_spv_file(&self, path: impl AsRef<Path>) -> Result<()>
pub fn write_to_spv_file(&self, path: impl AsRef<Path>) -> Result<()>
Examples found in repository?
examples/spv-read-write-roundtrip.rs (line 39)
1fn main() -> std::io::Result<()> {
2 match &std::env::args().collect::<Vec<_>>()[..] {
3 [_, in_file, out_file] => {
4 let parser = spirt::spv::read::ModuleParser::read_from_spv_file(in_file)?;
5 let mut emitter = spirt::spv::write::ModuleEmitter::with_header(parser.header);
6
7 {
8 // FIXME(eddyb) show more of the header.
9 let [_, v, ..] = parser.header;
10 eprintln!("SPIR-V {}.{} module:", v >> 16, (v >> 8) & 0xff);
11 }
12
13 for inst in parser {
14 let inst = inst.unwrap();
15
16 eprint!(" ");
17
18 if let Some(id) = inst.result_id {
19 eprint!("%{id}");
20 if let Some(type_id) = inst.result_type_id {
21 eprint!(": %{type_id}");
22 }
23 eprint!(" = ");
24 }
25
26 eprint!("{}", inst.opcode.name());
27 spirt::spv::print::inst_operands(
28 inst.opcode,
29 inst.imms.iter().copied(),
30 inst.ids.iter().map(|id| format!("%{id}")),
31 )
32 .for_each(|operand_parts| eprint!(" {}", operand_parts.concat_to_plain_text()));
33
34 eprintln!();
35
36 emitter.push_inst(&inst).unwrap();
37 }
38
39 emitter.write_to_spv_file(out_file)
40 }
41 args => {
42 eprintln!("Usage: {} IN OUT", args[0]);
43 std::process::exit(1);
44 }
45 }
46}
Auto Trait Implementations§
impl Freeze for ModuleEmitter
impl RefUnwindSafe for ModuleEmitter
impl Send for ModuleEmitter
impl Sync for ModuleEmitter
impl Unpin for ModuleEmitter
impl UnwindSafe for ModuleEmitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more