| 355 | //------------------------------------------------------------------------- |
| 356 | |
| 357 | void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks) |
| 358 | { |
| 359 | // Alloc stream |
| 360 | U32 numLineBreaks = getNumLineBreaks(); |
| 361 | *stream = new U32[mCodePos + (numLineBreaks * 2)]; |
| 362 | dMemset(*stream, '\0', mCodePos + (numLineBreaks * 2)); |
| 363 | *size = mCodePos; |
| 364 | |
| 365 | // Dump chunks & line breaks |
| 366 | U32 outBytes = mCodePos * sizeof(U32); |
| 367 | U8 *outPtr = *((U8**)stream); |
| 368 | for (CodeData *itr = mCode; itr != NULL; itr = itr->next) |
| 369 | { |
| 370 | U32 bytesToCopy = itr->size > outBytes ? outBytes : itr->size; |
| 371 | dMemcpy(outPtr, itr->data, bytesToCopy); |
| 372 | outPtr += bytesToCopy; |
| 373 | outBytes -= bytesToCopy; |
| 374 | } |
| 375 | |
| 376 | *lineBreaks = *stream + mCodePos; |
| 377 | dMemcpy(*lineBreaks, mBreakLines.address(), sizeof(U32) * mBreakLines.size()); |
| 378 | |
| 379 | // Apply patches on top |
| 380 | for (U32 i=0; i<mPatchList.size(); i++) |
| 381 | { |
| 382 | PatchEntry &e = mPatchList[i]; |
| 383 | (*stream)[e.addr] = e.value; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | //------------------------------------------------------------------------- |
| 388 | |