From 00746bf09047cdf01c19dac513a532bcf3ed3ea3 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 9 Jul 2025 14:41:19 +0800 Subject: Stable names and backwards compat for serialized IR modules (#7644) * stable names * tests, options and ci for stable names * Add back compat design document * fix warnings * formatting * comment * neaten * regenerate command line reference * consolidate ci scripts * faster ci * remove libreadline * Move new function to end of interface --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-options.cpp | 83 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-options.cpp') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index af799839c..fde13463e 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -868,7 +868,15 @@ void initCommandOptions(CommandOptions& options) "-verify-debug-serial-ir", nullptr, "Verify IR in the front-end."}, - {OptionKind::DumpModule, "-dump-module", nullptr, "Disassemble and print the module IR."}}; + {OptionKind::DumpModule, "-dump-module", nullptr, "Disassemble and print the module IR."}, + {OptionKind::GetModuleInfo, + "-get-module-info", + nullptr, + "Print the name and version of a serialized IR Module"}, + {OptionKind::GetSupportedModuleVersions, + "-get-supported-module-versions", + nullptr, + "Print the minimum and maximum module versions this compiler supports"}}; _addOptions(makeConstArrayView(debuggingOpts), options); /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Experimental !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -3146,6 +3154,79 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) } + break; + } + case OptionKind::GetModuleInfo: + { + CommandLineArg fileName; + SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName)); + auto desc = slang::SessionDesc(); + ComPtr session; + m_session->createSession(desc, session.writeRef()); + ComPtr diagnostics; + + FileStream file; + if (SLANG_FAILED(file.init( + fileName.value, + FileMode::Open, + FileAccess::Read, + FileShare::None))) + { + m_sink->diagnose(arg.loc, Diagnostics::cannotOpenFile, fileName.value); + return SLANG_FAIL; + } + + List buffer; + file.seek(SeekOrigin::End, 0); + const Int64 size = file.getPosition(); + buffer.setCount(size + 1); + file.seek(SeekOrigin::Start, 0); + SLANG_RETURN_ON_FAIL(file.readExactly(buffer.getBuffer(), (size_t)size)); + buffer[size] = 0; + file.close(); + + ComPtr module; + // Load buffer as an IR blob + ComPtr blob; + blob = RawBlob::create(buffer.getBuffer(), size); + + const char* moduleName = nullptr; + const char* moduleCompilerVersion = nullptr; + SlangInt moduleVersion = ~0; + SLANG_RETURN_ON_FAIL(session->loadModuleInfoFromIRBlob( + blob, + moduleVersion, + moduleCompilerVersion, + moduleName)); + + char infoBuffer[512]; + snprintf( + infoBuffer, + sizeof(infoBuffer), + "Module Name: %s\n" + "Module Version: %lld\n" + "Compiler Version: %s\n", + moduleName ? moduleName : "null", + static_cast(moduleVersion), + moduleCompilerVersion ? moduleCompilerVersion : "null"); + + m_sink->diagnoseRaw(Severity::Note, infoBuffer); + + break; + } + case OptionKind::GetSupportedModuleVersions: + { + char infoBuffer[512]; + snprintf( + infoBuffer, + sizeof(infoBuffer), + "Minimum supported version: %lu\n" + "Maximum supported version: %lu\n", + (unsigned long)IRModule::k_minSupportedModuleVersion, + (unsigned long)IRModule::k_maxSupportedModuleVersion); + + m_sink->diagnoseRaw(Severity::Note, infoBuffer); + break; } case OptionKind::EmitSeparateDebug: -- cgit v1.2.3