diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-24 10:56:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-24 10:56:53 -0700 |
| commit | d245c72f2a92a74ccda83f41758c1948ae5132d3 (patch) | |
| tree | f036e1f2afb7febe2de9b09990bcde6c04f3bad1 /source/slang/slang-check-expr.cpp | |
| parent | 0b808453407f8feef8574cae99afd90771712185 (diff) | |
Compiler time evaluation of all int and bool operators. (#2376)
* Compiler time evaluation of all int and bool operators.
* Fix linux compile error.
* Fix.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 7257790af..8e14af72a 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -977,6 +977,19 @@ namespace Slang return PolynomialIntVal::mul(m_astBuilder, argVals[0], argVals[1]); } } + else if (opName == getName("/") || opName == getName("==") || opName == getName(">=") || opName == getName("<=") || opName == getName("!=") + || opName == getName(">") || opName == getName("<") || opName == getName("&&") || opName == getName("||") || opName == getName("!") + || opName == getName("|") || opName == getName("&") || opName == getName("^") || opName == getName("~") || opName == getName("%") || + opName == getName("?:") || opName == getName("<<") || opName == getName(">>")) + { + auto result = m_astBuilder->create<SomeIntVal>(); + result->args.addRange(argVals, argCount); + result->funcDeclRef = funcDeclRef; + result->funcType = as<Type>(funcDeclRefExpr.getExpr()->type->substitute( + m_astBuilder, funcDeclRefExpr.getSubsts())); + SLANG_RELEASE_ASSERT(result->funcType); + return result; + } return nullptr; } @@ -1062,6 +1075,15 @@ namespace Slang CASE(/); CASE(%); #undef CASE + else if (opName == getName("?:")) + { + if (argCount != 3) + return nullptr; + if (constArgVals[0] != 0) + resultValue = constArgVals[1]; + else + resultValue = constArgVals[2]; + } // TODO(tfoley): more cases else { |
