diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-09-27 11:17:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-27 11:17:39 -0700 |
| commit | 74f2f47cb63b02638270beecd20acea1a0f5665e (patch) | |
| tree | af50d0355c7fccb4fb93fc1a0d45c66b5d07f1c9 /source/slang/compiler.cpp | |
| parent | b6cf0f4ae0f3f9d1f377d3f134dcf994676e68b4 (diff) | |
First attempt at a Linux build (#193)
* First attempt at a Linux build
- Fix up places where C++ idioms were written assuming lenient behavior of Microsoft's compiler
- Add a few more alternatives for platform-specific behavior where Windows was the only platform accounted for.
- Add a basic Makefile that can at least invoke our build, even if it isn't going good dependency tracking, etc.
- Build `libslang.so` and `slangc` that depends on it, using a relative `RPATH` to make the binary portable (I hope)
- Add an initial `.travis.yml` to see if we can trigger their build process.
* Fixup: const bug in `List::Sort`
I'm not clear why this gets picked up by the gcc *and* clang that Travis uses, but not the (newer) gcc I'm using on Ubuntu here, but I'm hoping it is just some missing `const` qualifiers.
* Fixup: reorder specialization of "class info"
Clang complains about things being specialized after being instantiated (implicilty), and I hope it is just the fact that I generate the class info for the roots of the hierarchy after the other cases. We'll see.
* Fixup: add `platform.cpp` to unified/lumped build
* Fixup: Windows uses `FreeLibrary`
and not `UnloadLibrary`
* Fixup: fix Windows project file to include new source file
This obviously points to the fact that we are going to need to be generating these files sooner or later.
Diffstat (limited to 'source/slang/compiler.cpp')
| -rw-r--r-- | source/slang/compiler.cpp | 117 |
1 files changed, 55 insertions, 62 deletions
diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index b8830c0b4..d7de5c42e 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -1,6 +1,7 @@ // Compiler.cpp : Defines the entry point for the console application. // #include "../core/basic.h" +#include "../core/platform.h" #include "../core/slang-io.h" #include "compiler.h" #include "lexer.h" @@ -12,21 +13,43 @@ #include "reflection.h" #include "emit.h" -// Utilities for pass-through modes -#include "../slang-glslang/slang-glslang.h" +// Enable calling through to `fxc` to +// generate code on Windows. +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include <Windows.h> + #undef WIN32_LEAN_AND_MEAN + #undef NOMINMAX + #include <d3dcompiler.h> + #ifndef SLANG_ENABLE_DXBC_SUPPORT + #define SLANG_ENABLE_DXBC_SUPPORT 1 + #endif +#endif +// +// Otherwise, don't enable DXBC by default: +#ifndef SLANG_ENABLE_DXBC_SUPPORT + #define SLANG_ENABLE_DXBC_SUPPORT 0 +#endif +// Enable calling through to `glslang` on +// all platforms. +#ifndef SLANG_ENABLE_GLSLANG_SUPPORT + #define SLANG_ENABLE_GLSLANG_SUPPORT 1 +#endif -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include <Windows.h> -#undef WIN32_LEAN_AND_MEAN -#undef NOMINMAX -#include <d3dcompiler.h> +#if SLANG_ENABLE_GLSLANG_SUPPORT +#include "../slang-glslang/slang-glslang.h" #endif -#include <io.h> +// Includes to allow us to control console +// output when writing assembly dumps. #include <fcntl.h> +#ifdef _WIN32 +#include <io.h> +#else +#include <unistd.h> +#endif #ifdef _MSC_VER #pragma warning(disable: 4996) @@ -189,7 +212,7 @@ namespace Slang } } -#ifdef _WIN32 +#if SLANG_ENABLE_DXBC_SUPPORT HMODULE loadD3DCompilerDLL(CompileRequest* request) { char const* libraryName = "d3dcompiler_47"; @@ -264,28 +287,6 @@ namespace Slang return data; } -#if 0 - List<uint8_t> EmitDXBytecode( - ExtraContext& context) - { - if(context.getTranslationUnitOptions().entryPoints.Count() != 1) - { - if(context.getTranslationUnitOptions().entryPoints.Count() == 0) - { - // TODO(tfoley): need to write diagnostics into this whole thing... - fprintf(stderr, "no entry point specified\n"); - } - else - { - fprintf(stderr, "multiple entry points specified\n"); - } - return List<uint8_t>(); - } - - return EmitDXBytecodeForEntryPoint(context, context.getTranslationUnitOptions().entryPoints[0]); - } -#endif - String dissassembleDXBC( CompileRequest* compileRequest, void const* data, @@ -345,32 +346,16 @@ namespace Slang return result; } - -#if 0 - String EmitDXBytecodeAssembly( - ExtraContext& context) - { - if(context.getTranslationUnitOptions().entryPoints.Count() == 0) - { - // TODO(tfoley): need to write diagnostics into this whole thing... - fprintf(stderr, "no entry point specified\n"); - return ""; - } - - StringBuilder sb; - for (auto entryPoint : context.getTranslationUnitOptions().entryPoints) - { - sb << EmitDXBytecodeAssemblyForEntryPoint(context, entryPoint); - } - return sb.ProduceString(); - } #endif - HMODULE loadGLSLCompilerDLL(CompileRequest* request) +#if SLANG_ENABLE_GLSLANG_SUPPORT + + SharedLibrary loadGLSLCompilerDLL(CompileRequest* request) { char const* libraryName = "slang-glslang"; // TODO(tfoley): let user specify version of glslang DLL to use. - HMODULE glslCompiler = LoadLibraryA(libraryName); + + SharedLibrary glslCompiler = SharedLibrary::load(libraryName); if (!glslCompiler) { request->mSink.diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libraryName); @@ -378,9 +363,9 @@ namespace Slang return glslCompiler; } - HMODULE getGLSLCompilerDLL(CompileRequest* request) + SharedLibrary getGLSLCompilerDLL(CompileRequest* request) { - static HMODULE glslCompiler = loadGLSLCompilerDLL(request); + static SharedLibrary glslCompiler = loadGLSLCompilerDLL(request); return glslCompiler; } @@ -393,11 +378,11 @@ namespace Slang static glslang_CompileFunc glslang_compile = nullptr; if (!glslang_compile) { - HMODULE glslCompiler = getGLSLCompilerDLL(slangCompileRequest); + SharedLibrary glslCompiler = getGLSLCompilerDLL(slangCompileRequest); if (!glslCompiler) return 1; - glslang_compile = (glslang_CompileFunc)GetProcAddress(glslCompiler, "glslang_compile"); + glslang_compile = (glslang_CompileFunc) glslCompiler.findFuncByName("glslang_compile"); if (!glslang_compile) return 1; } @@ -532,6 +517,7 @@ namespace Slang } break; +#if SLANG_ENABLE_DXBC_SUPPORT case CodeGenTarget::DXBytecode: { List<uint8_t> code = EmitDXBytecodeForEntryPoint(entryPoint); @@ -547,6 +533,7 @@ namespace Slang result = CompileResult(code); } break; +#endif case CodeGenTarget::SPIRV: { @@ -712,6 +699,7 @@ namespace Slang switch (compileRequest->Target) { + #if SLANG_ENABLE_DXBC_SUPPORT case CodeGenTarget::DXBytecode: { String assembly = dissassembleDXBC(compileRequest, @@ -720,6 +708,7 @@ namespace Slang writeOutputToConsole(compileRequest, assembly); } break; + #endif case CodeGenTarget::SPIRV: { @@ -738,7 +727,9 @@ namespace Slang else { // Redirecting stdout to a file, so do the usual thing + #ifdef _WIN32 _setmode(stdoutFileDesc, _O_BINARY); + #endif writeOutputFile( compileRequest, stdout, @@ -955,10 +946,6 @@ namespace Slang dumpIntermediateText(compileRequest, data, size, ".spv.asm"); break; - case CodeGenTarget::DXBytecodeAssembly: - dumpIntermediateText(compileRequest, data, size, ".dxbc.asm"); - break; - case CodeGenTarget::SlangIRAssembly: dumpIntermediateText(compileRequest, data, size, ".slang-ir.asm"); break; @@ -971,6 +958,11 @@ namespace Slang } break; + #if SLANG_ENABLE_DXBC_SUPPORT + case CodeGenTarget::DXBytecodeAssembly: + dumpIntermediateText(compileRequest, data, size, ".dxbc.asm"); + break; + case CodeGenTarget::DXBytecode: dumpIntermediateBinary(compileRequest, data, size, ".dxbc"); { @@ -978,6 +970,7 @@ namespace Slang dumpIntermediateText(compileRequest, dxbcAssembly.begin(), dxbcAssembly.Length(), ".dxbc.asm"); } break; + #endif case CodeGenTarget::SlangIR: dumpIntermediateBinary(compileRequest, data, size, ".slang-ir"); |
