Model :upper16: and :lower16: as ARM specific MCTargetExpr. This is a step
[oota-llvm.git] / utils / TableGen / ClangAttrEmitter.cpp
index ee606e0e50f23e32e485b712eb53bde8b68ec337..db10d7906e238304ebdadbb1141640273c682859 100644 (file)
@@ -19,8 +19,8 @@
 
 using namespace llvm;
 
-static const std::vector<StringRef> getValueAsListOfStrings(Record &R,
-                                                            StringRef FieldName) {
+static const std::vector<StringRef>
+getValueAsListOfStrings(Record &R, StringRef FieldName) {
   ListInit *List = R.getValueAsListInit(FieldName);
   assert (List && "Got a null ListInit");
 
@@ -44,7 +44,7 @@ std::string ReadPCHRecord(StringRef type) {
   return StringSwitch<std::string>(type)
     .EndsWith("Decl *", "cast_or_null<" + std::string(type, 0, type.size()-1) +
               ">(GetDecl(Record[Idx++]))")
-    .Case("QualType", "ReadTypeRecord(Idx++)")
+    .Case("QualType", "GetType(Record[Idx++])")
     .Default("Record[Idx++]");
 }
 
@@ -71,6 +71,7 @@ namespace {
         upperName[0] = std::toupper(upperName[0]);
       }
     }
+    virtual ~Argument() {}
 
     StringRef getLowerName() const { return lowerName; }
     StringRef getUpperName() const { return upperName; }
@@ -97,8 +98,6 @@ namespace {
       : Argument(Arg, Attr), type(T)
     {}
 
-    std::string getType() const { return type; }
-
     void writeAccessors(raw_ostream &OS) const {
       OS << "  " << type << " get" << getUpperName() << "() const {\n";
       OS << "    return " << getLowerName() << ";\n";
@@ -172,7 +171,8 @@ namespace {
       OS << "char *" << getLowerName() << ";";
     }
     void writePCHReadDecls(raw_ostream &OS) const {
-      OS << "    std::string " << getLowerName() << "= ReadString(Record, Idx);\n";
+      OS << "    std::string " << getLowerName()
+         << "= ReadString(Record, Idx);\n";
     }
     void writePCHReadArgs(raw_ostream &OS) const {
       OS << getLowerName();
@@ -270,10 +270,10 @@ namespace {
       OS << "    bool is" << getLowerName() << "Expr = Record[Idx++];\n";
       OS << "    void *" << getLowerName() << "Ptr;\n";
       OS << "    if (is" << getLowerName() << "Expr)\n";
-      OS << "      " << getLowerName() << "Ptr = ReadExpr(DeclsCursor);\n";
+      OS << "      " << getLowerName() << "Ptr = ReadExpr(F);\n";
       OS << "    else\n";
       OS << "      " << getLowerName()
-         << "Ptr = GetTypeSourceInfo(DeclsCursor, Record, Idx);\n";
+         << "Ptr = GetTypeSourceInfo(F, Record, Idx);\n";
     }
     void writePCHWrite(raw_ostream &OS) const {
       OS << "    Record.push_back(SA->is" << getUpperName() << "Expr());\n";
@@ -581,7 +581,7 @@ void ClangAttrListEmitter::run(raw_ostream &OS) {
 }
 
 void ClangAttrPCHReadEmitter::run(raw_ostream &OS) {
-  OS << "// This file is generated by TableGen. Do not edi.\n\n";
+  OS << "// This file is generated by TableGen. Do not edit.\n\n";
 
   std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"),
                        ArgRecords;
@@ -637,3 +637,21 @@ void ClangAttrPCHWriteEmitter::run(raw_ostream &OS) {
   }
   OS << "  }\n";
 }
+
+void ClangAttrSpellingListEmitter::run(raw_ostream &OS) {
+  OS << "// This file is generated by TableGen. Do not edit.\n\n";
+
+  std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
+  
+  for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); I != E; ++I) {
+    Record &Attr = **I;
+
+    std::vector<StringRef> Spellings = getValueAsListOfStrings(Attr, "Spellings");
+
+    for (std::vector<StringRef>::const_iterator I = Spellings.begin(), E = Spellings.end(); I != E; ++I) {
+      StringRef Spelling = *I;
+      OS << ".Case(\"" << Spelling << "\", true)\n";
+    }
+  }
+
+}