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>
17using namespace llvm;
18
19#define DEBUG_TYPE "attr-enum"
20
21namespace {
22
23class Attributes {
24public:
25  Attributes(RecordKeeper &R) : Records(R) {}
26  void emit(raw_ostream &OS);
27
28private:
29  void emitTargetIndependentEnums(raw_ostream &OS);
30
31  RecordKeeper &Records;
32};
33
34} // End anonymous namespace.
35
36void 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
49void Attributes::emit(raw_ostream &OS) {
50  emitTargetIndependentEnums(OS);
51}
52
53namespace llvm {
54
55void EmitAttributes(RecordKeeper &RK, raw_ostream &OS) {
56  Attributes(RK).emit(OS);
57}
58
59} // End llvm namespace.
60