OperatorNodes.h

Go to the documentation of this file.
00001 /*
00002  *      OperatorNodes.h -
00003  *
00004  *  Copyright (C) 2002-2003 The Pentagram Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef MATHNODES_H
00022 #define MATHNODES_H
00023 
00024 #include "GenericNodes.h"
00025 
00026 /*bool is_temp(uint32 op)
00027 {
00028         // in crusader 'u8's end is actually a push type opcode.
00029         if((!crusader) && op==0x79)
00030                 return true;
00031 
00032         switch(op)
00033         {
00034                 case 0x12: // pop temp
00035                 //case 0x4E: // push global
00036                 case 0x4F: // pop global
00037                 case 0x50: // ret
00038                 case 0x51: // jne
00039                 case 0x52: // jmp
00040                 case 0x53: // suspend
00041                 case 0x5D: // push byte retval
00042                 case 0x5E: // push word retval
00043                 case 0x5F: // push dword retval
00044                 case 0x62: // free string bp
00045                 case 0x63: // free slist bp
00046                 case 0x64: // free list bp
00047                 case 0x65: // free string sp
00048                 case 0x66: // free list sp
00049                 //case 0x67: // free slist sp
00050                 case 0x6C: // param pid change
00051                 case 0x70: // loop
00052                 case 0x73: // loopnext
00053                 case 0x74: // loopscr
00054                 case 0x75: // foreach list
00055                 case 0x76: // foreach slist
00056                 case 0x7A: // end
00057                         return true;
00058                 default:   // else...
00059                         return false;
00060         }
00061         return false; // can't happen
00062 }
00063 
00064 class TempNode : public Node
00065 {
00066         public:
00067                 TempNode() : Node(), offset(0) {};
00068                 ~TempNode() {};
00069 
00070                 void print() const;
00071                 void fold(const uint32 end);
00072 
00073                 enum temptype { POP_TEMP, PUSH_GLOBAL, POP_GLOBAL,
00074                         RET, JNE, JMP, SUSPEND,
00075                         PUSH_BYTE_RET, PUSH_WORD_RET, PUSH_DWORD_RET,
00076                         FREE_STRING_BP, FREE_SLIST_BP, FREE_LIST_BP,
00077                         FREE_STRING_SP, FREE_LIST_SP, FREE_SLIST_SP,
00078                         PARAM_PID_CHANGE,
00079                         LOOP, LOOPNEXT, LOOPSCR,
00080                         FOREACH_LIST, FOREACH_SLIST,
00081                         END
00082                         } ttype;
00083 
00084         protected:
00085 
00086         private:
00087                 uint32 offset; // jne/jmp/ *global/foreach*list
00088                 sint32 delta; // loopscr
00089                 Node *node; // loop/free* /foreach*list/param pid change
00090                 uint32 size; // loop/ *global/foreach*list
00091                 uint32 type; // loop/param pid change
00092 };*/
00093 
00094 
00095 /*bool is_convert(uint32 op)
00096 {
00097         switch(op)
00098         {
00099                 case 0x60: // word-to-dword
00100                 case 0x61: // dword-to-word
00101                 case 0x6B: // str-to-ptr
00102                         return true;
00103                 default:   // else...
00104                         return false;
00105         }
00106         return false; // can't happen
00107 }
00108 
00109 class ConvertNode : public UniNode
00110 {
00111         public:
00112                 ConvertNode() : UniNode("Convert"), ctype(NONE) {};
00113                 ~ConvertNode() {};
00114 
00115                 void print() const;
00116                 void fold(const uint32 end);
00117 
00118         protected:
00119                 enum convtype { NONE, WORD_DWORD, DWORD_WORD, STR_PTR } ctype;
00120 
00121         private:
00122 };*/
00123 
00124 class UniOperatorNode : public UniNode
00125 {
00126         public:
00127                 UniOperatorNode(const uint32 opcode, const uint32 offset)
00128                         : UniNode(opcode, offset, Type(Type::T_INVALID))
00129                         {
00130                                 assert(acceptOp(opcode, 0x30, 0x6B));
00131                                 switch(opcode)
00132                                 {
00133                                         case 0x30: otype = NOT; rtype(Type::T_WORD); break;
00134                                         case 0x6B: otype = STR_TO_PTR; rtype(Type::T_STRPTR); break;
00135                                         default: assert(false);
00136                                 }
00137                         };
00138                 ~UniOperatorNode() {};
00139 
00140                 void print_unk(Console &o, const uint32 isize) const;
00141                 void print_asm(Console &o) const;
00142                 void print_bin(ODequeDataSource  &o) const;
00143                 bool fold(DCUnit *unit, std::deque<Node *> &nodes);
00144 
00145         protected:
00146                 enum optype { NOT, STR_TO_PTR/*, BITNOT*/ } otype;
00147 
00148         private:
00149 };
00150 
00151 class BinOperatorNode : public BinNode
00152 {
00153         public:
00154                 BinOperatorNode(const uint32 opcode, const uint32 offset)
00155                         : BinNode(opcode, offset, Type(Type::T_INVALID))
00156                         {
00157                                 assert(acceptOp(opcode, 0x14, 0x1C, 0x1E) || acceptOp(opcode, 0x24, 0x28, 0x2A, 0x2C)
00158                                         || acceptOp(opcode, 0x32, 0x34, 0x36) || acceptOp(opcode, 0x54));
00159                                 switch(opcode)
00160                                 {
00161                                         case 0x14: otype = M_ADD;     rtype(Type::T_WORD); break;
00162                                         case 0x1C: otype = M_SUB;     rtype(Type::T_WORD); break;
00163                                         case 0x1E: otype = M_MUL;     rtype(Type::T_WORD); break;
00164 
00165                                         case 0x24: otype = M_CMP;     rtype(Type::T_WORD); break;
00166                                         case 0x28: otype = M_LT;      rtype(Type::T_WORD); break;
00167                                         case 0x2A: otype = M_LE;      rtype(Type::T_WORD); break;
00168                                         case 0x2C: otype = M_GT;      rtype(Type::T_WORD); break;
00169                                         case 0x32: otype = M_AND;     rtype(Type::T_WORD); break;
00170                                         case 0x34: otype = M_OR;      rtype(Type::T_WORD); break;
00171                                         case 0x36: otype = M_NE;      rtype(Type::T_WORD); break;
00172 
00173                                         case 0x54: otype = M_IMPLIES; rtype(Type::T_WORD); break;
00174 
00175                                         default: assert(false);
00176                                 }
00177                         };
00178                 ~BinOperatorNode() {};
00179 
00180                 void print_unk(Console &o, const uint32 isize) const;
00181                 void print_asm(Console &o) const;
00182                 void print_bin(ODequeDataSource  &o) const;
00183                 bool fold(DCUnit *unit, std::deque<Node *> &nodes);
00184 
00185         protected:
00186                 enum optype { M_ADD, M_SUB, M_MUL, M_CMP, M_AND, M_OR, M_NE, M_LT, M_LE, M_GT, M_IMPLIES } otype;
00187 
00188         private:
00189 };
00190 
00191 #endif

Generated on Fri Jul 27 22:27:28 2007 for pentagram by  doxygen 1.4.7