remove option from tablegen for building static header.
[oota-llvm.git] / utils / TableGen / ClangAttrEmitter.cpp
1 //===- ClangAttrEmitter.cpp - Generate Clang attribute handling =-*- C++ -*--=//
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 // These tablegen backends emit Clang attribute processing code
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ClangAttrEmitter.h"
15 #include "Record.h"
16 #include <algorithm>
17
18 using namespace llvm;
19
20 void ClangAttrClassEmitter::run(raw_ostream &OS) {
21   OS << "// This file is generated by TableGen. Do not edit.\n\n";
22   OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
23   OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n";
24
25   std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
26
27   for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
28        i != e; ++i) {
29     Record &R = **i;
30
31     if (R.getValueAsBit("DoNotEmit"))
32       continue;
33
34     OS << "class " << R.getName() << "Attr : public Attr {\n";
35
36     std::vector<Record*> Args = R.getValueAsListOfDefs("Args");
37
38     // FIXME: Handle arguments
39     assert(Args.empty() && "Can't yet handle arguments");
40
41     OS << "\n public:\n";
42     OS << "  " << R.getName() << "Attr(";
43     
44     // Arguments go here
45     
46     OS << ")\n";
47     OS << "    : Attr(attr::" << R.getName() << ")";
48
49     // Arguments go here
50     
51     OS << " {}\n\n";
52
53     OS << "  virtual Attr *clone (ASTContext &C) const;\n";
54     OS << "  static bool classof(const Attr *A) { return A->getKind() == "
55        << "attr::" << R.getName() << "; }\n";
56     OS << "  static bool classof(const " << R.getName()
57        << "Attr *) { return true; }\n";
58     OS << "};\n\n";
59   }
60
61   OS << "#endif\n";
62 }
63
64 void ClangAttrListEmitter::run(raw_ostream &OS) {
65   OS << "// This file is generated by TableGen. Do not edit.\n\n";
66
67   OS << "#ifndef LAST_ATTR\n";
68   OS << "#define LAST_ATTR(NAME) ATTR(NAME)\n";
69   OS << "#endif\n\n";
70    
71   std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
72   std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
73
74   if (i != e) {
75     // Move the end iterator back to emit the last attribute.
76     for(--e; i != e; ++i)
77       OS << "ATTR(" << (*i)->getName() << ")\n";
78     
79     OS << "LAST_ATTR(" << (*i)->getName() << ")\n\n";
80   }
81
82   OS << "#undef LAST_ATTR\n";
83   OS << "#undef ATTR\n";
84 }