Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a % for Operand::IdRef Display impl #184

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
quote! {
Operand::#element(ref v) => write!(f, "{}", &format!("{:?}", v)[3..])
}
} else if element == "IdRef" || element == "IdScope" || element == "IdMemorySemantics" {
// Prefix operands with a % so they're distinguishable from e.g. integer arguments.
quote! {
Operand::#element(ref v) => write!(f, "%{}", v)
}
} else {
quote! {
Operand::#element(ref v) => write!(f, "{:?}", v)
Expand Down
6 changes: 3 additions & 3 deletions rspirv/dr/autogen_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ impl fmt::Display for Operand {
Operand::RayQueryIntersection(ref v) => write!(f, "{:?}", v),
Operand::RayQueryCommittedIntersectionType(ref v) => write!(f, "{:?}", v),
Operand::RayQueryCandidateIntersectionType(ref v) => write!(f, "{:?}", v),
Operand::IdMemorySemantics(ref v) => write!(f, "{:?}", v),
Operand::IdScope(ref v) => write!(f, "{:?}", v),
Operand::IdRef(ref v) => write!(f, "{:?}", v),
Operand::IdMemorySemantics(ref v) => write!(f, "%{}", v),
Operand::IdScope(ref v) => write!(f, "%{}", v),
Operand::IdRef(ref v) => write!(f, "%{}", v),
Operand::LiteralString(ref v) => write!(f, "{:?}", v),
Operand::LiteralExtInstInteger(ref v) => write!(f, "{:?}", v),
Operand::LiteralSpecConstantOpInteger(ref v) => write!(f, "{:?}", v),
Expand Down
13 changes: 13 additions & 0 deletions rspirv/dr/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,17 @@ mod tests {
dr::Operand::from(spirv::Op::IAdd)
);
}

#[test]
fn test_operand_display() {
assert_eq!(
format!(
"{}",
dr::Operand::FunctionControl(spirv::FunctionControl::INLINE)
),
"INLINE",
);
assert_eq!(format!("{}", dr::Operand::IdRef(3)), "%3");
assert_eq!(format!("{}", dr::Operand::LiteralInt32(3)), "3");
}
}