pub struct Printer<'a> {
cx: &'a Context,
use_styles: IndexMap<Use, UseStyle, BuildHasherDefault<FxHasher>>,
attrs_with_spv_name_in_use: FxHashMap<AttrSet, &'a Inst>,
}
Fields§
§cx: &'a Context
§use_styles: IndexMap<Use, UseStyle, BuildHasherDefault<FxHasher>>
§attrs_with_spv_name_in_use: FxHashMap<AttrSet, &'a Inst>
Subset of the Plan
’s original attrs_to_unique_spv_name
map, only
containing those entries which are actively used for UseStyle::Named
values in use_styles
, and therefore need to be hidden from attributes.
Implementations§
source§impl Printer<'_>
impl Printer<'_>
fn error_style(&self) -> Styles
fn comment_style(&self) -> Styles
fn named_argument_label_style(&self) -> Styles
fn numeric_literal_style(&self) -> Styles
fn string_literal_style(&self) -> Styles
fn string_literal_escape_style(&self) -> Styles
fn declarative_keyword_style(&self) -> Styles
fn imperative_keyword_style(&self) -> Styles
fn spv_base_style(&self) -> Styles
fn spv_op_style(&self) -> Styles
fn spv_enumerand_name_style(&self) -> Styles
fn attr_style(&self) -> Styles
sourcefn demote_style_for_namespace_prefix(&self, style: Styles) -> Styles
fn demote_style_for_namespace_prefix(&self, style: Styles) -> Styles
Compute a suitable style for an unintrusive foo.
“namespace prefix”,
from a more typical style (by shrinking and/or reducing visibility).
source§impl<'a> Printer<'a>
impl<'a> Printer<'a>
sourcefn pretty_string_literal(&self, s: &str) -> Fragment
fn pretty_string_literal(&self, s: &str) -> Fragment
Pretty-print a string literal with escaping and styling.
sourcefn pretty_named_argument_prefix<'b>(
&self,
name: impl Into<Cow<'b, str>>
) -> Fragment
fn pretty_named_argument_prefix<'b>( &self, name: impl Into<Cow<'b, str>> ) -> Fragment
Pretty-print a name:
style “named argument” prefix.
sourcefn pretty_type_ascription_suffix(&self, ty: Type) -> Fragment
fn pretty_type_ascription_suffix(&self, ty: Type) -> Fragment
Pretty-print a : T
style “type ascription” suffix.
This should be used everywhere some type ascription notation is needed, to ensure consistency across all such situations.
sourcefn pretty_spv_opcode(
&self,
opcode_name_style: Styles,
opcode: Opcode
) -> Fragment
fn pretty_spv_opcode( &self, opcode_name_style: Styles, opcode: Opcode ) -> Fragment
Pretty-print a SPIR-V opcode
’s name, prefixed by "spv."
.
sourcefn sanitize_spv_operand_name<'b>(&self, name: &'b str) -> Option<Cow<'b, str>>
fn sanitize_spv_operand_name<'b>(&self, name: &'b str) -> Option<Cow<'b, str>>
Clean up a spv::print::TokensForOperand
string (common helper used below).
sourcefn pretty_spv_print_tokens_for_operand(
&self,
operand: TokensForOperand<Option<Fragment>>
) -> Fragment
fn pretty_spv_print_tokens_for_operand( &self, operand: TokensForOperand<Option<Fragment>> ) -> Fragment
Pretty-print a spv::print::TokensForOperand
(common helper used below).
sourcefn pretty_spv_operand_from_imms(
&self,
imms: impl IntoIterator<Item = Imm>
) -> Fragment
fn pretty_spv_operand_from_imms( &self, imms: impl IntoIterator<Item = Imm> ) -> Fragment
Pretty-print a single SPIR-V operand from only immediates, potentially composed of an enumerand with parameters (which consumes more immediates).
sourcefn pretty_spv_imm(&self, kind: OperandKind, word: u32) -> Fragment
fn pretty_spv_imm(&self, kind: OperandKind, word: u32) -> Fragment
Pretty-print a single SPIR-V (short) immediate (e.g. an enumerand).
sourcefn pretty_spv_inst<OPF: Into<Option<Fragment>>>(
&self,
spv_inst_name_style: Styles,
opcode: Opcode,
imms: &[Imm],
printed_ids: impl IntoIterator<Item = OPF>
) -> Fragment
fn pretty_spv_inst<OPF: Into<Option<Fragment>>>( &self, spv_inst_name_style: Styles, opcode: Opcode, imms: &[Imm], printed_ids: impl IntoIterator<Item = OPF> ) -> Fragment
Pretty-print an arbitrary SPIR-V opcode
with its SPIR-V operands being
given by imms
(non-IDs) and printed_ids
(IDs, printed by the caller).
printed_ids
elements can be None
to indicate an ID operand is implicit
in SPIR-T, and should not be printed (e.g. decorations’ target IDs).
But if printed_ids
doesn’t need to have None
elements, it can skip
the Option
entirely (i.e. have pretty::Fragment
elements directly).
Immediate and ID
operands are interleaved (in the order mandated by
the SPIR-V standard) and together wrapped in parentheses, e.g.:
spv.OpFoo(spv.FooEnum.Bar, v1, 123, v2, "baz")
.
This should be used everywhere a SPIR-V instruction needs to be printed, to ensure consistency across all such situations.