summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/core/common.h8
-rw-r--r--source/core/slang-string.h4
-rw-r--r--source/slang/bytecode.cpp66
-rw-r--r--source/slang/check.cpp24
-rw-r--r--source/slang/compiler.cpp5
-rw-r--r--source/slang/dxc-support.cpp1
-rw-r--r--source/slang/emit.cpp365
-rw-r--r--source/slang/ir-insts.h14
-rw-r--r--source/slang/ir.cpp46
-rw-r--r--source/slang/lower-to-ir.cpp74
-rw-r--r--source/slang/lower.cpp12
-rw-r--r--source/slang/mangle.cpp6
-rw-r--r--source/slang/parameter-binding.cpp4
-rw-r--r--source/slang/parser.cpp2
-rw-r--r--source/slang/slang.cpp4
-rw-r--r--source/slang/syntax.cpp6
-rw-r--r--source/slang/type-layout.cpp12
-rw-r--r--source/slang/vm.cpp13
18 files changed, 341 insertions, 325 deletions
diff --git a/source/core/common.h b/source/core/common.h
index dbb837821..3a4543085 100644
--- a/source/core/common.h
+++ b/source/core/common.h
@@ -43,6 +43,14 @@ namespace Slang
#define SLANG_RETURN_NEVER /* empty */
#endif
+#ifdef _MSC_VER
+#define UNREACHABLE_RETURN(x)
+#define UNREACHABLE(x)
+#else
+#define UNREACHABLE_RETURN(x) return x;
+#define UNREACHABLE(x) x;
+#endif
+
SLANG_RETURN_NEVER void signalUnexpectedError(char const* message);
}
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 3f2b85d28..0808d9715 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -523,7 +523,7 @@ namespace Slang
UInt IndexOf(const char * str, UInt id) const // String str
{
- if (id < 0 || id >= getLength())
+ if (id >= getLength())
return UInt(-1);
auto findRs = strstr(begin() + id, str);
UInt res = findRs ? findRs - begin() : -1;
@@ -612,7 +612,7 @@ namespace Slang
{
if (!buffer)
return false;
- return (IndexOf(str) >= 0) ? true : false;
+ return (IndexOf(str) != UInt(-1)) ? true : false;
}
bool Contains(const String & str) const
diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp
index ee055a01f..e3cd9e74e 100644
--- a/source/slang/bytecode.cpp
+++ b/source/slang/bytecode.cpp
@@ -156,7 +156,7 @@ BCPtr<void>::RawVal allocateRaw(
for(size_t ii = currentOffset; ii < endOffset; ++ii)
context->shared->bytecode.Add(0);
- return (BCPtr<void>::RawVal)beginOffset;
+ return beginOffset;
}
template<typename T>
@@ -241,10 +241,11 @@ BCConst getGlobalValue(
BytecodeGenerationContext* context,
IRValue* value)
{
- BCConst bcConst;
- if( context->shared->mapValueToGlobal.TryGetValue(value, bcConst) )
- return bcConst;
-
+ {
+ BCConst bcConst;
+ if (context->shared->mapValueToGlobal.TryGetValue(value, bcConst))
+ return bcConst;
+ }
// Next we need to check for things that can be mapped to
// global IDs on the fly.
@@ -255,8 +256,9 @@ BCConst getGlobalValue(
UInt constID = context->shared->constants.Count();
context->shared->constants.Add(value);
+ BCConst bcConst;
bcConst.flavor = kBCConstFlavor_Constant;
- bcConst.id = (uint32_t)constID;
+ bcConst.id = constID;
context->shared->mapValueToGlobal.Add(value, bcConst);
@@ -268,10 +270,13 @@ BCConst getGlobalValue(
break;
}
- bcConst.flavor = (uint32_t) -1;
- bcConst.id = (uint32_t)-9999;
SLANG_UNEXPECTED("no ID for inst");
- //return bcConst;
+ {
+ UNREACHABLE(BCConst bcConst);
+ UNREACHABLE(bcConst.flavor = (BCConstFlavor)-1);
+ UNREACHABLE(bcConst.id = -9999);
+ UNREACHABLE_RETURN(bcConst);
+ }
}
Int getLocalID(
@@ -389,17 +394,17 @@ void generateBytecodeForInst(
case kIROp_FloatLit:
{
- auto ii = (IRConstant*) inst;
- encodeUInt(context, ii->op);
- encodeOperand(context, ii->getType());
+ auto cInst = (IRConstant*) inst;
+ encodeUInt(context, cInst->op);
+ encodeOperand(context, cInst->getType());
static const UInt size = sizeof(IRFloatingPointValue);
unsigned char buffer[size];
- memcpy(buffer, &ii->u.floatVal, sizeof(buffer));
+ memcpy(buffer, &cInst->u.floatVal, sizeof(buffer));
- for(UInt i = 0; i < size; ++i)
+ for(UInt ii = 0; ii < size; ++ii)
{
- encodeUInt8(context, buffer[i]);
+ encodeUInt8(context, buffer[ii]);
}
// destination:
@@ -476,7 +481,7 @@ BytecodeGenerationPtr<BCType> emitBCType(
auto bcArgs = (bcType + 1).bitCast<BCPtr<uint8_t>>();
bcType->op = op;
- bcType->argCount = (uint32_t)argCount;
+ bcType->argCount = argCount;
for(UInt aa = 0; aa < argCount; ++aa)
{
@@ -486,7 +491,7 @@ BytecodeGenerationPtr<BCType> emitBCType(
UInt id = context->shared->bcTypes.Count();
context->shared->mapTypeToID.Add(type, id);
context->shared->bcTypes.Add(bcType);
- bcType->id = (uint32_t)id;
+ bcType->id = id;
return bcType;
}
@@ -574,6 +579,7 @@ BytecodeGenerationPtr<BCType> emitBCTypeImpl(
SLANG_UNEXPECTED("unimplemented");
+ UNREACHABLE_RETURN(BytecodeGenerationPtr<BCType>());
}
BytecodeGenerationPtr<BCType> emitBCType(
@@ -699,7 +705,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
// Allocate the array of block objects to be stored in the
// bytecode file.
auto bcBlocks = allocateArray<BCBlock>(context, blockCount);
- bcFunc->blockCount = (uint32_t)blockCount;
+ bcFunc->blockCount = blockCount;
bcFunc->blocks = bcBlocks;
// Now loop through the blocks again, and allocate the storage
@@ -746,7 +752,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
}
}
- bcBlocks[blockID].paramCount = (uint32_t)paramCount;
+ bcBlocks[blockID].paramCount = paramCount;
}
// Okay, we've counted how many registers we need for each block,
@@ -754,7 +760,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
UInt regCount = regCounter;
auto bcRegs = allocateArray<BCReg>(context, regCount);
- bcFunc->regCount = (uint32_t)regCount;
+ bcFunc->regCount = regCount;
bcFunc->regs = bcRegs;
// Now we will loop over things again to fill in the information
@@ -782,7 +788,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
#if 0
bcRegs[localID].name = tryGenerateNameForSymbol(context, pp);
#endif
- bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID;
+ bcRegs[localID].previousVarIndexPlusOne = localID;
bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, pp);
}
@@ -804,7 +810,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
#if 0
bcRegs[localID].name = tryGenerateNameForSymbol(context, ii);
#endif
- bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID;
+ bcRegs[localID].previousVarIndexPlusOne = localID;
bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, ii);
}
break;
@@ -824,11 +830,11 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
#if 0
bcRegs[localID].name = tryGenerateNameForSymbol(context, ii);
#endif
- bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID;
+ bcRegs[localID].previousVarIndexPlusOne = localID;
bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, ii);
bcRegs[localID+1].op = ii->op;
- bcRegs[localID+1].previousVarIndexPlusOne = (uint32_t)localID+1;
+ bcRegs[localID+1].previousVarIndexPlusOne = localID+1;
bcRegs[localID+1].typeID = getTypeID(context,
(ii->getType()->As<PtrType>())->getValueType());
}
@@ -899,7 +905,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
UInt constCount = subContext->remappedGlobalSymbols.Count();
auto bcConsts = allocateArray<BCConst>(context, constCount);
- bcFunc->constCount = (uint32_t)constCount;
+ bcFunc->constCount = constCount;
bcFunc->consts = bcConsts;
for( UInt cc = 0; cc < constCount; ++cc )
@@ -965,7 +971,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule(
// Ensure that local code inside functions can see these symbols
BCConst bcConst;
bcConst.flavor = kBCConstFlavor_GlobalSymbol;
- bcConst.id = (uint32_t)globalID;
+ bcConst.id = globalID;
context->shared->mapValueToGlobal.Add(gv, bcConst);
// In the global scope, global IDs are also the local IDs
@@ -974,7 +980,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule(
auto bcSymbols = allocateArray<BCPtr<BCSymbol>>(context, symbolCount);
- bcModule->symbolCount = (uint32_t)symbolCount;
+ bcModule->symbolCount = symbolCount;
bcModule->symbols = bcSymbols;
for( auto gv = irModule->getFirstGlobalValue(); gv; gv = gv->getNextValue() )
@@ -994,7 +1000,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule(
// At this point we should have identified all the literals we need:
UInt constantCount = context->shared->constants.Count();
auto bcConstants = allocateArray<BCConstant>(context, constantCount);
- bcModule->constantCount = (uint32_t)constantCount;
+ bcModule->constantCount = constantCount;
bcModule->constants = bcConstants;
for(UInt cc = 0; cc < constantCount; ++cc)
@@ -1022,7 +1028,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule(
// At this point we should have collected all the types we need:
UInt typeCount = context->shared->bcTypes.Count();
auto bcTypes = allocateArray<BCPtr<BCType>>(context, typeCount);
- bcModule->typeCount = (uint32_t)typeCount;
+ bcModule->typeCount = typeCount;
bcModule->types = bcTypes;
for(UInt tt = 0; tt < typeCount; ++tt)
@@ -1059,7 +1065,7 @@ void generateBytecodeContainer(
}
UInt bcModuleCount = bcModulesList.Count();
- header->moduleCount = (uint32_t)bcModuleCount;
+ header->moduleCount = bcModuleCount;
auto bcModules = allocateArray<BCPtr<BCModule>>(context, bcModuleCount);
header->modules = bcModules;
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 8e5bab4e5..d01c913b1 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -536,7 +536,7 @@ namespace Slang
bool CoerceToProperTypeImpl(
TypeExp const& typeExp,
RefPtr<Type>* outProperType,
- DiagnosticSink* sink)
+ DiagnosticSink* diagSink)
{
Type* type = typeExp.type.Ptr();
if(!type && typeExp.exp)
@@ -566,11 +566,11 @@ namespace Slang
{
if (!typeParam->initType.exp)
{
- if (sink)
+ if (diagSink)
{
if (!isRewriteMode())
{
- sink->diagnose(typeExp.exp.Ptr(), Diagnostics::unimplemented, "can't fill in default for generic type parameter");
+ diagSink->diagnose(typeExp.exp.Ptr(), Diagnostics::unimplemented, "can't fill in default for generic type parameter");
}
*outProperType = getSession()->getErrorType();
}
@@ -585,11 +585,11 @@ namespace Slang
{
if (!valParam->initExpr)
{
- if (sink)
+ if (diagSink)
{
if (!isRewriteMode())
{
- sink->diagnose(typeExp.exp.Ptr(), Diagnostics::unimplemented, "can't fill in default for generic type parameter");
+ diagSink->diagnose(typeExp.exp.Ptr(), Diagnostics::unimplemented, "can't fill in default for generic type parameter");
}
*outProperType = getSession()->getErrorType();
}
@@ -1580,7 +1580,7 @@ namespace Slang
}
bool doesSignatureMatchRequirement(
- CallableDecl* memberDecl,
+ CallableDecl* /*memberDecl*/,
DeclRef<CallableDecl> requiredMemberDeclRef)
{
// TODO: actually implement matching here. For now we'll
@@ -2088,8 +2088,8 @@ namespace Slang
for (UInt cc = 0; cc < constraintCount; ++cc)
{
- auto fstConstraint = fstConstraints[cc];
- auto sndConstraint = sndConstraints[cc];
+ //auto fstConstraint = fstConstraints[cc];
+ //auto sndConstraint = sndConstraints[cc];
// TODO: the challenge here is that the
// constraints are going to be expressed
@@ -3538,7 +3538,7 @@ namespace Slang
// to `interfaceDeclRef`.
//
SLANG_UNEXPECTED("reflexive type witness");
- //return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
auto breadcrumbs = inBreadcrumbs;
@@ -3553,7 +3553,7 @@ namespace Slang
// because `A : B` and `B : C` then `A : C`
//
SLANG_UNEXPECTED("transitive type witness");
- //return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
// Simple case: we have a single declaration
@@ -6157,10 +6157,10 @@ namespace Slang
}
}
- RefPtr<Expr> visitStaticMemberExpr(StaticMemberExpr* expr)
+ RefPtr<Expr> visitStaticMemberExpr(StaticMemberExpr* /*expr*/)
{
SLANG_UNEXPECTED("should not occur in unchecked AST");
- //return expr;
+ UNREACHABLE_RETURN(nullptr);
}
RefPtr<Expr> lookupResultFailure(
diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp
index f045253b0..302b5704f 100644
--- a/source/slang/compiler.cpp
+++ b/source/slang/compiler.cpp
@@ -827,10 +827,9 @@ String dissassembleDXILUsingDXC(
}
void emitEntryPoints(
- TargetRequest* targetReq)
+ TargetRequest* /*targetReq*/)
{
- CompileRequest* compileReq = targetReq->compileRequest;
-
+
}
void generateOutputForTarget(
diff --git a/source/slang/dxc-support.cpp b/source/slang/dxc-support.cpp
index 8de63f494..b18a25e43 100644
--- a/source/slang/dxc-support.cpp
+++ b/source/slang/dxc-support.cpp
@@ -167,7 +167,6 @@ namespace Slang
IDxcBlobEncoding* dxcErrorBlob = nullptr;
if (!FAILED(dxcResult->GetErrorBuffer(&dxcErrorBlob)))
{
- void* data = dxcErrorBlob->GetBufferPointer();
compileRequest->mSink.diagnoseRaw(
FAILED(resultCode) ? Severity::Error : Severity::Warning,
(char const*)dxcErrorBlob->GetBufferPointer());
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index ccf7f94c0..849ca7e66 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -2398,7 +2398,7 @@ struct EmitVisitor
if(needClose) Emit(")");
}
- void visitThisExpr(ThisExpr* expr, ExprEmitArg const& arg)
+ void visitThisExpr(ThisExpr* /*expr*/, ExprEmitArg const& arg)
{
auto prec = kEOp_Atomic;
auto outerPrec = arg.outerPrec;
@@ -4099,8 +4099,7 @@ emitDeclImpl(decl, nullptr);
{
auto semanticName = varLayout->systemValueSemantic;
semanticName = semanticName.ToLower();
- auto semanticIndex = varLayout->systemValueSemanticIndex;
-
+
if(semanticName == "sv_position")
{
return "gl_Position";
@@ -4199,7 +4198,7 @@ emitDeclImpl(decl, nullptr);
};
void emitDeclarator(
- EmitContext* context,
+ EmitContext* ctx,
IRDeclaratorInfo* declarator)
{
if(!declarator)
@@ -4214,20 +4213,20 @@ emitDeclImpl(decl, nullptr);
case IRDeclaratorInfo::Flavor::Ptr:
emit("*");
- emitDeclarator(context, declarator->next);
+ emitDeclarator(ctx, declarator->next);
break;
case IRDeclaratorInfo::Flavor::Array:
- emitDeclarator(context, declarator->next);
+ emitDeclarator(ctx, declarator->next);
emit("[");
- emitIROperand(context, declarator->elementCount);
+ emitIROperand(ctx, declarator->elementCount);
emit("]");
break;
}
}
void emitIRSimpleValue(
- EmitContext* context,
+ EmitContext* /*context*/,
IRInst* inst)
{
switch(inst->op)
@@ -4374,9 +4373,9 @@ emitDeclImpl(decl, nullptr);
}
#endif
- CodeGenTarget getTarget(EmitContext* context)
+ CodeGenTarget getTarget(EmitContext* ctx)
{
- return context->shared->target;
+ return ctx->shared->target;
}
#if 0
@@ -4476,7 +4475,7 @@ emitDeclImpl(decl, nullptr);
#endif
bool shouldFoldIRInstIntoUseSites(
- EmitContext* context,
+ EmitContext* ctx,
IRValue* inst)
{
// Certain opcodes should always be folded in
@@ -4510,7 +4509,7 @@ emitDeclImpl(decl, nullptr);
// GLSL doesn't allow texture/resource types to
// be used as first-class values, so we need
// to fold them into their use sites in all cases
- if(getTarget(context) == CodeGenTarget::GLSL)
+ if(getTarget(ctx) == CodeGenTarget::GLSL)
return true;
}
@@ -4519,7 +4518,7 @@ emitDeclImpl(decl, nullptr);
}
bool isDerefBaseImplicit(
- EmitContext* context,
+ EmitContext* /*context*/,
IRValue* inst)
{
auto type = inst->getType();
@@ -4538,13 +4537,13 @@ emitDeclImpl(decl, nullptr);
void emitIROperand(
- EmitContext* context,
+ EmitContext* ctx,
IRValue* inst)
{
- if( shouldFoldIRInstIntoUseSites(context, inst) )
+ if( shouldFoldIRInstIntoUseSites(ctx, inst) )
{
emit("(");
- emitIRInstExpr(context, inst);
+ emitIRInstExpr(ctx, inst);
emit(")");
return;
}
@@ -4559,7 +4558,7 @@ emitDeclImpl(decl, nullptr);
}
void emitIRArgs(
- EmitContext* context,
+ EmitContext* ctx,
IRInst* inst)
{
UInt argCount = inst->argCount;
@@ -4569,13 +4568,13 @@ emitDeclImpl(decl, nullptr);
for(UInt aa = 0; aa < argCount; ++aa)
{
if(aa != 0) emit(", ");
- emitIROperand(context, args[aa].usedValue);
+ emitIROperand(ctx, args[aa].usedValue);
}
emit(")");
}
void emitIRType(
- EmitContext* context,
+ EmitContext* /*context*/,
IRType* type,
String const& name)
{
@@ -4583,7 +4582,7 @@ emitDeclImpl(decl, nullptr);
}
void emitIRType(
- EmitContext* context,
+ EmitContext* /*context*/,
IRType* type,
Name* name)
{
@@ -4591,14 +4590,14 @@ emitDeclImpl(decl, nullptr);
}
void emitIRType(
- EmitContext* context,
+ EmitContext* /*context*/,
IRType* type)
{
EmitType(type);
}
void emitIRInstResultDecl(
- EmitContext* context,
+ EmitContext* ctx,
IRInst* inst)
{
auto type = inst->getType();
@@ -4608,7 +4607,7 @@ emitDeclImpl(decl, nullptr);
if (type->Equals(getSession()->getVoidType()))
return;
- emitIRType(context, type, getIRName(inst));
+ emitIRType(ctx, type, getIRName(inst));
emit(" = ");
}
@@ -4673,10 +4672,10 @@ emitDeclImpl(decl, nullptr);
int readCount()
{
int c = peek();
- if(!isDigit(c))
+ if(!isDigit((char)c))
{
SLANG_UNEXPECTED("bad name mangling");
- return 0;
+ UNREACHABLE_RETURN(0);
}
get();
@@ -4688,7 +4687,7 @@ emitDeclImpl(decl, nullptr);
{
count = count*10 + c - '0';
c = peek();
- if(!isDigit(c))
+ if(!isDigit((char)c))
return count;
get();
@@ -4701,7 +4700,7 @@ emitDeclImpl(decl, nullptr);
for(;;)
{
int c = peek();
- if(!isDigit(c))
+ if(!isDigit((char)c))
return result;
// Read the length part
@@ -4709,7 +4708,7 @@ emitDeclImpl(decl, nullptr);
if(count > (end_ - cursor_))
{
SLANG_UNEXPECTED("bad name mangling");
- return result;
+ UNREACHABLE_RETURN(result);
}
result = UnownedStringSlice(cursor_, cursor_ + count);
@@ -4719,7 +4718,7 @@ emitDeclImpl(decl, nullptr);
};
void emitIntrinsicCallExpr(
- EmitContext* context,
+ EmitContext* ctx,
IRCall* inst,
IRFunc* func)
{
@@ -4741,38 +4740,38 @@ emitDeclImpl(decl, nullptr);
for( UInt aa = 1; aa < argCount; ++aa )
{
if(aa != 1) emit(", ");
- emitIROperand(context, inst->getArg(aa));
+ emitIROperand(ctx, inst->getArg(aa));
}
emit(")");
}
void emitIRCallExpr(
- EmitContext* context,
+ EmitContext* ctx,
IRCall* inst)
{
// We want to detect any call to an intrinsic operation,
// that we can emit it directly without mangling, etc.
auto funcValue = inst->getArg(0);
- if(auto irFunc = asTargetIntrinsic(context, funcValue))
+ if(auto irFunc = asTargetIntrinsic(ctx, funcValue))
{
- emitIntrinsicCallExpr(context, inst, irFunc);
+ emitIntrinsicCallExpr(ctx, inst, irFunc);
}
else
{
- emitIROperand(context, funcValue);
+ emitIROperand(ctx, funcValue);
emit("(");
UInt argCount = inst->getArgCount();
for( UInt aa = 1; aa < argCount; ++aa )
{
if(aa != 1) emit(", ");
- emitIROperand(context, inst->getArg(aa));
+ emitIROperand(ctx, inst->getArg(aa));
}
emit(")");
}
}
void emitIRInstExpr(
- EmitContext* context,
+ EmitContext* ctx,
IRValue* value)
{
IRInst* inst = (IRInst*) value;
@@ -4781,40 +4780,40 @@ emitDeclImpl(decl, nullptr);
case kIROp_IntLit:
case kIROp_FloatLit:
case kIROp_boolConst:
- emitIRSimpleValue(context, inst);
+ emitIRSimpleValue(ctx, inst);
break;
case kIROp_Construct:
// Simple constructor call
- if( inst->getArgCount() == 1 && getTarget(context) == CodeGenTarget::HLSL)
+ if( inst->getArgCount() == 1 && getTarget(ctx) == CodeGenTarget::HLSL)
{
// Need to emit as cast for HLSL
emit("(");
- emitIRType(context, inst->getType());
+ emitIRType(ctx, inst->getType());
emit(") ");
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
}
else
{
- emitIRType(context, inst->getType());
- emitIRArgs(context, inst);
+ emitIRType(ctx, inst->getType());
+ emitIRArgs(ctx, inst);
}
break;
case kIROp_constructVectorFromScalar:
// Simple constructor call
- if( getTarget(context) == CodeGenTarget::HLSL )
+ if( getTarget(ctx) == CodeGenTarget::HLSL )
{
emit("(");
- emitIRType(context, inst->getType());
+ emitIRType(ctx, inst->getType());
emit(")");
}
else
{
- emitIRType(context, inst->getType());
+ emitIRType(ctx, inst->getType());
}
emit("(");
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(")");
break;
@@ -4824,7 +4823,7 @@ emitDeclImpl(decl, nullptr);
IRFieldExtract* fieldExtract = (IRFieldExtract*) inst;
- emitIROperand(context, fieldExtract->getBase());
+ emitIROperand(ctx, fieldExtract->getBase());
emit(".");
emit(getIRName(fieldExtract->getField()));
}
@@ -4836,9 +4835,9 @@ emitDeclImpl(decl, nullptr);
IRFieldAddress* ii = (IRFieldAddress*) inst;
- if (!isDerefBaseImplicit(context, ii->getBase()))
+ if (!isDerefBaseImplicit(ctx, ii->getBase()))
{
- emitIROperand(context, ii->getBase());
+ emitIROperand(ctx, ii->getBase());
emit(".");
}
@@ -4848,9 +4847,9 @@ emitDeclImpl(decl, nullptr);
#define CASE(OPCODE, OP) \
case OPCODE: \
- emitIROperand(context, inst->getArg(0)); \
+ emitIROperand(ctx, inst->getArg(0)); \
emit(" " #OP " "); \
- emitIROperand(context, inst->getArg(1)); \
+ emitIROperand(ctx, inst->getArg(1)); \
break
CASE(kIROp_Add, +);
@@ -4884,22 +4883,22 @@ emitDeclImpl(decl, nullptr);
// when working with matrices.
case kIROp_Mul:
// Are we targetting GLSL, and is this a matrix product?
- if(getTarget(context) == CodeGenTarget::GLSL
+ if(getTarget(ctx) == CodeGenTarget::GLSL
&& inst->type->As<MatrixExpressionType>())
{
emit("matrixCompMult(");
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(", ");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit(")");
}
else
{
// Default handling is to just rely on infix
// `operator*`.
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(" * ");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
}
break;
@@ -4913,64 +4912,64 @@ emitDeclImpl(decl, nullptr);
{
emit("~");
}
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
}
break;
case kIROp_Sample:
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(".Sample(");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit(", ");
- emitIROperand(context, inst->getArg(2));
+ emitIROperand(ctx, inst->getArg(2));
emit(")");
break;
case kIROp_SampleGrad:
// argument 0 is the instruction's type
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(".SampleGrad(");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit(", ");
- emitIROperand(context, inst->getArg(2));
+ emitIROperand(ctx, inst->getArg(2));
emit(", ");
- emitIROperand(context, inst->getArg(3));
+ emitIROperand(ctx, inst->getArg(3));
emit(", ");
- emitIROperand(context, inst->getArg(4));
+ emitIROperand(ctx, inst->getArg(4));
emit(")");
break;
case kIROp_Load:
// TODO: this logic will really only work for a simple variable reference...
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
break;
case kIROp_Store:
// TODO: this logic will really only work for a simple variable reference...
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(" = ");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
break;
case kIROp_Call:
{
- emitIRCallExpr(context, (IRCall*)inst);
+ emitIRCallExpr(ctx, (IRCall*)inst);
}
break;
case kIROp_BufferLoad:
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit("[");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit("]");
break;
case kIROp_BufferStore:
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit("[");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit("] = ");
- emitIROperand(context, inst->getArg(2));
+ emitIROperand(ctx, inst->getArg(2));
break;
case kIROp_GroupMemoryBarrierWithGroupSync:
@@ -4979,16 +4978,16 @@ emitDeclImpl(decl, nullptr);
case kIROp_getElement:
case kIROp_getElementPtr:
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit("[");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit("]");
break;
case kIROp_Mul_Vector_Matrix:
case kIROp_Mul_Matrix_Vector:
case kIROp_Mul_Matrix_Matrix:
- if(getTarget(context) == CodeGenTarget::GLSL)
+ if(getTarget(ctx) == CodeGenTarget::GLSL)
{
// GLSL expresses inner-product multiplications
// with the ordinary infix `*` operator.
@@ -4998,16 +4997,16 @@ emitDeclImpl(decl, nullptr);
// because the notion of what is a "row" vs. a "column"
// is reversed between HLSL/Slang and GLSL.
//
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit(" * ");
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
}
else
{
emit("mul(");
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
emit(", ");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit(")");
}
break;
@@ -5015,7 +5014,7 @@ emitDeclImpl(decl, nullptr);
case kIROp_swizzle:
{
auto ii = (IRSwizzle*)inst;
- emitIROperand(context, ii->getBase());
+ emitIROperand(ctx, ii->getBase());
emit(".");
UInt elementCount = ii->getElementCount();
for (UInt ee = 0; ee < elementCount; ++ee)
@@ -5035,7 +5034,7 @@ emitDeclImpl(decl, nullptr);
case kIROp_specialize:
{
- emitIROperand(context, inst->getArg(0));
+ emitIROperand(ctx, inst->getArg(0));
}
break;
@@ -5046,10 +5045,10 @@ emitDeclImpl(decl, nullptr);
}
void emitIRInst(
- EmitContext* context,
+ EmitContext* ctx,
IRInst* inst)
{
- if (shouldFoldIRInstIntoUseSites(context, inst))
+ if (shouldFoldIRInstIntoUseSites(ctx, inst))
{
return;
}
@@ -5057,8 +5056,8 @@ emitDeclImpl(decl, nullptr);
switch(inst->op)
{
default:
- emitIRInstResultDecl(context, inst);
- emitIRInstExpr(context, inst);
+ emitIRInstResultDecl(ctx, inst);
+ emitIRInstExpr(ctx, inst);
emit(";\n");
break;
@@ -5068,7 +5067,7 @@ emitDeclImpl(decl, nullptr);
auto valType = ((PtrType*)ptrType)->getValueType();
auto name = getIRName(inst);
- emitIRType(context, valType, name);
+ emitIRType(ctx, valType, name);
emit(";\n");
}
break;
@@ -5088,17 +5087,17 @@ emitDeclImpl(decl, nullptr);
case kIROp_ReturnVal:
emit("return ");
- emitIROperand(context, ((IRReturnVal*) inst)->getVal());
+ emitIROperand(ctx, ((IRReturnVal*) inst)->getVal());
emit(";\n");
break;
case kIROp_swizzleSet:
{
auto ii = (IRSwizzleSet*)inst;
- emitIRInstResultDecl(context, inst);
- emitIROperand(context, inst->getArg(0));
+ emitIRInstResultDecl(ctx, inst);
+ emitIROperand(ctx, inst->getArg(0));
emit(";\n");
- emitIROperand(context, inst);
+ emitIROperand(ctx, inst);
emit(".");
UInt elementCount = ii->getElementCount();
for (UInt ee = 0; ee < elementCount; ++ee)
@@ -5114,7 +5113,7 @@ emitDeclImpl(decl, nullptr);
emit(kComponents[elementIndex]);
}
emit(" = ");
- emitIROperand(context, inst->getArg(1));
+ emitIROperand(ctx, inst->getArg(1));
emit(";\n");
}
break;
@@ -5122,11 +5121,11 @@ emitDeclImpl(decl, nullptr);
}
void emitIRSemantics(
- EmitContext* context,
+ EmitContext* ctx,
IRValue* inst)
{
// Don't emit semantics if we aren't translating down to HLSL
- switch (context->shared->target)
+ switch (ctx->shared->target)
{
case CodeGenTarget::HLSL:
break;
@@ -5164,7 +5163,7 @@ emitDeclImpl(decl, nullptr);
}
VarLayout* getVarLayout(
- EmitContext* context,
+ EmitContext* /*context*/,
IRValue* var)
{
auto decoration = var->findDecoration<IRLayoutDecoration>();
@@ -5175,11 +5174,11 @@ emitDeclImpl(decl, nullptr);
}
void emitIRLayoutSemantics(
- EmitContext* context,
+ EmitContext* ctx,
IRValue* inst,
char const* uniformSemanticSpelling = "register")
{
- auto layout = getVarLayout(context, inst);
+ auto layout = getVarLayout(ctx, inst);
if (layout)
{
emitHLSLRegisterSemantics(layout, uniformSemanticSpelling);
@@ -5196,7 +5195,7 @@ emitDeclImpl(decl, nullptr);
// be captured.
//
void emitIRStmtsForBlocks(
- EmitContext* context,
+ EmitContext* ctx,
IRBlock* begin,
IRBlock* end)
{
@@ -5208,7 +5207,7 @@ emitDeclImpl(decl, nullptr);
assert(isTerminatorInst(terminator));
for (auto inst = block->getFirstInst(); inst != terminator; inst = inst->getNextInst())
{
- emitIRInst(context, inst);
+ emitIRInst(ctx, inst);
}
// Now look at the terminator instruction, which will tell us what we need to emit next.
@@ -5221,7 +5220,7 @@ emitDeclImpl(decl, nullptr);
case kIROp_ReturnVal:
case kIROp_ReturnVoid:
- emitIRInst(context, terminator);
+ emitIRInst(ctx, terminator);
return;
case kIROp_if:
@@ -5233,10 +5232,10 @@ emitDeclImpl(decl, nullptr);
auto afterBlock = t->getAfterBlock();
emit("if(");
- emitIROperand(context, t->getCondition());
+ emitIROperand(ctx, t->getCondition());
emit(")\n{\n");
emitIRStmtsForBlocks(
- context,
+ ctx,
trueBlock,
afterBlock);
emit("}\n");
@@ -5256,15 +5255,15 @@ emitDeclImpl(decl, nullptr);
auto afterBlock = t->getAfterBlock();
emit("if(");
- emitIROperand(context, t->getCondition());
+ emitIROperand(ctx, t->getCondition());
emit(")\n{\n");
emitIRStmtsForBlocks(
- context,
+ ctx,
trueBlock,
afterBlock);
emit("}\nelse\n{\n");
emitIRStmtsForBlocks(
- context,
+ ctx,
falseBlock,
afterBlock);
emit("}\n");
@@ -5309,7 +5308,7 @@ emitDeclImpl(decl, nullptr);
emit("for(;;)\n{\n");
emitIRStmtsForBlocks(
- context,
+ ctx,
targetBlock,
nullptr);
@@ -5352,7 +5351,7 @@ emitDeclImpl(decl, nullptr);
//
emitIRStmtsForBlocks(
- context,
+ ctx,
targetBlock,
nullptr);
@@ -5381,7 +5380,7 @@ emitDeclImpl(decl, nullptr);
auto afterBlock = t->getTrueBlock();
emit("if(");
- emitIROperand(context, t->getCondition());
+ emitIROperand(ctx, t->getCondition());
emit(")\n{} else break;\n");
// Continue with the block after the test
@@ -5455,10 +5454,9 @@ emitDeclImpl(decl, nullptr);
}
void emitIRSimpleFunc(
- EmitContext* context,
+ EmitContext* ctx,
IRFunc* func)
{
- auto funcType = func->getType();
auto resultType = func->getResultType();
// Deal with decorations that need
@@ -5502,7 +5500,7 @@ emitDeclImpl(decl, nullptr);
auto name = getIRFuncName(func);
- emitIRType(context, resultType, name);
+ emitIRType(ctx, resultType, name);
emit("(");
auto firstParam = func->getFirstParam();
@@ -5512,14 +5510,14 @@ emitDeclImpl(decl, nullptr);
emit(", ");
auto paramName = getIRName(pp);
- emitIRType(context, pp->getType(), paramName);
+ emitIRType(ctx, pp->getType(), paramName);
- emitIRSemantics(context, pp);
+ emitIRSemantics(ctx, pp);
}
emit(")");
- emitIRSemantics(context, func);
+ emitIRSemantics(ctx, func);
// TODO: encode declaration vs. definition
if(isDefinition(func))
@@ -5528,7 +5526,7 @@ emitDeclImpl(decl, nullptr);
// Need to emit the operations in the blocks of the function
- emitIRStmtsForBlocks(context, func->getFirstBlock(), nullptr);
+ emitIRStmtsForBlocks(ctx, func->getFirstBlock(), nullptr);
emit("}\n");
}
@@ -5539,7 +5537,7 @@ emitDeclImpl(decl, nullptr);
}
void emitIRFuncDecl(
- EmitContext* context,
+ EmitContext* ctx,
IRFunc* func)
{
// We don't want to declare generic functions,
@@ -5550,7 +5548,7 @@ emitDeclImpl(decl, nullptr);
// We also don't want to emit declarations for operations
// that only appear in the IR as stand-ins for built-in
// operations on that target.
- if (isTargetIntrinsic(context, func))
+ if (isTargetIntrinsic(ctx, func))
return;
// Finally, don't emit a declaration for an entry point,
@@ -5571,7 +5569,7 @@ emitDeclImpl(decl, nullptr);
auto name = getIRFuncName(func);
- emitIRType(context, resultType, name);
+ emitIRType(ctx, resultType, name);
emit("(");
auto paramCount = funcType->getParamCount();
@@ -5604,13 +5602,13 @@ emitDeclImpl(decl, nullptr);
paramType = ptrType->getValueType();
}
- emitIRType(context, paramType, paramName);
+ emitIRType(ctx, paramType, paramName);
}
emit(");\n");
}
EntryPointLayout* getEntryPointLayout(
- EmitContext* context,
+ EmitContext* /*context*/,
IRFunc* func)
{
if( auto layoutDecoration = func->findDecoration<IRLayoutDecoration>() )
@@ -5637,7 +5635,7 @@ emitDeclImpl(decl, nullptr);
// declaration of an intrinsic/builtin for the
// current code-generation target.
bool isTargetIntrinsic(
- EmitContext* ctxt,
+ EmitContext* /*ctxt*/,
IRFunc* func)
{
// For now we do this in an overly simplistic
@@ -5672,13 +5670,13 @@ emitDeclImpl(decl, nullptr);
}
void emitIRFunc(
- EmitContext* context,
+ EmitContext* ctx,
IRFunc* func)
{
if(func->genericDecl)
{
Emit("/* ");
- emitIRFuncDecl(context, func);
+ emitIRFuncDecl(ctx, func);
Emit(" */\n");
return;
}
@@ -5692,17 +5690,17 @@ emitDeclImpl(decl, nullptr);
// We do not emit the declaration for
// functions that appear to be intrinsics/builtins
// in the target langugae.
- if (isTargetIntrinsic(context, func))
+ if (isTargetIntrinsic(ctx, func))
return;
- emitIRFuncDecl(context, func);
+ emitIRFuncDecl(ctx, func);
}
else
{
// The common case is that what we
// have is just an ordinary function,
// and we can emit it as such.
- emitIRSimpleFunc(context, func);
+ emitIRSimpleFunc(ctx, func);
}
}
@@ -5729,13 +5727,13 @@ emitDeclImpl(decl, nullptr);
#endif
void emitIRVarModifiers(
- EmitContext* context,
+ EmitContext* ctx,
VarLayout* layout)
{
if (!layout)
return;
- auto target = context->shared->target;
+ auto target = ctx->shared->target;
// We need to handle the case where the variable has
// a matrix type, and has been given a non-standard
@@ -5785,7 +5783,7 @@ emitDeclImpl(decl, nullptr);
}
- if (context->shared->target == CodeGenTarget::GLSL)
+ if (ctx->shared->target == CodeGenTarget::GLSL)
{
// Layout-related modifiers need to come before the declaration,
// so deal with them here.
@@ -5820,14 +5818,14 @@ emitDeclImpl(decl, nullptr);
}
void emitHLSLParameterBlock(
- EmitContext* context,
+ EmitContext* ctx,
IRGlobalVar* varDecl,
UniformParameterBlockType* type)
{
emit("cbuffer ");
emit(getIRName(varDecl));
- auto layout = getVarLayout(context, varDecl);
+ auto layout = getVarLayout(ctx, varDecl);
assert(layout);
auto info = layout->FindResourceInfo(LayoutResourceKind::ConstantBuffer);
@@ -5866,10 +5864,10 @@ emitDeclImpl(decl, nullptr);
auto fieldLayout = structTypeLayout->fields[fieldIndex++];
- emitIRVarModifiers(context, fieldLayout);
+ emitIRVarModifiers(ctx, fieldLayout);
auto fieldType = GetType(ff);
- emitIRType(context, fieldType, getIRName(ff));
+ emitIRType(ctx, fieldType, getIRName(ff));
emitHLSLParameterBlockFieldLayoutSemantics(layout, fieldLayout);
@@ -5886,11 +5884,11 @@ emitDeclImpl(decl, nullptr);
}
void emitGLSLParameterBlock(
- EmitContext* context,
+ EmitContext* ctx,
IRGlobalVar* varDecl,
UniformParameterBlockType* type)
{
- auto layout = getVarLayout(context, varDecl);
+ auto layout = getVarLayout(ctx, varDecl);
assert(layout);
auto info = layout->FindResourceInfo(LayoutResourceKind::DescriptorTableSlot);
@@ -5943,10 +5941,10 @@ emitDeclImpl(decl, nullptr);
auto fieldLayout = structTypeLayout->fields[fieldIndex++];
- emitIRVarModifiers(context, fieldLayout);
+ emitIRVarModifiers(ctx, fieldLayout);
auto fieldType = GetType(ff);
- emitIRType(context, fieldType, getIRName(ff));
+ emitIRType(ctx, fieldType, getIRName(ff));
// emitHLSLParameterBlockFieldLayoutSemantics(layout, fieldLayout);
@@ -5968,24 +5966,24 @@ emitDeclImpl(decl, nullptr);
}
void emitIRParameterBlock(
- EmitContext* context,
+ EmitContext* ctx,
IRGlobalVar* varDecl,
UniformParameterBlockType* type)
{
- switch (context->shared->target)
+ switch (ctx->shared->target)
{
case CodeGenTarget::HLSL:
- emitHLSLParameterBlock(context, varDecl, type);
+ emitHLSLParameterBlock(ctx, varDecl, type);
break;
case CodeGenTarget::GLSL:
- emitGLSLParameterBlock(context, varDecl, type);
+ emitGLSLParameterBlock(ctx, varDecl, type);
break;
}
}
void emitIRVar(
- EmitContext* context,
+ EmitContext* ctx,
IRVar* varDecl)
{
auto allocatedType = varDecl->getType();
@@ -5997,7 +5995,7 @@ emitDeclImpl(decl, nullptr);
{
case kIROp_ConstantBufferType:
case kIROp_TextureBufferType:
- emitIRParameterBlock(context, varDecl, (IRUniformBufferType*) varType);
+ emitIRParameterBlock(ctx, varDecl, (IRUniformBufferType*) varType);
return;
default:
@@ -6007,9 +6005,9 @@ emitDeclImpl(decl, nullptr);
// Need to emit appropriate modifiers here.
- auto layout = getVarLayout(context, varDecl);
+ auto layout = getVarLayout(ctx, varDecl);
- emitIRVarModifiers(context, layout);
+ emitIRVarModifiers(ctx, layout);
#if 0
switch (addressSpace)
@@ -6023,17 +6021,17 @@ emitDeclImpl(decl, nullptr);
}
#endif
- emitIRType(context, varType, getIRName(varDecl));
+ emitIRType(ctx, varType, getIRName(varDecl));
- emitIRSemantics(context, varDecl);
+ emitIRSemantics(ctx, varDecl);
- emitIRLayoutSemantics(context, varDecl);
+ emitIRLayoutSemantics(ctx, varDecl);
emit(";\n");
}
void emitIRGlobalVar(
- EmitContext* context,
+ EmitContext* ctx,
IRGlobalVar* varDecl)
{
auto allocatedType = varDecl->getType();
@@ -6043,7 +6041,7 @@ emitDeclImpl(decl, nullptr);
if (auto paramBlockType = varType->As<UniformParameterBlockType>())
{
emitIRParameterBlock(
- context,
+ ctx,
varDecl,
paramBlockType);
return;
@@ -6051,9 +6049,9 @@ emitDeclImpl(decl, nullptr);
// Need to emit appropriate modifiers here.
- auto layout = getVarLayout(context, varDecl);
+ auto layout = getVarLayout(ctx, varDecl);
- emitIRVarModifiers(context, layout);
+ emitIRVarModifiers(ctx, layout);
#if 0
switch (addressSpace)
@@ -6067,17 +6065,17 @@ emitDeclImpl(decl, nullptr);
}
#endif
- emitIRType(context, varType, getIRName(varDecl));
+ emitIRType(ctx, varType, getIRName(varDecl));
- emitIRSemantics(context, varDecl);
+ emitIRSemantics(ctx, varDecl);
- emitIRLayoutSemantics(context, varDecl);
+ emitIRLayoutSemantics(ctx, varDecl);
emit(";\n");
}
void emitIRGlobalInst(
- EmitContext* context,
+ EmitContext* ctx,
IRGlobalValue* inst)
{
// TODO: need to be able to `switch` on the IR opcode here,
@@ -6085,15 +6083,15 @@ emitDeclImpl(decl, nullptr);
switch(inst->op)
{
case kIROp_Func:
- emitIRFunc(context, (IRFunc*) inst);
+ emitIRFunc(ctx, (IRFunc*) inst);
break;
case kIROp_global_var:
- emitIRGlobalVar(context, (IRGlobalVar*) inst);
+ emitIRGlobalVar(ctx, (IRGlobalVar*) inst);
break;
case kIROp_Var:
- emitIRVar(context, (IRVar*) inst);
+ emitIRVar(ctx, (IRVar*) inst);
break;
default:
@@ -6102,7 +6100,7 @@ emitDeclImpl(decl, nullptr);
}
void ensureStructDecl(
- EmitContext* context,
+ EmitContext* ctx,
DeclRef<StructDecl> declRef)
{
// TODO: Eventually need to deal with the case where
@@ -6110,10 +6108,10 @@ emitDeclImpl(decl, nullptr);
//
auto decl = declRef.getDecl();
- if(context->shared->irDeclsVisited.Contains(decl))
+ if(ctx->shared->irDeclsVisited.Contains(decl))
return;
- context->shared->irDeclsVisited.Add(decl);
+ ctx->shared->irDeclsVisited.Add(decl);
// First emit any types used by fields of this type
for( auto ff : GetFields(declRef) )
@@ -6122,7 +6120,7 @@ emitDeclImpl(decl, nullptr);
continue;
auto fieldType = GetType(ff);
- emitIRUsedType(context, fieldType);
+ emitIRUsedType(ctx, fieldType);
}
Emit("struct ");
@@ -6134,7 +6132,7 @@ emitDeclImpl(decl, nullptr);
continue;
auto fieldType = GetType(ff);
- emitIRType(context, fieldType, getIRName(ff));
+ emitIRType(ctx, fieldType, getIRName(ff));
EmitSemantics(ff.getDecl());
@@ -6147,7 +6145,7 @@ emitDeclImpl(decl, nullptr);
// make sure that we have emitted whatever
// it needs.
void emitIRUsedType(
- EmitContext* context,
+ EmitContext* ctx,
Type* type)
{
if(type->As<BasicExpressionType>())
@@ -6158,19 +6156,19 @@ emitDeclImpl(decl, nullptr);
{}
else if(auto arrayType = type->As<ArrayExpressionType>())
{
- emitIRUsedType(context, arrayType->baseType);
+ emitIRUsedType(ctx, arrayType->baseType);
}
else if( auto textureType = type->As<TextureTypeBase>() )
{
- emitIRUsedType(context, textureType->elementType);
+ emitIRUsedType(ctx, textureType->elementType);
}
else if( auto genericType = type->As<BuiltinGenericType>() )
{
- emitIRUsedType(context, genericType->elementType);
+ emitIRUsedType(ctx, genericType->elementType);
}
else if( auto ptrType = type->As<PtrType>() )
{
- emitIRUsedType(context, ptrType->getValueType());
+ emitIRUsedType(ctx, ptrType->getValueType());
}
else if(type->As<SamplerStateType>() )
{
@@ -6189,7 +6187,7 @@ emitDeclImpl(decl, nullptr);
if( auto structDeclRef = declRef.As<StructDecl>() )
{
//
- ensureStructDecl(context, structDeclRef);
+ ensureStructDecl(ctx, structDeclRef);
}
}
else
@@ -6197,7 +6195,7 @@ emitDeclImpl(decl, nullptr);
}
void emitIRUsedTypesForValue(
- EmitContext* context,
+ EmitContext* ctx,
IRValue* value)
{
if(!value) return;
@@ -6206,17 +6204,17 @@ emitDeclImpl(decl, nullptr);
case kIROp_Func:
{
auto irFunc = (IRFunc*) value;
- emitIRUsedType(context, irFunc->getResultType());
+ emitIRUsedType(ctx, irFunc->getResultType());
for( auto bb = irFunc->getFirstBlock(); bb; bb = bb->getNextBlock() )
{
for( auto pp = bb->getFirstParam(); pp; pp = pp->getNextParam() )
{
- emitIRUsedTypesForValue(context, pp);
+ emitIRUsedTypesForValue(ctx, pp);
}
for( auto ii = bb->getFirstInst(); ii; ii = ii->getNextInst() )
{
- emitIRUsedTypesForValue(context, ii);
+ emitIRUsedTypesForValue(ctx, ii);
}
}
}
@@ -6224,27 +6222,27 @@ emitDeclImpl(decl, nullptr);
default:
{
- emitIRUsedType(context, value->type);
+ emitIRUsedType(ctx, value->type);
}
break;
}
}
void emitIRUsedTypesForModule(
- EmitContext* context,
+ EmitContext* ctx,
IRModule* module)
{
for( auto gv = module->getFirstGlobalValue(); gv; gv = gv->getNextValue() )
{
- emitIRUsedTypesForValue(context, gv);
+ emitIRUsedTypesForValue(ctx, gv);
}
}
void emitIRModule(
- EmitContext* context,
+ EmitContext* ctx,
IRModule* module)
{
- emitIRUsedTypesForModule(context, module);
+ emitIRUsedTypesForModule(ctx, module);
// Before we emit code, we need to forward-declare
// all of our functions so that we don't have to
@@ -6255,14 +6253,14 @@ emitDeclImpl(decl, nullptr);
continue;
auto func = (IRFunc*) gv;
- emitIRFuncDecl(context, func);
+ emitIRFuncDecl(ctx, func);
}
for( auto gv = module->getFirstGlobalValue(); gv; gv = gv->getNextValue() )
{
- emitIRGlobalInst(context, gv);
+ emitIRGlobalInst(ctx, gv);
}
}
@@ -6352,8 +6350,7 @@ String emitEntryPoint(
CodeGenTarget finalTarget)
{
auto translationUnit = entryPoint->getTranslationUnit();
- auto session = entryPoint->compileRequest->mSession;
-
+
SharedEmitContext sharedContext;
sharedContext.target = target;
sharedContext.finalTarget = finalTarget;
diff --git a/source/slang/ir-insts.h b/source/slang/ir-insts.h
index 587fe3cd2..f70ab46ff 100644
--- a/source/slang/ir-insts.h
+++ b/source/slang/ir-insts.h
@@ -320,25 +320,25 @@ struct SharedIRBuilder
struct IRBuilder
{
// Shared state for all IR builders working on the same module
- SharedIRBuilder* shared;
+ SharedIRBuilder* sharedBuilder;
Session* getSession()
{
- return shared->getSession();
+ return sharedBuilder->getSession();
}
- IRModule* getModule() { return shared->module; }
+ IRModule* getModule() { return sharedBuilder->module; }
// The current function and block being inserted into
// (or `null` if we aren't inserting).
- IRFunc* func = nullptr;
- IRBlock* block = nullptr;
+ IRFunc* curFunc = nullptr;
+ IRBlock* curBlock = nullptr;
//
// An instruction in the current block that we should insert before
IRInst* insertBeforeInst = nullptr;
- IRFunc* getFunc() { return func; }
- IRBlock* getBlock() { return block; }
+ IRFunc* getFunc() { return curFunc; }
+ IRBlock* getBlock() { return curBlock; }
void addInst(IRBlock* block, IRInst* inst);
void addInst(IRInst* inst);
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp
index 5f3ca6c62..e424b4cc3 100644
--- a/source/slang/ir.cpp
+++ b/source/slang/ir.cpp
@@ -212,7 +212,7 @@ namespace Slang
return;
}
- auto parent = block;
+ auto parent = curBlock;
if (!parent)
return;
@@ -260,7 +260,7 @@ namespace Slang
IRInst* inst = (IRInst*) malloc(size);
memset(inst, 0, size);
- inst->argCount = (uint32_t)(fixedArgCount + varArgCount);
+ inst->argCount = fixedArgCount + varArgCount;
inst->op = op;
@@ -492,7 +492,7 @@ namespace Slang
key.inst = &keyInst;
IRConstant* irValue = nullptr;
- if( builder->shared->constantMap.TryGetValue(key, irValue) )
+ if( builder->sharedBuilder->constantMap.TryGetValue(key, irValue) )
{
// We found a match, so just use that.
return irValue;
@@ -509,7 +509,7 @@ namespace Slang
memcpy(&irValue->u, value, valueSize);
key.inst = irValue;
- builder->shared->constantMap.Add(key, irValue);
+ builder->sharedBuilder->constantMap.Add(key, irValue);
return irValue;
}
@@ -890,11 +890,11 @@ namespace Slang
{
auto bb = createBlock();
- auto f = this->func;
+ auto f = this->curFunc;
if (f)
{
f->addBlock(bb);
- this->block = bb;
+ this->curBlock = bb;
}
return bb;
}
@@ -907,7 +907,7 @@ namespace Slang
kIROp_Param,
type);
- if (auto bb = block)
+ if (auto bb = curBlock)
{
bb->addParam(param);
}
@@ -1695,7 +1695,6 @@ namespace Slang
dumpChildrenRaw(context, block);
}
-
#if 0
static void dumpChildrenRaw(
IRDumpContext* context,
@@ -1720,7 +1719,6 @@ namespace Slang
dump(context, "}\n");
}
#endif
-
static void dumpInst(
IRDumpContext* context,
IRInst* inst)
@@ -2239,8 +2237,7 @@ namespace Slang
void IRInst::removeArguments()
{
- UInt oldArgCount = this->argCount;
- for( UInt aa = 0; aa < oldArgCount; ++aa )
+ for( UInt aa = 0; aa < argCount; ++aa )
{
IRUse& use = getArgs()[aa];
@@ -2280,7 +2277,7 @@ namespace Slang
shared.session = session;
IRBuilder builder;
- builder.shared = &shared;
+ builder.sharedBuilder = &shared;
RefPtr<PtrType> ptrType = session->getPtrType(valueType);
@@ -2550,6 +2547,7 @@ namespace Slang
default:
SLANG_UNEXPECTED("unimplemented");
+ UNREACHABLE_RETURN(ScalarizedVal());
}
}
@@ -2667,8 +2665,8 @@ namespace Slang
shared.module = module;
shared.session = session;
IRBuilder builder;
- builder.shared = &shared;
- builder.func = func;
+ builder.sharedBuilder = &shared;
+ builder.curFunc = func;
// We will start by looking at the return type of the
// function, because that will enable us to do an
@@ -2725,7 +2723,7 @@ namespace Slang
IRValue* returnValue = returnInst->getVal();
// Make sure we add these instructions to the right block
- builder.block = bb;
+ builder.curBlock = bb;
// Write to our global variable(s) from the value being returned.
assign(&builder, resultGlobal, ScalarizedVal::value(returnValue));
@@ -2777,7 +2775,7 @@ namespace Slang
// Any initialization code we insert nees to be at the start
// of the block:
- builder.block = firstBlock;
+ builder.curBlock = firstBlock;
builder.insertBeforeInst = firstBlock->getFirstInst();
// TODO: We need to distinguish any true pointers in the
@@ -2836,7 +2834,7 @@ namespace Slang
break;
}
- builder.block = bb;
+ builder.curBlock = bb;
builder.insertBeforeInst = terminatorInst;
assign(&builder, globalOutputVal, localVal);
@@ -3078,6 +3076,7 @@ namespace Slang
break;
default:
SLANG_UNEXPECTED("no value registered for IR value");
+ UNREACHABLE_RETURN(nullptr);
}
}
@@ -3238,7 +3237,7 @@ namespace Slang
{
auto clonedKey = context->maybeCloneValue(originalEntry->requirementKey.usedValue);
auto clonedVal = context->maybeCloneValue(originalEntry->satisfyingVal.usedValue);
- context->builder->createWitnessTableEntry(
+ /*auto clonedEntry = */context->builder->createWitnessTableEntry(
clonedTable,
clonedKey,
clonedVal);
@@ -3262,7 +3261,7 @@ namespace Slang
// Next we are going to clone the actual code.
IRBuilder builderStorage = *context->builder;
IRBuilder* builder = &builderStorage;
- builder->func = clonedFunc;
+ builder->curFunc = clonedFunc;
// We will walk through the blocks of the function, and clone each of them.
//
@@ -3278,7 +3277,7 @@ namespace Slang
registerClonedValue(context, clonedBlock, originalBlock);
// We can go ahead and clone parameters here, while we are at it.
- builder->block = clonedBlock;
+ builder->curBlock = clonedBlock;
for (auto originalParam = originalBlock->getFirstParam();
originalParam;
originalParam = originalParam->getNextParam())
@@ -3299,7 +3298,7 @@ namespace Slang
{
assert(cb);
- builder->block = cb;
+ builder->curBlock = cb;
for (auto oi = ob->getFirstInst(); oi; oi = oi->getNextInst())
{
cloneInst(context, builder, oi);
@@ -3423,6 +3422,7 @@ namespace Slang
default:
SLANG_UNEXPECTED("unhandled case");
+ UNREACHABLE_RETURN("unknown");
}
}
@@ -3524,6 +3524,7 @@ namespace Slang
{
// This shouldn't happen!
SLANG_UNEXPECTED("no matching function registered");
+ UNREACHABLE_RETURN(cloneSimpleFunc(context, originalFunc));
}
// We will try to track the "best" definition we can find.
@@ -3595,7 +3596,7 @@ namespace Slang
sharedBuilder->session = session;
IRBuilder* builder = &sharedContext->builderStorage;
- builder->shared = sharedBuilder;
+ builder->sharedBuilder = sharedBuilder;
if( !module )
{
@@ -3753,6 +3754,7 @@ namespace Slang
else
{
SLANG_UNEXPECTED("unimplemented");
+ UNREACHABLE_RETURN(nullptr);
}
}
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index 81fab7108..4595a0319 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -401,7 +401,7 @@ IRValue* getOneValOfType(
// TODO: should make sure to handle vector and matrix types here
SLANG_UNEXPECTED("inc/dec type");
- return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
LoweredValInfo emitPreOp(
@@ -665,19 +665,20 @@ top:
{
auto boundSubscriptInfo = lowered.getBoundSubscriptInfo();
- for (auto getter : getMembersOfType<GetterDecl>(boundSubscriptInfo->declRef))
+ auto getters = getMembersOfType<GetterDecl>(boundSubscriptInfo->declRef);
+ if (getters.Count())
{
lowered = emitCallToDeclRef(
context,
boundSubscriptInfo->type,
- getter,
+ *getters.begin(),
nullptr,
boundSubscriptInfo->args);
goto top;
}
SLANG_UNEXPECTED("subscript had no getter");
- return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
break;
@@ -694,7 +695,7 @@ top:
default:
SLANG_UNEXPECTED("unhandled value flavor");
- return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
}
@@ -733,7 +734,7 @@ RefPtr<Type> getSimpleType(LoweredTypeInfo lowered)
default:
SLANG_UNEXPECTED("unhandled value flavor");
- return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
}
@@ -836,7 +837,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower
IRBuilder* getBuilder() { return context->irBuilder; }
- LoweredValInfo visitVal(Val* val)
+ LoweredValInfo visitVal(Val* /*val*/)
{
SLANG_UNIMPLEMENTED_X("value lowering");
}
@@ -1011,7 +1012,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
return info;
}
- LoweredValInfo visitOverloadedExpr(OverloadedExpr* expr)
+ LoweredValInfo visitOverloadedExpr(OverloadedExpr* /*expr*/)
{
SLANG_UNEXPECTED("overloaded expressions should not occur in checked AST");
}
@@ -1025,7 +1026,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
return subscriptValue(type, baseVal, indexVal);
}
- LoweredValInfo visitThisExpr(ThisExpr* expr)
+ LoweredValInfo visitThisExpr(ThisExpr* /*expr*/)
{
return context->thisVal;
}
@@ -1096,7 +1097,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
else
{
SLANG_UNIMPLEMENTED_X("codegen for deref expression");
- return LoweredValInfo();
+ UNREACHABLE_RETURN(LoweredValInfo());
}
}
@@ -1105,7 +1106,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
return lowerSubExpr(expr->base);
}
- LoweredValInfo visitInitializerListExpr(InitializerListExpr* expr)
+ LoweredValInfo visitInitializerListExpr(InitializerListExpr* /*expr*/)
{
SLANG_UNIMPLEMENTED_X("codegen for initializer list expression");
}
@@ -1129,7 +1130,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
SLANG_UNEXPECTED("unexpected constant type");
}
- LoweredValInfo visitAggTypeCtorExpr(AggTypeCtorExpr* expr)
+ LoweredValInfo visitAggTypeCtorExpr(AggTypeCtorExpr* /*expr*/)
{
SLANG_UNIMPLEMENTED_X("codegen for aggregate type constructor expression");
}
@@ -1140,8 +1141,6 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
InvokeExpr* expr,
List<IRValue*>* ioArgs)
{
- auto& irArgs = *ioArgs;
-
for( auto arg : expr->Arguments )
{
// TODO: Need to handle case of l-value arguments,
@@ -1170,8 +1169,6 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
List<IRValue*>* ioArgs,
List<OutArgumentFixup>* ioFixups)
{
- auto funcDecl = funcDeclRef.getDecl();
- auto& args = expr->Arguments;
UInt argCount = expr->Arguments.Count();
UInt argIndex = 0;
for (auto paramDeclRef : getMembersOfType<ParamDecl>(funcDeclRef))
@@ -1265,7 +1262,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
else
{
SLANG_UNEXPECTED("shouldn't relaly happen");
- addDirectCallArgs(expr, ioArgs);
+ UNREACHABLE(addDirectCallArgs(expr, ioArgs));
}
}
@@ -1461,7 +1458,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
default:
SLANG_UNIMPLEMENTED_X("subscript expr");
- return LoweredValInfo();
+ UNREACHABLE_RETURN(LoweredValInfo());
}
}
@@ -1505,17 +1502,17 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
return emitDeclRef(context, expr->declRef);
}
- LoweredValInfo visitSelectExpr(SelectExpr* expr)
+ LoweredValInfo visitSelectExpr(SelectExpr* /*expr*/)
{
SLANG_UNIMPLEMENTED_X("codegen for select expression");
}
- LoweredValInfo visitGenericAppExpr(GenericAppExpr* expr)
+ LoweredValInfo visitGenericAppExpr(GenericAppExpr* /*expr*/)
{
SLANG_UNIMPLEMENTED_X("generic application expression during code generation");
}
- LoweredValInfo visitSharedTypeExpr(SharedTypeExpr* expr)
+ LoweredValInfo visitSharedTypeExpr(SharedTypeExpr* /*expr*/)
{
SLANG_UNIMPLEMENTED_X("shared type expression during code generation");
}
@@ -1621,7 +1618,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor>
IRBuilder* getBuilder() { return context->irBuilder; }
- void visitStmt(Stmt* stmt)
+ void visitStmt(Stmt* /*stmt*/)
{
SLANG_UNIMPLEMENTED_X("stmt catch-all");
}
@@ -1640,7 +1637,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor>
{
auto builder = getBuilder();
- auto prevBlock = builder->block;
+ auto prevBlock = builder->curBlock;
auto parentFunc = prevBlock->parentFunc;
// If the previous block doesn't already have
@@ -1653,8 +1650,8 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor>
parentFunc->addBlock(block);
- builder->func = parentFunc;
- builder->block = block;
+ builder->curFunc = parentFunc;
+ builder->curBlock = block;
}
// Start a new block at the current location.
@@ -2024,7 +2021,8 @@ top:
auto type = subscriptInfo->type;
// Search for an appropriate "setter" declaration
- for (auto setterDeclRef : getMembersOfType<SetterDecl>(subscriptInfo->declRef))
+ auto setters = getMembersOfType<SetterDecl>(subscriptInfo->declRef);
+ if (setters.Count())
{
auto allArgs = subscriptInfo->args;
@@ -2033,7 +2031,7 @@ top:
emitCallToDeclRef(
context,
context->getSession()->getVoidType(),
- setterDeclRef,
+ *setters.begin(),
nullptr,
allArgs);
return;
@@ -2060,12 +2058,12 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
return context->irBuilder;
}
- LoweredValInfo visitDeclBase(DeclBase* decl)
+ LoweredValInfo visitDeclBase(DeclBase* /*decl*/)
{
SLANG_UNIMPLEMENTED_X("decl catch-all");
}
- LoweredValInfo visitDecl(Decl* decl)
+ LoweredValInfo visitDecl(Decl* /*decl*/)
{
SLANG_UNIMPLEMENTED_X("decl catch-all");
}
@@ -2075,7 +2073,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
return LoweredValInfo::simple(context->irBuilder->getTypeVal(decl->type.type));
}
- LoweredValInfo visitGenericTypeParamDecl(GenericTypeParamDecl* decl)
+ LoweredValInfo visitGenericTypeParamDecl(GenericTypeParamDecl* /*decl*/)
{
return LoweredValInfo();
}
@@ -2126,7 +2124,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
auto irRequirement = context->irBuilder->getDeclRefVal(requiredMemberDeclRef);
auto irSatisfyingVal = getSimpleVal(context, ensureDecl(context, satisfyingMemberDecl));
- auto witnessTableEntry = context->irBuilder->createWitnessTableEntry(
+ context->irBuilder->createWitnessTableEntry(
witnessTable,
irRequirement,
irSatisfyingVal);
@@ -2689,7 +2687,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// need to create an IR function here
IRFunc* irFunc = subBuilder->createFunc();
- subBuilder->func = irFunc;
+ subBuilder->curFunc = irFunc;
trySetMangledName(irFunc, decl);
@@ -2741,7 +2739,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
//
IRType* irParamType = irResultType;
paramTypes.Add(irParamType);
- IRParam* irParam = subBuilder->emitParam(irParamType);
+ subBuilder->emitParam(irParamType);
// TODO: we need some way to wire this up to the `newValue`
// or whatever name we give for that parameter inside
@@ -2777,7 +2775,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// This is a function definition, so we need to actually
// construct IR for the body...
IRBlock* entryBlock = subBuilder->emitBlock();
- subBuilder->block = entryBlock;
+ subBuilder->curBlock = entryBlock;
UInt paramTypeIndex = 0;
for( auto paramInfo : parameterLists.params )
@@ -2858,7 +2856,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// We need to carefully add a terminator instruction to the end
// of the body, in case the user didn't do so.
- if (!isTerminatorInst(subContext->irBuilder->block->lastInst))
+ if (!isTerminatorInst(subContext->irBuilder->curBlock->lastInst))
{
if (irResultType->Equals(context->getSession()->getVoidType()))
{
@@ -2874,7 +2872,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// and then emit a dataflow error if this block
// can't be eliminated.
SLANG_UNEXPECTED("Needed a return here");
- subContext->irBuilder->emitReturn();
+ UNREACHABLE(subContext->irBuilder->emitReturn());
}
}
}
@@ -2961,7 +2959,7 @@ LoweredValInfo ensureDecl(
return result;
IRBuilder subIRBuilder;
- subIRBuilder.shared = context->irBuilder->shared;
+ subIRBuilder.sharedBuilder = context->irBuilder->sharedBuilder;
IRGenContext subContext = *context;
@@ -3191,7 +3189,7 @@ IRModule* generateIRForTranslationUnit(
IRBuilder builderStorage;
IRBuilder* builder = &builderStorage;
- builder->shared = sharedBuilder;
+ builder->sharedBuilder = sharedBuilder;
IRModule* module = builder->createModule();
sharedBuilder->module = module;
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index 7f18659ae..d207aac72 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -424,7 +424,7 @@ static SourceLoc getPosition(LoweredExpr const& expr)
case LoweredExpr::Flavor::VaryingTuple: return expr.getVaryingTupleExpr()->loc;
default:
SLANG_UNREACHABLE("all cases handled");
- return SourceLoc();
+ UNREACHABLE_RETURN(SourceLoc());
}
}
@@ -907,7 +907,7 @@ struct LoweringVisitor
default:
SLANG_UNREACHABLE("all cases handled");
- return LoweredExpr();
+ UNREACHABLE_RETURN(LoweredExpr());
}
}
@@ -2241,11 +2241,11 @@ struct LoweringVisitor
Modifiers shallowCloneModifiers(Modifiers const& oldModifiers)
{
- RefPtr<SharedModifiers> shared = new SharedModifiers();
- shared->next = oldModifiers.first;
+ RefPtr<SharedModifiers> sharedModifiers = new SharedModifiers();
+ sharedModifiers->next = oldModifiers.first;
Modifiers newModifiers;
- newModifiers.first = shared;
+ newModifiers.first = sharedModifiers;
return newModifiers;
}
@@ -3840,7 +3840,7 @@ struct LoweringVisitor
substitutions->args.Add(elementType);
substitutions->args.Add(elementCount);
- auto declRef = DeclRef<Decl>(vectorTypeDecl.Ptr(), substitutions);
+ auto declRef = DeclRef<Decl>(vectorTypeDecl.Ptr(), substs);
return DeclRefType::Create(
session,
diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp
index 69f1f0b75..b9fba6380 100644
--- a/source/slang/mangle.cpp
+++ b/source/slang/mangle.cpp
@@ -58,10 +58,10 @@ namespace Slang
{
if( auto constVal = dynamic_cast<ConstantIntVal*>(val) )
{
- auto val = constVal->value;
- if( val >= 0 && val <= 9 )
+ auto cVal = constVal->value;
+ if(cVal >= 0 && cVal <= 9 )
{
- emit(context, (UInt) val);
+ emit(context, (UInt)cVal);
return;
}
}
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index fed838e6b..18294bb3e 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -567,7 +567,7 @@ getTypeLayoutForGlobalShaderParameter(
default:
SLANG_UNEXPECTED("unhandled source language");
- return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
}
@@ -1314,7 +1314,7 @@ static RefPtr<TypeLayout> processEntryPointParameter(
}
SLANG_UNEXPECTED("unhandled type kind");
- return nullptr;
+ UNREACHABLE_RETURN(nullptr);
}
static void collectEntryPointParameters(
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index bf85356db..8e0d5d66f 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -3394,7 +3394,7 @@ namespace Slang
return expr;
}
- static RefPtr<Expr> parseBoolLitExpr(Parser* parser, bool value)
+ static RefPtr<Expr> parseBoolLitExpr(Parser* /*parser*/, bool value)
{
RefPtr<ConstantExpr> constExpr = new ConstantExpr();
constExpr->ConstType = ConstantExpr::ConstantType::Bool;
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 602a929b2..1cda8e7d0 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -963,8 +963,8 @@ spGetTranslationUnitCount(
// Get the output code associated with a specific translation unit
SLANG_API char const* spGetTranslationUnitSource(
- SlangCompileRequest* request,
- int translationUnitIndex)
+ SlangCompileRequest* /*request*/,
+ int /*translationUnitIndex*/)
{
fprintf(stderr, "DEPRECATED: spGetTranslationUnitSource()\n");
return nullptr;
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 161f9cc26..9b6f6d44b 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -886,6 +886,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
bool NamedExpressionType::EqualsImpl(Type * /*type*/)
{
SLANG_UNEXPECTED("unreachable");
+ UNREACHABLE_RETURN(false);
}
Type* NamedExpressionType::CreateCanonicalType()
@@ -896,6 +897,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
int NamedExpressionType::GetHashCode()
{
SLANG_UNEXPECTED("unreachable");
+ UNREACHABLE_RETURN(0);
}
// FuncType
@@ -1033,6 +1035,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
int TypeType::GetHashCode()
{
SLANG_UNEXPECTED("unreachable");
+ UNREACHABLE_RETURN(0);
}
// GenericDeclRefType
@@ -1304,6 +1307,8 @@ void Type::accept(IValVisitor* visitor, void* extra)
return expr;
SLANG_UNIMPLEMENTED_X("generic substitution into expressions");
+
+ UNREACHABLE_RETURN(expr);
}
@@ -1483,6 +1488,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
else
{
SLANG_UNEXPECTED("unhandled syntax class name");
+ UNREACHABLE_RETURN(nullptr);
}
}
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index 0825da6b4..822311f60 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -51,7 +51,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
default:
SLANG_UNEXPECTED("uhandled scalar type");
- return SimpleLayoutInfo( LayoutResourceKind::Uniform, 0, 1 );
+ UNREACHABLE_RETURN(SimpleLayoutInfo( LayoutResourceKind::Uniform, 0, 1 ));
}
}
@@ -76,7 +76,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
default:
SLANG_UNEXPECTED("unhandled scalar type");
- return SimpleLayoutInfo();
+ UNREACHABLE_RETURN(SimpleLayoutInfo());
}
}
@@ -359,13 +359,11 @@ GLSLObjectLayoutRulesImpl kGLSLObjectLayoutRulesImpl;
struct GLSLPushConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override
+ virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind /*kind*/) override
{
// Special-case the layout for a constant-buffer, because we don't
// want it to allocate a descriptor-table slot
return SimpleLayoutInfo(LayoutResourceKind::PushConstantBuffer, 1);
-
- return GLSLObjectLayoutRulesImpl::GetObjectLayout(kind);
}
};
GLSLPushConstantBufferObjectLayoutRulesImpl kGLSLPushConstantBufferObjectLayoutRulesImpl_;
@@ -401,7 +399,7 @@ struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
// TODO: how to handle these?
default:
SLANG_UNEXPECTED("unhandled shader parameter kind");
- return SimpleLayoutInfo();
+ UNREACHABLE_RETURN(SimpleLayoutInfo());
}
}
};
@@ -717,7 +715,7 @@ static SimpleLayoutInfo getParameterBlockLayoutInfo(
else
{
SLANG_UNEXPECTED("unhandled parameter block type");
- return SimpleLayoutInfo();
+ UNREACHABLE_RETURN(SimpleLayoutInfo());
}
}
diff --git a/source/slang/vm.cpp b/source/slang/vm.cpp
index d5bacaa36..d795a841b 100644
--- a/source/slang/vm.cpp
+++ b/source/slang/vm.cpp
@@ -513,8 +513,8 @@ void computeTypeSizeAlign(
break;
default:
- impl->size = 0;
SLANG_UNIMPLEMENTED_X("type sizing");
+ UNREACHABLE(impl->size = 0);
break;
}
@@ -597,6 +597,9 @@ VMType loadVMType(
return getType(vmModule->vm, impl);
}
+
+ UNREACHABLE(SLANG_UNEXPECTED("unimplemented"));
+ UNREACHABLE_RETURN(VMType());
break;
}
}
@@ -860,7 +863,7 @@ void resumeThread(
case kIROp_BufferStore:
{
VMType resultType = decodeType(frame, &ip);
- /*UInt argCount =*/ decodeUInt(&ip);
+ /*UInt argCount = */decodeUInt(&ip);
char* bufferData = decodeOperand<char*>(frame, &ip);
uint32_t index = decodeOperand<uint32_t>(frame, &ip);
@@ -1021,7 +1024,7 @@ void resumeThread(
// knowing too much about an instruction...
VMType resultType = decodeType(frame, &ip);
- /*UInt argCount =*/ decodeUInt(&ip);
+ /*UInt argCount = */decodeUInt(&ip);
void* argPtrs[16] = { 0 };
auto leftOpnd = decodeOperandPtrAndType(frame, &ip);
auto type = leftOpnd.type;
@@ -1046,7 +1049,7 @@ void resumeThread(
case kIROp_Mul:
{
VMType type = decodeType(frame, &ip);
- /*UInt argCount =*/ decodeUInt(&ip);
+ /*UInt argCount = */decodeUInt(&ip);
void* leftPtr = decodeOperandPtr<void>(frame, &ip);
void* rightPtr = decodeOperandPtr<void>(frame, &ip);
@@ -1068,7 +1071,7 @@ void resumeThread(
case kIROp_Sub:
{
VMType type = decodeType(frame, &ip);
- /*UInt argCount =*/ decodeUInt(&ip);
+ /*UInt argCount = */decodeUInt(&ip);
void* leftPtr = decodeOperandPtr<void>(frame, &ip);
void* rightPtr = decodeOperandPtr<void>(frame, &ip);