Пример #1
0
Value* GreaterThanEqualExpression::getValue() {
    assert(leftExpression != NULL);
    assert(rightExpression != NULL);
    assert(leftExpression->getType() == rightExpression->getType());

    IRBuilder<>* builder = codegen::getBuilder();
    int c;
    if(leftExpression->getType() != COLEXPRESSION) {
        c = leftExpression->getType();
    } else {
        c = convertDTtoET(leftExpression->getDataType());
    }
    switch(c) {
        case LONGVALUEEXPRESSION:
            return builder->CreateICmpSGE(leftExpression->getValue(), rightExpression->getValue());
        case DOUBLEVALUEEXPRESSION:
            return builder->CreateFCmpOGE(leftExpression->getValue(), rightExpression->getValue());
        case STRINGVALUEEXPRESSION:
        case DATEVALUEEXPRESSION:
            return codegen::stringCmp(leftExpression->getValue(), rightExpression->getValue(), GREATERTHANEQUALEXPRESSION);
        default:
            cout << "Unknown expression type!" << endl;
            exit(-1);
    }

    return NULL;
}
Пример #2
0
/*
 * float t1(float p) { return (p>0)?p:-p; }
 */
Function *createAbs(Module *m, LLVMContext &Context) {
    Type *floatTy = Type::getFloatTy(Context);
    Type *ArgTypes[] = { floatTy };
    FunctionType *Ty = FunctionType::get(floatTy, ArgTypes, false);
    Function *func = Function::Create(Ty,
            GlobalValue::ExternalLinkage, "fabs", m);

    BasicBlock *bb = BasicBlock::Create(Context, "EntryBlock", func);
    IRBuilder<> *builder = new IRBuilder<>(bb);

    Value *arg0 = func->arg_begin();arg0->setName("arg0");
    Value *v    = builder->CreateFCmpOGE(arg0, ConstantFP::get(floatTy, 0.0));
    Value *v0   = builder->CreateFNeg(arg0);
    Value *ret  = builder->CreateSelect(v, arg0, v0);
    builder->CreateRet(ret);
    return func;
}