summaryrefslogtreecommitdiffstats
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-05-11 13:56:14 -0700
committerGitHub <noreply@github.com>2018-05-11 13:56:14 -0700
commit5e604a6f39ef8e8086702d41113ea78856804c99 (patch)
tree035a4de9b84bdc04f377344dcaea931aa1896fa4 /source/slang/emit.cpp
parent10c0ffa7de111bd2c0096015bba5ca2110d03bc1 (diff)
Cleanups around behavior when the compiler fails (#553)
* Cleanups around behavior when the compiler fails * Add another case where we try to `noteInternalErrorLoc()` if an exception in thrown. This one is the in the logic for emitting an IR instruciton. This could be improved by adding another layer at the function level (as a catch-all for instructions with no location), but something is better than nothing. * Change a bunch of `assert()`s over to `SLANG_ASSERT()`s, so that we can theoretically take more control over them (e.g., make release builds with asserts enabled) * Some other small cleanups around the assertions we perform. In the survey I made, I didn't really see many obvious "smoking gun" cases where we could produce a significantly better error message for some of the unimplemented/unexpected paths, other than to actually implement the missing functionality. * fixup
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index bf7fceb0e..edb5d5cb2 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -3453,11 +3453,11 @@ struct EmitVisitor
for (UInt ee = 0; ee < elementCount; ++ee)
{
IRInst* irElementIndex = ii->getElementIndex(ee);
- assert(irElementIndex->op == kIROp_IntLit);
+ SLANG_RELEASE_ASSERT(irElementIndex->op == kIROp_IntLit);
IRConstant* irConst = (IRConstant*)irElementIndex;
UInt elementIndex = (UInt)irConst->u.intVal;
- assert(elementIndex < 4);
+ SLANG_RELEASE_ASSERT(elementIndex < 4);
char const* kComponents[] = { "x", "y", "z", "w" };
emit(kComponents[elementIndex]);
@@ -3514,6 +3514,25 @@ struct EmitVisitor
IRInst* inst,
IREmitMode mode)
{
+ try
+ {
+ emitIRInstImpl(ctx, inst, mode);
+ }
+ // Don't emit any context message for an explicit `AbortCompilationException`
+ // because it should only happen when an error is already emitted.
+ catch(AbortCompilationException&) { throw; }
+ catch(...)
+ {
+ ctx->shared->entryPoint->compileRequest->noteInternalErrorLoc(inst->sourceLoc);
+ throw;
+ }
+ }
+
+ void emitIRInstImpl(
+ EmitContext* ctx,
+ IRInst* inst,
+ IREmitMode mode)
+ {
if (shouldFoldIRInstIntoUseSites(ctx, inst, mode))
{
return;
@@ -3584,11 +3603,11 @@ struct EmitVisitor
for (UInt ee = 0; ee < elementCount; ++ee)
{
IRInst* irElementIndex = ii->getElementIndex(ee);
- assert(irElementIndex->op == kIROp_IntLit);
+ SLANG_RELEASE_ASSERT(irElementIndex->op == kIROp_IntLit);
IRConstant* irConst = (IRConstant*)irElementIndex;
UInt elementIndex = (UInt)irConst->u.intVal;
- assert(elementIndex < 4);
+ SLANG_RELEASE_ASSERT(elementIndex < 4);
char const* kComponents[] = { "x", "y", "z", "w" };
emit(kComponents[elementIndex]);
@@ -3609,11 +3628,11 @@ struct EmitVisitor
for (UInt ee = 0; ee < elementCount; ++ee)
{
IRInst* irElementIndex = ii->getElementIndex(ee);
- assert(irElementIndex->op == kIROp_IntLit);
+ SLANG_RELEASE_ASSERT(irElementIndex->op == kIROp_IntLit);
IRConstant* irConst = (IRConstant*)irElementIndex;
UInt elementIndex = (UInt)irConst->u.intVal;
- assert(elementIndex < 4);
+ SLANG_RELEASE_ASSERT(elementIndex < 4);
char const* kComponents[] = { "x", "y", "z", "w" };
emit(kComponents[elementIndex]);
@@ -3717,7 +3736,7 @@ struct EmitVisitor
if (argIndex >= argCount)
{
- assert(!"not enough arguments for branch");
+ SLANG_UNEXPECTED("not enough arguments for branch");
break;
}
@@ -3822,7 +3841,7 @@ struct EmitVisitor
// Start by emitting the non-terminator instructions in the block.
auto terminator = block->getLastInst();
- assert(as<IRTerminatorInst>(terminator));
+ SLANG_ASSERT(as<IRTerminatorInst>(terminator));
for (auto inst = block->getFirstInst(); inst != terminator; inst = inst->getNextInst())
{
emitIRInst(ctx, inst, IREmitMode::Default);
@@ -5003,7 +5022,7 @@ struct EmitVisitor
Emit(ctx->shared->uniqueIDCounter++);
auto varLayout = getVarLayout(ctx, varDecl);
- assert(varLayout);
+ SLANG_RELEASE_ASSERT(varLayout);
EmitVarChain blockChain(varLayout);
@@ -5051,7 +5070,7 @@ struct EmitVisitor
emit(getIRName(varDecl));
auto varLayout = getVarLayout(ctx, varDecl);
- assert(varLayout);
+ SLANG_RELEASE_ASSERT(varLayout);
EmitVarChain blockChain(varLayout);
@@ -5077,7 +5096,7 @@ struct EmitVisitor
if(auto structType = as<IRStructType>(elementType))
{
auto structTypeLayout = typeLayout.As<StructTypeLayout>();
- assert(structTypeLayout);
+ SLANG_RELEASE_ASSERT(structTypeLayout);
UInt fieldIndex = 0;
for(auto ff : structType->getFields())
@@ -5133,7 +5152,7 @@ struct EmitVisitor
IRParameterBlockType* type)
{
auto varLayout = getVarLayout(ctx, varDecl);
- assert(varLayout);
+ SLANG_RELEASE_ASSERT(varLayout);
EmitVarChain blockChain(varLayout);
@@ -5180,7 +5199,7 @@ struct EmitVisitor
}
auto varLayout = getVarLayout(ctx, varDecl);
- assert(varLayout);
+ SLANG_RELEASE_ASSERT(varLayout);
EmitVarChain blockChain(varLayout);
@@ -5218,7 +5237,7 @@ struct EmitVisitor
if(auto structType = as<IRStructType>(elementType))
{
auto structTypeLayout = typeLayout.As<StructTypeLayout>();
- assert(structTypeLayout);
+ SLANG_RELEASE_ASSERT(structTypeLayout);
UInt fieldIndex = 0;
for(auto ff : structType->getFields())
@@ -5501,13 +5520,13 @@ struct EmitVisitor
{
// We expect to see only a single block
auto block = valDecl->getFirstBlock();
- assert(block);
- assert(!block->getNextBlock());
+ SLANG_RELEASE_ASSERT(block);
+ SLANG_RELEASE_ASSERT(!block->getNextBlock());
// We expect the terminator to be a `return`
// instruction with a value.
auto returnInst = (IRReturnVal*) block->getLastInst();
- assert(returnInst->op == kIROp_ReturnVal);
+ SLANG_RELEASE_ASSERT(returnInst->op == kIROp_ReturnVal);
// Now we want to emit the expression form of
// the value being returned, and force any