[LLVMdev] Make a comparation with IR builder

Manuele Conti manuele.conti at sirius-es.it
Fri Jan 11 00:26:14 PST 2013

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;

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");



More information about the llvm-dev mailing list