From 664e0da8dff1d04860cc46ce8139cbd47e15c552 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 4 Nov 2017 15:37:40 -0400 Subject: fix all unreachable code warnings --- source/slang/check.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/slang/check.cpp') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 0c35c4bf4..dbbd8f283 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -3328,7 +3328,7 @@ namespace Slang // to `interfaceDeclRef`. // SLANG_UNEXPECTED("reflexive type witness"); - return nullptr; + UNREACHABLE_RETURN(nullptr); } auto breadcrumbs = inBreadcrumbs; @@ -3343,7 +3343,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 @@ -5947,7 +5947,7 @@ namespace Slang RefPtr visitStaticMemberExpr(StaticMemberExpr* expr) { SLANG_UNEXPECTED("should not occur in unchecked AST"); - return expr; + UNREACHABLE_RETURN(expr); } RefPtr lookupResultFailure( -- cgit v1.2.3 From 288841f66c808af70ad7687f9704c87075129b18 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 4 Nov 2017 16:09:48 -0400 Subject: fixed all warnings --- source/slang/bytecode.cpp | 27 ++- source/slang/check.cpp | 20 +- source/slang/compiler.cpp | 5 +- source/slang/dxc-support.cpp | 1 - source/slang/emit.cpp | 361 ++++++++++++++++++------------------- source/slang/ir-insts.h | 14 +- source/slang/ir.cpp | 61 +++---- source/slang/lower-to-ir.cpp | 51 +++--- source/slang/lower.cpp | 16 +- source/slang/mangle.cpp | 6 +- source/slang/parser.cpp | 2 +- source/slang/slang.cpp | 4 +- source/slang/type-layout.cpp | 2 +- source/slang/vm.cpp | 23 ++- tools/eval-test/main.cpp | 3 +- tools/render-test/render-d3d11.cpp | 2 +- tools/render-test/render-gl.cpp | 6 +- tools/slang-generate/main.cpp | 9 +- 18 files changed, 301 insertions(+), 312 deletions(-) (limited to 'source/slang/check.cpp') diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp index ed969b72d..2130972e2 100644 --- a/source/slang/bytecode.cpp +++ b/source/slang/bytecode.cpp @@ -77,7 +77,6 @@ struct BytecodeGenerationPtr BytecodeGenerationPtr operator+(Int index) const { - UInt size = sizeof(T); Int delta = index * sizeof(T); UInt newOffset = offset + delta; return BytecodeGenerationPtr( @@ -196,7 +195,7 @@ void encodeUInt( { if( value < 128 ) { - encodeUInt8(context, value); + encodeUInt8(context, (uint8_t)value); return; } @@ -242,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. @@ -348,7 +348,6 @@ void generateBytecodeForInst( // auto argCount = inst->getArgCount(); - auto type = inst->getType(); encodeUInt(context, inst->op); encodeOperand(context, inst->getType()); encodeUInt(context, argCount); @@ -392,13 +391,13 @@ 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 ii = 0; ii < size; ++ii) { @@ -840,7 +839,7 @@ BytecodeGenerationPtr generateBytecodeSymbolForInst( } } } - assert(regCounter == regCount); + assert((UInt)regCounter == regCount); // Now that we've allocated our blocks and our registers // we can go through the actual process of emitting instructions. Hooray! @@ -851,7 +850,7 @@ BytecodeGenerationPtr generateBytecodeSymbolForInst( List blockOffsets; for( auto bb = irFunc->getFirstBlock(); bb; bb = bb->getNextBlock() ) { - UInt blockID = blockCounter++; + blockCounter++; // Get local bytecode offset for current block. UInt blockOffset = subContext->currentBytecode.Count(); @@ -1055,8 +1054,6 @@ void generateBytecodeContainer( // TODO: Need to dump BC representation of compiled kernel codes // for each specified code-generation target. - UInt translationUnitCount = compileReq->translationUnits.Count(); - List> bcModulesList; for (auto translationUnitReq : compileReq->translationUnits) { diff --git a/source/slang/check.cpp b/source/slang/check.cpp index dbbd8f283..b0cda278c 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -475,7 +475,7 @@ namespace Slang bool CoerceToProperTypeImpl( TypeExp const& typeExp, RefPtr* outProperType, - DiagnosticSink* sink) + DiagnosticSink* diagSink) { Type* type = typeExp.type.Ptr(); if(!type && typeExp.exp) @@ -505,11 +505,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(); } @@ -524,11 +524,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(); } @@ -1484,7 +1484,7 @@ namespace Slang } bool doesSignatureMatchRequirement( - CallableDecl* memberDecl, + CallableDecl* /*memberDecl*/, DeclRef requiredMemberDeclRef) { // TODO: actually implement matching here. For now we'll @@ -1923,8 +1923,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 @@ -4083,7 +4083,7 @@ namespace Slang // Create a witness that attests to the fact that `type` // is equal to itself. RefPtr createTypeEqualityWitness( - Type* type) + Type* /*type*/) { SLANG_UNEXPECTED("unimplemented"); } @@ -5944,7 +5944,7 @@ namespace Slang } } - RefPtr visitStaticMemberExpr(StaticMemberExpr* expr) + RefPtr visitStaticMemberExpr(StaticMemberExpr* /*expr*/) { SLANG_UNEXPECTED("should not occur in unchecked AST"); UNREACHABLE_RETURN(expr); 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 af4f0ad6a..336d73abe 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -2395,7 +2395,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; @@ -4090,8 +4090,7 @@ emitDeclImpl(decl, nullptr); { auto semanticName = varLayout->systemValueSemantic; semanticName = semanticName.ToLower(); - auto semanticIndex = varLayout->systemValueSemanticIndex; - + if(semanticName == "sv_position") { return "gl_Position"; @@ -4190,7 +4189,7 @@ emitDeclImpl(decl, nullptr); }; void emitDeclarator( - EmitContext* context, + EmitContext* ctx, IRDeclaratorInfo* declarator) { if(!declarator) @@ -4205,20 +4204,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) @@ -4365,9 +4364,9 @@ emitDeclImpl(decl, nullptr); } #endif - CodeGenTarget getTarget(EmitContext* context) + CodeGenTarget getTarget(EmitContext* ctx) { - return context->shared->target; + return ctx->shared->target; } #if 0 @@ -4467,7 +4466,7 @@ emitDeclImpl(decl, nullptr); #endif bool shouldFoldIRInstIntoUseSites( - EmitContext* context, + EmitContext* ctx, IRValue* inst) { // Certain opcodes should always be folded in @@ -4501,7 +4500,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; } @@ -4510,7 +4509,7 @@ emitDeclImpl(decl, nullptr); } bool isDerefBaseImplicit( - EmitContext* context, + EmitContext* /*context*/, IRValue* inst) { auto type = inst->getType(); @@ -4529,13 +4528,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; } @@ -4550,7 +4549,7 @@ emitDeclImpl(decl, nullptr); } void emitIRArgs( - EmitContext* context, + EmitContext* ctx, IRInst* inst) { UInt argCount = inst->argCount; @@ -4560,13 +4559,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) { @@ -4574,7 +4573,7 @@ emitDeclImpl(decl, nullptr); } void emitIRType( - EmitContext* context, + EmitContext* /*context*/, IRType* type, Name* name) { @@ -4582,14 +4581,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(); @@ -4599,7 +4598,7 @@ emitDeclImpl(decl, nullptr); if (type->Equals(getSession()->getVoidType())) return; - emitIRType(context, type, getIRName(inst)); + emitIRType(ctx, type, getIRName(inst)); emit(" = "); } @@ -4664,7 +4663,7 @@ emitDeclImpl(decl, nullptr); int readCount() { int c = peek(); - if(!isDigit(c)) + if(!isDigit((char)c)) { SLANG_UNEXPECTED("bad name mangling"); UNREACHABLE_RETURN(0); @@ -4679,7 +4678,7 @@ emitDeclImpl(decl, nullptr); { count = count*10 + c - '0'; c = peek(); - if(!isDigit(c)) + if(!isDigit((char)c)) return count; get(); @@ -4692,7 +4691,7 @@ emitDeclImpl(decl, nullptr); for(;;) { int c = peek(); - if(!isDigit(c)) + if(!isDigit((char)c)) return result; // Read the length part @@ -4710,7 +4709,7 @@ emitDeclImpl(decl, nullptr); }; void emitIntrinsicCallExpr( - EmitContext* context, + EmitContext* ctx, IRCall* inst, IRFunc* func) { @@ -4732,38 +4731,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; @@ -4772,40 +4771,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; @@ -4815,7 +4814,7 @@ emitDeclImpl(decl, nullptr); IRFieldExtract* fieldExtract = (IRFieldExtract*) inst; - emitIROperand(context, fieldExtract->getBase()); + emitIROperand(ctx, fieldExtract->getBase()); emit("."); emit(getIRName(fieldExtract->getField())); } @@ -4827,9 +4826,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("."); } @@ -4839,9 +4838,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, +); @@ -4875,22 +4874,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()) { 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; @@ -4904,64 +4903,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: @@ -4970,16 +4969,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. @@ -4989,16 +4988,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; @@ -5006,7 +5005,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) @@ -5026,7 +5025,7 @@ emitDeclImpl(decl, nullptr); case kIROp_specialize: { - emitIROperand(context, inst->getArg(0)); + emitIROperand(ctx, inst->getArg(0)); } break; @@ -5037,10 +5036,10 @@ emitDeclImpl(decl, nullptr); } void emitIRInst( - EmitContext* context, + EmitContext* ctx, IRInst* inst) { - if (shouldFoldIRInstIntoUseSites(context, inst)) + if (shouldFoldIRInstIntoUseSites(ctx, inst)) { return; } @@ -5048,8 +5047,8 @@ emitDeclImpl(decl, nullptr); switch(inst->op) { default: - emitIRInstResultDecl(context, inst); - emitIRInstExpr(context, inst); + emitIRInstResultDecl(ctx, inst); + emitIRInstExpr(ctx, inst); emit(";\n"); break; @@ -5059,7 +5058,7 @@ emitDeclImpl(decl, nullptr); auto valType = ((PtrType*)ptrType)->getValueType(); auto name = getIRName(inst); - emitIRType(context, valType, name); + emitIRType(ctx, valType, name); emit(";\n"); } break; @@ -5079,17 +5078,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) @@ -5105,7 +5104,7 @@ emitDeclImpl(decl, nullptr); emit(kComponents[elementIndex]); } emit(" = "); - emitIROperand(context, inst->getArg(1)); + emitIROperand(ctx, inst->getArg(1)); emit(";\n"); } break; @@ -5113,11 +5112,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; @@ -5155,7 +5154,7 @@ emitDeclImpl(decl, nullptr); } VarLayout* getVarLayout( - EmitContext* context, + EmitContext* /*context*/, IRValue* var) { auto decoration = var->findDecoration(); @@ -5166,11 +5165,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); @@ -5187,7 +5186,7 @@ emitDeclImpl(decl, nullptr); // be captured. // void emitIRStmtsForBlocks( - EmitContext* context, + EmitContext* ctx, IRBlock* begin, IRBlock* end) { @@ -5199,7 +5198,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. @@ -5212,7 +5211,7 @@ emitDeclImpl(decl, nullptr); case kIROp_ReturnVal: case kIROp_ReturnVoid: - emitIRInst(context, terminator); + emitIRInst(ctx, terminator); return; case kIROp_if: @@ -5224,10 +5223,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"); @@ -5247,15 +5246,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"); @@ -5300,7 +5299,7 @@ emitDeclImpl(decl, nullptr); emit("for(;;)\n{\n"); emitIRStmtsForBlocks( - context, + ctx, targetBlock, nullptr); @@ -5343,7 +5342,7 @@ emitDeclImpl(decl, nullptr); // emitIRStmtsForBlocks( - context, + ctx, targetBlock, nullptr); @@ -5372,7 +5371,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 @@ -5446,10 +5445,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 @@ -5493,7 +5491,7 @@ emitDeclImpl(decl, nullptr); auto name = getIRFuncName(func); - emitIRType(context, resultType, name); + emitIRType(ctx, resultType, name); emit("("); auto firstParam = func->getFirstParam(); @@ -5503,14 +5501,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)) @@ -5519,7 +5517,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"); } @@ -5530,7 +5528,7 @@ emitDeclImpl(decl, nullptr); } void emitIRFuncDecl( - EmitContext* context, + EmitContext* ctx, IRFunc* func) { // We don't want to declare generic functions, @@ -5541,7 +5539,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, @@ -5562,7 +5560,7 @@ emitDeclImpl(decl, nullptr); auto name = getIRFuncName(func); - emitIRType(context, resultType, name); + emitIRType(ctx, resultType, name); emit("("); auto paramCount = funcType->getParamCount(); @@ -5595,13 +5593,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() ) @@ -5628,7 +5626,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 @@ -5663,13 +5661,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; } @@ -5683,17 +5681,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); } } @@ -5720,13 +5718,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 @@ -5776,7 +5774,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. @@ -5811,14 +5809,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); @@ -5857,10 +5855,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); @@ -5877,11 +5875,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); @@ -5934,10 +5932,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); @@ -5959,24 +5957,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(); @@ -5988,7 +5986,7 @@ emitDeclImpl(decl, nullptr); { case kIROp_ConstantBufferType: case kIROp_TextureBufferType: - emitIRParameterBlock(context, varDecl, (IRUniformBufferType*) varType); + emitIRParameterBlock(ctx, varDecl, (IRUniformBufferType*) varType); return; default: @@ -5998,9 +5996,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) @@ -6014,17 +6012,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(); @@ -6034,7 +6032,7 @@ emitDeclImpl(decl, nullptr); if (auto paramBlockType = varType->As()) { emitIRParameterBlock( - context, + ctx, varDecl, paramBlockType); return; @@ -6042,9 +6040,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) @@ -6058,17 +6056,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, @@ -6076,15 +6074,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: @@ -6093,7 +6091,7 @@ emitDeclImpl(decl, nullptr); } void ensureStructDecl( - EmitContext* context, + EmitContext* ctx, DeclRef declRef) { // TODO: Eventually need to deal with the case where @@ -6101,10 +6099,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) ) @@ -6113,7 +6111,7 @@ emitDeclImpl(decl, nullptr); continue; auto fieldType = GetType(ff); - emitIRUsedType(context, fieldType); + emitIRUsedType(ctx, fieldType); } Emit("struct "); @@ -6125,7 +6123,7 @@ emitDeclImpl(decl, nullptr); continue; auto fieldType = GetType(ff); - emitIRType(context, fieldType, getIRName(ff)); + emitIRType(ctx, fieldType, getIRName(ff)); EmitSemantics(ff.getDecl()); @@ -6138,7 +6136,7 @@ emitDeclImpl(decl, nullptr); // make sure that we have emitted whatever // it needs. void emitIRUsedType( - EmitContext* context, + EmitContext* ctx, Type* type) { if(type->As()) @@ -6149,19 +6147,19 @@ emitDeclImpl(decl, nullptr); {} else if(auto arrayType = type->As()) { - emitIRUsedType(context, arrayType->baseType); + emitIRUsedType(ctx, arrayType->baseType); } else if( auto textureType = type->As() ) { - emitIRUsedType(context, textureType->elementType); + emitIRUsedType(ctx, textureType->elementType); } else if( auto genericType = type->As() ) { - emitIRUsedType(context, genericType->elementType); + emitIRUsedType(ctx, genericType->elementType); } else if( auto ptrType = type->As() ) { - emitIRUsedType(context, ptrType->getValueType()); + emitIRUsedType(ctx, ptrType->getValueType()); } else if(type->As() ) { @@ -6180,7 +6178,7 @@ emitDeclImpl(decl, nullptr); if( auto structDeclRef = declRef.As() ) { // - ensureStructDecl(context, structDeclRef); + ensureStructDecl(ctx, structDeclRef); } } else @@ -6188,7 +6186,7 @@ emitDeclImpl(decl, nullptr); } void emitIRUsedTypesForValue( - EmitContext* context, + EmitContext* ctx, IRValue* value) { if(!value) return; @@ -6197,17 +6195,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); } } } @@ -6215,27 +6213,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 @@ -6246,14 +6244,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); } } @@ -6343,8 +6341,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 f7bcc2eb2..8127fb70f 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 102fb947c..efd3730ae 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -206,14 +206,13 @@ namespace Slang void IRBuilder::addInst( IRInst* inst) { - auto insertBefore = insertBeforeInst; if(insertBeforeInst) { inst->insertBefore(insertBeforeInst); return; } - auto parent = block; + auto parent = curBlock; if (!parent) return; @@ -221,7 +220,7 @@ namespace Slang } static IRValue* createValueImpl( - IRBuilder* builder, + IRBuilder* /*builder*/, UInt size, IROp op, IRType* type) @@ -249,7 +248,7 @@ namespace Slang // arguments *after* the type (which is a mandatory // argument for all instructions). static IRInst* createInstImpl( - IRBuilder* builder, + IRBuilder* /*builder*/, UInt size, IROp op, IRType* type, @@ -261,7 +260,6 @@ namespace Slang IRInst* inst = (IRInst*) malloc(size); memset(inst, 0, size); - auto module = builder->getModule(); inst->argCount = fixedArgCount + varArgCount; inst->op = op; @@ -494,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; @@ -511,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; } @@ -819,12 +817,12 @@ namespace Slang IRFunc* IRBuilder::createFunc() { - IRFunc* func = createValue( + IRFunc* rsFunc = createValue( this, kIROp_Func, nullptr); - addGlobalValue(getModule(), func); - return func; + addGlobalValue(getModule(), rsFunc); + return rsFunc; } IRGlobalVar* IRBuilder::createGlobalVar( @@ -882,11 +880,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; } @@ -899,7 +897,7 @@ namespace Slang kIROp_Param, type); - if (auto bb = block) + if (auto bb = curBlock) { bb->addParam(param); } @@ -1119,13 +1117,13 @@ namespace Slang } IRInst* IRBuilder::emitBranch( - IRBlock* block) + IRBlock* pBlock) { auto inst = createInst( this, kIROp_unconditionalBranch, nullptr, - block); + pBlock); addInst(inst); return inst; } @@ -1687,7 +1685,7 @@ namespace Slang dumpChildrenRaw(context, block); } - +#if 0 static void dumpChildrenRaw( IRDumpContext* context, IRFunc* func) @@ -1710,7 +1708,7 @@ namespace Slang dumpIndent(context); dump(context, "}\n"); } - +#endif static void dumpInst( IRDumpContext* context, IRInst* inst) @@ -2229,7 +2227,6 @@ namespace Slang void IRInst::removeArguments() { - UInt argCount = this->argCount; for( UInt aa = 0; aa < argCount; ++aa ) { IRUse& use = getArgs()[aa]; @@ -2270,7 +2267,7 @@ namespace Slang shared.session = session; IRBuilder builder; - builder.shared = &shared; + builder.sharedBuilder = &shared; RefPtr ptrType = session->getPtrType(valueType); @@ -2374,9 +2371,9 @@ namespace Slang IRBuilder* builder, Type* type, VarLayout* varLayout, - TypeLayout* typeLayout, - LayoutResourceKind kind, - GlobalVaryingDeclarator* declarator) + TypeLayout* /*typeLayout*/, + LayoutResourceKind /*kind*/, + GlobalVaryingDeclarator* /*declarator*/) { // TODO: We might be creating an `in` or `out` variable based on // an `in out` function parameter. In this case we should @@ -2658,8 +2655,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 @@ -2716,7 +2713,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)); @@ -2768,7 +2765,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 @@ -2827,7 +2824,7 @@ namespace Slang break; } - builder.block = bb; + builder.curBlock = bb; builder.insertBeforeInst = terminatorInst; assign(&builder, globalOutputVal, localVal); @@ -3216,7 +3213,7 @@ namespace Slang { auto clonedKey = context->maybeCloneValue(originalEntry->requirementKey.usedValue); auto clonedVal = context->maybeCloneValue(originalEntry->satisfyingVal.usedValue); - auto clonedEntry = context->builder->createWitnessTableEntry( + /*auto clonedEntry = */context->builder->createWitnessTableEntry( clonedTable, clonedKey, clonedVal); @@ -3240,7 +3237,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. // @@ -3256,7 +3253,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()) @@ -3277,7 +3274,7 @@ namespace Slang { assert(cb); - builder->block = cb; + builder->curBlock = cb; for (auto oi = ob->getFirstInst(); oi; oi = oi->getNextInst()) { cloneInst(context, builder, oi); @@ -3575,7 +3572,7 @@ namespace Slang sharedBuilder->session = session; IRBuilder* builder = &sharedContext->builderStorage; - builder->shared = sharedBuilder; + builder->sharedBuilder = sharedBuilder; if( !module ) { diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 17ebacf98..0c933374b 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -668,11 +668,10 @@ top: auto getters = getMembersOfType(boundSubscriptInfo->declRef); if (getters.Count()) { - auto& getter = *getters.begin(); lowered = emitCallToDeclRef( context, boundSubscriptInfo->type, - getter, + *getters.begin(), nullptr, boundSubscriptInfo->args); goto top; @@ -838,7 +837,7 @@ struct ValLoweringVisitor : ValVisitorirBuilder; } - LoweredValInfo visitVal(Val* val) + LoweredValInfo visitVal(Val* /*val*/) { SLANG_UNIMPLEMENTED_X("value lowering"); } @@ -1005,7 +1004,7 @@ struct ExprLoweringVisitorBase : ExprVisitor return info; } - LoweredValInfo visitOverloadedExpr(OverloadedExpr* expr) + LoweredValInfo visitOverloadedExpr(OverloadedExpr* /*expr*/) { SLANG_UNEXPECTED("overloaded expressions should not occur in checked AST"); } @@ -1019,7 +1018,7 @@ struct ExprLoweringVisitorBase : ExprVisitor return subscriptValue(type, baseVal, indexVal); } - LoweredValInfo visitThisExpr(ThisExpr* expr) + LoweredValInfo visitThisExpr(ThisExpr* /*expr*/) { return context->thisVal; } @@ -1099,7 +1098,7 @@ struct ExprLoweringVisitorBase : ExprVisitor return lowerSubExpr(expr->base); } - LoweredValInfo visitInitializerListExpr(InitializerListExpr* expr) + LoweredValInfo visitInitializerListExpr(InitializerListExpr* /*expr*/) { SLANG_UNIMPLEMENTED_X("codegen for initializer list expression"); } @@ -1123,7 +1122,7 @@ struct ExprLoweringVisitorBase : ExprVisitor SLANG_UNEXPECTED("unexpected constant type"); } - LoweredValInfo visitAggTypeCtorExpr(AggTypeCtorExpr* expr) + LoweredValInfo visitAggTypeCtorExpr(AggTypeCtorExpr* /*expr*/) { SLANG_UNIMPLEMENTED_X("codegen for aggregate type constructor expression"); } @@ -1134,8 +1133,6 @@ struct ExprLoweringVisitorBase : ExprVisitor InvokeExpr* expr, List* ioArgs) { - auto& irArgs = *ioArgs; - for( auto arg : expr->Arguments ) { // TODO: Need to handle case of l-value arguments, @@ -1164,8 +1161,6 @@ struct ExprLoweringVisitorBase : ExprVisitor List* ioArgs, List* ioFixups) { - auto funcDecl = funcDeclRef.getDecl(); - auto& args = expr->Arguments; UInt argCount = expr->Arguments.Count(); UInt argIndex = 0; for (auto paramDeclRef : getMembersOfType(funcDeclRef)) @@ -1499,17 +1494,17 @@ struct ExprLoweringVisitorBase : ExprVisitor 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"); } @@ -1615,7 +1610,7 @@ struct StmtLoweringVisitor : StmtVisitor IRBuilder* getBuilder() { return context->irBuilder; } - void visitStmt(Stmt* stmt) + void visitStmt(Stmt* /*stmt*/) { SLANG_UNIMPLEMENTED_X("stmt catch-all"); } @@ -1634,7 +1629,7 @@ struct StmtLoweringVisitor : StmtVisitor { auto builder = getBuilder(); - auto prevBlock = builder->block; + auto prevBlock = builder->curBlock; auto parentFunc = prevBlock->parentFunc; // If the previous block doesn't already have @@ -1647,8 +1642,8 @@ struct StmtLoweringVisitor : StmtVisitor parentFunc->addBlock(block); - builder->func = parentFunc; - builder->block = block; + builder->curFunc = parentFunc; + builder->curBlock = block; } // Start a new block at the current location. @@ -2055,17 +2050,17 @@ struct DeclLoweringVisitor : DeclVisitor 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"); } - LoweredValInfo visitGenericTypeParamDecl(GenericTypeParamDecl* decl) + LoweredValInfo visitGenericTypeParamDecl(GenericTypeParamDecl* /*decl*/) { return LoweredValInfo(); } @@ -2116,7 +2111,7 @@ struct DeclLoweringVisitor : DeclVisitor auto irRequirement = context->irBuilder->getDeclRefVal(requiredMemberDeclRef); auto irSatisfyingVal = getSimpleVal(context, ensureDecl(context, satisfyingMemberDecl)); - auto witnessTableEntry = context->irBuilder->createWitnessTableEntry( + context->irBuilder->createWitnessTableEntry( witnessTable, irRequirement, irSatisfyingVal); @@ -2678,7 +2673,7 @@ struct DeclLoweringVisitor : DeclVisitor // need to create an IR function here IRFunc* irFunc = subBuilder->createFunc(); - subBuilder->func = irFunc; + subBuilder->curFunc = irFunc; trySetMangledName(irFunc, decl); @@ -2730,7 +2725,7 @@ struct DeclLoweringVisitor : DeclVisitor // 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 @@ -2766,7 +2761,7 @@ struct DeclLoweringVisitor : DeclVisitor // 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 ) @@ -2847,7 +2842,7 @@ struct DeclLoweringVisitor : DeclVisitor // 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())) { @@ -2950,7 +2945,7 @@ LoweredValInfo ensureDecl( return result; IRBuilder subIRBuilder; - subIRBuilder.shared = context->irBuilder->shared; + subIRBuilder.sharedBuilder = context->irBuilder->sharedBuilder; IRGenContext subContext = *context; @@ -3171,7 +3166,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 429ebbc97..73854a5c7 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -2236,11 +2236,11 @@ struct LoweringVisitor Modifiers shallowCloneModifiers(Modifiers const& oldModifiers) { - RefPtr shared = new SharedModifiers(); - shared->next = oldModifiers.first; + RefPtr sharedModifiers = new SharedModifiers(); + sharedModifiers->next = oldModifiers.first; Modifiers newModifiers; - newModifiers.first = shared; + newModifiers.first = sharedModifiers; return newModifiers; } @@ -3809,12 +3809,12 @@ struct LoweringVisitor "Vector").As(); auto vectorTypeDecl = vectorGenericDecl->inner; - auto substitutions = new Substitutions(); - substitutions->genericDecl = vectorGenericDecl.Ptr(); - substitutions->args.Add(elementType); - substitutions->args.Add(elementCount); + auto substs = new Substitutions(); + substs->genericDecl = vectorGenericDecl.Ptr(); + substs->args.Add(elementType); + substs->args.Add(elementCount); - auto declRef = DeclRef(vectorTypeDecl.Ptr(), substitutions); + auto declRef = DeclRef(vectorTypeDecl.Ptr(), substs); return DeclRefType::Create( session, diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp index 63e54d065..ed17a7ffa 100644 --- a/source/slang/mangle.cpp +++ b/source/slang/mangle.cpp @@ -58,10 +58,10 @@ namespace Slang { if( auto constVal = dynamic_cast(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/parser.cpp b/source/slang/parser.cpp index 322f403e6..8ec6f70ca 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -3342,7 +3342,7 @@ namespace Slang return expr; } - static RefPtr parseBoolLitExpr(Parser* parser, bool value) + static RefPtr parseBoolLitExpr(Parser* /*parser*/, bool value) { RefPtr constExpr = new ConstantExpr(); constExpr->ConstType = ConstantExpr::ConstantType::Bool; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index f1d1d6ba2..ecee38777 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -962,8 +962,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/type-layout.cpp b/source/slang/type-layout.cpp index bfdc6c366..822311f60 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -359,7 +359,7 @@ 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 diff --git a/source/slang/vm.cpp b/source/slang/vm.cpp index 4b912fb7c..02f8e82fd 100644 --- a/source/slang/vm.cpp +++ b/source/slang/vm.cpp @@ -528,7 +528,7 @@ void computeTypeSizeAlign( } VMType getType( - VM* vm, + VM* /*vm*/, VMTypeImpl* typeImpl) { // TODO: need to look up an existing type that matches... @@ -604,7 +604,7 @@ VMType loadVMType( } } -void* allocateImpl(VM* vm, UInt size, UInt align) +void* allocateImpl(VM* /*vm*/, UInt size, UInt /*align*/) { void* ptr = malloc(size); memset(ptr, 0, size); @@ -666,7 +666,7 @@ void* loadVMSymbol( VMModule* loadVMModuleInstance( VM* vm, void const* bytecode, - size_t bytecodeSize) + size_t /*bytecodeSize*/) { BCHeader* bcHeader = (BCHeader*) bytecode; @@ -739,7 +739,7 @@ void* findGlobalSymbolPtr( } VMThread* createThread( - VM* vm) + VM* /*vm*/) { VMThread* thread = new VMThread(); thread->frame = nullptr; @@ -863,7 +863,7 @@ void resumeThread( case kIROp_BufferStore: { VMType resultType = decodeType(frame, &ip); - UInt argCount = decodeUInt(&ip); + /*UInt argCount = */decodeUInt(&ip); char* bufferData = decodeOperand(frame, &ip); uint32_t index = decodeOperand(frame, &ip); @@ -944,10 +944,9 @@ void resumeThread( case kIROp_ReturnVal: { VMType instType = decodeType(frame, &ip); - UInt argCount = decodeUInt(&ip); + /*UInt argCount =*/ decodeUInt(&ip); void* argPtr = decodeOperandPtr(frame, &ip); - VMFrame* oldFrame = frame; VMFrame* newFrame = frame->parent; vmThread->frame = newFrame; @@ -980,7 +979,7 @@ void resumeThread( Int destinationBlock = decodeSInt(&ip); for( UInt aa = 2; aa < argCount; ++aa ) { - void* argPtr = decodeOperandPtr(frame, &ip); + decodeOperandPtr(frame, &ip); } // TODO: we need to deal with the case of @@ -1006,7 +1005,7 @@ void resumeThread( Int falseBlockID = decodeSInt(&ip); for( UInt aa = 4; aa < argCount; ++aa ) { - void* argPtr = decodeOperandPtr(frame, &ip); + decodeOperandPtr(frame, &ip); } Int destinationBlock = *condition ? trueBlockID : falseBlockID; @@ -1025,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; @@ -1050,7 +1049,7 @@ void resumeThread( case kIROp_Mul: { VMType type = decodeType(frame, &ip); - UInt argCount = decodeUInt(&ip); + /*UInt argCount = */decodeUInt(&ip); void* leftPtr = decodeOperandPtr(frame, &ip); void* rightPtr = decodeOperandPtr(frame, &ip); @@ -1072,7 +1071,7 @@ void resumeThread( case kIROp_Sub: { VMType type = decodeType(frame, &ip); - UInt argCount = decodeUInt(&ip); + /*UInt argCount = */decodeUInt(&ip); void* leftPtr = decodeOperandPtr(frame, &ip); void* rightPtr = decodeOperandPtr(frame, &ip); diff --git a/tools/eval-test/main.cpp b/tools/eval-test/main.cpp index 486de7bd9..0159f0107 100644 --- a/tools/eval-test/main.cpp +++ b/tools/eval-test/main.cpp @@ -16,7 +16,8 @@ int main( char const* inputPath = argv[1]; // Slurp in the input file, so that we can compile and run it - FILE* inputFile = fopen(inputPath, "rb"); + FILE* inputFile; + fopen_s(&inputFile, inputPath, "rb"); assert(inputFile); fseek(inputFile, 0, SEEK_END); diff --git a/tools/render-test/render-d3d11.cpp b/tools/render-test/render-d3d11.cpp index ee34445d0..a40e6e6e0 100644 --- a/tools/render-test/render-d3d11.cpp +++ b/tools/render-test/render-d3d11.cpp @@ -1088,7 +1088,7 @@ public: } else { - printf("invalid output type at %d.\n"); + printf("invalid output type at %d.\n", id); } } id++; diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp index a853a53a4..f07e27985 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/render-test/render-gl.cpp @@ -8,6 +8,7 @@ #include #include #include "core/basic.h" +#include "core/secure-crt.h" #include "external/stb/stb_image_write.h" // TODO(tfoley): eventually we should be able to run these @@ -736,7 +737,7 @@ public: { glSamplerParameteri(rs.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(rs.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(rs.handle, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8.0f); + glSamplerParameteri(rs.handle, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8); } else { @@ -802,7 +803,8 @@ public: virtual void serializeOutput(BindingState* state, const char * fileName) { GLBindingState * glState = (GLBindingState*)state; - FILE * f = fopen(fileName, "wt"); + FILE * f; + fopen_s(&f, fileName, "wt"); for (auto & entry : glState->entries) { if (entry.isOutput) diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp index eef7d95c7..8208354e4 100644 --- a/tools/slang-generate/main.cpp +++ b/tools/slang-generate/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "../../source/core/secure-crt.h" struct StringSpan { @@ -401,7 +402,8 @@ int main( // Read the contents o the file and translate it into a "template" file - FILE* inputStream = fopen(inputPath, "rb"); + FILE* inputStream; + fopen_s(&inputStream, inputPath, "rb"); fseek(inputStream, 0, SEEK_END); size_t inputSize = ftell(inputStream); fseek(inputStream, 0, SEEK_SET); @@ -415,9 +417,10 @@ int main( Node* node = readInput(input, inputEnd); char outputPath[1024]; - sprintf(outputPath, "%s.h", inputPath); + sprintf_s(outputPath, "%s.h", inputPath); - FILE* outputStream = fopen(outputPath, "w"); + FILE* outputStream; + fopen_s(&outputStream, outputPath, "w"); emitBody(outputStream, node); -- cgit v1.2.3 From a7dd782d7895e1f277573fb9923be653ab813941 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 4 Nov 2017 16:23:21 -0400 Subject: fix linux build --- source/slang/bytecode.cpp | 9 ++++++--- source/slang/check.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'source/slang/check.cpp') diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp index 2130972e2..e3cd9e74e 100644 --- a/source/slang/bytecode.cpp +++ b/source/slang/bytecode.cpp @@ -271,9 +271,12 @@ BCConst getGlobalValue( } SLANG_UNEXPECTED("no ID for inst"); - UNREACHABLE(bcConst.flavor = (BCConstFlavor) -1); - UNREACHABLE(bcConst.id = -9999); - UNREACHABLE_RETURN(bcConst); + { + UNREACHABLE(BCConst bcConst); + UNREACHABLE(bcConst.flavor = (BCConstFlavor)-1); + UNREACHABLE(bcConst.id = -9999); + UNREACHABLE_RETURN(bcConst); + } } Int getLocalID( diff --git a/source/slang/check.cpp b/source/slang/check.cpp index cbdf68bf2..65b2295cc 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -5993,7 +5993,7 @@ namespace Slang RefPtr visitStaticMemberExpr(StaticMemberExpr* /*expr*/) { SLANG_UNEXPECTED("should not occur in unchecked AST"); - UNREACHABLE_RETURN(expr); + UNREACHABLE_RETURN(nullptr); } RefPtr lookupResultFailure( -- cgit v1.2.3