Note that there are some explanatory texts on larger screens.

plurals
  1. POLLVM Value sign
    primarykey
    data
    text
    <p>I'm having some problems when loading values. Here's a simple example of the IR that my compiler generates to show the problem:</p> <pre><code>define i32 @main() { entry: %a = alloca i32 ; &lt;i32*&gt; [#uses=2] store i32 1, i32* %a %r = load i32* %a ; &lt;i32&gt; [#uses=1] br label %Return Return: ; preds = %entry ret i32 %r } </code></pre> <p>but instead of return 1 it returns 16777216. I have tested the program with different values and it seems that it's a matter of internal binary representation of integer values.</p> <p>Edited: I show you the trace of calls to llvm that my compiler makes to generate the code above. bloques.back().last is of type Value* and bloques.back().bl is BasicBlock* (the current Block)</p> <pre><code>bloques.back().last = dyn_cast&lt;Value&gt;(ConstantInt::get( Type::getInt32Ty(getGlobalContext()), $1, true)); // $1 is an int AllocaInst *alloc = new AllocaInst( Type::getInt32Ty(getGlobalContext()), izq.c_str(), bloques.back().bl); Value *derecha = bloques.back().last; StoreInst *s = new StoreInst(derecha, alloc, false, bloques.back().bl); bloques.back().last = alloc; LoadInst* v1 = new LoadInst(bloques.back().last, "r", false, bloques.back().bl); bloques.back().last = v1; BasicBlock* blockReturn = BasicBlock::Create(getGlobalContext(), "Return", Main); Value* last = bloques.back().last; BranchInst::Create(blockReturn, bloques.back().bl); ReturnInst::Create(getGlobalContext(), last, blockReturn); </code></pre> <p>The source code corresponding to the IR representation would be:</p> <pre><code>a = 1 return a </code></pre> <p>Edit2: In my main function after generate the code and before start the execution via JIT I do this:</p> <pre><code>ExecutionEngine *EE = EngineBuilder(M).create(); string str = EE-&gt;getTargetData()-&gt;getStringRepresentation(); str[0] = 'e'; M-&gt;setDataLayout(str); if (verifyModule(*M)) { errs() &lt;&lt; argv[0] &lt;&lt; ": Error building the function!\n"; return 1; } vector&lt;GenericValue&gt; noargs; GenericValue GV = EE-&gt;runFunction(Main, noargs); outs() &lt;&lt; "Result: " &lt;&lt; GV.IntVal &lt;&lt; "\n"; return 0; </code></pre> <p>Solved: finally i've found the solution. To change the endianness I do the following (a little spaguetti but it works):</p> <pre><code>Module *M = new Module("pythoncode", getGlobalContext()); ExecutionEngine *EE2 = EngineBuilder(M).create(); string str = EE2-&gt;getTargetData()-&gt;getStringRepresentation(); str[0] = 'e'; cout &lt;&lt; str &lt;&lt; endl; M-&gt;setDataLayout(str); ExecutionEngine *EE = EngineBuilder(M).create(); </code></pre> <p>Thanks in advance.</p> <p>Santos Merino.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload