00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #include <fstream>
00021 #include "ShTypeInfo.hpp"
00022 #include "ShCastManager.hpp"
00023 #include "ShVariantCast.hpp"
00024
00025 namespace {
00026 using namespace SH;
00027
00028 template<typename Dest, ShDataType DestDT, typename Src, ShDataType SrcDT>
00029 void addCast(bool automatic)
00030 {
00031 ShCastManager::instance()->addCast(ShDataVariantCast<Dest, DestDT, Src, SrcDT>::instance(), automatic);
00032 }
00033
00034
00035 template<typename Dest, typename Src>
00036 void addPromotion()
00037 {
00038 addCast<Dest, SH_HOST, Src, SH_HOST>(true);
00039 addCast<Src, SH_HOST, Dest, SH_HOST>(false);
00040 }
00041
00042
00043
00044 template<typename T>
00045 void addMemoryCast()
00046 {
00047 addCast<T, SH_HOST, T, SH_MEM>(false);
00048 addCast<T, SH_MEM, T, SH_HOST>(false);
00049 }
00050
00051 }
00052
00053 namespace SH {
00054
00055
00056 void ShTypeInfo::addCasts()
00057 {
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 addPromotion<double, float>();
00073
00074 addPromotion<float, ShHalf>();
00075 addPromotion<float, int>();
00076 addPromotion<float, unsigned int>();
00077 addPromotion<float, ShFracInt> ();
00078 addPromotion<float, ShFracShort> ();
00079 addPromotion<float, ShFracByte> ();
00080 addPromotion<float, ShFracUInt> ();
00081 addPromotion<float, ShFracUShort> ();
00082 addPromotion<float, ShFracUByte> ();
00083
00084 addPromotion<int, short>();
00085 addPromotion<int, char>();
00086 addPromotion<int, unsigned short>();
00087 addPromotion<int, unsigned char>();
00088
00089
00090 addCast<float, SH_HOST, short, SH_HOST>(false);
00091 addCast<float, SH_HOST, char, SH_HOST>(false);
00092 addCast<float, SH_HOST, unsigned short, SH_HOST>(false);
00093 addCast<float, SH_HOST, unsigned char, SH_HOST>(false);
00094
00095 addMemoryCast<double>();
00096 addMemoryCast<float>();
00097 addMemoryCast<ShHalf>();
00098
00099 addMemoryCast<int>();
00100 addMemoryCast<short>();
00101 addMemoryCast<char>();
00102 addMemoryCast<unsigned int>();
00103 addMemoryCast<unsigned short>();
00104 addMemoryCast<unsigned char>();
00105
00106 addMemoryCast<ShFraction<int> >();
00107 addMemoryCast<ShFraction<short> >();
00108 addMemoryCast<ShFraction<char> >();
00109 addMemoryCast<ShFraction<unsigned int> >();
00110 addMemoryCast<ShFraction<unsigned short> >();
00111 addMemoryCast<ShFraction<unsigned char> >();
00112
00113 ShCastManager::instance()->init();
00114
00115 #if 0
00116 std::ofstream fout("castgraph.dot");
00117 ShCastManager::instance()->graphvizDump(fout);
00118 system("dot -Tps < castgraph.dot > castgraph.ps");
00119 #endif
00120 }
00121
00122 }