00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef Fennel_PointerIntegralInstruction_Included
00023 #define Fennel_PointerIntegralInstruction_Included
00024
00025 #include "fennel/calculator/PointerInstruction.h"
00026
00027 FENNEL_BEGIN_NAMESPACE
00028
00029
00030 template<typename PTR_TYPE>
00031 class PointerIntegralInstruction : public PointerInstruction
00032 {
00033 public:
00034 explicit
00035 PointerIntegralInstruction(
00036 RegisterRef<PTR_TYPE>* result,
00037 RegisterRef<PointerSizeT>* op1,
00038 StandardTypeDescriptorOrdinal pointerType)
00039 : mResult(result),
00040 mOp1(op1),
00041 mPointerType(pointerType)
00042 {}
00043
00044 ~PointerIntegralInstruction() {
00045 #ifndef __MSVC__
00046
00047 if (0) {
00048 PointerInstruction_NotAPointerType<PTR_TYPE>();
00049 }
00050 #endif
00051 }
00052
00053 protected:
00054 RegisterRef<PTR_TYPE>* mResult;
00055 RegisterRef<PointerSizeT>* mOp1;
00056 StandardTypeDescriptorOrdinal mPointerType;
00057 };
00058
00059
00060
00061 template <typename PTR_TYPE>
00062 class PointerPutSize : public PointerIntegralInstruction<PTR_TYPE>
00063 {
00064 public:
00065 explicit
00066 PointerPutSize(
00067 RegisterRef<PTR_TYPE>* result,
00068 RegisterRef<PointerSizeT>* op1,
00069 StandardTypeDescriptorOrdinal pointerType)
00070 : PointerIntegralInstruction<PTR_TYPE>(result, op1, pointerType)
00071 {}
00072
00073 virtual
00074 ~PointerPutSize() {}
00075
00076 virtual void exec(TProgramCounter& pc) const {
00077 pc++;
00078
00079 if (PointerIntegralInstruction<PTR_TYPE>::mOp1->isNull()) {
00080 PointerIntegralInstruction<PTR_TYPE>::mResult->toNull();
00081 PointerIntegralInstruction<PTR_TYPE>::mResult->length(0);
00082 } else {
00083
00084 PointerIntegralInstruction<PTR_TYPE>::mResult->length
00085 (PointerIntegralInstruction<PTR_TYPE>::mOp1->value());
00086 }
00087 }
00088
00089 static const char * longName()
00090 {
00091 return "PointerPutSize";
00092 }
00093
00094 static const char * shortName()
00095 {
00096 return "PUTS";
00097 }
00098
00099 static int numArgs()
00100 {
00101 return 2;
00102 }
00103
00104 void describe(string& out, bool values) const {
00105 RegisterRef<PTR_TYPE> mOp2;
00106 describeHelper(
00107 out, values, longName(), shortName(),
00108 PointerIntegralInstruction<PTR_TYPE>::mResult,
00109 PointerIntegralInstruction<PTR_TYPE>::mOp1, &mOp2);
00110 }
00111
00112 static InstructionSignature
00113 signature(StandardTypeDescriptorOrdinal type) {
00114 vector<StandardTypeDescriptorOrdinal> v;
00115 v.push_back(type);
00116 v.push_back(POINTERSIZET_STANDARD_TYPE);
00117 return InstructionSignature(shortName(), v);
00118 }
00119
00120 static Instruction*
00121 create(InstructionSignature const & sig)
00122 {
00123 assert(sig.size() == numArgs());
00124 assert((sig[1])->type() == POINTERSIZET_STANDARD_TYPE);
00125 return new
00126 PointerPutSize(
00127 static_cast<RegisterRef<PTR_TYPE>*> (sig[0]),
00128 static_cast<RegisterRef<PointerSizeT>*> (sig[1]),
00129 (sig[0])->type());
00130 }
00131 };
00132
00135
00136 class FENNEL_CALCULATOR_EXPORT PointerIntegralInstructionRegister
00137 : InstructionRegister {
00138
00139
00140 template < template <typename> class INSTCLASS2 >
00141 static void
00142 registerTypes(vector<StandardTypeDescriptorOrdinal> const &t) {
00143
00144 for (uint i = 0; i < t.size(); i++) {
00145 StandardTypeDescriptorOrdinal type = t[i];
00146
00147 InstructionSignature sig = INSTCLASS2<char>::signature(type);
00148 switch (type) {
00149
00150
00151
00152
00153 #define Fennel_InstructionRegisterSwitch_Array 1
00154 #include "fennel/calculator/InstructionRegisterSwitch.h"
00155 default:
00156 throw std::logic_error("Default InstructionRegister");
00157 }
00158 }
00159 }
00160
00161 public:
00162 static void
00163 registerInstructions() {
00164 vector<StandardTypeDescriptorOrdinal> t;
00165
00166
00167
00168 t = InstructionSignature::typeVector(StandardTypeDescriptor::isArray);
00169
00170
00171
00172
00173
00174
00175 registerTypes<fennel::PointerPutSize>(t);
00176
00177 }
00178 };
00179
00180
00181 FENNEL_END_NAMESPACE
00182
00183 #endif
00184
00185
00186