Documentation update

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@85 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2009-10-28 12:10:06 +00:00
commit 43998cc2df
15 changed files with 1343 additions and 2192 deletions

19
tools/intrs_for_doc.py Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
import os
intrs = []
for line in file('../llvm/_intrinsic_ids.py'):
if line.startswith('INTR_'):
if 'INTR_ARM_' not in line and \
'INTR_BFIN_' not in line and \
'INTR_PPC_' not in line and \
'INTR_SPU_' not in line and \
'INTR_X86_' not in line and \
'INTR_XCORE_' not in line:
intrs.append(line.split()[0])
i = 0
while i < len(intrs):
print "`" + "`,`".join(intrs[i:min(i+3,len(intrs)+1)]) + "`"
i += 3

View file

@ -1,9 +1,10 @@
About About
===== =====
llvm-py is developed by Mahadevan R, in his spare time. He can be llvm-py is developed and maintained by Mahadevan R, with contributions from
reached at mdevan.foobar@gmail.com, on the llvm-dev mailing list and many users all over the world. He can be reached at mdevan.foobar@gmail.com,
irc.oftc.net#llvm (mdevan). on the llvm-dev mailing list and (sometimes) as mdevan on irc.oftc.net#llvm.
Many thanks to the guys over at LLVM for all the nifty software. Many thanks to the guys over at LLVM for all the nifty software, for all
the llvm-py contributors.

View file

@ -1,23 +1,14 @@
Download Download
======== ========
The latest release is 0.5, released 22-Nov-2008 (link:#changelog[Changelog] The latest release is 0.6, released 28-Oct-2009 (link:#changelog[Changelog]
below). 0.5 works only with LLVM 2.4, use 0.4 if you have LLVM 2.3. below). 0.6 works only with LLVM 2.6.
Download it here: Download it here:
- http://llvm-py.googlecode.com/files/llvm-py-0.6.tar.bz2[llvm-py-0.6.tar.bz2] (primary)
- link:llvm-py-0.6.tar.bz2[llvm-py-0.6.tar.bz2] (mirror)
[frame="all",grid="all"] Older versions are available http://llvm-py.googlecode.com/files/[here].
````~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Release,Date,Package,Mirror
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.5,22-Nov-2008,http://llvm-py.googlecode.com/files/llvm-py-0.5.tar.bz2[llvm-py-0.5.tar.bz2],link:llvm-py-0.5.tar.bz2[llvm-py-0.5.tar.bz2]
0.4,21-Nov-2008,http://llvm-py.googlecode.com/files/llvm-py-0.4.tar.bz2[llvm-py-0.4.tar.bz2],link:llvm-py-0.4.tar.bz2[llvm-py-0.4.tar.bz2]
0.3,8-Sep-2008,http://llvm-py.googlecode.com/files/llvm-py-0.3.tar.bz2[llvm-py-0.3.tar.bz2],link:llvm-py-0.3.tar.bz2[llvm-py-0.3.tar.bz2]
0.2.1,18-Jun-2008,http://llvm-py.googlecode.com/files/llvm-py-0.2.1.tar.bz2[llvm-py-0.2.1.tar.bz2],link:llvm-py-0.2.1.tar.bz2[llvm-py-0.2.1.tar.bz2]
0.2,15-Jun-2008,http://llvm-py.googlecode.com/files/llvm-py-0.2.tar.bz2[llvm-py-0.2.tar.bz2],link:llvm-py-0.2.tar.bz2[llvm-py-0.2.tar.bz2]
0.1,20-May-2008,http://llvm-py.googlecode.com/files/llvm-py-0.1.tar.bz2[llvm-py-0.1.tar.bz2],link:llvm-py-0.1.tar.bz2[llvm-py-0.1.tar.bz2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The latest code can be checked out from SVN like so: The latest code can be checked out from SVN like so:

View file

@ -14,7 +14,7 @@ ported to llvm-py. Below are the links to the original LLVM tutorial and
the corresponding Python code using llvm-py: the corresponding Python code using llvm-py:
.Simple JIT Tutorials .Simple JIT Tutorials
(These were contributed by Sebastien Binet; thanks!) (contributed by Sebastien Binet)
1. A First Function 1. A First Function
http://www.llvm.org/docs/tutorial/JITTutorial1.html[LLVM] http://www.llvm.org/docs/tutorial/JITTutorial1.html[LLVM]

View file

@ -8,32 +8,16 @@ Python and C modules that wrap over the native C++/C bindings of LLVM,
and does not use / have dependencies on "glue utilities" like and does not use / have dependencies on "glue utilities" like
Boost.Python, swig etc. Boost.Python, swig etc.
llvm-py is just hatching. It should be stable enough to start hacking llvm-py is available as a source package (only). It works / should work
away, though. Be sure to send in a patch if you miss any specific LLVM with GNU/Linux, *BSD and Mac OS X platforms, on both 32-bit and 64-bit
API. architectures. Python 2.4 or better (but 3.x is untested) is required.
The SVN HEAD usually works with the latest released LLVM. In case you
_Availability_: llvm-py is available (as a source package) for LLVM 2.4 discover that any of these claims are wrong, feel free to send across
and Python 2.5. It has been built and tested on Linux and FreeBSD a patch.
(x86 and amd64).
News News
---- ----
22-Nov-2008:: 28-Oct-2009::
0.5 released. For LLVM 2.4. SVN r83 works with LLVM 2.6. Website updated.
21-Nov-2008::
0.4 released. Bug fixes, few additional APIs, code cleanup.
8-Sep-2008::
0.3 released. Passes, intrinsics, bitcode, assembly!
18-Jun-2008::
0.2.1 released. Builds cleanly with LLVM 2.3 and 2.3+svn.
15-Jun-2008::
0.2 released. Lots of cleanup, new website, more documentation.
20-May-2008::
0.1 released.

View file

@ -19,6 +19,13 @@ Python bindings for LLVM provides a gentler learning curve for working
with the LLVM APIs. It should also be easier to create working with the LLVM APIs. It should also be easier to create working
prototypes and experimental languages using this medium. prototypes and experimental languages using this medium.
Together with http://clang.llvm.org/[clang] or
http://llvm.org/cmds/llvmgcc.html[llvm-gcc] it also a provides a means
to quickly instrument C and C++ sources. For e.g., llvm-gcc can be used to
generate the LLVM assembly for a given C source file, which can then be
loaded and manipulated (adding profiling code to every function, say) using
a llvm-py based Python script.
.License .License
Both LLVM and llvm-py are distributed under (different) permissive Both LLVM and llvm-py are distributed under (different) permissive
open source licenses. llvm-py uses the open source licenses. llvm-py uses the
@ -26,16 +33,16 @@ http://opensource.org/licenses/bsd-license.php[new BSD license]. More
information is available link:license.html[here]. information is available link:license.html[here].
.Platforms .Platforms
Currently, llvm-py has been built and tested only on Linux (i386, amd64) llvm-py has been built/tested/reported to work on various GNU/Linux
and OpenBSD (i386, amd64). However, it should be trivial to build it on flavours, *BSD, Mac OS X; on i386 and amd64 architectures. Windows is not
other unices. Windows is not supported, for a variety of reasons. supported, for a variety of reasons.
.Versions .Versions
llvm-py 0.5 requires verion 2.4 of LLVM. It will not work with previous llvm-py 0.6 requires verion 2.6 of LLVM. It will not work with previous
versions. versions.
llvm-py has been built and tested with Python 2.5. It should work with llvm-py has been built and tested with Python 2.6. It should work with
Python 2.4, with minimal changes, if any. Python 2.4 and 2.5. It has not been tried with Python 3.x (patches welcome).
[[install]] [[install]]
@ -46,19 +53,18 @@ llvm-py is distributed as a source tarball. You'll need to build and
install it before it can be used. At least the following will be install it before it can be used. At least the following will be
required for this: required for this:
- C and C\+\+ compilers (gcc/g\+\+) - C and C++ compilers (gcc/g++)
- Python itself - Python itself
- Python development files (headers and libraries) - Python development files (headers and libraries)
- LLVM, either installed or built - LLVM, either installed or built
On debian-based systems, the first three can be installed with the On debian-based systems, the first three can be installed with the
command `sudo apt-get install gcc g\+\+ python python-dev`. Note that command `sudo apt-get install gcc g++ python python-dev`. Ensure that your
ubuntu repository has an old version of llvm (1.8) which will not work distro's respository has the appropriate version of LLVM!
with llvm-py.
It does not matter which compiler LLVM itself was built with (g\+\+, It does not matter which compiler LLVM itself was built with (g++,
llvm-g\+\+ or any other); llvm-py can be built with any compiler. It has llvm-g++ or any other); llvm-py can be built with any compiler. It has
been tried only with gcc/g\+\+ though. been tried only with gcc/g++ though.
LLVM and `--enable-pic` LLVM and `--enable-pic`
@ -73,7 +79,7 @@ independent code). Be sure to use the `--enable-pic` option while
configuring LLVM (default is no PIC), like this: configuring LLVM (default is no PIC), like this:
---- ----
~/llvm-2.4$ ./configure --enable-pic --enable-optimized ~/llvm$ ./configure --enable-pic --enable-optimized
---- ----
@ -104,8 +110,8 @@ If you have +llvm-config+ in your path, you can build and install
llvm-py this way: llvm-py this way:
----------------------------------------------------------------------- -----------------------------------------------------------------------
$ tar jxvf llvm-py-0.5.tar.bz2 $ tar jxvf llvm-py-0.6.tar.bz2
$ cd llvm-py-0.5 $ cd llvm-py-0.6
$ sudo python setup.py install $ sudo python setup.py install
----------------------------------------------------------------------- -----------------------------------------------------------------------
@ -113,8 +119,8 @@ If you need to tell the build script where +llvm-config+ is, do it this
way: way:
----------------------------------------------------------------------- -----------------------------------------------------------------------
$ tar jxvf llvm-py-0.5.tar.bz2 $ tar jxvf llvm-py-0.6.tar.bz2
$ cd llvm-py-0.5 $ cd llvm-py-0.6
$ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config $ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config
----------------------------------------------------------------------- -----------------------------------------------------------------------
@ -122,8 +128,8 @@ To build a debug version of llvm-py, that links against the debug
libraries of LLVM, use this: libraries of LLVM, use this:
----------------------------------------------------------------------- -----------------------------------------------------------------------
$ tar jxvf llvm-py-0.5.tar.bz2 $ tar jxvf llvm-py-0.6.tar.bz2
$ cd llvm-py-0.5 $ cd llvm-py-0.6
$ python setup.py build -g --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config $ python setup.py build -g --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config
$ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config $ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config
----------------------------------------------------------------------- -----------------------------------------------------------------------
@ -144,12 +150,12 @@ Uninstall
To get rid of llvm-py completely, if you wish to do so: To get rid of llvm-py completely, if you wish to do so:
---- ----
# rm -rf /usr/lib/python2.5/site-packages/llvm # rm -rf /usr/lib/python2.6/site-packages/llvm
# rm -f /usr/lib/python2.5/site-packages/llvm_py-0.1.egg-info # rm -f /usr/lib/python2.6/site-packages/llvm_py-0.6-py2.6.egg-info
---- ----
- You need to be root to do this. - You need to be root to do this.
- Paths are for debian-based systems, in other distros it might be different. - Python site package path might be different on your system.
- Note that there are version numbers (both Python's and llvm-py's) - Note that there are version numbers (both Python's and llvm-py's)
which you might need to change to suit your system. which you might need to change to suit your system.
@ -263,43 +269,42 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The corresponding LLVM assembly: The corresponding LLVM assembly:
----------------------------------------------------------------------- -----------------------------------------------------------------------
; ModuleID = '/tmp/webcompile/_4940_0.bc' ; ModuleID = '/tmp/webcompile/_22154_0.bc'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32" target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i386-pc-linux-gnu" target triple = "i386-pc-linux-gnu"
define i32 @sum(i32 %n) nounwind { define i32 @sum(i32 %n) nounwind readnone {
entry: entry:
%tmp215 = icmp eq i32 %n, 0 ; <i1> [#uses=1] %0 = icmp eq i32 %n, 0 ; <i1> [#uses=1]
br i1 %tmp215, label %bb10, label %tailrecurse.bb10_crit_edge br i1 %0, label %bb2, label %bb1
tailrecurse.bb10_crit_edge: ; preds = %entry bb1: ; preds = %entry
%tmp = add i32 %n, -1 ; <i32> [#uses=3] %1 = add i32 %n, -1 ; <i32> [#uses=2]
%tmp17 = mul i32 %tmp, %tmp ; <i32> [#uses=1] %2 = icmp eq i32 %1, 0 ; <i1> [#uses=1]
%tmp18 = add i32 %tmp17, %n ; <i32> [#uses=1] br i1 %2, label %sum.exit, label %bb1.i
%tmp. = zext i32 %tmp to i64 ; <i64> [#uses=2]
%tmp19 = add i64 %tmp., -1 ; <i64> [#uses=1]
%tmp20 = mul i64 %tmp19, %tmp. ; <i64> [#uses=1]
%tmp21 = lshr i64 %tmp20, 1 ; <i64> [#uses=1]
%tmp.22 = trunc i64 %tmp21 to i32 ; <i32> [#uses=1]
%tmp24 = sub i32 %tmp18, %tmp.22 ; <i32> [#uses=1]
ret i32 %tmp24
bb10: ; preds = %entry bb1.i: ; preds = %bb1
%3 = add i32 %n, -2 ; <i32> [#uses=1]
%4 = tail call i32 @sum(i32 %3) nounwind ; <i32> [#uses=1]
%5 = add i32 %4, %1 ; <i32> [#uses=1]
br label %sum.exit
sum.exit: ; preds = %bb1.i, %bb1
%6 = phi i32 [ %5, %bb1.i ], [ 0, %bb1 ] ; <i32> [#uses=1]
%7 = add i32 %6, %n ; <i32> [#uses=1]
ret i32 %7
bb2: ; preds = %entry
ret i32 0 ret i32 0
} }
----------------------------------------------------------------------- -----------------------------------------------------------------------
Note the usage of SSA form and the total absence of any loop or Note the usage of SSA form. The long string called `target datalayout` is a
recursion at all! The long string called `target datalayout` is a
specification of the platform ABI (like endianness, sizes of types, specification of the platform ABI (like endianness, sizes of types,
alignment etc.). alignment etc.).
The http://www.llvm.org/docs/LangRef.html[LLVM Language Reference] The http://www.llvm.org/docs/LangRef.html[LLVM Language Reference]
defines the LLVM assembly language including the entire instruction set. defines the LLVM assembly language including the entire instruction set.
The table below lists all the LLVM instructions. Each instruction links
to it's documentation.
include::instrset.inc[]
Modules Modules
@ -341,7 +346,7 @@ loaded and executed by +opt+. (Although llvm-py does not allow you to
write your own passes, it does allow you to navigate the entire IR at write your own passes, it does allow you to navigate the entire IR at
any stage, and perform any transforms on it as you like.) any stage, and perform any transforms on it as you like.)
[TODO: pass manager, execution engine, bit code] TODO: pass manager, execution engine, bit code
The llvm-py Package The llvm-py Package
@ -427,7 +432,7 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This avoids quite some typing. Both conventions work, however. This avoids quite some typing. Both conventions work, however.
TIP: Python-style documentation strings (`\_\_doc\_\_`) are present in TIP: Python-style documentation strings (`__doc__`) are present in
llvm-py. You can use the +help()+ of the interactive Python llvm-py. You can use the +help()+ of the interactive Python
interpreter or the +object?+ of http://ipython.scipy.org/moin/[IPython] interpreter or the +object?+ of http://ipython.scipy.org/moin/[IPython]
to get online help. (Note: not complete yet!) to get online help. (Note: not complete yet!)
@ -552,10 +557,10 @@ stringifying them (see below).
object `fileobj`. object `fileobj`.
.Special Methods .Special Methods
`\_\_str\_\_`:: `__str__`::
`Module` objects can be stringified into it's LLVM assembly language `Module` objects can be stringified into it's LLVM assembly language
representation. representation.
`\_\_eq\_\_`:: `__eq__`::
`Module` objects can be compared for equality. Internally, this `Module` objects can be compared for equality. Internally, this
converts both arguments into their LLVM assembly representations and converts both arguments into their LLVM assembly representations and
compares the resultant strings. compares the resultant strings.
@ -589,10 +594,9 @@ The following table lists all the available types along with the static
method which has to be used to construct it and the name of the class whose method which has to be used to construct it and the name of the class whose
object is actually returned by the static method. object is actually returned by the static method.
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="3",options="header"]
`50`30`20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Name,Constructor Method,Class Name,Constructor Method,Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
integer of bitwidth `n`, +Type.int(n)+, +IntegerType+ integer of bitwidth `n`, +Type.int(n)+, +IntegerType+
32-bit float, +Type.float()+, +Type+ 32-bit float, +Type.float()+, +Type+
64-bit double, +Type.double()+, +Type+ 64-bit double, +Type.double()+, +Type+
@ -608,7 +612,7 @@ vector, "+Type.vector(elty, count)+", +VectorType+
void, +Type.void()+, +Type+ void, +Type.void()+, +Type+
label, +Type.label()+, +Type+ label, +Type.label()+, +Type+
opaque, +Type.opaque()+, +Type+ opaque, +Type.opaque()+, +Type+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
The class hierarchy is: The class hierarchy is:
----------------------------------------------------------------------- -----------------------------------------------------------------------
@ -666,7 +670,7 @@ The class-level documentation follows:
.Properties .Properties
`kind` [read-only]:: `kind` [read-only]::
A value (enum) representing the ``type'' of the object. It will be A value (enum) representing the "type" of the object. It will be
one of the following constants defined in `llvm.core`: one of the following constants defined in `llvm.core`:
+ +
[python] [python]
@ -678,13 +682,14 @@ TYPE_X86_FP80 = 3
TYPE_FP128 = 4 TYPE_FP128 = 4
TYPE_PPC_FP128 = 5 TYPE_PPC_FP128 = 5
TYPE_LABEL = 6 TYPE_LABEL = 6
TYPE_INTEGER = 7 TYPE_METADATA = 7
TYPE_FUNCTION = 8 TYPE_INTEGER = 8
TYPE_STRUCT = 9 TYPE_FUNCTION = 9
TYPE_ARRAY = 10 TYPE_STRUCT = 10
TYPE_POINTER = 11 TYPE_ARRAY = 11
TYPE_OPAQUE = 12 TYPE_POINTER = 12
TYPE_VECTOR = 13 TYPE_OPAQUE = 13
TYPE_VECTOR = 14
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ +
Example: Example:
@ -701,10 +706,10 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
of `TypeHandle` objects. of `TypeHandle` objects.
.Special Methods .Special Methods
`\_\_str\_\_`:: `__str__`::
`Type` objects can be stringified into it's LLVM assembly language `Type` objects can be stringified into it's LLVM assembly language
representation. representation.
`\_\_eq\_\_`:: `__eq__`::
`Type` objects can be compared for equality. Internally, this `Type` objects can be compared for equality. Internally, this
converts both arguments into their LLVM assembly representations and converts both arguments into their LLVM assembly representations and
compares the resultant strings. compares the resultant strings.
@ -899,7 +904,7 @@ Programmer's Manual section
http://llvm.org/docs/ProgrammersManual.html#TypeResolve["LLVM Type http://llvm.org/docs/ProgrammersManual.html#TypeResolve["LLVM Type
Resolution"]. The TypeHandle class of llvm-py corresponds to Resolution"]. The TypeHandle class of llvm-py corresponds to
http://www.llvm.org/doxygen/classllvm_1_1PATypeHolder.html[`llvm::PATypeHolder`] http://www.llvm.org/doxygen/classllvm_1_1PATypeHolder.html[`llvm::PATypeHolder`]
in C\+\+. The above example is available as in C++. The above example is available as
http://code.google.com/p/llvm-py/source/browse/trunk/test/typehandle.py[test/typehandle.py] http://code.google.com/p/llvm-py/source/browse/trunk/test/typehandle.py[test/typehandle.py]
in the source distribution. in the source distribution.
@ -964,10 +969,10 @@ the `Builder` class. These are also covered separately.
An `llvm.core.Type` object representing the type of the value. An `llvm.core.Type` object representing the type of the value.
.Special Methods .Special Methods
`\_\_str\_\_`:: `__str__`::
`Value` objects can be stringified into it's LLVM assembly language `Value` objects can be stringified into it's LLVM assembly language
representation. representation.
`\_\_eq\_\_`:: `__eq__`::
`Value` objects can be compared for equality. Internally, this `Value` objects can be compared for equality. Internally, this
converts both arguments into their LLVM assembly representations and converts both arguments into their LLVM assembly representations and
compares the resultant strings. compares the resultant strings.
@ -1003,13 +1008,12 @@ The following constructors (static methods) can be used to create
constants: constants:
[[constctors]] [[constctors]]
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="2",options="header"]
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Constructor Method, What It Creates Constructor Method, What It Creates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`null(ty)`, A null value (all zeros) of type `ty` `null(ty)`, A null value (all zeros) of type `ty`
`all_ones(ty)`, All 1's value of type `ty` `all_ones(ty)`, All 1's value of type `ty`
`undef(ty)`, An ``undefined'' value of type `ty` `undef(ty)`, An "undefined" value of type `ty`
"`int(ty, value)`", "Integer of type `ty`, with value `value` (a Python int or long)" "`int(ty, value)`", "Integer of type `ty`, with value `value` (a Python int or long)"
"`int_signextend(ty, value)`", Integer of signed type `ty` (use for signed types) "`int_signextend(ty, value)`", Integer of signed type `ty` (use for signed types)
"`real(ty, value)`", "Floating point value of type `ty`, with value `value` (a Python float)" "`real(ty, value)`", "Floating point value of type `ty`, with value `value` (a Python float)"
@ -1020,7 +1024,7 @@ Constructor Method, What It Creates
"`packed_struct(ty, consts)`", "As `struct(ty, consts)` but packed" "`packed_struct(ty, consts)`", "As `struct(ty, consts)` but packed"
"`vector(consts)`", "Vector, initialized with `consts` (an iterable yielding `Constant` objects of the appropriate type)" "`vector(consts)`", "Vector, initialized with `consts` (an iterable yielding `Constant` objects of the appropriate type)"
"`sizeof(ty)`", "Constant value representing the sizeof the type `ty`" "`sizeof(ty)`", "Constant value representing the sizeof the type `ty`"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
The following operations on constants are supported. For more details on The following operations on constants are supported. For more details on
any operation, consult the any operation, consult the
@ -1028,10 +1032,9 @@ http://www.llvm.org/docs/LangRef.html#constantexprs[Constant Expressions]
section of the LLVM Language Reference. section of the LLVM Language Reference.
[[constops]] [[constops]]
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="2",options="header"]
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Method, Operation Method, Operation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`k.neg()`, "negation, same as `0 - k`" `k.neg()`, "negation, same as `0 - k`"
`k.not_()`, "1's complement of `k`. Note trailing underscore." `k.not_()`, "1's complement of `k`. Note trailing underscore."
`k.add(k2)`, "`k + k2`" `k.add(k2)`, "`k + k2`"
@ -1068,16 +1071,15 @@ Method, Operation
`k.extract_element(idx)`, "Extract value at `idx` (integer constant) from a vector constant `k`." `k.extract_element(idx)`, "Extract value at `idx` (integer constant) from a vector constant `k`."
"`k.insert_element(k2,idx)`", "Insert value `k2` (scalar constant) at index `idx` (integer constant) of vector constant `k`." "`k.insert_element(k2,idx)`", "Insert value `k2` (scalar constant) at index `idx` (integer constant) of vector constant `k`."
"`k.shuffle_vector(k2,mask)`", "Shuffle vector constant `k` based on vector constants `k2` and `mask`." "`k.shuffle_vector(k2,mask)`", "Shuffle vector constant `k` based on vector constants `k2` and `mask`."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
[[ipred]] [[ipred]]
Predicates for use with `icmp` instruction are listed below. All Predicates for use with `icmp` instruction are listed below. All
of these are integer constants defined in the `llvm.core` module. of these are integer constants defined in the `llvm.core` module.
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="2",options="header"]
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Value, Meaning Value, Meaning
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`IPRED_EQ`, Equality `IPRED_EQ`, Equality
`IPRED_NE`, Inequality `IPRED_NE`, Inequality
`IPRED_UGT`, Unsigned greater than `IPRED_UGT`, Unsigned greater than
@ -1088,16 +1090,15 @@ Value, Meaning
`IPRED_SGE`, Signed greater than or equal `IPRED_SGE`, Signed greater than or equal
`IPRED_SLT`, Signed less than `IPRED_SLT`, Signed less than
`IPRED_SLE`, Signed less than or equal `IPRED_SLE`, Signed less than or equal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
[[rpred]] [[rpred]]
Predicates for use with `fcmp` instruction are listed below. All Predicates for use with `fcmp` instruction are listed below. All
of these are integer constants defined in the `llvm.core` module. of these are integer constants defined in the `llvm.core` module.
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="2",options="header"]
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Value, Meaning Value, Meaning
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`RPRED_FALSE`, Always false `RPRED_FALSE`, Always false
`RPRED_OEQ`, True if ordered and equal `RPRED_OEQ`, True if ordered and equal
`RPRED_OGT`, True if ordered and greater than `RPRED_OGT`, True if ordered and greater than
@ -1114,7 +1115,7 @@ Value, Meaning
`RPRED_ULE`, "True if unordered, less than or equal" `RPRED_ULE`, "True if unordered, less than or equal"
`RPRED_UNE`, True if unordered or not equal `RPRED_UNE`, True if unordered or not equal
`RPRED_TRUE `, Always true `RPRED_TRUE `, Always true
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
.llvm.core.Constant .llvm.core.Constant
[caption=""] [caption=""]
@ -1144,34 +1145,38 @@ llvm.core) as values for `linkage` (see
http://www.llvm.org/docs/LangRef.html#linkage[LLVM documentaion] for http://www.llvm.org/docs/LangRef.html#linkage[LLVM documentaion] for
details on each): details on each):
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="2",options="header"]
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Value, Equivalent LLVM Assembly Keyword Value, Equivalent LLVM Assembly Keyword
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `LINKAGE_EXTERNAL`, `externally_visible`
`LINKAGE_LINKONCE`, `linkonce` `LINKAGE_AVAILABLE_EXTERNALLY`, `available_externally`
`LINKAGE_WEAK`, `weak` `LINKAGE_LINKONCE_ANY`, `linkonce`
`LINKAGE_LINKONCE_ODR`, `linkonce_odr`
`LINKAGE_WEAK_ANY`, `weak`
`LINKAGE_WEAK_ODR`, `weak_odr`
`LINKAGE_APPENDING`, `appending` `LINKAGE_APPENDING`, `appending`
`LINKAGE_INTERNAL`, `internal` `LINKAGE_INTERNAL`, `internal`
`LINKAGE_PRIVATE`, `private`
`LINKAGE_LINKER_PRIVATE`, `linker_private`
`LINKAGE_DLLIMPORT`, `dllimport` `LINKAGE_DLLIMPORT`, `dllimport`
`LINKAGE_DLLEXPORT`, `dllexport` `LINKAGE_DLLEXPORT`, `dllexport`
`LINKAGE_EXTERNAL`, `externally visible`
`LINKAGE_EXTERNAL_WEAK`, `extern_weak` `LINKAGE_EXTERNAL_WEAK`, `extern_weak`
`LINKAGE_COMMON`, `common`
`LINKAGE_GHOST`, Stand-in functions `LINKAGE_GHOST`, Stand-in functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
The `section` property can be assigned strings (like ".rodata"), which The `section` property can be assigned strings (like ".rodata"), which
will be used if the target supports it. Visibility property can be set will be used if the target supports it. Visibility property can be set
to one of thse constants (from llvm.core, see also to one of thse constants (from llvm.core, see also
http://www.llvm.org/docs/LangRef.html#visibility[LLVM docs]): http://www.llvm.org/docs/LangRef.html#visibility[LLVM docs]):
[frame="all",grid="all"] [frame="all",grid="all",format="csv",cols="2",options="header"]
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
Value, Equivalent LLVM Assembly Keyword Value, Equivalent LLVM Assembly Keyword
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`VISIBILITY_DEFAULT`, `default` `VISIBILITY_DEFAULT`, `default`
`VISIBILITY_HIDDEN`, `hidden` `VISIBILITY_HIDDEN`, `hidden`
`VISIBILITY_PROTECTED`, `protected` `VISIBILITY_PROTECTED`, `protected`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
The `alignment` property can be 0 (default), or can be set to a power of The `alignment` property can be 0 (default), or can be set to a power of
2. The read-only property `is_declaration` can be used to check if the 2. The read-only property `is_declaration` can be used to check if the
@ -1345,38 +1350,43 @@ http://www.llvm.org/docs/LangRef.html#int_bswap[llvm.bswap]. The
integer argument. The list of intrinsic IDs defined as integer constants integer argument. The list of intrinsic IDs defined as integer constants
in `llvm.core`. These are: in `llvm.core`. These are:
[frame="all",grid="all"] [format="csv",cols="3"]
`33`33`33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |======================================================================
INTR_ANNOTATION,INTR_ATOMIC_CMP_SWAP,INTR_ATOMIC_LOAD_ADD `INTR_ALPHA_UMULH`,`INTR_ANNOTATION`,`INTR_ATOMIC_CMP_SWAP`
INTR_ATOMIC_LOAD_AND,INTR_ATOMIC_LOAD_MAX,INTR_ATOMIC_LOAD_MIN `INTR_ATOMIC_LOAD_ADD`,`INTR_ATOMIC_LOAD_AND`,`INTR_ATOMIC_LOAD_MAX`
INTR_ATOMIC_LOAD_NAND,INTR_ATOMIC_LOAD_OR,INTR_ATOMIC_LOAD_SUB `INTR_ATOMIC_LOAD_MIN`,`INTR_ATOMIC_LOAD_NAND`,`INTR_ATOMIC_LOAD_OR`
INTR_ATOMIC_LOAD_UMAX,INTR_ATOMIC_LOAD_UMIN,INTR_ATOMIC_LOAD_XOR `INTR_ATOMIC_LOAD_SUB`,`INTR_ATOMIC_LOAD_UMAX`,`INTR_ATOMIC_LOAD_UMIN`
INTR_ATOMIC_SWAP,INTR_BSWAP,INTR_COS `INTR_ATOMIC_LOAD_XOR`,`INTR_ATOMIC_SWAP`,`INTR_BSWAP`
INTR_CTLZ,INTR_CTPOP,INTR_CTTZ `INTR_CONVERTFF`,`INTR_CONVERTFSI`,`INTR_CONVERTFUI`
INTR_DBG_DECLARE,INTR_DBG_FUNC_START,INTR_DBG_REGION_END `INTR_CONVERTSIF`,`INTR_CONVERTSS`,`INTR_CONVERTSU`
INTR_DBG_REGION_START,INTR_DBG_STOPPOINT,INTR_EH_DWARF_CFA `INTR_CONVERTUIF`,`INTR_CONVERTUS`,`INTR_CONVERTUU`
INTR_EH_EXCEPTION,INTR_EH_RETURN_I32,INTR_EH_RETURN_I64 `INTR_COS`,`INTR_CTLZ`,`INTR_CTPOP`
INTR_EH_SELECTOR_I32,INTR_EH_SELECTOR_I64,INTR_EH_TYPEID_FOR_I32 `INTR_CTTZ`,`INTR_DBG_DECLARE`,`INTR_DBG_FUNC_START`
INTR_EH_TYPEID_FOR_I64,INTR_EH_UNWIND_INIT,INTR_EXP `INTR_DBG_REGION_END`,`INTR_DBG_REGION_START`,`INTR_DBG_STOPPOINT`
INTR_EXP2,INTR_FLT_ROUNDS,INTR_FRAMEADDRESS `INTR_EH_DWARF_CFA`,`INTR_EH_EXCEPTION`,`INTR_EH_RETURN_I32`
INTR_GCREAD,INTR_GCROOT,INTR_GCWRITE `INTR_EH_RETURN_I64`,`INTR_EH_SELECTOR_I32`,`INTR_EH_SELECTOR_I64`
INTR_INIT_TRAMPOLINE,INTR_LOG,INTR_LOG10 `INTR_EH_SJLJ_LONGJMP`,`INTR_EH_SJLJ_LSDA`,`INTR_EH_SJLJ_SETJMP`
INTR_LOG2,INTR_LONGJMP,INTR_MEMCPY_I32 `INTR_EH_TYPEID_FOR_I32`,`INTR_EH_TYPEID_FOR_I64`,`INTR_EH_UNWIND_INIT`
INTR_MEMCPY_I64,INTR_MEMMOVE_I32,INTR_MEMMOVE_I64 `INTR_EXP`,`INTR_EXP2`,`INTR_FLT_ROUNDS`
INTR_MEMORY_BARRIER,INTR_MEMSET_I32,INTR_MEMSET_I64 `INTR_FRAMEADDRESS`,`INTR_GCREAD`,`INTR_GCROOT`
INTR_PART_SELECT,INTR_PART_SET,INTR_PCMARKER `INTR_GCWRITE`,`INTR_INIT_TRAMPOLINE`,`INTR_LOG`
INTR_POW,INTR_POWI,INTR_PREFETCH `INTR_LOG10`,`INTR_LOG2`,`INTR_LONGJMP`
INTR_READCYCLECOUNTER,INTR_RETURNADDRESS,INTR_SETJMP `INTR_MEMCPY`,`INTR_MEMMOVE`,`INTR_MEMORY_BARRIER`
INTR_SIGLONGJMP,INTR_SIGSETJMP,INTR_SIN `INTR_MEMSET`,`INTR_PCMARKER`,`INTR_POW`
INTR_SQRT,INTR_STACKRESTORE,INTR_STACKSAVE `INTR_POWI`,`INTR_PREFETCH`,`INTR_PTR_ANNOTATION`
INTR_TRAP,INTR_VACOPY,INTR_VAEND `INTR_READCYCLECOUNTER`,`INTR_RETURNADDRESS`,`INTR_SADD_WITH_OVERFLOW`
INTR_VAR_ANNOTATION,INTR_VASTART, `INTR_SETJMP`,`INTR_SIGLONGJMP`,`INTR_SIGSETJMP`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `INTR_SIN`,`INTR_SMUL_WITH_OVERFLOW`,`INTR_SQRT`
`INTR_SSUB_WITH_OVERFLOW`,`INTR_STACKPROTECTOR`,`INTR_STACKRESTORE`
`INTR_STACKSAVE`,`INTR_TRAP`,`INTR_UADD_WITH_OVERFLOW`
`INTR_UMUL_WITH_OVERFLOW`,`INTR_USUB_WITH_OVERFLOW`,`INTR_VACOPY`
`INTR_VAEND`,`INTR_VAR_ANNOTATION`,`INTR_VASTART`
|======================================================================
There are also target-specific intrinsics (which correspond to that There are also target-specific intrinsics (which correspond to that
target's CPU instructions) available, but are omitted here for brevity. target's CPU instructions) available, but are omitted here for brevity.
Full list can be seen from Full list can be seen from
http://code.google.com/p/llvm-py/source/browse/trunk/llvm/core.py[`core.py`]. http://code.google.com/p/llvm-py/source/browse/trunk/llvm/_intrinsic_ids.py[`_intrinsic_ids.py`].
See the http://www.llvm.org/docs/LangRef.html[LLVM Language Reference] See the http://www.llvm.org/docs/LangRef.html[LLVM Language Reference]
for more information on the intrinsics, and the for more information on the intrinsics, and the
http://code.google.com/p/llvm-py/source/browse#svn/trunk/test[test] http://code.google.com/p/llvm-py/source/browse#svn/trunk/test[test]
@ -1401,7 +1411,7 @@ Value, Equivalent LLVM Assembly Keyword
See the http://www.llvm.org/docs/LangRef.html#callingconv[LLVM docs] for See the http://www.llvm.org/docs/LangRef.html#callingconv[LLVM docs] for
more information on each. Backend-specific numbered conventions can be more information on each. Backend-specific numbered conventions can be
directly set as numbers. directly passed as integers.
An arbitrary string identifying which garbage collector to use can be An arbitrary string identifying which garbage collector to use can be
set or got with the property `collector`. set or got with the property `collector`.
@ -1456,6 +1466,7 @@ should be dropped after `delete` has been called.
Functions can be verified with the `verify` method. This does not work Functions can be verified with the `verify` method. This does not work
properly yet (aborts on errors), investigation pending. properly yet (aborts on errors), investigation pending.
TODO function attributes
Argument (llvm.core) Argument (llvm.core)
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
@ -1547,6 +1558,9 @@ the file named
http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE[LICENSE] http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE[LICENSE]
available in the source distribution. available in the source distribution.
There is an llvm-py mailing list / users group:
http://groups.google.com/group/llvm-py.
The entire llvm-py website is generated from marked up text files The entire llvm-py website is generated from marked up text files
using the tool http://www.methods.co.nz/asciidoc/[AsciiDoc]. These text using the tool http://www.methods.co.nz/asciidoc/[AsciiDoc]. These text
files and the (pre-)generated HTML pages are available in the source files and the (pre-)generated HTML pages are available in the source

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.5.0" />
<meta name="description" content="Python bindings for LLVM" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="llvm python compiler backend bindings" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
@ -33,16 +33,17 @@
</div> </div>
<div id="preamble"> <div id="preamble">
<div class="sectionbody"> <div class="sectionbody">
<p>llvm-py is developed by Mahadevan R, in his spare time. He can be <div class="paragraph"><p>llvm-py is developed and maintained by Mahadevan R, with contributions from
reached at mdevan.foobar@gmail.com, on the llvm-dev mailing list and many users all over the world. He can be reached at <a href="mailto:mdevan.foobar@gmail.com">mdevan.foobar@gmail.com</a>,
irc.oftc.net#llvm (mdevan).</p> on the llvm-dev mailing list and (sometimes) as mdevan on irc.oftc.net#llvm.</p></div>
<p>Many thanks to the guys over at LLVM for all the nifty software.</p> <div class="paragraph"><p>Many thanks to the guys over at LLVM for all the nifty software, for all
the llvm-py contributors.</p></div>
</div> </div>
</div> </div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 08-Sep-2008. Last updated 2009-10-28.
</div> </div>
</div> </div>
</div> </div>

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.5.0" />
<meta name="description" content="Python bindings for LLVM" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="llvm python compiler backend bindings" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
@ -33,8 +33,8 @@
</div> </div>
<div id="preamble"> <div id="preamble">
<div class="sectionbody"> <div class="sectionbody">
<p>You can make a difference, just by:</p> <div class="paragraph"><p>You can make a difference, just by:</p></div>
<ul> <div class="ulist"><ul>
<li> <li>
<p> <p>
getting llvm-py to work on an as-yet-untested platform getting llvm-py to work on an as-yet-untested platform
@ -60,9 +60,9 @@ improving the test scripts and documentation
spreading the word spreading the word
</p> </p>
</li> </li>
</ul> </ul></div>
<p>Useful links:</p> <div class="paragraph"><p>Useful links:</p></div>
<ul> <div class="ulist"><ul>
<li> <li>
<p> <p>
Google code hosting: <a href="http://code.google.com/p/llvm-py/">http://code.google.com/p/llvm-py/</a> Google code hosting: <a href="http://code.google.com/p/llvm-py/">http://code.google.com/p/llvm-py/</a>
@ -78,20 +78,20 @@ Browse SVN: <a href="http://code.google.com/p/llvm-py/source/browse/">http://cod
Issues tracker: <a href="http://code.google.com/p/llvm-py/issues/list">http://code.google.com/p/llvm-py/issues/list</a> Issues tracker: <a href="http://code.google.com/p/llvm-py/issues/list">http://code.google.com/p/llvm-py/issues/list</a>
</p> </p>
</li> </li>
</ul> </ul></div>
<p>SVN HEAD can be checked out like so:</p> <div class="paragraph"><p>SVN HEAD can be checked out like so:</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py</tt></pre> <pre><tt>$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py</tt></pre>
</div></div> </div></div>
<p>Usual caveats apply: cutting edge, may be broken (but usually not), <div class="paragraph"><p>Usual caveats apply: cutting edge, may be broken (but usually not),
update and merge before sending patches etc.</p> update and merge before sending patches etc.</p></div>
</div> </div>
</div> </div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 08-Sep-2008. Last updated 2009-10-28.
</div> </div>
</div> </div>
</div> </div>

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.6" /> <meta name="generator" content="AsciiDoc 8.5.0" />
<meta name="description" content="Python bindings for LLVM" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="llvm python compiler backend bindings" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
@ -33,127 +33,18 @@
</div> </div>
<div id="preamble"> <div id="preamble">
<div class="sectionbody"> <div class="sectionbody">
<div class="para"><p>The latest release is 0.5, released 22-Nov-2008 (<a href="#changelog">Changelog</a> <div class="paragraph"><p>The latest release is 0.6, released 28-Oct-2009 (<a href="#changelog">Changelog</a>
below). 0.5 works only with LLVM 2.4, use 0.4 if you have LLVM 2.3.</p></div> below). 0.6 works only with LLVM 2.6.</p></div>
<div class="para"><p>Download it here:</p></div> <div class="paragraph"><p>Download it here:
<div class="tableblock"> - <a href="http://llvm-py.googlecode.com/files/llvm-py-0.6.tar.bz2">llvm-py-0.6.tar.bz2</a> (primary)
<table rules="all" - <a href="llvm-py-0.6.tar.bz2">llvm-py-0.6.tar.bz2</a> (mirror)</p></div>
frame="border" <div class="paragraph"><p>Older versions are available <a href="http://llvm-py.googlecode.com/files/">here</a>.</p></div>
cellspacing="0" cellpadding="4"> <div class="paragraph"><p>The latest code can be checked out from SVN like so:</p></div>
<col width="200" />
<col width="200" />
<col width="200" />
<col width="200" />
<thead>
<tr>
<th align="left">
Release
</th>
<th align="left">
Date
</th>
<th align="left">
Package
</th>
<th align="left">
Mirror
</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td align="left">
0.5
</td>
<td align="left">
22-Nov-2008
</td>
<td align="left">
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.5.tar.bz2">llvm-py-0.5.tar.bz2</a>
</td>
<td align="left">
<a href="llvm-py-0.5.tar.bz2">llvm-py-0.5.tar.bz2</a>
</td>
</tr>
<tr>
<td align="left">
0.4
</td>
<td align="left">
21-Nov-2008
</td>
<td align="left">
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.4.tar.bz2">llvm-py-0.4.tar.bz2</a>
</td>
<td align="left">
<a href="llvm-py-0.4.tar.bz2">llvm-py-0.4.tar.bz2</a>
</td>
</tr>
<tr>
<td align="left">
0.3
</td>
<td align="left">
8-Sep-2008
</td>
<td align="left">
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.3.tar.bz2">llvm-py-0.3.tar.bz2</a>
</td>
<td align="left">
<a href="llvm-py-0.3.tar.bz2">llvm-py-0.3.tar.bz2</a>
</td>
</tr>
<tr>
<td align="left">
0.2.1
</td>
<td align="left">
18-Jun-2008
</td>
<td align="left">
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.2.1.tar.bz2">llvm-py-0.2.1.tar.bz2</a>
</td>
<td align="left">
<a href="llvm-py-0.2.1.tar.bz2">llvm-py-0.2.1.tar.bz2</a>
</td>
</tr>
<tr>
<td align="left">
0.2
</td>
<td align="left">
15-Jun-2008
</td>
<td align="left">
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.2.tar.bz2">llvm-py-0.2.tar.bz2</a>
</td>
<td align="left">
<a href="llvm-py-0.2.tar.bz2">llvm-py-0.2.tar.bz2</a>
</td>
</tr>
<tr>
<td align="left">
0.1
</td>
<td align="left">
20-May-2008
</td>
<td align="left">
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.1.tar.bz2">llvm-py-0.1.tar.bz2</a>
</td>
<td align="left">
<a href="llvm-py-0.1.tar.bz2">llvm-py-0.1.tar.bz2</a>
</td>
</tr>
</tbody>
</table>
</div>
<div class="para"><p>The latest code can be checked out from SVN like so:</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py</tt></pre> <pre><tt>$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py</tt></pre>
</div></div> </div></div>
<div class="para"><p>Follow the steps <a href="userguide.html#install">described here</a> to install the <div class="paragraph"><p>Follow the steps <a href="userguide.html#install">described here</a> to install the
package.</p></div> package.</p></div>
</div> </div>
</div> </div>
@ -161,7 +52,24 @@ package.</p></div>
<div class="sectionbody"> <div class="sectionbody">
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>0.5, 22-Nov-2008: <pre><tt>0.6, in progress:
* Migrate to LLVM 2.6 (KS Sreeram) (Issue #25).
* Inline function (Corrado Zoccolo).
* Get pointer to function (Corrado Zoccolo).
* More properties/methods for TargetData (Florian Noding) (Issue #16).
* Value.uses API.
* Fetch operands of instructions (Seth Warn).
* Unaliased objects (with Seth Warn).
* Value factory, more Constant subclasses.
* Module.link_in and Instruction.is_volatile (Seth Warn).
* Fix Builder.position_at_beginning crash (Issue #10).
* Builds on gentoo.
* Code cleanup.
* Migrate to LLVM 2.5.
0.5, 22-Nov-2008:
* Added vicmp, vfcmp instructions and constant expressions. * Added vicmp, vfcmp instructions and constant expressions.
* Builds on FreeBSD. * Builds on FreeBSD.
@ -221,7 +129,7 @@ package.</p></div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 2008-11-22. Last updated 2009-10-28.
</div> </div>
</div> </div>
</div> </div>

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.5.0" />
<meta name="description" content="Python bindings for LLVM" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="llvm python compiler backend bindings" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
@ -31,24 +31,23 @@
<div id="header"> <div id="header">
<h1>Examples and LLVM Tutorials</h1> <h1>Examples and LLVM Tutorials</h1>
</div> </div>
<h2>Examples</h2> <h2 id="_examples">Examples</h2>
<div class="sectionbody"> <div class="sectionbody">
<h3>A Simple Function</h3> <h3 id="_a_simple_function">A Simple Function</h3><div style="clear:left"></div>
<p>Let's create a (LLVM) module containing a single function, corresponding <div class="paragraph"><p>Let&#8217;s create a (LLVM) module containing a single function, corresponding
to the <tt>C</tt> function:</p> to the <tt>C</tt> function:</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.4 <div class="content"><!-- Generator: GNU source-highlight 3.1
by Lorenzo Bettini by Lorenzo Bettini
http://www.lorenzobettini.it http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite --> http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">sum</span></span><span style="color: #990000">(</span><span style="color: #009900">int</span> a<span style="color: #990000">,</span> <span style="color: #009900">int</span> b<span style="color: #990000">)</span> <pre><tt><span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">sum</span></span><span style="color: #990000">(</span><span style="color: #009900">int</span> a<span style="color: #990000">,</span> <span style="color: #009900">int</span> b<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span> <span style="color: #FF0000">{</span>
<span style="font-weight: bold"><span style="color: #0000FF">return</span></span> a <span style="color: #990000">+</span> b<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> a <span style="color: #990000">+</span> b<span style="color: #990000">;</span>
<span style="color: #FF0000">}</span> <span style="color: #FF0000">}</span></tt></pre></div></div>
</tt></pre></div></div> <div class="paragraph"><p>Here&#8217;s how it looks like:</p></div>
<p>Here's how it looks like:</p>
<div class="listingblock"> <div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.4 <div class="content"><!-- Generator: GNU source-highlight 3.1
by Lorenzo Bettini by Lorenzo Bettini
http://www.lorenzobettini.it http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite --> http://www.gnu.org/software/src-highlite -->
@ -59,45 +58,44 @@ http://www.gnu.org/software/src-highlite -->
<span style="font-weight: bold"><span style="color: #000080">from</span></span> llvm<span style="color: #990000">.</span>core <span style="font-weight: bold"><span style="color: #000080">import</span></span> <span style="color: #990000">*</span> <span style="font-weight: bold"><span style="color: #000080">from</span></span> llvm<span style="color: #990000">.</span>core <span style="font-weight: bold"><span style="color: #000080">import</span></span> <span style="color: #990000">*</span>
<span style="font-style: italic"><span style="color: #9A1900"># Create an (empty) module.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Create an (empty) module.</span></span>
my<span style="color: #009900">_</span>module <span style="color: #990000">=</span> <span style="color: #009900">Module</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span><span style="color: #FF0000">'my_module'</span><span style="color: #990000">)</span> my_module <span style="color: #990000">=</span> Module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span><span style="color: #FF0000">'my_module'</span><span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># All the types involved here are "int"s. This type is represented</span></span> <span style="font-style: italic"><span style="color: #9A1900"># All the types involved here are "int"s. This type is represented</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># by an object of the llvm.core.Type class:</span></span> <span style="font-style: italic"><span style="color: #9A1900"># by an object of the llvm.core.Type class:</span></span>
ty<span style="color: #009900">_</span>int <span style="color: #990000">=</span> <span style="color: #009900">Type</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">()</span> <span style="font-style: italic"><span style="color: #9A1900"># by default 32 bits</span></span> ty_int <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">()</span> <span style="font-style: italic"><span style="color: #9A1900"># by default 32 bits</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We need to represent the class of functions that accept two integers</span></span> <span style="font-style: italic"><span style="color: #9A1900"># We need to represent the class of functions that accept two integers</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># and return an integer. This is represented by an object of the</span></span> <span style="font-style: italic"><span style="color: #9A1900"># and return an integer. This is represented by an object of the</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># function type (llvm.core.FunctionType):</span></span> <span style="font-style: italic"><span style="color: #9A1900"># function type (llvm.core.FunctionType):</span></span>
ty<span style="color: #009900">_</span>func <span style="color: #990000">=</span> <span style="color: #009900">Type</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span>ty<span style="color: #009900">_</span>int<span style="color: #990000">,</span> <span style="color: #990000">[</span>ty<span style="color: #009900">_</span>int<span style="color: #990000">,</span> ty<span style="color: #009900">_</span>int<span style="color: #990000">])</span> ty_func <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span>ty_int<span style="color: #990000">,</span> <span style="color: #990000">[</span>ty_int<span style="color: #990000">,</span> ty_int<span style="color: #990000">])</span>
<span style="font-style: italic"><span style="color: #9A1900"># Now we need a function named 'sum' of this type. Functions are not</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Now we need a function named 'sum' of this type. Functions are not</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># free-standing (in llvm-py); it needs to be contained in a module.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># free-standing (in llvm-py); it needs to be contained in a module.</span></span>
f<span style="color: #009900">_</span>sum <span style="color: #990000">=</span> my<span style="color: #009900">_</span>module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_function</span></span><span style="color: #990000">(</span>ty<span style="color: #009900">_</span>func<span style="color: #990000">,</span> <span style="color: #FF0000">"sum"</span><span style="color: #990000">)</span> f_sum <span style="color: #990000">=</span> my_module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_function</span></span><span style="color: #990000">(</span>ty_func<span style="color: #990000">,</span> <span style="color: #FF0000">"sum"</span><span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># Let's name the function arguments as 'a' and 'b'.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Let's name the function arguments as 'a' and 'b'.</span></span>
f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"a"</span> f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"a"</span>
f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"b"</span> f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"b"</span>
<span style="font-style: italic"><span style="color: #9A1900"># Our function needs a "basic block" -- a set of instructions that</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Our function needs a "basic block" -- a set of instructions that</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># end with a terminator (like return, branch etc.). By convention</span></span> <span style="font-style: italic"><span style="color: #9A1900"># end with a terminator (like return, branch etc.). By convention</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># the first block is called "entry".</span></span> <span style="font-style: italic"><span style="color: #9A1900"># the first block is called "entry".</span></span>
bb <span style="color: #990000">=</span> f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append_basic_block</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"entry"</span><span style="color: #990000">)</span> bb <span style="color: #990000">=</span> f_sum<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append_basic_block</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"entry"</span><span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># Let's add instructions into the block. For this, we need an</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Let's add instructions into the block. For this, we need an</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># instruction builder:</span></span> <span style="font-style: italic"><span style="color: #9A1900"># instruction builder:</span></span>
builder <span style="color: #990000">=</span> <span style="color: #009900">Builder</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>bb<span style="color: #990000">)</span> builder <span style="color: #990000">=</span> Builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>bb<span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># OK, now for the instructions themselves. We'll create an add</span></span> <span style="font-style: italic"><span style="color: #9A1900"># OK, now for the instructions themselves. We'll create an add</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># instruction that returns the sum as a value, which we'll use</span></span> <span style="font-style: italic"><span style="color: #9A1900"># instruction that returns the sum as a value, which we'll use</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># a ret instruction to return.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># a ret instruction to return.</span></span>
tmp <span style="color: #990000">=</span> builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add</span></span><span style="color: #990000">(</span>f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">],</span> f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">],</span> <span style="color: #FF0000">"tmp"</span><span style="color: #990000">)</span> tmp <span style="color: #990000">=</span> builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add</span></span><span style="color: #990000">(</span>f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">],</span> f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">],</span> <span style="color: #FF0000">"tmp"</span><span style="color: #990000">)</span>
builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">ret</span></span><span style="color: #990000">(</span>tmp<span style="color: #990000">)</span> builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">ret</span></span><span style="color: #990000">(</span>tmp<span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># We've completed the definition now! Let's see the LLVM assembly</span></span> <span style="font-style: italic"><span style="color: #9A1900"># We've completed the definition now! Let's see the LLVM assembly</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># language representation of what we've created:</span></span> <span style="font-style: italic"><span style="color: #9A1900"># language representation of what we've created:</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">print</span></span> my<span style="color: #009900">_</span>module <span style="font-weight: bold"><span style="color: #0000FF">print</span></span> my_module</tt></pre></div></div>
</tt></pre></div></div> <div class="paragraph"><p>Here is the output:</p></div>
<p>Here is the output:</p>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>; ModuleID = 'my_module' <pre><tt>; ModuleID = 'my_module'
@ -108,10 +106,10 @@ entry:
ret i32 %tmp ret i32 %tmp
}</tt></pre> }</tt></pre>
</div></div> </div></div>
<h3>Adding JIT Compilation</h3> <h3 id="_adding_jit_compilation">Adding JIT Compilation</h3><div style="clear:left"></div>
<p>Let's compile this function in-memory and run it.</p> <div class="paragraph"><p>Let&#8217;s compile this function in-memory and run it.</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.4 <div class="content"><!-- Generator: GNU source-highlight 3.1
by Lorenzo Bettini by Lorenzo Bettini
http://www.lorenzobettini.it http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite --> http://www.gnu.org/software/src-highlite -->
@ -123,50 +121,48 @@ http://www.gnu.org/software/src-highlite -->
<span style="font-weight: bold"><span style="color: #000080">from</span></span> llvm<span style="color: #990000">.</span>ee <span style="font-weight: bold"><span style="color: #000080">import</span></span> <span style="color: #990000">*</span> <span style="font-style: italic"><span style="color: #9A1900"># new import: ee = Execution Engine</span></span> <span style="font-weight: bold"><span style="color: #000080">from</span></span> llvm<span style="color: #990000">.</span>ee <span style="font-weight: bold"><span style="color: #000080">import</span></span> <span style="color: #990000">*</span> <span style="font-style: italic"><span style="color: #9A1900"># new import: ee = Execution Engine</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># Create a module, as in the previous example.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Create a module, as in the previous example.</span></span>
my<span style="color: #009900">_</span>module <span style="color: #990000">=</span> <span style="color: #009900">Module</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span><span style="color: #FF0000">'my_module'</span><span style="color: #990000">)</span> my_module <span style="color: #990000">=</span> Module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span><span style="color: #FF0000">'my_module'</span><span style="color: #990000">)</span>
ty<span style="color: #009900">_</span>int <span style="color: #990000">=</span> <span style="color: #009900">Type</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">()</span> <span style="font-style: italic"><span style="color: #9A1900"># by default 32 bits</span></span> ty_int <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">()</span> <span style="font-style: italic"><span style="color: #9A1900"># by default 32 bits</span></span>
ty<span style="color: #009900">_</span>func <span style="color: #990000">=</span> <span style="color: #009900">Type</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span>ty<span style="color: #009900">_</span>int<span style="color: #990000">,</span> <span style="color: #990000">[</span>ty<span style="color: #009900">_</span>int<span style="color: #990000">,</span> ty<span style="color: #009900">_</span>int<span style="color: #990000">])</span> ty_func <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span>ty_int<span style="color: #990000">,</span> <span style="color: #990000">[</span>ty_int<span style="color: #990000">,</span> ty_int<span style="color: #990000">])</span>
f<span style="color: #009900">_</span>sum <span style="color: #990000">=</span> my<span style="color: #009900">_</span>module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_function</span></span><span style="color: #990000">(</span>ty<span style="color: #009900">_</span>func<span style="color: #990000">,</span> <span style="color: #FF0000">"sum"</span><span style="color: #990000">)</span> f_sum <span style="color: #990000">=</span> my_module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_function</span></span><span style="color: #990000">(</span>ty_func<span style="color: #990000">,</span> <span style="color: #FF0000">"sum"</span><span style="color: #990000">)</span>
f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"a"</span> f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"a"</span>
f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"b"</span> f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">].</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"b"</span>
bb <span style="color: #990000">=</span> f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append_basic_block</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"entry"</span><span style="color: #990000">)</span> bb <span style="color: #990000">=</span> f_sum<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append_basic_block</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"entry"</span><span style="color: #990000">)</span>
builder <span style="color: #990000">=</span> <span style="color: #009900">Builder</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>bb<span style="color: #990000">)</span> builder <span style="color: #990000">=</span> Builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>bb<span style="color: #990000">)</span>
tmp <span style="color: #990000">=</span> builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add</span></span><span style="color: #990000">(</span>f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">],</span> f<span style="color: #009900">_</span>sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">],</span> <span style="color: #FF0000">"tmp"</span><span style="color: #990000">)</span> tmp <span style="color: #990000">=</span> builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add</span></span><span style="color: #990000">(</span>f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">],</span> f_sum<span style="color: #990000">.</span>args<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">],</span> <span style="color: #FF0000">"tmp"</span><span style="color: #990000">)</span>
builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">ret</span></span><span style="color: #990000">(</span>tmp<span style="color: #990000">)</span> builder<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">ret</span></span><span style="color: #990000">(</span>tmp<span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># Create a module provider object first. Modules can come from</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Create a module provider object first. Modules can come from</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># in-memory IRs like what we created now, or from bitcode (.bc)</span></span> <span style="font-style: italic"><span style="color: #9A1900"># in-memory IRs like what we created now, or from bitcode (.bc)</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># files. The module provider abstracts this detail.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># files. The module provider abstracts this detail.</span></span>
mp <span style="color: #990000">=</span> <span style="color: #009900">ModuleProvider</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>my<span style="color: #009900">_</span>module<span style="color: #990000">)</span> mp <span style="color: #990000">=</span> ModuleProvider<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>my_module<span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># Create an execution engine object. This will create a JIT compiler</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Create an execution engine object. This will create a JIT compiler</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># on platforms that support it, or an interpreter otherwise.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># on platforms that support it, or an interpreter otherwise.</span></span>
ee <span style="color: #990000">=</span> <span style="color: #009900">ExecutionEngine</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>mp<span style="color: #990000">)</span> ee <span style="color: #990000">=</span> ExecutionEngine<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span>mp<span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># The arguments needs to be passed as "GenericValue" objects.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># The arguments needs to be passed as "GenericValue" objects.</span></span>
arg1 <span style="color: #990000">=</span> <span style="color: #009900">GenericValue</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span>ty<span style="color: #009900">_</span>int<span style="color: #990000">,</span> <span style="color: #993399">100</span><span style="color: #990000">)</span> arg1 <span style="color: #990000">=</span> GenericValue<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span>ty_int<span style="color: #990000">,</span> <span style="color: #993399">100</span><span style="color: #990000">)</span>
arg2 <span style="color: #990000">=</span> <span style="color: #009900">GenericValue</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span>ty<span style="color: #009900">_</span>int<span style="color: #990000">,</span> <span style="color: #993399">42</span><span style="color: #990000">)</span> arg2 <span style="color: #990000">=</span> GenericValue<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span>ty_int<span style="color: #990000">,</span> <span style="color: #993399">42</span><span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># Now let's compile and run!</span></span> <span style="font-style: italic"><span style="color: #9A1900"># Now let's compile and run!</span></span>
retval <span style="color: #990000">=</span> ee<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">run_function</span></span><span style="color: #990000">(</span>f<span style="color: #009900">_</span>sum<span style="color: #990000">,</span> <span style="color: #990000">[</span>arg1<span style="color: #990000">,</span> arg2<span style="color: #990000">])</span> retval <span style="color: #990000">=</span> ee<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">run_function</span></span><span style="color: #990000">(</span>f_sum<span style="color: #990000">,</span> <span style="color: #990000">[</span>arg1<span style="color: #990000">,</span> arg2<span style="color: #990000">])</span>
<span style="font-style: italic"><span style="color: #9A1900"># The return value is also GenericValue. Let's print it.</span></span> <span style="font-style: italic"><span style="color: #9A1900"># The return value is also GenericValue. Let's print it.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">print</span></span> <span style="color: #FF0000">"returned"</span><span style="color: #990000">,</span> retval<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">as_int</span></span><span style="color: #990000">()</span> <span style="font-weight: bold"><span style="color: #0000FF">print</span></span> <span style="color: #FF0000">"returned"</span><span style="color: #990000">,</span> retval<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">as_int</span></span><span style="color: #990000">()</span></tt></pre></div></div>
</tt></pre></div></div> <div class="paragraph"><p>And here&#8217;s the output:</p></div>
<p>And here's the output:</p>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>returned 142</tt></pre> <pre><tt>returned 142</tt></pre>
</div></div> </div></div>
</div> </div>
<h2>LLVM Tutorials</h2> <h2 id="_llvm_tutorials">LLVM Tutorials</h2>
<div class="sectionbody"> <div class="sectionbody">
<p>The <a href="http://www.llvm.org/docs/tutorial/">LLVM tutorials</a> have been <div class="paragraph"><p>The <a href="http://www.llvm.org/docs/tutorial/">LLVM tutorials</a> have been
ported to llvm-py. Below are the links to the original LLVM tutorial and ported to llvm-py. Below are the links to the original LLVM tutorial and
the corresponding Python code using llvm-py:</p> the corresponding Python code using llvm-py:</p></div>
<div class="title">Simple JIT Tutorials</div> <div class="paragraph"><div class="title">Simple JIT Tutorials</div><p>(contributed by Sebastien Binet)</p></div>
<p>(These were contributed by Sebastien Binet; thanks!)</p> <div class="olist arabic"><ol class="arabic">
<ol>
<li> <li>
<p> <p>
A First Function A First Function
@ -181,8 +177,8 @@ A More Complicated Function
<a href="examples/JITTutorial2.html">llvm-py</a> <a href="examples/JITTutorial2.html">llvm-py</a>
</p> </p>
</li> </li>
</ol> </ol></div>
<div class="title">Kaleidoscope: Implementing a Language with LLVM</div><ol> <div class="olist arabic"><div class="title">Kaleidoscope: Implementing a Language with LLVM</div><ol class="arabic">
<li> <li>
<p> <p>
Tutorial Introduction and the Lexer (TODO) Tutorial Introduction and the Lexer (TODO)
@ -223,12 +219,12 @@ Extending the language: mutable variables / SSA construction (TODO)
Conclusion and other useful LLVM tidbits (TODO) Conclusion and other useful LLVM tidbits (TODO)
</p> </p>
</li> </li>
</ol> </ol></div>
</div> </div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 08-Sep-2008. Last updated 2009-10-28.
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,4 +1,4 @@
<!-- Generator: GNU source-highlight 2.4 <!-- Generator: GNU source-highlight 3.1
by Lorenzo Bettini by Lorenzo Bettini
http://www.lorenzobettini.it http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite --> http://www.gnu.org/software/src-highlite -->
@ -7,30 +7,30 @@ http://www.gnu.org/software/src-highlite -->
<b><font color="#000080">from</font></b> llvm<font color="#990000">.</font>core <b><font color="#000080">import</font></b> <font color="#990000">*</font> <b><font color="#000080">from</font></b> llvm<font color="#990000">.</font>core <b><font color="#000080">import</font></b> <font color="#990000">*</font>
<i><font color="#9A1900"># create a module</font></i> <i><font color="#9A1900"># create a module</font></i>
module <font color="#990000">=</font> <font color="#009900">Module</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font><font color="#FF0000">"tut1"</font><font color="#990000">)</font> module <font color="#990000">=</font> Module<font color="#990000">.</font><b><font color="#000000">new</font></b> <font color="#990000">(</font><font color="#FF0000">"tut1"</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a function type taking 3 32-bit integers, return a 32-bit integer</font></i> <i><font color="#9A1900"># create a function type taking 3 32-bit integers, return a 32-bit integer</font></i>
ty<font color="#009900">_</font>int <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">int </font></b><font color="#990000">(</font><font color="#993399">32</font><font color="#990000">)</font> ty_int <font color="#990000">=</font> Type<font color="#990000">.</font><b><font color="#000000">int</font></b> <font color="#990000">(</font><font color="#993399">32</font><font color="#990000">)</font>
func<font color="#009900">_</font>type <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">function </font></b><font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,</font> <font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,)*</font><font color="#993399">3</font><font color="#990000">)</font> func_type <font color="#990000">=</font> Type<font color="#990000">.</font><b><font color="#000000">function</font></b> <font color="#990000">(</font>ty_int<font color="#990000">,</font> <font color="#990000">(</font>ty_int<font color="#990000">,)*</font><font color="#993399">3</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a function of that type</font></i> <i><font color="#9A1900"># create a function of that type</font></i>
mul<font color="#009900">_</font>add <font color="#990000">=</font> <font color="#009900">Function</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>module<font color="#990000">,</font> func<font color="#009900">_</font>type<font color="#990000">,</font> <font color="#FF0000">"mul_add"</font><font color="#990000">)</font> mul_add <font color="#990000">=</font> Function<font color="#990000">.</font><b><font color="#000000">new</font></b> <font color="#990000">(</font>module<font color="#990000">,</font> func_type<font color="#990000">,</font> <font color="#FF0000">"mul_add"</font><font color="#990000">)</font>
mul<font color="#009900">_</font>add<font color="#990000">.</font>calling<font color="#009900">_</font>convention <font color="#990000">=</font> <font color="#009900">CC_C</font> mul_add<font color="#990000">.</font>calling_convention <font color="#990000">=</font> CC_C
x <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">];</font> x<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"x"</font> x <font color="#990000">=</font> mul_add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">];</font> x<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"x"</font>
y <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">1</font><font color="#990000">];</font> y<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"y"</font> y <font color="#990000">=</font> mul_add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">1</font><font color="#990000">];</font> y<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"y"</font>
z <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">];</font> z<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"z"</font> z <font color="#990000">=</font> mul_add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">];</font> z<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"z"</font>
<i><font color="#9A1900"># implement the function</font></i> <i><font color="#9A1900"># implement the function</font></i>
<i><font color="#9A1900"># new block</font></i> <i><font color="#9A1900"># new block</font></i>
blk <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"entry"</font><font color="#990000">)</font> blk <font color="#990000">=</font> mul_add<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"entry"</font><font color="#990000">)</font>
<i><font color="#9A1900"># IR builder</font></i> <i><font color="#9A1900"># IR builder</font></i>
bldr <font color="#990000">=</font> <font color="#009900">Builder</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>blk<font color="#990000">)</font> bldr <font color="#990000">=</font> Builder<font color="#990000">.</font><b><font color="#000000">new</font></b> <font color="#990000">(</font>blk<font color="#990000">)</font>
tmp<font color="#009900">_</font><font color="#993399">1</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">mul </font></b><font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp_1"</font><font color="#990000">)</font> tmp_1 <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">mul</font></b> <font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp_1"</font><font color="#990000">)</font>
tmp<font color="#009900">_</font><font color="#993399">2</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">add </font></b><font color="#990000">(</font>tmp<font color="#009900">_</font><font color="#993399">1</font><font color="#990000">,</font> z<font color="#990000">,</font> <font color="#FF0000">"tmp_2"</font><font color="#990000">)</font> tmp_2 <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">add</font></b> <font color="#990000">(</font>tmp_1<font color="#990000">,</font> z<font color="#990000">,</font> <font color="#FF0000">"tmp_2"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret </font></b><font color="#990000">(</font>tmp<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">ret</font></b> <font color="#990000">(</font>tmp_2<font color="#990000">)</font>
<b><font color="#0000FF">print</font></b> module <b><font color="#0000FF">print</font></b> module
</tt></pre> </tt></pre>

View file

@ -1,4 +1,4 @@
<!-- Generator: GNU source-highlight 2.4 <!-- Generator: GNU source-highlight 3.1
by Lorenzo Bettini by Lorenzo Bettini
http://www.lorenzobettini.it http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite --> http://www.gnu.org/software/src-highlite -->
@ -7,14 +7,14 @@ http://www.gnu.org/software/src-highlite -->
<b><font color="#000080">from</font></b> llvm<font color="#990000">.</font>core <b><font color="#000080">import</font></b> <font color="#990000">*</font> <b><font color="#000080">from</font></b> llvm<font color="#990000">.</font>core <b><font color="#000080">import</font></b> <font color="#990000">*</font>
<i><font color="#9A1900"># create a module</font></i> <i><font color="#9A1900"># create a module</font></i>
module <font color="#990000">=</font> <font color="#009900">Module</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font><font color="#FF0000">"tut2"</font><font color="#990000">)</font> module <font color="#990000">=</font> Module<font color="#990000">.</font><b><font color="#000000">new</font></b> <font color="#990000">(</font><font color="#FF0000">"tut2"</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a function type taking 2 integers, return a 32-bit integer</font></i> <i><font color="#9A1900"># create a function type taking 2 integers, return a 32-bit integer</font></i>
ty<font color="#009900">_</font>int <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">int </font></b><font color="#990000">(</font><font color="#993399">32</font><font color="#990000">)</font> ty_int <font color="#990000">=</font> Type<font color="#990000">.</font><b><font color="#000000">int</font></b> <font color="#990000">(</font><font color="#993399">32</font><font color="#990000">)</font>
func<font color="#009900">_</font>type <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">function </font></b><font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,</font> <font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,</font> ty<font color="#009900">_</font>int<font color="#990000">))</font> func_type <font color="#990000">=</font> Type<font color="#990000">.</font><b><font color="#000000">function</font></b> <font color="#990000">(</font>ty_int<font color="#990000">,</font> <font color="#990000">(</font>ty_int<font color="#990000">,</font> ty_int<font color="#990000">))</font>
<i><font color="#9A1900"># create a function of that type</font></i> <i><font color="#9A1900"># create a function of that type</font></i>
gcd <font color="#990000">=</font> <font color="#009900">Function</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>module<font color="#990000">,</font> func<font color="#009900">_</font>type<font color="#990000">,</font> <font color="#FF0000">"gcd"</font><font color="#990000">)</font> gcd <font color="#990000">=</font> Function<font color="#990000">.</font><b><font color="#000000">new</font></b> <font color="#990000">(</font>module<font color="#990000">,</font> func_type<font color="#990000">,</font> <font color="#FF0000">"gcd"</font><font color="#990000">)</font>
<i><font color="#9A1900"># name function args</font></i> <i><font color="#9A1900"># name function args</font></i>
x <font color="#990000">=</font> gcd<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">];</font> x<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"x"</font> x <font color="#990000">=</font> gcd<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">];</font> x<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"x"</font>
@ -25,31 +25,31 @@ y <font color="#990000">=</font> gcd<font color="#990000">.</font>args<font colo
<i><font color="#9A1900"># blocks...</font></i> <i><font color="#9A1900"># blocks...</font></i>
entry <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"entry"</font><font color="#990000">)</font> entry <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"entry"</font><font color="#990000">)</font>
ret <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"return"</font><font color="#990000">)</font> ret <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"return"</font><font color="#990000">)</font>
cond<font color="#009900">_</font>false <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"cond_false"</font><font color="#990000">)</font> cond_false <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"cond_false"</font><font color="#990000">)</font>
cond<font color="#009900">_</font>true <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"cond_true"</font><font color="#990000">)</font> cond_true <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"cond_true"</font><font color="#990000">)</font>
cond<font color="#009900">_</font>false<font color="#009900">_</font><font color="#993399">2</font> <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"cond_false_2"</font><font color="#990000">)</font> cond_false_2 <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block</font></b> <font color="#990000">(</font><font color="#FF0000">"cond_false_2"</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a llvm::IRBuilder</font></i> <i><font color="#9A1900"># create a llvm::IRBuilder</font></i>
bldr <font color="#990000">=</font> <font color="#009900">Builder</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>entry<font color="#990000">)</font> bldr <font color="#990000">=</font> Builder<font color="#990000">.</font><b><font color="#000000">new</font></b> <font color="#990000">(</font>entry<font color="#990000">)</font>
x<font color="#009900">_</font>eq<font color="#009900">_</font>y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">icmp </font></b><font color="#990000">(</font><font color="#009900">IPRED_EQ</font><font color="#990000">,</font> x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font> x_eq_y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">icmp</font></b> <font color="#990000">(</font>IPRED_EQ<font color="#990000">,</font> x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">cbranch </font></b><font color="#990000">(</font>x<font color="#009900">_</font>eq<font color="#009900">_</font>y<font color="#990000">,</font> ret<font color="#990000">,</font> cond<font color="#009900">_</font>false<font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">cbranch</font></b> <font color="#990000">(</font>x_eq_y<font color="#990000">,</font> ret<font color="#990000">,</font> cond_false<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end</font></b> <font color="#990000">(</font>ret<font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">position_at_end</font></b> <font color="#990000">(</font>ret<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret</font></b><font color="#990000">(</font>x<font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">ret</font></b><font color="#990000">(</font>x<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>cond<font color="#009900">_</font>false<font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">position_at_end</font></b> <font color="#990000">(</font>cond_false<font color="#990000">)</font>
x<font color="#009900">_</font>lt<font color="#009900">_</font>y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">icmp </font></b><font color="#990000">(</font><font color="#009900">IPRED_ULT</font><font color="#990000">,</font> x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font> x_lt_y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">icmp</font></b> <font color="#990000">(</font>IPRED_ULT<font color="#990000">,</font> x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">cbranch </font></b><font color="#990000">(</font>x<font color="#009900">_</font>lt<font color="#009900">_</font>y<font color="#990000">,</font> cond<font color="#009900">_</font>true<font color="#990000">,</font> cond<font color="#009900">_</font>false<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">cbranch</font></b> <font color="#990000">(</font>x_lt_y<font color="#990000">,</font> cond_true<font color="#990000">,</font> cond_false_2<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>cond<font color="#009900">_</font>true<font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">position_at_end</font></b> <font color="#990000">(</font>cond_true<font color="#990000">)</font>
y<font color="#009900">_</font>sub<font color="#009900">_</font>x <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">sub </font></b><font color="#990000">(</font>y<font color="#990000">,</font> x<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font> y_sub_x <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">sub</font></b> <font color="#990000">(</font>y<font color="#990000">,</font> x<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
recur<font color="#009900">_</font><font color="#993399">1</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">call </font></b><font color="#990000">(</font>gcd<font color="#990000">,</font> <font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#009900">_</font>sub<font color="#009900">_</font>x<font color="#990000">,),</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font> recur_1 <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">call</font></b> <font color="#990000">(</font>gcd<font color="#990000">,</font> <font color="#990000">(</font>x<font color="#990000">,</font> y_sub_x<font color="#990000">,),</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret </font></b><font color="#990000">(</font>recur<font color="#009900">_</font><font color="#993399">1</font><font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">ret</font></b> <font color="#990000">(</font>recur_1<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>cond<font color="#009900">_</font>false<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">position_at_end</font></b> <font color="#990000">(</font>cond_false_2<font color="#990000">)</font>
x<font color="#009900">_</font>sub<font color="#009900">_</font>y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">sub </font></b><font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"x_sub_y"</font><font color="#990000">)</font> x_sub_y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">sub</font></b> <font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"x_sub_y"</font><font color="#990000">)</font>
recur<font color="#009900">_</font><font color="#993399">2</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">call </font></b><font color="#990000">(</font>gcd<font color="#990000">,</font> <font color="#990000">(</font>x<font color="#009900">_</font>sub<font color="#009900">_</font>y<font color="#990000">,</font> y<font color="#990000">,),</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font> recur_2 <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">call</font></b> <font color="#990000">(</font>gcd<font color="#990000">,</font> <font color="#990000">(</font>x_sub_y<font color="#990000">,</font> y<font color="#990000">,),</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret </font></b><font color="#990000">(</font>recur<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font> bldr<font color="#990000">.</font><b><font color="#000000">ret</font></b> <font color="#990000">(</font>recur_2<font color="#990000">)</font>
<b><font color="#0000FF">print</font></b> module <b><font color="#0000FF">print</font></b> module
</tt></pre> </tt></pre>

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.6" /> <meta name="generator" content="AsciiDoc 8.5.0" />
<meta name="description" content="Python bindings for LLVM" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="llvm python compiler backend bindings" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
@ -33,69 +33,29 @@
</div> </div>
<div id="preamble"> <div id="preamble">
<div class="sectionbody"> <div class="sectionbody">
<div class="para"><p>llvm-py provides <a href="http://www.python.org/">Python</a> bindings for <div class="paragraph"><p>llvm-py provides <a href="http://www.python.org/">Python</a> bindings for
<a href="http://llvm.org/">LLVM</a>. It's goal is to expose enough of LLVM APIs to <a href="http://llvm.org/">LLVM</a>. It&#8217;s goal is to expose enough of LLVM APIs to
implement a compiler backend or a VM in pure Python. llvm-py consists of implement a compiler backend or a VM in pure Python. llvm-py consists of
Python and C modules that wrap over the native C++/C bindings of LLVM, Python and C modules that wrap over the native C++/C bindings of LLVM,
and does not use / have dependencies on "glue utilities" like and does not use / have dependencies on "glue utilities" like
Boost.Python, swig etc.</p></div> Boost.Python, swig etc.</p></div>
<div class="para"><p>llvm-py is just hatching. It should be stable enough to start hacking <div class="paragraph"><p>llvm-py is available as a source package (only). It works / should work
away, though. Be sure to send in a patch if you miss any specific LLVM with GNU/Linux, *BSD and Mac OS X platforms, on both 32-bit and 64-bit
API.</p></div> architectures. Python 2.4 or better (but 3.x is untested) is required.
<div class="para"><p><em>Availability</em>: llvm-py is available (as a source package) for LLVM 2.4 The SVN HEAD usually works with the latest released LLVM. In case you
and Python 2.5. It has been built and tested on Linux and FreeBSD discover that any of these claims are wrong, feel free to send across
(x86 and amd64).</p></div> a patch.</p></div>
</div> </div>
</div> </div>
<h2 id="_news">News</h2> <h2 id="_news">News</h2>
<div class="sectionbody"> <div class="sectionbody">
<div class="vlist"><dl> <div class="dlist"><dl>
<dt> <dt class="hdlist1">
22-Nov-2008 28-Oct-2009
</dt> </dt>
<dd> <dd>
<p> <p>
0.5 released. For LLVM 2.4. SVN r83 works with LLVM 2.6. Website updated.
</p>
</dd>
<dt>
21-Nov-2008
</dt>
<dd>
<p>
0.4 released. Bug fixes, few additional APIs, code cleanup.
</p>
</dd>
<dt>
8-Sep-2008
</dt>
<dd>
<p>
0.3 released. Passes, intrinsics, bitcode, assembly!
</p>
</dd>
<dt>
18-Jun-2008
</dt>
<dd>
<p>
0.2.1 released. Builds cleanly with LLVM 2.3 and 2.3+svn.
</p>
</dd>
<dt>
15-Jun-2008
</dt>
<dd>
<p>
0.2 released. Lots of cleanup, new website, more documentation.
</p>
</dd>
<dt>
20-May-2008
</dt>
<dd>
<p>
0.1 released.
</p> </p>
</dd> </dd>
</dl></div> </dl></div>
@ -103,7 +63,7 @@ and Python 2.5. It has been built and tested on Linux and FreeBSD
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 2008-11-22. Last updated 2009-10-28.
</div> </div>
</div> </div>
</div> </div>

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.5.0" />
<meta name="description" content="Python bindings for LLVM" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="llvm python compiler backend bindings" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
@ -33,13 +33,13 @@
</div> </div>
<div id="preamble"> <div id="preamble">
<div class="sectionbody"> <div class="sectionbody">
<p>llvm-py is distributed under the <div class="paragraph"><p>llvm-py is distributed under the
<a href="http://www.opensource.org/licenses/bsd-license.php">new BSD license</a>. <a href="http://www.opensource.org/licenses/bsd-license.php">new BSD license</a>.
This is similar to LLVM's license. You should be able to use llvm-py This is similar to LLVM&#8217;s license. You should be able to use llvm-py
where-ever and how-ever you're able to use LLVM itself.</p> where-ever and how-ever you&#8217;re able to use LLVM itself.</p></div>
<p>The license text is present in the <div class="paragraph"><p>The license text is present in the
<a href="http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE">LICENSE</a> <a href="http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE">LICENSE</a>
file in the distribution, and is reproduced here:</p> file in the distribution, and is reproduced here:</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>Copyright (c) 2008, Mahadevan R All rights reserved. <pre><tt>Copyright (c) 2008, Mahadevan R All rights reserved.
@ -74,7 +74,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 08-Sep-2008. Last updated 2009-10-28.
</div> </div>
</div> </div>
</div> </div>

File diff suppressed because it is too large Load diff