use crate::spirv;
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct Instruction<'a> {
pub opname: &'a str,
pub opcode: spirv::Op,
pub capabilities: &'a [spirv::Capability],
pub extensions: &'a [&'a str],
pub operands: &'a [LogicalOperand],
}
pub struct ExtendedInstruction<'a> {
pub opname: &'a str,
pub opcode: spirv::Word,
pub capabilities: &'a [spirv::Capability],
pub extensions: &'a [&'a str],
pub operands: &'a [LogicalOperand],
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct LogicalOperand {
pub kind: OperandKind,
pub quantifier: OperandQuantifier,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum OperandQuantifier {
One,
ZeroOrOne,
ZeroOrMore,
}
macro_rules! inst {
($op:ident, [$( $cap:ident ),*], [$( $ext:expr ),*], [$( ($kind:ident, $quant:ident) ),*]) => {
Instruction {
opname: stringify!($op),
opcode: spirv::Op::$op,
capabilities: &[
$( spirv::Capability::$cap ),*
],
extensions: &[
$( $ext ),*
],
operands: &[
$( LogicalOperand {
kind: OperandKind::$kind,
quantifier: OperandQuantifier::$quant }
),*
],
}
}
}
macro_rules! ext_inst {
($opname:ident, $opcode: expr, [$( $cap:ident ),*], [$( $ext:expr ),*],
[$( ($kind:ident, $quant:ident) ),*]) => {
ExtendedInstruction {
opname: stringify!($opname),
opcode: $opcode,
capabilities: &[
$( spirv::Capability::$cap ),*
],
extensions: &[
$( $ext ),*
],
operands: &[
$( LogicalOperand {
kind: OperandKind::$kind,
quantifier: OperandQuantifier::$quant }
),*
],
}
}
}
pub struct CoreInstructionTable;
impl CoreInstructionTable {
pub fn lookup_opcode(opcode: u16) -> Option<&'static Instruction<'static>> {
INSTRUCTION_TABLE
.iter()
.find(|inst| (inst.opcode as u16) == opcode)
}
pub fn get(opcode: spirv::Op) -> &'static Instruction<'static> {
INSTRUCTION_TABLE
.iter()
.find(|inst| (inst.opcode == opcode))
.expect("internal error")
}
pub fn iter() -> impl Iterator<Item = &'static Instruction<'static>> {
INSTRUCTION_TABLE.iter()
}
}
include!("autogen_table.rs");
pub struct GlslStd450InstructionTable;
impl GlslStd450InstructionTable {
pub fn lookup_opcode(opcode: u32) -> Option<&'static ExtendedInstruction<'static>> {
GLSL_STD_450_INSTRUCTION_TABLE
.iter()
.find(|inst| inst.opcode == opcode)
}
pub fn get(opcode: spirv::GLOp) -> &'static ExtendedInstruction<'static> {
GLSL_STD_450_INSTRUCTION_TABLE
.iter()
.find(|inst| (inst.opcode == opcode as spirv::Word))
.expect("internal error")
}
pub fn iter() -> impl Iterator<Item = &'static ExtendedInstruction<'static>> {
GLSL_STD_450_INSTRUCTION_TABLE.iter()
}
}
include!("autogen_glsl_std_450.rs");
#[allow(clippy::upper_case_acronyms)]
pub struct OpenCLStd100InstructionTable;
impl OpenCLStd100InstructionTable {
pub fn lookup_opcode(opcode: u32) -> Option<&'static ExtendedInstruction<'static>> {
OPENCL_STD_100_INSTRUCTION_TABLE
.iter()
.find(|inst| inst.opcode == opcode)
}
pub fn get(opcode: spirv::CLOp) -> &'static ExtendedInstruction<'static> {
OPENCL_STD_100_INSTRUCTION_TABLE
.iter()
.find(|inst| (inst.opcode == opcode as spirv::Word))
.expect("internal error")
}
pub fn iter() -> impl Iterator<Item = &'static ExtendedInstruction<'static>> {
OPENCL_STD_100_INSTRUCTION_TABLE.iter()
}
}
include!("autogen_opencl_std_100.rs");