aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-03-13 22:38:57 +0000
committerChris Lattner <sabre@nondot.org>2006-03-13 22:38:57 +0000
commit18faf5d9f7f89130b9e3304965b81e1c70ebb75c (patch)
tree18fcdb88ac198e01a5b7dbfff6a2e5881aca5159 /utils
parent8ae7a3315f2a1be225cd83dd5c95428c0ddff4fd (diff)
downloadexternal_llvm-18faf5d9f7f89130b9e3304965b81e1c70ebb75c.zip
external_llvm-18faf5d9f7f89130b9e3304965b81e1c70ebb75c.tar.gz
external_llvm-18faf5d9f7f89130b9e3304965b81e1c70ebb75c.tar.bz2
Verify that packed type operands have the right size and base type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/CodeGenIntrinsics.h4
-rw-r--r--utils/TableGen/IntrinsicEmitter.cpp30
2 files changed, 28 insertions, 6 deletions
diff --git a/utils/TableGen/CodeGenIntrinsics.h b/utils/TableGen/CodeGenIntrinsics.h
index 7404c70..bca52bc 100644
--- a/utils/TableGen/CodeGenIntrinsics.h
+++ b/utils/TableGen/CodeGenIntrinsics.h
@@ -30,6 +30,10 @@ namespace llvm {
/// of the arguments. These are things like Type::UIntTyID.
std::vector<std::string> ArgTypes;
+ /// ArgTypeDefs - The records for each argument type.
+ ///
+ std::vector<Record*> ArgTypeDefs;
+
// Memory mod/ref behavior of this intrinsic.
enum {
NoMem, ReadArgMem, ReadMem, WriteArgMem, WriteMem
diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp
index bf300ca..9396bdf 100644
--- a/utils/TableGen/IntrinsicEmitter.cpp
+++ b/utils/TableGen/IntrinsicEmitter.cpp
@@ -13,6 +13,7 @@
#include "IntrinsicEmitter.h"
#include "Record.h"
+#include "llvm/ADT/StringExtras.h"
using namespace llvm;
//===----------------------------------------------------------------------===//
@@ -52,6 +53,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
Record *TyEl = DI->getDef();
assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
ArgTypes.push_back(TyEl->getValueAsString("TypeVal"));
+ ArgTypeDefs.push_back(TyEl);
}
if (ArgTypes.size() == 0)
throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!";
@@ -151,6 +153,25 @@ EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
OS << "#endif\n\n";
}
+static void EmitTypeVerify(std::ostream &OS, const std::string &Val,
+ Record *ArgType) {
+ OS << " Assert1(" << Val << "->getTypeID() == "
+ << ArgType->getValueAsString("TypeVal") << ",\n"
+ << " \"Illegal intrinsic type!\", IF);\n";
+
+ // If this is a packed type, check that the subtype and size are correct.
+ if (ArgType->isSubClassOf("LLVMPackedType")) {
+ Record *SubType = ArgType->getValueAsDef("ElTy");
+ OS << " Assert1(cast<PackedType>(" << Val
+ << ")->getElementType()->getTypeID() == "
+ << SubType->getValueAsString("TypeVal") << ",\n"
+ << " \"Illegal intrinsic type!\", IF);\n";
+ OS << " Assert1(cast<PackedType>(" << Val << ")->getNumElements() == "
+ << ArgType->getValueAsInt("NumElts") << ",\n"
+ << " \"Illegal intrinsic type!\", IF);\n";
+ }
+}
+
void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
std::ostream &OS) {
OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
@@ -163,13 +184,10 @@ void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
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";
+ EmitTypeVerify(OS, "FTy->getReturnType()", Ints[i].ArgTypeDefs[0]);
for (unsigned j = 1; j != Ints[i].ArgTypes.size(); ++j)
- OS << " Assert1(FTy->getParamType(" << j-1 << ")->getTypeID() == "
- << Ints[i].ArgTypes[j] << ",\n"
- << " \"Illegal argument type!\", IF);\n";
+ EmitTypeVerify(OS, "FTy->getParamType(" + utostr(j-1) + ")",
+ Ints[i].ArgTypeDefs[j]);
OS << " break;\n";
}
OS << " }\n";