#pragma once #include #include #include void AddLocalVarAddrSchedule(); void ObpPlus( int step = 1 ); class UserProc; class Schedule { public: enum Type { None = 10000, GlobalVar, // グローバル変数スケジュール LocalVar, // ローカル変数スケジュール DataTable, // データテーブル スケジュール Relocation, // リロケーション情報スケジュール UserProc, // ユーザ定義関数呼び出し側スケジュール AddressOf, // ユーザ定義関数位置スケジュール }; private: Type type; long offset; union{ LONG_PTR lpValue; const ::UserProc *pUserProc; }; // XMLシリアライズ用 private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP( type ); ar & BOOST_SERIALIZATION_NVP( offset ); } public: Schedule() { } Schedule( Type type, long offset ) : type( type ) , offset( offset ) , lpValue( 0 ) { } Schedule( const ::UserProc *pUserProc, long offest ) : type( Schedule::UserProc ) , offset( offset ) , pUserProc( pUserProc ) { } ~Schedule() { } void SpecifyAddressOf() { if( type != Schedule::UserProc ) { SetError(); } type = Schedule::AddressOf; } }; typedef std::vector Schedules; class NativeCode { int allocateSize; char *codeBuffer; int size; Schedules schedules; // XMLシリアライズ用 private: friend class boost::serialization::access; BOOST_SERIALIZATION_SPLIT_MEMBER(); template void load(Archive& ar, const unsigned int version) { std::string code; ar & BOOST_SERIALIZATION_NVP( code ); ar & BOOST_SERIALIZATION_NVP( size ); ar & BOOST_SERIALIZATION_NVP( schedules ); // 読み込み後の処理 Realloc( size ); for( int i=0; i void save(Archive& ar, const unsigned int version) const { // 保存準備 char *tempCode = (char *)malloc( (size+1) * 3 ); for( int i=0; icodeBuffer+codePos) = newLongValue; } void OverwriteOld( int _obpOld, long newLongValue ) { // 未完成 extern char *OpBuffer; *(long *)(OpBuffer+_obpOld) = newLongValue; } void Put( const char *codeBuffer, int size ) { Realloc( size ); memcpy( this->codeBuffer + this->size, codeBuffer, size ); this->size += size; // 未完成 extern char *OpBuffer; extern int obp; memcpy( OpBuffer + obp, codeBuffer, size ); ObpPlus( size ); } void Put( const NativeCode &nativeCode ) { Put( nativeCode.codeBuffer, nativeCode.size ); } void Put( _int64 i64data ) { Put( (const char *)(&i64data), sizeof(_int64) ); } void Put( long l, Schedule::Type scheduleType = Schedule::None ) { if( scheduleType != Schedule::None ) { schedules.push_back( Schedule( scheduleType, size ) ); } *((long *)(codeBuffer+size))=l; size += sizeof(long); // 未完成 switch( scheduleType ) { case Schedule::None: // 何もしない break; case Schedule::GlobalVar: extern CSchedule *pobj_GlobalVarSchedule; pobj_GlobalVarSchedule->add(); break; case Schedule::LocalVar: AddLocalVarAddrSchedule(); break; case Schedule::DataTable: extern CSchedule *pobj_DataTableSchedule; pobj_DataTableSchedule->add(); break; case Schedule::Relocation: // 未完成 break; default: Jenga::Throw( "scheduleTypeが無効な値を保持している" ); break; } extern char *OpBuffer; extern int obp; *((long *)(OpBuffer+obp))=l; ObpPlus( sizeof(long) ); } void PutUserProcSchedule( const UserProc *pUserProc, bool isCall ); void Put( short s ) { Put( (const char *)(&s), sizeof(short) ); } void Put( char c ) { codeBuffer[size++] = c; Realloc(); // 未完成 extern char *OpBuffer; extern int obp; OpBuffer[obp]=c; ObpPlus(); } };