diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/check.cpp | 83 | ||||
| -rw-r--r-- | source/slang/options.cpp | 4 | ||||
| -rw-r--r-- | source/slang/parameter-binding.cpp | 1 | ||||
| -rw-r--r-- | source/slang/reflection.cpp | 64 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 12 | ||||
| -rw-r--r-- | source/slang/type-layout.h | 1 |
6 files changed, 119 insertions, 46 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 5141d8634..bc5d144b0 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -6798,50 +6798,55 @@ namespace Slang } entryPoint->genericParameterTypes.Add(type); } - // check that user-provioded type arguments conforms to the generic type - // parameter declaration of this translation unit - - // collect global generic parameters from all imported modules - List<RefPtr<GlobalGenericParamDecl>> globalGenericParams; - // add current translation unit first - { - auto globalGenParams = translationUnit->SyntaxNode->getMembersOfType<GlobalGenericParamDecl>(); - for (auto p : globalGenParams) - globalGenericParams.Add(p); - } - // add imported modules - for (auto loadedModule : entryPoint->compileRequest->loadedModulesList) - { - auto moduleDecl = loadedModule->moduleDecl; - auto globalGenParams = moduleDecl->getMembersOfType<GlobalGenericParamDecl>(); - for (auto p : globalGenParams) - globalGenericParams.Add(p); - } - if (globalGenericParams.Count() != entryPoint->genericParameterTypes.Count()) + + // validate global type arguments only when we are generating code + if ((entryPoint->compileRequest->compileFlags & SLANG_COMPILE_FLAG_NO_CODEGEN) == 0) { - sink->diagnose(entryPoint->decl, Diagnostics::mismatchEntryPointTypeArgument, globalGenericParams.Count(), + // check that user-provioded type arguments conforms to the generic type + // parameter declaration of this translation unit + + // collect global generic parameters from all imported modules + List<RefPtr<GlobalGenericParamDecl>> globalGenericParams; + // add current translation unit first + { + auto globalGenParams = translationUnit->SyntaxNode->getMembersOfType<GlobalGenericParamDecl>(); + for (auto p : globalGenParams) + globalGenericParams.Add(p); + } + // add imported modules + for (auto loadedModule : entryPoint->compileRequest->loadedModulesList) + { + auto moduleDecl = loadedModule->moduleDecl; + auto globalGenParams = moduleDecl->getMembersOfType<GlobalGenericParamDecl>(); + for (auto p : globalGenParams) + globalGenericParams.Add(p); + } + if (globalGenericParams.Count() != entryPoint->genericParameterTypes.Count()) + { + sink->diagnose(entryPoint->decl, Diagnostics::mismatchEntryPointTypeArgument, globalGenericParams.Count(), entryPoint->genericParameterTypes.Count()); - return; - } - // if number of entry-point type arguments matches parameters, try find - // SubtypeWitness for each argument - int index = 0; - for (auto & gParam : globalGenericParams) - { - for (auto constraint : gParam->getMembersOfType<GenericTypeConstraintDecl>()) + return; + } + // if number of entry-point type arguments matches parameters, try find + // SubtypeWitness for each argument + int index = 0; + for (auto & gParam : globalGenericParams) { - auto interfaceType = GetSup(DeclRef<GenericTypeConstraintDecl>(constraint, nullptr)); - SemanticsVisitor visitor(sink, entryPoint->compileRequest, translationUnit); - auto witness = visitor.tryGetSubtypeWitness(entryPoint->genericParameterTypes[index], interfaceType); - if (!witness) + for (auto constraint : gParam->getMembersOfType<GenericTypeConstraintDecl>()) { - sink->diagnose(gParam, - Diagnostics::typeArgumentDoesNotConformToInterface, gParam->nameAndLoc.name, entryPoint->genericParameterTypes[index], - interfaceType); + auto interfaceType = GetSup(DeclRef<GenericTypeConstraintDecl>(constraint, nullptr)); + SemanticsVisitor visitor(sink, entryPoint->compileRequest, translationUnit); + auto witness = visitor.tryGetSubtypeWitness(entryPoint->genericParameterTypes[index], interfaceType); + if (!witness) + { + sink->diagnose(gParam, + Diagnostics::typeArgumentDoesNotConformToInterface, gParam->nameAndLoc.name, entryPoint->genericParameterTypes[index], + interfaceType); + } + entryPoint->genericParameterWitnesses.Add(witness); } - entryPoint->genericParameterWitnesses.Add(witness); + index++; } - index++; } if (sink->errorCount != 0) return; @@ -6851,8 +6856,6 @@ namespace Slang // if they are of types that are appropriate to the stage, etc. } - - void checkTranslationUnit( TranslationUnitRequest* translationUnit) { diff --git a/source/slang/options.cpp b/source/slang/options.cpp index 97deeb544..a5ed8eca6 100644 --- a/source/slang/options.cpp +++ b/source/slang/options.cpp @@ -278,6 +278,10 @@ struct OptionsParser { flags |= SLANG_COMPILE_FLAG_NO_MANGLING; } + else if (argStr == "-no-codegen") + { + flags |= SLANG_COMPILE_FLAG_NO_CODEGEN; + } else if(argStr == "-dump-ir" ) { requestImpl->shouldDumpIR = true; diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 4ec4f6fd5..6145015f1 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -700,6 +700,7 @@ static void collectGlobalGenericParameter( layout->decl = paramDecl; layout->index = (int)context->shared->programLayout->globalGenericParams.Count(); context->shared->programLayout->globalGenericParams.Add(layout); + context->shared->programLayout->globalGenericParamsMap[layout->decl->getName()->text] = layout.Ptr(); } // Collect a single declaration into our set of parameters diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index bd95f48fa..5270df8b4 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -39,6 +39,11 @@ static inline SlangReflectionTypeLayout* convert(TypeLayout* type) return (SlangReflectionTypeLayout*) type; } +static inline GenericParamLayout* convert(SlangReflectionTypeParameter * typeParam) +{ + return (GenericParamLayout*)typeParam; +} + static inline VarDeclBase* convert(SlangReflectionVariable* var) { return (VarDeclBase*) var; @@ -126,7 +131,6 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) { return SLANG_TYPE_KIND_RESOURCE; } - // TODO: need a better way to handle this stuff... #define CASE(TYPE) \ else if(type->As<TYPE>()) do { \ @@ -153,6 +157,14 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) { return SLANG_TYPE_KIND_STRUCT; } + else if (auto genericParamType = declRef.As<GlobalGenericParamDecl>()) + { + return SLANG_TYPE_KIND_GENERIC_TYPE_PARAMETER; + } + else if (auto interfaceType = declRef.As<InterfaceDecl>()) + { + return SLANG_TYPE_KIND_INTERFACE; + } } else if (auto errorType = type->As<ErrorType>()) { @@ -848,7 +860,7 @@ namespace Slang return 0; } - + static VarLayout* getParameterByIndex(RefPtr<TypeLayout> typeLayout, unsigned index) { if(auto parameterGroupLayout = typeLayout.As<ParameterGroupTypeLayout>()) @@ -974,6 +986,33 @@ SLANG_API int spReflectionEntryPoint_usesAnySampleRateInput( return (entryPointLayout->flags & EntryPointLayout::Flag::usesAnySampleRateInput) != 0; } +// SlangReflectionTypeParameter +SLANG_API char const* spReflectionTypeParameter_GetName(SlangReflectionTypeParameter * inTypeParam) +{ + auto typeParam = convert(inTypeParam); + return typeParam->decl->getName()->text.Buffer(); +} + +SLANG_API unsigned spReflectionTypeParameter_GetIndex(SlangReflectionTypeParameter * inTypeParam) +{ + auto typeParam = convert(inTypeParam); + return (unsigned)(typeParam->index); +} + +SLANG_API unsigned int spReflectionTypeParameter_GetConstraintCount(SlangReflectionTypeParameter* inTypeParam) +{ + auto typeParam = convert(inTypeParam); + auto constraints = typeParam->decl->getMembersOfType<GenericTypeConstraintDecl>(); + return (unsigned int)constraints.Count(); +} + +SLANG_API SlangReflectionType* spReflectionTypeParameter_GetConstraintByIndex(SlangReflectionTypeParameter * inTypeParam, unsigned index) +{ + auto typeParam = convert(inTypeParam); + auto constraints = typeParam->decl->getMembersOfType<GenericTypeConstraintDecl>(); + return (SlangReflectionType*)constraints.ToArray()[index]->sup.Ptr(); +} + // Shader Reflection namespace Slang @@ -1006,6 +1045,27 @@ SLANG_API SlangReflectionParameter* spReflection_GetParameterByIndex(SlangReflec return convert(globalStructLayout->fields[index].Ptr()); } +SLANG_API unsigned int spReflection_GetTypeParameterCount(SlangReflection * reflection) +{ + auto program = convert(reflection); + return (unsigned int)program->globalGenericParams.Count(); +} + +SLANG_API SlangReflectionTypeParameter* spReflection_GetTypeParameterByIndex(SlangReflection * reflection, unsigned int index) +{ + auto program = convert(reflection); + return (SlangReflectionTypeParameter*)program->globalGenericParams[index].Ptr(); +} + +SLANG_API SlangReflectionTypeParameter * spReflection_FindTypeParameter(SlangReflection * inProgram, char const * name) +{ + auto program = convert(inProgram); + if (!program) return nullptr; + GenericParamLayout * result = nullptr; + program->globalGenericParamsMap.TryGetValue(name, result); + return (SlangReflectionTypeParameter*)result; +} + SLANG_API SlangUInt spReflection_getEntryPointCount(SlangReflection* inProgram) { auto program = convert(inProgram); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index ea86663ea..3156e5008 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -293,9 +293,12 @@ int CompileRequest::executeActionsInner() if (mSink.GetErrorCount() != 0) return 1; - // Generate initial IR for all the translation - // units, if we are in a mode where IR is called for. - generateIR(); + if ((compileFlags & SLANG_COMPILE_FLAG_NO_CODEGEN) == 0) + { + // Generate initial IR for all the translation + // units, if we are in a mode where IR is called for. + generateIR(); + } if (mSink.GetErrorCount() != 0) return 1; @@ -315,7 +318,8 @@ int CompileRequest::executeActionsInner() // If command line specifies to skip codegen, we exit here. // Note: this is a debugging option. - if (shouldSkipCodegen) + if (shouldSkipCodegen || + ((compileFlags & SLANG_COMPILE_FLAG_NO_CODEGEN) != 0)) return 0; // Generate output code, in whatever format was requested diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index 6874fc460..904dacd91 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -450,6 +450,7 @@ public: List<RefPtr<EntryPointLayout>> entryPoints; List<RefPtr<GenericParamLayout>> globalGenericParams; + Dictionary<String, GenericParamLayout*> globalGenericParamsMap; // HACK: binding to use when we have to create // a dummy sampler just to appease glslang |
