diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-07-17 10:26:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-17 10:26:37 -0400 |
| commit | 749634a2a6e03acf435c39f78b933a01b90a7440 (patch) | |
| tree | 950203d3fc29610428b0ca03eb756911b9b11f47 /source/slang/slang-options.cpp | |
| parent | f52f5cd4a7b5b71617b949fc62a78abe8c4822b3 (diff) | |
Slang -> C++ -> SharedLibrary -> Test (#999)
* WIP: Adding support for C/C++ compilation to slang API.
* Removed BackEndType in test harness -> use SlangPassThrough to identify backends
Only require stage for targets that require it.
Detection of all different backends.
* Windows/Unix create temporary filename.
* WIP: Output CPU binaries.
* Added a pass-through c/c++ test.
* Compile C++/C and store in temporary file.
* Read the binary back into memory.
* Set debug info and optimization flags for C/C++.
Make the CPPCompiler debug/optimization levels match slangs.
* Handling of include paths and math precision.
* Dumping c++/c source and exe/shared library.
* Put hex dump into own util.
* End to end pass through c compilation test.
* WIP: Simple execute test working on Linux/Unix.
* Fix typo on linux.
* WIP: To compile slang to cpp shared library. Report backend compiler errors.
* Compiles slang -> cpp and loads as shared library.
* Fix problem on c-cross-compile test because prelude is now included with <> quotes.
* Run slang generated cpp code - using hard coded data.
* Added cpp-execute-simple, and test output.
* Fix warning that broke win32 build.
* Fix compilation problem on osx.
Diffstat (limited to 'source/slang/slang-options.cpp')
| -rw-r--r-- | source/slang/slang-options.cpp | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 4b3a9f8f0..81fb468eb 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -36,6 +36,26 @@ SlangResult tryReadCommandLineArgument(DiagnosticSink* sink, char const* option, return SLANG_OK; } +#define SLANG_PASS_THROUGH_TYPES(x) \ + x(none, NONE) \ + x(fxc, FXC) \ + x(dxc, DXC) \ + x(glslang, GLSLANG) \ + x(vs, VISUAL_STUDIO) \ + x(visualstudio, VISUAL_STUDIO) \ + x(clang, CLANG) \ + x(gcc, GCC) \ + x(c, GENERIC_C_CPP) \ + x(cpp, GENERIC_C_CPP) + +static SlangResult _parsePassThrough(const UnownedStringSlice& name, SlangPassThrough& outPassThrough) +{ +#define SLANG_PASS_THROUGH_TYPE_CHECK(x, y) \ + if (name == #x) { outPassThrough = SLANG_PASS_THROUGH_##y; return SLANG_OK; } + SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_CHECK) + return SLANG_FAIL; +} + struct OptionsParser { SlangSession* session = nullptr; @@ -278,6 +298,9 @@ struct OptionsParser { ".tesc", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_HULL }, { ".tese", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_DOMAIN }, { ".comp", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_COMPUTE }, + + { ".c", SLANG_SOURCE_LANGUAGE_C, SLANG_STAGE_NONE }, + { ".cpp", SLANG_SOURCE_LANGUAGE_CPP, SLANG_STAGE_NONE }, }; for (int i = 0; i < SLANG_COUNT_OF(entries); ++i) @@ -360,8 +383,12 @@ struct OptionsParser CASE(".spv", SPIRV); CASE(".spv.asm", SPIRV_ASM); - CASE(".c", C_SOURCE); - CASE(".cpp", CPP_SOURCE); + CASE(".c", C_SOURCE); + CASE(".cpp", CPP_SOURCE); + + CASE(".exe", EXECUTABLE); + CASE(".dll", SHARED_LIBRARY); + CASE(".so", SHARED_LIBRARY); #undef CASE @@ -422,6 +449,23 @@ struct OptionsParser rawTarget->floatingPointMode = mode; } + static bool _passThroughRequiresStage(PassThroughMode passThrough) + { + switch (passThrough) + { + case PassThroughMode::Glslang: + case PassThroughMode::Dxc: + case PassThroughMode::Fxc: + { + return true; + } + default: + { + return false; + } + } + } + SlangResult parse( int argc, char const* const* argv) @@ -561,18 +605,13 @@ struct OptionsParser SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name)); SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE; - if (name == "fxc") { passThrough = SLANG_PASS_THROUGH_FXC; } - else if (name == "dxc") { passThrough = SLANG_PASS_THROUGH_DXC; } - else if (name == "glslang") { passThrough = SLANG_PASS_THROUGH_GLSLANG; } - else + if (SLANG_FAILED(_parsePassThrough(name.getUnownedSlice(), passThrough))) { sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, name); return SLANG_FAIL; } - spSetPassThrough( - compileRequest, - passThrough); + spSetPassThrough(compileRequest, passThrough); } else if (argStr == "-dxc-path") { @@ -938,7 +977,7 @@ struct OptionsParser // because fxc/dxc/glslang don't have a facility for taking // a named entry point and pulling its stage from an attribute. // - if( requestImpl->passThrough != PassThroughMode::None ) + if(_passThroughRequiresStage(requestImpl->passThrough) ) { for( auto& rawEntryPoint : rawEntryPoints ) { |
