spirt::spv::write

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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fn main() -> std::io::Result<()> {
    match &std::env::args().collect::<Vec<_>>()[..] {
        [_, in_file, out_file] => {
            let parser = spirt::spv::read::ModuleParser::read_from_spv_file(in_file)?;
            let mut emitter = spirt::spv::write::ModuleEmitter::with_header(parser.header);

            {
                // FIXME(eddyb) show more of the header.
                let [_, v, ..] = parser.header;
                eprintln!("SPIR-V {}.{} module:", v >> 16, (v >> 8) & 0xff);
            }

            for inst in parser {
                let inst = inst.unwrap();

                eprint!("  ");

                if let Some(id) = inst.result_id {
                    eprint!("%{id}");
                    if let Some(type_id) = inst.result_type_id {
                        eprint!(": %{type_id}");
                    }
                    eprint!(" = ");
                }

                eprint!("{}", inst.opcode.name());
                spirt::spv::print::inst_operands(
                    inst.opcode,
                    inst.imms.iter().copied(),
                    inst.ids.iter().map(|id| format!("%{id}")),
                )
                .for_each(|operand_parts| eprint!(" {}", operand_parts.concat_to_plain_text()));

                eprintln!();

                emitter.push_inst(&inst).unwrap();
            }

            emitter.write_to_spv_file(out_file)
        }
        args => {
            eprintln!("Usage: {} IN OUT", args[0]);
            std::process::exit(1);
        }
    }
}
source

pub fn push_inst(&mut self, inst: &InstWithIds) -> Result<()>

Examples found in repository?
examples/spv-read-write-roundtrip.rs (line 36)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fn main() -> std::io::Result<()> {
    match &std::env::args().collect::<Vec<_>>()[..] {
        [_, in_file, out_file] => {
            let parser = spirt::spv::read::ModuleParser::read_from_spv_file(in_file)?;
            let mut emitter = spirt::spv::write::ModuleEmitter::with_header(parser.header);

            {
                // FIXME(eddyb) show more of the header.
                let [_, v, ..] = parser.header;
                eprintln!("SPIR-V {}.{} module:", v >> 16, (v >> 8) & 0xff);
            }

            for inst in parser {
                let inst = inst.unwrap();

                eprint!("  ");

                if let Some(id) = inst.result_id {
                    eprint!("%{id}");
                    if let Some(type_id) = inst.result_type_id {
                        eprint!(": %{type_id}");
                    }
                    eprint!(" = ");
                }

                eprint!("{}", inst.opcode.name());
                spirt::spv::print::inst_operands(
                    inst.opcode,
                    inst.imms.iter().copied(),
                    inst.ids.iter().map(|id| format!("%{id}")),
                )
                .for_each(|operand_parts| eprint!(" {}", operand_parts.concat_to_plain_text()));

                eprintln!();

                emitter.push_inst(&inst).unwrap();
            }

            emitter.write_to_spv_file(out_file)
        }
        args => {
            eprintln!("Usage: {} IN OUT", args[0]);
            std::process::exit(1);
        }
    }
}
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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fn main() -> std::io::Result<()> {
    match &std::env::args().collect::<Vec<_>>()[..] {
        [_, in_file, out_file] => {
            let parser = spirt::spv::read::ModuleParser::read_from_spv_file(in_file)?;
            let mut emitter = spirt::spv::write::ModuleEmitter::with_header(parser.header);

            {
                // FIXME(eddyb) show more of the header.
                let [_, v, ..] = parser.header;
                eprintln!("SPIR-V {}.{} module:", v >> 16, (v >> 8) & 0xff);
            }

            for inst in parser {
                let inst = inst.unwrap();

                eprint!("  ");

                if let Some(id) = inst.result_id {
                    eprint!("%{id}");
                    if let Some(type_id) = inst.result_type_id {
                        eprint!(": %{type_id}");
                    }
                    eprint!(" = ");
                }

                eprint!("{}", inst.opcode.name());
                spirt::spv::print::inst_operands(
                    inst.opcode,
                    inst.imms.iter().copied(),
                    inst.ids.iter().map(|id| format!("%{id}")),
                )
                .for_each(|operand_parts| eprint!(" {}", operand_parts.concat_to_plain_text()));

                eprintln!();

                emitter.push_inst(&inst).unwrap();
            }

            emitter.write_to_spv_file(out_file)
        }
        args => {
            eprintln!("Usage: {} IN OUT", args[0]);
            std::process::exit(1);
        }
    }
}

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.