diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-02-13 12:35:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-13 12:35:40 -0500 |
| commit | fd61c775f2e0e744c4bbbc2672d42e17c6863c1c (patch) | |
| tree | 753df099b956914081d78a20678b09bd558d00d3 /source | |
| parent | f07834e19a34d5f9c03d681083b5ba30e262889d (diff) | |
* Fix for unary - on glsl (#1222)
* Test to check fix
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 2212cf9cc..5f784cba3 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -1967,19 +1967,31 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO needClose = maybeEmitParens(outerPrec, prec); - // If it's a BitNot, but the data type is bool special case to ! - if (emitOp == EmitOp::BitNot && as<IRBoolType>(inst->getDataType())) + switch (inst->op) { - m_writer->emit("!"); - } - else - { - m_writer->emit(prec.op); + case kIROp_BitNot: + { + // If it's a BitNot, but the data type is bool special case to ! + m_writer->emit(as<IRBoolType>(inst->getDataType()) ? "!" : prec.op); + break; + } + case kIROp_Not: + { + m_writer->emit(prec.op); + break; + } + case kIROp_Neg: + { + // Emit a space after the unary -, so if we are followed by a negative literal we don't end up with -- + // which some downstream compilers determine to be decrement. + m_writer->emit("- "); + break; + } } - + emitOperand(operand, rightSide(prec, outerPrec)); break; - } + } case kIROp_Load: { auto base = inst->getOperand(0); |
