Skip to content

Commit

Permalink
Support const args in asm! (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
khyperia authored Feb 12, 2021
1 parent edbbf38 commit 56067de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> {
*line.last_mut().unwrap() =
Token::Typeof(&operands[operand_idx], span, kind)
}
None => line.push(Token::Placeholder(&operands[operand_idx], span)),
None => match &operands[operand_idx] {
InlineAsmOperandRef::Const { string } => line.push(Token::Word(string)),
item => line.push(Token::Placeholder(item, span)),
},
}
}
}
Expand Down Expand Up @@ -249,7 +252,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
.def(self.span(), self),
Op::TypeVector => SpirvType::Vector {
element: inst.operands[0].unwrap_id_ref(),
count: inst.operands[0].unwrap_literal_int32(),
count: inst.operands[1].unwrap_literal_int32(),
}
.def(self.span(), self),
Op::TypeArray => {
Expand Down
21 changes: 21 additions & 0 deletions crates/spirv-builder/src/test/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ OpFunctionEnd"#,
);
}

#[test]
fn asm_const_arg() {
val(r#"
fn asm() {
unsafe {
const N: usize = 3;
asm!(
"%int = OpTypeInt 32 0",
"%type = OpTypeVector %int {len}",
len = const N,
);
}
}
#[allow(unused_attributes)]
#[spirv(fragment)]
pub fn main() {
asm();
}
"#);
}

#[test]
fn logical_and() {
val(r#"
Expand Down

0 comments on commit 56067de

Please sign in to comment.