diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-10-25 11:24:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-25 11:24:16 -0400 |
| commit | 4f0415e338862ffec50c2d47eddea958255b504e (patch) | |
| tree | 084c8e25552e328ed14eafcf0431493f58f973e8 | |
| parent | 2700a89f8c80620f1d523563cc80ec0da39e9761 (diff) | |
Feature/premake linux (#689)
* Premake work in progress for linux.
* Added dump function.
* Remove examples on linux
Small warning fix.
* * Don't build render-test on linux
* Removed work around virtual destructor warning, and just used virtual dtor for simplicity
* Git ignore obj directories
* Fix premake working on windows.
* * Fix sprintf_s functions
* Make generates arg parsing more robust
* Added FloatIntUnion to avoid type punning/strong aliasing issues, and repeated union definitions.
* Work around problems building on linux with getClass claiming a strict aliasing issue.
* Fix for targetBlock appearing potentiall used unintialized to gcc.
* Linux slang link options -fPIC to make dll.
* Add -fPIC to build options on linux.
* Add -ldl for linux on slang.
* Fixes to try and get premake working with .so on linux.
* Make core compile with -fPIC
* Try to fix linux linking with --no-as-needed before -ldl
* Add rpath back.
* Remove render-gl from linux build.
* Re-add location for linux.
* Don't include <malloc.h> except on windows.
* Remove unused line to fix warning on osx.
* Remove ambiguity on OSX for operator <<.
* Fixing ambiguity with operator overloading and Int types for OSX.
* Fix ambiguity around UInt and operator
* Fix ambiguity of UInt conversion for OSX.
* Added UnambiguousInt and UnambiguousUInt to make it easier to work around OSX integer coercion for UInt/Int types.
33 files changed, 252 insertions, 150 deletions
diff --git a/.gitignore b/.gitignore index 0be132a45..ad99e1d70 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.sdf bin/ intermediate/ +obj/ # Files generated by test runner. # diff --git a/premake5.lua b/premake5.lua index 73c7f65e2..d1b33425e 100644 --- a/premake5.lua +++ b/premake5.lua @@ -36,11 +36,26 @@ -- Visual Studio terms). It sets up basic build settings that will -- apply across all projects. -- + +-- To output linux will output to linux +-- % premake5 --os=linux gmake +-- +-- % cd build.linux +-- % make config=release_x64 +-- or +-- % make config=debug_x64 +-- +-- From in the build directory you can use +-- % premake5 --file=../premake5.lua --os=linux gmake + workspace "slang" -- We will support debug/release configuration and x86/x64 builds. configurations { "Debug", "Release" } platforms { "x86", "x64" } + filter { "system:linux" } + location("build.linux") + -- The output binary directory will be derived from the OS -- and configuration options, e.g. `bin/windows-x64/debug/` targetdir "bin/%{cfg.system}-%{cfg.platform:lower()}/%{cfg.buildcfg:lower()}" @@ -67,6 +82,15 @@ workspace "slang" filter { "platforms:x86" } architecture "x86" + filter { "toolset:clang or gcc*" } + buildoptions { "-Wno-unused-parameter", "-Wno-type-limits", "-Wno-sign-compare", "-Wno-unused-variable", "-Wno-reorder", "-Wno-switch", "-Wno-return-type", "-Wno-unused-local-typedefs", "-Wno-parentheses", "-std=c++11", "-fvisibility=hidden", "-std=gnu++11" } + + filter { "toolset:gcc*"} + buildoptions { "-Wno-nonnull-compare", "-Wno-unused-but-set-variable", "-Wno-implicit-fallthrough" } + + filter { "toolset:clang" } + buildoptions { "-Wno-deprecated-register", "-Wno-tautological-compare"} + -- When compiling the debug configuration, we want to turn -- optimization off, make sure debug symbols are output, -- and add the same preprocessor definition that VS @@ -82,7 +106,33 @@ workspace "slang" filter { "configurations:release" } optimize "On" defines { "NDEBUG" } - + + filter { "system:linux" } + linkoptions{ "-Wl,-rpath,'$$ORIGIN',--no-as-needed", "-ldl"} + + +function dump(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. dump(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + +function dumpTable(o) + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. tostring(v) .. ',\n' + end + return s .. '} ' +end + -- -- We are now going to start defining the projects, where -- each project builds some binary artifact (an executable, @@ -272,22 +322,23 @@ function example(name) links { "slang", "core", "gfx" } end --- --- With all of these helper routines defined, we can now define the --- actual projects quite simply. For example, here is the entire --- declaration of the "Hello, World" example project: --- -example "hello-world" --- --- Note how we are calling our custom `example()` subroutine with --- the same syntax sugar that Premake usually advocates for their --- `project()` function. This allows us to treat `example` as --- a kind of specialized "subclass" of `project` --- - --- Let's go ahead and set up the projects for our other example now. -example "model-viewer" +if os.target() == "windows" then + -- + -- With all of these helper routines defined, we can now define the + -- actual projects quite simply. For example, here is the entire + -- declaration of the "Hello, World" example project: + -- + example "hello-world" + -- + -- Note how we are calling our custom `example()` subroutine with + -- the same syntax sugar that Premake usually advocates for their + -- `project()` function. This allows us to treat `example` as + -- a kind of specialized "subclass" of `project` + -- + -- Let's go ahead and set up the projects for our other example now. + example "model-viewer" +end -- Most of the other projects have more interesting configuration going -- on, so let's walk through them in order of increasing complexity. @@ -308,7 +359,11 @@ standardProject "core" -- warnings "Extra" flags { "FatalWarnings" } - + + -- We need the core library to be relocatable to be able to link with slang.so + filter { "system:linux" } + buildoptions{"-fPIC"} + -- -- `slang-generate` is a tool we use for source code generation on -- the compiler. It depends on the `core` library, so we need to @@ -369,19 +424,20 @@ tool "slang-eval-test" -- TODO: Fix that requirement. -- -tool "render-test" - uuid "96610759-07B9-4EEB-A974-5C634A2E742B" - includedirs { ".", "external", "source", "tools/gfx" } - links { "core", "slang", "gfx" } - filter { "system:windows" } - +if os.target() == "windows" then + tool "render-test" + uuid "96610759-07B9-4EEB-A974-5C634A2E742B" + includedirs { ".", "external", "source", "tools/gfx" } + links { "core", "slang", "gfx" } + systemversion "10.0.14393.0" -- For Windows targets, we want to copy d3dcompiler_47.dll, -- dxcompiler.dll, and dxil.dll from the Windows SDK redistributable -- directory into the output directory. postbuildcommands { '"$(SolutionDir)tools\\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/%{cfg.platform:lower()}/" "%{cfg.targetdir}/"'} - +end + -- -- `gfx` is a utility library for doing GPU rendering -- and compute, which is used by both our testing and exmaples. @@ -405,7 +461,8 @@ tool "gfx" -- directory into the output directory. postbuildcommands { '"$(SolutionDir)tools\\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/%{cfg.platform:lower()}/" "%{cfg.targetdir}/"'} - + filter { "system:not windows" } + removefiles { "tools/gfx/circular-resource-heap-d3d12.cpp", "tools/gfx/d3d-util.cpp", "tools/gfx/descriptor-heap-d3d12.cpp", "tools/gfx/render-d3d11.cpp", "tools/gfx/render-d3d12.cpp", "tools/gfx/render-gl.cpp", "tools/gfx/resource-d3d12.cpp", "tools/gfx/render-vk.cpp", "tools/gfx/vk-swap-chain.cpp", "tools/gfx/window.cpp" } -- -- The `slangc` command-line application is just a very thin wrapper @@ -464,6 +521,9 @@ standardProject "slang" -- dependson { "slang-generate" } + filter { "system:linux" } + buildoptions{"-fPIC"} + -- Next, we want to add a custom build rule for each of the -- files that makes up the standard library. Those are -- always named `*.meta.slang`, so we can select for them @@ -564,7 +624,8 @@ standardProject "slang-glslang" filter { "system:linux" } addSourceDir("external/glslang/glslang/OSDependent/Unix") - + buildoptions{"-fPIC", "-pthread"} + -- -- With glslang's build out of the way, we've now covered everything we have -- to build to get Slang and its tools/examples built. diff --git a/source/core/allocator.h b/source/core/allocator.h index 46550a054..3306d3780 100644 --- a/source/core/allocator.h +++ b/source/core/allocator.h @@ -2,6 +2,9 @@ #define CORE_LIB_ALLOCATOR_H #include <stdlib.h> +#ifdef _MSC_VER +# include <malloc.h> +#endif namespace Slang { @@ -9,6 +12,8 @@ namespace Slang { #ifdef _MSC_VER return _aligned_malloc(size, alignment); +#elif defined(__CYGWIN__) + return aligned_alloc(alignment, size); #else void * rs = 0; int succ = posix_memalign(&rs, alignment, size); diff --git a/source/core/common.h b/source/core/common.h index 17161ab14..5aa7b7737 100644 --- a/source/core/common.h +++ b/source/core/common.h @@ -38,9 +38,12 @@ namespace Slang } #ifdef _MSC_VER -#define SLANG_RETURN_NEVER __declspec(noreturn) +# define SLANG_RETURN_NEVER __declspec(noreturn) +//#elif SLANG_CLANG +//# define SLANG_RETURN_NEVER [[noreturn]] #else -#define SLANG_RETURN_NEVER /* empty */ +# define SLANG_RETURN_NEVER [[noreturn]] +//# define SLANG_RETURN_NEVER /* empty */ #endif #ifdef _MSC_VER diff --git a/source/core/secure-crt.h b/source/core/secure-crt.h index a76fb2679..52a0d4870 100644 --- a/source/core/secure-crt.h +++ b/source/core/secure-crt.h @@ -5,6 +5,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <strings.h> + #include <wchar.h> inline void memcpy_s(void *dest, size_t numberOfElements, const void * src, size_t count) @@ -30,16 +32,26 @@ inline size_t wcsnlen_s(const wchar_t * str, size_t /*numberofElements*/) return wcslen(str); } -inline size_t strnlen_s(const char * str, size_t numberofElements) +inline size_t strnlen_s(const char * str, size_t numberOfElements) { - return strnlen(str, numberofElements); +#if defined( __CYGWIN__ ) + const char* cur = str; + if (str) + { + const char*const end = str + numberOfElements; + while (*cur && cur < end) cur++; + } + return size_t(cur - str); +#else + return strnlen(str, numberOfElements); +#endif } inline int sprintf_s(char * buffer, size_t sizeOfBuffer, const char * format, ...) { va_list argptr; va_start(argptr, format); - int rs = snprintf(buffer, sizeOfBuffer, format, argptr); + int rs = vsnprintf(buffer, sizeOfBuffer, format, argptr); va_end(argptr); return rs; } @@ -48,7 +60,7 @@ inline int swprintf_s(wchar_t * buffer, size_t sizeOfBuffer, const wchar_t * for { va_list argptr; va_start(argptr, format); - int rs = swprintf(buffer, sizeOfBuffer, format, argptr); + int rs = vswprintf(buffer, sizeOfBuffer, format, argptr); va_end(argptr); return rs; } diff --git a/source/core/slang-cpu-defines.h b/source/core/slang-cpu-defines.h index dc76008b9..5ad1ecf88 100644 --- a/source/core/slang-cpu-defines.h +++ b/source/core/slang-cpu-defines.h @@ -54,6 +54,19 @@ #define SLANG_PTR_IS_64 (SLANG_PROCESSOR_ARM_64 | SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_POWER_PC_64) #define SLANG_PTR_IS_32 (SLANG_PTR_IS_64 ^ 1) +// TODO: This isn't great. The problem is UInt maps to size_t, and on some targets (like OSX) +// size_t is distinct from any other integral type. So that creates an ambiguity +// Really we want to modify the StringBuilder and elsewhere to handle the case when it is known it can't unambiguously coerce +namespace Slang { +#ifdef SLANG_PTR_IS_64 +typedef UInt64 UnambigousUInt; +typedef Int64 UnambiguousInt; +#else +typedef UInt32 UnambigousUInt; +typedef Int32 UnambiguousInt; +#endif +} // namespace Slang + // Processor features #if SLANG_PROCESSOR_FAMILY_X86 # define SLANG_LITTLE_ENDIAN 1 diff --git a/source/core/slang-math.h b/source/core/slang-math.h index 6d6b3e7a1..a245e2d2c 100644 --- a/source/core/slang-math.h +++ b/source/core/slang-math.h @@ -8,6 +8,17 @@ namespace Slang class Math { public: + // Use to fix type punning issues with strict aliasing + union FloatIntUnion + { + float fvalue; + int ivalue; + + inline static FloatIntUnion makeFromInt(int i) { FloatIntUnion cast; cast.ivalue = i; return cast; } + inline static FloatIntUnion makeFromFloat(float f) { FloatIntUnion cast; cast.fvalue = f; return cast; } + }; + + static const float Pi; template<typename T> static T Min(const T& v1, const T&v2) @@ -110,30 +121,19 @@ namespace Slang } */ }; - inline int FloatAsInt(float val) + inline int FloatAsInt(float val) { - union InterCast - { - float fvalue; - int ivalue; - } cast; - cast.fvalue = val; - return cast.ivalue; + return Math::FloatIntUnion::makeFromFloat(val).ivalue; } - inline float IntAsFloat(int val) + inline float IntAsFloat(int val) { - union InterCast - { - float fvalue; - int ivalue; - } cast; - cast.ivalue = val; - return cast.fvalue; + return Math::FloatIntUnion::makeFromInt(val).fvalue; } inline unsigned short FloatToHalf(float val) { - int x = *(int*)&val; + const auto x = FloatAsInt(val); + unsigned short bits = (x >> 16) & 0x8000; unsigned short m = (x >> 12) & 0x07ff; unsigned int e = (x >> 23) & 0xff; @@ -158,19 +158,9 @@ namespace Slang inline float HalfToFloat(unsigned short input) { - union InterCast - { - float fvalue; - int ivalue; - InterCast() = default; - InterCast(int ival) - { - ivalue = ival; - } - }; - static const InterCast magic = InterCast((127 + (127 - 15)) << 23); - static const InterCast was_infnan = InterCast((127 + 16) << 23); - InterCast o; + static const auto magic = Math::FloatIntUnion::makeFromInt((127 + (127 - 15)) << 23); + static const auto was_infnan = Math::FloatIntUnion::makeFromInt((127 + 16) << 23); + Math::FloatIntUnion o; o.ivalue = (input & 0x7fff) << 13; // exponent/mantissa bits o.fvalue *= magic.fvalue; // exponent adjust if (o.fvalue >= was_infnan.fvalue) // make sure Inf/NaN survive diff --git a/source/core/stream.cpp b/source/core/stream.cpp index b705b13a1..949ce718c 100644 --- a/source/core/stream.cpp +++ b/source/core/stream.cpp @@ -91,9 +91,9 @@ namespace Slang default: break; } - int shFlag; #ifdef _WIN32 - switch (share) + int shFlag = _SH_DENYRW; + switch (share) { case Slang::FileShare::None: shFlag = _SH_DENYRW; @@ -130,13 +130,13 @@ namespace Slang } Int64 FileStream::GetPosition() { -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) fpos_t pos; fgetpos(handle, &pos); return pos; #elif defined(__APPLE__) return ftell(handle); -#else +#else fpos64_t pos; fgetpos64(handle, &pos); return *(Int64*)(&pos); diff --git a/source/core/type-traits.h b/source/core/type-traits.h index 5a05538d3..804b4d3fe 100644 --- a/source/core/type-traits.h +++ b/source/core/type-traits.h @@ -37,8 +37,8 @@ namespace Slang template <typename B, typename D> struct IsConvertible { - static TraitResultYes Use(B) {}; - static TraitResultNo Use(...) {}; + static TraitResultYes Use(B) { return TraitResultYes(); }; + static TraitResultNo Use(...) { return TraitResultNo(); }; enum { Value = sizeof(Use(*(D*)(nullptr))) == sizeof(TraitResultYes) }; }; } diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 47713e6cc..278ba7b61 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -5283,7 +5283,6 @@ namespace Slang RefPtr<Type> bestType; if(auto basicType = type.As<BasicExpressionType>()) { - basicType->baseType; for(Int baseTypeFlavorIndex = 0; baseTypeFlavorIndex < Int(BaseType::CountOf); baseTypeFlavorIndex++) { // Don't consider `type`, since we already know it doesn't work. diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index b1e6e0fd6..0502c9bf6 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -80,19 +80,19 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) case BaseType::Double: sb << "\n , __BuiltinFloatingPointType\n"; sb << "\n , __BuiltinRealType\n"; - // fall through to: + ; // fall through to: case BaseType::Int8: case BaseType::Int16: case BaseType::Int: case BaseType::Int64: sb << "\n , __BuiltinSignedArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::UInt8: case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: sb << "\n , __BuiltinArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::Bool: sb << "\n , __BuiltinType\n"; break; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index f0d61fa12..97a2d1edd 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -80,19 +80,19 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) case BaseType::Double: sb << "\n , __BuiltinFloatingPointType\n"; sb << "\n , __BuiltinRealType\n"; - // fall through to: + ; // fall through to: case BaseType::Int8: case BaseType::Int16: case BaseType::Int: case BaseType::Int64: sb << "\n , __BuiltinSignedArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::UInt8: case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: sb << "\n , __BuiltinArithmeticType\n"; - // fall through to: + ; // fall through to: case BaseType::Bool: sb << "\n , __BuiltinType\n"; break; diff --git a/source/slang/default-file-system.h b/source/slang/default-file-system.h index 47644f5ad..7805dd81a 100644 --- a/source/slang/default-file-system.h +++ b/source/slang/default-file-system.h @@ -43,6 +43,7 @@ public: private: /// Make so not constructible DefaultFileSystem() {} + virtual ~DefaultFileSystem() {} ISlangUnknown* getInterface(const Guid& guid); @@ -88,6 +89,8 @@ public: m_fileSystem(fileSystem) { } + virtual ~WrapFileSystem() {} + protected: ISlangUnknown* getInterface(const Guid& guid); diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp index c4638f29a..7271c04d3 100644 --- a/source/slang/diagnostics.cpp +++ b/source/slang/diagnostics.cpp @@ -173,7 +173,7 @@ static void formatDiagnostic( sb << humaneLoc.pathInfo.foundPath; sb << "("; - sb << humaneLoc.line; + sb << Int32(humaneLoc.line); sb << "): "; sb << getSeverityName(diagnostic.severity); diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index c9e19dffc..9c7d61c51 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -2213,7 +2213,7 @@ struct EmitVisitor context->shared->uniqueNameCounters[key] = count+1; - sb.append(count); + sb.append(Int32(count)); return sb.ProduceString(); } @@ -2238,8 +2238,7 @@ struct EmitVisitor // for the instruction. StringBuilder sb; sb << "_S"; - sb << getID(inst); - + sb << Int32(getID(inst)); return sb.ProduceString(); } @@ -5000,7 +4999,7 @@ struct EmitVisitor String paramName; paramName.append("_"); - paramName.append(pp); + paramName.append(Int32(pp)); auto paramType = funcType->getParamType(pp); emitIRParamType(ctx, paramType, paramName); diff --git a/source/slang/ir-legalize-types.cpp b/source/slang/ir-legalize-types.cpp index 931ceb85a..b86c9f6e9 100644 --- a/source/slang/ir-legalize-types.cpp +++ b/source/slang/ir-legalize-types.cpp @@ -1201,7 +1201,7 @@ static LegalVal declareSimpleVar( if (mangledNameStr.Length() != 0) { mangledNameStr.append("L"); - mangledNameStr.append(globalNameInfo->counter++); + mangledNameStr.append(Int32(globalNameInfo->counter++)); globalVar->mangledName = context->session->getNameObj(mangledNameStr); } } diff --git a/source/slang/ir-restructure.cpp b/source/slang/ir-restructure.cpp index dc35a8aee..d8d3fe7c9 100644 --- a/source/slang/ir-restructure.cpp +++ b/source/slang/ir-restructure.cpp @@ -250,7 +250,7 @@ namespace Slang // information that can inform our control-flow restructuring pass. // SLANG_UNEXPECTED("unhandled terminator instruction opcode"); - // fall through to: + ; // fall through to: case kIROp_Unreachable: case kIROp_MissingReturn: case kIROp_ReturnVal: diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index f05aeabf6..6e14edc1f 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3,6 +3,8 @@ #include "ir-insts.h" #include "../core/basic.h" +#include "../core/slang-cpu-defines.h" + #include "mangle.h" namespace Slang @@ -2570,8 +2572,7 @@ namespace Slang IRDumpContext* context, UInt val) { - context->builder->append(val); - + context->builder->append(UnambigousUInt(val)); // fprintf(context->file, "%llu", (unsigned long long)val); } @@ -2771,10 +2772,6 @@ namespace Slang IRDumpContext* context, IRType* type); - static void dumpDeclRef( - IRDumpContext* context, - DeclRef<Decl> const& declRef); - static void dumpOperand( IRDumpContext* context, IRInst* inst) diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 1ee521e3b..6cce469ea 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -2691,7 +2691,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // We just need to look up the basic block that // corresponds to the break label for that statement, // and then emit an instruction to jump to it. - IRBlock* targetBlock; + IRBlock* targetBlock = nullptr; context->shared->breakLabels.TryGetValue(parentStmt, targetBlock); SLANG_ASSERT(targetBlock); getBuilder()->emitBreak(targetBlock); @@ -2710,7 +2710,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // We just need to look up the basic block that // corresponds to the continue label for that statement, // and then emit an instruction to jump to it. - IRBlock* targetBlock; + IRBlock* targetBlock = nullptr; context->shared->continueLabels.TryGetValue(parentStmt, targetBlock); SLANG_ASSERT(targetBlock); getBuilder()->emitContinue(targetBlock); diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp index c35ad1e14..c2645929f 100644 --- a/source/slang/mangle.cpp +++ b/source/slang/mangle.cpp @@ -4,6 +4,8 @@ #include "ir-insts.h" #include "syntax.h" +#include "../core/slang-cpu-defines.h" + namespace Slang { struct ManglingContext @@ -22,7 +24,7 @@ namespace Slang ManglingContext* context, UInt value) { - context->sb.append(value); + context->sb.append(UnambigousUInt(value)); } void emit( diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 4ebbdd191..9ccd7b962 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -993,7 +993,7 @@ namespace Slang nameToken.Content = nameToken.Content + ":"; break; } - + ; // fall-thru default: parser->sink->diagnose(nameToken.loc, Diagnostics::invalidOperator, nameToken); break; @@ -3689,12 +3689,14 @@ namespace Slang case TokenType::OpGeq: // Don't allow these ops inside a generic argument if (parser->genericDepth > 0) return Precedence::Invalid; + ; // fall-thru case TokenType::OpLeq: case TokenType::OpLess: return Precedence::RelationalComparison; case TokenType::OpRsh: // Don't allow this op inside a generic argument if (parser->genericDepth > 0) return Precedence::Invalid; + ; // fall-thru case TokenType::OpLsh: return Precedence::BitShift; case TokenType::OpAdd: diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index ca11b24e8..47aa0cfd4 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -992,7 +992,7 @@ static Token AdvanceToken(PreprocessorDirectiveContext* context) static Token PeekToken(PreprocessorDirectiveContext* context) { if (IsEndOfLine(context)) - context->preprocessor->endOfFileToken; + return context->preprocessor->endOfFileToken; return PeekToken(context->preprocessor); } @@ -2091,11 +2091,11 @@ static const PreprocessorDirective kDirectives[] = { "version", &handleGLSLVersionDirective, 0 }, { "extension", &handleGLSLExtensionDirective, 0 }, - { NULL, NULL }, + { nullptr, nullptr, 0 }, }; static const PreprocessorDirective kInvalidDirective = { - NULL, &HandleInvalidDirective, 0, + nullptr, &HandleInvalidDirective, 0, }; // Look up the directive with the given name. diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 5a4718af4..936c92fdd 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -24,6 +24,7 @@ namespace Slang case '\t': case '\\': pathBuilder << "\\"; + ; // fall-thru default: pathBuilder << *cc; break; diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h index 8f6b8f7cb..aba9b7bd9 100644 --- a/source/slang/source-loc.h +++ b/source/slang/source-loc.h @@ -60,12 +60,12 @@ struct PathInfo const String getMostUniquePath() const; // So simplify construction. In normal usage it's safer to use make methods over constructing directly. - static PathInfo makeUnknown() { return PathInfo { Type::Unknown, "unknown" }; } - static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste" }; } + static PathInfo makeUnknown() { return PathInfo { Type::Unknown, "unknown", String() }; } + static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste", String()}; } static PathInfo makeNormal(const String& foundPathIn, const String& canonicalPathIn) { SLANG_ASSERT(canonicalPathIn.Length() > 0 && foundPathIn.Length() > 0); return PathInfo { Type::Normal, foundPathIn, canonicalPathIn }; } - static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn }; } - static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string" }; } - static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line" }; } + static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn, String()}; } + static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string", String() }; } + static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line", String() }; } Type type; ///< The type of path String foundPath; ///< The path where the file was found (might contain relative elements) diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 019740a5e..7bd2afc12 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -330,8 +330,8 @@ namespace Slang SyntaxClassBase() {} - SyntaxClassBase(ClassInfo const* classInfo) - : classInfo(classInfo) + SyntaxClassBase(ClassInfo const* classInfoIn) + : classInfo(classInfoIn) {} void* createInstanceImpl() const @@ -375,11 +375,13 @@ namespace Slang return (T*)createInstanceImpl(); } + SyntaxClass(const ClassInfo* classInfoIn): + SyntaxClassBase(classInfoIn) + {} + static SyntaxClass<T> getClass() { - SyntaxClass<T> result; - result.classInfo = &SyntaxClass::Impl<T>::kClassInfo; - return result; + return SyntaxClass<T>(&SyntaxClassBase::Impl<T>::kClassInfo); } template<typename U> diff --git a/tools/gfx/model.cpp b/tools/gfx/model.cpp index 62e6ec1fd..ce176727b 100644 --- a/tools/gfx/model.cpp +++ b/tools/gfx/model.cpp @@ -195,6 +195,11 @@ RefPtr<TextureResource> loadTextureImage( return texture; } +static std::string makeString(const char* start, const char* end) +{ + return std::string(start, size_t(end - start)); +} + Result ModelLoader::load( char const* inputPath, void** outModel) @@ -208,7 +213,7 @@ Result ModelLoader::load( std::string baseDir; if( auto lastSlash = strrchr(inputPath, '/') ) { - baseDir = std::string(inputPath, lastSlash); + baseDir = makeString(inputPath, lastSlash); } std::string diagnostics; diff --git a/tools/gfx/model.h b/tools/gfx/model.h index b92dfda76..17b16510e 100644 --- a/tools/gfx/model.h +++ b/tools/gfx/model.h @@ -5,6 +5,7 @@ #include "vector-math.h" #include <vector> +#include <string> namespace gfx { diff --git a/tools/gfx/render.h b/tools/gfx/render.h index f59a5ef9f..bfbe0f82a 100644 --- a/tools/gfx/render.h +++ b/tools/gfx/render.h @@ -5,6 +5,8 @@ //#include "shader-input-layout.h" +#include <float.h> + #include "../../slang-com-helper.h" #include "../../source/core/smart-pointer.h" @@ -424,6 +426,10 @@ class TextureResource: public Resource Desc m_desc; }; +// Needed for building on cygwin with gcc +#undef Always +#undef None + enum class ComparisonFunc : uint8_t { Never = 0, diff --git a/tools/gfx/window.cpp b/tools/gfx/window.cpp index 8456e1ead..9e2195141 100644 --- a/tools/gfx/window.cpp +++ b/tools/gfx/window.cpp @@ -1,6 +1,5 @@ // window.cpp #include "window.h" -#pragma once #include <stdio.h> diff --git a/tools/gfx/window.h b/tools/gfx/window.h index e154acec3..e6f886f42 100644 --- a/tools/gfx/window.h +++ b/tools/gfx/window.h @@ -5,7 +5,7 @@ namespace gfx { -typedef struct Window Window; +struct Window; enum class KeyCode { @@ -94,7 +94,7 @@ int runApplication( #define GFX_CONSOLE_MAIN(APPLICATION_ENTRY) \ int main(int argc, char** argv) { \ - return gfx::runApplication(&(APPLIATION_ENTRY), argc, argv); \ + return gfx::runApplication(&(APPLICATION_ENTRY), argc, argv); \ } #ifdef _WIN32 diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp index 54aa3c429..ec0bc0844 100644 --- a/tools/render-test/options.cpp +++ b/tools/render-test/options.cpp @@ -147,7 +147,7 @@ SlangResult parseOptions(int* argc, char** argv) } // any arguments left over were positional arguments - argCount = (int)(writeCursor - argv); + argCount = (int)(writeCursor - (const char**)argv); argCursor = argv; argEnd = argCursor + argCount; diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp index 6b51f0e47..78097d1f1 100644 --- a/tools/slang-generate/main.cpp +++ b/tools/slang-generate/main.cpp @@ -625,28 +625,35 @@ void usage(char const* appName) fprintf(stderr, "usage: %s <input>\n", appName); } -char* readAllText(char const * fileName) +SlangResult readAllText(char const * fileName, String& stringOut) { FILE * f; fopen_s(&f, fileName, "rb"); if (!f) { - return ""; + stringOut = ""; + return SLANG_FAIL; } else { + stringOut = fseek(f, 0, SEEK_END); auto size = ftell(f); - char * buffer = new char[size + 1]; - memset(buffer, 0, size + 1); + + StringRepresentation* stringRep = StringRepresentation::createWithCapacityAndLength(size, size); + stringOut = String(stringRep); + + char * buffer = stringRep->getData(); + memset(buffer, 0, size); fseek(f, 0, SEEK_SET); fread(buffer, sizeof(char), size, f); fclose(f); - return buffer; + + return SLANG_OK; } } -void writeAllText(char const *srcFileName, char const* fileName, char* content) +void writeAllText(char const *srcFileName, char const* fileName, const char* content) { FILE * f = nullptr; fopen_s(&f, fileName, "wb"); @@ -751,34 +758,28 @@ List<SourceFile*> gSourceFiles; int main( int argc, - char** argv) + const char*const* argv) { // Parse command-line arguments. - char** argCursor = argv; - char** argEnd = argv + argc; - + List<const char*> inputPaths; char const* appName = "slang-generate"; - if( argCursor != argEnd ) - { - appName = *argCursor++; - } - - char** writeCursor = argv; - char const* const* inputPaths = writeCursor; - - while(argCursor != argEnd) - { - *writeCursor++ = *argCursor++; - } - size_t inputPathCount = writeCursor - inputPaths; - if(inputPathCount == 0) { - usage(appName); - exit(1); + const char*const* argCursor = argv; + const char*const* argEnd = argv + argc; + // Copy the app name + if( argCursor != argEnd ) + { + appName = *argCursor++; + } + // Copy the input paths + for (; argCursor != argEnd; ++argCursor) + { + inputPaths.Add(*argCursor); + } } - if( argCursor != argEnd ) + if(inputPaths.Count() == 0) { usage(appName); exit(1); @@ -786,9 +787,8 @@ int main( // Read each input file and process it according // to the type of treatment it requires. - for (size_t ii = 0; ii < inputPathCount; ++ii) + for (const char* inputPath: inputPaths) { - char const* inputPath = inputPaths[ii]; SourceFile* sourceFile = parseSourceFile(inputPath); if (sourceFile) { @@ -804,27 +804,28 @@ int main( auto node = sourceFile->node; // write output to a temporary file first - char outputPath[1024]; - sprintf_s(outputPath, "%s.temp.h", inputPath); + StringBuilder outputPath; + outputPath << inputPath << ".temp.h"; FILE* outputStream; - fopen_s(&outputStream, outputPath, "w"); + fopen_s(&outputStream, outputPath.Buffer(), "w"); emitTemplateNodes(outputStream, node); fclose(outputStream); // update final output only when content has changed - char outputPathFinal[1024]; - sprintf_s(outputPathFinal, "%s.h", inputPath); + StringBuilder outputPathFinal; + outputPathFinal << inputPath << ".h"; - char * allTextOld = readAllText(outputPathFinal); - char * allTextNew = readAllText(outputPath); - if (strcmp(allTextNew, allTextOld) != 0) + String allTextOld, allTextNew; + readAllText(outputPathFinal.Buffer(), allTextOld); + readAllText(outputPath.Buffer(), allTextNew); + if (allTextOld != allTextNew) { - writeAllText(inputPath, outputPathFinal, allTextNew); + writeAllText(inputPath, outputPathFinal.Buffer(), allTextNew.Buffer()); } - remove(outputPath); + remove(outputPath.Buffer()); } return 0; diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp index af9a9b9f0..8eda760d4 100644 --- a/tools/slang-test/main.cpp +++ b/tools/slang-test/main.cpp @@ -392,7 +392,7 @@ void skipToEndOfLine(char const** ioCursor) cursor++; } } - // fall through to: + ; // fall through to: case 0: *ioCursor = cursor; return; |
