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

Try out winnow #86

Closed
wants to merge 13 commits into from
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ rustc-hash = "1.1.0"
unicode-ident = "1"
once_cell = "1.17.0"
indexmap = "2"
winnow = { version = "0.6.7", features = ["unstable-recover"] }
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }

[dev-dependencies]
wgpu = { version = "0.20", features = ["naga-ir"] }
futures-lite = "1"
tracing-subscriber = { version = "0.3", features = ["std", "fmt"] }

[patch.crates-io]
naga = { git = "https://github.com/stefnotch/wgpu/", branch = "compile-with-context" }
wgpu = { git = "https://github.com/stefnotch/wgpu/", branch = "compile-with-context" }
146 changes: 0 additions & 146 deletions src/compose/comment_strip_iter.rs

This file was deleted.

96 changes: 96 additions & 0 deletions src/compose/compiled_module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use std::collections::HashMap;

use naga::Handle;

use super::{composer::ModuleName, mangle};

pub trait NagaGlobalHandle {
fn name<'a>(&self, module: &'a naga::Module) -> Option<&'a str>;
fn mangled_name(&self, module: &CompiledModule) -> Option<String> {
self.name(&module.module)
.map(|name| mangle(&module.name, name))
}
}

impl NagaGlobalHandle for Handle<naga::Type> {
fn name<'a>(&self, module: &'a naga::Module) -> Option<&'a str> {
module
.types
.get_handle(*self)
.ok()
.and_then(|v| v.name.as_deref())
}
}

impl NagaGlobalHandle for Handle<naga::Constant> {
fn name<'a>(&self, module: &'a naga::Module) -> Option<&'a str> {
module
.constants
.try_get(*self)
.ok()
.and_then(|v| v.name.as_deref())
}
}

impl NagaGlobalHandle for Handle<naga::Override> {
fn name<'a>(&self, module: &'a naga::Module) -> Option<&'a str> {
module
.overrides
.try_get(*self)
.ok()
.and_then(|v| v.name.as_deref())
}
}

impl NagaGlobalHandle for Handle<naga::GlobalVariable> {
fn name<'a>(&self, module: &'a naga::Module) -> Option<&'a str> {
module
.global_variables
.try_get(*self)
.ok()
.and_then(|v| v.name.as_deref())
}
}

impl NagaGlobalHandle for Handle<naga::Function> {
fn name<'a>(&self, module: &'a naga::Module) -> Option<&'a str> {
module
.functions
.try_get(*self)
.ok()
.and_then(|v| v.name.as_deref())
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ModuleGlobal {
Struct(Handle<naga::Type>),
Constant(Handle<naga::Constant>),
Override(Handle<naga::Override>),
GlobalVariable(Handle<naga::GlobalVariable>),
Function(Handle<naga::Function>),
EntryPoint(String),
}

/// A module with mangled names.
/// And fragments of a header.
pub struct CompiledModule {
pub name: ModuleName,
/// Module with mangled names.
pub module: naga::Module,
/// Exports with the original names.
pub exports: HashMap<String, ModuleGlobal>,
}
impl CompiledModule {
pub fn get_export(&self, item_name: &str) -> Option<ModuleGlobal> {
self.exports.get(item_name).cloned()
}
}

pub struct FinalModuleData<'a> {
structs: HashMap<&'a str, Handle<naga::Type>>,
constants: HashMap<&'a str, Handle<naga::Constant>>,
overrides: HashMap<&'a str, Handle<naga::Override>>,
global_variables: HashMap<&'a str, Handle<naga::GlobalVariable>>,
functions: HashMap<&'a str, Handle<naga::Function>>,
}
Loading
Loading