summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp769
1 files changed, 334 insertions, 435 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index d86825766..37d72cadc 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -79,66 +79,50 @@ public:
ExpressionType::Finalize();
}
- CompileUnit createPredefUnit()
- {
- CompileUnit translationUnit;
-
-
- RefPtr<ProgramSyntaxNode> translationUnitSyntax = new ProgramSyntaxNode();
-
- TranslationUnitOptions translationUnitOptions;
- translationUnit.options = translationUnitOptions;
- translationUnit.SyntaxNode = translationUnitSyntax;
-
- return translationUnit;
- }
-
void addBuiltinSource(
RefPtr<Scope> const& scope,
String const& path,
String const& source);
};
-struct CompileRequest
+struct IncludeHandlerImpl : IncludeHandler
{
- // Pointer to parent session
- Session* mSession;
-
- // Input options
- CompileOptions Options;
-
- // Output stuff
- DiagnosticSink mSink;
- String mDiagnosticOutput;
-
- RefPtr<CollectionOfTranslationUnits> mCollectionOfTranslationUnits;
-
- RefPtr<ProgramLayout> mReflectionData;
+ CompileRequest* request;
- CompileResult mResult;
+ virtual IncludeResult TryToFindIncludeFile(
+ String const& pathToInclude,
+ String const& pathIncludedFrom,
+ String* outFoundPath,
+ String* outFoundSource) override
+ {
+ String path = Path::Combine(Path::GetDirectoryName(pathIncludedFrom), pathToInclude);
+ if (File::Exists(path))
+ {
+ *outFoundPath = path;
+ *outFoundSource = File::ReadAllText(path);
- List<String> mDependencyFilePaths;
+ request->mDependencyFilePaths.Add(path);
- CompileRequest(Session* session)
- : mSession(session)
- {}
+ // HACK(tfoley): We might have found the file in the same directory,
+ // but what if this is also inside an auto-import path?
+ for (auto & dir : request->searchDirectories)
+ {
+ // Only consider auto-import paths
+ if(dir.kind != SearchDirectory::Kind::AutoImport)
+ continue;
- ~CompileRequest()
- {}
+ String otherPath = Path::Combine(dir.path, pathToInclude);
- struct IncludeHandlerImpl : IncludeHandler
- {
- CompileRequest* request;
+ if(otherPath == path)
+ return IncludeResult::FoundAutoImportFile;
+ }
- List<SearchDirectory> searchDirs;
+ return IncludeResult::FoundIncludeFile;
+ }
- virtual IncludeResult TryToFindIncludeFile(
- String const& pathToInclude,
- String const& pathIncludedFrom,
- String* outFoundPath,
- String* outFoundSource) override
+ for (auto & dir : request->searchDirectories)
{
- String path = Path::Combine(Path::GetDirectoryName(pathIncludedFrom), pathToInclude);
+ path = Path::Combine(dir.path, pathToInclude);
if (File::Exists(path))
{
*outFoundPath = path;
@@ -146,464 +130,381 @@ struct CompileRequest
request->mDependencyFilePaths.Add(path);
- // HACK(tfoley): We might have found the file in the same directory,
- // but what if this is also inside an auto-import path?
- for (auto & dir : searchDirs)
- {
- // Only consider auto-import paths
- if(dir.kind != SearchDirectory::Kind::AutoImport)
- continue;
-
- String otherPath = Path::Combine(dir.path, pathToInclude);
-
- if(otherPath == path)
- return IncludeResult::FoundAutoImportFile;
- }
-
- return IncludeResult::FoundIncludeFile;
- }
-
- for (auto & dir : searchDirs)
- {
- path = Path::Combine(dir.path, pathToInclude);
- if (File::Exists(path))
+ switch( dir.kind )
{
- *outFoundPath = path;
- *outFoundSource = File::ReadAllText(path);
-
- request->mDependencyFilePaths.Add(path);
+ case SearchDirectory::Kind::Default:
+ return IncludeResult::FoundIncludeFile;
- switch( dir.kind )
- {
- case SearchDirectory::Kind::Default:
- return IncludeResult::FoundIncludeFile;
-
- case SearchDirectory::Kind::AutoImport:
- return IncludeResult::FoundAutoImportFile;
- }
+ case SearchDirectory::Kind::AutoImport:
+ return IncludeResult::FoundAutoImportFile;
}
}
- return IncludeResult::NotFound;
- }
- };
-
-
- CompileUnit parseTranslationUnit(
- TranslationUnitOptions const& translationUnitOptions,
- CompileOptions& options)
- {
- IncludeHandlerImpl includeHandler;
- includeHandler.request = this;
-
- CompileUnit translationUnit;
-
- RefPtr<Scope> languageScope;
- switch (translationUnitOptions.sourceLanguage)
- {
- case SourceLanguage::HLSL:
- languageScope = mSession->hlslLanguageScope;
- break;
-
- case SourceLanguage::GLSL:
- languageScope = mSession->glslLanguageScope;
- break;
-
- case SourceLanguage::Slang:
- default:
- languageScope = mSession->slangLanguageScope;
- break;
- }
-
- Dictionary<String, String> preprocessorDefinitions;
- for(auto& def : options.preprocessorDefinitions)
- preprocessorDefinitions.Add(def.Key, def.Value);
- for(auto& def : translationUnitOptions.preprocessorDefinitions)
- preprocessorDefinitions.Add(def.Key, def.Value);
-
- RefPtr<ProgramSyntaxNode> translationUnitSyntax = new ProgramSyntaxNode();
-
- for (auto sourceFile : translationUnitOptions.sourceFiles)
- {
- auto sourceFilePath = sourceFile->path;
-
- auto searchDirs = options.searchDirectories;
- searchDirs.Reverse();
- searchDirs.Add(SearchDirectory(Path::GetDirectoryName(sourceFilePath), SearchDirectory::Kind::Default));
- searchDirs.Reverse();
- includeHandler.searchDirs = searchDirs;
-
- String source = sourceFile->content;
-
- auto tokens = preprocessSource(
- source,
- sourceFilePath,
- mResult.GetErrorWriter(),
- &includeHandler,
- preprocessorDefinitions,
- translationUnitSyntax.Ptr(),
- this);
-
- parseSourceFile(
- translationUnitSyntax.Ptr(),
- options,
- translationUnitOptions,
- tokens,
- mResult.GetErrorWriter(),
- sourceFilePath,
- languageScope);
}
+ return IncludeResult::NotFound;
+ }
+};
- translationUnit.options = translationUnitOptions;
- translationUnit.SyntaxNode = translationUnitSyntax;
- return translationUnit;
- }
+void CompileRequest::parseTranslationUnit(
+ TranslationUnitRequest* translationUnit)
+{
+ IncludeHandlerImpl includeHandler;
+ includeHandler.request = this;
- CompileUnit parseTranslationUnit(
- TranslationUnitOptions const& translationUnitOptions)
+ RefPtr<Scope> languageScope;
+ switch (translationUnit->sourceLanguage)
{
- return parseTranslationUnit(translationUnitOptions, Options);
+ case SourceLanguage::HLSL:
+ languageScope = mSession->hlslLanguageScope;
+ break;
+
+ case SourceLanguage::GLSL:
+ languageScope = mSession->glslLanguageScope;
+ break;
+
+ case SourceLanguage::Slang:
+ default:
+ languageScope = mSession->slangLanguageScope;
+ break;
}
- void checkTranslationUnit(
- CompileUnit& translationUnit,
- RefPtr<SyntaxVisitor> visitor)
- {
- visitor->setSourceLanguage(translationUnit.options.sourceLanguage);
- translationUnit.SyntaxNode->Accept(visitor.Ptr());
- }
+ Dictionary<String, String> combinedPreprocessorDefinitions;
+ for(auto& def : preprocessorDefinitions)
+ combinedPreprocessorDefinitions.Add(def.Key, def.Value);
+ for(auto& def : translationUnit->preprocessorDefinitions)
+ combinedPreprocessorDefinitions.Add(def.Key, def.Value);
+
+ RefPtr<ProgramSyntaxNode> translationUnitSyntax = new ProgramSyntaxNode();
+ translationUnit->SyntaxNode = translationUnitSyntax;
- void checkTranslationUnit(
- CompileUnit& translationUnit,
- CompileOptions& options)
+ for (auto sourceFile : translationUnit->sourceFiles)
{
- RefPtr<SyntaxVisitor> visitor = CreateSemanticsVisitor(
- mResult.GetErrorWriter(),
- options,
- translationUnit.options,
+ auto sourceFilePath = sourceFile->path;
+ String source = sourceFile->content;
+
+ auto tokens = preprocessSource(
+ source,
+ sourceFilePath,
+ &mSink,
+ &includeHandler,
+ combinedPreprocessorDefinitions,
+ translationUnitSyntax.Ptr(),
this);
- checkTranslationUnit(translationUnit, visitor);
+ parseSourceFile(
+ translationUnit,
+ tokens,
+ &mSink,
+ sourceFilePath,
+ languageScope);
}
+}
+
+void CompileRequest::checkTranslationUnit(
+ TranslationUnitRequest* translationUnit)
+{
+ RefPtr<SyntaxVisitor> visitor = CreateSemanticsVisitor(
+ &mSink,
+ this,
+ translationUnit);
- void checkCollectionOfTranslationUnits(
- RefPtr<CollectionOfTranslationUnits> collectionOfTranslationUnits)
+ visitor->setSourceLanguage(translationUnit->sourceLanguage);
+ translationUnit->SyntaxNode->Accept(visitor.Ptr());
+}
+
+void CompileRequest::checkAllTranslationUnits()
+{
+ for( auto& translationUnit : translationUnits )
{
- for( auto& translationUnit : collectionOfTranslationUnits->translationUnits )
- {
- checkTranslationUnit(translationUnit, Options);
- }
+ checkTranslationUnit(translationUnit.Ptr());
}
+}
- void generateOutputForCollectionOfTranslationUnits(
- RefPtr<CollectionOfTranslationUnits> collectionOfTranslationUnits)
+int CompileRequest::executeActionsInner()
+{
+ // Do some cleanup on settings specified by user.
+ // In particular, we want to propagate flags from the overall request down to
+ // each translation unit.
+ for( auto& translationUnit : translationUnits )
{
- // Do binding generation, and then reflection (globally)
- // before we move on to any code-generation activites.
- GenerateParameterBindings(collectionOfTranslationUnits.Ptr());
-
-
- // HACK(tfoley): for right now I just want to pretty-print an AST
- // into another language, so the whole compiler back-end is just
- // getting in the way.
- //
- // I'm going to bypass it for now and see what I can do:
-
- ExtraContext extra;
- extra.options = &Options;
- extra.programLayout = collectionOfTranslationUnits->layout.Ptr();
- extra.compileResult = &mResult;
+ translationUnit->compileFlags |= compileFlags;
- generateOutput(extra, collectionOfTranslationUnits.Ptr());
+ // However, the "no checking" flag shouldn't be applied to
+ // any translation unit that is native Slang code.
+ if( translationUnit->sourceLanguage == SourceLanguage::Slang )
+ {
+ translationUnit->compileFlags &= ~SLANG_COMPILE_FLAG_NO_CHECKING;
+ }
}
- int executeCompilerDriverActions()
+#if 0
+ // If we are being asked to do pass-through, then we need to do that here...
+ if (passThrough != PassThroughMode::None)
{
- // Do some cleanup on settings specified by user.
- // In particular, we want to propagate flags from the overall request down to
- // each translation unit.
- for( auto& translationUnitOptions : Options.translationUnits )
+ for (auto& translationUnitOptions : Options.translationUnits)
{
- translationUnitOptions.compileFlags |= Options.compileFlags;
-
- // However, the "no checking" flag shouldn't be applied to
- // any translation unit that is native Slang code.
- if( translationUnitOptions.sourceLanguage == SourceLanguage::Slang )
+ switch (translationUnitOptions.sourceLanguage)
{
- translationUnitOptions.compileFlags &= SLANG_COMPILE_FLAG_NO_CHECKING;
+ // We can pass-through code written in a native shading language
+ case SourceLanguage::GLSL:
+ case SourceLanguage::HLSL:
+ break;
+
+ // All other translation units need to be skipped
+ default:
+ continue;
}
- }
- // If we are being asked to do pass-through, then we need to do that here...
- if (Options.passThrough != PassThroughMode::None)
- {
- for (auto& translationUnitOptions : Options.translationUnits)
- {
- switch (translationUnitOptions.sourceLanguage)
- {
- // We can pass-through code written in a native shading language
- case SourceLanguage::GLSL:
- case SourceLanguage::HLSL:
- break;
-
- // All other translation units need to be skipped
- default:
- continue;
- }
-
- auto sourceFile = translationUnitOptions.sourceFiles[0];
- auto sourceFilePath = sourceFile->path;
- String source = sourceFile->content;
+ auto sourceFile = translationUnitOptions.sourceFiles[0];
+ auto sourceFilePath = sourceFile->path;
+ String source = sourceFile->content;
- auto translationUnitResult = passThrough(
- source,
- sourceFilePath,
- Options,
- translationUnitOptions);
+ auto translationUnitResult = passThrough(
+ source,
+ sourceFilePath,
+ Options,
+ translationUnitOptions);
- mResult.translationUnits.Add(translationUnitResult);
- }
- return 0;
+ mResult.translationUnits.Add(translationUnitResult);
}
+ return 0;
+ }
+#endif
- // TODO: load the stdlib
-
- mCollectionOfTranslationUnits = new CollectionOfTranslationUnits();
-
+ // We only do parsing and semantic checking if we *aren't* doing
+ // a pass-through compilation.
+ //
+ // Note that we *do* perform output generation as normal in pass-through mode.
+ if( passThrough == PassThroughMode::None )
+ {
// Parse everything from the input files requested
- //
- // TODO: this may trigger the loading and/or compilation of additional modules.
- for (auto& translationUnitOptions : Options.translationUnits)
+ for (auto& translationUnit : translationUnits)
{
- auto translationUnit = parseTranslationUnit(translationUnitOptions);
- mCollectionOfTranslationUnits->translationUnits.Add(translationUnit);
+ parseTranslationUnit(translationUnit.Ptr());
}
- if (mResult.GetErrorCount() != 0)
+ if (mSink.GetErrorCount() != 0)
return 1;
// Perform semantic checking on the whole collection
- checkCollectionOfTranslationUnits(mCollectionOfTranslationUnits);
- if (mResult.GetErrorCount() != 0)
+ checkAllTranslationUnits();
+ if (mSink.GetErrorCount() != 0)
return 1;
- // Generate output code, in whatever format was requested
- generateOutputForCollectionOfTranslationUnits(mCollectionOfTranslationUnits);
- if (mResult.GetErrorCount() != 0)
+ // Now do shader parameter binding generation, which
+ // needs to be performed globally.
+ generateParameterBindings(this);
+ if (mSink.GetErrorCount() != 0)
return 1;
+ }
- // Extract the reflection layout information so that users
- // can easily query it.
- mReflectionData = mCollectionOfTranslationUnits->layout;
+ // Generate output code, in whatever format was requested
+ generateOutput(this);
+ if (mSink.GetErrorCount() != 0)
+ return 1;
- return 0;
- }
+ return 0;
+}
- // Act as expected of the API-based compiler
- int executeAPIActions()
- {
- mResult.mSink = &mSink;
+// Act as expected of the API-based compiler
+int CompileRequest::executeActions()
+{
+ int err = executeActionsInner();
- int err = executeCompilerDriverActions();
+ mDiagnosticOutput = mSink.outputBuffer.ProduceString();
- mDiagnosticOutput = mSink.outputBuffer.ProduceString();
+ return err;
+}
- if (mSink.GetErrorCount() != 0)
- return mSink.GetErrorCount();
+int CompileRequest::addTranslationUnit(SourceLanguage language, String const& name)
+{
+ int result = translationUnits.Count();
- return err;
- }
+ RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest();
+ translationUnit->compileRequest = this;
+ translationUnit->sourceLanguage = SourceLanguage(language);
- int addTranslationUnit(SourceLanguage language, String const& name)
- {
- int result = Options.translationUnits.Count();
+ translationUnits.Add(translationUnit);
- TranslationUnitOptions translationUnit;
- translationUnit.sourceLanguage = SourceLanguage(language);
+ return result;
+}
- Options.translationUnits.Add(translationUnit);
+void CompileRequest::addTranslationUnitSourceString(
+ int translationUnitIndex,
+ String const& path,
+ String const& source)
+{
+ RefPtr<SourceFile> sourceFile = new SourceFile();
+ sourceFile->path = path;
+ sourceFile->content = source;
- return result;
- }
+ translationUnits[translationUnitIndex]->sourceFiles.Add(sourceFile);
+}
- void addTranslationUnitSourceString(
- int translationUnitIndex,
- String const& path,
- String const& source)
+void CompileRequest::addTranslationUnitSourceFile(
+ int translationUnitIndex,
+ String const& path)
+{
+ String source;
+ try
{
- RefPtr<SourceFile> sourceFile = new SourceFile();
- sourceFile->path = path;
- sourceFile->content = source;
-
- Options.translationUnits[translationUnitIndex].sourceFiles.Add(sourceFile);
+ source = File::ReadAllText(path);
}
-
- void addTranslationUnitSourceFile(
- int translationUnitIndex,
- String const& path)
+ catch (...)
{
- String source;
- try
- {
- source = File::ReadAllText(path);
- }
- catch (...)
- {
- // Emit a diagnostic!
- mSink.diagnose(
- CodePosition(0, 0, 0, path),
- Diagnostics::cannotOpenFile,
- path);
- return;
- }
+ // Emit a diagnostic!
+ mSink.diagnose(
+ CodePosition(0, 0, 0, path),
+ Diagnostics::cannotOpenFile,
+ path);
+ return;
+ }
- addTranslationUnitSourceString(
- translationUnitIndex,
- path,
- source);
+ addTranslationUnitSourceString(
+ translationUnitIndex,
+ path,
+ source);
- mDependencyFilePaths.Add(path);
- }
+ mDependencyFilePaths.Add(path);
+}
- int addTranslationUnitEntryPoint(
- int translationUnitIndex,
- String const& name,
- Profile profile)
- {
- EntryPointOption entryPoint;
- entryPoint.name = name;
- entryPoint.profile = profile;
+int CompileRequest::addEntryPoint(
+ int translationUnitIndex,
+ String const& name,
+ Profile profile)
+{
+ RefPtr<EntryPointRequest> entryPoint = new EntryPointRequest();
+ entryPoint->compileRequest = this;
+ entryPoint->name = name;
+ entryPoint->profile = profile;
+ entryPoint->translationUnitIndex = translationUnitIndex;
- // TODO: realistically want this to be global across all TUs...
- int result = Options.translationUnits[translationUnitIndex].entryPoints.Count();
+ auto translationUnit = translationUnits[translationUnitIndex].Ptr();
+ translationUnit->entryPoints.Add(entryPoint);
- Options.translationUnits[translationUnitIndex].entryPoints.Add(entryPoint);
- return result;
- }
+ int result = entryPoints.Count();
+ entryPoints.Add(entryPoint);
+ return result;
+}
- Dictionary<String, RefPtr<ProgramSyntaxNode>> loadedModules;
+RefPtr<ProgramSyntaxNode> CompileRequest::loadModule(
+ String const& name,
+ String const& path,
+ String const& source,
+ CodePosition const& loc)
+{
+ RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest();
+ translationUnit->compileRequest = this;
- RefPtr<ProgramSyntaxNode> loadModule(
- String const& name,
- String const& path,
- String const& source,
- CodePosition const& loc)
- {
- // now we need to try compiling it, etc.
+ // We don't want to use the same options that the user specified
+ // for loading modules on-demand. In particular, we always want
+ // semantic checking to be enabled.
+ //
+ // TODO: decide which options, if any, should be inherited.
- // We don't want to use the same options that the user specified
- // for loading modules on-demand. In particular, we always want
- // semantic checking to be enabled.
- CompileOptions moduleOptions;
- moduleOptions.searchDirectories = Options.searchDirectories;
- moduleOptions.profile = Options.profile;
+ RefPtr<SourceFile> sourceFile = new SourceFile();
+ sourceFile->path = path;
+ sourceFile->content = source;
- RefPtr<SourceFile> sourceFile = new SourceFile();
- sourceFile->path = path;
- sourceFile->content = source;
+ translationUnit->sourceFiles.Add(sourceFile);
- TranslationUnitOptions translationUnitOptions;
- translationUnitOptions.sourceFiles.Add(sourceFile);
+ parseTranslationUnit(translationUnit.Ptr());
- CompileUnit translationUnit = parseTranslationUnit(translationUnitOptions, moduleOptions);
+ // TODO: handle errors
- // TODO: handle errors
+ checkTranslationUnit(translationUnit.Ptr());
- checkTranslationUnit(translationUnit, moduleOptions);
+ // Skip code generation
- // Skip code generation
+ //
- //
+ RefPtr<ProgramSyntaxNode> moduleDecl = translationUnit->SyntaxNode;
- RefPtr<ProgramSyntaxNode> moduleDecl = translationUnit.SyntaxNode;
+ loadedModules.Add(name, moduleDecl);
- loadedModules.Add(name, moduleDecl);
+ return moduleDecl;
- return moduleDecl;
+}
- }
+String CompileRequest::autoImportModule(
+ String const& path,
+ String const& source,
+ CodePosition const& loc)
+{
+ // TODO: may want to have some kind of canonicalization step here
+ String name = path;
- String autoImportModule(
- String const& path,
- String const& source,
- CodePosition const& loc)
- {
- // TODO: may want to have some kind of canonicalization step here
- String name = path;
+ // Have we already loaded a module matching this name?
+ if (loadedModules.TryGetValue(name))
+ return name;
+
+ loadModule(name, path, source, loc);
- // Have we already loaded a module matching this name?
- if (loadedModules.TryGetValue(name))
- return name;
+ return name;
+}
- loadModule(name, path, source, loc);
+RefPtr<ProgramSyntaxNode> CompileRequest::findOrImportModule(
+ String const& name,
+ CodePosition const& loc)
+{
+ // Have we already loaded a module matching this name?
+ // If so, return it.
+ RefPtr<ProgramSyntaxNode> moduleDecl;
+ if (loadedModules.TryGetValue(name, moduleDecl))
+ return moduleDecl;
- return name;
- }
+ // Derive a file name for the module, by taking the given
+ // identifier, replacing all occurences of `_` with `-`,
+ // and then appending `.slang`.
+ //
+ // For example, `foo_bar` becomes `foo-bar.slang`.
- RefPtr<ProgramSyntaxNode> findOrImportModule(
- String const& name,
- CodePosition const& loc)
+ StringBuilder sb;
+ for (auto c : name)
{
- // Have we already loaded a module matching this name?
- // If so, return it.
- RefPtr<ProgramSyntaxNode> moduleDecl;
- if (loadedModules.TryGetValue(name, moduleDecl))
- return moduleDecl;
-
- // Derive a file name for the module, by taking the given
- // identifier, replacing all occurences of `_` with `-`,
- // and then appending `.slang`.
- //
- // For example, `foo_bar` becomes `foo-bar.slang`.
+ if (c == '_')
+ c = '-';
- StringBuilder sb;
- for (auto c : name)
- {
- if (c == '_')
- c = '-';
-
- sb.Append(c);
- }
- sb.Append(".slang");
+ sb.Append(c);
+ }
+ sb.Append(".slang");
- String fileName = sb.ProduceString();
+ String fileName = sb.ProduceString();
- // Next, try to find the file of the given name,
- // using our ordinary include-handling logic.
+ // Next, try to find the file of the given name,
+ // using our ordinary include-handling logic.
- IncludeHandlerImpl includeHandler;
- includeHandler.request = this;
+ IncludeHandlerImpl includeHandler;
+ includeHandler.request = this;
- String pathIncludedFrom = loc.FileName;
+ String pathIncludedFrom = loc.FileName;
- String foundPath;
- String foundSource;
- IncludeResult includeResult = includeHandler.TryToFindIncludeFile(fileName, pathIncludedFrom, &foundPath, &foundSource);
- switch( includeResult )
+ String foundPath;
+ String foundSource;
+ IncludeResult includeResult = includeHandler.TryToFindIncludeFile(fileName, pathIncludedFrom, &foundPath, &foundSource);
+ switch( includeResult )
+ {
+ case IncludeResult::NotFound:
+ case IncludeResult::Error:
{
- case IncludeResult::NotFound:
- case IncludeResult::Error:
- {
- this->mSink.diagnose(loc, Diagnostics::cannotFindFile, fileName);
-
- loadedModules[name] = nullptr;
- return nullptr;
- }
- break;
+ this->mSink.diagnose(loc, Diagnostics::cannotFindFile, fileName);
- default:
- break;
+ loadedModules[name] = nullptr;
+ return nullptr;
}
+ break;
- // We've found a file that we can load for the given module, so
- // go ahead and perform the module-load action
- return loadModule(
- name,
- foundPath,
- foundSource,
- loc);
+ default:
+ break;
}
-};
+ // We've found a file that we can load for the given module, so
+ // go ahead and perform the module-load action
+ return loadModule(
+ name,
+ foundPath,
+ foundSource,
+ loc);
+}
RefPtr<ProgramSyntaxNode> findOrImportModule(
CompileRequest* request,
@@ -627,29 +528,29 @@ void Session::addBuiltinSource(
String const& path,
String const& source)
{
- CompileRequest compileRequest(this);
+ RefPtr<CompileRequest> compileRequest = new CompileRequest(this);
- auto translationUnitIndex = compileRequest.addTranslationUnit(SourceLanguage::Slang, path);
+ auto translationUnitIndex = compileRequest->addTranslationUnit(SourceLanguage::Slang, path);
- compileRequest.addTranslationUnitSourceString(
+ compileRequest->addTranslationUnitSourceString(
translationUnitIndex,
path,
source);
- int err = compileRequest.executeAPIActions();
+ int err = compileRequest->executeActions();
if (err)
{
- fprintf(stderr, "%s", compileRequest.mDiagnosticOutput.Buffer());
+ fprintf(stderr, "%s", compileRequest->mDiagnosticOutput.Buffer());
#ifdef _WIN32
- OutputDebugStringA(compileRequest.mDiagnosticOutput.Buffer());
+ OutputDebugStringA(compileRequest->mDiagnosticOutput.Buffer());
#endif
assert(!"error in stdlib");
}
// Extract the AST for the code we just parsed
- auto syntax = compileRequest.mCollectionOfTranslationUnits->translationUnits[translationUnitIndex].SyntaxNode;
+ auto syntax = compileRequest->translationUnits[translationUnitIndex]->SyntaxNode;
// HACK(tfoley): mark all declarations in the "stdlib" so
// that we can detect them later (e.g., so we don't emit them)
@@ -739,21 +640,21 @@ SLANG_API void spSetCompileFlags(
SlangCompileRequest* request,
SlangCompileFlags flags)
{
- REQ(request)->Options.compileFlags = flags;
+ REQ(request)->compileFlags = flags;
}
SLANG_API void spSetCodeGenTarget(
SlangCompileRequest* request,
int target)
{
- REQ(request)->Options.Target = (Slang::CodeGenTarget)target;
+ REQ(request)->Target = (Slang::CodeGenTarget)target;
}
SLANG_API void spSetPassThrough(
SlangCompileRequest* request,
SlangPassThrough passThrough)
{
- REQ(request)->Options.passThrough = Slang::PassThroughMode(passThrough);
+ REQ(request)->passThrough = Slang::PassThroughMode(passThrough);
}
SLANG_API void spSetDiagnosticCallback(
@@ -772,14 +673,14 @@ SLANG_API void spAddSearchPath(
SlangCompileRequest* request,
const char* path)
{
- REQ(request)->Options.searchDirectories.Add(Slang::SearchDirectory(path, Slang::SearchDirectory::Kind::Default));
+ REQ(request)->searchDirectories.Add(Slang::SearchDirectory(path, Slang::SearchDirectory::Kind::Default));
}
SLANG_API void spAddAutoImportPath(
SlangCompileRequest* request,
const char* path)
{
- REQ(request)->Options.searchDirectories.Add(Slang::SearchDirectory(path, Slang::SearchDirectory::Kind::AutoImport));
+ REQ(request)->searchDirectories.Add(Slang::SearchDirectory(path, Slang::SearchDirectory::Kind::AutoImport));
}
SLANG_API void spAddPreprocessorDefine(
@@ -787,7 +688,7 @@ SLANG_API void spAddPreprocessorDefine(
const char* key,
const char* value)
{
- REQ(request)->Options.preprocessorDefinitions[key] = value;
+ REQ(request)->preprocessorDefinitions[key] = value;
}
SLANG_API char const* spGetDiagnosticOutput(
@@ -820,7 +721,7 @@ SLANG_API void spTranslationUnit_addPreprocessorDefine(
{
auto req = REQ(request);
- req->Options.translationUnits[translationUnitIndex].preprocessorDefinitions[key] = value;
+ req->translationUnits[translationUnitIndex]->preprocessorDefinitions[key] = value;
}
@@ -833,7 +734,7 @@ SLANG_API void spAddTranslationUnitSourceFile(
auto req = REQ(request);
if(!path) return;
if(translationUnitIndex < 0) return;
- if(translationUnitIndex >= req->Options.translationUnits.Count()) return;
+ if(translationUnitIndex >= req->translationUnits.Count()) return;
req->addTranslationUnitSourceFile(
translationUnitIndex,
@@ -851,7 +752,7 @@ SLANG_API void spAddTranslationUnitSourceString(
auto req = REQ(request);
if(!source) return;
if(translationUnitIndex < 0) return;
- if(translationUnitIndex >= req->Options.translationUnits.Count()) return;
+ if(translationUnitIndex >= req->translationUnits.Count()) return;
if(!path) path = "";
@@ -869,7 +770,7 @@ SLANG_API SlangProfileID spFindProfile(
return Slang::Profile::LookUp(name).raw;
}
-SLANG_API int spAddTranslationUnitEntryPoint(
+SLANG_API int spAddEntryPoint(
SlangCompileRequest* request,
int translationUnitIndex,
char const* name,
@@ -879,10 +780,9 @@ SLANG_API int spAddTranslationUnitEntryPoint(
auto req = REQ(request);
if(!name) return -1;
if(translationUnitIndex < 0) return -1;
- if(translationUnitIndex >= req->Options.translationUnits.Count()) return -1;
+ if(translationUnitIndex >= req->translationUnits.Count()) return -1;
-
- return req->addTranslationUnitEntryPoint(
+ return req->addEntryPoint(
translationUnitIndex,
name,
Slang::Profile(Slang::Profile::RawVal(profile)));
@@ -895,7 +795,7 @@ SLANG_API int spCompile(
{
auto req = REQ(request);
- int anyErrors = req->executeAPIActions();
+ int anyErrors = req->executeActions();
return anyErrors;
}
@@ -925,7 +825,7 @@ spGetTranslationUnitCount(
SlangCompileRequest* request)
{
auto req = REQ(request);
- return req->mResult.translationUnits.Count();
+ return req->translationUnits.Count();
}
// Get the output code associated with a specific translation unit
@@ -934,16 +834,15 @@ SLANG_API char const* spGetTranslationUnitSource(
int translationUnitIndex)
{
auto req = REQ(request);
- return req->mResult.translationUnits[translationUnitIndex].outputSource.Buffer();
+ return req->translationUnits[translationUnitIndex]->result.outputSource.Buffer();
}
SLANG_API char const* spGetEntryPointSource(
SlangCompileRequest* request,
- int translationUnitIndex,
int entryPointIndex)
{
auto req = REQ(request);
- return req->mResult.translationUnits[translationUnitIndex].entryPoints[entryPointIndex].outputSource.Buffer();
+ return req->entryPoints[entryPointIndex]->result.outputSource.Buffer();
}
@@ -955,7 +854,7 @@ SLANG_API SlangReflection* spGetReflection(
if( !request ) return 0;
auto req = REQ(request);
- return (SlangReflection*) req->mReflectionData.Ptr();
+ return (SlangReflection*) req->layout.Ptr();
}