summaryrefslogtreecommitdiff
path: root/source/core/slang-cpp-compiler.h
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.h
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.h')
-rw-r--r--source/core/slang-cpp-compiler.h53
1 files changed, 41 insertions, 12 deletions
diff --git a/source/core/slang-cpp-compiler.h b/source/core/slang-cpp-compiler.h
index 60b534556..851975d72 100644
--- a/source/core/slang-cpp-compiler.h
+++ b/source/core/slang-cpp-compiler.h
@@ -40,6 +40,8 @@ public:
/// Get the version as a value
Int getVersionValue() const { return majorVersion * 100 + minorVersion; }
+ void appendAsText(StringBuilder& out) const;
+
/// Ctor
Desc(CompilerType inType = CompilerType::Unknown, Int inMajorVersion = 0, Int inMinorVersion = 0):type(inType), majorVersion(inMajorVersion), minorVersion(inMinorVersion) {}
@@ -50,16 +52,26 @@ public:
enum class OptimizationLevel
{
- Normal, ///< Normal optimization
- Debug, ///< General has no optimizations
+ None, ///< Don't optimize at all.
+ Default, ///< Default optimization level: balance code quality and compilation time.
+ High, ///< Optimize aggressively.
+ Maximal, ///< Include optimizations that may take a very long time, or may involve severe space-vs-speed tradeoffs
};
- enum DebugInfoType
+ enum class DebugInfoType
+ {
+ None, ///< Don't emit debug information at all.
+ Minimal, ///< Emit as little debug information as possible, while still supporting stack traces.
+ Standard, ///< Emit whatever is the standard level of debug information for each target.
+ Maximal, ///< Emit as much debug information as possible for each target.
+ };
+ enum class FloatingPointMode
{
- None, ///< Binary has no debug information
- Maximum, ///< Has maximum debug information
- Normal, ///< Has normal debug information
+ Default,
+ Fast,
+ Precise,
};
+
enum TargetType
{
Executable, ///< Produce an executable
@@ -84,10 +96,11 @@ public:
};
};
- OptimizationLevel optimizationLevel = OptimizationLevel::Debug;
- DebugInfoType debugInfoType = DebugInfoType::Normal;
+ OptimizationLevel optimizationLevel = OptimizationLevel::Default;
+ DebugInfoType debugInfoType = DebugInfoType::Standard;
TargetType targetType = TargetType::Executable;
SourceType sourceType = SourceType::CPP;
+ FloatingPointMode floatingPointMode = FloatingPointMode::Default;
Flags flags = Flag::EnableExceptionHandling;
@@ -163,6 +176,11 @@ public:
const Desc& getDesc() const { return m_desc; }
/// Compile using the specified options. The result is in resOut
virtual SlangResult compile(const CompileOptions& options, Output& outOutput) = 0;
+ /// Given the compilation options and the module name, determines the actual file name used for output
+ virtual SlangResult calcModuleFilePath(const CompileOptions& options, StringBuilder& outPath) = 0;
+
+ /// Return the compiler type as name
+ static UnownedStringSlice getCompilerTypeAsText(CompilerType type);
protected:
@@ -180,26 +198,31 @@ public:
typedef void(*CalcArgsFunc)(const CPPCompiler::CompileOptions& options, CommandLine& cmdLine);
typedef SlangResult(*ParseOutputFunc)(const ExecuteResult& exeResult, Output& output);
+ typedef SlangResult(*CalcModuleFilePathFunc)(const CPPCompiler::CompileOptions& options, StringBuilder& outPath);
virtual SlangResult compile(const CompileOptions& options, Output& outOutput) SLANG_OVERRIDE;
+ virtual SlangResult calcModuleFilePath(const CompileOptions& options, StringBuilder& outPath) SLANG_OVERRIDE;
- GenericCPPCompiler(const Desc& desc, const String& exeName, CalcArgsFunc calcArgsFunc, ParseOutputFunc parseOutputFunc) :
+ GenericCPPCompiler(const Desc& desc, const String& exeName, CalcArgsFunc calcArgsFunc, ParseOutputFunc parseOutputFunc, CalcModuleFilePathFunc calcModuleFilePathFunc) :
Super(desc),
m_calcArgsFunc(calcArgsFunc),
- m_parseOutputFunc(parseOutputFunc)
+ m_parseOutputFunc(parseOutputFunc),
+ m_calcModuleFilePathFunc(calcModuleFilePathFunc)
{
m_cmdLine.setExecutableFilename(exeName);
}
- GenericCPPCompiler(const Desc& desc, const CommandLine& cmdLine, CalcArgsFunc calcArgsFunc, ParseOutputFunc parseOutputFunc) :
+ GenericCPPCompiler(const Desc& desc, const CommandLine& cmdLine, CalcArgsFunc calcArgsFunc, ParseOutputFunc parseOutputFunc, CalcModuleFilePathFunc calcModuleFilePathFunc) :
Super(desc),
m_cmdLine(cmdLine),
m_calcArgsFunc(calcArgsFunc),
- m_parseOutputFunc(parseOutputFunc)
+ m_parseOutputFunc(parseOutputFunc),
+ m_calcModuleFilePathFunc(calcModuleFilePathFunc)
{}
CalcArgsFunc m_calcArgsFunc;
ParseOutputFunc m_parseOutputFunc;
+ CalcModuleFilePathFunc m_calcModuleFilePathFunc;
CommandLine m_cmdLine;
};
@@ -225,6 +248,9 @@ public:
/// Set the default compiler
void setDefaultCompiler(CPPCompiler* compiler) { m_defaultCompiler = compiler; }
+ /// True if has a compiler of the specified type
+ bool hasCompiler(CPPCompiler::CompilerType compilerType) const;
+
protected:
Index _findIndex(const CPPCompiler::Desc& desc) const;
@@ -263,6 +289,9 @@ struct CPPCompilerUtil
/// Given a set, registers compilers found through standard means and determines a reasonable default compiler if possible
static SlangResult initializeSet(CPPCompilerSet* set);
+
+
+
};