summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-06-08 17:26:33 -0400
committerGitHub <noreply@github.com>2023-06-08 17:26:33 -0400
commit3913091a021a8f4525f0050dfb83d1c2b8fc6f6b (patch)
tree32d7560aa9ca037db8c156776b83785cac7994f0 /source/slang
parentc492288b4778b19bd66ac31edb076add096e757d (diff)
Improvements around StringBlob (#2921)
* #include an absolute path didn't work - because paths were taken to always be relative. * Small fixes and improvements around reflection tool. * Make PrettyWriter printing a class. * Improvements around handling StringBlob and storing stdlib source in ISlangBlob. * Fix some issues with comments around StringBlob. * Default initialize StringBlob fields.
Diffstat (limited to 'source/slang')
-rwxr-xr-xsource/slang/slang-compiler.h25
-rw-r--r--source/slang/slang-stdlib.cpp75
-rw-r--r--source/slang/slang.cpp6
3 files changed, 49 insertions, 57 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 66454b2da..4e396e1f5 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -2988,18 +2988,19 @@ namespace Slang
// Generated code for stdlib, etc.
String stdlibPath;
- String coreLibraryCode;
- String slangLibraryCode;
- String hlslLibraryCode;
- String glslLibraryCode;
- String autodiffLibraryCode;
-
- String getStdlibPath();
- String getCoreLibraryCode();
- String getHLSLLibraryCode();
- String getAutodiffLibraryCode();
-
-
+
+ ComPtr<ISlangBlob> coreLibraryCode;
+ //ComPtr<ISlangBlob> slangLibraryCode;
+ ComPtr<ISlangBlob> hlslLibraryCode;
+ //ComPtr<ISlangBlob> glslLibraryCode;
+ ComPtr<ISlangBlob> autodiffLibraryCode;
+
+ String getStdlibPath();
+
+ ComPtr<ISlangBlob> getCoreLibraryCode();
+ ComPtr<ISlangBlob> getHLSLLibraryCode();
+ ComPtr<ISlangBlob> getAutodiffLibraryCode();
+
RefPtr<SharedASTBuilder> m_sharedASTBuilder;
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index a31c77985..3ef510990 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -14,16 +14,16 @@ namespace Slang
{
String Session::getStdlibPath()
{
- if(stdlibPath.getLength() != 0)
- return stdlibPath;
-
- // Make sure we have a line of text from __FILE__, that we'll extract the filename from
- List<UnownedStringSlice> lines;
- StringUtil::calcLines(UnownedStringSlice::fromLiteral(__FILE__), lines);
- SLANG_ASSERT(lines.getCount() > 0 && lines[0].getLength() > 0);
+ if(stdlibPath.getLength() == 0)
+ {
+ // Make sure we have a line of text from __FILE__, that we'll extract the filename from
+ List<UnownedStringSlice> lines;
+ StringUtil::calcLines(UnownedStringSlice::fromLiteral(__FILE__), lines);
+ SLANG_ASSERT(lines.getCount() > 0 && lines[0].getLength() > 0);
- // Make the path just the filename to remove issues around path being included on different targets
- stdlibPath = Path::getFileName(lines[0]);
+ // Make the path just the filename to remove issues around path being included on different targets
+ stdlibPath = Path::getFileName(lines[0]);
+ }
return stdlibPath;
}
@@ -263,54 +263,45 @@ namespace Slang
#define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"" << path << "\"\n"
- String Session::getCoreLibraryCode()
+ ComPtr<ISlangBlob> Session::getCoreLibraryCode()
{
#if !defined(SLANG_DISABLE_STDLIB_SOURCE)
- if (coreLibraryCode.getLength() > 0)
- return coreLibraryCode;
-
- StringBuilder sb;
-
- const String path = getStdlibPath();
-
- #include "core.meta.slang.h"
-
- coreLibraryCode = sb.produceString();
+ if (!coreLibraryCode)
+ {
+ StringBuilder sb;
+ const String path = getStdlibPath();
+ #include "core.meta.slang.h"
+ coreLibraryCode = StringBlob::moveCreate(sb);
+ }
#endif
return coreLibraryCode;
}
- String Session::getHLSLLibraryCode()
+ ComPtr<ISlangBlob> Session::getHLSLLibraryCode()
{
#if !defined(SLANG_DISABLE_STDLIB_SOURCE)
- if (hlslLibraryCode.getLength() > 0)
- return hlslLibraryCode;
-
- const String path = getStdlibPath();
-
- StringBuilder sb;
-
- #include "hlsl.meta.slang.h"
-
- hlslLibraryCode = sb.produceString();
+ if (!hlslLibraryCode)
+ {
+ const String path = getStdlibPath();
+ StringBuilder sb;
+ #include "hlsl.meta.slang.h"
+ hlslLibraryCode = StringBlob::moveCreate(sb);
+ }
#endif
return hlslLibraryCode;
}
- String Session::getAutodiffLibraryCode()
+ ComPtr<ISlangBlob> Session::getAutodiffLibraryCode()
{
#if !defined(SLANG_DISABLE_STDLIB_SOURCE)
- if (autodiffLibraryCode.getLength() > 0)
- return autodiffLibraryCode;
-
- const String path = getStdlibPath();
-
- StringBuilder sb;
-
- #include "diff.meta.slang.h"
-
- autodiffLibraryCode = sb.produceString();
+ if (!autodiffLibraryCode)
+ {
+ const String path = getStdlibPath();
+ StringBuilder sb;
+ #include "diff.meta.slang.h"
+ autodiffLibraryCode = StringBlob::moveCreate(sb);
+ }
#endif
return autodiffLibraryCode;
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index d651f0737..5e0064226 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -313,9 +313,9 @@ SlangResult Session::compileStdLib(slang::CompileStdLibFlags compileFlags)
}
// TODO(JS): Could make this return a SlangResult as opposed to exception
- addBuiltinSource(coreLanguageScope, "core", StringBlob::moveCreate(getCoreLibraryCode()));
- addBuiltinSource(hlslLanguageScope, "hlsl", StringBlob::moveCreate(getHLSLLibraryCode()));
- addBuiltinSource(autodiffLanguageScope, "diff", StringBlob::moveCreate(getAutodiffLibraryCode()));
+ addBuiltinSource(coreLanguageScope, "core", getCoreLibraryCode());
+ addBuiltinSource(hlslLanguageScope, "hlsl", getHLSLLibraryCode());
+ addBuiltinSource(autodiffLanguageScope, "diff", getAutodiffLibraryCode());
if (compileFlags & slang::CompileStdLibFlag::WriteDocumentation)
{