Struct ModuleEmitter

Source
pub struct ModuleEmitter {
    pub words: Vec<u32>,
}

Fields§

§words: Vec<u32>

Output SPIR-V words.

Implementations§

Source§

impl ModuleEmitter

Source

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}
Source

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}
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.