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