From 3a3a8b5f7701109fc413f42692c4de5769870489 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 7 Dec 2022 12:02:30 -0800 Subject: Lower-to-ir no longer produce `Construct` inst. (#2553) Co-authored-by: Yong He --- source/slang/slang-stdlib.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-stdlib.cpp') diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 6df9eea46..352d4ee27 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -3,7 +3,7 @@ #include "slang-compiler.h" #include "slang-ir.h" #include "slang-syntax.h" - +#include "slang-ir-util.h" #include "../core/slang-string-util.h" #define STRINGIZE(x) STRINGIZE2(x) @@ -193,6 +193,29 @@ namespace Slang } } + IROp getBaseTypeConversionOp( + BaseTypeConversionInfo const& toInfo, + BaseTypeConversionInfo const& fromInfo) + { + if (toInfo.tag == fromInfo.tag) + return (IROp)0; + + IROp intrinsicOpCode = (IROp)0; + auto toStyle = getTypeStyle(toInfo.tag); + auto fromStyle = getTypeStyle(fromInfo.tag); + if (toStyle == kIROp_BoolType) toStyle = kIROp_IntType; + if (fromStyle == kIROp_BoolType) fromStyle = kIROp_IntType; + if (toStyle == kIROp_IntType && fromStyle == kIROp_IntType) + intrinsicOpCode = kIROp_IntCast; + if (toStyle == kIROp_IntType && fromStyle == kIROp_FloatType) + intrinsicOpCode = kIROp_CastFloatToInt; + if (toStyle == kIROp_FloatType && fromStyle == kIROp_IntType) + intrinsicOpCode = kIROp_CastIntToFloat; + if (toStyle == kIROp_FloatType && fromStyle == kIROp_FloatType) + intrinsicOpCode = kIROp_FloatCast; + return intrinsicOpCode; + } + struct IntrinsicOpInfo { IROp opCode; char const* funcName; char const* opName; char const* interface; unsigned flags; }; static const IntrinsicOpInfo intrinsicUnaryOps[] = { -- cgit v1.2.3