From 327f2b7ec50a7480b458d6d3ba8e2ca7fcdb8498 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 20 Jun 2017 08:11:27 -0700 Subject: Overhaul handling of entry points and translation units. The main user-visible change here is that instead of `spAddTranslationUnitEntryPoint` we have `spAddEntryPoint`, to reflect that the list of entry points is "global" to a compile request. As a result, `spGetEntryPointSource` now only needs the entry point index, and not the translation unit index. There are a bunch more behind-the-scenes changes, though, reflecting a streamlining of the concepts related to compilation into a smaller number of classes. Now there is: - `Session` (unchanged) to manage the lifetimes of shared stuff like the stdlib - `CompileRequest` (merges in `CompileOptions`) to handle all the lifetime related to a single invocation of the compiler - `TranslationUnitRequest` (merges `TranslationUnitOptions`, `CompileUnit`) to represent a single translation unit ("module") that the user is trying to compile. This is a single file for HLSL/GLSL, but can be multiple files for Slang. - `EntryPointRequest` (merges `EntryPointOption` and a bit of `EntryPointResult`) to track a single entry point that the user is asking to compile (that entry point always comes from a single translation unit) A lot of functions used to take some combination of these and end up with really long signatures. I've given most of the objects "parent" pointers so that they can get back to all the context they need, so most functions don't need as many parameters. It may eventually be important to tease these apart again, in particular: - The code-generation side of things (the `*Result` types) might need to be pulled out in case we want to codegen multiple times from the same AST - Similarly, the layout stuff may also need to be pulled out, in case we want to lay things out multiple times with different rules. --- source/slang/parameter-binding.cpp | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'source/slang/parameter-binding.cpp') diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 0756eb68c..70cb4e7ba 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -941,7 +941,7 @@ static void processEntryPointParameter( static void collectEntryPointParameters( ParameterBindingContext* context, - EntryPointOption const& entryPoint, + EntryPointRequest* entryPoint, ProgramSyntaxNode* translationUnitSyntax) { // First, look for the entry point with the specified name @@ -950,7 +950,7 @@ static void collectEntryPointParameters( buildMemberDictionary(translationUnitSyntax); Decl* entryPointDecl; - if( !translationUnitSyntax->memberDictionary.TryGetValue(entryPoint.name, entryPointDecl) ) + if( !translationUnitSyntax->memberDictionary.TryGetValue(entryPoint->name, entryPointDecl) ) { // No such entry point! return; @@ -970,7 +970,7 @@ static void collectEntryPointParameters( // Create the layout object here auto entryPointLayout = new EntryPointLayout(); - entryPointLayout->profile = entryPoint.profile; + entryPointLayout->profile = entryPoint->profile; entryPointLayout->entryPoint = entryPointFuncDecl; @@ -1043,18 +1043,18 @@ static void collectEntryPointParameters( // inputs and outputs). static Stage inferStageForTranslationUnit( - CompileUnit const& translationUnit) + TranslationUnitRequest* translationUnit) { // In the specific case where we are compiling GLSL input, // and have only a single entry point, use the stage // of the entry point. // // TODO: can we generalize this at all? - if( translationUnit.options.sourceLanguage == SourceLanguage::GLSL ) + if( translationUnit->sourceLanguage == SourceLanguage::GLSL ) { - if( translationUnit.options.entryPoints.Count() == 1 ) + if( translationUnit->entryPoints.Count() == 1 ) { - return translationUnit.options.entryPoints[0].profile.GetStage(); + return translationUnit->entryPoints[0]->profile.GetStage(); } } @@ -1063,36 +1063,36 @@ inferStageForTranslationUnit( static void collectParameters( ParameterBindingContext* inContext, - CollectionOfTranslationUnits* program) + CompileRequest* request) { ParameterBindingContext contextData = *inContext; auto context = &contextData; - for( auto& translationUnit : program->translationUnits ) + for( auto& translationUnit : request->translationUnits ) { - context->stage = inferStageForTranslationUnit(translationUnit); + context->stage = inferStageForTranslationUnit(translationUnit.Ptr()); // First look at global-scope parameters - collectGlobalScopeParameters(context, translationUnit.SyntaxNode.Ptr()); + collectGlobalScopeParameters(context, translationUnit->SyntaxNode.Ptr()); // Next consider parameters for entry points - for( auto& entryPoint : translationUnit.options.entryPoints ) + for( auto& entryPoint : translationUnit->entryPoints ) { - context->stage = entryPoint.profile.GetStage(); - collectEntryPointParameters(context, entryPoint, translationUnit.SyntaxNode.Ptr()); + context->stage = entryPoint->profile.GetStage(); + collectEntryPointParameters(context, entryPoint.Ptr(), translationUnit->SyntaxNode.Ptr()); } } } -void GenerateParameterBindings( - CollectionOfTranslationUnits* program) +void generateParameterBindings( + CompileRequest* request) { // TODO: infer a language or set of language rules to use based on the // source files and entry points given auto language = SourceLanguage::Unknown; - for( auto& translationUnit : program->translationUnits ) + for( auto& translationUnit : request->translationUnits ) { - auto translationUnitLanguage = translationUnit.options.sourceLanguage; + auto translationUnitLanguage = translationUnit->sourceLanguage; if( language == SourceLanguage::Unknown ) { language = translationUnitLanguage; @@ -1129,7 +1129,7 @@ void GenerateParameterBindings( context.layoutRules = sharedContext.defaultLayoutRules; // Walk through AST to discover all the parameters - collectParameters(&context, program); + collectParameters(&context, request); // Now walk through the parameters to generate initial binding information for( auto& parameter : sharedContext.parameters ) @@ -1245,7 +1245,7 @@ void GenerateParameterBindings( // We now have a bunch of layout information, which we should // record into a suitable object that represents the program programLayout->globalScopeLayout = globalScopeLayout; - program->layout = programLayout; + request->layout = programLayout; } } -- cgit v1.2.3