Changeset 287 in dev for trunk/abdev/BasicCompiler_Common/include
- Timestamp:
- Aug 16, 2007, 7:55:02 PM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler_Common/include
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r282 r287 455 455 void PutOld( long l, Schedule::Type scheduleType ) 456 456 { 457 pNativeCode->Put ( l, scheduleType );457 pNativeCode->PutEx( l, scheduleType ); 458 458 } 459 459 const PertialSchedule *PutOld( long l, bool isPertialSchedule ) … … 465 465 pPertialSchedule = pertialSchedules.back(); 466 466 } 467 pNativeCode->Put ( l, Schedule::None );467 pNativeCode->PutEx( l, Schedule::None ); 468 468 return pPertialSchedule; 469 469 } 470 470 void PutOld( const NativeCode &nativeCode ) 471 471 { 472 pNativeCode->Put ( nativeCode );472 pNativeCode->PutEx( nativeCode ); 473 473 } 474 474 void PutOld( char c ) -
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r282 r287 6 6 7 7 #include <BoostSerializationSupport.h> 8 9 #include <Binary.h> 8 10 9 11 class UserProc; … … 219 221 typedef std::vector<SourceLine> SourceLines; 220 222 221 class NativeCode 223 class NativeCode : public Binary 222 224 { 223 int allocateSize;224 char *codeBuffer;225 int size;226 227 225 // リンカで解決しなければならないスケジュール 228 226 Schedules schedules; … … 234 232 private: 235 233 friend class boost::serialization::access; 236 BOOST_SERIALIZATION_SPLIT_MEMBER(); 237 template<class Archive> void load(Archive& ar, const unsigned int version) 234 template<class Archive> void serialize(Archive& ar, const unsigned int version) 238 235 { 239 236 trace_for_serialize( "serializing(load) - NativeCode" ); 240 237 241 std::string code; 242 ar & BOOST_SERIALIZATION_NVP( code ); 243 ar & BOOST_SERIALIZATION_NVP( size ); 238 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Binary ); 244 239 ar & BOOST_SERIALIZATION_NVP( schedules ); 245 240 ar & BOOST_SERIALIZATION_NVP( sourceLines ); 246 247 // 読み込み後の処理248 Realloc( size );249 for( int i=0; i<size; i++ )250 {251 ULONG_PTR l1 = ( ( code[i*3] >= 'a' ) ? ( code[i*3] - 'a' + 0x0a ) : ( code[i*3] - '0' ) ) * 0x10;252 ULONG_PTR l2 = ( code[i*3+1] >= 'a' ) ? ( code[i*3+1] - 'a' + 0x0a ) : ( code[i*3+1] - '0' );253 ULONG_PTR l = l1 + l2;254 codeBuffer[i] = static_cast<char>(l);255 }256 }257 template<class Archive> void save(Archive& ar, const unsigned int version) const258 {259 trace_for_serialize( "serializing(save) - NativeCode" );260 261 // 保存準備262 char *tempCode = (char *)calloc( (size+1) * 3, 1 );263 for( int i=0; i<size; i++ )264 {265 char temp[32];266 sprintf( temp, "%02x,", (unsigned char)codeBuffer[i] );267 tempCode[i*3] = temp[0];268 tempCode[i*3+1] = temp[1];269 tempCode[i*3+2] = temp[2];270 }271 272 std::string code = tempCode;273 free( tempCode );274 275 ar & BOOST_SERIALIZATION_NVP( code );276 ar & BOOST_SERIALIZATION_NVP( size );277 ar & BOOST_SERIALIZATION_NVP( schedules );278 ar & BOOST_SERIALIZATION_NVP( sourceLines );279 }280 281 282 void Realloc( int newSize )283 {284 if( allocateSize < newSize + 8192 )285 {286 while( allocateSize < newSize + 8192 )287 {288 allocateSize += 8192;289 }290 codeBuffer = (char *)realloc( codeBuffer, allocateSize );291 }292 241 } 293 242 294 243 public: 295 244 NativeCode() 296 : allocateSize( 8192 ) 297 , codeBuffer( (char *)malloc( allocateSize ) ) 298 , size( 0 ) 245 : Binary() 299 246 { 300 247 } 301 248 NativeCode( const NativeCode &nativeCode ) 302 : allocateSize( 8192 ) 303 , codeBuffer( (char *)malloc( allocateSize ) ) 304 , size( 0 ) 305 { 306 Put( nativeCode ); 249 : Binary() 250 { 251 PutEx( nativeCode ); 307 252 } 308 253 NativeCode( const char *codeBuffer, int size ) 309 : allocateSize( 8192 ) 310 , codeBuffer( (char *)malloc( allocateSize ) ) 311 , size( 0 ) 312 { 313 Put( codeBuffer, size ); 254 : Binary( codeBuffer, size ) 255 { 314 256 } 315 257 ~NativeCode() 316 258 { 317 free( codeBuffer );318 }319 void Clear()320 {321 size = 0;322 259 } 323 260 … … 325 262 { 326 263 Clear(); 327 Put( nativeCode ); 328 } 329 330 const char *GetCodeBuffer() const 331 { 332 return codeBuffer; 333 } 334 int GetSize() const 335 { 336 return size; 337 } 264 PutEx( nativeCode ); 265 } 266 338 267 const Schedules &GetSchedules() const 339 268 { … … 341 270 } 342 271 343 long GetLong( int codePos ) const 344 { 345 return *(long *)(this->codeBuffer+codePos); 346 } 347 348 void Overwrite( int codePos, char c ) 349 { 350 codeBuffer[codePos] = c; 351 } 352 void Overwrite( int codePos, long newLongValue ) 353 { 354 *(long *)(this->codeBuffer+codePos) = newLongValue; 355 } 356 357 void Put( const char *codeBuffer, int size ) 358 { 359 Realloc( this->size + size ); 360 361 memcpy( this->codeBuffer + this->size, codeBuffer, size ); 362 this->size += size; 363 } 364 void Put( const NativeCode &nativeCode ); 365 void Put( _int64 i64data ) 366 { 367 Put( (const char *)(&i64data), sizeof(_int64) ); 368 } 369 void Put( long l, Schedule::Type scheduleType = Schedule::None ) 272 void PutEx( const NativeCode &nativeCode ); 273 void PutEx( long l, Schedule::Type scheduleType ) 370 274 { 371 275 if( scheduleType != Schedule::None ) 372 276 { 373 schedules.push_back( Schedule( scheduleType, size ) ); 374 } 375 376 *((long *)(codeBuffer+size))=l; 377 size += sizeof(long); 277 schedules.push_back( Schedule( scheduleType, GetSize() ) ); 278 } 279 280 Put( l ); 378 281 } 379 282 void PutUserProcSchedule( const UserProc *pUserProc, bool isCall ); 380 283 void PutDllProcSchedule( const DllProc *pDllProc ); 381 284 void PutVtblSchedule( const CClass *pClass ); 382 void Put( short s )383 {384 Put( (const char *)(&s), sizeof(short) );385 }386 void Put( char c )387 {388 Realloc( size + 1 );389 codeBuffer[size++] = c;390 }391 285 392 286 const SourceLines &GetSourceLines() const -
trunk/abdev/BasicCompiler_Common/include/Variable.h
r275 r287 254 254 const Variable *Find( const Symbol &symbol )const; 255 255 256 void Add( Variable *pVar );256 void Add( Variable *pVar, bool isResetOffsetAddress = true ); 257 257 258 258 int GetAllSize() const … … 276 276 } 277 277 }; 278 279 class GlobalVar : public Variable 280 { 281 BYTE *initBuffer; 282 public: 283 GlobalVar() 284 { 285 initBuffer = (BYTE *)malloc( 1 ); 286 } 287 ~GlobalVar() 288 { 289 free( initBuffer ); 290 } 291 };
Note:
See TracChangeset
for help on using the changeset viewer.