Changes in directory llvm/utils/TableGen:
CodeGenIntrinsics.h updated: 1.2 -> 1.3 IntrinsicEmitter.cpp updated: 1.2 -> 1.3 IntrinsicEmitter.h updated: 1.2 -> 1.3 --- Log message: parse intrinsic types autogenerate an intrinsic verifier --- Diffs of the changes: (+50 -4) CodeGenIntrinsics.h | 4 ++++ IntrinsicEmitter.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++--- IntrinsicEmitter.h | 3 ++- 3 files changed, 50 insertions(+), 4 deletions(-) Index: llvm/utils/TableGen/CodeGenIntrinsics.h diff -u llvm/utils/TableGen/CodeGenIntrinsics.h:1.2 llvm/utils/TableGen/CodeGenIntrinsics.h:1.3 --- llvm/utils/TableGen/CodeGenIntrinsics.h:1.2 Fri Mar 3 00:13:41 2006 +++ llvm/utils/TableGen/CodeGenIntrinsics.h Thu Mar 9 16:05:04 2006 @@ -26,6 +26,10 @@ std::string Name; // The name of the LLVM function "llvm.bswap.i32" std::string EnumName; // The name of the enum "bswap_i32" + /// ArgTypes - The type primitive enum value for the return value and all + /// of the arguments. These are things like Type::UIntTyID. + std::vector<std::string> ArgTypes; + // Memory mod/ref behavior of this intrinsic. enum { NoMem, ReadArgMem, ReadMem, WriteArgMem, WriteMem Index: llvm/utils/TableGen/IntrinsicEmitter.cpp diff -u llvm/utils/TableGen/IntrinsicEmitter.cpp:1.2 llvm/utils/TableGen/IntrinsicEmitter.cpp:1.3 --- llvm/utils/TableGen/IntrinsicEmitter.cpp:1.2 Thu Mar 9 14:34:19 2006 +++ llvm/utils/TableGen/IntrinsicEmitter.cpp Thu Mar 9 16:05:04 2006 @@ -42,6 +42,18 @@ else Name += EnumName[i]; } + + // Parse the list of argument types. + ListInit *TypeList = R->getValueAsListInit("Types"); + for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { + DefInit *DI = dynamic_cast<DefInit*>(TypeList->getElement(i)); + assert(DI && "Invalid list type!"); + Record *TyEl = DI->getDef(); + assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); + ArgTypes.push_back(TyEl->getValueAsString("TypeVal")); + } + if (ArgTypes.size() == 0) + throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!"; } //===----------------------------------------------------------------------===// @@ -58,6 +70,9 @@ // Emit the function name recognizer. EmitFnNameRecognizer(Ints, OS); + + // Emit the intrinsic verifier. + EmitVerifier(Ints, OS); } void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints, @@ -84,8 +99,7 @@ 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"; + OS << " default: break;\n"; // Emit the intrinsics in sorted order. char LastChar = 0; for (std::map<std::string, std::string>::iterator I = IntMapping.begin(), @@ -102,6 +116,33 @@ << I->second << ";\n"; } OS << " }\n"; - OS << "#endif\n"; + OS << " // The 'llvm.' namespace is reserved!\n"; + OS << " assert(0 && \"Unknown LLVM intrinsic function!\");\n"; + OS << "#endif\n\n"; +} + +void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints, + std::ostream &OS) { + OS << "// Verifier::visitIntrinsicFunctionCall code.\n"; + OS << "#ifdef GET_INTRINSIC_VERIFIER\n"; + OS << " switch (ID) {\n"; + OS << " default: assert(0 && \"Invalid intrinsic!\");\n"; + for (unsigned i = 0, e = Ints.size(); i != e; ++i) { + OS << " case Intrinsic::" << Ints[i].EnumName << ":\t\t// " + << Ints[i].Name << "\n"; + OS << " Assert1(FTy->getNumParams() == " << Ints[i].ArgTypes.size()-1 + << ",\n" + << " \"Illegal # arguments for intrinsic function!\", IF);\n"; + OS << " Assert1(FTy->getReturnType()->getTypeID() == " + << Ints[i].ArgTypes[0] << ",\n" + << " \"Illegal result type!\", IF);\n"; + for (unsigned j = 1; j != Ints[i].ArgTypes.size(); ++j) + OS << " Assert1(FTy->getParamType(" << j-1 << ")->getTypeID() == " + << Ints[i].ArgTypes[j] << ",\n" + << " \"Illegal result type!\", IF);\n"; + OS << " break;\n"; + } + OS << " }\n"; + OS << "#endif\n\n"; } Index: llvm/utils/TableGen/IntrinsicEmitter.h diff -u llvm/utils/TableGen/IntrinsicEmitter.h:1.2 llvm/utils/TableGen/IntrinsicEmitter.h:1.3 --- llvm/utils/TableGen/IntrinsicEmitter.h:1.2 Thu Mar 9 14:34:19 2006 +++ llvm/utils/TableGen/IntrinsicEmitter.h Thu Mar 9 16:05:04 2006 @@ -31,7 +31,8 @@ void EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS); - + void EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints, + std::ostream &OS); }; } // End llvm namespace _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits