mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 00:32:55 +00:00
Simplify the first example, as the LLVM IR interfaces have evolved. Other
examples in this doc could also be simplified dramatically in similar ways. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15428 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cc455dea0f
commit
532c92d04a
@ -131,31 +131,28 @@ I noted that most of the important LLVM IR (Intermediate Representation) C++
|
|||||||
classes were derived from the Value class. The full power of that simple
|
classes were derived from the Value class. The full power of that simple
|
||||||
design only became fully understood once I started constructing executable
|
design only became fully understood once I started constructing executable
|
||||||
expressions for Stacker.</p>
|
expressions for Stacker.</p>
|
||||||
|
|
||||||
<p>This really makes your programming go faster. Think about compiling code
|
<p>This really makes your programming go faster. Think about compiling code
|
||||||
for the following C/C++ expression: <code>(a|b)*((x+1)/(y+1))</code>. Assuming
|
for the following C/C++ expression: <code>(a|b)*((x+1)/(y+1))</code>. Assuming
|
||||||
the values are on the stack in the order a, b, x, y, this could be
|
the values are on the stack in the order a, b, x, y, this could be
|
||||||
expressed in stacker as: <code>1 + SWAP 1 + / ROT2 OR *</code>.
|
expressed in stacker as: <code>1 + SWAP 1 + / ROT2 OR *</code>.
|
||||||
You could write a function using LLVM that computes this expression like this: </p>
|
You could write a function using LLVM that computes this expression like
|
||||||
<pre><code>
|
this: </p>
|
||||||
|
|
||||||
|
<div class="doc_code"><pre>
|
||||||
Value*
|
Value*
|
||||||
expression(BasicBlock* bb, Value* a, Value* b, Value* x, Value* y )
|
expression(BasicBlock* bb, Value* a, Value* b, Value* x, Value* y )
|
||||||
{
|
{
|
||||||
Instruction* tail = bb->getTerminator();
|
ConstantSInt* one = ConstantSInt::get(Type::IntTy, 1);
|
||||||
ConstantSInt* one = ConstantSInt::get( Type::IntTy, 1);
|
BinaryOperator* or1 = BinaryOperator::createOr(a, b, "", bb);
|
||||||
BinaryOperator* or1 =
|
BinaryOperator* add1 = BinaryOperator::createAdd(x, one, "", bb);
|
||||||
BinaryOperator::create( Instruction::Or, a, b, "", tail );
|
BinaryOperator* add2 = BinaryOperator::createAdd(y, one, "", bb);
|
||||||
BinaryOperator* add1 =
|
BinaryOperator* div1 = BinaryOperator::createDiv(add1, add2, "", bb);
|
||||||
BinaryOperator::create( Instruction::Add, x, one, "", tail );
|
BinaryOperator* mult1 = BinaryOperator::createMul(or1, div1, "", bb);
|
||||||
BinaryOperator* add2 =
|
|
||||||
BinaryOperator::create( Instruction::Add, y, one, "", tail );
|
|
||||||
BinaryOperator* div1 =
|
|
||||||
BinaryOperator::create( Instruction::Div, add1, add2, "", tail);
|
|
||||||
BinaryOperator* mult1 =
|
|
||||||
BinaryOperator::create( Instruction::Mul, or1, div1, "", tail );
|
|
||||||
|
|
||||||
return mult1;
|
return mult1;
|
||||||
}
|
}
|
||||||
</code></pre>
|
</pre></div>
|
||||||
|
|
||||||
<p>"Okay, big deal," you say? It is a big deal. Here's why. Note that I didn't
|
<p>"Okay, big deal," you say? It is a big deal. Here's why. Note that I didn't
|
||||||
have to tell this function which kinds of Values are being passed in. They could be
|
have to tell this function which kinds of Values are being passed in. They could be
|
||||||
<code>Instruction</code>s, <code>Constant</code>s, <code>GlobalVariable</code>s, or
|
<code>Instruction</code>s, <code>Constant</code>s, <code>GlobalVariable</code>s, or
|
||||||
|
Loading…
x
Reference in New Issue
Block a user