Exemplo n.º 1
0
/**
 * Print a getelementptr instruction.
 *
 * @param v  the aggregate data structure to index
 * @param i  an iterator to the first type indexed by the instruction
 * @param e  an iterator specifying the upper bound on the types indexed by the
 *           instruction
 */
void JVMWriter::printGepInstruction(const Value *v,
                                    gep_type_iterator i,
                                    gep_type_iterator e) {
    // load address
    printCastInstruction(Instruction::IntToPtr, v, NULL, v->getType());

    // calculate offset
    for(; i != e; i++) {
        unsigned int size = 0;
        const Value *indexValue = i.getOperand();

        if(const StructType *structTy = dyn_cast<StructType>(*i)) {
            for(unsigned int f = 0,
                    fieldIndex = cast<ConstantInt>(indexValue)->getZExtValue();
                    f < fieldIndex; f++)
                size = alignOffset(
                           size + targetData->getTypeAllocSize(
                               structTy->getContainedType(f)),
                           targetData->getABITypeAlignment(
                               structTy->getContainedType(f + 1)));
            printPtrLoad(size);
            printSimpleInstruction("iadd");
        } else {
            if(const SequentialType *seqTy = dyn_cast<SequentialType>(*i))
                size = targetData->getTypeAllocSize(seqTy->getElementType());
            else
                size = targetData->getTypeAllocSize(*i);

            if(const ConstantInt *c = dyn_cast<ConstantInt>(indexValue)) {
                // constant optimisation
                if(c->isNullValue()) {
                    // do nothing
                } else if(c->getValue().isNegative()) {
                    printPtrLoad(c->getValue().abs().getZExtValue() * size);
                    printSimpleInstruction("isub");
                } else {
                    printPtrLoad(c->getZExtValue() * size);
                    printSimpleInstruction("iadd");
                }
            } else {
                printPtrLoad(size);
                printCastInstruction(Instruction::IntToPtr, indexValue,
                                     NULL, indexValue->getType());
                printSimpleInstruction("imul");
                printSimpleInstruction("iadd");
            }
        }
    }
}
Exemplo n.º 2
0
void TabPanel::updateLayout(void)
{
    Pnt2f InsideInsetsTopLeft,InsideInsetsBottomRight;
    getInsideInsetsBounds(InsideInsetsTopLeft,InsideInsetsBottomRight);

    UInt16 AxisIndex(0);
    if (getTabPlacement() == PLACEMENT_EAST || getTabPlacement() == PLACEMENT_WEST)
    {
        AxisIndex=1;
    }
    Real32 largestMinorAxis(0.0f);
    Real32 cumMajorAxis(0.0f);
    Pnt2f alignOffset(0.0f,0.0f);
    Vec2f offset(0.0f,0.0f);

    Vec2f TabBorderTopLeftWidth, TabBorderBottomRightWidth;
    calculateMaxTabBorderLengths(TabBorderTopLeftWidth[0], TabBorderBottomRightWidth[0],TabBorderTopLeftWidth[1], TabBorderBottomRightWidth[1]);

    // first layout all of the tabs
    // naturally the alignments and such is necessary
    // on the first sweep, get the maximum size and cumLength
    const Real32 TabMajorAxisSpacing(5.0f);
    Vec2f TabReqSize;
    for (UInt32 i=0; i < getMFTabs()->size(); ++i)
    {
        TabReqSize = getTabs(i)->getRequestedSize() + Vec2f(getTabBorderInsets().x() + getTabBorderInsets().y(),
                                                            getTabBorderInsets().z() + getTabBorderInsets().w());
        cumMajorAxis += TabReqSize[AxisIndex];
        if (TabReqSize[(AxisIndex+1)%2] > largestMinorAxis)
        {
            largestMinorAxis = TabReqSize[(AxisIndex+1)%2];
        }
    }
    cumMajorAxis += TabMajorAxisSpacing * 2.0f * getMFTabs()->size();
    cumMajorAxis += static_cast<Real32>(getMFTabs()->size()) * (TabBorderTopLeftWidth[AxisIndex] + TabBorderBottomRightWidth[AxisIndex]);
    largestMinorAxis += (TabBorderTopLeftWidth[(AxisIndex+1)%2] + TabBorderBottomRightWidth[(AxisIndex+1)%2]);


    // set up the alignment and offset
    Vec2f TabSize;
    TabSize[AxisIndex] = cumMajorAxis;
    TabSize[(AxisIndex+1)%2] = largestMinorAxis;
    Vec2f Alignment;
    Alignment[(AxisIndex+1)%2] = getTabAlignment();
    switch(getTabPlacement())
    {
        case PLACEMENT_SOUTH:
        case PLACEMENT_EAST:
            Alignment[AxisIndex] = 1.0;
            break;
        case PLACEMENT_NORTH:
        case PLACEMENT_WEST:
            Alignment[AxisIndex] = 0.0;
            break;
    }
    alignOffset = calculateAlignment(InsideInsetsTopLeft, (InsideInsetsBottomRight-InsideInsetsTopLeft),TabSize,Alignment.x(),Alignment.y());
    offset = Vec2f(InsideInsetsTopLeft);
    offset[(AxisIndex+1)%2] += TabBorderTopLeftWidth[(AxisIndex+1)%2];

    // set sizes and positions of all tabs
    Vec2f Size;
    Pnt2f Pos;
    for (UInt32 i=0; i < getMFTabs()->size(); ++i)
    {
        offset[AxisIndex] += TabBorderTopLeftWidth[AxisIndex];
        Size = getTabs(i)->getRequestedSize() + Vec2f(getTabBorderInsets().x() + getTabBorderInsets().y(),
                                                      getTabBorderInsets().z() + getTabBorderInsets().w());
        if(getTabs(i)->getSize() != Size)
        {
            getTabs(i)->setSize(Size);
        }
        Pos = alignOffset + offset;
        if(getTabs(i)->getPosition() != Pos)
        {
            getTabs(i)->setPosition(Pos);
        }
        offset[AxisIndex] += getTabs(i)->getSize()[AxisIndex] + TabBorderBottomRightWidth[AxisIndex];
    }

    if((getSelectedIndex()+1) > getMFTabContents()->size())
    {
        setSelectedIndex(getMFTabContents()->size()-1);
    }
    if(getMFTabContents()->size() > 0 && getSelectedIndex() != -1)
    {
        Vec2f ContentBorderTopLeftWidth, ContentBorderBottomRightWidth;
        calculateContentBorderLengths(getContentBorder(), ContentBorderTopLeftWidth[0], ContentBorderBottomRightWidth[0],ContentBorderTopLeftWidth[1], ContentBorderBottomRightWidth[1]);
        // now set size and position of the active tab's contents
        offset = Vec2f(InsideInsetsTopLeft);
        if (getTabPlacement() == PLACEMENT_NORTH || getTabPlacement() == PLACEMENT_WEST)
        {
            offset[(AxisIndex+1)%2] += largestMinorAxis;
        }
        Size = InsideInsetsBottomRight-InsideInsetsTopLeft-(ContentBorderTopLeftWidth + ContentBorderBottomRightWidth);
        Size[(AxisIndex+1)%2] -= TabSize[(AxisIndex+1)%2];
        if(getTabContents(getSelectedIndex())->getSize() != Size)
        {
            getTabContents(getSelectedIndex())->setSize(Size);
        }
        Pos = Pnt2f(0.0f,0.0f) + offset + ContentBorderTopLeftWidth;
        if(getTabContents(getSelectedIndex())->getPosition() != Pos)
        {
            getTabContents(getSelectedIndex())->setPosition(Pos);
        }
    }
}
Exemplo n.º 3
0
inline uintptr_t memoryAlignOffset(const void * _ptr)
{
    return alignOffset(_ptr, sizeof(T));
}
Exemplo n.º 4
0
static void* ObjectGetDataPtr(Object* o) {
  unsigned long long offset = (unsigned long long) &o->data[0];
  unsigned long long dataLocation = alignOffset(offset, o->type->alignment);
  return (void*) dataLocation;
}