summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Stepinski <rob.stepinski@gmail.com>2019-11-22 18:20:18 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-11-22 15:20:18 -0800
commit63dcbe50d40afc15196eeca6ba0b04657adf6953 (patch)
tree05f63d4f83cdd34a5788f0c6d449a94fb3104d0b
parent1d51b01cc7a6ab5fa26e0eb109ca29ed0f24ebe1 (diff)
Add command line option to override language file extension (#1135)
-rw-r--r--source/slang/slang-compiler.cpp26
-rw-r--r--source/slang/slang-diagnostic-defs.h1
-rw-r--r--source/slang/slang-options.cpp29
-rw-r--r--source/slang/slang-profile.h2
4 files changed, 54 insertions, 4 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index a5c078dc4..64be1505e 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -460,6 +460,32 @@ namespace Slang
}
}
+ static const struct
+ {
+ char const* name;
+ SourceLanguage sourceLanguage;
+ } kSourceLanguages[] =
+ {
+ { "slang", SourceLanguage::Slang },
+ { "hlsl", SourceLanguage::HLSL },
+ { "glsl", SourceLanguage::GLSL },
+ { "c", SourceLanguage::C },
+ { "cxx", SourceLanguage::CPP },
+ };
+
+ SourceLanguage findSourceLanguageByName(String const& name)
+ {
+ for (auto entry : kSourceLanguages)
+ {
+ if (name == entry.name)
+ {
+ return entry.sourceLanguage;
+ }
+ }
+
+ return SourceLanguage::Unknown;
+ };
+
SlangResult checkExternalCompilerSupport(Session* session, PassThroughMode passThrough)
{
switch (passThrough)
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 4e48cc95b..d43b2ca82 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -70,6 +70,7 @@ DIAGNOSTIC( 15, Error, unknownStage, "unknown stage '$0'");
DIAGNOSTIC( 16, Error, unknownPassThroughTarget, "unknown pass-through target '$0'");
DIAGNOSTIC( 17, Error, unknownCommandLineOption, "unknown command-line option '$0'");
DIAGNOSTIC( 18, Error, unknownFileSystemOption, "unknown file-system option '$0'");
+DIAGNOSTIC( 19, Error, unknownSourceLanguage, "unknown source language '$0'");
DIAGNOSTIC( 20, Error, entryPointsNeedToBeAssociatedWithTranslationUnits, "when using multiple source files, entry points must be specified after their corresponding source file(s)");
DIAGNOSTIC( 21, Error, expectedArgumentForOption, "expected an argument for command-line option '$0'");
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 97dca94ca..92310c1c1 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -324,7 +324,8 @@ struct OptionsParser
}
SlangResult addInputPath(
- char const* inPath)
+ char const* inPath,
+ SourceLanguage langOverride = SourceLanguage::Unknown)
{
inputPathCount++;
@@ -332,7 +333,7 @@ struct OptionsParser
// how we should handle it.
String path = String(inPath);
- if( path.endsWith(".slang") )
+ if( path.endsWith(".slang") || langOverride == SourceLanguage::Slang)
{
// Plain old slang code
addInputSlangPath(path);
@@ -340,8 +341,8 @@ struct OptionsParser
}
Stage impliedStage = Stage::Unknown;
- SlangSourceLanguage sourceLanguage = findSourceLanguageFromPath(path, impliedStage);
-
+ SlangSourceLanguage sourceLanguage = langOverride == SourceLanguage::Unknown ? findSourceLanguageFromPath(path, impliedStage) : SlangSourceLanguage(langOverride);
+
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
requestImpl->getSink()->diagnose(SourceLoc(), Diagnostics::cannotDeduceSourceLanguage, inPath);
@@ -707,6 +708,26 @@ struct OptionsParser
rawEntryPoints.add(rawEntryPoint);
}
+ else if (argStr == "-lang")
+ {
+ String name;
+ SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
+
+ SourceLanguage sourceLanguage = findSourceLanguageByName(name);
+
+ if (sourceLanguage == SourceLanguage::Unknown)
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::unknownSourceLanguage, name);
+ return SLANG_FAIL;
+ }
+ else
+ {
+ while ((*argCursor)[0] != '-' && argCursor != argEnd)
+ {
+ SLANG_RETURN_ON_FAIL(addInputPath(*argCursor++, sourceLanguage));
+ }
+ }
+ }
else if (argStr == "-pass-through")
{
String name;
diff --git a/source/slang/slang-profile.h b/source/slang/slang-profile.h
index 9c6ff1182..7c801cc7e 100644
--- a/source/slang/slang-profile.h
+++ b/source/slang/slang-profile.h
@@ -105,6 +105,8 @@ namespace Slang
Stage findStageByName(String const& name);
UnownedStringSlice getStageText(Stage stage);
+
+ SourceLanguage findSourceLanguageByName(String const& name);
}
#endif