summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-05-28 14:01:51 -0400
committerGitHub <noreply@github.com>2020-05-28 14:01:51 -0400
commitc2d31347ea06c768045e7c503ef0188e0e5356de (patch)
tree1a4ee67aafca0a709ae691104023431bb6829825 /source/slang/slang.cpp
parente5d0f3360f44a4cdd2390e7817db17bb3cc0dd04 (diff)
WIP: ASTBuilder (#1358)
* Compiles. * Small tidy up around session/ASTBuilder. * Tests are now passing. * Fix Visual Studio project. * Fix using new X to use builder when protectedness of Ctor is not enough. Substitute->substitute * Add some missing ast nodes created outside of ASTBuilder. * Compile time check that ASTBuilder is making an AST type. * Moced findClasInfo and findSyntaxClass (essentially the same thing) to SharedASTBuilder from Session.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp71
1 files changed, 30 insertions, 41 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 2c698eeaf..486034876 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -118,26 +118,18 @@ void Session::init()
// Set all the shared library function pointers to nullptr
::memset(m_sharedLibraryFunctions, 0, sizeof(m_sharedLibraryFunctions));
-
- // Initialize the lookup table of syntax classes:
-
- // 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)
- {
- const ReflectClassInfo* info = ReflectClassInfo::getInfo(ASTNodeType(i));
- if (info)
- {
- mapNameToSyntaxClass.Add(getNamePool()->getName(info->m_name), SyntaxClass<Slang::RefObject>(info));
- }
- }
- }
+ // Set up shared AST builder
+ m_sharedASTBuilder = new SharedASTBuilder;
+ m_sharedASTBuilder->init(this);
+ // Use to create a ASTBuilder
+ RefPtr<ASTBuilder> builtinAstBuilder(new ASTBuilder(m_sharedASTBuilder));
+
// Make sure our source manager is initialized
builtinSourceManager.initialize(nullptr, nullptr);
- m_builtinLinkage = new Linkage(this);
+
+ m_builtinLinkage = new Linkage(this, builtinAstBuilder);
// Because the `Session` retains the builtin `Linkage`,
// we need to make sure that the parent pointer inside
@@ -149,9 +141,7 @@ void Session::init()
//
m_builtinLinkage->_stopRetainingParentSession();
- // Initialize representations of some very basic types:
- initializeTypes();
-
+
// Create scopes for various language builtins.
//
// TODO: load these on-demand to avoid parsing
@@ -160,7 +150,7 @@ void Session::init()
baseLanguageScope = new Scope();
auto baseModuleDecl = populateBaseLanguageModule(
- this,
+ m_builtinLinkage->getASTBuilder(),
baseLanguageScope);
loadedModuleCode.add(baseModuleDecl);
@@ -198,7 +188,8 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createSession(
slang::SessionDesc const& desc,
slang::ISession** outSession)
{
- RefPtr<Linkage> linkage = new Linkage(this);
+ RefPtr<ASTBuilder> astBuilder(new ASTBuilder(m_sharedASTBuilder));
+ RefPtr<Linkage> linkage = new Linkage(this, astBuilder);
Int targetCount = desc.targetCount;
for(Int ii = 0; ii < targetCount; ++ii)
@@ -507,10 +498,11 @@ Profile getEffectiveProfile(EntryPoint* entryPoint, TargetRequest* target)
//
-Linkage::Linkage(Session* session)
+Linkage::Linkage(Session* session, ASTBuilder* astBuilder)
: m_session(session)
, m_retainedSession(session)
, m_sourceManager(&m_defaultSourceManager)
+ , m_astBuilder(astBuilder)
{
getNamePool()->setRootNamePool(session->getRootNamePool());
@@ -868,7 +860,7 @@ RefPtr<Expr> Linkage::parseTermString(String typeStr, RefPtr<Scope> scope)
nullptr);
return parseTermFromSourceFile(
- getSessionImpl(),
+ getASTBuilder(),
tokens, &sink, scope, getNamePool(), SourceLanguage::Slang);
}
@@ -960,7 +952,7 @@ void FrontEndCompileRequest::parseTranslationUnit(
combinedPreprocessorDefinitions.Add(def.Key, def.Value);
auto module = translationUnit->getModule();
- RefPtr<ModuleDecl> translationUnitSyntax = new ModuleDecl();
+ RefPtr<ModuleDecl> translationUnitSyntax = linkage->getASTBuilder()->create<ModuleDecl>();
translationUnitSyntax->nameAndLoc.name = translationUnit->moduleName;
translationUnitSyntax->module = module;
module->setModuleDecl(translationUnitSyntax);
@@ -980,7 +972,7 @@ void FrontEndCompileRequest::parseTranslationUnit(
//
if( m_isStandardLibraryCode )
{
- translationUnitSyntax->modifiers.first = new FromStdLibModifier();
+ translationUnitSyntax->modifiers.first = linkage->getASTBuilder()->create<FromStdLibModifier>();
}
for (auto sourceFile : translationUnit->getSourceFiles())
@@ -994,6 +986,7 @@ void FrontEndCompileRequest::parseTranslationUnit(
module);
parseSourceFile(
+ linkage->getASTBuilder(),
translationUnit,
tokens,
getSink(),
@@ -1062,7 +1055,7 @@ void FrontEndCompileRequest::generateIR()
// * it can generate diagnostics
/// Generate IR for translation unit
- RefPtr<IRModule> irModule(generateIRForTranslationUnit(translationUnit));
+ RefPtr<IRModule> irModule(generateIRForTranslationUnit(getLinkage()->getASTBuilder(), translationUnit));
if (verifyDebugSerialization)
{
@@ -1212,7 +1205,8 @@ EndToEndCompileRequest::EndToEndCompileRequest(
: m_session(session)
, m_sink(nullptr)
{
- m_linkage = new Linkage(session);
+ RefPtr<ASTBuilder> astBuilder(new ASTBuilder(session->m_sharedASTBuilder));
+ m_linkage = new Linkage(session, astBuilder);
init();
}
@@ -1534,7 +1528,7 @@ void Linkage::loadParsedModule(
// If we didn't run into any errors, then try to generate
// IR code for the imported module.
SLANG_ASSERT(errorCountAfter == 0);
- loadedModule->setIRModule(generateIRForTranslationUnit(translationUnit));
+ loadedModule->setIRModule(generateIRForTranslationUnit(getASTBuilder(), translationUnit));
}
loadedModulesList.add(loadedModule);
}
@@ -2337,7 +2331,7 @@ SpecializedComponentType::SpecializedComponentType(
if(specializationInfo)
funcDeclRef = specializationInfo->specializedFuncDeclRef;
- (*mangledEntryPointNames).add(getMangledName(funcDeclRef));
+ (*mangledEntryPointNames).add(getMangledName(m_astBuilder, funcDeclRef));
}
void visitModule(Module*, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE
@@ -2346,12 +2340,18 @@ SpecializedComponentType::SpecializedComponentType(
{ visitChildren(composite, specializationInfo); }
void visitSpecialized(SpecializedComponentType* specialized) SLANG_OVERRIDE
{ visitChildren(specialized); }
+
+ EntryPointMangledNameCollector(ASTBuilder* astBuilder):
+ m_astBuilder(astBuilder)
+ {
+ }
+ ASTBuilder* m_astBuilder;
};
// With the visitor defined, we apply it to ourself to compute
// and collect the mangled entry point names.
//
- EntryPointMangledNameCollector collector;
+ EntryPointMangledNameCollector collector(getLinkage()->getASTBuilder());
collector.mangledEntryPointNames = &m_entryPointMangledNames;
collector.visitSpecialized(this);
}
@@ -2605,19 +2605,8 @@ void Session::addBuiltinSource(
Session::~Session()
{
- // free all built-in types first
- errorType = nullptr;
- initializerListType = nullptr;
- overloadedType = nullptr;
- irBasicBlockType = nullptr;
- constExprRate = nullptr;
-
destroyTypeCheckingCache();
- for (Index i = 0; i < SLANG_COUNT_OF(builtinTypes); ++i)
- {
- builtinTypes[i].setNull();
- }
// destroy modules next
loadedModuleCode = decltype(loadedModuleCode)();
}