From 749634a2a6e03acf435c39f78b933a01b90a7440 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 17 Jul 2019 10:26:37 -0400 Subject: 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. --- source/core/slang-visual-studio-compiler-util.cpp | 91 ++++++++++++++++++++--- 1 file changed, 80 insertions(+), 11 deletions(-) (limited to 'source/core/slang-visual-studio-compiler-util.cpp') diff --git a/source/core/slang-visual-studio-compiler-util.cpp b/source/core/slang-visual-studio-compiler-util.cpp index 20d655e78..765edc349 100644 --- a/source/core/slang-visual-studio-compiler-util.cpp +++ b/source/core/slang-visual-studio-compiler-util.cpp @@ -10,6 +10,33 @@ namespace Slang { +/* static */ SlangResult VisualStudioCompilerUtil::calcModuleFilePath(const CompileOptions& options, StringBuilder& outPath) +{ + outPath.Clear(); + + switch (options.targetType) + { + case TargetType::SharedLibrary: + { + outPath << options.modulePath << ".dll"; + return SLANG_OK; + } + case TargetType::Executable: + { + outPath << options.modulePath << ".exe"; + return SLANG_OK; + } + case TargetType::Object: + { + outPath << options.modulePath << ".obj"; + return SLANG_OK; + } + default: break; + } + + return SLANG_FAIL; +} + /* static */void VisualStudioCompilerUtil::calcArgs(const CompileOptions& options, CommandLine& cmdLine) { // https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=vs-2019 @@ -30,30 +57,72 @@ namespace Slang } } + switch (options.debugInfoType) + { + default: + { + // Multithreaded statically linked runtime library + cmdLine.addArg("/MD"); + break; + } + case DebugInfoType::Maximal: + { + // Multithreaded statically linked *debug* runtime library + cmdLine.addArg("/MDd"); + break; + } + } + + // /Fd - followed by name of the pdb file + if (options.debugInfoType != DebugInfoType::None) + { + cmdLine.addPrefixPathArg("/Fd", options.modulePath, ".pdb"); + } + switch (options.optimizationLevel) { - case OptimizationLevel::Debug: + case OptimizationLevel::None: { // No optimization - cmdLine.addArg("/Od"); - - cmdLine.addArg("/MDd"); + cmdLine.addArg("/Od"); + break; + } + case OptimizationLevel::Default: + { break; } - case OptimizationLevel::Normal: + case OptimizationLevel::High: { cmdLine.addArg("/O2"); - // Multithreaded DLL - cmdLine.addArg("/MD"); + break; + } + case OptimizationLevel::Maximal: + { + cmdLine.addArg("/Ox"); break; } default: break; } - // /Fd - followed by name of the pdb file - if (options.debugInfoType != DebugInfoType::None) + switch (options.floatingPointMode) { - cmdLine.addPrefixPathArg("/Fd", options.modulePath, ".pdb"); + case FloatingPointMode::Default: break; + case FloatingPointMode::Precise: + { + // precise is default behavior, VS also has 'strict' + // + // ```/fp:strict has behavior similar to /fp:precise, that is, the compiler preserves the source ordering and rounding properties of floating-point code when + // it generates and optimizes object code for the target machine, and observes the standard when handling special values. In addition, the program may safely + // access or modify the floating-point environment at runtime.``` + + cmdLine.addArg("/fp:precise"); + break; + } + case FloatingPointMode::Fast: + { + cmdLine.addArg("/fp:fast"); + break; + } } switch (options.targetType) @@ -61,7 +130,7 @@ namespace Slang case TargetType::SharedLibrary: { // Create dynamic link library - if (options.optimizationLevel == OptimizationLevel::Debug) + if (options.debugInfoType == DebugInfoType::None) { cmdLine.addArg("/LDd"); } -- cgit v1.2.3