예제 #1
0
IOperand		*Operand<T>::operator-(const IOperand &rhs) const
{
    Operand               first;
    Operand               second;
    eOperandType          new_type;

    first = *this;
    second = rhs;
    new_type = select_type(first.getType(), second.getType());
    if (new_type == Int8)
        return (createOperand(new_type, convint8_t(first.toString()) -
                              convint8_t(second.toString())));
    if (new_type == Int16)
        return (createOperand(new_type, convint16_t(first.toString()) -
                              convint16_t(second.toString())));
    if (new_type == Int32)
        return (createOperand(new_type, convint32_t(first.toString()) -
                              convint32_t(second.toString())));
    if (new_type == Float)
        return (createOperand(new_type, convinfloat(first.toString()) -
                              convinfloat(second.toString())));
    if (new_type == Double)
        return (createOperand(new_type, convindouble(first.toString()) -
                              convindouble(second.toString())));
    return (NULL);
}
AbstractNode *NodeFactory::create(enum NodeType type, std::string &token)
{
	switch (type)
	{
	case OPERATOR_OPEN_BRACKET:
		return createOpenBracket();
		break;
	case OPERATOR_CLOSE_BRACKET:
		return createCloseBracket();
		break;
	case OPERATOR_MUL:
		return createMul();
		break;
	case OPERATOR_MINUS:
		return createMinus();
		break;
	case OPERATOR_DIV:
		return createDiv();
		break;
	case OPERATOR_ADD:
		return createAdd();
		break;
	case OPERAND:
		return createOperand(token);
		break;
	}
	return NULL;
}
예제 #3
0
Inst* OSR::createNewVarInst(SsaOpnd* old, Type* type,
                            Inst* old_inst, SsaOpnd* rc, Operation op) {
    InstFactory& instFactory = irManager.getInstFactory();
    OpndManager& opndManager = irManager.getOpndManager();

    VarOpnd* oldVar = old->asSsaVarOpnd()->getVar();
    VarOpnd* newVar = createOperand(type, oldVar, rc, op);
    SsaVarOpnd* newSsaVar = opndManager.createSsaVarOpnd(newVar);
    if (old_inst->getOpcode() == Op_StVar) {
        return instFactory.makeStVar(newSsaVar,
                                     old_inst->getSrc(0)->asSsaOpnd());
    } else {
        U_32 num = old_inst->getNumSrcOperands();
        Opnd** newOpnds = new(mm) Opnd* [num];
        for (U_32 i = 0; i < num; i++) {
            newOpnds[i] = old_inst->getSrc(i)->asSsaOpnd();
        }
        return (PhiInst*)instFactory.makePhi(newSsaVar, num, newOpnds);
    }
}
예제 #4
0
std::shared_ptr<Predicate> PredicateParser::createPredicate(const std::string& fullExpression, int idxOpFrom, int idxOpTo, size_t from, size_t to)
{
    if(idxOpFrom  >= idxOpTo)
    {
        unpackBrackets(fullExpression, from, to);
        PredicateParser childParaser(false);
        childParaser.parse(fullExpression, from, to);
        return childParaser.getResult();
    }
    else
    {
        auto idxLowerest = idxOpFrom;
        for(auto idxCur = idxLowerest + 1; idxCur < idxOpTo; ++idxCur)
        {
            if(mOperators[idxLowerest] > mOperators[idxCur])
            {
                idxLowerest = idxCur;
            }
        }

        auto& opInfo = mOperators[idxLowerest];
        if(mOperators[idxLowerest].isUnary())
        {
            auto pChild = createPredicate(fullExpression, idxLowerest + 1, idxOpTo, opInfo.to, to);
            auto pUnary = createUnary(opInfo, pChild);
            return pUnary;
        }
        else
        {
            auto leftFrom = from;
            auto rightTo = to;

            auto pArthemetic = createArthemeticOp(opInfo);
            if(nullptr != pArthemetic)
            {
                auto pLeft = createOperand(fullExpression, idxOpFrom, idxLowerest, leftFrom, opInfo.from);
                auto pRight = createOperand(fullExpression, idxLowerest + 1, idxOpTo, opInfo.to, rightTo);

                pArthemetic->setLeft(pLeft);
                pArthemetic->setRight(pRight);

                return pArthemetic;
            }

            auto pCompare = createCompOp(opInfo);
            if(nullptr != pCompare)
            {
                auto pLeft = createOperand(fullExpression, idxOpFrom, idxLowerest, leftFrom, opInfo.from);
                auto pRight = createOperand(fullExpression, idxLowerest + 1, idxOpTo, opInfo.to, rightTo);

                pCompare->setLeft(pLeft);
                pCompare->setRight(pRight);

                return pCompare;
            }

            auto pLogic = createLogicOp(opInfo);
            if(nullptr != pLogic)
            {
                auto pLeft = createPredicate(fullExpression, idxOpFrom, idxLowerest, leftFrom, opInfo.from);
                auto pRight = createPredicate(fullExpression, idxLowerest + 1, idxOpTo, opInfo.to, rightTo);

                pLogic->setLeft(pLeft);
                pLogic->setRight(pRight);

                return pLogic;
            }

            throw std::logic_error("unknow operator");
        }
    }
}