Add constant stat.

Signed Off: Ali Saidi <saidi@eecs.umich.edu>

--HG--
extra : convert_revision : 3da9e507117d0279e212d151d78c312fd9cf0b5c
This commit is contained in:
Vilas Sridharan 2007-10-30 22:21:05 -04:00
parent 503fb8ebed
commit 04d1cfe31c

View file

@ -2030,6 +2030,39 @@ class ConstNode : public Node
virtual std::string str() const { return to_string(vresult[0]); }
};
template <class T>
class ConstVectorNode : public Node
{
private:
VResult vresult;
public:
ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
const VResult &result() const { return vresult; }
virtual Result total() const
{
int size = this->size();
Result tmp = 0;
for (int i = 0; i < size; i++)
{
tmp += vresult[i];
}
return tmp;
}
virtual size_t size() const { return vresult.size(); }
virtual std::string str() const
{
int size = this->size();
std::string tmp = "(";
for (int i = 0; i < size; i++)
{
tmp += csprintf("%s ",to_string(vresult[i]));
}
tmp += ")";
return tmp;
}
};
template <class Op>
struct OpString;
@ -2888,6 +2921,13 @@ constant(T val)
return NodePtr(new ConstNode<T>(val));
}
template <typename T>
inline Temp
constantVector(T val)
{
return NodePtr(new ConstVectorNode<T>(val));
}
inline Temp
sum(Temp val)
{