From a54b7cbd452b3adb2f51346140d996b29c2cdb30 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Fri, 12 Jan 2007 07:05:14 +0000 Subject: For 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm2cpp/CppWriter.cpp | 51 +++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'tools/llvm2cpp/CppWriter.cpp') diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp index 1f6cbaf288..82997cebcc 100644 --- a/tools/llvm2cpp/CppWriter.cpp +++ b/tools/llvm2cpp/CppWriter.cpp @@ -161,28 +161,25 @@ sanitize(std::string& str) { 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(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 @@ std::string 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(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 @@ CppWriter::printCppName(const Value* val) { 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 @@ CppWriter::printTypes(const Module* M) { // 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) << ");"; -- cgit v1.2.3-70-g09d2