summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-06-02 14:05:35 -0400
committerGitHub <noreply@github.com>2020-06-02 14:05:35 -0400
commitf87b6327879ce425531bc1d83f3053c36773d27e (patch)
tree189de0738ece2d935564cb5fc389a075a1f3194f /source
parent926a0c51071f6cf5718c77958cc801030ce9d404 (diff)
Make stdlib path just be the filename. (#1364)
* Made bad-operaor-call available on all targets. Fix the line filename to not inclue path, to avoid paths being absolute and therefores value be host environment dependent (causing tests to fail). * Disable on linux because theres still a problem on gcc x86 where the file path is different. * Fix to some typos in bad-operator-call.slang * Fix diagnostic for bad-operator-call.slang
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-stdlib.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index 1f59b1686..a310ba748 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -4,6 +4,8 @@
#include "slang-ir.h"
#include "slang-syntax.h"
+#include "../core/slang-string-util.h"
+
#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x
#define LINE_STRING STRINGIZE(__LINE__)
@@ -15,23 +17,13 @@ namespace Slang
if(stdlibPath.getLength() != 0)
return stdlibPath;
- StringBuilder pathBuilder;
- for( auto cc = __FILE__; *cc; ++cc )
- {
- switch( *cc )
- {
- case '\n':
- case '\t':
- case '\\':
- pathBuilder << "\\";
- ; // fall-thru
- default:
- pathBuilder << *cc;
- break;
- }
- }
- stdlibPath = pathBuilder.ProduceString();
+ // 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]);
return stdlibPath;
}
@@ -226,6 +218,13 @@ namespace Slang
{ kIROp_Leq, "<=", "__BuiltinArithmeticType", ARITHMETIC_MASK | BOOL_RESULT },
};
+ // Both the following functions use these macros.
+ // NOTE! They require a variable named path to emit the #line correctly if in source file.
+#define SLANG_RAW(TEXT) sb << TEXT;
+#define SLANG_SPLICE(EXPR) sb << (EXPR);
+
+#define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"" << path << "\"\n"
+
String Session::getCoreLibraryCode()
{
if (coreLibraryCode.getLength() > 0)
@@ -233,12 +232,7 @@ namespace Slang
StringBuilder sb;
- String path = getStdlibPath();
-
-#define SLANG_RAW(TEXT) sb << TEXT;
-#define SLANG_SPLICE(EXPR) sb << (EXPR);
-
-#define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"" << path << "\"\n"
+ const String path = getStdlibPath();
#include "core.meta.slang.h"
@@ -251,6 +245,8 @@ namespace Slang
if (hlslLibraryCode.getLength() > 0)
return hlslLibraryCode;
+ const String path = getStdlibPath();
+
StringBuilder sb;
#include "hlsl.meta.slang.h"