MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / parse

Method parse

crates/rustc_codegen_spirv/src/builder/spirv_asm.rs:1091–1128  ·  view source on GitHub ↗
(ty: SpirvType<'_>, w: &str)

Source from the content-addressed store, hash-verified

1089 assert!(matches!(inst.class.opcode, Op::Constant | Op::SpecConstant));
1090 let ty = inst.result_type.unwrap();
1091 fn parse(ty: SpirvType<'_>, w: &str) -> Result<dr::Operand, String> {
1092 fn fmt(x: impl ToString) -> String {
1093 x.to_string()
1094 }
1095 Ok(match ty {
1096 SpirvType::Integer(8, false) => {
1097 dr::Operand::LiteralInt32(w.parse::<u8>().map_err(fmt)? as u32)
1098 }
1099 SpirvType::Integer(16, false) => {
1100 dr::Operand::LiteralInt32(w.parse::<u16>().map_err(fmt)? as u32)
1101 }
1102 SpirvType::Integer(32, false) => {
1103 dr::Operand::LiteralInt32(w.parse::<u32>().map_err(fmt)?)
1104 }
1105 SpirvType::Integer(64, false) => {
1106 dr::Operand::LiteralInt64(w.parse::<u64>().map_err(fmt)?)
1107 }
1108 SpirvType::Integer(8, true) => {
1109 dr::Operand::LiteralInt32(w.parse::<i8>().map_err(fmt)? as i32 as u32)
1110 }
1111 SpirvType::Integer(16, true) => {
1112 dr::Operand::LiteralInt32(w.parse::<i16>().map_err(fmt)? as i32 as u32)
1113 }
1114 SpirvType::Integer(32, true) => {
1115 dr::Operand::LiteralInt32(w.parse::<i32>().map_err(fmt)? as u32)
1116 }
1117 SpirvType::Integer(64, true) => {
1118 dr::Operand::LiteralInt64(w.parse::<i64>().map_err(fmt)? as u64)
1119 }
1120 SpirvType::Float(32) => {
1121 dr::Operand::LiteralFloat32(w.parse::<f32>().map_err(fmt)?)
1122 }
1123 SpirvType::Float(64) => {
1124 dr::Operand::LiteralFloat64(w.parse::<f64>().map_err(fmt)?)
1125 }
1126 _ => return Err("expected number literal in OpConstant".to_string()),
1127 })
1128 }
1129 match parse(self.lookup_type(ty), word) {
1130 Ok(op) => inst.operands.push(op),
1131 Err(err) => self.err(&err),

Callers 1

parse_one_operandMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected