diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-06-04 17:15:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-04 17:15:38 -0400 |
| commit | ecac0c76a93bd123d5a5a86473716ad166f8c5d6 (patch) | |
| tree | 183314db50ba8be4e173581204a4d3df6fc41be0 /source | |
| parent | f3d637ba4d90bc2e23db07f1a9df5a6be7533f08 (diff) | |
Add a ASTBuilder to a Module (#1369)
Only construct on valid ASTBuilder (was being called on nullptr on occassion)
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ast-builder.cpp | 12 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 7 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 24 |
3 files changed, 31 insertions, 12 deletions
diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index 316390353..67ce80120 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -21,18 +21,20 @@ void SharedASTBuilder::init(Session* session) m_session = session; // We just want as a place to store allocations of shared types - RefPtr<ASTBuilder> astBuilder(new ASTBuilder); - - astBuilder->m_sharedASTBuilder = this; + { + RefPtr<ASTBuilder> astBuilder(new ASTBuilder); + astBuilder->m_sharedASTBuilder = this; + m_astBuilder = astBuilder.detach(); + } + // Clear the built in types memset(m_builtinTypes, 0, sizeof(m_builtinTypes)); + // Create common shared types m_errorType = m_astBuilder->create<ErrorType>(); m_initializerListType = m_astBuilder->create<InitializerListType>(); m_overloadedType = m_astBuilder->create<OverloadGroupType>(); - m_astBuilder = astBuilder.detach(); - // We can just iterate over the class pointers. // NOTE! That this adds the names of the abstract classes too(!) for (Index i = 0; i < Index(ASTNodeType::CountOf); ++i) diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 2c23a89bc..d5de51ac4 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -970,6 +970,9 @@ namespace Slang List<Module*> const& getModuleDependencies() SLANG_OVERRIDE { return m_moduleDependencyList.getModuleList(); } List<String> const& getFilePathDependencies() SLANG_OVERRIDE { return m_filePathDependencyList.getFilePathList(); } + /// Get the ASTBuilder + ASTBuilder* getASTBuilder() { return &m_astBuilder; } + /// Collect information on the shader parameters of the module. /// /// This method should only be called once, after the core @@ -1044,6 +1047,10 @@ namespace Slang // that was defined as part of the module. // List<RefPtr<EntryPoint>> m_entryPoints; + + // The builder that owns all of the AST nodes from parsing the source of + // this module. + ASTBuilder m_astBuilder; }; typedef Module LoadedModule; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 793b81ebf..331277bf3 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -124,13 +124,17 @@ void Session::init() // Use to create a ASTBuilder RefPtr<ASTBuilder> builtinAstBuilder(new ASTBuilder(m_sharedASTBuilder)); - + + // And the global ASTBuilder + globalAstBuilder = new ASTBuilder(m_sharedASTBuilder); + // Make sure our source manager is initialized builtinSourceManager.initialize(nullptr, nullptr); - + // Built in linkage uses the built in builder m_builtinLinkage = new Linkage(this, builtinAstBuilder); + // Because the `Session` retains the builtin `Linkage`, // we need to make sure that the parent pointer inside // `Linkage` doesn't create a retain cycle. @@ -952,7 +956,10 @@ void FrontEndCompileRequest::parseTranslationUnit( combinedPreprocessorDefinitions.Add(def.Key, def.Value); auto module = translationUnit->getModule(); - RefPtr<ModuleDecl> translationUnitSyntax = linkage->getASTBuilder()->create<ModuleDecl>(); + + ASTBuilder* astBuilder = module->getASTBuilder(); + + RefPtr<ModuleDecl> translationUnitSyntax = astBuilder->create<ModuleDecl>(); translationUnitSyntax->nameAndLoc.name = translationUnit->moduleName; translationUnitSyntax->module = module; module->setModuleDecl(translationUnitSyntax); @@ -966,13 +973,13 @@ void FrontEndCompileRequest::parseTranslationUnit( // // We are adding the marker here, before we even parse the // code in the module, in case the subsequent steps would - // like to treat the standard library differently. Alternatiely + // like to treat the standard library differently. Alternatively // we could pass down the `m_isStandardLibraryCode` flag to // these passes. // if( m_isStandardLibraryCode ) { - translationUnitSyntax->modifiers.first = linkage->getASTBuilder()->create<FromStdLibModifier>(); + translationUnitSyntax->modifiers.first = astBuilder->create<FromStdLibModifier>(); } for (auto sourceFile : translationUnit->getSourceFiles()) @@ -986,7 +993,7 @@ void FrontEndCompileRequest::parseTranslationUnit( module); parseSourceFile( - linkage->getASTBuilder(), + astBuilder, translationUnit, tokens, getSink(), @@ -1054,7 +1061,9 @@ void FrontEndCompileRequest::generateIR() // * it can dump ir // * it can generate diagnostics - /// Generate IR for translation unit + /// Generate IR for translation unit. + /// TODO(JS): Use the linkage ASTBuilder, because it seems possible that cross module constructs are possible in + /// ir lowering. RefPtr<IRModule> irModule(generateIRForTranslationUnit(getLinkage()->getASTBuilder(), translationUnit)); if (verifyDebugSerialization) @@ -1771,6 +1780,7 @@ void FilePathDependencyList::addDependency(Module* module) Module::Module(Linkage* linkage) : ComponentType(linkage) + , m_astBuilder(linkage->getASTBuilder()->getSharedASTBuilder()) { addModuleDependency(this); } |
