summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-expr.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-08-26 01:42:34 +0800
committerGitHub <noreply@github.com>2023-08-25 10:42:34 -0700
commitef4c9f1f1c297f1a33be95795a7a7561e0cc3bde (patch)
tree9ea81689432040905772aeec447adad88f212e01 /source/slang/slang-check-expr.cpp
parent036abc85ba1db9c8c06289f0a0492e9a95a228b9 (diff)
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 <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
-rw-r--r--source/slang/slang-check-expr.cpp60
1 files changed, 60 insertions, 0 deletions
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 <result-id> 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;
+ }
}