summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/compiler.cpp16
-rw-r--r--source/slang/diagnostics.cpp30
-rw-r--r--source/slang/diagnostics.h6
3 files changed, 44 insertions, 8 deletions
diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp
index 7df978707..284bb200a 100644
--- a/source/slang/compiler.cpp
+++ b/source/slang/compiler.cpp
@@ -236,15 +236,14 @@ namespace Slang
// TODO(tfoley): need a better policy for how we translate diagnostics
// back into the Slang world (although we should always try to generate
// HLSL that doesn't produce any diagnostics...)
- String diagnostics = (char const*) diagnosticsBlob->GetBufferPointer();
- fprintf(stderr, "%s", diagnostics.begin());
- OutputDebugStringA(diagnostics.begin());
+ entryPoint->compileRequest->mSink.diagnoseRaw(
+ FAILED(hr) ? Severity::Error : Severity::Warning,
+ (char const*) diagnosticsBlob->GetBufferPointer());
diagnosticsBlob->Release();
}
if (FAILED(hr))
{
- // TODO(tfoley): What to do on failure?
- exit(1);
+ return List<uint8_t>();
}
return data;
}
@@ -376,9 +375,10 @@ namespace Slang
if (err)
{
- OutputDebugStringA(diagnosticOutput.Buffer());
- fprintf(stderr, "%s", diagnosticOutput.Buffer());
- exit(1);
+ entryPoint->compileRequest->mSink.diagnoseRaw(
+ Severity::Error,
+ diagnosticOutput.begin());
+ return err;
}
return 0;
diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp
index 0c55a94bd..870e6d172 100644
--- a/source/slang/diagnostics.cpp
+++ b/source/slang/diagnostics.cpp
@@ -194,6 +194,36 @@ void DiagnosticSink::diagnoseImpl(CodePosition const& pos, DiagnosticInfo const&
}
}
+void DiagnosticSink::diagnoseRaw(
+ Severity severity,
+ char const* message)
+{
+ if (severity >= Severity::Error)
+ {
+ errorCount++;
+ }
+
+ // Did the client supply a callback for us to use?
+ if( callback )
+ {
+ // If so, pass the error string along to them
+ callback(message, callbackUserData);
+ }
+ else
+ {
+ // If the user doesn't have a callback, then just
+ // collect our diagnostic messages into a buffer
+ outputBuffer.append(message);
+ }
+
+ if (severity >= Severity::Fatal)
+ {
+ // TODO: figure out a better policy for aborting compilation
+ throw InvalidOperationException();
+ }
+}
+
+
namespace Diagnostics
{
#define DIAGNOSTIC(id, severity, name, messageFormat) const DiagnosticInfo name = { id, Severity::severity, messageFormat };
diff --git a/source/slang/diagnostics.h b/source/slang/diagnostics.h
index 8834f1a6e..6957fc763 100644
--- a/source/slang/diagnostics.h
+++ b/source/slang/diagnostics.h
@@ -185,6 +185,12 @@ namespace Slang
}
void diagnoseImpl(CodePosition const& pos, DiagnosticInfo const& info, int argCount, DiagnosticArg const* const* args);
+
+ // Add a diagnostic with raw text
+ // (used when we get errors from a downstream compiler)
+ void diagnoseRaw(
+ Severity severity,
+ char const* message);
};
namespace Diagnostics