diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-23 16:39:46 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-23 16:39:46 -0800 |
| commit | 401d8cdb12ae69aeb216c80c9bb90240d8359649 (patch) | |
| tree | 4548c9de52bdeff424a0a3969ad407fccb3c0f09 /source/slang/slang-options.cpp | |
| parent | 58eb6f7da01af1767282ee12b0b4b25c57e52afb (diff) | |
Add slangc interface to compile and use ir modules. (#3615)
* Add slangc interface to compile and use ir modules.
* Fix glsl scalar layout settings not copied to target.
* Fix.
* Cleanups.
Diffstat (limited to 'source/slang/slang-options.cpp')
| -rw-r--r-- | source/slang/slang-options.cpp | 106 |
1 files changed, 45 insertions, 61 deletions
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 8e94b73cc..39578a1ea 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -557,7 +557,7 @@ void initCommandOptions(CommandOptions& options) SLANG_ASSERT(options.hasContiguousUserValueRange(CommandOptions::LookupKind::Category, UserValue(0), UserValue(ValueCategory::CountOf))); } -SlangResult _addLibraryReference(EndToEndCompileRequest* req, IArtifact* artifact); +SlangResult _addLibraryReference(EndToEndCompileRequest* req, String path, IArtifact* artifact, bool includeEntryPoint); class ReproPathVisitor : public Slang::Path::Visitor { @@ -650,7 +650,6 @@ struct OptionsParser struct RawTarget { CodeGenTarget format = CodeGenTarget::Unknown; - SlangTargetFlags targetFlags = kDefaultTargetFlags; int targetID = -1; CompilerOptionSet optionSet; @@ -736,6 +735,7 @@ struct OptionsParser void _appendMinimalUsage(StringBuilder& out); void _outputMinimalUsage(); + SlangResult addReferencedModule(String path, SourceLoc loc, bool includeEntryPoint); SlangResult _parseReferenceModule(const CommandLineArg& arg); SlangResult _parseReproFileSystem(const CommandLineArg& arg); SlangResult _parseLoadRepro(const CommandLineArg& arg); @@ -772,9 +772,6 @@ struct OptionsParser // If not, it will be `-1`. int m_slangTranslationUnitIndex = -1; - // The number of input files that have been specified - int m_inputPathCount = 0; - int m_translationUnitCount = 0; int m_currentTranslationUnitIndex = -1; @@ -931,13 +928,15 @@ SlangSourceLanguage findSourceLanguageFromPath(const String& path, Stage& outImp SlangResult OptionsParser::addInputPath(char const* inPath, SourceLanguage langOverride ) { - m_inputPathCount++; - // look at the extension on the file name to determine // how we should handle it. String path = String(inPath); - if (path.endsWith(".slang") || langOverride == SourceLanguage::Slang) + if (path.endsWith(".slang-module") || path.endsWith(".slang-lib")) + { + return addReferencedModule(path, SourceLoc(), false); + } + else if (path.endsWith(".slang") || langOverride == SourceLanguage::Slang) { // Plain old slang code addInputSlangPath(path); @@ -1298,20 +1297,13 @@ SlangResult OptionsParser::_expectInt(const CommandLineArg& initArg, Int& outInt return SLANG_OK; } -SlangResult OptionsParser::_parseReferenceModule(const CommandLineArg& arg) +SlangResult OptionsParser::addReferencedModule(String path, SourceLoc loc, bool includeEntryPoint) { - SLANG_UNUSED(arg); - - CommandLineArg referenceModuleName; - SLANG_RETURN_ON_FAIL(m_reader.expectArg(referenceModuleName)); - - const auto path = referenceModuleName.value; - auto desc = ArtifactDescUtil::getDescFromPath(path.getUnownedSlice()); if (desc.kind == ArtifactKind::Unknown) { - m_sink->diagnose(referenceModuleName.loc, Diagnostics::unknownLibraryKind, Path::getPathExt(path)); + m_sink->diagnose(loc, Diagnostics::unknownLibraryKind, Path::getPathExt(path)); return SLANG_FAIL; } @@ -1329,7 +1321,7 @@ SlangResult OptionsParser::_parseReferenceModule(const CommandLineArg& arg) if (!ArtifactDescUtil::isLinkable(desc)) { - m_sink->diagnose(referenceModuleName.loc, Diagnostics::kindNotLinkable, Path::getPathExt(path)); + m_sink->diagnose(loc, Diagnostics::kindNotLinkable, Path::getPathExt(path)); return SLANG_FAIL; } @@ -1354,16 +1346,36 @@ SlangResult OptionsParser::_parseReferenceModule(const CommandLineArg& arg) fileRep = new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice(), nullptr); if (!fileRep->exists()) { - m_sink->diagnose(referenceModuleName.loc, Diagnostics::libraryDoesNotExist, path); + m_sink->diagnose(loc, Diagnostics::libraryDoesNotExist, path); return SLANG_FAIL; } } artifact->addRepresentation(fileRep); - SLANG_RETURN_ON_FAIL(_addLibraryReference(m_requestImpl, artifact)); + SLANG_RETURN_ON_FAIL(_addLibraryReference(m_requestImpl, path, artifact, includeEntryPoint)); + for (Index i = m_rawTranslationUnits.getCount(); i < m_requestImpl->getTranslationUnitCount(); i++) + { + RawTranslationUnit rawTU; + rawTU.translationUnitID = (int)i; + rawTU.impliedStage = Stage::Unknown; + rawTU.sourceLanguage = SLANG_SOURCE_LANGUAGE_SLANG; + m_rawTranslationUnits.add(rawTU); + } + m_currentTranslationUnitIndex = m_requestImpl->getTranslationUnitCount() - 1; + m_slangTranslationUnitIndex = m_currentTranslationUnitIndex; return SLANG_OK; } +SlangResult OptionsParser::_parseReferenceModule(const CommandLineArg& arg) +{ + SLANG_UNUSED(arg); + + CommandLineArg referenceModuleName; + SLANG_RETURN_ON_FAIL(m_reader.expectArg(referenceModuleName)); + + return addReferencedModule(referenceModuleName.value, referenceModuleName.loc, true); +} + SlangResult OptionsParser::_parseReproFileSystem(const CommandLineArg& arg) { SLANG_UNUSED(arg); @@ -2171,13 +2183,9 @@ SlangResult OptionsParser::_parse( return SLANG_FAIL; } case OptionKind::EmitSpirvViaGLSL: - { - getCurrentTarget()->targetFlags &= ~SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; - } - break; case OptionKind::EmitSpirvDirectly: { - getCurrentTarget()->targetFlags |= SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; + getCurrentTarget()->optionSet.add(optionKind, true); } break; case OptionKind::SPIRVCoreGrammarJSON: @@ -2367,7 +2375,8 @@ SlangResult OptionsParser::_parse( entryPoint.translationUnitIndex = 0; } } - else + else if (m_frontEndReq->additionalLoadedModules && + m_frontEndReq->additionalLoadedModules->getCount() == 0) { // Otherwise, we require that all entry points be specified after // the translation unit to which tye belong. @@ -2610,21 +2619,7 @@ SlangResult OptionsParser::_parse( if (m_rawTargets.getCount() == 1) { - if (m_defaultTarget.optionSet.getProfileVersion() != ProfileVersion::Unknown) - { - setProfileVersion(getCurrentTarget(), m_defaultTarget.optionSet.getProfileVersion()); - } - for (auto atom : m_defaultTarget.optionSet.getArray(CompilerOptionName::Capability)) - { - addCapabilityAtom(getCurrentTarget(), (CapabilityName)atom.intValue); - } - - getCurrentTarget()->targetFlags |= m_defaultTarget.targetFlags; - - if (defaultTargetFloatingPointMode != FloatingPointMode::Default) - { - setFloatingPointMode(getCurrentTarget(), defaultTargetFloatingPointMode); - } + m_rawTargets[0].optionSet.overrideWith(m_defaultTarget.optionSet); } else { @@ -2648,18 +2643,6 @@ SlangResult OptionsParser::_parse( } } - if (m_defaultTarget.targetFlags != kDefaultTargetFlags) - { - if (m_rawTargets.getCount() == 0) - { - m_sink->diagnose(SourceLoc(), Diagnostics::targetFlagsIgnoredBecauseNoTargets); - } - else - { - m_sink->diagnose(SourceLoc(), Diagnostics::targetFlagsIgnoredBecauseBeforeAllTargets); - } - } - if (defaultTargetFloatingPointMode != FloatingPointMode::Default) { if (m_rawTargets.getCount() == 0) @@ -2705,11 +2688,6 @@ SlangResult OptionsParser::_parse( m_requestImpl->addTargetCapability(targetID, SlangCapabilityID(atom.intValue)); } - if (rawTarget.targetFlags) - { - m_compileRequest->setTargetFlags(targetID, rawTarget.targetFlags); - } - auto floatingPointMode = rawTarget.optionSet.getEnumOption<FloatingPointMode>(CompilerOptionName::FloatingPointMode); if (floatingPointMode != FloatingPointMode::Default) { @@ -2826,7 +2804,7 @@ SlangResult OptionsParser::_parse( break; case CodeGenTarget::SPIRV: case CodeGenTarget::SPIRVAssembly: - if (getCurrentTarget()->targetFlags & SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY) + if (getCurrentTarget()->optionSet.shouldEmitSPIRVDirectly()) { rawOutput.isWholeProgram = true; } @@ -2857,7 +2835,7 @@ SlangResult OptionsParser::_parse( targetInfo = new EndToEndCompileRequest::TargetInfo(); m_requestImpl->m_targetInfos[target] = targetInfo; } - + target->getOptionSet().overrideWith(m_rawTargets[rawOutput.targetIndex].optionSet); if (rawOutput.isWholeProgram) { if (targetInfo->wholeTargetOutputPath != "") @@ -2874,7 +2852,13 @@ SlangResult OptionsParser::_parse( { if (rawOutput.entryPointIndex == -1) continue; - Int entryPointID = m_rawEntryPoints[rawOutput.entryPointIndex].entryPointID; + auto entryPoint = m_rawEntryPoints[rawOutput.entryPointIndex]; + Int entryPointID = entryPoint.entryPointID; + if (entryPointID == -1) + { + m_sink->diagnose(SourceLoc(), Diagnostics::entryPointFunctionNotFound, entryPoint.name); + continue; + } auto entryPointReq = m_requestImpl->getFrontEndReq()->getEntryPointReqs()[entryPointID]; //String outputPath; |
