<div dir="ltr"><div><div><div><div><div><div><div>As you may have noticed, although the assertions from the debug+assert LLVM build are factually correct, for the purposes of debugging code linked against it, it's not all that useful.<br>
<br></div>I have found it useful to build a wrapper layer around LLVM in my project. The primary purpose of the wrapper was to isolate my application from changes in the LLVM API, as it seems to be a moving target. However, for places where I trigger LLVM's assertions frequently, I have "copied" those assertions into my wrapper to do the same checks prior to calling into LLVM, and to produce useful diagnostics in the case of failure.<br>
<br></div>For example, I often get argument mismatches between a function call and its definition. So, in my callFunction wrapper, I do the type checks, and in the event of failure, I print out:<br></div>- the name of the function being called<br>
</div>- the position of the argument whose type mismatches<br></div>- the formal and actual types in question.<br><br></div>You can consider doing the same - create a wrapper around your calls into LLVM, and add better diagnostics where required.<br>
<br></div>If there is sufficient interest, I might document better what I did.<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 4, 2014 at 8:18 AM, Prakash Premkumar <span dir="ltr"><<a href="mailto:prakash.prax@gmail.com" target="_blank">prakash.prax@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I am trying to write a simple interpreter.</div><div><br></div><div>I am trying to generate LLVM IR for assignment operation. The code for the generation part looks like this </div>
<div>
<br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">llvm::Value* codeGenSymTab(llvm::LLVMContext& context) {<br>
printf("\n CodeGen SymTab \n");<br> Value *num = ConstantInt::get(Type::getInt64Ty(context), aTable.value, true);<br> Value *alloc = new AllocaInst(IntegerType::get(context, 32), aTable.variableName,entry);<br>
StoreInst *ptr = new StoreInst(num,alloc,false,entry);<br>}</blockquote><div><br></div><div>Here goes the SymTab definition:</div><div><br></div><div>struct SymTab {</div><div> char* variableName;</div><div> int value; </div>
<div> llvm::Value* (*codeGen)(llvm::LLVMContext& context); </div><div>}; </div></div><div><br></div><div><br></div><div>When I try to execute the output file,I get the following error:</div><div><br></div><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Assertion failed: (getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"), function AssertOK, file Instructions.cpp, line 1084.<br>
Abort trap: 6</blockquote><div><br></div><div>Can you help me resolve it ?</div><div><br></div><div>Thanks</div><span class="HOEnZb"><font color="#888888"><div>Prakash </div>
</font></span></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>