DOC: Add first version of updated documentation.

This commit is contained in:
Travis E. Oliphant 2012-08-09 13:53:21 -05:00
commit 415c01f745
19 changed files with 474 additions and 595 deletions

View file

@ -1,45 +1,36 @@
+-------------------------+
| layout: page |
+-------------------------+
| title: JIT Tutorial 1 |
+-------------------------+
A First Function
==================
{% highlight python %} #!/usr/bin/env python
.. code-block:: python
from llvm.core import \*
#!/usr/bin/env python
from llvm.core import *
create a module
===============
#create a module
module = Module.new("tut1")
module = Module.new ("tut1")
#create a function type taking 3 32-bit integers, return a 32-bit integer
ty_int = Type.int(32)
func_type = Type.function(ty_int, (ty_int,)*3)
create a function type taking 3 32-bit integers, return a 32-bit integer
========================================================================
#create a function of that type
mul_add = Function.new (module, func_type, "mul_add")
mul_add.calling_convention = CC_C
x = mul_add.args[0]; x.name = "x"
y = mul_add.args[1]; y.name = "y"
z = mul_add.args[2]; z.name = "z"
ty\_int = Type.int (32) func\_type = Type.function (ty\_int,
(ty\_int,)\*3)
#implement the function
create a function of that type
==============================
#new block
blk = mul_add.append_basic_block("entry")
mul\_add = Function.new (module, func\_type, "mul\_add")
mul\_add.calling\_convention = CC\_C x = mul\_add.args[0]; x.name = "x"
y = mul\_add.args[1]; y.name = "y" z = mul\_add.args[2]; z.name = "z"
#IR builder
bldr = Builder.new(blk)
tmp_1 = bldr.mul(x, y, "tmp_1")
tmp_2 = bldr.add(tmp_1, z, "tmp_2")
implement the function
======================
bldr.ret(tmp_2)
new block
=========
blk = mul\_add.append\_basic\_block ("entry")
IR builder
==========
bldr = Builder.new (blk) tmp\_1 = bldr.mul (x, y, "tmp\_1") tmp\_2 =
bldr.add (tmp\_1, z, "tmp\_2")
bldr.ret (tmp\_2)
print(module) {% endhighlight %}
print module