summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-11-07 11:57:48 -0800
committerGitHub <noreply@github.com>2017-11-07 11:57:48 -0800
commitd1b45f3059e100d096327eb178c1bac365e564f1 (patch)
tree161fd25105ed7e924f1ad5b53517c55f101ddd5a /source
parent9919c823938ae929b16efac9d507f6d5eb122bf4 (diff)
IR: support for select and negate (#257)
- During IR emit, treat a "select" expression (`?:` operator) like any other `InvokeExpr`, since it will have an `__intrinsic_op` modifier attached to turn it into a `select` instruction. - During HLSL/GLSL emit from IR, turn a `select` instruction into a `?:` expression - Also add support for the `neg` instruction during HLSL/GLSL emit Note that right now we are assuming HLSL semantics for `?:` where it does not short-circuit. Correctly handling the GLSL case would require going back to special-case codegen for `SelectExpr`, but we can cross that bridge when we come to it.
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp17
-rw-r--r--source/slang/lower-to-ir.cpp5
2 files changed, 17 insertions, 5 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index d95946204..b66ff76c9 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -4911,6 +4911,13 @@ emitDeclImpl(decl, nullptr);
}
break;
+ case kIROp_Neg:
+ {
+ emit("-");
+ emitIROperand(ctx, inst->getArg(0));
+ }
+ break;
+
case kIROp_Sample:
emitIROperand(ctx, inst->getArg(0));
emit(".Sample(");
@@ -5033,6 +5040,16 @@ emitDeclImpl(decl, nullptr);
}
break;
+ case kIROp_Select:
+ {
+ emitIROperand(ctx, inst->getArg(0));
+ emit(" ? ");
+ emitIROperand(ctx, inst->getArg(1));
+ emit(" : ");
+ emitIROperand(ctx, inst->getArg(2));
+ }
+ break;
+
default:
emit("/* unhandled */");
break;
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index 2672c5698..2c64c539b 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -1497,11 +1497,6 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
return emitDeclRef(context, expr->declRef);
}
- LoweredValInfo visitSelectExpr(SelectExpr* /*expr*/)
- {
- SLANG_UNIMPLEMENTED_X("codegen for select expression");
- }
-
LoweredValInfo visitGenericAppExpr(GenericAppExpr* /*expr*/)
{
SLANG_UNIMPLEMENTED_X("generic application expression during code generation");