@@ -22,15 +22,15 @@ std::shared_ptr<TypeDef> IR::addTypeDef(std::string name,
2222 return typeDefs.back ();
2323}
2424
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) {
2828 std::shared_ptr<Enum> e = std::make_shared<Enum>(
2929 std::move (name), type, std::move (enumerators), std::move (location));
30+
3031 enums.push_back (e);
31- if (!e->isAnonymous ()) {
32- typeDefs.push_back (e->generateTypeDef ());
33- }
32+
33+ return e;
3434}
3535
3636std::shared_ptr<TypeDef>
@@ -89,7 +89,7 @@ void IR::addVarDefine(std::string name, std::shared_ptr<Variable> variable) {
8989bool IR::libObjEmpty () const {
9090 return functions.empty () && !shouldOutputType (typeDefs) &&
9191 !shouldOutputType (structs) && !shouldOutputType (unions) &&
92- varDefines.empty () && variables.empty ();
92+ varDefines.empty () && variables.empty () && enums. empty () ;
9393}
9494
9595llvm::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) {
120120
121121 std::vector<std::shared_ptr<const Type>> visitedTypes;
122122
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+
123130 for (const auto &typeDef : ir.typeDefs ) {
124131 visitedTypes.clear ();
125132 if (ir.shouldOutputTypeDef (typeDef, visitedTypes)) {
@@ -435,6 +442,10 @@ std::shared_ptr<TypeDef> IR::getTypeDefWithName(const std::string &name) const {
435442 return getDeclarationWithName (typeDefs, name);
436443}
437444
445+ std::shared_ptr<Enum> IR::getEnumWithName (const std::string &name) const {
446+ return getDeclarationWithName (enums, name);
447+ }
448+
438449template <typename T>
439450T IR::getDeclarationWithName (const std::vector<T> &declarations,
440451 const std::string &name) const {
0 commit comments