Convert the crate to a library crate
This commit is contained in:
parent
e35f178011
commit
c7529b82b7
|
@ -220,18 +220,6 @@ dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shader_prepoc"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"pest",
|
|
||||||
"pest_derive",
|
|
||||||
"regex",
|
|
||||||
"thiserror",
|
|
||||||
"tracing",
|
|
||||||
"tracing-subscriber",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sharded-slab"
|
name = "sharded-slab"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
|
@ -375,6 +363,18 @@ version = "0.9.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wgsl_preprocessor"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"pest",
|
||||||
|
"pest_derive",
|
||||||
|
"regex",
|
||||||
|
"thiserror",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "shader_prepoc"
|
name = "wgsl_preprocessor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
|
@ -13,79 +13,6 @@ pub use preprocessor::*;
|
||||||
#[grammar = "wgsl.pest"]
|
#[grammar = "wgsl.pest"]
|
||||||
pub(crate) struct WgslParser;
|
pub(crate) struct WgslParser;
|
||||||
|
|
||||||
fn main() {
|
|
||||||
tracing_subscriber::fmt()
|
|
||||||
// enable everything
|
|
||||||
.with_max_level(tracing::Level::TRACE)
|
|
||||||
// sets this to be the default, global collector for this application.
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let mut p = Processor::new();
|
|
||||||
let inner_include_src = fs::read_to_string("shaders/inner_include.wgsl").unwrap();
|
|
||||||
p.parse_module(&inner_include_src)
|
|
||||||
.unwrap()
|
|
||||||
.expect("failed to find module");
|
|
||||||
|
|
||||||
let simple_include_src = fs::read_to_string("shaders/simple.wgsl").unwrap();
|
|
||||||
p.parse_module(&simple_include_src)
|
|
||||||
.unwrap()
|
|
||||||
.expect("failed to find module");
|
|
||||||
|
|
||||||
let base_include_src = fs::read_to_string("shaders/base.wgsl").unwrap();
|
|
||||||
let base_module_path = p.parse_module(&base_include_src)
|
|
||||||
.unwrap()
|
|
||||||
.expect("failed to find module");
|
|
||||||
|
|
||||||
for (name, module) in &p.modules {
|
|
||||||
println!("{name}:");
|
|
||||||
|
|
||||||
if !module.constants.is_empty() || !module.functions.is_empty() {
|
|
||||||
println!(" defines:");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (name, def) in &module.constants {
|
|
||||||
println!(" const {name}, {}-{}", def.start_pos, def.end_pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (name, def) in &module.functions {
|
|
||||||
let requires: Vec<String> = def.requirements.iter().map(|r| {
|
|
||||||
let pre = r.module.as_ref().map(|m| format!("{m}::")).unwrap_or_default();
|
|
||||||
format!("{}{}", pre, r.name)
|
|
||||||
}).collect();
|
|
||||||
println!(" fn {name}, {}-{}. requires: {:?}", def.start_pos, def.end_pos, requires);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(" imported modules: {:?}", module.module_imports);
|
|
||||||
|
|
||||||
if !module.item_imports.is_empty() {
|
|
||||||
println!(" type imports:");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (module, usages) in &module.item_imports {
|
|
||||||
println!(" {}: {:?}", module, usages.imports);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !module.import_usages.is_empty() {
|
|
||||||
println!(" usages:");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (module, usages) in &module.import_usages {
|
|
||||||
println!(" {}:", module);
|
|
||||||
|
|
||||||
for import in usages.iter() {
|
|
||||||
println!(
|
|
||||||
" {:?} `{}` at {}:",
|
|
||||||
import.ty, import.name, import.start_pos
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let base_include_src = fs::read_to_string("shaders/base.wgsl").unwrap();
|
|
||||||
let out = p.process_file(&base_module_path, &base_include_src).unwrap();
|
|
||||||
fs::write("out.wgsl", out).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum ExternalUsageType {
|
pub enum ExternalUsageType {
|
||||||
Variable,
|
Variable,
|
Loading…
Reference in New Issue