From a810aa31f5f366d69e67be96c169fec7d6041df7 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 7 Mar 2024 17:28:19 -0800 Subject: Link-time constant and linkage API improvements. (#3708) * Link-time constant and linkage API improvements. * Fix. * Allow module name to be empty. * Fix. * Fix. * Fix compile error. --- source/slang/slang-check-modifier.cpp | 51 ++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'source/slang/slang-check-modifier.cpp') diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp index 0f49891d0..cf4bf3b02 100644 --- a/source/slang/slang-check-modifier.cpp +++ b/source/slang/slang-check-modifier.cpp @@ -12,13 +12,20 @@ namespace Slang { + IntVal* SemanticsVisitor::checkLinkTimeConstantIntVal( + Expr* expr) + { + expr = CheckExpr(expr); + return CheckIntegerConstantExpression(expr, IntegerConstantExpressionCoercionType::AnyInteger, nullptr, ConstantFoldingKind::LinkTime); + } + ConstantIntVal* SemanticsVisitor::checkConstantIntVal( Expr* expr) { // First type-check the expression as normal expr = CheckExpr(expr); - auto intVal = CheckIntegerConstantExpression(expr, IntegerConstantExpressionCoercionType::AnyInteger, nullptr); + auto intVal = CheckIntegerConstantExpression(expr, IntegerConstantExpressionCoercionType::AnyInteger, nullptr, ConstantFoldingKind::CompileTime); if(!intVal) return nullptr; @@ -37,7 +44,7 @@ namespace Slang // First type-check the expression as normal expr = CheckExpr(expr); - auto intVal = CheckEnumConstantExpression(expr); + auto intVal = CheckEnumConstantExpression(expr, ConstantFoldingKind::CompileTime); if(!intVal) return nullptr; @@ -320,26 +327,33 @@ namespace Slang { SLANG_ASSERT(attr->args.getCount() == 3); - int32_t values[3]; + IntVal* values[3]; for (int i = 0; i < 3; ++i) { - int32_t value = 1; + IntVal* value = nullptr; auto arg = attr->args[i]; if (arg) { - auto intValue = checkConstantIntVal(arg); + auto intValue = checkLinkTimeConstantIntVal(arg); if (!intValue) { return false; } - if (intValue->getValue() < 1) + if (auto constIntVal = as(intValue)) { - getSink()->diagnose(attr, Diagnostics::nonPositiveNumThreads, intValue->getValue()); - return false; + if (constIntVal->getValue() < 1) + { + getSink()->diagnose(attr, Diagnostics::nonPositiveNumThreads, constIntVal->getValue()); + return false; + } } - value = int32_t(intValue->getValue()); + value = intValue; + } + else + { + value = m_astBuilder->getIntVal(m_astBuilder->getIntType(), 1); } values[i] = value; } @@ -1317,11 +1331,11 @@ namespace Slang { SLANG_ASSERT(attr->args.getCount() == 3); - int32_t values[3]; + IntVal* values[3]; for (int i = 0; i < 3; ++i) { - int32_t value = 1; + IntVal* value = nullptr; auto arg = attr->args[i]; if (arg) @@ -1331,12 +1345,19 @@ namespace Slang { return nullptr; } - if (intValue->getValue() < 1) + if (auto cintVal = as(intValue)) { - getSink()->diagnose(attr, Diagnostics::nonPositiveNumThreads, intValue->getValue()); - return nullptr; + if (cintVal->getValue() < 1) + { + getSink()->diagnose(attr, Diagnostics::nonPositiveNumThreads, cintVal->getValue()); + return nullptr; + } } - value = int32_t(intValue->getValue()); + value = intValue; + } + else + { + value = m_astBuilder->getIntVal(m_astBuilder->getIntType(), 1); } values[i] = value; } -- cgit v1.2.3