From ef4c9f1f1c297f1a33be95795a7a7561e0cc3bde Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Sat, 26 Aug 2023 01:42:34 +0800 Subject: Initial version of spirv_asm block (#3151) * Initial version of spirv_asm block * Correct indentation of parent instruction dumping * neater dumping for spirv_asm instructions * Add $$ DollarDollar token * Allow passing addresses to spirv_asm blocks * spirv OpUndef * String literals in spirv asm * OpName for spirv_asm ids * Correct failure in lower spirv_asm * correct position for spirv_asm idents * comment correct * several more tests for spirv_asm blocks * Fill out some unimplemented functions for spirv_asm expressions --------- Co-authored-by: Yong He --- source/slang/slang-check-expr.cpp | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'source/slang/slang-check-expr.cpp') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 3d2f81edb..5266f02f6 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -3895,4 +3895,64 @@ namespace Slang return expr; } + + Expr* SemanticsExprVisitor::visitSPIRVAsmExpr(SPIRVAsmExpr* expr) + { + // We will iterate over all the operands in all the insts and check + // them + for(auto& inst : expr->insts) + { + const bool isLast = &inst == &expr->insts.getLast(); + for(auto& operand : inst.operands) + { + if(operand.flavor == SPIRVAsmOperand::SlangType) + { + // This is a $$type operand, fill in the TypeExp member of the operand + TypeExp& typeExpr = operand.type; + typeExpr.exp = operand.expr; + typeExpr = CheckProperType(typeExpr); + operand.expr = typeExpr.exp; + } + else if(operand.flavor == SPIRVAsmOperand::SlangValue + || operand.flavor == SPIRVAsmOperand::SlangValueAddr) + { + // This is a $expr operand, check the expr + operand.expr = dispatch(operand.expr); + } + else if(operand.flavor == SPIRVAsmOperand::NamedValue + && operand.token.getContent() == "result") + { + // This is the marker, check that it only + // appears in the last instruction. + + // TODO: We could consider relaxing this, because SPIR-V + // does have forward references for decorations and such + if (!isLast) + { + getSink()->diagnose(operand.token, Diagnostics::misplacedResultIdMarker); + getSink()->diagnoseWithoutSourceView(expr, Diagnostics::considerOpCopyObject); + } + } + } + } + + // Assign the type of this expression from the type of the last + // instruction, otherwise void + if(expr->insts.getCount()) + { + // TODO: we trust that this is correct, but could should verify + const auto lastOperands = expr->insts.getLast().operands; + if(lastOperands.getCount() >= 2 + && lastOperands[0].flavor == SPIRVAsmOperand::SlangType + && lastOperands[1].flavor == SPIRVAsmOperand::NamedValue + && lastOperands[1].token.getContent() == "result") + { + expr->type = lastOperands[0].type.type; + } + } + if(!expr->type) + expr->type = m_astBuilder->getVoidType(); + + return expr; + } } -- cgit v1.2.3