@@ -22,15 +22,15 @@ std::shared_ptr<TypeDef> IR::addTypeDef(std::string name,
22
22
return typeDefs.back ();
23
23
}
24
24
25
- void IR::addEnum (std::string name, const std::string &type,
26
- std::vector<Enumerator> enumerators,
27
- std::shared_ptr<Location> location) {
25
+ std::shared_ptr<Enum> IR::addEnum (std::string name, const std::string &type,
26
+ std::vector<Enumerator> enumerators,
27
+ std::shared_ptr<Location> location) {
28
28
std::shared_ptr<Enum> e = std::make_shared<Enum>(
29
29
std::move (name), type, std::move (enumerators), std::move (location));
30
+
30
31
enums.push_back (e);
31
- if (!e->isAnonymous ()) {
32
- typeDefs.push_back (e->generateTypeDef ());
33
- }
32
+
33
+ return e;
34
34
}
35
35
36
36
std::shared_ptr<TypeDef>
@@ -89,7 +89,7 @@ void IR::addVarDefine(std::string name, std::shared_ptr<Variable> variable) {
89
89
bool IR::libObjEmpty () const {
90
90
return functions.empty () && !shouldOutputType (typeDefs) &&
91
91
!shouldOutputType (structs) && !shouldOutputType (unions) &&
92
- varDefines.empty () && variables.empty ();
92
+ varDefines.empty () && variables.empty () && enums. empty () ;
93
93
}
94
94
95
95
llvm::raw_ostream &operator <<(llvm::raw_ostream &s, const IR &ir) {
@@ -120,6 +120,13 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
120
120
121
121
std::vector<std::shared_ptr<const Type>> visitedTypes;
122
122
123
+ for (const auto &e : ir.enums ) {
124
+ visitedTypes.clear ();
125
+ if (!e->isAnonymous () && ir.shouldOutput (e, visitedTypes)) {
126
+ s << e->getDefinition ();
127
+ }
128
+ }
129
+
123
130
for (const auto &typeDef : ir.typeDefs ) {
124
131
visitedTypes.clear ();
125
132
if (ir.shouldOutputTypeDef (typeDef, visitedTypes)) {
@@ -435,6 +442,10 @@ std::shared_ptr<TypeDef> IR::getTypeDefWithName(const std::string &name) const {
435
442
return getDeclarationWithName (typeDefs, name);
436
443
}
437
444
445
+ std::shared_ptr<Enum> IR::getEnumWithName (const std::string &name) const {
446
+ return getDeclarationWithName (enums, name);
447
+ }
448
+
438
449
template <typename T>
439
450
T IR::getDeclarationWithName (const std::vector<T> &declarations,
440
451
const std::string &name) const {
0 commit comments