00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include <iostream>
00028 #include "ShStatement.hpp"
00029
00030 namespace SH {
00031
00032 ShStatementInfo::ShStatementInfo()
00033 {
00034 }
00035
00036 ShStatementInfo::~ShStatementInfo()
00037 {
00038 }
00039
00040 ShStatement::ShStatement(ShVariable dest, ShOperation op)
00041 : dest(dest), op(op)
00042 {
00043 }
00044
00045 ShStatement::ShStatement(ShVariable dest, ShOperation op, ShVariable src1)
00046 : dest(dest), op(op)
00047 {
00048 if(op == SH_OP_ASN && dest.size() != src1.size()) {
00049 SH_DEBUG_PRINT("SH_OP_ASN dest.size() != src.size() (" << dest.size() << " != " << src1.size());
00050 SH_DEBUG_PRINT(" dest=" << dest.name() << " src=" << src1.name());
00051 SH_DEBUG_ASSERT(dest.size() == src1.size());
00052 }
00053 src[0] = src1;
00054 }
00055
00056 ShStatement::ShStatement(ShVariable dest, ShVariable src0, ShOperation op, ShVariable src1)
00057 : dest(dest), op(op)
00058 {
00059 src[0] = src0;
00060 src[1] = src1;
00061 }
00062
00063 ShStatement::ShStatement(ShVariable dest, ShOperation op, ShVariable src0, ShVariable src1, ShVariable src2)
00064 : dest(dest), op(op)
00065 {
00066 src[0] = src0;
00067 src[1] = src1;
00068 src[2] = src2;
00069 }
00070
00071 ShStatement::ShStatement(const ShStatement& other)
00072 : dest(other.dest),
00073 op(other.op),
00074 marked(other.marked)
00075 {
00076 for (int i = 0; i < 3; i++) src[i] = other.src[i];
00077 for (std::list<ShStatementInfo*>::const_iterator I = other.info.begin(); I != other.info.end(); ++I) {
00078 info.push_back((*I)->clone());
00079 }
00080 }
00081
00082
00083 ShStatement& ShStatement::operator=(const ShStatement& other)
00084 {
00085 if (&other == this) return *this;
00086
00087 dest = other.dest;
00088 op = other.op;
00089 marked = other.marked;
00090 for (int i = 0; i < 3; i++) src[i] = other.src[i];
00091
00092 for (std::list<ShStatementInfo*>::const_iterator I = info.begin();
00093 I != info.end(); ++I) {
00094 delete *I;
00095 }
00096 info.clear();
00097
00098 for (std::list<ShStatementInfo*>::const_iterator I = other.info.begin();
00099 I != other.info.end(); ++I) {
00100 info.push_back((*I)->clone());
00101 }
00102
00103 return *this;
00104 }
00105
00106 ShStatement::~ShStatement()
00107 {
00108 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end(); ++I) {
00109 delete *I;
00110 }
00111 }
00112
00113 std::ostream& operator<<(std::ostream& out, const ShStatement& stmt)
00114 {
00115 if (stmt.op == SH::SH_OP_ASN) {
00116
00117 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << stmt.src[0].name() << stmt.src[0].swizzle();
00118 return out;
00119 }
00120
00121 switch (SH::opInfo[stmt.op].arity) {
00122 case 0:
00123 out << SH::opInfo[stmt.op].name << " " << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle();
00124 break;
00125 case 1:
00126 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << SH::opInfo[stmt.op].name
00127 << " " << (stmt.src[0].neg() ? "-" : "") << stmt.src[0].name() << stmt.src[0].swizzle();
00128 break;
00129 case 2:
00130 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << (stmt.src[0].neg() ? "-" : "") << stmt.src[0].name() << stmt.src[0].swizzle()
00131 << " " << SH::opInfo[stmt.op].name << " " <<(stmt.src[1].neg() ? "-" : "") << stmt.src[1].name() << stmt.src[1].swizzle();
00132 break;
00133 case 3:
00134 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << SH::opInfo[stmt.op].name << " "
00135 << (stmt.src[0].neg() ? "-" : "") << stmt.src[0].name() << stmt.src[0].swizzle() << ", "
00136 << (stmt.src[1].neg() ? "-" : "") << stmt.src[1].name() << stmt.src[1].swizzle() << ", "
00137 << (stmt.src[2].neg() ? "-" : "") << stmt.src[2].name() << stmt.src[2].swizzle();
00138 break;
00139 default:
00140 out << "<<<Unknown arity>>>";
00141 break;
00142 }
00143 return out;
00144 }
00145
00146 void ShStatement::add_info(ShStatementInfo* new_info)
00147 {
00148 info.push_back(new_info);
00149 }
00150
00151 void ShStatement::remove_info(ShStatementInfo* old_info)
00152 {
00153 info.remove(old_info);
00154 }
00155
00156 }
00157