Skip to content

Commit 5a12186

Browse files
authored
Merge pull request KhronosGroup#283 from jayrulez/beeflang
Implemented Beef language header generation
2 parents b765c35 + d6b5958 commit 5a12186

File tree

12 files changed

+1948
-9
lines changed

12 files changed

+1948
-9
lines changed

include/spirv/unified1/spirv.bf

Lines changed: 1878 additions & 0 deletions
Large diffs are not rendered by default.

include/spirv/unified1/spirv.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// the Binary Section of the SPIR-V specification.
2727

2828
// Enumeration tokens for SPIR-V, in various styles:
29-
// C, C++, C++11, JSON, Lua, Python, C#, D
29+
// C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3030
//
3131
// - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3232
// - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -36,6 +36,8 @@
3636
// - C# will use enum classes in the Specification class located in the "Spv" namespace,
3737
// e.g.: Spv.Specification.SourceLanguage.GLSL
3838
// - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
39+
// - Beef will use enum classes in the Specification class located in the "Spv" namespace,
40+
// e.g.: Spv.Specification.SourceLanguage.GLSL
3941
//
4042
// Some tokens act like mask values, which can be OR'd together,
4143
// while others are mutually exclusive. The mask-like ones have

include/spirv/unified1/spirv.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/*
3333
** Enumeration tokens for SPIR-V, in various styles:
34-
** C, C++, C++11, JSON, Lua, Python, C#, D
34+
** C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3535
**
3636
** - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3737
** - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -41,6 +41,8 @@
4141
** - C# will use enum classes in the Specification class located in the "Spv" namespace,
4242
** e.g.: Spv.Specification.SourceLanguage.GLSL
4343
** - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
44+
** - Beef will use enum classes in the Specification class located in the "Spv" namespace,
45+
** e.g.: Spv.Specification.SourceLanguage.GLSL
4446
**
4547
** Some tokens act like mask values, which can be OR'd together,
4648
** while others are mutually exclusive. The mask-like ones have

include/spirv/unified1/spirv.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// the Binary Section of the SPIR-V specification.
2727

2828
// Enumeration tokens for SPIR-V, in various styles:
29-
// C, C++, C++11, JSON, Lua, Python, C#, D
29+
// C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3030
//
3131
// - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3232
// - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -36,6 +36,8 @@
3636
// - C# will use enum classes in the Specification class located in the "Spv" namespace,
3737
// e.g.: Spv.Specification.SourceLanguage.GLSL
3838
// - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
39+
// - Beef will use enum classes in the Specification class located in the "Spv" namespace,
40+
// e.g.: Spv.Specification.SourceLanguage.GLSL
3941
//
4042
// Some tokens act like mask values, which can be OR'd together,
4143
// while others are mutually exclusive. The mask-like ones have

include/spirv/unified1/spirv.hpp11

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// the Binary Section of the SPIR-V specification.
2727

2828
// Enumeration tokens for SPIR-V, in various styles:
29-
// C, C++, C++11, JSON, Lua, Python, C#, D
29+
// C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3030
//
3131
// - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3232
// - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -36,6 +36,8 @@
3636
// - C# will use enum classes in the Specification class located in the "Spv" namespace,
3737
// e.g.: Spv.Specification.SourceLanguage.GLSL
3838
// - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
39+
// - Beef will use enum classes in the Specification class located in the "Spv" namespace,
40+
// e.g.: Spv.Specification.SourceLanguage.GLSL
3941
//
4042
// Some tokens act like mask values, which can be OR'd together,
4143
// while others are mutually exclusive. The mask-like ones have

include/spirv/unified1/spirv.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
[
3838
"Enumeration tokens for SPIR-V, in various styles:",
39-
" C, C++, C++11, JSON, Lua, Python, C#, D",
39+
" C, C++, C++11, JSON, Lua, Python, C#, D, Beef",
4040
"",
4141
"- C will have tokens with a \"Spv\" prefix, e.g.: SpvSourceLanguageGLSL",
4242
"- C++ will have tokens in the \"spv\" name space, e.g.: spv::SourceLanguageGLSL",
@@ -46,6 +46,8 @@
4646
"- C# will use enum classes in the Specification class located in the \"Spv\" namespace,",
4747
" e.g.: Spv.Specification.SourceLanguage.GLSL",
4848
"- D will have tokens under the \"spv\" module, e.g: spv.SourceLanguage.GLSL",
49+
"- Beef will use enum classes in the Specification class located in the \"Spv\" namespace,",
50+
" e.g.: Spv.Specification.SourceLanguage.GLSL",
4951
"",
5052
"Some tokens act like mask values, which can be OR'd together,",
5153
"while others are mutually exclusive. The mask-like ones have",

include/spirv/unified1/spirv.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
-- the Binary Section of the SPIR-V specification.
2727

2828
-- Enumeration tokens for SPIR-V, in various styles:
29-
-- C, C++, C++11, JSON, Lua, Python, C#, D
29+
-- C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3030
--
3131
-- - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3232
-- - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -36,6 +36,8 @@
3636
-- - C# will use enum classes in the Specification class located in the "Spv" namespace,
3737
-- e.g.: Spv.Specification.SourceLanguage.GLSL
3838
-- - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
39+
-- - Beef will use enum classes in the Specification class located in the "Spv" namespace,
40+
-- e.g.: Spv.Specification.SourceLanguage.GLSL
3941
--
4042
-- Some tokens act like mask values, which can be OR'd together,
4143
-- while others are mutually exclusive. The mask-like ones have

include/spirv/unified1/spirv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# the Binary Section of the SPIR-V specification.
2727

2828
# Enumeration tokens for SPIR-V, in various styles:
29-
# C, C++, C++11, JSON, Lua, Python, C#, D
29+
# C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3030
#
3131
# - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3232
# - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -36,6 +36,8 @@
3636
# - C# will use enum classes in the Specification class located in the "Spv" namespace,
3737
# e.g.: Spv.Specification.SourceLanguage.GLSL
3838
# - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
39+
# - Beef will use enum classes in the Specification class located in the "Spv" namespace,
40+
# e.g.: Spv.Specification.SourceLanguage.GLSL
3941
#
4042
# Some tokens act like mask values, which can be OR'd together,
4143
# while others are mutually exclusive. The mask-like ones have

include/spirv/unified1/spv.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/+
3333
+ Enumeration tokens for SPIR-V, in various styles:
34-
+ C, C++, C++11, JSON, Lua, Python, C#, D
34+
+ C, C++, C++11, JSON, Lua, Python, C#, D, Beef
3535
+
3636
+ - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
3737
+ - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
@@ -41,6 +41,8 @@
4141
+ - C# will use enum classes in the Specification class located in the "Spv" namespace,
4242
+ e.g.: Spv.Specification.SourceLanguage.GLSL
4343
+ - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL
44+
+ - Beef will use enum classes in the Specification class located in the "Spv" namespace,
45+
+ e.g.: Spv.Specification.SourceLanguage.GLSL
4446
+
4547
+ Some tokens act like mask values, which can be OR'd together,
4648
+ while others are mutually exclusive. The mask-like ones have

tools/buildHeaders/header.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ namespace {
199199

200200
const std::string TPrinter::DocComment2 =
201201
"Enumeration tokens for SPIR-V, in various styles:\n"
202-
" C, C++, C++11, JSON, Lua, Python, C#, D\n"
202+
" C, C++, C++11, JSON, Lua, Python, C#, D, Beef\n"
203203
"\n"
204204
"- C will have tokens with a \"Spv\" prefix, e.g.: SpvSourceLanguageGLSL\n"
205205
"- C++ will have tokens in the \"spv\" name space, e.g.: spv::SourceLanguageGLSL\n"
@@ -209,6 +209,8 @@ namespace {
209209
"- C# will use enum classes in the Specification class located in the \"Spv\" namespace,\n"
210210
" e.g.: Spv.Specification.SourceLanguage.GLSL\n"
211211
"- D will have tokens under the \"spv\" module, e.g: spv.SourceLanguage.GLSL\n"
212+
"- Beef will use enum classes in the Specification class located in the \"Spv\" namespace,\n"
213+
" e.g.: Spv.Specification.SourceLanguage.GLSL\n"
212214
"\n"
213215
"Some tokens act like mask values, which can be OR'd together,\n"
214216
"while others are mutually exclusive. The mask-like ones have\n"
@@ -779,6 +781,43 @@ namespace {
779781
}
780782
};
781783

784+
// Beef printer
785+
class TPrinterBeef final : public TPrinter {
786+
private:
787+
std::string commentBOL() const override { return "// "; }
788+
789+
void printPrologue(std::ostream& out) const override {
790+
out << "namespace Spv\n{\n";
791+
out << indent() << "using System;\n\n";
792+
out << indent() << "public static class Specification\n";
793+
out << indent() << "{\n";
794+
}
795+
796+
void printEpilogue(std::ostream& out) const override {
797+
out << indent() << "}\n";
798+
out << "}\n";
799+
}
800+
801+
std::string enumBeg(const std::string& s, enumStyle_t style) const override {
802+
return indent(2) + "[AllowDuplicates, CRepr] public enum " + s + styleStr(style) + "\n" + indent(2) + "{\n";
803+
}
804+
805+
std::string enumEnd(const std::string& s, enumStyle_t style, bool isLast) const override {
806+
return indent(2) + "}" + +(isLast ? "\n" : "\n\n");
807+
}
808+
809+
std::string enumFmt(const std::string& s, const valpair_t& v,
810+
enumStyle_t style, bool isLast) const override {
811+
return indent(3) + prependIfDigit(s, v.second) + " = " + fmtStyleVal(v.first, style) + ",\n";
812+
}
813+
814+
std::string fmtConstInt(unsigned val, const std::string& name,
815+
const char* fmt, bool isLast) const override {
816+
return indent(2) + std::string("public const uint32 ") + name +
817+
" = " + fmtNum(fmt, val) + (isLast ? ";\n\n" : ";\n");
818+
}
819+
};
820+
782821
} // namespace
783822

784823
namespace spv {
@@ -795,6 +834,7 @@ namespace spv {
795834
langInfo.push_back(std::make_pair(ELangPython, "spirv.py"));
796835
langInfo.push_back(std::make_pair(ELangCSharp, "spirv.cs"));
797836
langInfo.push_back(std::make_pair(ELangD, "spv.d"));
837+
langInfo.push_back(std::make_pair(ELangBeef, "spirv.bf"));
798838

799839
for (const auto& lang : langInfo) {
800840
std::ofstream out(lang.second, std::ios::out);
@@ -822,6 +862,7 @@ namespace spv {
822862
case ELangPython: p = TPrinterPtr(new TPrinterPython); break;
823863
case ELangCSharp: p = TPrinterPtr(new TPrinterCSharp); break;
824864
case ELangD: p = TPrinterPtr(new TPrinterD); break;
865+
case ELangBeef: p = TPrinterPtr(new TPrinterBeef); break;
825866
case ELangAll: PrintAllHeaders(); break;
826867
default:
827868
std::cerr << "Unknown language." << std::endl;

0 commit comments

Comments
 (0)