diff options
author | Remi Thebault <remi.thebault@gmail.com> | 2019-01-02 17:13:13 +0100 |
---|---|---|
committer | Remi Thebault <remi.thebault@gmail.com> | 2019-01-02 17:13:13 +0100 |
commit | 9591b0c41988ec4867deebe0d34e096f24abfc9b (patch) | |
tree | b54757b6b06ad9764d95728223d38ab90ad94261 /tools | |
parent | 4618b86e9e4b027a22040732dfee35e399cd2c47 (diff) | |
download | spirv-headers-9591b0c41988ec4867deebe0d34e096f24abfc9b.tar.gz |
adding support for D language
Diffstat (limited to 'tools')
-rw-r--r-- | tools/buildHeaders/header.cpp | 42 | ||||
-rw-r--r-- | tools/buildHeaders/header.h | 1 | ||||
-rw-r--r-- | tools/buildHeaders/main.cpp | 6 |
3 files changed, 45 insertions, 4 deletions
diff --git a/tools/buildHeaders/header.cpp b/tools/buildHeaders/header.cpp index 6f96d1c..e99110d 100644 --- a/tools/buildHeaders/header.cpp +++ b/tools/buildHeaders/header.cpp @@ -197,14 +197,16 @@ namespace { const std::string TPrinter::DocComment2 = "Enumeration tokens for SPIR-V, in various styles:\n" - " C, C++, C++11, JSON, Lua, Python, C#\n" + " C, C++, C++11, JSON, Lua, Python, C#, D\n" "\n" "- C will have tokens with a \"Spv\" prefix, e.g.: SpvSourceLanguageGLSL\n" "- C++ will have tokens in the \"spv\" name space, e.g.: spv::SourceLanguageGLSL\n" "- C++11 will use enum classes in the spv namespace, e.g.: spv::SourceLanguage::GLSL\n" "- Lua will use tables, e.g.: spv.SourceLanguage.GLSL\n" "- Python will use dictionaries, e.g.: spv['SourceLanguage']['GLSL']\n" - "- C# will use enum classes in the Specification class located in the \"Spv\" namespace, e.g.: Spv.Specification.SourceLanguage.GLSL\n" + "- C# will use enum classes in the Specification class located in the \"Spv\" namespace,\n" + " e.g.: Spv.Specification.SourceLanguage.GLSL\n" + "- D will have tokens under the \"spv\" module, e.g: spv.SourceLanguage.GLSL\n" "\n" "Some tokens act like mask values, which can be OR'd together,\n" "while others are mutually exclusive. The mask-like ones have\n" @@ -695,6 +697,40 @@ namespace { } }; + // D printer + class TPrinterD final : public TPrinter { + private: + std::string commentBeg() const override { return "/+\n"; } + std::string commentBOL() const override { return " + "; } + std::string commentEnd(bool isLast) const override { return " +/\n"; } + + void printPrologue(std::ostream& out) const override { + out << "module spv;\n\n"; + } + + void printEpilogue(std::ostream& out) const override { + } + + std::string enumBeg(const std::string& s, enumStyle_t style) const override { + return "enum " + s + styleStr(style) + " : uint\n{\n"; + } + + std::string enumEnd(const std::string& s, enumStyle_t style, bool isLast) const override { + return std::string("}\n\n"); + } + + std::string enumFmt(const std::string& s, const valpair_t& v, + enumStyle_t style, bool isLast) const override { + return indent() + prependIfDigit("_", v.second) + " = " + fmtStyleVal(v.first, style) + ",\n"; + } + + std::string fmtConstInt(unsigned val, const std::string& name, + const char* fmt, bool isLast) const override { + return std::string("enum uint ") + name + + " = " + fmtNum(fmt, val) + (isLast ? ";\n\n" : ";\n"); + } + }; + } // namespace namespace spv { @@ -710,6 +746,7 @@ namespace spv { langInfo.push_back(std::make_pair(ELangLua, "spirv.lua")); langInfo.push_back(std::make_pair(ELangPython, "spirv.py")); langInfo.push_back(std::make_pair(ELangCSharp, "spirv.cs")); + langInfo.push_back(std::make_pair(ELangD, "spv.d")); for (const auto& lang : langInfo) { std::ofstream out(lang.second, std::ios::out); @@ -736,6 +773,7 @@ namespace spv { case ELangLua: p = TPrinterPtr(new TPrinterLua); break; case ELangPython: p = TPrinterPtr(new TPrinterPython); break; case ELangCSharp: p = TPrinterPtr(new TPrinterCSharp); break; + case ELangD: p = TPrinterPtr(new TPrinterD); break; case ELangAll: PrintAllHeaders(); break; default: std::cerr << "Unknown language." << std::endl; diff --git a/tools/buildHeaders/header.h b/tools/buildHeaders/header.h index 6ab13ce..2f4c999 100644 --- a/tools/buildHeaders/header.h +++ b/tools/buildHeaders/header.h @@ -42,6 +42,7 @@ namespace spv { ELangLua, // Lua ELangPython, // Python ELangCSharp, // CSharp + ELangD, // D ELangAll, // print headers in all languages to files }; diff --git a/tools/buildHeaders/main.cpp b/tools/buildHeaders/main.cpp index e78fd1e..b721a90 100644 --- a/tools/buildHeaders/main.cpp +++ b/tools/buildHeaders/main.cpp @@ -51,6 +51,7 @@ void Usage() " Lua - Lua module\n" " Python - Python module (also accepts Py)\n" " C# - C# module (also accepts CSharp)\n" + " D - D module\n" " -H print header in all supported languages to files in current directory\n" ); } @@ -91,9 +92,10 @@ bool ProcessArguments(int argc, char* argv[]) Language = spv::ELangLua; } else if (language == "python" || language == "py") { Language = spv::ELangPython; - } - else if (language == "c#" || language == "csharp") { + } else if (language == "c#" || language == "csharp") { Language = spv::ELangCSharp; + } else if (language == "d") { + Language = spv::ELangD; } else return false; |