summaryrefslogtreecommitdiff
path: root/source/slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-18 19:13:02 -0500
committerGitHub <noreply@github.com>2020-02-18 19:13:02 -0500
commit45d1a680634c59d1081ed09dddaa444695296492 (patch)
treeaf803579f32d1592a297d70e41f848184dea93ea /source/slang
parent8ee39e08c48a315163fe1850dbb12ca292020d4d (diff)
Added support for Targets to TypeTextUtil. (#1226)
* Added support for Targets to TypeTextUtil. * Made Function names 'get' and 'find' instead of 'as' in TypeTextUtil.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-check.cpp2
-rw-r--r--source/slang/slang-compiler.cpp59
-rw-r--r--source/slang/slang-compiler.h3
-rw-r--r--source/slang/slang-emit.cpp4
-rw-r--r--source/slang/slang-options.cpp52
-rw-r--r--source/slang/slang-state-serialize.cpp4
6 files changed, 17 insertions, 107 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 77e3ffc9f..990f9a0f5 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -182,7 +182,7 @@ namespace Slang
SlangFuncPtr func = sharedLibrary->findFuncByName(info.name);
if (!func)
{
- UnownedStringSlice compilerName = TypeTextUtil::asText(SlangPassThrough(info.compilerType));
+ UnownedStringSlice compilerName = TypeTextUtil::getPassThroughName(SlangPassThrough(info.compilerType));
sink->diagnose(SourceLoc(), Diagnostics::failedToFindFunctionForCompiler, info.name, compilerName);
return nullptr;
}
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 65c48d2f2..94cf7f73c 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -75,65 +75,6 @@
namespace Slang
{
-
-// NOTE! These must be in the same order as the SlangCompileTarget enum
-#define SLANG_CODE_GEN_TARGETS(x) \
- x("unknown", Unknown) \
- x("none", None) \
- x("glsl", GLSL) \
- x("glsl-vulkan", GLSL_Vulkan) \
- x("glsl-vulkan-one-desc", GLSL_Vulkan_OneDesc) \
- x("hlsl", HLSL) \
- x("spirv", SPIRV) \
- x("spirv-asm,spirv-assembly", SPIRVAssembly) \
- x("dxbc", DXBytecode) \
- x("dxbc-asm,dxbc-assembly", DXBytecodeAssembly) \
- x("dxil", DXIL) \
- x("dxil-asm,dxil-assembly", DXILAssembly) \
- x("c", CSource) \
- x("cpp", CPPSource) \
- x("exe,executable", Executable) \
- x("sharedlib,sharedlibrary,dll", SharedLibrary) \
- x("callable,host-callable", HostCallable) \
- x("cu,cuda", CUDASource) \
- x("ptx", PTX)
-
-#define SLANG_CODE_GEN_INFO(names, e) \
- { CodeGenTarget::e, UnownedStringSlice::fromLiteral(names) },
-
- struct CodeGenTargetInfo
- {
- CodeGenTarget target;
- UnownedStringSlice names;
- };
-
- static const CodeGenTargetInfo s_codeGenTargetInfos[] =
- {
- SLANG_CODE_GEN_TARGETS(SLANG_CODE_GEN_INFO)
- };
-
- CodeGenTarget calcCodeGenTargetFromName(const UnownedStringSlice& name)
- {
- for (int i = 0; i < SLANG_COUNT_OF(s_codeGenTargetInfos); ++i)
- {
- const auto& info = s_codeGenTargetInfos[i];
-
- // If this assert fails, then the SLANG_CODE_GEN_TARGETS macro has the wrong order
- SLANG_ASSERT(i == int(info.target));
-
- if (StringUtil::indexOfInSplit(info.names, ',', name) >= 0)
- {
- return info.target;
- }
- }
- return CodeGenTarget::Unknown;
- }
- UnownedStringSlice getCodeGenTargetName(CodeGenTarget target)
- {
- // Return the first name
- return StringUtil::getAtInSplit(s_codeGenTargetInfos[int(target)].names, ',', 0);
- }
-
SlangResult CompileResult::getSharedLibrary(ComPtr<ISlangSharedLibrary>& outSharedLibrary)
{
if (downstreamResult)
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 151e89b34..e337c2fff 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -72,9 +72,6 @@ namespace Slang
CountOf = SLANG_TARGET_COUNT_OF,
};
- CodeGenTarget calcCodeGenTargetFromName(const UnownedStringSlice& name);
- UnownedStringSlice getCodeGenTargetName(CodeGenTarget target);
-
enum class ContainerFormat : SlangContainerFormat
{
None = SLANG_CONTAINER_FORMAT_NONE,
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 6e3ce9c56..d5dc9cbe7 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -2,6 +2,8 @@
#include "slang-emit.h"
#include "../core/slang-writer.h"
+#include "../core/slang-type-text-util.h"
+
#include "slang-ir-bind-existentials.h"
#include "slang-ir-dce.h"
#include "slang-ir-entry-point-uniforms.h"
@@ -525,7 +527,7 @@ String emitEntryPointSourceFromIR(
if (!sourceEmitter)
{
- sink->diagnose(SourceLoc(), Diagnostics::unableToGenerateCodeForTarget, getCodeGenTargetName(target));
+ sink->diagnose(SourceLoc(), Diagnostics::unableToGenerateCodeForTarget, TypeTextUtil::getCompileTargetName(SlangCompileTarget(target)));
return String();
}
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 456c43fa6..c97439b29 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -341,50 +341,20 @@ struct OptionsParser
void addOutputPath(char const* inPath)
{
String path = String(inPath);
+ String ext = Path::getFileExt(path);
- if (!inPath) {}
-#define CASE(EXT, TARGET) \
- else if(path.endsWith(EXT)) do { addOutputPath(path, CodeGenTarget(SLANG_##TARGET)); } while(0)
-
- CASE(".hlsl", HLSL);
- CASE(".fx", HLSL);
-
- CASE(".dxbc", DXBC);
- CASE(".dxbc.asm", DXBC_ASM);
-
- CASE(".dxil", DXIL);
- CASE(".dxil.asm", DXIL_ASM);
-
- CASE(".glsl", GLSL);
- CASE(".vert", GLSL);
- CASE(".frag", GLSL);
- CASE(".geom", GLSL);
- CASE(".tesc", GLSL);
- CASE(".tese", GLSL);
- CASE(".comp", GLSL);
-
- CASE(".spv", SPIRV);
- CASE(".spv.asm", SPIRV_ASM);
-
- CASE(".c", C_SOURCE);
- CASE(".cpp", CPP_SOURCE);
-
- CASE(".exe", EXECUTABLE);
- CASE(".dll", SHARED_LIBRARY);
- CASE(".so", SHARED_LIBRARY);
-
-#undef CASE
-
- else if (path.endsWith(".slang-module") || path.endsWith(".slang-lib"))
+ if (ext == "slang-module" || ext == "slang-lib")
{
spSetOutputContainerFormat(compileRequest, SLANG_CONTAINER_FORMAT_SLANG_MODULE);
requestImpl->m_containerOutputPath = path;
}
else
{
- // Allow an unknown-format `-o`, assuming we get a target format
+ const SlangCompileTarget target = TypeTextUtil::findCompileTargetFromExtension(ext.getUnownedSlice());
+ // If the target is not found the value returned is Unknown. This is okay because
+ // we allow an unknown-format `-o`, assuming we get a target format
// from another argument.
- addOutputPath(path, CodeGenTarget::Unknown);
+ addOutputPath(path, CodeGenTarget(target));
}
}
@@ -615,7 +585,7 @@ struct OptionsParser
String name;
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
- const CodeGenTarget format = calcCodeGenTargetFromName(name.getUnownedSlice());
+ const CodeGenTarget format = (CodeGenTarget)TypeTextUtil::findCompileTargetFromName(name.getUnownedSlice());
if (format == CodeGenTarget::Unknown)
{
@@ -710,7 +680,7 @@ struct OptionsParser
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_FAILED(TypeTextUtil::asPassThrough(name.getUnownedSlice(), passThrough)))
+ if (SLANG_FAILED(TypeTextUtil::findPassThrough(name.getUnownedSlice(), passThrough)))
{
sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, name);
return SLANG_FAIL;
@@ -945,7 +915,7 @@ struct OptionsParser
String compilerText;
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, compilerText));
- SlangSourceLanguage sourceLanguage = TypeTextUtil::asSourceLanguage(sourceLanguageText.getUnownedSlice());
+ SlangSourceLanguage sourceLanguage = TypeTextUtil::findSourceLanguage(sourceLanguageText.getUnownedSlice());
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
sink->diagnose(SourceLoc(), Diagnostics::unknownSourceLanguage, sourceLanguageText);
@@ -953,7 +923,7 @@ struct OptionsParser
}
SlangPassThrough compiler;
- if (SLANG_FAILED(TypeTextUtil::asPassThrough(compilerText.getUnownedSlice(), compiler)))
+ if (SLANG_FAILED(TypeTextUtil::findPassThrough(compilerText.getUnownedSlice(), compiler)))
{
sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, compilerText);
return SLANG_FAIL;
@@ -987,7 +957,7 @@ struct OptionsParser
String slice = argStr.subString(1, index - 1);
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_SUCCEEDED(TypeTextUtil::asPassThrough(slice.getUnownedSlice(), passThrough)))
+ if (SLANG_SUCCEEDED(TypeTextUtil::findPassThrough(slice.getUnownedSlice(), passThrough)))
{
session->setDownstreamCompilerPath(passThrough, name.getBuffer());
continue;
diff --git a/source/slang/slang-state-serialize.cpp b/source/slang/slang-state-serialize.cpp
index 7b689e762..e98c309f8 100644
--- a/source/slang/slang-state-serialize.cpp
+++ b/source/slang/slang-state-serialize.cpp
@@ -1229,7 +1229,7 @@ static SlangResult _calcCommandLine(OffsetBase& base, StateSerializeUtil::Reques
default:
{
cmd.addArg("-pass-through");
- cmd.addArg(TypeTextUtil::asText(SlangPassThrough(requestState->passThroughMode)));
+ cmd.addArg(TypeTextUtil::getPassThroughName(SlangPassThrough(requestState->passThroughMode)));
break;
}
}
@@ -1253,7 +1253,7 @@ static SlangResult _calcCommandLine(OffsetBase& base, StateSerializeUtil::Reques
TargetRequestState& src = base.asRaw(requestState->targetRequests[i]);
cmd.addArg("-target");
- cmd.addArg(getCodeGenTargetName(CodeGenTarget(src.target)));
+ cmd.addArg(TypeTextUtil::getCompileTargetName(SlangCompileTarget(src.target)));
cmd.addArg("-profile");
cmd.addArg(Profile(src.profile).getName());