@@ -15,6 +15,18 @@ use smallvec::SmallVec;
1515/// See `CUSTOM_EXT_INST_SET`'s docs for further constraints on the full name.
1616pub const CUSTOM_EXT_INST_SET_PREFIX : & str = concat ! ( "Rust." , env!( "CARGO_PKG_NAME" ) , "." ) ;
1717
18+ macro_rules! join_cargo_pkg_version_major_minor_patch {
19+ ( $sep: literal) => {
20+ concat!(
21+ env!( "CARGO_PKG_VERSION_MAJOR" ) ,
22+ $sep,
23+ env!( "CARGO_PKG_VERSION_MINOR" ) ,
24+ $sep,
25+ env!( "CARGO_PKG_VERSION_PATCH" ) ,
26+ )
27+ } ;
28+ }
29+
1830lazy_static ! {
1931 /// `OpExtInstImport` "instruction set" name for all Rust-GPU instructions.
2032 ///
@@ -30,10 +42,6 @@ lazy_static! {
3042 /// if the definitions of the custom instructions have changed - this is
3143 /// achieved by hashing the `SCHEMA` constant from `def_custom_insts!` below
3244 pub static ref CUSTOM_EXT_INST_SET : String = {
33- const VER_MAJOR : & str = env!( "CARGO_PKG_VERSION_MAJOR" ) ;
34- const VER_MINOR : & str = env!( "CARGO_PKG_VERSION_MINOR" ) ;
35- const VER_PATCH : & str = env!( "CARGO_PKG_VERSION_PATCH" ) ;
36-
3745 let schema_hash = {
3846 use rustc_data_structures:: stable_hasher:: StableHasher ;
3947 use std:: hash:: Hash ;
@@ -43,11 +51,47 @@ lazy_static! {
4351 let ( lo, hi) = hasher. finalize( ) ;
4452 ( lo as u128 ) | ( ( hi as u128 ) << 64 )
4553 } ;
46-
47- format!( "{CUSTOM_EXT_INST_SET_PREFIX}{VER_MAJOR}_{VER_MINOR}_{VER_PATCH }.{schema_hash:x}" )
54+ let version = join_cargo_pkg_version_major_minor_patch! ( "_" ) ;
55+ format!( "{CUSTOM_EXT_INST_SET_PREFIX}{version }.{schema_hash:x}" )
4856 } ;
4957}
5058
59+ pub fn register_to_spirt_context ( cx : & spirt:: Context ) {
60+ use spirt:: spv:: spec:: { ExtInstSetDesc , ExtInstSetInstructionDesc } ;
61+ cx. register_custom_ext_inst_set (
62+ & CUSTOM_EXT_INST_SET ,
63+ ExtInstSetDesc {
64+ // HACK(eddyb) this is the most compact form I've found, that isn't
65+ // outright lossy by omitting "Rust vs Rust-GPU" or the version.
66+ short_alias : Some (
67+ concat ! ( "Rust-GPU " , join_cargo_pkg_version_major_minor_patch!( "." ) ) . into ( ) ,
68+ ) ,
69+ instructions : SCHEMA
70+ . iter ( )
71+ . map ( |& ( i, name, operand_names) | {
72+ (
73+ i,
74+ ExtInstSetInstructionDesc {
75+ name : name. into ( ) ,
76+ operand_names : operand_names
77+ . iter ( )
78+ . map ( |name| {
79+ name. strip_prefix ( ".." )
80+ . unwrap_or ( name)
81+ . replace ( '_' , " " )
82+ . into ( )
83+ } )
84+ . collect ( ) ,
85+ is_debuginfo : name. contains ( "Debug" )
86+ || name. contains ( "InlinedCallFrame" ) ,
87+ } ,
88+ )
89+ } )
90+ . collect ( ) ,
91+ } ,
92+ ) ;
93+ }
94+
5195macro_rules! def_custom_insts {
5296 ( $( $num: literal => $name: ident $( { $( $field: ident) ,+ $( , ..$variadic_field: ident) ? $( , ) ? } ) ?) ,+ $( , ) ?) => {
5397 const SCHEMA : & [ ( u32 , & str , & [ & str ] ) ] = & [
0 commit comments