summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorKevin Petit <kevin.petit@arm.com>2023-05-05 18:55:42 +0100
committerKevin Petit <kevin.petit@arm.com>2023-05-17 16:51:22 +0100
commitd8c780f48ce5493744d8c97a0d70615c95e506b5 (patch)
treeb63bfba0f2c2c9f422a20a746375c837e1362610 /tools
parent268a061764ee69f09a477a695bf6a11ffe311b8d (diff)
downloadSPIRV-Headers-d8c780f48ce5493744d8c97a0d70615c95e506b5.tar.gz
SPIRV-Headers-d8c780f48ce5493744d8c97a0d70615c95e506b5.tar.bz2
SPIRV-Headers-d8c780f48ce5493744d8c97a0d70615c95e506b5.zip
Make the generated operators for masks constexpr
Generate the overloaded C++11 operators as constexpr instead of inline. constexpr implies inline but makes it possible to use the operators in constexpr functions. Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/buildHeaders/header.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/tools/buildHeaders/header.cpp b/tools/buildHeaders/header.cpp
index fbae044..4ee358b 100644
--- a/tools/buildHeaders/header.cpp
+++ b/tools/buildHeaders/header.cpp
@@ -574,13 +574,8 @@ namespace {
// C++ printer
class TPrinterCPP : public TPrinterCBase {
- private:
- void printPrologue(std::ostream& out) const override {
- TPrinterCBase::printPrologue(out);
- out << "namespace spv {\n\n";
- }
-
- void printEpilogue(std::ostream& out) const override {
+ protected:
+ void printMaskOperators(std::ostream& out, const std::string& specifiers) const {
const Json::Value& enums = spvRoot["spv"]["enum"];
out << "// Overload bitwise operators for mask bit combining\n\n";
@@ -593,20 +588,28 @@ namespace {
const auto typeName = opName + styleStr(enumMask);
// Overload operator|
- out << "inline " << typeName << " operator|(" << typeName << " a, " << typeName << " b) { return " <<
+ out << specifiers << " " << typeName << " operator|(" << typeName << " a, " << typeName << " b) { return " <<
typeName << "(unsigned(a) | unsigned(b)); }\n";
// Overload operator&
- out << "inline " << typeName << " operator&(" << typeName << " a, " << typeName << " b) { return " <<
+ out << specifiers << " " << typeName << " operator&(" << typeName << " a, " << typeName << " b) { return " <<
typeName << "(unsigned(a) & unsigned(b)); }\n";
// Overload operator^
- out << "inline " << typeName << " operator^(" << typeName << " a, " << typeName << " b) { return " <<
+ out << specifiers << " " << typeName << " operator^(" << typeName << " a, " << typeName << " b) { return " <<
typeName << "(unsigned(a) ^ unsigned(b)); }\n";
// Overload operator~
- out << "inline " << typeName << " operator~(" << typeName << " a) { return " <<
+ out << specifiers << " " << typeName << " operator~(" << typeName << " a) { return " <<
typeName << "(~unsigned(a)); }\n";
}
}
+ }
+ private:
+ void printPrologue(std::ostream& out) const override {
+ TPrinterCBase::printPrologue(out);
+ out << "namespace spv {\n\n";
+ }
+ void printEpilogue(std::ostream& out) const override {
+ printMaskOperators(out, "inline");
out << "\n} // end namespace spv\n\n";
out << "#endif // #ifndef spirv_" << headerGuardSuffix() << std::endl;
}
@@ -642,6 +645,11 @@ namespace {
// C++11 printer (uses enum classes)
class TPrinterCPP11 final : public TPrinterCPP {
private:
+ void printEpilogue(std::ostream& out) const override {
+ printMaskOperators(out, "constexpr");
+ out << "\n} // end namespace spv\n\n";
+ out << "#endif // #ifndef spirv_" << headerGuardSuffix() << std::endl;
+ }
std::string enumBeg(const std::string& s, enumStyle_t style) const override {
return std::string("enum class ") + s + styleStr(style) + " : unsigned {\n";
}