Move from vkxml to vk-parse

This commit is contained in:
Maik Klein 2018-06-04 11:26:14 +02:00
parent bfed51f8d3
commit dc378d7b9f
5 changed files with 26 additions and 23 deletions

View file

@ -2,4 +2,5 @@
members = [ members = [
"examples", "examples",
"ash", "ash",
"generator",
] ]

View file

@ -2,9 +2,6 @@
extern crate lazy_static; extern crate lazy_static;
extern crate libc; extern crate libc;
extern crate shared_library; extern crate shared_library;
extern crate enumflags;
#[macro_use]
extern crate enumflags_derive;
pub use instance::{DeviceError, Instance}; pub use instance::{DeviceError, Instance};
pub use device::Device; pub use device::Device;
pub use entry::{Entry, InstanceError, LoadingError}; pub use entry::{Entry, InstanceError, LoadingError};
@ -14,11 +11,10 @@ mod device;
mod entry; mod entry;
pub mod prelude; pub mod prelude;
pub mod vk; pub mod vk;
//mod allocator;
pub mod extensions; pub mod extensions;
pub mod version; pub mod version;
pub mod util; pub mod util;
mod vk_test; // mod vk_test;
pub trait RawPtr<T> { pub trait RawPtr<T> {
fn as_raw_ptr(&self) -> *const T; fn as_raw_ptr(&self) -> *const T;

View file

@ -4,7 +4,8 @@ version = "0.1.0"
authors = ["Maik Klein <maikklein@googlemail.com>"] authors = ["Maik Klein <maikklein@googlemail.com>"]
[dependencies] [dependencies]
vkxml = {path = "/home/maik/projects/vkxml"} vk-parse = {git = "https://github.com/krolli/vk-parse"}
vkxml = {git = "https://github.com/terrybrashaw/vkxml"}
#vkxml = {git = "https://github.com/maikklein/vkxml"} #vkxml = {git = "https://github.com/maikklein/vkxml"}
heck = "0.3.0" heck = "0.3.0"
proc-macro2 = "0.2.3" proc-macro2 = "0.2.3"

View file

@ -1,13 +1,13 @@
#[macro_use] #[macro_use]
extern crate generator; extern crate generator;
use std::fs::File;
use generator::*; use generator::*;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File;
use std::io::Write; use std::io::Write;
use std::path::Path;
fn main() { fn main() {
let file = File::open("New-Vulkan-XML-Format/vk_new.xml").expect("vknew"); //let file = File::open("New-Vulkan-XML-Format/vk_new.xml").expect("vknew");
let spec = vkxml::Registry::from_file(file).expect(""); let spec = vk_parse::parse_file_as_vkxml(Path::new("vk.xml"));
write_source_code(&spec); write_source_code(&spec);
} }

View file

@ -7,11 +7,12 @@ extern crate proc_macro2;
#[macro_use] #[macro_use]
extern crate quote; extern crate quote;
extern crate syn; extern crate syn;
pub extern crate vk_parse;
pub extern crate vkxml; pub extern crate vkxml;
use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
use proc_macro2::Term; use proc_macro2::Term;
use quote::Tokens; use quote::Tokens;
use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
use syn::Ident; use syn::Ident;
pub enum Constant { pub enum Constant {
@ -25,7 +26,7 @@ impl Constant {
pub fn value(&self) -> Option<i64> { pub fn value(&self) -> Option<i64> {
match *self { match *self {
Constant::Number(n) => Some(n as i64), Constant::Number(n) => Some(n as i64),
Constant::Hex(ref hex) => Some(hex.parse().expect("hex parse")), Constant::Hex(ref hex) => i64::from_str_radix(&hex, 16).ok(),
Constant::BitPos(pos) => Some((1 << pos) as i64), Constant::BitPos(pos) => Some((1 << pos) as i64),
_ => None, _ => None,
} }
@ -37,7 +38,7 @@ impl Constant {
quote!{#term} quote!{#term}
} }
Constant::Hex(ref s) => { Constant::Hex(ref s) => {
let term = Term::intern(s); let term = Term::intern(&format!("0x{}", s));
quote!{#term} quote!{#term}
} }
Constant::Text(ref text) => { Constant::Text(ref text) => {
@ -323,15 +324,19 @@ pub fn generate_typedef(typedef: &vkxml::Typedef) -> Tokens {
pub type #typedef_name = #typedef_ty; pub type #typedef_name = #typedef_ty;
} }
} }
pub fn generate_bitmask(bitmask: &vkxml::Bitmask) -> Tokens { pub fn generate_bitmask(bitmask: &vkxml::Bitmask) -> Option<Tokens> {
// Workaround for empty bitmask
if bitmask.name.len() == 0 {
return None;
}
let name = &bitmask.name[2..]; let name = &bitmask.name[2..];
let name_without_flags = name.replace("Flags", ""); let name_without_flags = name.replace("Flags", "");
let ident = Ident::from(name); let ident = Ident::from(name);
let ident_without_flags = Ident::from(name_without_flags.as_str()); let ident_without_flags = Ident::from(name_without_flags.as_str());
let type_token = to_type_tokens(&bitmask.basetype, None); let type_token = to_type_tokens(&bitmask.basetype, None);
quote!{ Some(quote!{
pub type #ident = BitFlags<flags::#ident_without_flags>; pub type #ident = BitFlags<flags::#ident_without_flags>;
} })
} }
pub fn to_variant_ident(enum_name: &str, variant_name: &str) -> Ident { pub fn to_variant_ident(enum_name: &str, variant_name: &str) -> Ident {
let tag = ["AMD", "NN", "KHR", "NV", "EXT", "NVX", "KHX"] let tag = ["AMD", "NN", "KHR", "NV", "EXT", "NVX", "KHX"]
@ -400,7 +405,7 @@ pub fn generate_enum(_enum: &vkxml::Enumeration) -> EnumType {
let (variant_name, value) = match *elem { let (variant_name, value) = match *elem {
vkxml::EnumerationElement::Enum(ref constant) => { vkxml::EnumerationElement::Enum(ref constant) => {
let c = Constant::from_constant(constant); let c = Constant::from_constant(constant);
println!("value {:?}", c.value()); //println!("value {:?}", c.value());
(constant.name.as_str(), c.to_tokens()) (constant.name.as_str(), c.to_tokens())
} }
_ => { _ => {
@ -446,12 +451,12 @@ pub fn generate_struct(_struct: &vkxml::Struct) -> Tokens {
} }
} }
} }
pub fn generate_definition(definition: &vkxml::DefinitionsElement) -> Tokens { pub fn generate_definition(definition: &vkxml::DefinitionsElement) -> Option<Tokens> {
match *definition { match *definition {
vkxml::DefinitionsElement::Typedef(ref typedef) => generate_typedef(typedef), vkxml::DefinitionsElement::Typedef(ref typedef) => Some(generate_typedef(typedef)),
vkxml::DefinitionsElement::Struct(ref _struct) => generate_struct(_struct), vkxml::DefinitionsElement::Struct(ref _struct) => Some(generate_struct(_struct)),
vkxml::DefinitionsElement::Bitmask(ref mask) => generate_bitmask(mask), vkxml::DefinitionsElement::Bitmask(ref mask) => generate_bitmask(mask),
_ => quote!{}, _ => None,
} }
} }
pub fn generate_core_spec(feature: &vkxml::Feature, commands: &CommandMap) -> quote::Tokens { pub fn generate_core_spec(feature: &vkxml::Feature, commands: &CommandMap) -> quote::Tokens {
@ -502,8 +507,8 @@ pub fn generate_core_spec(feature: &vkxml::Feature, commands: &CommandMap) -> qu
} }
pub fn write_source_code(spec: &vkxml::Registry) { pub fn write_source_code(spec: &vkxml::Registry) {
use std::io::Write;
use std::fs::File; use std::fs::File;
use std::io::Write;
let commands: HashMap<vkxml::Identifier, &vkxml::Command> = spec.elements let commands: HashMap<vkxml::Identifier, &vkxml::Command> = spec.elements
.iter() .iter()
.filter_map(|elem| match elem { .filter_map(|elem| match elem {
@ -576,7 +581,7 @@ pub fn write_source_code(spec: &vkxml::Registry) {
}, },
); );
let definition_code: Vec<_> = definitions.into_iter().map(generate_definition).collect(); let definition_code: Vec<_> = definitions.into_iter().filter_map(generate_definition).collect();
let feature_code: Vec<_> = features let feature_code: Vec<_> = features
.iter() .iter()