diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-08-08 16:09:29 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-08 16:09:29 -0400 |
| commit | c1cc93dd962a6db6c839341f11d2654cf0e62e37 (patch) | |
| tree | cc9048411387322e6910854bd63e606ae8ba03e8 | |
| parent | 2552217b76c0bd83e18fceba1d35a367bf569eca (diff) | |
Make SlangSession an alias for slang::IGlobalSession (#1011)
* Make SlangSession an alias for slang::IGlobalSession.
Use asInternal/asExternal for casting in slang.cpp
Special case handling of asInternal which argument dependent lookup doesn't find.
* To improve implementation asInternal/asExternal in slang.cpp - tried making the internal impls forward to the Slang:: implementations. This caused ambiguities (for example when a function has using namespace Slang in it). To avoid these problems and make it clear where implementation is coming from use Slang::asInternal and removed the forwarding functions.
Made the impls SLANG_FORCE_INLINE instead of inline.
* Made asInternal/asExternal use SLANG_FORCE_INLINE uniformly.
| -rw-r--r-- | slang.h | 6 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 34 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 110 |
3 files changed, 76 insertions, 74 deletions
@@ -1055,10 +1055,14 @@ extern "C" #define SLANG_UUID_ISlangWriter { 0xec457f0e, 0x9add, 0x4e6b,{ 0x85, 0x1c, 0xd7, 0xfa, 0x71, 0x6d, 0x15, 0xfd } }; + namespace slang { + struct IGlobalSession; + } // namespace slang + /*! @brief An instance of the Slang library. */ - typedef struct SlangSession SlangSession; + typedef slang::IGlobalSession SlangSession; typedef struct SlangProgramLayout SlangProgramLayout; diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 46b257fe3..8f9c20044 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1943,66 +1943,76 @@ namespace Slang // abstract over the conversion required for each pair of types. // -inline slang::IGlobalSession* asExternal(Session* session) +SLANG_FORCE_INLINE slang::IGlobalSession* asExternal(Session* session) { return static_cast<slang::IGlobalSession*>(session); } -inline slang::ISession* asExternal(Linkage* linkage) +SLANG_FORCE_INLINE Session* asInternal(slang::IGlobalSession* session) +{ + return static_cast<Session*>(session); +} + +SLANG_FORCE_INLINE slang::ISession* asExternal(Linkage* linkage) { return static_cast<slang::ISession*>(linkage); } -inline Module* asInternal(slang::IModule* module) +SLANG_FORCE_INLINE Module* asInternal(slang::IModule* module) { return static_cast<Module*>(module); } -inline slang::IModule* asExternal(Module* module) +SLANG_FORCE_INLINE slang::IModule* asExternal(Module* module) { return static_cast<slang::IModule*>(module); } -inline ComponentType* asInternal(slang::IComponentType* componentType) +SLANG_FORCE_INLINE ComponentType* asInternal(slang::IComponentType* componentType) { return static_cast<ComponentType*>(componentType); } -inline slang::IComponentType* asExternal(ComponentType* componentType) +SLANG_FORCE_INLINE slang::IComponentType* asExternal(ComponentType* componentType) { return static_cast<slang::IComponentType*>(componentType); } -static inline slang::ProgramLayout* asExternal(ProgramLayout* programLayout) +SLANG_FORCE_INLINE slang::ProgramLayout* asExternal(ProgramLayout* programLayout) { return (slang::ProgramLayout*) programLayout; } -inline Type* asInternal(slang::TypeReflection* type) +SLANG_FORCE_INLINE Type* asInternal(slang::TypeReflection* type) { return reinterpret_cast<Type*>(type); } -inline slang::TypeReflection* asExternal(Type* type) +SLANG_FORCE_INLINE slang::TypeReflection* asExternal(Type* type) { return reinterpret_cast<slang::TypeReflection*>(type); } -inline TypeLayout* asInternal(slang::TypeLayoutReflection* type) +SLANG_FORCE_INLINE TypeLayout* asInternal(slang::TypeLayoutReflection* type) { return reinterpret_cast<TypeLayout*>(type); } -inline slang::TypeLayoutReflection* asExternal(TypeLayout* type) +SLANG_FORCE_INLINE slang::TypeLayoutReflection* asExternal(TypeLayout* type) { return reinterpret_cast<slang::TypeLayoutReflection*>(type); } -inline SlangCompileRequest* asExternal(EndToEndCompileRequest* request) +SLANG_FORCE_INLINE SlangCompileRequest* asExternal(EndToEndCompileRequest* request) { return reinterpret_cast<SlangCompileRequest*>(request); } +SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* request) +{ + return reinterpret_cast<EndToEndCompileRequest*>(request); +} + } #endif diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index b030e5cf9..cae9855e0 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -2442,21 +2442,9 @@ Session::~Session() // implementation of C interface -static SlangSession* convert(Slang::Session* session) -{ return reinterpret_cast<SlangSession*>(session); } - -static Slang::Session* convert(SlangSession* session) -{ return reinterpret_cast<Slang::Session*>(session); } - -static SlangCompileRequest* convert(Slang::EndToEndCompileRequest* request) -{ return reinterpret_cast<SlangCompileRequest*>(request); } - -static Slang::EndToEndCompileRequest* convert(SlangCompileRequest* request) -{ return reinterpret_cast<Slang::EndToEndCompileRequest*>(request); } - SLANG_API SlangSession* spCreateSession(const char*) { - return convert(new Slang::Session()); + return asExternal(new Slang::Session()); } SLANG_API SlangResult slang_createGlobalSession( @@ -2476,7 +2464,7 @@ SLANG_API void spDestroySession( SlangSession* session) { if(!session) return; - delete convert(session); + delete Slang::asInternal(session); } SLANG_API void spAddBuiltins( @@ -2484,7 +2472,7 @@ SLANG_API void spAddBuiltins( char const* sourcePath, char const* sourceString) { - auto s = convert(session); + auto s = Slang::asInternal(session); s->addBuiltinSource( // TODO(tfoley): Add ability to directly new builtins to the approriate scope @@ -2498,7 +2486,7 @@ SLANG_API void spSessionSetSharedLibraryLoader( SlangSession* session, ISlangSharedLibraryLoader* loader) { - auto s = convert(session); + auto s = Slang::asInternal(session); if (!loader) { @@ -2525,7 +2513,7 @@ SLANG_API void spSessionSetSharedLibraryLoader( SLANG_API ISlangSharedLibraryLoader* spSessionGetSharedLibraryLoader( SlangSession* session) { - auto s = convert(session); + auto s = Slang::asInternal(session); return (s->sharedLibraryLoader == Slang::DefaultSharedLibraryLoader::getSingleton()) ? nullptr : s->sharedLibraryLoader.get(); } @@ -2533,7 +2521,7 @@ SLANG_API SlangResult spSessionCheckCompileTargetSupport( SlangSession* session, SlangCompileTarget target) { - auto s = convert(session); + auto s = Slang::asInternal(session); return Slang::checkCompileTargetSupport(s, Slang::CodeGenTarget(target)); } @@ -2541,16 +2529,16 @@ SLANG_API SlangResult spSessionCheckPassThroughSupport( SlangSession* session, SlangPassThrough passThrough) { - auto s = convert(session); + auto s = Slang::asInternal(session); return Slang::checkExternalCompilerSupport(s, Slang::PassThroughMode(passThrough)); } SLANG_API SlangCompileRequest* spCreateCompileRequest( SlangSession* session) { - auto s = convert(session); + auto s = Slang::asInternal(session); auto req = new Slang::EndToEndCompileRequest(s); - return convert(req); + return asExternal(req); } /*! @@ -2560,7 +2548,7 @@ SLANG_API void spDestroyCompileRequest( SlangCompileRequest* request) { if(!request) return; - auto req = convert(request); + auto req = Slang::asInternal(request); delete req; } @@ -2569,21 +2557,21 @@ SLANG_API void spSetFileSystem( ISlangFileSystem* fileSystem) { if(!request) return; - convert(request)->getLinkage()->setFileSystem(fileSystem); + Slang::asInternal(request)->getLinkage()->setFileSystem(fileSystem); } SLANG_API void spSetCompileFlags( SlangCompileRequest* request, SlangCompileFlags flags) { - convert(request)->getFrontEndReq()->compileFlags = flags; + Slang::asInternal(request)->getFrontEndReq()->compileFlags = flags; } SLANG_API void spSetDumpIntermediates( SlangCompileRequest* request, int enable) { - convert(request)->getBackEndReq()->shouldDumpIntermediates = enable != 0; + Slang::asInternal(request)->getBackEndReq()->shouldDumpIntermediates = enable != 0; } SLANG_API void spSetLineDirectiveMode( @@ -2592,13 +2580,13 @@ SLANG_API void spSetLineDirectiveMode( { // TODO: validation - convert(request)->getBackEndReq()->lineDirectiveMode = Slang::LineDirectiveMode(mode); + Slang::asInternal(request)->getBackEndReq()->lineDirectiveMode = Slang::LineDirectiveMode(mode); } SLANG_API void spSetCommandLineCompilerMode( SlangCompileRequest* request) { - convert(request)->isCommandLineCompile = true; + Slang::asInternal(request)->isCommandLineCompile = true; } @@ -2606,7 +2594,7 @@ SLANG_API void spSetCodeGenTarget( SlangCompileRequest* request, SlangCompileTarget target) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->targets.clear(); linkage->addTarget(Slang::CodeGenTarget(target)); @@ -2616,7 +2604,7 @@ SLANG_API int spAddCodeGenTarget( SlangCompileRequest* request, SlangCompileTarget target) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); return (int) linkage->addTarget(Slang::CodeGenTarget(target)); } @@ -2626,7 +2614,7 @@ SLANG_API void spSetTargetProfile( int targetIndex, SlangProfileID profile) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->targets[targetIndex]->targetProfile = Slang::Profile(profile); } @@ -2636,7 +2624,7 @@ SLANG_API void spSetTargetFlags( int targetIndex, SlangTargetFlags flags) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->targets[targetIndex]->targetFlags = flags; } @@ -2646,7 +2634,7 @@ SLANG_API void spSetTargetFloatingPointMode( int targetIndex, SlangFloatingPointMode mode) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->targets[targetIndex]->floatingPointMode = Slang::FloatingPointMode(mode); } @@ -2655,7 +2643,7 @@ SLANG_API void spSetMatrixLayoutMode( SlangCompileRequest* request, SlangMatrixLayoutMode mode) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->setMatrixLayoutMode(mode); } @@ -2676,7 +2664,7 @@ SLANG_API void spSetDebugInfoLevel( SlangCompileRequest* request, SlangDebugInfoLevel level) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->debugInfoLevel = Slang::DebugInfoLevel(level); } @@ -2688,7 +2676,7 @@ SLANG_API void spSetOptimizationLevel( SlangCompileRequest* request, SlangOptimizationLevel level) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->optimizationLevel = Slang::OptimizationLevel(level); } @@ -2698,7 +2686,7 @@ SLANG_API void spSetOutputContainerFormat( SlangCompileRequest* request, SlangContainerFormat format) { - auto req = convert(request); + auto req = Slang::asInternal(request); req->containerFormat = Slang::ContainerFormat(format); } @@ -2707,7 +2695,7 @@ SLANG_API void spSetPassThrough( SlangCompileRequest* request, SlangPassThrough passThrough) { - convert(request)->passThrough = Slang::PassThroughMode(passThrough); + Slang::asInternal(request)->passThrough = Slang::PassThroughMode(passThrough); } SLANG_API void spSetDiagnosticCallback( @@ -2718,7 +2706,7 @@ SLANG_API void spSetDiagnosticCallback( using namespace Slang; if(!request) return; - auto req = convert(request); + auto req = Slang::asInternal(request); ComPtr<ISlangWriter> writer(new CallbackWriter(callback, userData, WriterFlag::IsConsole)); req->setWriter(WriterChannel::Diagnostic, writer); @@ -2730,7 +2718,7 @@ SLANG_API void spSetWriter( ISlangWriter* writer) { if (!request) return; - auto req = convert(request); + auto req = Slang::asInternal(request); req->setWriter(Slang::WriterChannel(chan), writer); } @@ -2740,7 +2728,7 @@ SLANG_API ISlangWriter* spGetWriter( SlangWriterChannel chan) { if (!request) return nullptr; - auto req = convert(request); + auto req = Slang::asInternal(request); return req->getWriter(Slang::WriterChannel(chan)); } @@ -2748,7 +2736,7 @@ SLANG_API void spAddSearchPath( SlangCompileRequest* request, const char* path) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->addSearchPath(path); } @@ -2758,7 +2746,7 @@ SLANG_API void spAddPreprocessorDefine( const char* key, const char* value) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); linkage->addPreprocessorDefine(key, value); } @@ -2767,7 +2755,7 @@ SLANG_API char const* spGetDiagnosticOutput( SlangCompileRequest* request) { if(!request) return 0; - auto req = convert(request); + auto req = Slang::asInternal(request); return req->mDiagnosticOutput.begin(); } @@ -2778,7 +2766,7 @@ SLANG_API SlangResult spGetDiagnosticOutputBlob( if(!request) return SLANG_ERROR_INVALID_PARAMETER; if(!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - auto req = convert(request); + auto req = Slang::asInternal(request); if(!req->diagnosticOutputBlob) { @@ -2799,7 +2787,7 @@ SLANG_API int spAddTranslationUnit( { SLANG_UNUSED(name); - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); return frontEndReq->addTranslationUnit( @@ -2812,7 +2800,7 @@ SLANG_API void spTranslationUnit_addPreprocessorDefine( const char* key, const char* value) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); frontEndReq->translationUnits[translationUnitIndex]->preprocessorDefinitions[key] = value; @@ -2824,7 +2812,7 @@ SLANG_API void spAddTranslationUnitSourceFile( char const* path) { if(!request) return; - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); if(!path) return; if(translationUnitIndex < 0) return; @@ -2859,7 +2847,7 @@ SLANG_API void spAddTranslationUnitSourceStringSpan( { using namespace Slang; if(!request) return; - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); if(!sourceBegin) return; if(translationUnitIndex < 0) return; @@ -2880,7 +2868,7 @@ SLANG_API void spAddTranslationUnitSourceBlob( ISlangBlob* sourceBlob) { if(!request) return; - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); if(!sourceBlob) return; if(translationUnitIndex < 0) return; @@ -2931,7 +2919,7 @@ SLANG_API int spAddEntryPointEx( { using namespace Slang; if (!request) return -1; - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); if (!name) return -1; if (translationUnitIndex < 0) return -1; @@ -2952,7 +2940,7 @@ SLANG_API SlangResult spSetGlobalGenericArgs( char const** genericArgs) { if (!request) return SLANG_FAIL; - auto req = convert(request); + auto req = Slang::asInternal(request); auto& argStrings = req->globalSpecializationArgStrings; argStrings.clear(); @@ -2972,7 +2960,7 @@ SLANG_API SlangResult spSetTypeNameForGlobalExistentialTypeParam( if(slotIndex < 0) return SLANG_FAIL; if(!typeName) return SLANG_FAIL; - auto req = convert(request); + auto req = Slang::asInternal(request); auto& typeArgStrings = req->globalSpecializationArgStrings; if(Index(slotIndex) >= typeArgStrings.getCount()) typeArgStrings.setCount(slotIndex+1); @@ -2992,7 +2980,7 @@ SLANG_API SlangResult spSetTypeNameForEntryPointExistentialTypeParam( if(slotIndex < 0) return SLANG_FAIL; if(!typeName) return SLANG_FAIL; - auto req = convert(request); + auto req = Slang::asInternal(request); if(Index(entryPointIndex) >= req->entryPoints.getCount()) return SLANG_FAIL; @@ -3008,7 +2996,7 @@ SLANG_API SlangResult spSetTypeNameForEntryPointExistentialTypeParam( SLANG_API SlangResult spCompile( SlangCompileRequest* request) { - auto req = convert(request); + auto req = Slang::asInternal(request); #if !defined(SLANG_DEBUG_INTERNAL_ERROR) // By default we'd like to catch as many internal errors as possible, @@ -3063,7 +3051,7 @@ spGetDependencyFileCount( SlangCompileRequest* request) { if(!request) return 0; - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); auto program = frontEndReq->getGlobalAndEntryPointsComponentType(); return (int) program->getFilePathDependencies().getCount(); @@ -3077,7 +3065,7 @@ spGetDependencyFilePath( int index) { if(!request) return 0; - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); auto program = frontEndReq->getGlobalAndEntryPointsComponentType(); return program->getFilePathDependencies()[index].begin(); @@ -3087,7 +3075,7 @@ SLANG_API int spGetTranslationUnitCount( SlangCompileRequest* request) { - auto req = convert(request); + auto req = Slang::asInternal(request); auto frontEndReq = req->getFrontEndReq(); return (int) frontEndReq->translationUnits.getCount(); } @@ -3107,7 +3095,7 @@ SLANG_API void const* spGetEntryPointCode( size_t* outSize) { using namespace Slang; - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); @@ -3162,7 +3150,7 @@ SLANG_API SlangResult spGetEntryPointCodeBlob( if(!request) return SLANG_ERROR_INVALID_PARAMETER; if(!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); @@ -3214,7 +3202,7 @@ SLANG_API SlangResult spCompileRequest_getProgram( slang::IComponentType** outProgram) { if( !request ) return SLANG_ERROR_INVALID_PARAMETER; - auto req = convert(request); + auto req = Slang::asInternal(request); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); *outProgram = Slang::ComPtr<slang::IComponentType>(program).detach(); @@ -3225,7 +3213,7 @@ SLANG_API SlangReflection* spGetReflection( SlangCompileRequest* request) { if( !request ) return 0; - auto req = convert(request); + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); |
