1 //===- Attributes.cpp - Generate attributes -------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/Support/SourceMgr.h"
11 #include "llvm/Support/MemoryBuffer.h"
12 #include "llvm/TableGen/Error.h"
13 #include "llvm/TableGen/Record.h"
14 #include <algorithm>
15 #include <string>
16 #include <vector>
17 using namespace llvm;
18 
19 #define DEBUG_TYPE "attr-enum"
20 
21 namespace {
22 
23 class Attributes {
24 public:
Attributes(RecordKeeper & R)25   Attributes(RecordKeeper &R) : Records(R) {}
26   void emit(raw_ostream &OS);
27 
28 private:
29   void emitTargetIndependentEnums(raw_ostream &OS);
30 
31   RecordKeeper &Records;
32 };
33 
34 } // End anonymous namespace.
35 
emitTargetIndependentEnums(raw_ostream & OS)36 void Attributes::emitTargetIndependentEnums(raw_ostream &OS) {
37   OS << "#ifdef GET_ATTR_ENUM\n";
38   OS << "#undef GET_ATTR_ENUM\n";
39 
40   const std::vector<Record*> &Attrs =
41       Records.getAllDerivedDefinitions("EnumAttr");
42 
43   for (auto A : Attrs)
44     OS << A->getName() << ",\n";
45 
46   OS << "#endif\n";
47 }
48 
emit(raw_ostream & OS)49 void Attributes::emit(raw_ostream &OS) {
50   emitTargetIndependentEnums(OS);
51 }
52 
53 namespace llvm {
54 
EmitAttributes(RecordKeeper & RK,raw_ostream & OS)55 void EmitAttributes(RecordKeeper &RK, raw_ostream &OS) {
56   Attributes(RK).emit(OS);
57 }
58 
59 } // End llvm namespace.
60