summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-downstream-compiler.cpp2
-rw-r--r--source/core/slang-type-text-util.cpp101
-rw-r--r--source/core/slang-type-text-util.h26
3 files changed, 109 insertions, 20 deletions
diff --git a/source/core/slang-downstream-compiler.cpp b/source/core/slang-downstream-compiler.cpp
index 0a40092ea..8a795363d 100644
--- a/source/core/slang-downstream-compiler.cpp
+++ b/source/core/slang-downstream-compiler.cpp
@@ -49,7 +49,7 @@ static DownstreamCompiler::Infos _calcInfos()
void DownstreamCompiler::Desc::appendAsText(StringBuilder& out) const
{
- out << TypeTextUtil::asHumanText(type);
+ out << TypeTextUtil::getPassThroughAsHumanText(type);
// Append the version if there is a version
if (majorVersion || minorVersion)
diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp
index b9ccc4971..376efe0a9 100644
--- a/source/core/slang-type-text-util.cpp
+++ b/source/core/slang-type-text-util.cpp
@@ -1,6 +1,7 @@
#include "slang-type-text-util.h"
+#include "slang-string-util.h"
namespace Slang
{
@@ -36,16 +37,46 @@ struct ScalarTypeInfo
UnownedStringSlice text;
};
-static const ScalarTypeInfo s_scalarTypeInfo[] =
+static const ScalarTypeInfo s_scalarTypeInfos[] =
{
#define SLANG_SCALAR_TYPE_INFO(value, text) \
{ slang::TypeReflection::ScalarType::value, UnownedStringSlice::fromLiteral(#text) },
SLANG_SCALAR_TYPES(SLANG_SCALAR_TYPE_INFO)
};
+struct CompileTargetInfo
+{
+ SlangCompileTarget target; ///< The target
+ const char* extensions; ///< Comma delimited list of extensions associated with the target
+ const char* names; ///< Comma delimited list of names associated with the target. NOTE! First name is taken as the normal display name.
+};
+
+static const CompileTargetInfo s_compileTargetInfos[] =
+{
+ { SLANG_TARGET_UNKNOWN, "", "unknown"},
+ { SLANG_TARGET_NONE, "", "none"},
+ { SLANG_HLSL, "hlsl,fx", "hlsl"},
+ { SLANG_DXBC, "dxbc", "dxbc"},
+ { SLANG_DXBC_ASM, "dxbc.asm", "dxbc-asm,dxbc-assembly" },
+ { SLANG_DXIL, "dxil", "dxil" },
+ { SLANG_DXIL_ASM, "dxil.asm", "dxil-asm,dxil-assembly" },
+ { SLANG_GLSL, "glsl,vert,frag,geom,tesc,tese,comp", "glsl" },
+ { SLANG_GLSL_VULKAN, "", "glsl-vulkan" },
+ { SLANG_GLSL_VULKAN_ONE_DESC, "", "glsl-vulkan-one-desc" },
+ { SLANG_SPIRV, "spv", "spirv" },
+ { SLANG_SPIRV_ASM, "spv.asm", "spirv-asm,spirv-assembly" },
+ { SLANG_C_SOURCE, "c", "c" },
+ { SLANG_CPP_SOURCE, "cpp,c++,cxx", "cpp,c++,cxx" },
+ { SLANG_EXECUTABLE, "exe", "exe,executable" },
+ { SLANG_SHARED_LIBRARY, "dll,so", "sharedlib,sharedlibrary,dll" },
+ { SLANG_CUDA_SOURCE, "cu", "cuda,cu" },
+ { SLANG_PTX, "ptx", "ptx" },
+ { SLANG_HOST_CALLABLE, "", "host-callable,callable" }
+};
+
} // anonymous
-/* static */UnownedStringSlice TypeTextUtil::asText(slang::TypeReflection::ScalarType scalarType)
+/* static */UnownedStringSlice TypeTextUtil::getScalarTypeName(slang::TypeReflection::ScalarType scalarType)
{
typedef slang::TypeReflection::ScalarType ScalarType;
switch (scalarType)
@@ -58,11 +89,11 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
return UnownedStringSlice();
}
-/* static */slang::TypeReflection::ScalarType TypeTextUtil::asScalarType(const UnownedStringSlice& inText)
+/* static */slang::TypeReflection::ScalarType TypeTextUtil::findScalarType(const UnownedStringSlice& inText)
{
- for (Index i = 0; i < SLANG_COUNT_OF(s_scalarTypeInfo); ++i)
+ for (Index i = 0; i < SLANG_COUNT_OF(s_scalarTypeInfos); ++i)
{
- const auto& info = s_scalarTypeInfo[i];
+ const auto& info = s_scalarTypeInfos[i];
if (info.text == inText)
{
return info.type;
@@ -71,7 +102,7 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
return slang::TypeReflection::ScalarType::None;
}
-/* static */UnownedStringSlice TypeTextUtil::asHumanText(SlangPassThrough type)
+/* static */UnownedStringSlice TypeTextUtil::getPassThroughAsHumanText(SlangPassThrough type)
{
switch (type)
{
@@ -87,7 +118,7 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
}
}
-/* static */SlangSourceLanguage TypeTextUtil::asSourceLanguage(const UnownedStringSlice& text)
+/* static */SlangSourceLanguage TypeTextUtil::findSourceLanguage(const UnownedStringSlice& text)
{
if (text == "c" || text == "C")
{
@@ -116,7 +147,7 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
return SLANG_SOURCE_LANGUAGE_UNKNOWN;
}
-/* static */SlangPassThrough TypeTextUtil::asPassThrough(const UnownedStringSlice& slice)
+/* static */SlangPassThrough TypeTextUtil::findPassThrough(const UnownedStringSlice& slice)
{
#define SLANG_PASS_THROUGH_NAME_TO_TYPE(x, y) \
if (slice == UnownedStringSlice::fromLiteral(#x)) return SLANG_PASS_THROUGH_##y;
@@ -136,9 +167,9 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
return SLANG_PASS_THROUGH_NONE;
}
-/* static */SlangResult TypeTextUtil::asPassThrough(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough)
+/* static */SlangResult TypeTextUtil::findPassThrough(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough)
{
- outPassThrough = asPassThrough(slice);
+ outPassThrough = findPassThrough(slice);
// It could be none on error - if it's not equal to "none" then it must be an error
if (outPassThrough == SLANG_PASS_THROUGH_NONE && slice != UnownedStringSlice::fromLiteral("none"))
{
@@ -147,7 +178,7 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
return SLANG_OK;
}
-/* static */UnownedStringSlice TypeTextUtil::asText(SlangPassThrough passThru)
+/* static */UnownedStringSlice TypeTextUtil::getPassThroughName(SlangPassThrough passThru)
{
#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
case SLANG_PASS_THROUGH_##y: return UnownedStringSlice::fromLiteral(#x);
@@ -160,6 +191,54 @@ static const ScalarTypeInfo s_scalarTypeInfo[] =
return UnownedStringSlice::fromLiteral("unknown");
}
+/* static */SlangCompileTarget TypeTextUtil::findCompileTargetFromExtension(const UnownedStringSlice& slice)
+{
+ if (slice.size())
+ {
+ for (const auto& info : s_compileTargetInfos)
+ {
+ if (StringUtil::indexOfInSplit(UnownedStringSlice(info.extensions), ',', slice) >= 0)
+ {
+ return info.target;
+ }
+ }
+ }
+ return SLANG_TARGET_UNKNOWN;
+}
+
+/* static */ SlangCompileTarget TypeTextUtil::findCompileTargetFromName(const UnownedStringSlice& slice)
+{
+ if (slice.size())
+ {
+ for (const auto& info : s_compileTargetInfos)
+ {
+ if (StringUtil::indexOfInSplit(UnownedStringSlice(info.names), ',', slice) >= 0)
+ {
+ return info.target;
+ }
+ }
+ }
+ return SLANG_TARGET_UNKNOWN;
+}
+
+static Index _getTargetInfoIndex(SlangCompileTarget target)
+{
+ for (Index i = 0; i < SLANG_COUNT_OF(s_compileTargetInfos); ++i)
+ {
+ if (s_compileTargetInfos[i].target == target)
+ {
+ return i;
+ }
+ }
+ return -1;
+}
+
+UnownedStringSlice TypeTextUtil::getCompileTargetName(SlangCompileTarget target)
+{
+ const Index index = _getTargetInfoIndex(target);
+ // Return the first name
+ return index >= 0 ? StringUtil::getAtInSplit(UnownedStringSlice(s_compileTargetInfos[int(target)].names), ',', 0) : UnownedStringSlice();
+}
}
diff --git a/source/core/slang-type-text-util.h b/source/core/slang-type-text-util.h
index 73c1d9ef0..c4f9fb275 100644
--- a/source/core/slang-type-text-util.h
+++ b/source/core/slang-type-text-util.h
@@ -12,25 +12,35 @@ namespace Slang
/// Utility class to allow conversion of types (such as enums) to and from text types
struct TypeTextUtil
{
-
/// Get the scalar type as text.
- static Slang::UnownedStringSlice asText(slang::TypeReflection::ScalarType scalarType);
+ static Slang::UnownedStringSlice getScalarTypeName(slang::TypeReflection::ScalarType scalarType);
// Converts text to scalar type. Returns 'none' if not determined
- static slang::TypeReflection::ScalarType asScalarType(const Slang::UnownedStringSlice& text);
+ static slang::TypeReflection::ScalarType findScalarType(const Slang::UnownedStringSlice& text);
/// As human readable text
- static UnownedStringSlice asHumanText(SlangPassThrough type);
+ static UnownedStringSlice getPassThroughAsHumanText(SlangPassThrough type);
/// Given a source language name returns a source language. Name here is distinct from extension
- static SlangSourceLanguage asSourceLanguage(const UnownedStringSlice& text);
+ static SlangSourceLanguage findSourceLanguage(const UnownedStringSlice& text);
/// Given a name returns the pass through
- static SlangPassThrough asPassThrough(const UnownedStringSlice& slice);
- static SlangResult asPassThrough(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough);
+ static SlangPassThrough findPassThrough(const UnownedStringSlice& slice);
+ static SlangResult findPassThrough(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough);
/// Get the compilers name
- static UnownedStringSlice asText(SlangPassThrough passThru);
+ static UnownedStringSlice getPassThroughName(SlangPassThrough passThru);
+
+ /// Given a file extension determines suitable target
+ /// If doesn't match any target will return SLANG_TARGET_UNKNOWN
+ static SlangCompileTarget findCompileTargetFromExtension(const UnownedStringSlice& slice);
+
+ /// Given a name suitable target
+ /// If doesn't match any target will return SLANG_TARGET_UNKNOWN
+ static SlangCompileTarget findCompileTargetFromName(const UnownedStringSlice& slice);
+
+ /// Given a target returns the associated name.
+ static UnownedStringSlice getCompileTargetName(SlangCompileTarget target);
};
}