| 505 | //------------------------------------------------------------------------- |
| 506 | |
| 507 | void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks) |
| 508 | { |
| 509 | // Alloc stream |
| 510 | U32 numLineBreaks = getNumLineBreaks(); |
| 511 | *stream = new U32[mCodePos + (numLineBreaks * 2)]; |
| 512 | dMemset(*stream, '\0', mCodePos + (numLineBreaks * 2)); |
| 513 | *size = mCodePos; |
| 514 | |
| 515 | // Dump chunks & line breaks |
| 516 | U32 outBytes = mCodePos * sizeof(U32); |
| 517 | U8 *outPtr = *((U8**)stream); |
| 518 | for (CodeData *itr = mCode; itr != NULL; itr = itr->next) |
| 519 | { |
| 520 | U32 bytesToCopy = itr->size > outBytes ? outBytes : itr->size; |
| 521 | dMemcpy(outPtr, itr->data, bytesToCopy); |
| 522 | outPtr += bytesToCopy; |
| 523 | outBytes -= bytesToCopy; |
| 524 | } |
| 525 | |
| 526 | *lineBreaks = *stream + mCodePos; |
| 527 | dMemcpy(*lineBreaks, mBreakLines.address(), sizeof(U32) * mBreakLines.size()); |
| 528 | |
| 529 | // Apply patches on top |
| 530 | for (U32 i = 0; i<mPatchList.size(); i++) |
| 531 | { |
| 532 | PatchEntry &e = mPatchList[i]; |
| 533 | (*stream)[e.addr] = e.value; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | //------------------------------------------------------------------------- |
| 538 | |