@@ -4103,6 +4103,27 @@ namespace rr
41034103 return elements;
41044104 }
41054105
4106+ // toInt returns all the integer values in vals extended to a native width
4107+ // integer.
4108+ static std::vector<Value*> toInt (const std::vector<Value*>& vals, bool isSigned)
4109+ {
4110+ auto intTy = ::llvm::Type::getIntNTy (*::context, sizeof (int ) * 8 ); // Natural integer width.
4111+ std::vector<Value*> elements;
4112+ elements.reserve (vals.size ());
4113+ for (auto v : vals)
4114+ {
4115+ if (isSigned)
4116+ {
4117+ elements.push_back (V (::builder->CreateSExt (V (v), intTy)));
4118+ }
4119+ else
4120+ {
4121+ elements.push_back (V (::builder->CreateZExt (V (v), intTy)));
4122+ }
4123+ }
4124+ return elements;
4125+ }
4126+
41064127 // toDouble returns all the float values in vals extended to doubles.
41074128 static std::vector<Value*> toDouble (const std::vector<Value*>& vals)
41084129 {
@@ -4116,11 +4137,15 @@ namespace rr
41164137 return elements;
41174138 }
41184139
4119- std::vector<Value*> PrintValue::Ty<Byte4>::val(const RValue<Byte4>& v) { return extractAll (v.value , 4 ); }
4120- std::vector<Value*> PrintValue::Ty<Int4>::val(const RValue<Int4>& v) { return extractAll (v.value , 4 ); }
4121- std::vector<Value*> PrintValue::Ty<UInt4>::val(const RValue<UInt4>& v) { return extractAll (v.value , 4 ); }
4122- std::vector<Value*> PrintValue::Ty<Short4>::val(const RValue<Short4>& v) { return extractAll (v.value , 4 ); }
4123- std::vector<Value*> PrintValue::Ty<UShort4>::val(const RValue<UShort4>& v) { return extractAll (v.value , 4 ); }
4140+ std::vector<Value*> PrintValue::Ty<Byte4>::val(const RValue<Byte4>& v) { return toInt (extractAll (v.value , 4 ), false ); }
4141+ std::vector<Value*> PrintValue::Ty<Int>::val(const RValue<Int>& v) { return toInt ({v.value }, true ); }
4142+ std::vector<Value*> PrintValue::Ty<Int2>::val(const RValue<Int2>& v) { return toInt (extractAll (v.value , 2 ), true ); }
4143+ std::vector<Value*> PrintValue::Ty<Int4>::val(const RValue<Int4>& v) { return toInt (extractAll (v.value , 4 ), true ); }
4144+ std::vector<Value*> PrintValue::Ty<UInt>::val(const RValue<UInt>& v) { return toInt ({v.value }, false ); }
4145+ std::vector<Value*> PrintValue::Ty<UInt2>::val(const RValue<UInt2>& v) { return toInt (extractAll (v.value , 2 ), false ); }
4146+ std::vector<Value*> PrintValue::Ty<UInt4>::val(const RValue<UInt4>& v) { return toInt (extractAll (v.value , 4 ), false ); }
4147+ std::vector<Value*> PrintValue::Ty<Short4>::val(const RValue<Short4>& v) { return toInt (extractAll (v.value , 4 ), true ); }
4148+ std::vector<Value*> PrintValue::Ty<UShort4>::val(const RValue<UShort4>& v) { return toInt (extractAll (v.value , 4 ), false ); }
41244149 std::vector<Value*> PrintValue::Ty<Float>::val(const RValue<Float>& v) { return toDouble ({v.value }); }
41254150 std::vector<Value*> PrintValue::Ty<Float4>::val(const RValue<Float4>& v) { return toDouble (extractAll (v.value , 4 )); }
41264151 std::vector<Value*> PrintValue::Ty<const char *>::val(const char * v) { return {V (::builder->CreateGlobalStringPtr (v))}; }
@@ -4129,7 +4154,7 @@ namespace rr
41294154 {
41304155 // LLVM types used below.
41314156 auto i32Ty = ::llvm::Type::getInt32Ty (*::context);
4132- auto intTy = ::llvm::Type::getInt64Ty (*::context) ; // TODO: Natural int width.
4157+ auto intTy = ::llvm::Type::getIntNTy (*::context, sizeof ( int ) * 8 ) ; // Natural integer width.
41334158 auto i8PtrTy = ::llvm::Type::getInt8PtrTy (*::context);
41344159 auto funcTy = ::llvm::FunctionType::get (i32Ty, {i8PtrTy}, true );
41354160
0 commit comments