summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-06-10 13:29:02 -0700
committerGitHub <noreply@github.com>2024-06-10 13:29:02 -0700
commit72016f9201e4d7820f62e7ef78cee98ed1fc4da0 (patch)
treeb8d78b954791afd8ad409074cfd6cca96a6d6c79 /source/slang/slang-emit.cpp
parent712ce653d4c3d7284dd71389f31540d0da7f144e (diff)
Partial implementation of static_assert (#4294)
* Error out for types not supported by texture sample functions This commit prints errors with a new keyword, `static_assert`, when the given texture type is not supported for the target. * Moving the check to linkAndOptimizeIR after specialization is done * Remove unnecessary change * Adding test * Remove kIROp_StaticAssert once processed * Do not remove StaticAssert because it is needed for the next specialization * Remove after iteration of child is done --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-emit.cpp')
-rw-r--r--source/slang/slang-emit.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 02dab6dfa..da348fa64 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -362,6 +362,51 @@ void calcRequiredLoweringPassSet(RequiredLoweringPassSet& result, CodeGenContext
}
}
+bool checkStaticAssert(IRInst* inst, DiagnosticSink* sink)
+{
+ switch (inst->getOp())
+ {
+ case kIROp_StaticAssert:
+ {
+ IRInst* condi = inst->getOperand(0);
+ if (auto condiLit = as<IRBoolLit>(condi))
+ {
+ if (!condiLit->getValue())
+ {
+ IRInst* msg = inst->getOperand(1);
+ if (auto msgLit = as<IRStringLit>(msg))
+ {
+ sink->diagnose(inst, Diagnostics::staticAssertionFailure, msgLit->getStringSlice());
+ }
+ else
+ {
+ sink->diagnose(inst, Diagnostics::staticAssertionFailureWithoutMessage);
+ }
+ }
+ }
+ else
+ {
+ sink->diagnose(condi, Diagnostics::staticAssertionConditionNotConstant);
+ }
+
+ return true;
+ }
+ }
+
+ List<IRInst*> removeList;
+ for (auto child : inst->getChildren())
+ {
+ if (checkStaticAssert(child, sink))
+ removeList.add(child);
+ }
+ for (auto child : removeList)
+ {
+ child->removeAndDeallocate();
+ }
+
+ return false;
+}
+
Result linkAndOptimizeIR(
CodeGenContext* codeGenContext,
LinkingAndOptimizationOptions const& options,
@@ -881,6 +926,10 @@ Result linkAndOptimizeIR(
validateIRModuleIfEnabled(codeGenContext, irModule);
+ // Process `static_assert` after the specialization is done.
+ // Some information for `static_assert` is available only after the specialization.
+ checkStaticAssert(irModule->getModuleInst(), sink);
+
// For HLSL (and fxc/dxc) only, we need to "wrap" any
// structured buffers defined over matrix types so
// that they instead use an intermediate `struct`.