diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-08-12 15:41:41 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-12 15:41:41 -0400 |
| commit | 6fc2c37d9a4c408331db1b33deb3b46e74d2a7d2 (patch) | |
| tree | d763d0f85b61f853f5877ab9ee28d3edaeef302c /source/core/slang-cpp-compiler.h | |
| parent | a0416216ffaf3bd3b0533d967a6d62c477b22d09 (diff) | |
Callable CPU code support (#1014)
* First pass support for compiling to a loaded shared library.
* Improve documentation for cpu target.
* Removed the SLANG_COMPILE_FLAG_LOAD_SHARED_LIBRARY flag.
Use the SLANG_HOST_CALLABLE code target
Document mechanism.
* Fix typo in cpp-resource.slang
In test code if the target is 'callable' we don't need to compile (indeed there is no source file).
* Small refactor using CommandLineCPPCompiler as base class to implement VisualStudioCPPCompiler and GCCCPPCompiler.
* Improvements around CPPCompiler.
Mechanism to know products produced.
Cleaning up products after execution.
* Fix multiple definition of 'SourceType'
Diffstat (limited to 'source/core/slang-cpp-compiler.h')
| -rw-r--r-- | source/core/slang-cpp-compiler.h | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/source/core/slang-cpp-compiler.h b/source/core/slang-cpp-compiler.h index 851975d72..185e960f3 100644 --- a/source/core/slang-cpp-compiler.h +++ b/source/core/slang-cpp-compiler.h @@ -147,6 +147,27 @@ public: Int fileLine; ///< The line number the error came from }; + typedef uint32_t ProductFlags; + struct ProductFlag + { + enum Enum : ProductFlags + { + Debug = 0x1, ///< Used by debugger during execution + Execution = 0x2, ///< Required for execution + Compile = 0x4, ///< A product *required* for compilation + Miscellaneous = 0x8, ///< Anything else + All = 0xf, ///< All the flags + }; + }; + + enum class Product + { + DebugRun, + Run, + CompileTemporary, + All, + }; + struct Output { /// Reset to an initial empty state @@ -178,6 +199,10 @@ public: 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; + /// Given options determines the paths to products produced (including the 'moduleFilePath'). + /// Note that does *not* guarentee all products were or should be produced. Just aims to include all that could + /// be produced, such that can be removed on completion. + virtual SlangResult calcCompileProducts(const CompileOptions& options, ProductFlags flags, List<String>& outPaths) = 0; /// Return the compiler type as name static UnownedStringSlice getCompilerTypeAsText(CompilerType type); @@ -191,38 +216,31 @@ protected: Desc m_desc; }; -class GenericCPPCompiler : public CPPCompiler +class CommandLineCPPCompiler : public CPPCompiler { public: typedef CPPCompiler Super; - 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); - + // CPPCompiler virtual SlangResult compile(const CompileOptions& options, Output& outOutput) SLANG_OVERRIDE; - virtual SlangResult calcModuleFilePath(const CompileOptions& options, StringBuilder& outPath) SLANG_OVERRIDE; + + // Functions to be implemented for a specific CommandLine + virtual SlangResult calcArgs(const CompileOptions& options, CommandLine& cmdLine) = 0; + virtual SlangResult parseOutput(const ExecuteResult& exeResult, Output& output) = 0; - GenericCPPCompiler(const Desc& desc, const String& exeName, CalcArgsFunc calcArgsFunc, ParseOutputFunc parseOutputFunc, CalcModuleFilePathFunc calcModuleFilePathFunc) : - Super(desc), - m_calcArgsFunc(calcArgsFunc), - m_parseOutputFunc(parseOutputFunc), - m_calcModuleFilePathFunc(calcModuleFilePathFunc) + CommandLineCPPCompiler(const Desc& desc, const String& exeName) : + Super(desc) { m_cmdLine.setExecutableFilename(exeName); } - GenericCPPCompiler(const Desc& desc, const CommandLine& cmdLine, CalcArgsFunc calcArgsFunc, ParseOutputFunc parseOutputFunc, CalcModuleFilePathFunc calcModuleFilePathFunc) : + CommandLineCPPCompiler(const Desc& desc, const CommandLine& cmdLine) : Super(desc), - m_cmdLine(cmdLine), - m_calcArgsFunc(calcArgsFunc), - m_parseOutputFunc(parseOutputFunc), - m_calcModuleFilePathFunc(calcModuleFilePathFunc) + m_cmdLine(cmdLine) {} - CalcArgsFunc m_calcArgsFunc; - ParseOutputFunc m_parseOutputFunc; - CalcModuleFilePathFunc m_calcModuleFilePathFunc; + CommandLineCPPCompiler(const Desc& desc):Super(desc) {} + CommandLine m_cmdLine; }; @@ -261,7 +279,8 @@ protected: List<RefPtr<CPPCompiler>> m_compilers; }; -struct CPPCompilerUtil +/* Only purpose of having base-class here is to make all the CPPCompiler types available directly in derived Utils */ +struct CPPCompilerBaseUtil { typedef CPPCompiler::CompileOptions CompileOptions; typedef CPPCompiler::OptimizationLevel OptimizationLevel; @@ -269,6 +288,14 @@ struct CPPCompilerUtil typedef CPPCompiler::DebugInfoType DebugInfoType; typedef CPPCompiler::SourceType SourceType; + typedef CPPCompiler::OutputMessage OutputMessage; + typedef CPPCompiler::FloatingPointMode FloatingPointMode; + typedef CPPCompiler::ProductFlag ProductFlag; + typedef CPPCompiler::ProductFlags ProductFlags; +}; + +struct CPPCompilerUtil: public CPPCompilerBaseUtil +{ enum class MatchType { MinGreaterEqual, @@ -289,12 +316,8 @@ struct CPPCompilerUtil /// Given a set, registers compilers found through standard means and determines a reasonable default compiler if possible static SlangResult initializeSet(CPPCompilerSet* set); - - - }; - } #endif |
