summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/compiler.cpp2
-rw-r--r--source/slang/compiler.h11
-rw-r--r--source/slang/emit.cpp61
-rw-r--r--source/slang/slang.cpp9
4 files changed, 68 insertions, 15 deletions
diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp
index e16b9dec7..81f107bd8 100644
--- a/source/slang/compiler.cpp
+++ b/source/slang/compiler.cpp
@@ -690,7 +690,7 @@ namespace Slang
int id = counter++;
String path;
- path.append("slang-");
+ path.append("slang-dump-");
path.append(id);
path.append(ext);
diff --git a/source/slang/compiler.h b/source/slang/compiler.h
index a7d104b5f..09797664f 100644
--- a/source/slang/compiler.h
+++ b/source/slang/compiler.h
@@ -48,6 +48,14 @@ namespace Slang
ReflectionJSON = SLANG_REFLECTION_JSON,
};
+ enum class LineDirectiveMode : SlangLineDirectiveMode
+ {
+ Default = SLANG_LINE_DIRECTIVE_MODE_DEFAULT,
+ None = SLANG_LINE_DIRECTIVE_MODE_NONE,
+ Standard = SLANG_LINE_DIRECTIVE_MODE_STANDARD,
+ GLSL = SLANG_LINE_DIRECTIVE_MODE_GLSL,
+ };
+
enum class ResultFormat
{
None,
@@ -210,6 +218,9 @@ namespace Slang
// Should we dump intermediate results along the way, for debugging?
bool shouldDumpIntermediates = false;
+ // How should `#line` directives be emitted (if at all)?
+ LineDirectiveMode lineDirectiveMode = LineDirectiveMode::Default;
+
// Output stuff
DiagnosticSink mSink;
String mDiagnosticOutput;
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index ee90510a9..61e473c7d 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -511,16 +511,33 @@ struct EmitVisitor
bool shouldUseGLSLStyleLineDirective = false;
- // TODO: Eventually we should give he user a proper API
- // and command-line mechanism to control what kind of line
- // directives we output (and to turn the feature off
- // completely), but for now we always emit C-style line
- // directives *unless* the final target language is raw
- // GLSL code (all other targets will eventually pass
- // through glslang, which supports C-style line directives).
- if (context->shared->finalTarget == CodeGenTarget::GLSL)
+ auto mode = context->shared->entryPoint->compileRequest->lineDirectiveMode;
+ switch (mode)
{
+ case LineDirectiveMode::None:
+ SLANG_UNEXPECTED("should not trying to emit '#line' directive");
+ return;
+
+ case LineDirectiveMode::Default:
+ default:
+ // To try to make the default behavior reasonable, we will
+ // always use C-style line directives (to give the user
+ // good source locations on error messages from downstream
+ // compilers) *unless* they requested raw GLSL as the
+ // output (in which case we want to maximize compatibility
+ // with downstream tools).
+ if (context->shared->finalTarget == CodeGenTarget::GLSL)
+ {
+ shouldUseGLSLStyleLineDirective = true;
+ }
+ break;
+
+ case LineDirectiveMode::Standard:
+ break;
+
+ case LineDirectiveMode::GLSL:
shouldUseGLSLStyleLineDirective = true;
+ break;
}
if(shouldUseGLSLStyleLineDirective)
@@ -597,6 +614,12 @@ struct EmitVisitor
void emitLineDirectiveIfNeeded(
CodePosition const& sourceLocation)
{
+ // Don't do any of this work if the user has requested that we
+ // not emit line directives.
+ auto mode = context->shared->entryPoint->compileRequest->lineDirectiveMode;
+ if (mode == LineDirectiveMode::None)
+ return;
+
// Ignore invalid source locations
if(sourceLocation.Line <= 0)
return;
@@ -675,13 +698,16 @@ struct EmitVisitor
void emitTokenWithLocation(Token const& token)
{
- if( token.Position.FileName.Length() != 0 )
- {
- advanceToSourceLocation(token.Position);
- }
- else
+ auto mode = context->shared->entryPoint->compileRequest->lineDirectiveMode;
+ if (mode == LineDirectiveMode::None)
+ return;
+
+
+ if ((mode == LineDirectiveMode::None)
+ || token.Position.FileName.Length() == 0)
{
- // If we don't have the original position info, we need to play
+ // If we don't have the original position info, or we are in the
+ // mode where the user didn't want line directives, we need to play
// it safe and emit whitespace to line things up nicely
if(token.flags & TokenFlag::AtStartOfLine)
@@ -691,6 +717,13 @@ struct EmitVisitor
else // if(token.flags & TokenFlag::AfterWhitespace)
Emit(" ");
}
+ else
+ {
+ // If location information is available, and we are emitting
+ // such information, then just advance our tracking location
+ // to the right place.
+ advanceToSourceLocation(token.Position);
+ }
// Emit the raw textual content of the token
emit(token.Content);
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index caa50ad0e..65f12fe59 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -675,6 +675,15 @@ SLANG_API void spSetDumpIntermediates(
REQ(request)->shouldDumpIntermediates = enable != 0;
}
+SLANG_API void spSetLineDirectiveMode(
+ SlangCompileRequest* request,
+ SlangLineDirectiveMode mode)
+{
+ // TODO: validation
+
+ REQ(request)->lineDirectiveMode = Slang::LineDirectiveMode(mode);
+}
+
SLANG_API void spSetCodeGenTarget(
SlangCompileRequest* request,