summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-cpp.cpp
diff options
context:
space:
mode:
authorDietrich Geisler <dag368@cornell.edu>2020-12-18 10:10:10 -0700
committerGitHub <noreply@github.com>2020-12-18 09:10:10 -0800
commitf5fffa90e936ab462b3842f9b2cfa996ae870fe4 (patch)
tree4c199062c18975d6de680c1b69fba9e149ca27e7 /source/slang/slang-emit-cpp.cpp
parent0fa3bcffc7065927b18d1da2de722d1cb1b53ebf (diff)
Heterogeneous Flag Error Visibility (#1642)
* PR to fix issue #1638. This change introduces a diagnostic sink to the emitModule function, and updates all associated calls to that function. Additionally, this commit updates the heterogeneous hello world example to not need the entry and stage flags for simplicity. * Updated emit-cpp per suggested changes Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-emit-cpp.cpp')
-rw-r--r--source/slang/slang-emit-cpp.cpp57
1 files changed, 36 insertions, 21 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index e02ca3007..2a4b14954 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -2553,7 +2553,7 @@ void CPPSourceEmitter::_emitForwardDeclarations(const List<EmitAction>& actions)
}
}
-void CPPSourceEmitter::emitModuleImpl(IRModule* module)
+void CPPSourceEmitter::emitModuleImpl(IRModule* module, DiagnosticSink* sink)
{
// If we are emitting a heterogeneous program
// Emit the binary blob of each non-CPP target
@@ -2589,34 +2589,49 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module)
default:
auto targetProgram = program->getTargetProgram(targetRequest);
- DiagnosticSink sink(linkage->getSourceManager());
CompileResult result =
- targetProgram->getOrCreateEntryPointResult(index, &sink);
+ targetProgram->getOrCreateEntryPointResult(index, sink);
Slang::ComPtr<ISlangBlob> blob;
if (SLANG_FAILED(result.getBlob(blob)))
{
- SLANG_UNEXPECTED("No blob to emit");
- return;
+ sink->diagnoseRaw(Severity::Error,
+ "Slang heterogeneous error: No blob to emit\n");
+ m_writer->emit("size_t __");
+ m_writer->emit(entryPointName);
+ m_writer->emit("Size = 0;\n");
+ m_writer->emit("unsigned char __");
+ m_writer->emit(entryPointName);
+ m_writer->emit("[1];\n");
}
- auto ptr = (const unsigned char*)blob->getBufferPointer();
-
- m_writer->emit("size_t __");
- m_writer->emit(entryPointName );
- m_writer->emit("Size = ");
- m_writer->emitInt64(blob->getBufferSize());
- m_writer->emit(";\n");
-
- m_writer->emit("unsigned char __");
- m_writer->emit(entryPointName );
- m_writer->emit("[] = {");
- for (unsigned int i = 0; i < blob->getBufferSize() - 1; i++) {
- m_writer->emitUInt64(ptr[i]);
- m_writer->emit(", ");
+ else
+ {
+ auto ptr = (const unsigned char*)blob->getBufferPointer();
+
+ m_writer->emit("size_t __");
+ m_writer->emit(entryPointName);
+ m_writer->emit("Size = ");
+ m_writer->emitInt64(blob->getBufferSize());
+ m_writer->emit(";\n");
+
+ m_writer->emit("unsigned char __");
+ m_writer->emit(entryPointName);
+ m_writer->emit("[] = {");
+ // every 20 bytes, emit a newline
+ size_t j = 0;
+ for (size_t i = 0; i < blob->getBufferSize(); i++) {
+ m_writer->emitUInt64(ptr[i]);
+ m_writer->emit(", ");
+ if (j == 20)
+ {
+ m_writer->emit("\n");
+ j = 0;
+ }
+ j++;
+ }
+ m_writer->emit("};\n");
}
- m_writer->emitUInt64(ptr[blob->getBufferSize() - 1]);
- m_writer->emit("};\n");
}
}
// Emit a wrapper function for calling the shader blob