Move debug_flags definition out of the generator

This commit is contained in:
Benjamin Saunders 2021-12-21 15:21:49 -08:00
parent 0ae56a0961
commit e34f755ece
5 changed files with 32 additions and 54 deletions

View file

@ -25,7 +25,9 @@
*
**********************************************************************************************************************/
use crate::prelude::debug_flags;
use crate::vk::*;
use std::fmt;
use std::os::raw::*;

View file

@ -1,4 +1,5 @@
use std::convert::TryInto;
use std::fmt;
use crate::vk;
pub type VkResult<T> = Result<T, vk::Result>;
@ -81,3 +82,30 @@ where
}
}
}
pub(crate) fn debug_flags<Value: Into<u64> + Copy>(
f: &mut fmt::Formatter,
known: &[(Value, &'static str)],
value: Value,
) -> fmt::Result {
let mut first = true;
let mut accum = value.into();
for &(bit, name) in known {
let bit = bit.into();
if bit != 0 && accum & bit == bit {
if !first {
f.write_str(" | ")?;
}
f.write_str(name)?;
first = false;
accum &= !bit;
}
}
if accum != 0 {
if !first {
f.write_str(" | ")?;
}
write!(f, "{:b}", accum)?;
}
Ok(())
}

View file

@ -11,7 +11,6 @@ pub use aliases::*;
mod bitflags;
pub use bitflags::*;
mod const_debugs;
pub(crate) use const_debugs::*;
mod constants;
pub use constants::*;
mod definitions;

View file

@ -1,33 +1,8 @@
use crate::prelude::debug_flags;
use crate::vk::bitflags::*;
use crate::vk::definitions::*;
use crate::vk::enums::*;
use std::fmt;
pub(crate) fn debug_flags<Value: Into<u64> + Copy>(
f: &mut fmt::Formatter,
known: &[(Value, &'static str)],
value: Value,
) -> fmt::Result {
let mut first = true;
let mut accum = value.into();
for &(bit, name) in known {
let bit = bit.into();
if bit != 0 && accum & bit == bit {
if !first {
f.write_str(" | ")?;
}
f.write_str(name)?;
first = false;
accum &= !bit;
}
}
if accum != 0 {
if !first {
f.write_str(" | ")?;
}
write!(f, "{:b}", accum)?;
}
Ok(())
}
impl fmt::Debug for AccelerationStructureBuildTypeKHR {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let name = match *self {

View file

@ -2461,33 +2461,6 @@ pub fn generate_const_debugs(const_values: &BTreeMap<Ident, ConstantTypeInfo>) -
}
});
quote! {
pub(crate) fn debug_flags<Value: Into<u64> + Copy>(
f: &mut fmt::Formatter,
known: &[(Value, &'static str)],
value: Value,
) -> fmt::Result {
let mut first = true;
let mut accum = value.into();
for &(bit, name) in known {
let bit = bit.into();
if bit != 0 && accum & bit == bit {
if !first {
f.write_str(" | ")?;
}
f.write_str(name)?;
first = false;
accum &= !bit;
}
}
if accum != 0 {
if !first {
f.write_str(" | ")?;
}
write!(f, "{:b}", accum)?;
}
Ok(())
}
#(#impls)*
}
}
@ -2823,6 +2796,7 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
use crate::vk::bitflags::*;
use crate::vk::definitions::*;
use crate::vk::enums::*;
use crate::prelude::debug_flags;
#const_debugs
};