mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
46654c8b26
When emitting `EnumDefinition`s in C++, use the smallest uint type as the base class.
88 lines
2.2 KiB
Smarty
88 lines
2.2 KiB
Smarty
#pragma once
|
|
|
|
/*#-
|
|
This template file is distributed under the MIT License. See LICENSE.md for details.
|
|
The notice below applies to the generated files.
|
|
#*/
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
// This file is autogenerated! Do not edit it directly
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
#include "revng/ADT/KeyedObjectContainer.h"
|
|
#include "revng/TupleTree/EnumTraits.h"
|
|
#include "revng/TupleTree/NamedEnumScalarTraits.h"
|
|
#include "revng/Support/Assert.h"
|
|
|
|
namespace /*= base_namespace =*/::/*= enum.name =*/ {
|
|
/*= enum.doc | docstring =*/
|
|
enum Values : /*= enum | enum_underlying_type =*/ {
|
|
Invalid,
|
|
/** for member in enum.members **/
|
|
/*=- member.doc | docstring =*/
|
|
/*=- member.name =*/,
|
|
/** endfor **/
|
|
Count
|
|
};
|
|
|
|
inline llvm::StringRef getName(Values V) {
|
|
switch (V) {
|
|
case Invalid:
|
|
return "Invalid";
|
|
/**- for member in enum.members **/
|
|
case /*= member.name =*/:
|
|
return "/*= member.name =*/";
|
|
/**- endfor **/
|
|
default:
|
|
revng_abort();
|
|
break;
|
|
}
|
|
}
|
|
|
|
inline Values fromName(llvm::StringRef Name) {
|
|
/**- for member in enum.members **/
|
|
/**- if loop.first **/
|
|
if (Name == "/*= member.name =*/") {
|
|
return /*= member.name =*/;
|
|
}
|
|
/**- else **/
|
|
else if (Name == "/*= member.name =*/") {
|
|
return /*= member.name =*/;
|
|
}
|
|
/**- endif -**/
|
|
/**- endfor -**/
|
|
else {
|
|
return Invalid;
|
|
}
|
|
}
|
|
|
|
inline bool isValid(/*= base_namespace =*/::/*= enum.name =*/::Values Value) {
|
|
revng_assert(Value < Values::Count);
|
|
return Value != Values::Invalid;
|
|
}
|
|
|
|
} // namespace /*= base_namespace =*/::/*= enum.name =*/
|
|
|
|
template<>
|
|
struct KeyedObjectTraits</*= enum | fullname =*/>
|
|
: public IdentityKeyedObjectTraits</*= enum | fullname =*/> {};
|
|
|
|
namespace llvm::yaml {
|
|
template<>
|
|
struct ScalarEnumerationTraits</*= enum | fullname =*/>
|
|
: public NamedEnumScalarTraits</*= enum | fullname =*/> {
|
|
};
|
|
} // namespace llvm::yaml
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(/*= enum | fullname =*/)
|
|
|
|
/*# length + 1 to account for the implicit Invalid member -#*/
|
|
template<>
|
|
inline constexpr size_t EnumElementsCount</*= enum | fullname =*/> = /*= enum.members|length + 1 =*/;
|
|
|
|
template<>
|
|
inline llvm::StringRef getEnumName</*= enum | fullname =*/>() { return "/*= enum.name =*/"; }
|
|
|