From e1019257d1b05b93f2e55b59860fc62e12f746fd Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 18 Oct 2018 21:52:39 -0700 Subject: [PATCH] split shader compiler backend into separate crate --- Cargo.toml | 4 +-- .../Cargo.toml | 4 +-- .../build.rs | 0 .../src/backend.rs | 2 +- .../src/lib.rs | 7 +++-- .../src/tests.rs | 4 +-- .../Cargo.toml | 2 +- .../src/lib.rs | 26 +++++++++++++++- .../src}/types.rs | 16 +++++----- shader-compiler/src/lib.rs | 31 ------------------- vulkan-driver/Cargo.toml | 4 +-- vulkan-driver/src/lib.rs | 2 +- 12 files changed, 49 insertions(+), 53 deletions(-) rename {shader-compiler-llvm-7 => shader-compiler-backend-llvm-7}/Cargo.toml (78%) rename {shader-compiler-llvm-7 => shader-compiler-backend-llvm-7}/build.rs (100%) rename {shader-compiler-llvm-7 => shader-compiler-backend-llvm-7}/src/backend.rs (99%) rename {shader-compiler-llvm-7 => shader-compiler-backend-llvm-7}/src/lib.rs (75%) rename {shader-compiler-llvm-7 => shader-compiler-backend-llvm-7}/src/tests.rs (97%) rename {shader-compiler => shader-compiler-backend}/Cargo.toml (87%) rename shader-compiler/src/backend/mod.rs => shader-compiler-backend/src/lib.rs (95%) rename {shader-compiler/src/backend => shader-compiler-backend/src}/types.rs (96%) delete mode 100644 shader-compiler/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index e4c4905..be9c384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ # Copyright 2018 Jacob Lifshay [workspace] members = [ - "shader-compiler", - "shader-compiler-llvm-7", + "shader-compiler-backend", + "shader-compiler-backend-llvm-7", "vulkan-driver", ] diff --git a/shader-compiler-llvm-7/Cargo.toml b/shader-compiler-backend-llvm-7/Cargo.toml similarity index 78% rename from shader-compiler-llvm-7/Cargo.toml rename to shader-compiler-backend-llvm-7/Cargo.toml index b353559..323b2b8 100644 --- a/shader-compiler-llvm-7/Cargo.toml +++ b/shader-compiler-backend-llvm-7/Cargo.toml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # Copyright 2018 Jacob Lifshay [package] -name = "shader-compiler-llvm-7" +name = "shader-compiler-backend-llvm-7" version = "0.1.0" authors = ["Jacob Lifshay "] license = "LGPL-2.1-or-later" @@ -10,7 +10,7 @@ license = "LGPL-2.1-or-later" crate-type = ["rlib"] [dependencies] -shader-compiler = {path = "../shader-compiler"} +shader-compiler-backend = {path = "../shader-compiler-backend"} [build-dependencies] cmake = "0.1.35" diff --git a/shader-compiler-llvm-7/build.rs b/shader-compiler-backend-llvm-7/build.rs similarity index 100% rename from shader-compiler-llvm-7/build.rs rename to shader-compiler-backend-llvm-7/build.rs diff --git a/shader-compiler-llvm-7/src/backend.rs b/shader-compiler-backend-llvm-7/src/backend.rs similarity index 99% rename from shader-compiler-llvm-7/src/backend.rs rename to shader-compiler-backend-llvm-7/src/backend.rs index 26964bf..95bfa5a 100644 --- a/shader-compiler-llvm-7/src/backend.rs +++ b/shader-compiler-backend-llvm-7/src/backend.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright 2018 Jacob Lifshay use llvm; -use shader_compiler::backend; +use shader_compiler_backend as backend; use std::cell::RefCell; use std::collections::HashMap; use std::collections::HashSet; diff --git a/shader-compiler-llvm-7/src/lib.rs b/shader-compiler-backend-llvm-7/src/lib.rs similarity index 75% rename from shader-compiler-llvm-7/src/lib.rs rename to shader-compiler-backend-llvm-7/src/lib.rs index d797122..c840645 100644 --- a/shader-compiler-llvm-7/src/lib.rs +++ b/shader-compiler-backend-llvm-7/src/lib.rs @@ -1,8 +1,11 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright 2018 Jacob Lifshay -extern crate shader_compiler; +extern crate shader_compiler_backend; -#[cfg_attr(feature = "cargo-clippy", allow(clippy::const_static_lifetime))] +#[cfg_attr( + feature = "cargo-clippy", + allow(clippy::const_static_lifetime) +)] #[allow(dead_code)] #[allow(non_upper_case_globals)] #[allow(non_camel_case_types)] diff --git a/shader-compiler-llvm-7/src/tests.rs b/shader-compiler-backend-llvm-7/src/tests.rs similarity index 97% rename from shader-compiler-llvm-7/src/tests.rs rename to shader-compiler-backend-llvm-7/src/tests.rs index ac532cf..a679e71 100644 --- a/shader-compiler-llvm-7/src/tests.rs +++ b/shader-compiler-backend-llvm-7/src/tests.rs @@ -4,8 +4,8 @@ // we have a tests module inside a tests module to have rls parse this tests.rs file #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] mod tests { - use shader_compiler::backend::types::TypeBuilder; - use shader_compiler::backend::*; + use shader_compiler_backend::types::TypeBuilder; + use shader_compiler_backend::*; use std::mem; fn make_compiler() -> impl Compiler { diff --git a/shader-compiler/Cargo.toml b/shader-compiler-backend/Cargo.toml similarity index 87% rename from shader-compiler/Cargo.toml rename to shader-compiler-backend/Cargo.toml index 25f1138..ec8fc80 100644 --- a/shader-compiler/Cargo.toml +++ b/shader-compiler-backend/Cargo.toml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # Copyright 2018 Jacob Lifshay [package] -name = "shader-compiler" +name = "shader-compiler-backend" version = "0.1.0" authors = ["Jacob Lifshay "] license = "LGPL-2.1-or-later" diff --git a/shader-compiler/src/backend/mod.rs b/shader-compiler-backend/src/lib.rs similarity index 95% rename from shader-compiler/src/backend/mod.rs rename to shader-compiler-backend/src/lib.rs index 97f7441..0c3e1c3 100644 --- a/shader-compiler/src/backend/mod.rs +++ b/shader-compiler-backend/src/lib.rs @@ -1,7 +1,8 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright 2018 Jacob Lifshay +#![deny(missing_docs)] -//! Shader Compiler Backend traits +//! Shader Compiler Backend Traits for Kazan use std::collections::HashMap; use std::error::Error; @@ -249,3 +250,26 @@ pub trait Compiler: Copy + Send + Sync + 'static { config: Self::Config, ) -> Result>, U::Error>; } + +#[cfg(test)] +mod test { + #![allow(dead_code)] + + buildable_struct!{ + struct S1 { + } + } + + buildable_struct!{ + pub struct S2 { + v: u32, + } + } + + buildable_struct!{ + struct S3 { + p: *mut S2, + v: ::types::VecNx4, + } + } +} diff --git a/shader-compiler/src/backend/types.rs b/shader-compiler-backend/src/types.rs similarity index 96% rename from shader-compiler/src/backend/types.rs rename to shader-compiler-backend/src/types.rs index c364796..19167c8 100644 --- a/shader-compiler/src/backend/types.rs +++ b/shader-compiler-backend/src/types.rs @@ -3,7 +3,7 @@ //! types in backend IR -use backend::Context; +use super::Context; use std::cell::UnsafeCell; use std::fmt::Debug; use std::hash::Hash; @@ -18,23 +18,23 @@ macro_rules! buildable_struct_helper { $($member_name:ident: $member_type:ty,)* } } => { - impl $crate::backend::types::BuildableType for $name { - fn build<'a, Ty: $crate::backend::types::Type<'a>, TB: $crate::backend::types::TypeBuilder<'a, Ty>>(type_builder: &TB) -> Ty { - type_builder.build_struct(&[$(<$member_type as $crate::backend::types::BuildableType>::build(type_builder),)*]) + impl $crate::types::BuildableType for $name { + fn build<'a, Ty: $crate::types::Type<'a>, TB: $crate::types::TypeBuilder<'a, Ty>>(type_builder: &TB) -> Ty { + type_builder.build_struct(&[$(<$member_type as $crate::types::BuildableType>::build(type_builder),)*]) } } - impl $crate::backend::types::BuildableStruct for $name { + impl $crate::types::BuildableStruct for $name { fn get_members( - ) -> &'static [$crate::backend::types::BuildableStructMemberDescriptor] { + ) -> &'static [$crate::types::BuildableStructMemberDescriptor] { #[allow(dead_code, non_camel_case_types)] #[repr(usize)] enum MemberIndices { $($member_name,)* __Last, } - const MEMBERS: &'static [$crate::backend::types::BuildableStructMemberDescriptor] = &[ - $($crate::backend::types::BuildableStructMemberDescriptor { + const MEMBERS: &'static [$crate::types::BuildableStructMemberDescriptor] = &[ + $($crate::types::BuildableStructMemberDescriptor { name: stringify!($member_name), index: MemberIndices::$member_name as usize, },)* diff --git a/shader-compiler/src/lib.rs b/shader-compiler/src/lib.rs deleted file mode 100644 index bcbb3f0..0000000 --- a/shader-compiler/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1-or-later -// Copyright 2018 Jacob Lifshay -#![deny(missing_docs)] - -//! Shader Compiler for Kazan - -#[macro_use] -pub mod backend; - -#[cfg(test)] -mod test { - #![allow(dead_code)] - - buildable_struct!{ - struct S1 { - } - } - - buildable_struct!{ - pub struct S2 { - v: u32, - } - } - - buildable_struct!{ - struct S3 { - p: *mut S2, - v: ::backend::types::VecNx4, - } - } -} diff --git a/vulkan-driver/Cargo.toml b/vulkan-driver/Cargo.toml index b901326..ac2666d 100644 --- a/vulkan-driver/Cargo.toml +++ b/vulkan-driver/Cargo.toml @@ -14,8 +14,8 @@ crate-type = ["cdylib"] enum-map = "0.4" uuid = {version = "0.7", features = ["v5"]} sys-info = "0.5" -shader-compiler = {path = "../shader-compiler"} -shader-compiler-llvm-7 = {path = "../shader-compiler-llvm-7"} +shader-compiler-backend = {path = "../shader-compiler-backend"} +shader-compiler-backend-llvm-7 = {path = "../shader-compiler-backend-llvm-7"} [target.'cfg(unix)'.dependencies] xcb = {version = "0.8", features = ["shm"]} diff --git a/vulkan-driver/src/lib.rs b/vulkan-driver/src/lib.rs index 66fa5a7..8f297d9 100644 --- a/vulkan-driver/src/lib.rs +++ b/vulkan-driver/src/lib.rs @@ -7,7 +7,7 @@ extern crate enum_map; extern crate errno; #[cfg(unix)] extern crate libc; -extern crate shader_compiler; +extern crate shader_compiler_backend; extern crate sys_info; extern crate uuid; #[cfg(unix)] -- 2.30.2