Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autogen/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn gen_value_enum_operand_kind(grammar: &structs::OperandKind) -> TokenStream {

/// Returns the code defining the enum for an operand kind by parsing
/// the given SPIR-V `grammar`.
fn gen_operand_kind(grammar: &structs::OperandKind) -> Option<TokenStream> {
pub fn gen_operand_kind(grammar: &structs::OperandKind) -> Option<TokenStream> {
use structs::Category::*;
match grammar.category {
BitEnum => Some(gen_bit_enum_operand_kind(grammar)),
Expand Down
19 changes: 16 additions & 3 deletions autogen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ mod table;
mod utils;

use std::{
env, fs,
env,
fs,
io::Write,
path::{Path, PathBuf},
process,
Expand Down Expand Up @@ -132,6 +133,7 @@ fn main() {
("GLSL.std.450", "GLOp", "https://www.khronos.org/registry/spir-v/specs/unified1/GLSL.std.450.html"),
("OpenCL.std.100", "CLOp", "https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.ExtendedInstructionSet.100.html"),
("NonSemantic.DebugPrintF", "DebugPrintFOp", "https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/docs/debug_printf.md"),
("NonSemantic.Shader.DebugInfo.100", "DebugInfoOp", "https://github.khronos.org/SPIRV-Registry/nonsemantic/NonSemantic.Shader.DebugInfo.100.html"),
];
let extended_instruction_sets = extended_instruction_sets.map(|(ext, op, url)| {
let grammar: structs::ExtInstSetGrammar = serde_json::from_str(
Expand All @@ -148,6 +150,16 @@ fn main() {
// SPIR-V header
write_formatted(&autogen_src_dir.join("../spirv/autogen_spirv.rs"), {
let core = header::gen_spirv_header(&grammar);
let extended_instruction_operands =
extended_instruction_sets
.iter()
.flat_map(|(_, _, _, grammar)| {
grammar
.operand_kinds
.iter()
.filter_map(header::gen_operand_kind)
.map(|kind| kind.to_string())
});
let extended_instruction_sets =
extended_instruction_sets
.iter()
Expand All @@ -160,9 +172,10 @@ fn main() {
.to_string()
});
format!(
"{}\n{}",
"{}\n{}\n{}",
core,
extended_instruction_sets.collect::<Vec<_>>().join("\n")
extended_instruction_sets.collect::<Vec<_>>().join("\n"),
extended_instruction_operands.collect::<Vec<_>>().join("\n"),
)
});

Expand Down
8 changes: 7 additions & 1 deletion autogen/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct ExtInstSetGrammar {
pub version: Option<u32>,
pub revision: u32,
pub instructions: Vec<Instruction>,
#[serde(default)]
pub operand_kinds: Vec<OperandKind>,
}

fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result<u32, D::Error> {
Expand All @@ -92,7 +94,11 @@ fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result<u32, D::Err
}

fn visit_str<E: de::Error>(self, value: &str) -> result::Result<Self::Value, E> {
Ok(u32::from_str_radix(&value[2..], 16).unwrap())
if let Some(value) = value.strip_prefix("0x") {
Ok(u32::from_str_radix(value, 16).unwrap())
} else {
Ok(value.parse::<u32>().unwrap())
}
}

fn visit_u64<E: de::Error>(self, value: u64) -> result::Result<Self::Value, E> {
Expand Down
Loading