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 #ifndef FILE_PARAM_H
00026 #define FILE_PARAM_H
00027
00028 #include "registers.h"
00029 #include "relocationinfo.h"
00030
00031
00032
00033
00034
00035 class Param
00036 {
00037 public:
00038 #ifdef DEBUG
00039 void InitInvalid();
00040 void CheckValid();
00041 #endif
00042 enum TCRegistry { Registry };
00043 enum TCLiteral { Literal };
00044 enum TCFarLiteral { FarLiteral };
00045 enum TCMemory { Memory };
00046 enum Types { t_registry, t_literal, t_memory, t_farliteral };
00047 typedef enum MemoryTypes {
00048 #define DEFINE_MEMTYPE(name,size) name,
00049 #define DEFINE_MEMTYPEI(name,size) name = 0,
00050 #include "memtype.h"
00051 #undef DEFINE_MEMTYPE
00052 #undef DEFINE_MEMTYPEI
00053 memTypeCount
00054 } MemoryTypes;
00055
00056 enum Types GetType() const { return type; };
00057 Param():relocation(NULL) {};
00058
00059 Param(enum TCRegistry dummy,reg_t reg);
00060
00061 Param(enum TCLiteral dummy,int _literal,unsigned char _size=0);
00062
00063 Param(enum TCFarLiteral dummy,int _literal,unsigned char _size,int segment);
00064
00065 Param(enum TCMemory dummy,int address,MemoryTypes memType = memNone);
00066 Param(enum TCMemory dummy,reg_t reg,int address=0,MemoryTypes memType = memNone);
00067 Param(enum TCMemory dummy,reg_t reg1,reg_t reg2,int address=0,unsigned char multiplier=1,MemoryTypes memType = memNone);
00068
00069
00070 public:
00071 bool RegEqual(const Param& rhs) const
00072 { return type == t_registry && rhs.type == t_registry && mem_reg1 == rhs.mem_reg1; }
00073
00074 reg_t mem_reg1;
00075 reg_t mem_reg2;
00076 int literal;
00077 const Relocation* relocation;
00078 enum Types type;
00079 unsigned char factor;
00080 unsigned char GetSize() const;
00081 unsigned char GetLiteralSize() const
00082 {
00083 _PRG_ASSERT( type == t_literal || type == t_farliteral );
00084 return sm.size;
00085 };
00086 unsigned GetMemSize() const
00087 {
00088 _PRG_ASSERT( type == t_memory );
00089 _PRG_ASSERT( unsigned(sm.memType&0x7F) < memTypeCount );
00090 return memTypeSizes[sm.memType&0x7F];
00091 };
00092 void SetMemType(MemoryTypes _memType,bool bWriteSize = true)
00093 {
00094 _PRG_ASSERT( type == t_memory );
00095 _PRG_ASSERT( unsigned(_memType) < memTypeCount );
00096 _PRG_ASSERT( memTypeCount < 128 );
00097 sm.memType = (unsigned char)_memType;
00098 if (!bWriteSize)
00099 sm.memType |= 0x80;
00100 };
00101 bool MustWriteMemSize() const
00102 {
00103 _PRG_ASSERT( type == t_memory );
00104 return (sm.memType & 0x80) == 0;
00105 }
00106 private:
00107 union {
00108 unsigned char size;
00109 unsigned char memType;
00110 } sm;
00111 static unsigned memTypeSizes[memTypeCount];
00112 };
00113
00114 class RegParam: public Param
00115 {
00116 public:
00117 RegParam(reg_t reg);
00118 };
00119
00120 class LiteralParam: public Param
00121 {
00122 public:
00123 LiteralParam(int _literal,unsigned char _size=0);
00124 };
00125
00126 class MemoryParam: public Param
00127 {
00128 public:
00129 MemoryParam(int address,unsigned char size=0);
00130 MemoryParam(reg_t reg,int address=0,unsigned char size=0);
00131 MemoryParam(reg_t reg1,reg_t reg2,int address=0,unsigned char multiplier=1,unsigned char size=0);
00132 };
00133
00134 #endif //FILE_PARAM_H