Fennel: /home/pub/open/dev/fennel/calculator/IntegralPointerInstruction.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 #ifndef Fennel_IntegralPointerInstruction_Included 00023 #define Fennel_IntegralPointerInstruction_Included 00024 00025 #include "fennel/calculator/PointerInstruction.h" 00026 00027 FENNEL_BEGIN_NAMESPACE 00028 00031 00032 00033 template 00034 class IntegralPointerInstruction 00035 : public PointerInstruction 00036 { 00037 public: 00038 explicit 00039 IntegralPointerInstruction( 00040 RegisterRef* result, 00041 RegisterRef* op1, 00042 StandardTypeDescriptorOrdinal pointerType) 00043 : mResult(result), 00044 mOp1(op1), 00045 mPointerType(pointerType) 00046 {} 00047 00048 ~IntegralPointerInstruction() { 00049 #ifndef MSVC 00050
00051 if (0) { 00052 PointerInstruction_NotAPointerType(); 00053 } 00054 #endif 00055 } 00056 00057 protected: 00058 RegisterRef* mResult; 00059 RegisterRef* mOp1; 00060 StandardTypeDescriptorOrdinal mPointerType; 00061 }; 00062 00063 template 00064 class PointerGetSize : public IntegralPointerInstruction 00065 { 00066 public: 00067 explicit 00068 PointerGetSize( 00069 RegisterRef* result, 00070 RegisterRef* op1, 00071 StandardTypeDescriptorOrdinal pointerType) 00072 : IntegralPointerInstruction(result, op1, pointerType) 00073 {} 00074 00075 virtual 00076 ~PointerGetSize() {} 00077 00078 virtual void exec(TProgramCounter& pc) const { 00079 pc++; 00080 00081 if (IntegralPointerInstruction::mOp1->isNull()) { 00082 IntegralPointerInstruction::mResult->toNull(); 00083 } else { 00084
00085 IntegralPointerInstruction::mResult->value( 00086 IntegralPointerInstruction::mOp1->length()); 00087 } 00088 } 00089 00090 static const char * longName() 00091 { 00092 return "PointerGetSize"; 00093 } 00094 00095 static const char * shortName() 00096 { 00097 return "GETS"; 00098 } 00099 00100 static int numArgs() 00101 { 00102 return 2; 00103 } 00104 00105 void describe(string& out, bool values) const { 00106 RegisterRef mOp2; 00107 describeHelper( 00108 out, values, longName(), shortName(), 00109 IntegralPointerInstruction::mResult, 00110 IntegralPointerInstruction::mOp1, &mOp2); 00111 } 00112 00113 static InstructionSignature 00114 signature(StandardTypeDescriptorOrdinal type) { 00115 return InstructionSignature( 00116 shortName(), 00117 regDesc(1, numArgs() - 1, type, 0)); 00118 } 00119 00120 static Instruction* 00121 create(InstructionSignature const & sig) 00122 { 00123 assert(sig.size() == numArgs()); 00124 assert((sig[0])->type() == POINTERSIZET_STANDARD_TYPE); 00125 return new 00126 PointerGetSize( 00127 static_cast<RegisterRef> (sig[0]), 00128 static_cast<RegisterRef> (sig[1]), 00129 (sig[1])->type()); 00130 } 00131 }; 00132 00133 template 00134 class PointerGetMaxSize : public IntegralPointerInstruction 00135 { 00136 public: 00137 explicit 00138 PointerGetMaxSize( 00139 RegisterRef* result, 00140 RegisterRef* op1, 00141 StandardTypeDescriptorOrdinal pointerType) 00142 : IntegralPointerInstruction(result, op1, pointerType) 00143 {} 00144 00145 virtual 00146 ~PointerGetMaxSize() {} 00147 00148 virtual void exec(TProgramCounter& pc) const { 00149 pc++; 00150 00151 if (IntegralPointerInstruction::mOp1->isNull()) { 00152 IntegralPointerInstruction::mResult->toNull(); 00153 } else { 00154
00155 IntegralPointerInstruction::mResult->value( 00156 IntegralPointerInstruction::mOp1->storage()); 00157 } 00158 } 00159 00160 static const char * longName() 00161 { 00162 return "PointerGetMaxSize"; 00163 } 00164 00165 static const char * shortName() 00166 { 00167 return "GETMS"; 00168 } 00169 00170 static int numArgs() 00171 { 00172 return 2; 00173 } 00174 00175 void describe(string& out, bool values) const { 00176 RegisterRef mOp2; 00177 describeHelper( 00178 out, values, longName(), shortName(), 00179 IntegralPointerInstruction::mResult, 00180 IntegralPointerInstruction::mOp1, &mOp2); 00181 } 00182 00183 static InstructionSignature 00184 signature(StandardTypeDescriptorOrdinal type) { 00185 return InstructionSignature( 00186 shortName(), 00187 regDesc(1, numArgs() - 1, type, 0)); 00188 } 00189 00190 static Instruction* 00191 create(InstructionSignature const & sig) 00192 { 00193 assert(sig.size() == numArgs()); 00194 assert((sig[0])->type() == POINTERSIZET_STANDARD_TYPE); 00195 return new 00196 PointerGetMaxSize( 00197 static_cast<RegisterRef> (sig[0]), 00198 static_cast<RegisterRef> (sig[1]), 00199 (sig[1])->type()); 00200 } 00201 }; 00202 00203 00204 class FENNEL_CALCULATOR_EXPORT IntegralPointerInstructionRegister 00205 : InstructionRegister 00206 { 00207
00208 template < template class INSTCLASS2 > 00209 static void 00210 registerTypes(vector const &t) { 00211 00212 for (uint i = 0; i < t.size(); i++) { 00213 StandardTypeDescriptorOrdinal type = t[i]; 00214
00215 InstructionSignature sig = INSTCLASS2::signature(type); 00216 switch (type) { 00217
00218
00219
00220
00221 #define Fennel_InstructionRegisterSwitch_Array 1 00222 #include "fennel/calculator/InstructionRegisterSwitch.h" 00223 default: 00224 throw std::logic_error("Default InstructionRegister"); 00225 } 00226 } 00227 } 00228 00229 public: 00230 static void 00231 registerInstructions() { 00232 vector t; 00233
00234
00235
00236 t = InstructionSignature::typeVector(StandardTypeDescriptor::isArray); 00237 00238
00239
00240
00241
00242
00243 registerTypesfennel::PointerGetSize(t); 00244 registerTypesfennel::PointerGetMaxSize(t); 00245 } 00246 }; 00247 00248 FENNEL_END_NAMESPACE 00249 00250 #endif 00251 00252 00253