diff --git a/src/Bytecode.hh b/src/Bytecode.hh index 3b36d4f5b6626b5fde2b1dcf76916ac557414111..3272933314fe7b6089549c9f45972d1d9f4df10e 100644 --- a/src/Bytecode.hh +++ b/src/Bytecode.hh @@ -29,10 +29,6 @@ #include "CommonEnums.hh" -#ifdef BYTECODE_MEX -# include <dynmex.h> -#endif - using namespace std; // The different opcodes of bytecode @@ -1095,349 +1091,4 @@ BytecodeWriter &operator<<(BytecodeWriter &code_file, const FCALL_ &instr); template<> BytecodeWriter &operator<<(BytecodeWriter &code_file, const FBEGINBLOCK_ &instr); - -#ifdef BYTECODE_MEX -using instructions_list_t = vector<BytecodeInstruction *>; -class CodeLoad -{ -private: - char *code; - int nb_blocks; - vector<size_t> begin_block; -public: - - int - get_block_number() const - { - return nb_blocks; - }; - - size_t - get_begin_block(int block) const - { - return begin_block[block]; - } - void * - get_current_code() const - { - return code; - }; - instructions_list_t - get_op_code(const filesystem::path &codfile) - { - instructions_list_t tags_liste; - ifstream CompiledCode; - streamoff Code_Size; - CompiledCode.open(codfile, ios::in | ios::binary| ios::ate); - if (!CompiledCode.is_open()) - return tags_liste; - Code_Size = CompiledCode.tellg(); - CompiledCode.seekg(ios::beg); - code = static_cast<char *>(mxMalloc(Code_Size)); - CompiledCode.seekg(0); - CompiledCode.read(reinterpret_cast<char *>(code), Code_Size); - CompiledCode.close(); - nb_blocks = 0; - bool done = false; - int instruction = 0; - while (!done) - { - BytecodeInstruction *instr {reinterpret_cast<BytecodeInstruction *>(code)}; - switch (*reinterpret_cast<Tags *>(code)) - { - case Tags::FLDZ: -# ifdef DEBUGL - mexPrintf("FLDZ = %d size = %d\n", Tags::FLDZ, sizeof(FLDZ_)); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDZ_); - break; - case Tags::FEND: -# ifdef DEBUGL - mexPrintf("FEND\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FEND_); - done = true; - break; - case Tags::FENDBLOCK: -# ifdef DEBUGL - mexPrintf("FENDBLOCK\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FENDBLOCK_); - break; - case Tags::FENDEQU: -# ifdef DEBUGL - mexPrintf("FENDEQU\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FENDEQU_); - break; - case Tags::FDIMT: -# ifdef DEBUGL - mexPrintf("FDIMT = %d size = %d\n", Tags::FDIMT, sizeof(FDIMT_)); -# endif - tags_liste.push_back(instr); - code += sizeof(FDIMT_); - break; - case Tags::FDIMST: -# ifdef DEBUGL - mexPrintf("FDIMST\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FDIMST_); - break; - case Tags::FNUMEXPR: -# ifdef DEBUGL - mexPrintf("FNUMEXPR\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FNUMEXPR_); - break; - case Tags::FLDC: -# ifdef DEBUGL - mexPrintf("FLDC\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDC_); - break; - case Tags::FLDU: -# ifdef DEBUGL - mexPrintf("FLDU\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDU_); - break; - case Tags::FLDSU: -# ifdef DEBUGL - mexPrintf("FLDSU\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDSU_); - break; - case Tags::FLDR: -# ifdef DEBUGL - mexPrintf("FLDR\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDR_); - break; - case Tags::FLDT: -# ifdef DEBUGL - mexPrintf("FLDT\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDT_); - break; - case Tags::FLDST: -# ifdef DEBUGL - mexPrintf("FLDST\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDST_); - break; - case Tags::FSTPT: -# ifdef DEBUGL - mexPrintf("FSTPT = %d size = %d\n", Tags::FSTPT, sizeof(FSTPT_)); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPT_); - break; - case Tags::FSTPST: -# ifdef DEBUGL - mexPrintf("FSTPST\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPST_); - break; - case Tags::FSTPR: -# ifdef DEBUGL - mexPrintf("FSTPR\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPR_); - break; - case Tags::FSTPU: -# ifdef DEBUGL - mexPrintf("FSTPU\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPU_); - break; - case Tags::FSTPSU: -# ifdef DEBUGL - mexPrintf("FSTPSU\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPSU_); - break; - case Tags::FSTPG: -# ifdef DEBUGL - mexPrintf("FSTPG\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPG_); - break; - case Tags::FSTPG2: -# ifdef DEBUGL - mexPrintf("FSTPG2\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPG2_); - break; - case Tags::FSTPG3: -# ifdef DEBUGL - mexPrintf("FSTPG3\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPG3_); - break; - case Tags::FUNARY: -# ifdef DEBUGL - mexPrintf("FUNARY\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FUNARY_); - break; - case Tags::FBINARY: -# ifdef DEBUGL - mexPrintf("FBINARY\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FBINARY_); - break; - case Tags::FTRINARY: -# ifdef DEBUGL - mexPrintf("FTRINARY\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FTRINARY_); - break; - case Tags::FLDVS: -# ifdef DEBUGL - mexPrintf("FLDVS\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDVS_); - break; - case Tags::FLDSV: -# ifdef DEBUGL - mexPrintf("FLDSV\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDSV_); - break; - case Tags::FSTPSV: -# ifdef DEBUGL - mexPrintf("FSTPSV\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPSV_); - break; - case Tags::FLDV: -# ifdef DEBUGL - mexPrintf("FLDV\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDV_); - break; - case Tags::FSTPV: -# ifdef DEBUGL - mexPrintf("FSTPV\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPV_); - break; - case Tags::FBEGINBLOCK: -# ifdef DEBUGL - mexPrintf("FBEGINBLOCK\n"); -# endif - { - auto *fbegin_block = new FBEGINBLOCK_{code}; - begin_block.push_back(tags_liste.size()); - tags_liste.push_back(fbegin_block); - nb_blocks++; - } - break; - case Tags::FJMPIFEVAL: -# ifdef DEBUGL - mexPrintf("FJMPIFEVAL\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FJMPIFEVAL_); - break; - case Tags::FJMP: -# ifdef DEBUGL - mexPrintf("FJMP\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FJMP_); - break; - case Tags::FCALL: - { -# ifdef DEBUGL - mexPrintf("FCALL\n"); -# endif - auto *fcall = new FCALL_{code}; - tags_liste.push_back(fcall); -# ifdef DEBUGL - mexPrintf("FCALL finish\n"); mexEvalString("drawnow;"); - mexPrintf("-- *code=%d\n", *code); mexEvalString("drawnow;"); -# endif - } - break; - case Tags::FLDTEF: -# ifdef DEBUGL - mexPrintf("FLDTEF\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDTEF_); - break; - case Tags::FSTPTEF: -# ifdef DEBUGL - mexPrintf("FSTPTEF\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPTEF_); - break; - case Tags::FLDTEFD: -# ifdef DEBUGL - mexPrintf("FLDTEFD\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDTEFD_); - break; - case Tags::FSTPTEFD: -# ifdef DEBUGL - mexPrintf("FSTPTEFD\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPTEFD_); - break; - case Tags::FLDTEFDD: -# ifdef DEBUGL - mexPrintf("FLDTEFDD\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FLDTEFDD_); - break; - case Tags::FSTPTEFDD: -# ifdef DEBUGL - mexPrintf("FSTPTEFDD\n"); -# endif - tags_liste.push_back(instr); - code += sizeof(FSTPTEFDD_); - break; - default: - mexPrintf("Unknown Tag value=%d code=%x\n", *code, code); - done = true; - } - instruction++; - } - return tags_liste; - }; -}; -#endif // BYTECODE_MEX - #endif // _BYTECODE_HH