[llvm-commits] CVS: llvm/tools/llvm2cpp/CppWriter.cpp
Reid Spencer
reid at x10sys.com
Thu Jan 11 23:06:07 PST 2007
Changes in directory llvm/tools/llvm2cpp:
CppWriter.cpp updated: 1.31 -> 1.32
---
Log message:
For PR1064: http://llvm.org/PR1064 :
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
---
Diffs of the changes: (+24 -27)
CppWriter.cpp | 51 ++++++++++++++++++++++++---------------------------
1 files changed, 24 insertions(+), 27 deletions(-)
Index: llvm/tools/llvm2cpp/CppWriter.cpp
diff -u llvm/tools/llvm2cpp/CppWriter.cpp:1.31 llvm/tools/llvm2cpp/CppWriter.cpp:1.32
--- llvm/tools/llvm2cpp/CppWriter.cpp:1.31 Thu Jan 11 22:24:46 2007
+++ llvm/tools/llvm2cpp/CppWriter.cpp Fri Jan 12 01:05:14 2007
@@ -161,28 +161,25 @@
str[i] = '_';
}
-inline const char*
+inline std::string
getTypePrefix(const Type* Ty ) {
- const char* prefix;
switch (Ty->getTypeID()) {
- case Type::VoidTyID: prefix = "void_"; break;
- case Type::Int1TyID: prefix = "bool_"; break;
- case Type::Int8TyID: prefix = "int8_"; break;
- case Type::Int16TyID: prefix = "int16_"; break;
- case Type::Int32TyID: prefix = "int32_"; break;
- case Type::Int64TyID: prefix = "int64_"; break;
- case Type::FloatTyID: prefix = "float_"; break;
- case Type::DoubleTyID: prefix = "double_"; break;
- case Type::LabelTyID: prefix = "label_"; break;
- case Type::FunctionTyID: prefix = "func_"; break;
- case Type::StructTyID: prefix = "struct_"; break;
- case Type::ArrayTyID: prefix = "array_"; break;
- case Type::PointerTyID: prefix = "ptr_"; break;
- case Type::PackedTyID: prefix = "packed_"; break;
- case Type::OpaqueTyID: prefix = "opaque_"; break;
- default: prefix = "other_"; break;
+ case Type::VoidTyID: return "void_";
+ case Type::IntegerTyID:
+ return std::string("int") + utostr(cast<IntegerType>(Ty)->getBitWidth()) +
+ "_";
+ case Type::FloatTyID: return "float_";
+ case Type::DoubleTyID: return "double_";
+ case Type::LabelTyID: return "label_";
+ case Type::FunctionTyID: return "func_";
+ case Type::StructTyID: return "struct_";
+ case Type::ArrayTyID: return "array_";
+ case Type::PointerTyID: return "ptr_";
+ case Type::PackedTyID: return "packed_";
+ case Type::OpaqueTyID: return "opaque_";
+ default: return "other_";
}
- return prefix;
+ return "unknown_";
}
// Looks up the type in the symbol table and returns a pointer to its name or
@@ -313,14 +310,13 @@
CppWriter::getCppName(const Type* Ty)
{
// First, handle the primitive types .. easy
- if (Ty->isPrimitiveType()) {
+ if (Ty->isPrimitiveType() || Ty->isIntegral()) {
switch (Ty->getTypeID()) {
case Type::VoidTyID: return "Type::VoidTy";
- case Type::Int1TyID: return "Type::Int1Ty";
- case Type::Int8TyID: return "Type::Int8Ty";
- case Type::Int16TyID: return "Type::Int16Ty";
- case Type::Int32TyID: return "Type::Int32Ty";
- case Type::Int64TyID: return "Type::Int64Ty";
+ case Type::IntegerTyID: {
+ unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth();
+ return "IntegerType::get(" + utostr(BitWidth) + ")";
+ }
case Type::FloatTyID: return "Type::FloatTy";
case Type::DoubleTyID: return "Type::DoubleTy";
case Type::LabelTyID: return "Type::LabelTy";
@@ -414,7 +410,7 @@
bool
CppWriter::printTypeInternal(const Type* Ty) {
// We don't print definitions for primitive types
- if (Ty->isPrimitiveType())
+ if (Ty->isPrimitiveType() || Ty->isIntegral())
return false;
// If we already defined this type, we don't need to define it again.
@@ -603,7 +599,8 @@
// For primitive types and types already defined, just add a name
TypeMap::const_iterator TNI = TypeNames.find(TI->second);
- if (TI->second->isPrimitiveType() || TNI != TypeNames.end()) {
+ if (TI->second->isIntegral() || TI->second->isPrimitiveType() ||
+ TNI != TypeNames.end()) {
Out << "mod->addTypeName(\"";
printEscapedString(TI->first);
Out << "\", " << getCppName(TI->second) << ");";
More information about the llvm-commits
mailing list