Example #1
0
VarCell* Context::_newStackCell(uint32_t size, uint32_t alignment) {
  VarCell* cell = static_cast<VarCell*>(_zoneAllocator.alloc(sizeof(VarCell)));
  if (cell == nullptr)
    goto _NoMemory;

  if (alignment == 0)
    alignment = BaseContext_getDefaultAlignment(size);

  if (alignment > 64)
    alignment = 64;

  ASMJIT_ASSERT(Utils::isPowerOf2(alignment));
  size = Utils::alignTo<uint32_t>(size, alignment);

  // Insert it sorted according to the alignment and size.
  {
    VarCell** pPrev = &_memStackCells;
    VarCell* cur = *pPrev;

    while (cur != nullptr) {
      if ((cur->getAlignment() > alignment) ||
          (cur->getAlignment() == alignment && cur->getSize() > size)) {
        pPrev = &cur->_next;
        cur = *pPrev;
        continue;
      }

      break;
    }

    cell->_next = cur;
    cell->_offset = 0;
    cell->_size = size;
    cell->_alignment = alignment;

    *pPrev = cell;
    _memStackCellsUsed++;

    _memMaxAlign = Utils::iMax<uint32_t>(_memMaxAlign, alignment);
    _memStackTotal += size;
  }

  return cell;

_NoMemory:
  _compiler->setLastError(kErrorNoHeapMemory);
  return nullptr;
}
MemCell* Context::_newStackCell(uint32_t size, uint32_t alignment) {
  MemCell* cell = static_cast<MemCell*>(_baseZone.alloc(sizeof(MemCell)));
  if (cell == NULL)
    goto _NoMemory;

  if (alignment == 0)
    alignment = BaseContext_getDefaultAlignment(size);

  if (alignment > 64)
    alignment = 64;

  ASMJIT_ASSERT(IntUtil::isPowerOf2(alignment));
  size = IntUtil::alignTo<uint32_t>(size, alignment);

  // Insert it sorted according to the alignment and size.
  {
    MemCell** pPrev = &_memStackCells;
    MemCell* cur = *pPrev;

    for (cur = *pPrev; cur != NULL; cur = cur->_next) {
      if (cur->getAlignment() > alignment)
        continue;
      if (cur->getAlignment() == alignment && cur->getSize() > size)
        continue;
      break;
    }

    cell->_next = cur;
    cell->_offset = 0;
    cell->_size = size;
    cell->_alignment = alignment;

    *pPrev = cell;
    _memStackCellsUsed++;

    _memMaxAlign = IntUtil::iMax<uint32_t>(_memMaxAlign, alignment);
    _memStackTotal += size;
  }

  return cell;

_NoMemory:
  _compiler->setError(kErrorNoHeapMemory);
  return NULL;
}