Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShTypeInfo.cpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #include "ShTypeInfo.hpp"
00028 #include "ShContext.hpp"
00029 #include "ShInterval.hpp"
00030 #include "ShEval.hpp"
00031 #include "ShCastManager.hpp"
00032 #include "ShVariantCast.hpp"
00033 
00034 namespace {
00035 using namespace SH;
00036 
00037 // sets up m_valueType entries for host & memory type for the given value type
00038 template<typename T>
00039 void setTypeInfo(ShTypeInfo::TypeInfoMap &valueTypes) {
00040   ShValueType V = ShStorageTypeInfo<T>::value_type;
00041   valueTypes(V, SH_HOST) = ShDataTypeInfo<T, SH_HOST>::instance();
00042   valueTypes(V, SH_MEM) = ShDataTypeInfo<T, SH_MEM>::instance();
00043 }
00044 
00045 }
00046 
00047 namespace SH {
00048 
00049 ShTypeInfo::TypeInfoMap ShTypeInfo::m_valueTypes;
00050 
00051 void ShTypeInfo::init()
00052 {
00053   setTypeInfo<ShInterval<double> >(m_valueTypes);
00054   setTypeInfo<ShInterval<float> >(m_valueTypes);
00055 
00056   setTypeInfo<double>(m_valueTypes);
00057   setTypeInfo<float>(m_valueTypes);
00058   setTypeInfo<ShHalf>(m_valueTypes);
00059 
00060   setTypeInfo<int>(m_valueTypes);
00061   setTypeInfo<short>(m_valueTypes);
00062   setTypeInfo<char>(m_valueTypes);
00063   setTypeInfo<unsigned int>(m_valueTypes);
00064   setTypeInfo<unsigned short>(m_valueTypes);
00065   setTypeInfo<unsigned char>(m_valueTypes);
00066 
00067   setTypeInfo<ShFracInt> (m_valueTypes);
00068   setTypeInfo<ShFracShort> (m_valueTypes);
00069   setTypeInfo<ShFracByte> (m_valueTypes);
00070   setTypeInfo<ShFracUInt> (m_valueTypes);
00071   setTypeInfo<ShFracUShort> (m_valueTypes);
00072   setTypeInfo<ShFracUByte> (m_valueTypes);
00073 
00074   addOps();
00075 
00076   /* DEBUG */ //SH_DEBUG_PRINT("ShEval ops: \n" << ShEval::instance()->availableOps());
00077 
00078   addCasts();
00079 }
00080 
00081 const ShTypeInfo* ShTypeInfo::get(ShValueType valueType, ShDataType dataType)
00082 {
00083   const ShTypeInfo* result = m_valueTypes(valueType, dataType);
00084   if(!result) SH_DEBUG_PRINT("Null ShTypeInfo");
00085   return result;
00086 }
00087 
00088 const ShTypeInfo* shTypeInfo(ShValueType valueType, ShDataType dataType)
00089 {
00090   return ShTypeInfo::get(valueType, dataType); 
00091 }
00092 
00093 const ShVariantFactory* shVariantFactory(ShValueType valueType, ShDataType dataType)
00094 {
00095   return shTypeInfo(valueType, dataType)->variantFactory();  
00096 }
00097 
00098 const char* shValueTypeName(ShValueType valueType)
00099 {
00100   const ShTypeInfo* typeInfo = shTypeInfo(valueType, SH_HOST);
00101   if(!typeInfo) return ShStorageTypeInfo<ShInvalidStorageType>::name; 
00102   return typeInfo->name();
00103 }
00104 
00105 }

Generated on Mon Jan 24 18:36:36 2005 for Sh by  doxygen 1.4.1