00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef TYPE_H
00022 #define TYPE_H
00023
00024 #include "Console.h"
00025 #include "ODataSource.h"
00026
00027 class Type
00028 {
00029 public:
00030 enum ttype { T_VOID=0, T_BYTE, T_WORD, T_DWORD, T_STRING,
00031 T_PID, T_VAR, T_LIST, T_SLIST, T_STRPTR, T_INVALID };
00032
00033 Type(const ttype t) : _type(t) {};
00034 Type() : _type(T_INVALID) {};
00035
00036 inline Type &operator=(const ttype t) { _type = t; return *this; };
00037 inline Type &operator=(const Type &t) { _type = t._type; return *this; };
00038
00039 inline bool operator==(const ttype t) const
00040 {
00041 if( (_type==T_BYTE || _type==T_WORD) && (t==T_BYTE || t==T_WORD) )
00042 return true;
00043 else
00044 return _type == t;
00045 };
00046 inline bool operator!=(const ttype t) const { return !(*this == t); };
00047 inline bool operator==(const Type &t) const { return *this == t._type; };
00048 inline bool operator!=(const Type &t) const { return *this != t._type; };
00049
00050 inline ttype type() const { return _type; };
00051 inline const char *name() const { return _namearr[_type]; };
00052 inline uint32 size() const
00053 {
00054 switch(_type)
00055 {
00056 case T_VOID: return 0; break;
00057 case T_BYTE: return 2; break;
00058 case T_WORD: return 2; break;
00059 case T_DWORD: return 4; break;
00060 case T_STRING: return 2; break;
00061 case T_PID: return 2; break;
00062 case T_VAR: assert(false); break;
00063 case T_LIST: return 2; break;
00064 case T_SLIST: return 2; break;
00065 case T_STRPTR: return 4; break;
00066 case T_INVALID: return 0; break;
00067 default: assert(false);
00068 }
00069 return 0;
00070 };
00071 void print_unk(Console &o) const;
00072
00073 private:
00074 ttype _type;
00075 static const char * const _namearr[];
00076 };
00077
00078 class DataType
00079 {
00080 public:
00081 enum datatype { DT_NULL, DT_BYTES, DT_BP, DT_BPLIST, DT_BPADDR, DT_BPSTRPTR,
00082 DT_SP, DT_SPADDR, DT_STRING, DT_PID, DT_PRESULT, DT_RESULT, DT_GLOBAL, DT_TEMP };
00083
00084 DataType(const Type &newVType=Type::T_VOID, const datatype newDType=DT_NULL, const sint32 newValue=0)
00085 : _vtype(newVType), _dtype(newDType), _value(newValue) {};
00086 DataType(const Type::ttype &newVType, const datatype newDType, const std::string &newStrValue)
00087 : _vtype(newVType), _dtype(newDType), _strvalue(newStrValue) {};
00088 DataType(const Type::ttype &newVType, const datatype newDType, const uint32 var, const uint32 varIndex)
00089 : _vtype(newVType), _dtype(newDType), _value(var), _valueIndex(varIndex) {};
00090
00091 const Type &type() const { return _vtype; };
00092 const datatype &dtype() const { return _dtype; };
00093 sint32 value() const { return _value; };
00094
00095 void print_type_unk(Console &o) const { _vtype.print_unk(o); };
00096 void print_value_unk(Console &o) const;
00097 void print_value_asm(Console &o) const;
00098 void print_value_bin(ODequeDataSource &o) const;
00099
00100 private:
00101 Type _vtype;
00102 datatype _dtype;
00103 sint32 _value;
00104 std::string _strvalue;
00105 uint32 _valueIndex;
00106 };
00107
00108
00109
00110
00111 namespace suc
00112 {
00113 inline const char * const print_bp(const sint32 offset)
00114 {
00115 static char str[32];
00116 snprintf(str, 32, "[BP%c%02Xh]", offset>0x7F?'-':'+', offset>0x7F?0x100-offset:offset);
00117 return str;
00118 }
00119
00120 inline const char * const print_sp(const sint32 offset)
00121 {
00122 static char str[32];
00123 snprintf(str, 32, "[SP%c%02Xh]", offset>0x7F?'-':'+', offset>0x7F?0x100-offset:offset);
00124 return str;
00125 }
00126 }
00127
00128 inline bool acceptType(const Type &opcode, const Type::ttype want1)
00129 { return ((opcode==want1) ? true : false); };
00130 inline bool acceptType(const Type &opcode, const Type::ttype want1, const Type::ttype want2)
00131 { return (acceptType(opcode, want1) ? true :
00132 (opcode==want2) ? true : false); };
00133 inline bool acceptType(const Type &opcode, const Type::ttype want1, const Type::ttype want2, const Type::ttype want3)
00134 { return (acceptType(opcode, want1, want2) ? true :
00135 (opcode==want3) ? true : false); };
00136
00137 #endif
00138