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

ShEvaluate.cpp

00001 #include "ShEvaluate.hpp"
00002 #include "ShInstructions.hpp"
00003 #include "ShDebug.hpp"
00004 #include "ShContext.hpp"
00005 #include "ShVariant.hpp"
00006 
00007 namespace SH {
00008 
00009 void evaluate(ShStatement& stmt)
00010 {
00011   // TODO: Maybe not do this _every_ time we call evaluate...
00012   stmt.dest.node()->addVariant();
00013   for (int i = 0; i < opInfo[stmt.op].arity; i++) {
00014     stmt.src[i].node()->addVariant();
00015   }
00016   // Make sure we are outside of a program definition
00017   ShContext::current()->enter(0);
00018   switch (stmt.op) {
00019   case SH_OP_ASN:
00020     shASN(stmt.dest, stmt.src[0]);
00021     break;
00022   case SH_OP_ADD:
00023     shADD(stmt.dest, stmt.src[0], stmt.src[1]);
00024     break;
00025   case SH_OP_MUL:
00026     shMUL(stmt.dest, stmt.src[0], stmt.src[1]);
00027     break;
00028   case SH_OP_DIV:
00029     shDIV(stmt.dest, stmt.src[0], stmt.src[1]);
00030     break;
00031   case SH_OP_SLT:
00032     shSLT(stmt.dest, stmt.src[0], stmt.src[1]);
00033     break;
00034   case SH_OP_SLE:
00035     shSLE(stmt.dest, stmt.src[0], stmt.src[1]);
00036     break;
00037   case SH_OP_SGT:
00038     shSGT(stmt.dest, stmt.src[0], stmt.src[1]);
00039     break;
00040   case SH_OP_SGE:
00041     shSGE(stmt.dest, stmt.src[0], stmt.src[1]);
00042     break;
00043   case SH_OP_SEQ:
00044     shSEQ(stmt.dest, stmt.src[0], stmt.src[1]);
00045     break;
00046   case SH_OP_SNE:
00047     shSNE(stmt.dest, stmt.src[0], stmt.src[1]);
00048     break;
00049   case SH_OP_ABS:
00050     shABS(stmt.dest, stmt.src[0]);
00051     break;
00052   case SH_OP_ACOS:
00053     shACOS(stmt.dest, stmt.src[0]);
00054     break;
00055   case SH_OP_ASIN:
00056     shASIN(stmt.dest, stmt.src[0]);
00057     break;
00058   case SH_OP_ATAN:
00059     shATAN(stmt.dest, stmt.src[0]);
00060     break;
00061   case SH_OP_ATAN2:
00062     shATAN2(stmt.dest, stmt.src[0], stmt.src[1]);
00063     break;
00064   case SH_OP_CEIL:
00065     shCEIL(stmt.dest, stmt.src[0]);
00066     break;
00067   case SH_OP_COS:
00068     shCOS(stmt.dest, stmt.src[0]);
00069     break;
00070   case SH_OP_CMUL:
00071     shCMUL(stmt.dest, stmt.src[0]);
00072     break;
00073   case SH_OP_CSUM:
00074     shCSUM(stmt.dest, stmt.src[0]);
00075     break;
00076   case SH_OP_DOT:
00077     shDOT(stmt.dest, stmt.src[0], stmt.src[1]);
00078     break;
00079   case SH_OP_DX:
00080     shDX(stmt.dest, stmt.src[0]);
00081     break;
00082   case SH_OP_DY:
00083     shDY(stmt.dest, stmt.src[0]);
00084     break;
00085   case SH_OP_EXP:
00086     shEXP(stmt.dest, stmt.src[0]);
00087     break;
00088   case SH_OP_EXP2:
00089     shEXP2(stmt.dest, stmt.src[0]);
00090     break;
00091   case SH_OP_EXP10:
00092     shEXP10(stmt.dest, stmt.src[0]);
00093     break;
00094   case SH_OP_FLR:
00095     shFLR(stmt.dest, stmt.src[0]);
00096     break;
00097   case SH_OP_FRAC:
00098     shFRAC(stmt.dest, stmt.src[0]);
00099     break;
00100   case SH_OP_LOG:
00101     shLOG(stmt.dest, stmt.src[0]);
00102     break;
00103   case SH_OP_LOG2:
00104     shLOG2(stmt.dest, stmt.src[0]);
00105     break;
00106   case SH_OP_LOG10:
00107     shLOG10(stmt.dest, stmt.src[0]);
00108     break;
00109   case SH_OP_LRP:
00110     shLRP(stmt.dest, stmt.src[0], stmt.src[1], stmt.src[2]);
00111     break;
00112   case SH_OP_MAD:
00113     shMAD(stmt.dest, stmt.src[0], stmt.src[1], stmt.src[2]);
00114     break;
00115   case SH_OP_MAX:
00116     shMAX(stmt.dest, stmt.src[0], stmt.src[1]);
00117     break;
00118   case SH_OP_MIN:
00119     shMIN(stmt.dest, stmt.src[0], stmt.src[1]);
00120     break;
00121   case SH_OP_MOD:
00122     shMOD(stmt.dest, stmt.src[0], stmt.src[1]);
00123     break;
00124   case SH_OP_POW:
00125     shPOW(stmt.dest, stmt.src[0], stmt.src[1]);
00126     break;
00127   case SH_OP_RCP:
00128     shRCP(stmt.dest, stmt.src[0]);
00129     break;
00130   case SH_OP_RSQ:
00131     shRSQ(stmt.dest, stmt.src[0]);
00132     break;
00133   case SH_OP_SGN:
00134     shSGN(stmt.dest, stmt.src[0]);
00135     break;
00136   case SH_OP_SIN:
00137     shSIN(stmt.dest, stmt.src[0]);
00138     break;
00139   case SH_OP_SQRT:
00140     shSQRT(stmt.dest, stmt.src[0]);
00141     break;
00142   case SH_OP_TAN:
00143     shTAN(stmt.dest, stmt.src[0]);
00144     break;
00145   case SH_OP_NORM:
00146     shNORM(stmt.dest, stmt.src[0]);
00147     break;
00148   case SH_OP_XPD:
00149     shXPD(stmt.dest, stmt.src[0], stmt.src[1]);
00150     break;
00151   case SH_OP_COND:
00152     shCOND(stmt.dest, stmt.src[0], stmt.src[1], stmt.src[2]);
00153     break;
00154   case SH_OP_KIL:
00155     shKIL(stmt.src[0]);
00156     break;
00157   default:
00158     // TODO: Replace with shError().
00159     SH_DEBUG_ASSERT(0 && "Invalid Statement");
00160     break;
00161   }
00162   ShContext::current()->exit();
00163 }
00164 
00165 void evaluate(const ShProgramNodePtr& p)
00166 {
00167   ShCtrlGraphNodePtr node = p->ctrlGraph->entry();
00168 
00169   while (node != p->ctrlGraph->exit()) {
00170     if (!node) break; // Should never happen!
00171     
00172     ShBasicBlockPtr block = node->block;
00173     if (block) {
00174       for (ShBasicBlock::ShStmtList::iterator I = block->begin(); I != block->end(); ++I) {
00175         evaluate(*I);
00176       }
00177     }
00178 
00179     bool done = false;
00180     
00181     for (std::vector<ShCtrlGraphBranch>::const_iterator I = node->successors.begin();
00182          I != node->successors.end(); ++I) {
00183       I->cond.node()->addVariant(); // Make sure the condition has values.
00184       bool jmp = false;
00185       for (int i = 0; i < I->cond.size(); i++) if (I->cond.getVariant()->isTrue()) jmp = true;
00186       if (jmp) {
00187         done = true;
00188         node = I->node;
00189         break;
00190       }
00191     }
00192     if (done) continue;
00193 
00194     node = node->follower;
00195   }
00196 }
00197 
00198 }
00199 

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