VarNodes.h

Go to the documentation of this file.
00001 /*
00002  *      VarNodes.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 VARNODES_H
00022 #define VARNODES_H
00023 
00024 #include "Type.h"
00025 #include "GenericNodes.h"
00026 #include <string>
00027 
00028 class PopVarNode : public UniNode
00029 {
00030         public:
00031                 PopVarNode(const uint32 opcode, const uint32 offset, const uint32 newValue)
00032                         : UniNode(opcode, offset)
00033                 {
00034                         assert(acceptOp(opcode, 0x01));
00035                         switch(opcode)
00036                         {
00037                                 case 0x01: // popping a word var (2 bytes)
00038                                         _dtype = DataType(Type::T_WORD, DataType::DT_BP, newValue);
00039                                         break;
00040                                 default: assert(false);
00041                         }
00042                         rtype(_dtype.type());
00043                 };
00044                 PopVarNode(const uint32 opcode, const uint32 offset)
00045                         : UniNode(opcode, offset)
00046                 {
00047                         assert(acceptOp(opcode, 0x12));
00048                         switch(opcode)
00049                         {
00050                                 case 0x12: // popping a word into temp
00051                                         _dtype = DataType(Type::T_WORD, DataType::DT_TEMP);
00052                                         break;
00053                                 default: assert(false);
00054                         }
00055                         rtype(_dtype.type());
00056                 };
00057                 ~PopVarNode() { /*FORGET_OBJECT(lnode);*/ /* don't delete rnode */ };
00058 
00059                 void print_unk(Console &o, const uint32 isize) const;
00060                 void print_asm(Console &o) const;
00061                 void print_bin(ODequeDataSource &o) const;
00062 
00063                 bool fold(DCUnit * /*unit*/, std::deque<Node *> &nodes);
00064 
00065         protected:
00066 
00067         private:
00068                 DataType        _dtype;
00069 };
00070 
00071 class PushVarNode : public Node
00072 {
00073         public:
00074                 PushVarNode(const uint32 opcode, const uint32 offset, const uint32 newValue)
00075                         : Node(opcode, offset)
00076                 {
00077                         assert(acceptOp(opcode, 0x0B, 0x3F, 0x40, 0x4B) || acceptOp(opcode, 0x0C, 0x0A));
00078                         switch(opcode)
00079                         {
00080                                 case 0x0A: // pushing a byte (1 byte)
00081                                         _dtype = DataType(Type::T_BYTE, DataType::DT_BYTES, newValue);
00082                                         break;
00083                                 case 0x0B: // pushing a word (2 bytes)
00084                                         _dtype = DataType(Type::T_WORD, DataType::DT_BYTES, newValue);
00085                                         break;
00086                                 case 0x0C: // pushing a dword (4 bytes)
00087                                         _dtype = DataType(Type::T_DWORD, DataType::DT_BYTES, newValue);
00088                                         break;
00089                                 case 0x3F: // pushing a word var (2 bytes)
00090                                         _dtype = DataType(Type::T_WORD, DataType::DT_BP, newValue);
00091                                         break;
00092                                 case 0x40: // pushing a dword var (4 bytes)
00093                                         _dtype = DataType(Type::T_DWORD, DataType::DT_BP, newValue);
00094                                         break;
00095                                 case 0x4B: // pushing an address (4 bytes)
00096                                         _dtype = DataType(Type::T_DWORD, DataType::DT_BPADDR, newValue);
00097                                         break;
00098                                 default: assert(false);
00099                         }
00100                         rtype(_dtype.type());
00101                 };
00102                 PushVarNode(const uint32 opcode, const uint32 offset, const uint32 strSize, const std::string &str)
00103                         : Node(opcode, offset)
00104                 {
00105                         assert(acceptOp(opcode, 0x0D));
00106                         switch(opcode)
00107                         {
00108                                 case 0x0D: // pushing a string (2 bytes)
00109                                         assert(strSize==str.size());
00110                                         _dtype = DataType(Type::T_STRING, DataType::DT_STRING, str);
00111                                         break;
00112                                 default: assert(false);
00113                         }
00114                         rtype(_dtype.type());
00115                 };
00116                 PushVarNode(const uint32 opcode, const uint32 offset, const uint32 variable, const uint32 varindex)
00117                         : Node(opcode, offset)
00118                 {
00119                         assert(acceptOp(opcode, 0x4E));
00120                         _dtype = DataType(Type::T_WORD, DataType::DT_GLOBAL, variable, varindex);
00121                         rtype(_dtype.type());
00122                 };
00123                 PushVarNode(const uint32 opcode, const uint32 offset)
00124                         : Node(opcode, offset)
00125                 {
00126                         assert(acceptOp(opcode, 0x59));
00127                         switch(opcode)
00128                         {
00129                                 case 0x59:
00130                                         _dtype = DataType(Type::T_WORD, DataType::DT_PID);
00131                                         break;
00132                                 default: assert(false);
00133                         }
00134                         rtype(_dtype.type());
00135                 };
00136 
00137                 ~PushVarNode() {};
00138 
00139                 void print_unk(Console &o, const uint32 isize) const;
00140                 void print_asm(Console &o) const;
00141                 void print_bin(ODequeDataSource &o) const;
00142 
00143                 bool fold(DCUnit * /*unit*/, std::deque<Node *> &/*nodes*/) { return true; /* to be done */ };
00144 
00145                 /* NOTE: 'VT_VOID' is not really a vartype, just used for proper typecasting of
00146                         calls to functions that return no value, DT_DNULL isn't a real datatype either */
00147                 /* NOTE: 'VT_VAR' is not really a vartype either, it's just to handle a variable
00148                         number of parameters pushed as a global, if it's not a 'nice' number */
00149 
00150                 const DataType &dtype() const { return _dtype; };
00151 
00152         protected:
00153 
00154         private:
00155                 DataType        _dtype;
00156 
00157 /*              sint32          value;
00158                 // for list use only
00159                 uint32          value2;
00160                 // for string use only
00161                 std::string             strval;
00162                 // for global use only
00163                 uint32 global_offset;
00164                 uint32 global_size;*/
00165 };
00166 
00167 #endif

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