[llvm-commits] CVS: llvm/utils/TableGen/IntrinsicEmitter.cpp IntrinsicEmitter.h
Chris Lattner
lattner at cs.uiuc.edu
Thu Mar 9 12:34:32 PST 2006
Changes in directory llvm/utils/TableGen:
IntrinsicEmitter.cpp updated: 1.1 -> 1.2
IntrinsicEmitter.h updated: 1.1 -> 1.2
---
Log message:
autogenerate the function name recognizer
---
Diffs of the changes: (+41 -0)
IntrinsicEmitter.cpp | 37 +++++++++++++++++++++++++++++++++++++
IntrinsicEmitter.h | 4 ++++
2 files changed, 41 insertions(+)
Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
diff -u llvm/utils/TableGen/IntrinsicEmitter.cpp:1.1 llvm/utils/TableGen/IntrinsicEmitter.cpp:1.2
--- llvm/utils/TableGen/IntrinsicEmitter.cpp:1.1 Thu Mar 2 20:32:46 2006
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp Thu Mar 9 14:34:19 2006
@@ -55,10 +55,14 @@
// Emit the enum information.
EmitEnumInfo(Ints, OS);
+
+ // Emit the function name recognizer.
+ EmitFnNameRecognizer(Ints, OS);
}
void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
std::ostream &OS) {
+ OS << "// Enum values for Intrinsics.h\n";
OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
OS << " " << Ints[i].EnumName;
@@ -68,3 +72,36 @@
}
OS << "#endif\n\n";
}
+
+void IntrinsicEmitter::
+EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
+ std::ostream &OS) {
+ // Build a function name -> intrinsic name mapping.
+ std::map<std::string, std::string> IntMapping;
+ for (unsigned i = 0, e = Ints.size(); i != e; ++i)
+ IntMapping[Ints[i].Name] = Ints[i].EnumName;
+
+ OS << "// Function name -> enum value recognizer code.\n";
+ OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
+ OS << " switch (Name[5]) {\n";
+ OS << " // The 'llvm.' namespace is reserved!\n";
+ OS << " default: assert(0 && \"Unknown LLVM intrinsic function!\");\n";
+ // Emit the intrinsics in sorted order.
+ char LastChar = 0;
+ for (std::map<std::string, std::string>::iterator I = IntMapping.begin(),
+ E = IntMapping.end(); I != E; ++I) {
+ assert(I->first.size() > 5 && std::string(I->first.begin(),
+ I->first.begin()+5) == "llvm." &&
+ "Invalid intrinsic name!");
+ if (I->first[5] != LastChar) {
+ LastChar = I->first[5];
+ OS << " case '" << LastChar << "':\n";
+ }
+
+ OS << " if (Name == \"" << I->first << "\") return Intrinsic::"
+ << I->second << ";\n";
+ }
+ OS << " }\n";
+ OS << "#endif\n";
+}
+
Index: llvm/utils/TableGen/IntrinsicEmitter.h
diff -u llvm/utils/TableGen/IntrinsicEmitter.h:1.1 llvm/utils/TableGen/IntrinsicEmitter.h:1.2
--- llvm/utils/TableGen/IntrinsicEmitter.h:1.1 Thu Mar 2 20:32:46 2006
+++ llvm/utils/TableGen/IntrinsicEmitter.h Thu Mar 9 14:34:19 2006
@@ -28,6 +28,10 @@
void EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
std::ostream &OS);
+
+ void EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
+ std::ostream &OS);
+
};
} // End llvm namespace
More information about the llvm-commits
mailing list