diff options
| author | Yong He <yonghe@outlook.com> | 2022-04-21 11:03:30 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-21 11:03:30 -0700 |
| commit | 1b6cea2219307f6271e131c43d6e8f48910bd435 (patch) | |
| tree | 988538c9de24409eaf497f55c726f4f5e4709ff5 /tools | |
| parent | 3638e7735be67c8f4dae3f4544134441aa1e029d (diff) | |
Made translation units visible to transitive `import`s. (#2197)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-unit-test/unit-test-translation-unit-import.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/slang-unit-test/unit-test-translation-unit-import.cpp b/tools/slang-unit-test/unit-test-translation-unit-import.cpp index dfa75eb9f..9e79831e5 100644 --- a/tools/slang-unit-test/unit-test-translation-unit-import.cpp +++ b/tools/slang-unit-test/unit-test-translation-unit-import.cpp @@ -7,6 +7,7 @@ #include "tools/unit-test/slang-unit-test.h" #include "../../slang-com-ptr.h" +#include "../../source/core/slang-io.h" using namespace Slang; @@ -20,27 +21,38 @@ SLANG_UNIT_TEST(translationUnitImport) " return 5;" "};"; - // Source for the second translation unit that imports the first translation unit. + // Source for the a file that imports the first translation unit. // The import should succeed and `f` should be visible to this module. - const char* userSource = + const char* fileSource = R"( import generatedUnit; + int g(){ return f(); } + )"; + + // Source for a module that transitively uses the generated source via a file. + const char* userSource = R"( + import moduleG; [shader("compute")] [numthreads(4,1,1)] void computeMain( uint3 sv_dispatchThreadID : SV_DispatchThreadID, uniform RWStructuredBuffer<int> buffer) { - buffer[sv_dispatchThreadID.x] = f(); - } - )"; + buffer[sv_dispatchThreadID.x] = g(); + })"; + + auto session = spCreateSession(); auto request = spCreateCompileRequest(session); + + File::writeAllText("moduleG.slang", fileSource); + spAddCodeGenTarget(request, SLANG_HLSL); int generatedTranslationUnitIndex = spAddTranslationUnit(request, SLANG_SOURCE_LANGUAGE_SLANG, "generatedUnit"); spAddTranslationUnitSourceString( request, generatedTranslationUnitIndex, "generatedFile", generatedSource); + int entryPointTranslationUnitIndex = spAddTranslationUnit(request, SLANG_SOURCE_LANGUAGE_SLANG, "userUnit"); spAddTranslationUnitSourceString( request, entryPointTranslationUnitIndex, "userFile", userSource); @@ -52,8 +64,10 @@ SLANG_UNIT_TEST(translationUnitImport) Slang::ComPtr<ISlangBlob> outBlob; spGetEntryPointCodeBlob(request, 0, 0, outBlob.writeRef()); SLANG_CHECK(outBlob && outBlob->getBufferSize() != 0); - + spDestroyCompileRequest(request); spDestroySession(session); + + File::remove("moduleG.slang"); } |
