summaryrefslogtreecommitdiffstats
path: root/source/core/slang-cpp-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-07-17 10:26:37 -0400
committerGitHub <noreply@github.com>2019-07-17 10:26:37 -0400
commit749634a2a6e03acf435c39f78b933a01b90a7440 (patch)
tree950203d3fc29610428b0ca03eb756911b9b11f47 /source/core/slang-cpp-compiler.cpp
parentf52f5cd4a7b5b71617b949fc62a78abe8c4822b3 (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/core/slang-cpp-compiler.cpp')
-rw-r--r--source/core/slang-cpp-compiler.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/source/core/slang-cpp-compiler.cpp b/source/core/slang-cpp-compiler.cpp
index 0ed0a1ba8..54138ab27 100644
--- a/source/core/slang-cpp-compiler.cpp
+++ b/source/core/slang-cpp-compiler.cpp
@@ -19,6 +19,17 @@
namespace Slang
{
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompiler::Desc !!!!!!!!!!!!!!!!!!!!!!*/
+
+void CPPCompiler::Desc::appendAsText(StringBuilder& out) const
+{
+ out << getCompilerTypeAsText(type);
+ out << " ";
+ out << majorVersion;
+ out << ".";
+ out << minorVersion;
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompiler::OutputMessage !!!!!!!!!!!!!!!!!!!!!!*/
/* static */UnownedStringSlice CPPCompiler::OutputMessage::getTypeText(OutputMessage::Type type)
@@ -33,6 +44,21 @@ namespace Slang
}
}
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompiler !!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+/* static */UnownedStringSlice CPPCompiler::getCompilerTypeAsText(CompilerType type)
+{
+ switch (type)
+ {
+ default:
+ case CompilerType::Unknown: return UnownedStringSlice::fromLiteral("Unknown");
+ case CompilerType::VisualStudio:return UnownedStringSlice::fromLiteral("Visual Studio");
+ case CompilerType::GCC: return UnownedStringSlice::fromLiteral("GCC");
+ case CompilerType::Clang: return UnownedStringSlice::fromLiteral("Clang");
+ case CompilerType::SNC: return UnownedStringSlice::fromLiteral("SNC");
+ case CompilerType::GHS: return UnownedStringSlice::fromLiteral("GHS");
+ }
+}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompiler::Output !!!!!!!!!!!!!!!!!!!!!!*/
@@ -167,6 +193,11 @@ SlangResult GenericCPPCompiler::compile(const CompileOptions& options, Output& o
return m_parseOutputFunc(exeRes, outOutput);
}
+SlangResult GenericCPPCompiler::calcModuleFilePath(const CompileOptions& options, StringBuilder& outPath)
+{
+ return m_calcModuleFilePathFunc(options, outPath);
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompilerUtil !!!!!!!!!!!!!!!!!!!!!!*/
static CPPCompiler::Desc _calcCompiledWithDesc()
@@ -308,7 +339,7 @@ static void _addGCCFamilyCompiler(const String& exeName, CPPCompilerSet* compile
CPPCompiler::Desc desc;
if (SLANG_SUCCEEDED(GCCCompilerUtil::calcVersion(exeName, desc)))
{
- RefPtr<CPPCompiler> compiler(new GenericCPPCompiler(desc, exeName, &GCCCompilerUtil::calcArgs, &GCCCompilerUtil::parseOutput));
+ RefPtr<CPPCompiler> compiler(new GenericCPPCompiler(desc, exeName, &GCCCompilerUtil::calcArgs, &GCCCompilerUtil::parseOutput, GCCCompilerUtil::calcModuleFilePath));
compilerSet->addCompiler(compiler);
}
}
@@ -377,6 +408,19 @@ void CPPCompilerSet::getCompilers(List<CPPCompiler*>& outCompilers) const
outCompilers.addRange((CPPCompiler*const*)m_compilers.begin(), m_compilers.getCount());
}
+bool CPPCompilerSet::hasCompiler(CPPCompiler::CompilerType compilerType) const
+{
+ for (CPPCompiler* compiler : m_compilers)
+ {
+ const auto& desc = compiler->getDesc();
+ if (desc.type == compilerType)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
void CPPCompilerSet::addCompiler(CPPCompiler* compiler)
{
const Index index = _findIndex(compiler->getDesc());