diff --git a/include/slang.h b/include/slang.h index d0917b14fd..10f4e74742 100644 --- a/include/slang.h +++ b/include/slang.h @@ -4421,8 +4421,8 @@ struct IModule : public IComponentType /** Disassemble a module. */ - virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassemble( - slang::IBlob** outDisassembledBlob) = 0; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL + disassemble(slang::IBlob** outDisassembledBlob) = 0; }; #define SLANG_UUID_IModule IModule::getTypeGuid() diff --git a/source/slang-record-replay/record/slang-module.cpp b/source/slang-record-replay/record/slang-module.cpp index f17a62360f..628a29c90e 100644 --- a/source/slang-record-replay/record/slang-module.cpp +++ b/source/slang-record-replay/record/slang-module.cpp @@ -249,7 +249,7 @@ SlangResult ModuleRecorder::disassemble(ISlangBlob** outBlob) { // No need to record this call as it is just a query. slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); - auto res = m_actualModule->disassemble(outBlob); + auto res = m_actualModule->disassemble(outBlob); return res; } } // namespace SlangRecord diff --git a/source/slang-record-replay/record/slang-module.h b/source/slang-record-replay/record/slang-module.h index aceb8941b2..d9c83576db 100644 --- a/source/slang-record-replay/record/slang-module.h +++ b/source/slang-record-replay/record/slang-module.h @@ -56,7 +56,8 @@ class ModuleRecorder : public IModuleRecorder, public IComponentTypeRecorder ISlangBlob** outDiagnostics) override; virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDependencyFileCount() override; virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath(SlangInt32 index) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassemble(slang::IBlob** outDisassembly) override; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL + disassemble(slang::IBlob** outDisassembly) override; // Interfaces for `IComponentType` virtual SLANG_NO_THROW slang::ISession* SLANG_MCALL getSession() override diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 316b210095..d4e05bc48e 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1833,18 +1833,17 @@ class Module : public ComponentType, public slang::IModule // Source files that have been pulled into the module with `__include`. Dictionary m_mapSourceFileToFileDecl; - public: - SLANG_NO_THROW SlangResult SLANG_MCALL disassemble( - slang::IBlob** outDisassembledBlob) override - { - if (!outDisassembledBlob) - return SLANG_E_INVALID_ARG; - String disassembly; - this->getIRModule()->getModuleInst()->dump(disassembly); - auto blob = StringUtil::createStringBlob(disassembly); - *outDisassembledBlob = blob.detach(); - return SLANG_OK; - } +public: + SLANG_NO_THROW SlangResult SLANG_MCALL disassemble(slang::IBlob** outDisassembledBlob) override + { + if (!outDisassembledBlob) + return SLANG_E_INVALID_ARG; + String disassembly; + this->getIRModule()->getModuleInst()->dump(disassembly); + auto blob = StringUtil::createStringBlob(disassembly); + *outDisassembledBlob = blob.detach(); + return SLANG_OK; + } }; typedef Module LoadedModule; diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index d82340b947..6d1d76afce 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -8950,9 +8950,9 @@ void IRInst::addBlock(IRBlock* block) block->insertAtEnd(this); } -void IRInst::dump(String &outStr) -{ - StringBuilder sb; +void IRInst::dump(String& outStr) +{ + StringBuilder sb; if (auto intLit = as(this)) { @@ -8960,10 +8960,10 @@ void IRInst::dump(String &outStr) } else if (auto stringLit = as(this)) { - sb << stringLit->getStringSlice(); + sb << stringLit->getStringSlice(); } else - { + { IRDumpOptions options; StringWriter writer(&sb, Slang::WriterFlag::AutoFlush); dumpIR(this, options, nullptr, &writer); diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index 32dca99a34..64125be9a2 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -819,7 +819,7 @@ struct IRInst /// Print the IR to a string for debugging purposes. /// - void dump(String &outStr); + void dump(String& outStr); /// Insert a basic block at the end of this func/code containing inst. void addBlock(IRBlock* block); diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 504f558dfe..2d42e994d8 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -2953,40 +2953,44 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) case OptionKind::DumpModule: { CommandLineArg fileName; - SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName)); + SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName)); auto desc = slang::SessionDesc(); ComPtr session; m_session->createSession(desc, session.writeRef()); ComPtr diagnostics; // Coerce Slang to load from the given file, without letting it automatically - // choose .slang-module files over .slang files. + // choose .slang-module files over .slang files. // First try to load as source string, and fall back to loading as an IR Blob. // Avoid guessing based on filename or inspect the file contents. FILE* file = fopen(fileName.value.getBuffer(), "rb"); fseek(file, 0, SEEK_END); size_t size = ftell(file); fseek(file, 0, SEEK_SET); - std::vector buffer(size+1); + std::vector buffer(size + 1); fread(buffer.data(), 1, size, file); buffer[size] = 0; fclose(file); - + ComPtr module; - module = session->loadModuleFromSourceString("module", "path", buffer.data(), diagnostics.writeRef()); + module = session->loadModuleFromSourceString( + "module", + "path", + buffer.data(), + diagnostics.writeRef()); if (!module) { // Load buffer as an IR blob ComPtr blob; blob = RawBlob::create(buffer.data(), size); - + module = session->loadModuleFromIRBlob( "module", "path", blob, diagnostics.writeRef()); } - + if (module) { ComPtr disassemblyBlob; @@ -2997,7 +3001,9 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) } else { - m_sink->diagnoseRaw(Severity::Note, (const char*)disassemblyBlob->getBufferPointer()); + m_sink->diagnoseRaw( + Severity::Note, + (const char*)disassemblyBlob->getBufferPointer()); } } else @@ -3007,11 +3013,11 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) m_sink->diagnoseRaw( Severity::Error, (const char*)diagnostics->getBufferPointer()); - } + } return SLANG_FAIL; } - - + + break; } default: