summaryrefslogtreecommitdiff
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp361
1 files changed, 179 insertions, 182 deletions
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<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;
@@ -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<IRLayoutDecoration>();
@@ -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<IRLayoutDecoration>() )
@@ -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<UniformParameterBlockType>())
{
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<StructDecl> 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<BasicExpressionType>())
@@ -6149,19 +6147,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>() )
{
@@ -6180,7 +6178,7 @@ emitDeclImpl(decl, nullptr);
if( auto structDeclRef = declRef.As<StructDecl>() )
{
//
- 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;