<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi Justin,<br>
my class is a visitor pattern and I use accept method to go
recursive in suboject in my AST.<br>
In locals I store AllocaInst pointer.<br>
<br>
<pre wrap="">
void *visit(var1_init_decl_c *symbol) {
llvm::Type *lType;
varNames.clear();
varType = "";
symbol->var1_list->accept(*this); /* get a vector contains variable names */
symbol->spec_init->accept(*this); /* Store in varType variable list */
lType = typeOf(varType);
for (unsigned int i = 0; i < varNames.size(); i++) {
AllocaInst *alloc = new AllocaInst(lType, varNames[i].c_str(), currentBBlock);
locals[varNames[i]] = alloc;
}
return NULL;
}
Can I load a AllocaInst using CreateLoad instruction?
</pre>
Cheers,<br>
Manuele<br>
<br>
Il 11/01/2013 12:56, Justin Holewinski ha scritto:<br>
</div>
<blockquote
cite="mid:CAJgxuaeLGsP1r7YHPks43ovRs8CL0SC1MzhubmQK0RE-j3T93A@mail.gmail.com"
type="cite">
<p dir="ltr">you're not showing enough code. What does accept()
do?</p>
<p dir="ltr">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.</p>
<div class="gmail_quote">On Jan 11, 2013 3:28 AM, "Manuele Conti"
<<a moz-do-not-send="true"
href="mailto:manuele.conti@sirius-es.it">manuele.conti@sirius-es.it</a>>
wrote:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
I'm writing a code generation with my compiler. I read sever
example and documentation but I did understand what I make
wrong.<br>
What I try to do is a compare a local variable with a
constant.<br>
But when I create a ICMP instruction I get that instruction
are not of same type.<br>
I'm using llvm by svn repository updated at two week ago.<br>
<br>
The code that I try to generation is something like:<br>
<br>
if varInt = 1 then<br>
varInt := 10;<br>
end_if;<br>
<br>
<br>
This is my code:<br>
<br>
void *visit(integer_c *symbol) {<br>
int64_t value = GET_CVALUE(int64, symbol);<br>
if (typeid(*currentType) ==
typeid(get_datatype_info_c::bool_type_name)) {<br>
std::cout << "Creating integer: " <<
value << std::endl;<br>
return (void *)ConstantInt::get(Type::getInt1Ty(getGlobalContext()),
value, false);<br>
}<br>
return (void *)ConstantInt::get(Type::getInt16Ty(getGlobalContext()),
value, false);<br>
}<br>
<br>
void *visit(symbolic_variable_c *symbol) {<br>
std::string varName;<br>
AllocaInst *alloc;<br>
<br>
varName = get_var_name_c::get_name(symbol->var_name)->value;<br>
alloc = locals[varName];<br>
<br>
return (void *)alloc;<br>
}<br>
<br>
void *visit(equ_expression_c *symbol) {<br>
Value *lValue;<br>
Value *rValue;<br>
<br>
lValue = (Value *)symbol->l_exp->accept(*this);<br>
rValue = (Value *)symbol->r_exp->accept(*this);<br>
<br>
return Builder.CreateICmpEQ (lValue, rValue, "cond");<br>
<br>
}<br>
<br>
Cheers,<br>
Manuele<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a moz-do-not-send="true" href="mailto:LLVMdev@cs.uiuc.edu"
target="_blank">LLVMdev@cs.uiuc.edu</a> <a
moz-do-not-send="true" href="http://llvm.cs.uiuc.edu"
target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>