diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-10-31 15:02:18 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-31 15:02:18 -0400 |
| commit | f59df3814a514cab01f69a24e3330d13de3f9c92 (patch) | |
| tree | e8178e2ea376556b79d66c342547134f92640f34 /source/slang/slang.cpp | |
| parent | 72f86c8273b196d204213f02e73ba772201f903d (diff) | |
Reference IR modules with entry point (#1101)
* Added RiffReadHelper
* Move type to fourCC in Chunk simplifies some code.
* Make MemoryArena able to track external blocks.
Allow ownership of Data to vary.
Changed IR serialization to use moved allocations to avoid copies.
As it turns out all of the array writes could use unowned data, but doing so requires the IRData to stay in scope longer than IRSerialData, which it does at the moment - but perhaps needs better naming or a control for the feature.
* Write out slang-module container.
* WIP on -r option.
Loading modules - with -r.
* Making the serialized-module run (without using imported module).
* Split compiling module from the test.
* Separate module compilation with a function working.
* Remove serialization test as not used.
* Fix warning on gcc.
* Updated test to have types across module boundary.
* Allow entry point declaration.
A test that tries to build with just an entry point declaration and a module.
* Try to make link work with multiple modules.
* Multi module linking first pass working.
* Multi module test working with -module-name option
* Use isDefinition - for determining to add decorations to entry point lowering.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index ed0e87045..c7171d835 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1348,6 +1348,18 @@ int FrontEndCompileRequest::addTranslationUnit(SourceLanguage language, Name* mo { Index result = translationUnits.getCount(); + if (!moduleName) + { + // We want to ensure that symbols defined in different translation + // units get unique mangled names, so that we can, e.g., tell apart + // a `main()` function in `vertex.slang` and a `main()` in `fragment.slang`, + // even when they are being compiled together. + // + String generatedName = "tu"; + generatedName.append(translationUnits.getCount()); + moduleName = getNamePool()->getName(generatedName); + } + RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest(this); translationUnit->compileRequest = this; translationUnit->sourceLanguage = SourceLanguage(language); @@ -1359,18 +1371,6 @@ int FrontEndCompileRequest::addTranslationUnit(SourceLanguage language, Name* mo return (int) result; } -int FrontEndCompileRequest::addTranslationUnit(SourceLanguage language) -{ - // We want to ensure that symbols defined in different translation - // units get unique mangled names, so that we can, e.g., tell apart - // a `main()` function in `vertex.slang` and a `main()` in `fragment.slang`, - // even when they are being compiled together. - // - String generatedName = "tu"; - generatedName.append(translationUnits.getCount()); - return addTranslationUnit(language, getNamePool()->getName(generatedName)); -} - void FrontEndCompileRequest::addTranslationUnitSourceFile( int translationUnitIndex, SourceFile* sourceFile) @@ -3009,17 +3009,36 @@ SLANG_API SlangResult spGetDiagnosticOutputBlob( SLANG_API int spAddTranslationUnit( SlangCompileRequest* request, SlangSourceLanguage language, - char const* name) + char const* inName) { - SLANG_UNUSED(name); - auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); + Slang::NamePool* namePool = req->getFrontEndReq()->getNamePool(); + + // Work out a module name. Can be nullptr if so will generate a name + Slang::Name* moduleName = inName ? namePool->getName(inName) : frontEndReq->m_defaultModuleName; + + // If moduleName is nullptr a name will be generated + return frontEndReq->addTranslationUnit( - Slang::SourceLanguage(language)); + Slang::SourceLanguage(language), + moduleName); +} + +SLANG_API void spSetDefaultModuleName( + SlangCompileRequest* request, + const char* defaultModuleName) +{ + auto req = Slang::asInternal(request); + auto frontEndReq = req->getFrontEndReq(); + + Slang::NamePool* namePool = req->getFrontEndReq()->getNamePool(); + + frontEndReq->m_defaultModuleName = namePool->getName(defaultModuleName); } + SLANG_API void spTranslationUnit_addPreprocessorDefine( SlangCompileRequest* request, int translationUnitIndex, |
