[LLVMdev] Make a comparation with IR builder

Justin Holewinski justin.holewinski at gmail.com
Fri Jan 11 03:56:20 PST 2013


you're not showing enough code.  What does accept() do?

Based on your description, I strongly suspect that your alloca and constant
are not the same type.  Remember that alloca returns a pointer type that
you must load to get at the actual variable.
On Jan 11, 2013 3:28 AM, "Manuele Conti" <manuele.conti at sirius-es.it> wrote:

> Hi All,
> I'm writing a code generation with my compiler. I read sever example and
> documentation but I did understand what I make wrong.
> What I try to do is a compare a local variable with a constant.
> But when I create a ICMP instruction I get that instruction are not of
> same type.
> I'm using llvm by svn repository updated at two week ago.
>
> The code that I try to generation is something like:
>
> if varInt = 1 then
>    varInt := 10;
> end_if;
>
>
> This is my code:
>
> void *visit(integer_c *symbol)            {
>         int64_t value = GET_CVALUE(int64, symbol);
>         if (typeid(*currentType) == typeid(get_datatype_info_c::**bool_type_name))
>  {
>           std::cout << "Creating integer: " << value << std::endl;
>           return (void *)ConstantInt::get(Type::**getInt1Ty(getGlobalContext()),
> value, false);
>         }
>         return (void *)ConstantInt::get(Type::**
> getInt16Ty(getGlobalContext())**, value, false);
> }
>
> void *visit(symbolic_variable_c *symbol) {
>   std::string varName;
>   AllocaInst *alloc;
>
>   varName = get_var_name_c::get_name(**symbol->var_name)->value;
>   alloc = locals[varName];
>
>   return (void *)alloc;
> }
>
> void *visit(equ_expression_c *symbol) {
>         Value *lValue;
>         Value *rValue;
>
>         lValue = (Value *)symbol->l_exp->accept(*this)**;
>         rValue = (Value *)symbol->r_exp->accept(*this)**;
>
>         return Builder.CreateICmpEQ (lValue, rValue, "cond");
>
> }
>
>  Cheers,
> Manuele
>
>
>
>
> ______________________________**_________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/**mailman/listinfo/llvmdev<http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130111/9d4d46fc/attachment.html>


More information about the llvm-dev mailing list