/*
 * pointerarithmetic.cpp
 *
 * Author: pgess <v.melnychenko@xreate.org>
 * Created on March 29, 2017, 11:52 AM
 */
#include "pointerarithmetic.h"
#include "llvmlayer.h"
#include <vector>

using namespace llvm;

namespace xreate { namespace compilation {

llvm::Value*
PointerArithmetic::add(llvm::Value *left, llvm::Value *right, Context context, const std::string& hintVarDecl){
    LLVMLayer* llvm = context.pass->man->llvm;

    if (left->getType()->isPointerTy() && right->getType()->isIntegerTy()){

        std::vector<llvm::Value*> indexes{right};
        //{llvm::ConstantInt::get(llvm::Type::getInt32Ty(llvm::getGlobalContext()), 0)};
        //indexes.push_back(right);

        return llvm->builder.CreateGEP(left, llvm::ArrayRef<llvm::Value*>(indexes), hintVarDecl);
    }

    return nullptr;
}

} }