From 43998cc2df8ea813ee7e53cc201a03a8c1088f41 Mon Sep 17 00:00:00 2001 From: "mdevan.foobar" Date: Wed, 28 Oct 2009 12:10:06 +0000 Subject: [PATCH] Documentation update git-svn-id: http://llvm-py.googlecode.com/svn/trunk@85 8d1e9007-1d4e-0410-b67e-1979fd6579aa --- tools/intrs_for_doc.py | 19 + www/src/about.txt | 9 +- www/src/download.txt | 19 +- www/src/examples.txt | 2 +- www/src/index.txt | 32 +- www/src/userguide.txt | 262 +-- www/web/about.html | 13 +- www/web/contribute.html | 22 +- www/web/download.html | 148 +- www/web/examples.html | 100 +- www/web/examples/JITTutorial1.html | 28 +- www/web/examples/JITTutorial2.html | 50 +- www/web/index.html | 68 +- www/web/license.html | 14 +- www/web/userguide.html | 2749 ++++++++++------------------ 15 files changed, 1343 insertions(+), 2192 deletions(-) create mode 100755 tools/intrs_for_doc.py diff --git a/tools/intrs_for_doc.py b/tools/intrs_for_doc.py new file mode 100755 index 0000000..ec34625 --- /dev/null +++ b/tools/intrs_for_doc.py @@ -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 diff --git a/www/src/about.txt b/www/src/about.txt index 28b0b0a..3c10584 100644 --- a/www/src/about.txt +++ b/www/src/about.txt @@ -1,9 +1,10 @@ About ===== -llvm-py is developed by Mahadevan R, in his spare time. He can be -reached at mdevan.foobar@gmail.com, on the llvm-dev mailing list and -irc.oftc.net#llvm (mdevan). +llvm-py is developed and maintained by Mahadevan R, with contributions from +many users all over the world. He can be reached at mdevan.foobar@gmail.com, +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. diff --git a/www/src/download.txt b/www/src/download.txt index 20c6bd1..337bd88 100644 --- a/www/src/download.txt +++ b/www/src/download.txt @@ -1,23 +1,14 @@ Download ======== -The latest release is 0.5, released 22-Nov-2008 (link:#changelog[Changelog] -below). 0.5 works only with LLVM 2.4, use 0.4 if you have LLVM 2.3. +The latest release is 0.6, released 28-Oct-2009 (link:#changelog[Changelog] +below). 0.6 works only with LLVM 2.6. 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"] -````~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -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] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - +Older versions are available http://llvm-py.googlecode.com/files/[here]. The latest code can be checked out from SVN like so: diff --git a/www/src/examples.txt b/www/src/examples.txt index 4064ec1..b050b18 100644 --- a/www/src/examples.txt +++ b/www/src/examples.txt @@ -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: .Simple JIT Tutorials -(These were contributed by Sebastien Binet; thanks!) +(contributed by Sebastien Binet) 1. A First Function http://www.llvm.org/docs/tutorial/JITTutorial1.html[LLVM] diff --git a/www/src/index.txt b/www/src/index.txt index 49e127d..da63fc5 100644 --- a/www/src/index.txt +++ b/www/src/index.txt @@ -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 Boost.Python, swig etc. -llvm-py is just hatching. It should be stable enough to start hacking -away, though. Be sure to send in a patch if you miss any specific LLVM -API. - -_Availability_: llvm-py is available (as a source package) for LLVM 2.4 -and Python 2.5. It has been built and tested on Linux and FreeBSD -(x86 and amd64). +llvm-py is available as a source package (only). It works / should work +with GNU/Linux, *BSD and Mac OS X platforms, on both 32-bit and 64-bit +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 +discover that any of these claims are wrong, feel free to send across +a patch. News ---- -22-Nov-2008:: - 0.5 released. For LLVM 2.4. - -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. +28-Oct-2009:: + SVN r83 works with LLVM 2.6. Website updated. diff --git a/www/src/userguide.txt b/www/src/userguide.txt index f8eaccd..bb6470d 100644 --- a/www/src/userguide.txt +++ b/www/src/userguide.txt @@ -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 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 Both LLVM and llvm-py are distributed under (different) permissive 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]. .Platforms -Currently, llvm-py has been built and tested only on Linux (i386, amd64) -and OpenBSD (i386, amd64). However, it should be trivial to build it on -other unices. Windows is not supported, for a variety of reasons. +llvm-py has been built/tested/reported to work on various GNU/Linux +flavours, *BSD, Mac OS X; on i386 and amd64 architectures. Windows is not +supported, for a variety of reasons. .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. -llvm-py has been built and tested with Python 2.5. It should work with -Python 2.4, with minimal changes, if any. +llvm-py has been built and tested with Python 2.6. It should work with +Python 2.4 and 2.5. It has not been tried with Python 3.x (patches welcome). [[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 required for this: -- C and C\+\+ compilers (gcc/g\+\+) +- C and C++ compilers (gcc/g++) - Python itself - Python development files (headers and libraries) - LLVM, either installed or built On debian-based systems, the first three can be installed with the -command `sudo apt-get install gcc g\+\+ python python-dev`. Note that -ubuntu repository has an old version of llvm (1.8) which will not work -with llvm-py. +command `sudo apt-get install gcc g++ python python-dev`. Ensure that your +distro's respository has the appropriate version of LLVM! -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 -been tried only with gcc/g\+\+ though. +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 +been tried only with gcc/g++ though. 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: ---- -~/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: ----------------------------------------------------------------------- -$ tar jxvf llvm-py-0.5.tar.bz2 -$ cd llvm-py-0.5 +$ tar jxvf llvm-py-0.6.tar.bz2 +$ cd llvm-py-0.6 $ 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: ----------------------------------------------------------------------- -$ tar jxvf llvm-py-0.5.tar.bz2 -$ cd llvm-py-0.5 +$ tar jxvf llvm-py-0.6.tar.bz2 +$ cd llvm-py-0.6 $ 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: ----------------------------------------------------------------------- -$ tar jxvf llvm-py-0.5.tar.bz2 -$ cd llvm-py-0.5 +$ tar jxvf llvm-py-0.6.tar.bz2 +$ cd llvm-py-0.6 $ 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 ----------------------------------------------------------------------- @@ -144,12 +150,12 @@ Uninstall To get rid of llvm-py completely, if you wish to do so: ---- -# rm -rf /usr/lib/python2.5/site-packages/llvm -# rm -f /usr/lib/python2.5/site-packages/llvm_py-0.1.egg-info +# rm -rf /usr/lib/python2.6/site-packages/llvm +# rm -f /usr/lib/python2.6/site-packages/llvm_py-0.6-py2.6.egg-info ---- - 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) which you might need to change to suit your system. @@ -263,43 +269,42 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 triple = "i386-pc-linux-gnu" -define i32 @sum(i32 %n) nounwind { +define i32 @sum(i32 %n) nounwind readnone { entry: - %tmp215 = icmp eq i32 %n, 0 ; [#uses=1] - br i1 %tmp215, label %bb10, label %tailrecurse.bb10_crit_edge + %0 = icmp eq i32 %n, 0 ; [#uses=1] + br i1 %0, label %bb2, label %bb1 -tailrecurse.bb10_crit_edge: ; preds = %entry - %tmp = add i32 %n, -1 ; [#uses=3] - %tmp17 = mul i32 %tmp, %tmp ; [#uses=1] - %tmp18 = add i32 %tmp17, %n ; [#uses=1] - %tmp. = zext i32 %tmp to i64 ; [#uses=2] - %tmp19 = add i64 %tmp., -1 ; [#uses=1] - %tmp20 = mul i64 %tmp19, %tmp. ; [#uses=1] - %tmp21 = lshr i64 %tmp20, 1 ; [#uses=1] - %tmp.22 = trunc i64 %tmp21 to i32 ; [#uses=1] - %tmp24 = sub i32 %tmp18, %tmp.22 ; [#uses=1] - ret i32 %tmp24 +bb1: ; preds = %entry + %1 = add i32 %n, -1 ; [#uses=2] + %2 = icmp eq i32 %1, 0 ; [#uses=1] + br i1 %2, label %sum.exit, label %bb1.i -bb10: ; preds = %entry - ret i32 0 +bb1.i: ; preds = %bb1 + %3 = add i32 %n, -2 ; [#uses=1] + %4 = tail call i32 @sum(i32 %3) nounwind ; [#uses=1] + %5 = add i32 %4, %1 ; [#uses=1] + br label %sum.exit + +sum.exit: ; preds = %bb1.i, %bb1 + %6 = phi i32 [ %5, %bb1.i ], [ 0, %bb1 ] ; [#uses=1] + %7 = add i32 %6, %n ; [#uses=1] + ret i32 %7 + +bb2: ; preds = %entry + ret i32 0 } ----------------------------------------------------------------------- -Note the usage of SSA form and the total absence of any loop or -recursion at all! The long string called `target datalayout` is a +Note the usage of SSA form. The long string called `target datalayout` is a specification of the platform ABI (like endianness, sizes of types, alignment etc.). The http://www.llvm.org/docs/LangRef.html[LLVM Language Reference] 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 @@ -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 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 @@ -427,7 +432,7 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 interpreter or the +object?+ of http://ipython.scipy.org/moin/[IPython] to get online help. (Note: not complete yet!) @@ -552,10 +557,10 @@ stringifying them (see below). object `fileobj`. .Special Methods -`\_\_str\_\_`:: +`__str__`:: `Module` objects can be stringified into it's LLVM assembly language representation. -`\_\_eq\_\_`:: +`__eq__`:: `Module` objects can be compared for equality. Internally, this converts both arguments into their LLVM assembly representations and 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 object is actually returned by the static method. -[frame="all",grid="all"] -`50`30`20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="3",options="header"] +|====================================================================== Name,Constructor Method,Class -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ integer of bitwidth `n`, +Type.int(n)+, +IntegerType+ 32-bit float, +Type.float()+, +Type+ 64-bit double, +Type.double()+, +Type+ @@ -608,7 +612,7 @@ vector, "+Type.vector(elty, count)+", +VectorType+ void, +Type.void()+, +Type+ label, +Type.label()+, +Type+ opaque, +Type.opaque()+, +Type+ -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== The class hierarchy is: ----------------------------------------------------------------------- @@ -666,7 +670,7 @@ The class-level documentation follows: .Properties `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`: + [python] @@ -678,13 +682,14 @@ TYPE_X86_FP80 = 3 TYPE_FP128 = 4 TYPE_PPC_FP128 = 5 TYPE_LABEL = 6 -TYPE_INTEGER = 7 -TYPE_FUNCTION = 8 -TYPE_STRUCT = 9 -TYPE_ARRAY = 10 -TYPE_POINTER = 11 -TYPE_OPAQUE = 12 -TYPE_VECTOR = 13 +TYPE_METADATA = 7 +TYPE_INTEGER = 8 +TYPE_FUNCTION = 9 +TYPE_STRUCT = 10 +TYPE_ARRAY = 11 +TYPE_POINTER = 12 +TYPE_OPAQUE = 13 +TYPE_VECTOR = 14 source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Example: @@ -701,10 +706,10 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ of `TypeHandle` objects. .Special Methods -`\_\_str\_\_`:: +`__str__`:: `Type` objects can be stringified into it's LLVM assembly language representation. -`\_\_eq\_\_`:: +`__eq__`:: `Type` objects can be compared for equality. Internally, this converts both arguments into their LLVM assembly representations and compares the resultant strings. @@ -899,7 +904,7 @@ Programmer's Manual section http://llvm.org/docs/ProgrammersManual.html#TypeResolve["LLVM Type Resolution"]. The TypeHandle class of llvm-py corresponds to 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] 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. .Special Methods -`\_\_str\_\_`:: +`__str__`:: `Value` objects can be stringified into it's LLVM assembly language representation. -`\_\_eq\_\_`:: +`__eq__`:: `Value` objects can be compared for equality. Internally, this converts both arguments into their LLVM assembly representations and compares the resultant strings. @@ -1003,13 +1008,12 @@ The following constructors (static methods) can be used to create constants: [[constctors]] -[frame="all",grid="all"] -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="2",options="header"] +|====================================================================== Constructor Method, What It Creates -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `null(ty)`, A null value (all zeros) 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_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)" @@ -1020,7 +1024,7 @@ Constructor Method, What It Creates "`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)" "`sizeof(ty)`", "Constant value representing the sizeof the type `ty`" -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== The following operations on constants are supported. For more details on any operation, consult the @@ -1028,10 +1032,9 @@ http://www.llvm.org/docs/LangRef.html#constantexprs[Constant Expressions] section of the LLVM Language Reference. [[constops]] -[frame="all",grid="all"] -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="2",options="header"] +|====================================================================== Method, Operation -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `k.neg()`, "negation, same as `0 - k`" `k.not_()`, "1's complement of `k`. Note trailing underscore." `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.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`." -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== [[ipred]] Predicates for use with `icmp` instruction are listed below. All of these are integer constants defined in the `llvm.core` module. -[frame="all",grid="all"] -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="2",options="header"] +|====================================================================== Value, Meaning -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `IPRED_EQ`, Equality `IPRED_NE`, Inequality `IPRED_UGT`, Unsigned greater than @@ -1088,16 +1090,15 @@ Value, Meaning `IPRED_SGE`, Signed greater than or equal `IPRED_SLT`, Signed less than `IPRED_SLE`, Signed less than or equal -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== [[rpred]] Predicates for use with `fcmp` instruction are listed below. All of these are integer constants defined in the `llvm.core` module. -[frame="all",grid="all"] -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="2",options="header"] +|====================================================================== Value, Meaning -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `RPRED_FALSE`, Always false `RPRED_OEQ`, True if ordered and equal `RPRED_OGT`, True if ordered and greater than @@ -1114,7 +1115,7 @@ Value, Meaning `RPRED_ULE`, "True if unordered, less than or equal" `RPRED_UNE`, True if unordered or not equal `RPRED_TRUE `, Always true -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== .llvm.core.Constant [caption=""] @@ -1144,34 +1145,38 @@ llvm.core) as values for `linkage` (see http://www.llvm.org/docs/LangRef.html#linkage[LLVM documentaion] for details on each): -[frame="all",grid="all"] -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="2",options="header"] +|====================================================================== Value, Equivalent LLVM Assembly Keyword -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -`LINKAGE_LINKONCE`, `linkonce` -`LINKAGE_WEAK`, `weak` +`LINKAGE_EXTERNAL`, `externally_visible` +`LINKAGE_AVAILABLE_EXTERNALLY`, `available_externally` +`LINKAGE_LINKONCE_ANY`, `linkonce` +`LINKAGE_LINKONCE_ODR`, `linkonce_odr` +`LINKAGE_WEAK_ANY`, `weak` +`LINKAGE_WEAK_ODR`, `weak_odr` `LINKAGE_APPENDING`, `appending` `LINKAGE_INTERNAL`, `internal` +`LINKAGE_PRIVATE`, `private` +`LINKAGE_LINKER_PRIVATE`, `linker_private` `LINKAGE_DLLIMPORT`, `dllimport` `LINKAGE_DLLEXPORT`, `dllexport` -`LINKAGE_EXTERNAL`, `externally visible` `LINKAGE_EXTERNAL_WEAK`, `extern_weak` +`LINKAGE_COMMON`, `common` `LINKAGE_GHOST`, Stand-in functions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== The `section` property can be assigned strings (like ".rodata"), which will be used if the target supports it. Visibility property can be set to one of thse constants (from llvm.core, see also http://www.llvm.org/docs/LangRef.html#visibility[LLVM docs]): -[frame="all",grid="all"] -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[frame="all",grid="all",format="csv",cols="2",options="header"] +|====================================================================== Value, Equivalent LLVM Assembly Keyword -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `VISIBILITY_DEFAULT`, `default` `VISIBILITY_HIDDEN`, `hidden` `VISIBILITY_PROTECTED`, `protected` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +|====================================================================== 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 @@ -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 in `llvm.core`. These are: -[frame="all",grid="all"] -`33`33`33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -INTR_ANNOTATION,INTR_ATOMIC_CMP_SWAP,INTR_ATOMIC_LOAD_ADD -INTR_ATOMIC_LOAD_AND,INTR_ATOMIC_LOAD_MAX,INTR_ATOMIC_LOAD_MIN -INTR_ATOMIC_LOAD_NAND,INTR_ATOMIC_LOAD_OR,INTR_ATOMIC_LOAD_SUB -INTR_ATOMIC_LOAD_UMAX,INTR_ATOMIC_LOAD_UMIN,INTR_ATOMIC_LOAD_XOR -INTR_ATOMIC_SWAP,INTR_BSWAP,INTR_COS -INTR_CTLZ,INTR_CTPOP,INTR_CTTZ -INTR_DBG_DECLARE,INTR_DBG_FUNC_START,INTR_DBG_REGION_END -INTR_DBG_REGION_START,INTR_DBG_STOPPOINT,INTR_EH_DWARF_CFA -INTR_EH_EXCEPTION,INTR_EH_RETURN_I32,INTR_EH_RETURN_I64 -INTR_EH_SELECTOR_I32,INTR_EH_SELECTOR_I64,INTR_EH_TYPEID_FOR_I32 -INTR_EH_TYPEID_FOR_I64,INTR_EH_UNWIND_INIT,INTR_EXP -INTR_EXP2,INTR_FLT_ROUNDS,INTR_FRAMEADDRESS -INTR_GCREAD,INTR_GCROOT,INTR_GCWRITE -INTR_INIT_TRAMPOLINE,INTR_LOG,INTR_LOG10 -INTR_LOG2,INTR_LONGJMP,INTR_MEMCPY_I32 -INTR_MEMCPY_I64,INTR_MEMMOVE_I32,INTR_MEMMOVE_I64 -INTR_MEMORY_BARRIER,INTR_MEMSET_I32,INTR_MEMSET_I64 -INTR_PART_SELECT,INTR_PART_SET,INTR_PCMARKER -INTR_POW,INTR_POWI,INTR_PREFETCH -INTR_READCYCLECOUNTER,INTR_RETURNADDRESS,INTR_SETJMP -INTR_SIGLONGJMP,INTR_SIGSETJMP,INTR_SIN -INTR_SQRT,INTR_STACKRESTORE,INTR_STACKSAVE -INTR_TRAP,INTR_VACOPY,INTR_VAEND -INTR_VAR_ANNOTATION,INTR_VASTART, -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[format="csv",cols="3"] +|====================================================================== +`INTR_ALPHA_UMULH`,`INTR_ANNOTATION`,`INTR_ATOMIC_CMP_SWAP` +`INTR_ATOMIC_LOAD_ADD`,`INTR_ATOMIC_LOAD_AND`,`INTR_ATOMIC_LOAD_MAX` +`INTR_ATOMIC_LOAD_MIN`,`INTR_ATOMIC_LOAD_NAND`,`INTR_ATOMIC_LOAD_OR` +`INTR_ATOMIC_LOAD_SUB`,`INTR_ATOMIC_LOAD_UMAX`,`INTR_ATOMIC_LOAD_UMIN` +`INTR_ATOMIC_LOAD_XOR`,`INTR_ATOMIC_SWAP`,`INTR_BSWAP` +`INTR_CONVERTFF`,`INTR_CONVERTFSI`,`INTR_CONVERTFUI` +`INTR_CONVERTSIF`,`INTR_CONVERTSS`,`INTR_CONVERTSU` +`INTR_CONVERTUIF`,`INTR_CONVERTUS`,`INTR_CONVERTUU` +`INTR_COS`,`INTR_CTLZ`,`INTR_CTPOP` +`INTR_CTTZ`,`INTR_DBG_DECLARE`,`INTR_DBG_FUNC_START` +`INTR_DBG_REGION_END`,`INTR_DBG_REGION_START`,`INTR_DBG_STOPPOINT` +`INTR_EH_DWARF_CFA`,`INTR_EH_EXCEPTION`,`INTR_EH_RETURN_I32` +`INTR_EH_RETURN_I64`,`INTR_EH_SELECTOR_I32`,`INTR_EH_SELECTOR_I64` +`INTR_EH_SJLJ_LONGJMP`,`INTR_EH_SJLJ_LSDA`,`INTR_EH_SJLJ_SETJMP` +`INTR_EH_TYPEID_FOR_I32`,`INTR_EH_TYPEID_FOR_I64`,`INTR_EH_UNWIND_INIT` +`INTR_EXP`,`INTR_EXP2`,`INTR_FLT_ROUNDS` +`INTR_FRAMEADDRESS`,`INTR_GCREAD`,`INTR_GCROOT` +`INTR_GCWRITE`,`INTR_INIT_TRAMPOLINE`,`INTR_LOG` +`INTR_LOG10`,`INTR_LOG2`,`INTR_LONGJMP` +`INTR_MEMCPY`,`INTR_MEMMOVE`,`INTR_MEMORY_BARRIER` +`INTR_MEMSET`,`INTR_PCMARKER`,`INTR_POW` +`INTR_POWI`,`INTR_PREFETCH`,`INTR_PTR_ANNOTATION` +`INTR_READCYCLECOUNTER`,`INTR_RETURNADDRESS`,`INTR_SADD_WITH_OVERFLOW` +`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 target's CPU instructions) available, but are omitted here for brevity. 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] for more information on the intrinsics, and the 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 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 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 properly yet (aborts on errors), investigation pending. +TODO function attributes Argument (llvm.core) ~~~~~~~~~~~~~~~~~~~~ @@ -1547,6 +1558,9 @@ the file named http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE[LICENSE] 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 using the tool http://www.methods.co.nz/asciidoc/[AsciiDoc]. These text files and the (pre-)generated HTML pages are available in the source diff --git a/www/web/about.html b/www/web/about.html index b408ec1..56ef552 100644 --- a/www/web/about.html +++ b/www/web/about.html @@ -2,7 +2,7 @@ - + @@ -33,16 +33,17 @@
-

llvm-py is developed by Mahadevan R, in his spare time. He can be -reached at mdevan.foobar@gmail.com, on the llvm-dev mailing list and -irc.oftc.net#llvm (mdevan).

-

Many thanks to the guys over at LLVM for all the nifty software.

+

llvm-py is developed and maintained by Mahadevan R, with contributions from +many users all over the world. He can be reached at mdevan.foobar@gmail.com, +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, for all +the llvm-py contributors.

diff --git a/www/web/contribute.html b/www/web/contribute.html index b1c32ff..b7a57ee 100644 --- a/www/web/contribute.html +++ b/www/web/contribute.html @@ -2,7 +2,7 @@ - + @@ -33,8 +33,8 @@
-

You can make a difference, just by:

-
+

SVN HEAD can be checked out like so:

$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py
-

Usual caveats apply: cutting edge, may be broken (but usually not), -update and merge before sending patches etc.

+

Usual caveats apply: cutting edge, may be broken (but usually not), +update and merge before sending patches etc.

diff --git a/www/web/download.html b/www/web/download.html index a524621..0b43079 100644 --- a/www/web/download.html +++ b/www/web/download.html @@ -2,7 +2,7 @@ - + @@ -33,127 +33,18 @@
-

The latest release is 0.5, released 22-Nov-2008 (Changelog -below). 0.5 works only with LLVM 2.4, use 0.4 if you have LLVM 2.3.

-

Download it here:

-
- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Release - - Date - - Package - - Mirror -
- 0.5 - - 22-Nov-2008 - - llvm-py-0.5.tar.bz2 - - llvm-py-0.5.tar.bz2 -
- 0.4 - - 21-Nov-2008 - - llvm-py-0.4.tar.bz2 - - llvm-py-0.4.tar.bz2 -
- 0.3 - - 8-Sep-2008 - - llvm-py-0.3.tar.bz2 - - llvm-py-0.3.tar.bz2 -
- 0.2.1 - - 18-Jun-2008 - - llvm-py-0.2.1.tar.bz2 - - llvm-py-0.2.1.tar.bz2 -
- 0.2 - - 15-Jun-2008 - - llvm-py-0.2.tar.bz2 - - llvm-py-0.2.tar.bz2 -
- 0.1 - - 20-May-2008 - - 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 release is 0.6, released 28-Oct-2009 (Changelog +below). 0.6 works only with LLVM 2.6.

+

Download it here: +- llvm-py-0.6.tar.bz2 (primary) +- llvm-py-0.6.tar.bz2 (mirror)

+

Older versions are available here.

+

The latest code can be checked out from SVN like so:

$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py
-

Follow the steps described here to install the +

Follow the steps described here to install the package.

@@ -161,7 +52,24 @@ package.

-
0.5, 22-Nov-2008:
+
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.
   * Builds on FreeBSD.
@@ -221,7 +129,7 @@ package.

diff --git a/www/web/examples.html b/www/web/examples.html index 713c163..8accc86 100644 --- a/www/web/examples.html +++ b/www/web/examples.html @@ -2,7 +2,7 @@ - + @@ -31,24 +31,23 @@ -

Examples

+

Examples

-

A Simple Function

-

Let's create a (LLVM) module containing a single function, corresponding -to the C function:

+

A Simple Function

+

Let’s create a (LLVM) module containing a single function, corresponding +to the C function:

-
int sum(int a, int b)
 {
     return a + b;
-}
-
-

Here's how it looks like:

+}
+

Here’s how it looks like:

-
@@ -59,45 +58,44 @@ http://www.gnu.org/software/src-highlite --> from llvm.core import * # Create an (empty) module. -my_module = Module.new('my_module') +my_module = Module.new('my_module') # All the types involved here are "int"s. This type is represented # by an object of the llvm.core.Type class: -ty_int = Type.int() # by default 32 bits +ty_int = Type.int() # by default 32 bits # We need to represent the class of functions that accept two integers # and return an integer. This is represented by an object of the # function type (llvm.core.FunctionType): -ty_func = Type.function(ty_int, [ty_int, ty_int]) +ty_func = Type.function(ty_int, [ty_int, ty_int]) # Now we need a function named 'sum' of this type. Functions are not # free-standing (in llvm-py); it needs to be contained in a module. -f_sum = my_module.add_function(ty_func, "sum") +f_sum = my_module.add_function(ty_func, "sum") # Let's name the function arguments as 'a' and 'b'. -f_sum.args[0].name = "a" -f_sum.args[1].name = "b" +f_sum.args[0].name = "a" +f_sum.args[1].name = "b" # Our function needs a "basic block" -- a set of instructions that # end with a terminator (like return, branch etc.). By convention # the first block is called "entry". -bb = f_sum.append_basic_block("entry") +bb = f_sum.append_basic_block("entry") # Let's add instructions into the block. For this, we need an # instruction builder: -builder = Builder.new(bb) +builder = Builder.new(bb) # OK, now for the instructions themselves. We'll create an add # instruction that returns the sum as a value, which we'll use # a ret instruction to return. -tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp") +tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp") builder.ret(tmp) # We've completed the definition now! Let's see the LLVM assembly # language representation of what we've created: -print my_module -
-

Here is the output:

+print my_module +

Here is the output:

; ModuleID = 'my_module'
@@ -108,10 +106,10 @@ entry:
         ret i32 %tmp
 }
-

Adding JIT Compilation

-

Let's compile this function in-memory and run it.

+

Adding JIT Compilation

+

Let’s compile this function in-memory and run it.

-
@@ -123,50 +121,48 @@ http://www.gnu.org/software/src-highlite --> from llvm.ee import * # new import: ee = Execution Engine # Create a module, as in the previous example. -my_module = Module.new('my_module') -ty_int = Type.int() # by default 32 bits -ty_func = Type.function(ty_int, [ty_int, ty_int]) -f_sum = my_module.add_function(ty_func, "sum") -f_sum.args[0].name = "a" -f_sum.args[1].name = "b" -bb = f_sum.append_basic_block("entry") -builder = Builder.new(bb) -tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp") +my_module = Module.new('my_module') +ty_int = Type.int() # by default 32 bits +ty_func = Type.function(ty_int, [ty_int, ty_int]) +f_sum = my_module.add_function(ty_func, "sum") +f_sum.args[0].name = "a" +f_sum.args[1].name = "b" +bb = f_sum.append_basic_block("entry") +builder = Builder.new(bb) +tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp") builder.ret(tmp) # Create a module provider object first. Modules can come from # in-memory IRs like what we created now, or from bitcode (.bc) # files. The module provider abstracts this detail. -mp = ModuleProvider.new(my_module) +mp = ModuleProvider.new(my_module) # Create an execution engine object. This will create a JIT compiler # on platforms that support it, or an interpreter otherwise. -ee = ExecutionEngine.new(mp) +ee = ExecutionEngine.new(mp) # The arguments needs to be passed as "GenericValue" objects. -arg1 = GenericValue.int(ty_int, 100) -arg2 = GenericValue.int(ty_int, 42) +arg1 = GenericValue.int(ty_int, 100) +arg2 = GenericValue.int(ty_int, 42) # Now let's compile and run! -retval = ee.run_function(f_sum, [arg1, arg2]) +retval = ee.run_function(f_sum, [arg1, arg2]) # The return value is also GenericValue. Let's print it. -print "returned", retval.as_int() -
-

And here's the output:

+print "returned", retval.as_int() +

And here’s the output:

returned 142
-

LLVM Tutorials

+

LLVM Tutorials

-

The LLVM tutorials have been +

The LLVM tutorials have been ported to llvm-py. Below are the links to the original LLVM tutorial and -the corresponding Python code using llvm-py:

-
Simple JIT Tutorials
-

(These were contributed by Sebastien Binet; thanks!)

-
    +the corresponding Python code using llvm-py:

+
Simple JIT Tutorials

(contributed by Sebastien Binet)

+
  1. A First Function @@ -181,8 +177,8 @@ A More Complicated Function llvm-py

  2. -
-
Kaleidoscope: Implementing a Language with LLVM
    +
+
Kaleidoscope: Implementing a Language with LLVM
  1. 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)

  2. -
+
diff --git a/www/web/examples/JITTutorial1.html b/www/web/examples/JITTutorial1.html index f7a9fe4..245d5d7 100644 --- a/www/web/examples/JITTutorial1.html +++ b/www/web/examples/JITTutorial1.html @@ -1,4 +1,4 @@ - @@ -7,30 +7,30 @@ http://www.gnu.org/software/src-highlite --> from llvm.core import * # create a module -module = Module.new ("tut1") +module = Module.new ("tut1") # create a function type taking 3 32-bit integers, return a 32-bit integer -ty_int = Type.int (32) -func_type = Type.function (ty_int, (ty_int,)*3) +ty_int = Type.int (32) +func_type = Type.function (ty_int, (ty_int,)*3) # create a function of that type -mul_add = Function.new (module, func_type, "mul_add") -mul_add.calling_convention = CC_C -x = mul_add.args[0]; x.name = "x" -y = mul_add.args[1]; y.name = "y" -z = mul_add.args[2]; z.name = "z" +mul_add = Function.new (module, func_type, "mul_add") +mul_add.calling_convention = CC_C +x = mul_add.args[0]; x.name = "x" +y = mul_add.args[1]; y.name = "y" +z = mul_add.args[2]; z.name = "z" # implement the function # new block -blk = mul_add.append_basic_block ("entry") +blk = mul_add.append_basic_block ("entry") # IR builder -bldr = Builder.new (blk) -tmp_1 = bldr.mul (x, y, "tmp_1") -tmp_2 = bldr.add (tmp_1, z, "tmp_2") +bldr = Builder.new (blk) +tmp_1 = bldr.mul (x, y, "tmp_1") +tmp_2 = bldr.add (tmp_1, z, "tmp_2") -bldr.ret (tmp_2) +bldr.ret (tmp_2) print module diff --git a/www/web/examples/JITTutorial2.html b/www/web/examples/JITTutorial2.html index 3baa722..02afb25 100644 --- a/www/web/examples/JITTutorial2.html +++ b/www/web/examples/JITTutorial2.html @@ -1,4 +1,4 @@ - @@ -7,14 +7,14 @@ http://www.gnu.org/software/src-highlite --> from llvm.core import * # create a module -module = Module.new ("tut2") +module = Module.new ("tut2") # create a function type taking 2 integers, return a 32-bit integer -ty_int = Type.int (32) -func_type = Type.function (ty_int, (ty_int, ty_int)) +ty_int = Type.int (32) +func_type = Type.function (ty_int, (ty_int, ty_int)) # create a function of that type -gcd = Function.new (module, func_type, "gcd") +gcd = Function.new (module, func_type, "gcd") # name function args x = gcd.args[0]; x.name = "x" @@ -23,33 +23,33 @@ y = gcd.args# implement the function # blocks... -entry = gcd.append_basic_block ("entry") -ret = gcd.append_basic_block ("return") -cond_false = gcd.append_basic_block ("cond_false") -cond_true = gcd.append_basic_block ("cond_true") -cond_false_2 = gcd.append_basic_block ("cond_false_2") +entry = gcd.append_basic_block ("entry") +ret = gcd.append_basic_block ("return") +cond_false = gcd.append_basic_block ("cond_false") +cond_true = gcd.append_basic_block ("cond_true") +cond_false_2 = gcd.append_basic_block ("cond_false_2") # create a llvm::IRBuilder -bldr = Builder.new (entry) -x_eq_y = bldr.icmp (IPRED_EQ, x, y, "tmp") -bldr.cbranch (x_eq_y, ret, cond_false) +bldr = Builder.new (entry) +x_eq_y = bldr.icmp (IPRED_EQ, x, y, "tmp") +bldr.cbranch (x_eq_y, ret, cond_false) -bldr.position_at_end (ret) +bldr.position_at_end (ret) bldr.ret(x) -bldr.position_at_end (cond_false) -x_lt_y = bldr.icmp (IPRED_ULT, x, y, "tmp") -bldr.cbranch (x_lt_y, cond_true, cond_false_2) +bldr.position_at_end (cond_false) +x_lt_y = bldr.icmp (IPRED_ULT, x, y, "tmp") +bldr.cbranch (x_lt_y, cond_true, cond_false_2) -bldr.position_at_end (cond_true) -y_sub_x = bldr.sub (y, x, "tmp") -recur_1 = bldr.call (gcd, (x, y_sub_x,), "tmp") -bldr.ret (recur_1) +bldr.position_at_end (cond_true) +y_sub_x = bldr.sub (y, x, "tmp") +recur_1 = bldr.call (gcd, (x, y_sub_x,), "tmp") +bldr.ret (recur_1) -bldr.position_at_end (cond_false_2) -x_sub_y = bldr.sub (x, y, "x_sub_y") -recur_2 = bldr.call (gcd, (x_sub_y, y,), "tmp") -bldr.ret (recur_2) +bldr.position_at_end (cond_false_2) +x_sub_y = bldr.sub (x, y, "x_sub_y") +recur_2 = bldr.call (gcd, (x_sub_y, y,), "tmp") +bldr.ret (recur_2) print module diff --git a/www/web/index.html b/www/web/index.html index 3b7a265..f9f57f6 100644 --- a/www/web/index.html +++ b/www/web/index.html @@ -2,7 +2,7 @@ - + @@ -33,69 +33,29 @@
-

llvm-py provides Python bindings for -LLVM. It's goal is to expose enough of LLVM APIs to +

llvm-py provides Python bindings for +LLVM. It’s goal is to expose enough of LLVM APIs to 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, and does not use / have dependencies on "glue utilities" like Boost.Python, swig etc.

-

llvm-py is just hatching. It should be stable enough to start hacking -away, though. Be sure to send in a patch if you miss any specific LLVM -API.

-

Availability: llvm-py is available (as a source package) for LLVM 2.4 -and Python 2.5. It has been built and tested on Linux and FreeBSD -(x86 and amd64).

+

llvm-py is available as a source package (only). It works / should work +with GNU/Linux, *BSD and Mac OS X platforms, on both 32-bit and 64-bit +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 +discover that any of these claims are wrong, feel free to send across +a patch.

News

-
-
-22-Nov-2008 +
+
+28-Oct-2009

- 0.5 released. For LLVM 2.4. -

-
-
-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. + SVN r83 works with LLVM 2.6. Website updated.

@@ -103,7 +63,7 @@ and Python 2.5. It has been built and tested on Linux and FreeBSD
diff --git a/www/web/license.html b/www/web/license.html index 9e908d1..e9b8e73 100644 --- a/www/web/license.html +++ b/www/web/license.html @@ -2,7 +2,7 @@ - + @@ -33,13 +33,13 @@
-

llvm-py is distributed under the +

llvm-py is distributed under the new BSD license. -This is similar to LLVM's license. You should be able to use llvm-py -where-ever and how-ever you're able to use LLVM itself.

-

The license text is present in the +This is similar to LLVM’s license. You should be able to use llvm-py +where-ever and how-ever you’re able to use LLVM itself.

+

The license text is present in the LICENSE -file in the distribution, and is reproduced here:

+file in the distribution, and is reproduced here:

Copyright (c) 2008, Mahadevan R All rights reserved.
@@ -74,7 +74,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/www/web/userguide.html b/www/web/userguide.html index 7d8280e..234da97 100644 --- a/www/web/userguide.html +++ b/www/web/userguide.html @@ -2,7 +2,7 @@ - + @@ -43,42 +43,48 @@ window.onload = function(){generateToc(2)}
-

llvm-py provides Python bindings for LLVM. This document explains how +

llvm-py provides Python bindings for LLVM. This document explains how you can setup and use it. A working knowledge of Python and a basic idea of LLVM is assumed.

Introduction

-

LLVM (Low-Level Virtual Machine) provides enough +

LLVM (Low-Level Virtual Machine) provides enough infrastructure to use it as the backend for your compiled, or JIT-compiled language. It provides extensive optimization support, and static and dynamic (JIT) backends for many platforms. See the website at http://www.llvm.org/ to discover more.

-

Python bindings for LLVM provides a gentler learning curve for working +

Python bindings for LLVM provides a gentler learning curve for working with the LLVM APIs. It should also be easier to create working prototypes and experimental languages using this medium.

-
License

Both LLVM and llvm-py are distributed under (different) permissive +

Together with clang or +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

Both LLVM and llvm-py are distributed under (different) permissive open source licenses. llvm-py uses the new BSD license. More information is available here.

-
Platforms

Currently, llvm-py has been built and tested only on Linux (i386, amd64) -and OpenBSD (i386, amd64). However, it should be trivial to build it on -other unices. Windows is not supported, for a variety of reasons.

-
Versions

llvm-py 0.5 requires verion 2.4 of LLVM. It will not work with previous +

Platforms

llvm-py has been built/tested/reported to work on various GNU/Linux +flavours, *BSD, Mac OS X; on i386 and amd64 architectures. Windows is not +supported, for a variety of reasons.

+
Versions

llvm-py 0.6 requires verion 2.6 of LLVM. It will not work with previous versions.

-

llvm-py has been built and tested with Python 2.5. It should work with -Python 2.4, with minimal changes, if any.

+

llvm-py has been built and tested with Python 2.6. It should work with +Python 2.4 and 2.5. It has not been tried with Python 3.x (patches welcome).

Installation

-

llvm-py is distributed as a source tarball. You'll need to build and +

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 required for this:

-
    +
    • -C and C++ compilers (gcc/g++) +C and C compilers (gcc/g)

    • @@ -97,79 +103,78 @@ LLVM, either installed or built

    -

    On debian-based systems, the first three can be installed with the -command sudo apt-get install gcc g++ python python-dev. Note that -ubuntu repository has an old version of llvm (1.8) which will not work -with llvm-py.

    -

    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 +

    On debian-based systems, the first three can be installed with the +command sudo apt-get install gcc g++ python python-dev. Ensure that your +distro’s respository has the appropriate version of LLVM!

    +

    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 been tried only with gcc/g++ though.

    -

    LLVM and —enable-pic

    -

    The result of an LLVM build is a set of static libraries and object +

    LLVM and --enable-pic

    +

    The result of an LLVM build is a set of static libraries and object files. The llvm-py contains an extension package that is built into a shared object (_core.so) which links to these static libraries and object files. It is therefore required that the LLVM libraries and object files be built with the -fPIC option (generate position -independent code). Be sure to use the —enable-pic option while +independent code). Be sure to use the --enable-pic option while configuring LLVM (default is no PIC), like this:

    -
    ~/llvm-2.4$ ./configure --enable-pic --enable-optimized
    +
    ~/llvm$ ./configure --enable-pic --enable-optimized

    llvm-config

    -

    Inorder to build llvm-py, it's build script needs to know from where it -can invoke the llvm helper program, llvm-config. If you've installed +

    Inorder to build llvm-py, it’s build script needs to know from where it +can invoke the llvm helper program, llvm-config. If you’ve installed LLVM, then this will be available in your PATH, and nothing further -needs to be done. If you've built LLVM yourself, or for any reason -llvm-config is not in your PATH, you'll need to pass the full path +needs to be done. If you’ve built LLVM yourself, or for any reason +llvm-config is not in your PATH, you’ll need to pass the full path of llvm-config to the build script.

    -

    You'll need to be root to install llvm-py. Remember that your PATH +

    You’ll need to be root to install llvm-py. Remember that your PATH is different from that of root, so even if llvm-config is in your PATH, it may not be available when you do sudo.

    Steps

    -

    The commands illustrated below assume that the LLVM source is available -under /home/mdevan/llvm. If you've a previous version of llvm-py +

    The commands illustrated below assume that the LLVM source is available +under /home/mdevan/llvm. If you’ve a previous version of llvm-py installed, it is recommended to remove it first, as described below.

    -

    If you have llvm-config in your path, you can build and install +

    If you have llvm-config in your path, you can build and install llvm-py this way:

    -
    $ tar jxvf llvm-py-0.5.tar.bz2
    -$ cd llvm-py-0.5
    +
    $ tar jxvf llvm-py-0.6.tar.bz2
    +$ cd llvm-py-0.6
     $ sudo python setup.py install
    -

    If you need to tell the build script where llvm-config is, do it this +

    If you need to tell the build script where llvm-config is, do it this way:

    -
    $ tar jxvf llvm-py-0.5.tar.bz2
    -$ cd llvm-py-0.5
    +
    $ tar jxvf llvm-py-0.6.tar.bz2
    +$ cd llvm-py-0.6
     $ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config
    -

    To build a debug version of llvm-py, that links against the debug +

    To build a debug version of llvm-py, that links against the debug libraries of LLVM, use this:

    -
    $ tar jxvf llvm-py-0.5.tar.bz2
    -$ cd llvm-py-0.5
    +
    $ tar jxvf llvm-py-0.6.tar.bz2
    +$ cd llvm-py-0.6
     $ 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
    -

    Be warned that debug binaries will be huge (100MB+) ! They are required +

    Be warned that debug binaries will be huge (100MB+) ! They are required only if you need to debug into LLVM also.

    -

    setup.py is a standard Python distutils script. See the Python +

    setup.py is a standard Python distutils script. See the Python documentation regarding Installing Python Modules and Distributing Python Modules for more information on such scripts.

    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 -f /usr/lib/python2.5/site-packages/llvm_py-0.1.egg-info
    +
    # rm -rf /usr/lib/python2.6/site-packages/llvm
    +# rm -f /usr/lib/python2.6/site-packages/llvm_py-0.6-py2.6.egg-info
    -
      +
      • You need to be root to do this. @@ -177,12 +182,12 @@ 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.

      • @@ -190,15 +195,15 @@ Note that there are version numbers (both Python's and llvm-py's)

      The Concepts

      -

      This section explains a few concepts related to LLVM.

      +

      This section explains a few concepts related to LLVM.

      Intermediate Representation

      -

      The intermediate representation, or IR for short, is an in-memory data +

      The intermediate representation, or IR for short, is an in-memory data structure that represents executable code. The IR data structures allow for creation of types, constants, functions, function arguments, instructions, global variables and so on. For example, to create a function sum that takes two integers and returns their sum, we need to follow these steps:

      -
        +
        • create an integer type ti of required bitwidth @@ -225,7 +230,7 @@ add a basic block to the function using a helper object called an instruction builder, add two instructions into the basic block:

          -
            +
            1. an instruction to add the two arguments and store the result into @@ -240,19 +245,19 @@ a return instruction to return the value of the temporary variable

        -

        (A basic block is a block of instructions.)

        -

        LLVM has it's own instruction set; the instructions used above (add +

        (A basic block is a block of instructions.)

        +

        LLVM has it’s own instruction set; the instructions used above (add and ret) are from this set. The LLVM instructions are at a higher level than the usual assembly language; for example there are instructions related to variable argument handling, exception handling, and garbage collection. These allow high-level languages to be represented cleanly in the IR.

        SSA Form and PHI Nodes

        -

        All LLVM instructions are represented in the Static Single Assignment +

        All LLVM instructions are represented in the Static Single Assignment (SSA) form. Essentially, this means that any variable can be assigned to only once. Such a representation facilitates better optimization, among other benefits.

        -

        A consequence of single assignment are PHI (Φ) nodes. These +

        A consequence of single assignment are PHI (Φ) nodes. These are required when a variable can be assigned a different value based on the path of control flow. For example, the value of b at the end of execution of the snippet below:

        @@ -263,7 +268,7 @@ if (v < 10) a = 2; b = a;
        -

        cannot be determined statically. The value of 2 cannot be assigned to +

        cannot be determined statically. The value of 2 cannot be assigned to the original a, since a can be assigned to only once. There are two a 's in there, and the last assignment has to choose between which version to pick. This is accomplished by adding a PHI node:

        @@ -274,26 +279,26 @@ if (v < 10) a2 = 2; b = PHI(a1, a2);
        -

        The PHI node selects a1 or a2, depending on where the control +

        The PHI node selects a1 or a2, depending on where the control reached the PHI node. The argument a1 of the PHI node is associated with the block "a1 = 1;" and a2 with the block "a2 = 2;".

        -

        PHI nodes have to be explicitly created in the LLVM IR. Accordingly the +

        PHI nodes have to be explicitly created in the LLVM IR. Accordingly the LLVM instruction set has an instruction called phi.

        LLVM Assembly Language

        -

        The LLVM IR can be represented offline in two formats +

        The LLVM IR can be represented offline in two formats - a textual, human-readable form, similar to assembly language, called the LLVM assembly language (files with .ll extension) - a binary form, called the LLVM bitcode (files with .bc extension) All three formats (the in-memory IR, the LLVM assembly language and the LLVM bitcode) represent the same information. Each format can be converted into the other two formats (using LLVM APIs).

        -

        The LLVM demo page lets you type in C or C++ +

        The LLVM demo page lets you type in C or C++ code, converts it into LLVM IR and outputs the IR as LLVM assembly language code.

        -

        Just to get a feel of the LLVM assembly language, here's a function in C, +

        Just to get a feel of the LLVM assembly language, here’s a function in C, and the corresponding LLVM assembly (as generated by the demo page):

        -
        @@ -304,205 +309,48 @@ http://www.gnu.org/software/src-highlite --> return 0; else return n + sum(n-1); -} -
        -

        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 triple = "i386-pc-linux-gnu"
         
        -define i32 @sum(i32 %n) nounwind  {
        +define i32 @sum(i32 %n) nounwind readnone {
         entry:
        -        %tmp215 = icmp eq i32 %n, 0             ; <i1> [#uses=1]
        -        br i1 %tmp215, label %bb10, label %tailrecurse.bb10_crit_edge
        +    %0 = icmp eq i32 %n, 0      ; <i1> [#uses=1]
        +    br i1 %0, label %bb2, label %bb1
         
        -tailrecurse.bb10_crit_edge:             ; preds = %entry
        -        %tmp = add i32 %n, -1           ; <i32> [#uses=3]
        -        %tmp17 = mul i32 %tmp, %tmp             ; <i32> [#uses=1]
        -        %tmp18 = add i32 %tmp17, %n             ; <i32> [#uses=1]
        -        %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
        +bb1:        ; preds = %entry
        +    %1 = add i32 %n, -1     ; <i32> [#uses=2]
        +    %2 = icmp eq i32 %1, 0      ; <i1> [#uses=1]
        +    br i1 %2, label %sum.exit, label %bb1.i
         
        -bb10:           ; preds = %entry
        -        ret i32 0
        +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
         }
        -

        Note the usage of SSA form and the total absence of any loop or -recursion at all! The long string called target datalayout is a +

        Note the usage of SSA form. The long string called target datalayout is a specification of the platform ABI (like endianness, sizes of types, alignment etc.).

        -

        The LLVM Language Reference -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.

        -
        - - --- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        Table: LLVM Instruction Set
        - Category - - Instructions -
        - Terminator instructions - - ret, br, switch, invoke, unwind, unreachable -
        - Binary operations - - add, sub, mul, udiv, sdiv, fdiv, urem, srem, frem -
        - Bitwise binary operations - - shl, lshr, ashr, and, or, xor -
        - Vector operations - - extractelement, insertelement, shufflevector -
        - Aggregate operations - - extractvalue, insertvalue -
        - Memory access and addressing operations - - malloc, free, alloca, load, store, getelementptr -
        - Conversion operations - - trunc, zext, sext, fptrunc, fpext, fptoui, fptosi, uitofp, sitofp, ptrtoint, inttoptr, bitcast -
        - Other operations - - icmp, fcmp, vicmp, vfcmp, phi, select, call, va_arg, getresult -
        - Variable argument handling intrinsics - - llvm.va_start, llvm.va_end, llvm.va_copy -
        - Accurate garbage collection intrinsics - - llvm.returnaddress, llvm.frameaddress, llvm.stacksave, llvm.stackrestore, llvm.prefetch, llvm.pcmarker, llvm.readcyclecounter -
        - Standard C library intrinsics - - llvm.memcpy.*, llvm.memmove.*, llvm.memset.*, llvm.sqrt.*, llvm.powi.*, llvm.sin.*, llvm.cos.*, llvm.pow.* -
        - Bit manipulation intrinsics - - llvm.bswap.*, llvm.ctpop.*, llvm.ctlz.*, llvm.cttz.*, llvm.part.select.*, llvm.part.set.* -
        - Debugger intrinsics - - llvm.dbg.stoppoint, llvm.dbg.func.start, llvm.dbg.region.start, llvm.dbg.region.end, llvm.dbg.declare -
        - Exception handling intrinsics - - llvm.eh_exception, llvm.eh_selector, llvm.eh_typeid_for -
        - Trampoline intrinsics - - llvm.init.trampoline -
        - Atomic intrinsics - - llvm.memory.barrier, llvm.atomic.lcs, llvm.atomic.las, llvm.atomic.swap -
        - General intrinsics - - llvm.var.annotation, llvm.annotation.*, llvm.trap -
        -
        +

        The LLVM Language Reference +defines the LLVM assembly language including the entire instruction set.

        Modules

        -

        Modules, in the LLVM IR, are similar to a single C language source +

        Modules, in the LLVM IR, are similar to a single C language source file (.c file). A module contains:

        -
          +
          • functions (declarations and definitions) @@ -519,124 +367,123 @@ global type aliases (typedef-s)

          -

          Modules are top-level containers; all executable code representation is +

          Modules are top-level containers; all executable code representation is contained within modules.

          Optimization and Passes

          -

          LLVM provides quite a few optimization algorithms that work on the IR. +

          LLVM provides quite a few optimization algorithms that work on the IR. These algorithms are organized as passes. Each pass does something specific, like combining redundant instructions. Passes need not always optimize the IR, it can also do other operations like inserting instrumentation code, or analysing the IR (the result of which can be used by passes that do optimizations) or even printing call graphs.

          -

          This LLVM documentation page +

          This LLVM documentation page describes all the available passes, and what they do.

          -

          LLVM does not automatically choose to run any passes, anytime. Passes +

          LLVM does not automatically choose to run any passes, anytime. Passes have to be explicitly selected and run on each module. This gives you the flexibility to choose transformations and optimizations that are most suitable for the code in the module.

          -

          There is an LLVM binary called opt, +

          There is an LLVM binary called opt, which lets you run passes on bitcode files from the command line. You can write your own passes (in C/C++, as a shared library). This can be 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 any stage, and perform any transforms on it as you like.)

          +

          TODO: pass manager, execution engine, bit code

          The llvm-py Package

          -

          The llvm-py is a Python package, consisting of 6 modules, that wrap +

          The llvm-py is a Python package, consisting of 6 modules, that wrap over enough LLVM APIs to allow the implementation of your own -compiler/VM backend in pure Python. If you're come this far, you +compiler/VM backend in pure Python. If you’re come this far, you probably know why this is a good idea.

          -

          Out of the 6 modules, one is an “extension” module (i.e., it is +

          Out of the 6 modules, one is an “extension” module (i.e., it is written in C), and another one is a small private utility module, which leaves 4 public modules. These are:

          -
            +
            • -llvm — top-level package, common classes (like exceptions) +llvm — top-level package, common classes (like exceptions)

            • -llvm.core — IR-related APIs +llvm.core — IR-related APIs

            • -llvm.ee — execution engine related APIs +llvm.ee — execution engine related APIs

            • -llvm.passes — pass manager and passes related APIs +llvm.passes — pass manager and passes related APIs

            -

            The modules contain only classes and (integer) constants. Mostly simple -Python constructs are used (deliberately) — -property() and +

            The modules contain only classes and (integer) constants. Mostly simple +Python constructs are used (deliberately) — property() and property decorators are probably the most exotic animals around. All classes are "new style" classes. The APIs are designed to be navigable (and guessable!) once you know a few conventions. These conventions are highlighted in the sections below.

            -

            Here is a quick overview of the contents of each package:

            -
            llvm
              +

              Here is a quick overview of the contents of each package:

              +
              llvm
              • -LLVMException — exception class (currently the only one) +LLVMException — exception class (currently the only one)

              -
              llvm.core
                +
                llvm.core
                • -Module — represents an LLVM Module +Module — represents an LLVM Module

                • -Type — represents an LLVM Type +Type — represents an LLVM Type

                • IntegerType, FunctionType, StructType, ArrayType, PointerType, - VectorType — derived classes of Type + VectorType  — derived classes of Type

                • -TypeHandle — used for constructing recursive (self-referencing) types +TypeHandle — used for constructing recursive (self-referencing) types (e.g. linked list nodes)

                • -Value — represents an LLVM Value +Value — represents an LLVM Value

                • Constant, GlobalValue, GlobalVariable, Argument, Function, - Instruction, CallOrInvokeInstruction, PHINode, SwitchInstruction — - various derived classes of Value + Instruction, CallOrInvokeInstruction, PHINode, SwitchInstruction —  various derived classes of Value

                • -BasicBlock — another derived of Value, represents an LLVM basic block +BasicBlock — another derived of Value, represents an LLVM basic block

                • -Builder — used for creating instructions, wraps LLVM IRBuilder helper +Builder — used for creating instructions, wraps LLVM IRBuilder helper class

                • -ModuleProvider — required to use modules in execution engine and pass +ModuleProvider — required to use modules in execution engine and pass manager

                • @@ -674,29 +521,29 @@ constants ATTR_* that represent function parameter attributes

                -
                llvm.ee
                  +
                  llvm.ee
                  • -ExecutionEngine — represents an execution engine (which can be an +ExecutionEngine — represents an execution engine (which can be an either an interpreter or a JIT)

                  • -TargetData — represents the ABI of the target platform (details like +TargetData — represents the ABI of the target platform (details like sizes and alignment of primitive types, endinanness etc)

                  -
                  llvm.passes
                    +
                    llvm.passes
                    • -PassManager — represents an LLVM pass manager +PassManager — represents an LLVM pass manager

                    • -FunctionPassManager — represents an LLVM function pass manager +FunctionPassManager — represents an LLVM function pass manager

                    • @@ -705,20 +552,19 @@ constants PASS_* that represent various passes

                    -
                    A note on the 'import'ing of these modules

                    Pythonically, modules are imported with the statement "import +

                    A note on the 'import’ing of these modules

                    Pythonically, modules are imported with the statement "import llvm.core". However, you might find it more convenient to import llvm-py modules thus:

                    -
                    from llvm import *
                     from llvm.core import *
                     from llvm.ee import *
                    -from llvm.passes import *
                    -
                    -

                    This avoids quite some typing. Both conventions work, however.

                    +from llvm.passes import *
                  +

                  This avoids quite some typing. Both conventions work, however.

                  @@ -731,11 +577,11 @@ to get online help. (Note: not complete yet!)

                  Module (llvm.core)

                  -

                  Modules are top-level container objects. You need to create a module +

                  Modules are top-level container objects. You need to create a module object first, before you can add global variables, aliases or functions. Modules are created using the static method Module.new:

                  -
                  @@ -745,9 +591,8 @@ http://www.gnu.org/software/src-highlite --> from llvm.core import * # create a module -my_module = Module.new('my_module') -
                  -

                  The constructor of the Module class should not be used to instantiate +my_module = Module.new('my_module')

                  +

                  The constructor of the Module class should not be used to instantiate a Module object. This is a common feature for all llvm-py classes.

                  @@ -756,56 +601,53 @@ a Module object. This is a common feature for all llvm-py classes.

                  Convention
                  -

                  All llvm-py objects are instantiated using static methods of +

                  All llvm-py objects are instantiated using static methods of corresponding classes. Constructors should not be used.

                  -

                  The argument my_module is a module identifier (a plain string). A +

                  The argument my_module is a module identifier (a plain string). A module can also be constructed via deserialization from a bit code file, using the static method from_bitcode. This method takes a file-like object as argument, i.e., it should have a read() method that returns the entire data in a single call, as is the case with the builtin file object. Here is an example:

                  -
                  # create a module from a bit code file
                   bcfile = file("test.bc")
                  -my_module = Module.from_bitcode(bcfile)
                  -
                  -

                  There is corresponding serialization method also, called to_bitcode:

                  +my_module = Module.from_bitcode(bcfile)
                +

                There is corresponding serialization method also, called to_bitcode:

                -
                # write out a bit code file from the module
                 bcfile = file("test.bc", "w")
                -my_module.to_bitcode(bcfile)
                -
                -

                Modules can also be constructed from LLVM assembly files (.ll files). +my_module.to_bitcode(bcfile)

              +

              Modules can also be constructed from LLVM assembly files (.ll files). The static method from_assembly can be used for this. Similar to the from_bitcode method, this one also takes a file-like object as argument:

              -
              # create a module from an assembly file
               llfile = file("test.ll")
              -my_module = Module.from_assembly(llfile)
              -
              -

              Modules can be converted into their assembly representation by +my_module = Module.from_assembly(llfile)

            +

            Modules can be converted into their assembly representation by stringifying them (see below).

            llvm.core.Module
            -
            Static Constructors
            -
            +
            Static Constructors
            +
            new(module_id)
            @@ -814,7 +656,7 @@ stringifying them (see below).

            should be a string.

            -
            +
            from_bitcode(fileobj)
            @@ -823,7 +665,7 @@ stringifying them (see below).

            represented by the file-like object fileobj.

            -
            +
            from_assembly(fileobj)
            @@ -833,8 +675,8 @@ stringifying them (see below).

            -
            Properties
            -
            +
            Properties
            +
            data_layout
            @@ -842,7 +684,7 @@ stringifying them (see below).

            A string representing the ABI of the platform.

            -
            +
            target
            @@ -850,7 +692,7 @@ stringifying them (see below).

            A string like i386-pc-linux-gnu or i386-pc-solaris2.8.

            -
            +
            global_variables [read-only]
            @@ -859,7 +701,7 @@ stringifying them (see below).

            the global variables of the module.

            -
            +
            functions [read-only]
            @@ -869,8 +711,8 @@ stringifying them (see below).

          -
          Methods
          -
          +
          Methods
          +
          add_type_name(name, ty)
          @@ -878,7 +720,7 @@ stringifying them (see below).

          Add an alias (typedef) for the type ty with the name name.

          -
          +
          delete_type_name(name)
          @@ -886,7 +728,7 @@ stringifying them (see below).

          Delete an alias with the name name.

          -
          +
          add_global_variable(ty, name)
          @@ -895,7 +737,7 @@ stringifying them (see below).

          Returns a GlobalVariable object.

          -
          +
          get_global_variable_named(name)
          @@ -905,7 +747,7 @@ stringifying them (see below).

          variable does not exist.

          -
          +
          add_function(ty, name)
          @@ -914,7 +756,7 @@ stringifying them (see below).

          of an object of type FunctionType.

          -
          +
          get_function_named(name)
          @@ -923,7 +765,7 @@ stringifying them (see below).

          name. Raises LLVMException if such a function does not exist.

          -
          +
          verify()
          @@ -932,7 +774,7 @@ stringifying them (see below).

          errors.

          -
          +
          to_bitcode(fileobj)
          @@ -942,17 +784,17 @@ stringifying them (see below).

        -
        Special Methods
        -
        +
        Special Methods
        +
        __str__

        - Module objects can be stringified into it's LLVM assembly language + Module objects can be stringified into it’s LLVM assembly language representation.

        -
        +
        __eq__
        @@ -971,16 +813,16 @@ stringifying them (see below).

        Convention
        -

        All llvm-py objects (where it makes sense), when stringified, return -the LLVM assembly representation. “ print module_obj ” for example, +

        All llvm-py objects (where it makes sense), when stringified, return +the LLVM assembly representation. ‘` `print module_obj` '’ for example, prints the LLVM assembly form of the entire module.

        -

        Such objects, when compared for equality, internally compare these +

        Such objects, when compared for equality, internally compare these string representations.

        Types (llvm.core)

        -

        Types are what you think they are. A instance of llvm.core.Type, or +

        Types are what you think they are. A instance of llvm.core.Type, or one of its derived classes, represent a type. llvm-py does not use as many classes to represent types as does LLVM itself. Some types are represented using llvm.core.Type itself and the rest are represented @@ -988,199 +830,104 @@ using derived classes of llvm.core.Type. As usual, an instance is creat via one of the static methods of Type. These methods return an instance of either llvm.core.Type itself or one of its derived classes.

        -

        The following table lists all the available types along with the static +

        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 object is actually returned by the static method.

        ---+++ - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        - Name - - Constructor Method - - Class -
        NameConstructor MethodClass
        - integer of bitwidth n - - Type.int(n) - - IntegerType -
        - 32-bit float - - Type.float() - - Type -
        - 64-bit double - - Type.double() - - Type -
        - 80-bit float - - Type.x86_fp80() - - Type -
        - 128-bit float (112-bit mantissa) - - Type.fp128() - - Type -
        - 128-bit float (two 64-bits) - - Type.ppc_fp128() - - Type -
        - function - - Type.function(r, p, v) - - FunctionType -
        - unpacked struct - - Type.struct(eltys) - - StructType -
        - packed struct - - Type.packed_struct(eltys) - - StructType -
        - array - - Type.array(elty, count) - - ArrayType -
        - pointer to value of type pty - - Type.pointer(pty, addrspc) - - PointerType -
        - vector - - Type.vector(elty, count) - - VectorType -
        - void - - Type.void() - - Type -
        - label - - Type.label() - - Type -
        - opaque - - Type.opaque() - - Type -

        integer of bitwidth n

        Type.int(n)

        IntegerType

        32-bit float

        Type.float()

        Type

        64-bit double

        Type.double()

        Type

        80-bit float

        Type.x86_fp80()

        Type

        128-bit float (112-bit mantissa)

        Type.fp128()

        Type

        128-bit float (two 64-bits)

        Type.ppc_fp128()

        Type

        function

        Type.function(r, p, v)

        FunctionType

        unpacked struct

        Type.struct(eltys)

        StructType

        packed struct

        Type.packed_struct(eltys)

        StructType

        array

        Type.array(elty, count)

        ArrayType

        pointer to value of type pty

        Type.pointer(pty, addrspc)

        PointerType

        vector

        Type.vector(elty, count)

        VectorType

        void

        Type.void()

        Type

        label

        Type.label()

        Type

        opaque

        Type.opaque()

        Type

        -

        The class hierarchy is:

        +

        The class hierarchy is:

        Type
        @@ -1191,12 +938,12 @@ cellspacing="0" cellpadding="4">
           PointerType
           VectorType
        -

        The class-level documentation follows:

        +

        The class-level documentation follows:

        llvm.core.Type
        -
        Static Constructors
        -
        +
        Static Constructors
        +
        int(n)
        @@ -1204,7 +951,7 @@ cellspacing="0" cellpadding="4"> Create an integer type of bit width n.

        -
        +
        float()
        @@ -1212,7 +959,7 @@ cellspacing="0" cellpadding="4"> Create a 32-bit floating point type.

        -
        +
        double()
        @@ -1220,7 +967,7 @@ cellspacing="0" cellpadding="4"> Create a 64-bit floating point type.

        -
        +
        x86_fp80()
        @@ -1228,7 +975,7 @@ cellspacing="0" cellpadding="4"> Create a 80-bit 80x87-style floating point type.

        -
        +
        fp128()
        @@ -1236,7 +983,7 @@ cellspacing="0" cellpadding="4"> Create a 128-bit floating point type (112-bit mantissa).

        -
        +
        ppc_fp128()
        @@ -1244,7 +991,7 @@ cellspacing="0" cellpadding="4"> Create a 128-bit float (two 64-bits).

        -
        +
        function(ret, params, vararg=False)
        @@ -1256,7 +1003,7 @@ cellspacing="0" cellpadding="4"> variadic.

        -
        +
        struct(eltys)
        @@ -1265,7 +1012,7 @@ cellspacing="0" cellpadding="4"> Type objects representing the type of each element in order.

        -
        +
        packed_struct(eltys)
        @@ -1273,7 +1020,7 @@ cellspacing="0" cellpadding="4"> Like struct(eltys), but creates a packed struct.

        -
        +
        array(elty, count)
        @@ -1282,7 +1029,7 @@ cellspacing="0" cellpadding="4"> (which should be a Type).

        -
        +
        pointer(pty, addrspc=0)
        @@ -1292,7 +1039,7 @@ cellspacing="0" cellpadding="4"> LLVM docs or ask on llvm-dev for more info).

        -
        +
        void()
        @@ -1300,7 +1047,7 @@ cellspacing="0" cellpadding="4"> Creates a void type. Used for function return types.

        -
        +
        label()
        @@ -1308,7 +1055,7 @@ cellspacing="0" cellpadding="4"> Creates a label type.

        -
        +
        opaque()
        @@ -1317,17 +1064,17 @@ cellspacing="0" cellpadding="4">

        -
        Properties
        -
        +
        Properties
        +
        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:

        -
        @@ -1338,27 +1085,26 @@ TYPE_X86_FP80 = = 4 TYPE_PPC_FP128 = 5 TYPE_LABEL = 6 -TYPE_INTEGER = 7 -TYPE_FUNCTION = 8 -TYPE_STRUCT = 9 -TYPE_ARRAY = 10 -TYPE_POINTER = 11 -TYPE_OPAQUE = 12 -TYPE_VECTOR = 13 -
        -

        Example:

        +TYPE_METADATA = 7 +TYPE_INTEGER = 8 +TYPE_FUNCTION = 9 +TYPE_STRUCT = 10 +TYPE_ARRAY = 11 +TYPE_POINTER = 12 +TYPE_OPAQUE = 13 +TYPE_VECTOR = 14
        +

        Example:

        -
        assert Type.int().kind == TYPE_INTEGER
        -assert Type.void().kind == TYPE_VOID
        -
        +assert Type.void().kind == TYPE_VOID
        -
        Methods
        -
        +
        Methods
        +
        refine
        @@ -1368,17 +1114,17 @@ http://www.gnu.org/software/src-highlite -->

        -
        Special Methods
        -
        +
        Special Methods
        +
        __str__

        - Type objects can be stringified into it's LLVM assembly language + Type objects can be stringified into it’s LLVM assembly language representation.

        -
        +
        __eq__
        @@ -1393,15 +1139,15 @@ http://www.gnu.org/software/src-highlite -->
        llvm.core.IntegerType
        -
        Base Class
          +
          Base Class
          • llvm.core.Type

          -
          Properties
          -
          +
          Properties
          +
          width [read-only]
          @@ -1414,15 +1160,15 @@ http://www.gnu.org/software/src-highlite -->
          llvm.core.FunctionType
          -
          Base Class
            +
            Base Class
            • llvm.core.Type

            -
            Properties
            -
            +
            Properties
            +
            return_type [read-only]
            @@ -1430,7 +1176,7 @@ http://www.gnu.org/software/src-highlite --> A Type object, representing the return type of the function.

            -
            +
            vararg [read-only]
            @@ -1438,7 +1184,7 @@ http://www.gnu.org/software/src-highlite --> True if the function is variadic.

            -
            +
            args [read-only]
            @@ -1448,7 +1194,7 @@ http://www.gnu.org/software/src-highlite --> function. Used like this:

            -
            @@ -1456,10 +1202,9 @@ http://www.gnu.org/software/src-highlite --> for arg in func_type.args: assert arg.kind == TYPE_INTEGER assert arg == Type.int() -assert func_type.arg_count == len(func_type.args) -
            +assert func_type.arg_count == len(func_type.args)
          -
          +
          arg_count [read-only]
          @@ -1472,15 +1217,15 @@ http://www.gnu.org/software/src-highlite -->
          llvm.core.StructType
          -
          Base Class
            +
            Base Class
            • llvm.core.Type

            -
            Properties
            -
            +
            Properties
            +
            packed [read-only]
            @@ -1488,7 +1233,7 @@ http://www.gnu.org/software/src-highlite --> True if the structure is packed (no padding between elements).

            -
            +
            elements [read-only]
            @@ -1498,7 +1243,7 @@ http://www.gnu.org/software/src-highlite --> Used like this:

            -
            @@ -1506,10 +1251,9 @@ http://www.gnu.org/software/src-highlite --> for elem in struct_type.elements: assert elem.kind == TYPE_INTEGER assert elem == Type.int() -assert struct_type.element_count == len(struct_type.elements) -
            +assert struct_type.element_count == len(struct_type.elements)
          -
          +
          element_count [read-only]
          @@ -1522,15 +1266,15 @@ http://www.gnu.org/software/src-highlite -->
          llvm.core.ArrayType
          -
          Base Class
            +
            Base Class
            • llvm.core.Type

            -
            Properties
            -
            +
            Properties
            +
            element [read-only]
            @@ -1538,7 +1282,7 @@ http://www.gnu.org/software/src-highlite --> A Type object representing the type of the element of the array.

            -
            +
            count [read-only]
            @@ -1551,15 +1295,15 @@ http://www.gnu.org/software/src-highlite -->
            llvm.core.PointerType
            -
            Base Class
              +
              Base Class
              • llvm.core.Type

              -
              Properties
              -
              +
              Properties
              +
              address_space [read-only]
              @@ -1567,7 +1311,7 @@ http://www.gnu.org/software/src-highlite --> The address space of the pointer.

              -
              +
              pointee [read-only]
              @@ -1580,15 +1324,15 @@ http://www.gnu.org/software/src-highlite -->
              llvm.core.VectorType
              -
              Base Class
                +
                Base Class
                • llvm.core.Type

                -
                Properties
                -
                +
                Properties
                +
                element [read-only]
                @@ -1596,7 +1340,7 @@ http://www.gnu.org/software/src-highlite --> A Type object representing the type of the element of the vector.

                -
                +
                count [read-only]
                @@ -1606,9 +1350,9 @@ http://www.gnu.org/software/src-highlite -->
              -

              Here is an example that demonstrates the creation of types:

              +

              Here is an example that demonstrates the creation of types:

              -
              @@ -1647,23 +1391,21 @@ f3 = Type.= [ Type.pointer( Type.int(8) ) ] printf = Type.function( Type.int(), fnargs, True ) - # variadic function -
              + # variadic function

              TypeHandle (llvm.core)

              -

              TypeHandle objects are used to create recursive types, like this linked +

              TypeHandle objects are used to create recursive types, like this linked list node structure in C:

              -
              -
              struct node
              +
              struct node
               {
                   int data;
              -    struct node *next;
              -};
              -
              -

              This can be realized in llvm-py like this:

              + struct node *next; +};
              +

              This can be realized in llvm-py like this:

              #!/usr/bin/env python
              @@ -1686,14 +1428,14 @@ m.add_type_name("struct.node", th.type)
               # show what we created
               print m
              -

              which gives the output:

              +

              which gives the output:

              ; ModuleID = 'mod1'
                       %struct.node = type { i32, %struct.node* }
              -

              For more details on what is going on here, please refer the LLVM -Programmer's Manual section +

              For more details on what is going on here, please refer the LLVM +Programmer’s Manual section "LLVM Type Resolution". The TypeHandle class of llvm-py corresponds to llvm::PATypeHolder @@ -1703,8 +1445,8 @@ in the source distribution.

              llvm.core.TypeHandle
              -
              Static Constructors
              -
              +
              Static Constructors
              +
              new(abstract_ty)
              @@ -1715,8 +1457,8 @@ in the source distribution.

            -
            Properties
            -
            +
            Properties
            +
            type
            @@ -1728,10 +1470,10 @@ in the source distribution.

          Values (llvm.core)

          -

          llvm.core.Value is the base class of all values computed by a program +

          llvm.core.Value is the base class of all values computed by a program that may be used as operands to other values. A value has a type associated with it (an object of llvm.core.Type).

          -

          The class hierarchy is:

          +

          The class hierarchy is:

          Value
          @@ -1746,22 +1488,22 @@ associated with it (an object of llvm.core.Type).

          SwitchInstruction BasicBlock
          -

          The Value class is abstract, it's not meant to be instantiated. +

          The Value class is abstract, it’s not meant to be instantiated. Constant-s represent constants that appear within code or as initializers of globals. They are constructed using static methods of Constant. The Constant class is covered in a separate section below. The Function object represents an instance of a function type. Such objects contain Argument objects, which represent the actual, local-variable-like arguments of the function (not to be confused with -the arguments returned by a function type object — these represent +the arguments returned by a function type object — these represent the type of the arguments). The various Instruction-s are created by the Builder class. These are also covered separately.

          -

          Value objects have a type (read-only), and a name (read-write).

          +

          Value objects have a type (read-only), and a name (read-write).

          llvm.core.Value
          -
          Properties
          -
          +
          Properties
          +
          name
          @@ -1769,7 +1511,7 @@ the Builder class. These are also covered separately.

          The name of the value.

          -
          +
          type [read-only]
          @@ -1778,17 +1520,17 @@ the Builder class. These are also covered separately.

        -
        Special Methods
        -
        +
        Special Methods
        +
        __str__

        - Value objects can be stringified into it's LLVM assembly language + Value objects can be stringified into it’s LLVM assembly language representation.

        -
        +
        __eq__
        @@ -1801,14 +1543,13 @@ the Builder class. These are also covered separately.

        Constants (llvm.core)

        -

        Constant-s represents constants that appear within the code. The +

        Constant-s represents constants that appear within the code. The values of such objects are known at creation time. Constants can be -created from Python constants. A constant expression is also a constant -— given a Constant object, an operation (like addition, subtraction -etc) can be specified, to yield a new Constant object. Let's see some +created from Python constants. A constant expression is also a constant — given a Constant object, an operation (like addition, subtraction +etc) can be specified, to yield a new Constant object. Let’s see some examples:

        -
        @@ -1822,877 +1563,534 @@ k2 = k1. tr = Type.float() r1 = Constant.real(tr, "3.141592") # create from a string -r2 = Constant.real(tr, 1.61803399) # create from a Python float -
        -

        The following constructors (static methods) can be used to create +r2 = Constant.real(tr, 1.61803399) # create from a Python float

        +

        The following constructors (static methods) can be used to create constants:

        --++ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        - Constructor Method - - What It Creates -
        Constructor MethodWhat It Creates
        - null(ty) - - A null value (all zeros) of type ty -
        - all_ones(ty) - - All 1's 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_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) -
        - stringz(value) - - A null-terminated string. value is a Python string -
        - string(value) - - As string(ty), but not null terminated -
        - array(ty, consts) - - Array of type ty, initialized with consts (an iterable yielding Constant objects of the appropriate type) -
        - struct(ty, consts) - - Struct (unpacked) of type ty, initialized with consts (an iterable yielding Constant objects of the appropriate type) -
        - 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) -
        - sizeof(ty) - - Constant value representing the sizeof the type ty -

        null(ty)

        A null value (all zeros) of type ty

        all_ones(ty)

        All 1’s 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_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)

        stringz(value)

        A null-terminated string. value is a Python string

        string(value)

        As string(ty), but not null terminated

        array(ty, consts)

        Array of type ty, initialized with consts (an iterable yielding Constant objects of the appropriate type)

        struct(ty, consts)

        Struct (unpacked) of type ty, initialized with consts (an iterable yielding Constant objects of the appropriate type)

        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)

        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 Constant Expressions section of the LLVM Language Reference.

        --++ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        - Method - - Operation -
        MethodOperation
        - k.neg() - - negation, same as 0 - k -
        - k.not_() - - 1's complement of k. Note trailing underscore. -
        - k.add(k2) - - k + k2 -
        - k.sub(k2) - - k - k2 -
        - k.mul(k2) - - k * k2 -
        - k.udiv(k2) - - Quotient of unsigned division of k with k2 -
        - k.sdiv(k2) - - Quotient of signed division of k with k2 -
        - k.fdiv(k2) - - Quotient of floating point division of k with k2 -
        - k.urem(k2) - - Reminder of unsigned division of k with k2 -
        - k.srem(k2) - - Reminder of signed division of k with k2 -
        - k.frem(k2) - - Reminder of floating point division of k with k2 -
        - k.and_(k2) - - Bitwise and of k and k2. Note trailing underscore. -
        - k.or_(k2) - - Bitwise or of k and k2. Note trailing underscore. -
        - k.xor(k2) - - Bitwise exclusive-or of k and k2. -
        - k.icmp(ipred, k2) - - Compare k with k2 using the predicate ipred. See table below for list of predicates for integer operands. -
        - k.fcmp(rpred, k2) - - Compare k with k2 using the predicate rpred. See table below for list of predicates for real operands. -
        - k.shl(k2) - - Shift k left by k2 bits. -
        - k.lshr(k2) - - Shift k logically right by k2 bits (new bits are 0s). -
        - k.ashr(k2) - - Shift k arithmetically right by k2 bits (new bits are same as previous sign bit). -
        - k.gep(indices) - - TODO -
        - k.trunc(ty) - - Truncate k to a type ty of lower bitwidth. -
        - k.sext(ty) - - Sign extend k to a type ty of higher bitwidth, while extending the sign bit. -
        - k.zext(ty) - - Sign extend k to a type ty of higher bitwidth, all new bits are 0s. -
        - k.fptrunc(ty) - - Truncate floating point constant k to floating point type ty of lower size than k's. -
        - k.fpext(ty) - - Extend floating point constant k to floating point type ty of higher size than k's. -
        - k.uitofp(ty) - - Convert an unsigned integer constant k to floating point constant of type ty. -
        - k.sitofp(ty) - - Convert a signed integer constant k to floating point constant of type ty. -
        - k.fptoui(ty) - - Convert a floating point constant k to an unsigned integer constant of type ty. -
        - k.fptosi(ty) - - Convert a floating point constant k to a signed integer constant of type ty. -
        - k.ptrtoint(ty) - - Convert a pointer constant k to an integer constant of type ty. -
        - k.inttoptr(ty) - - Convert an integer constant k to a pointer constant of type ty. -
        - k.bitcast(ty) - - Convert k to a (equal-width) constant of type ty. -
        - k.select(cond,k2,k3) - - Replace value with k2 if the 1-bit integer constant cond is 1, else with k3. -
        - 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.shuffle_vector(k2,mask) - - Shuffle vector constant k based on vector constants k2 and mask. -

        k.neg()

        negation, same as 0 - k

        k.not_()

        1’s complement of k. Note trailing underscore.

        k.add(k2)

        k + k2

        k.sub(k2)

        k - k2

        k.mul(k2)

        k * k2

        k.udiv(k2)

        Quotient of unsigned division of k with k2

        k.sdiv(k2)

        Quotient of signed division of k with k2

        k.fdiv(k2)

        Quotient of floating point division of k with k2

        k.urem(k2)

        Reminder of unsigned division of k with k2

        k.srem(k2)

        Reminder of signed division of k with k2

        k.frem(k2)

        Reminder of floating point division of k with k2

        k.and_(k2)

        Bitwise and of k and k2. Note trailing underscore.

        k.or_(k2)

        Bitwise or of k and k2. Note trailing underscore.

        k.xor(k2)

        Bitwise exclusive-or of k and k2.

        k.icmp(ipred, k2)

        Compare k with k2 using the predicate ipred. See table below for list of predicates for integer operands.

        k.fcmp(rpred, k2)

        Compare k with k2 using the predicate rpred. See table below for list of predicates for real operands.

        k.shl(k2)

        Shift k left by k2 bits.

        k.lshr(k2)

        Shift k logically right by k2 bits (new bits are 0s).

        k.ashr(k2)

        Shift k arithmetically right by k2 bits (new bits are same as previous sign bit).

        k.gep(indices)

        TODO

        k.trunc(ty)

        Truncate k to a type ty of lower bitwidth.

        k.sext(ty)

        Sign extend k to a type ty of higher bitwidth, while extending the sign bit.

        k.zext(ty)

        Sign extend k to a type ty of higher bitwidth, all new bits are 0s.

        k.fptrunc(ty)

        Truncate floating point constant k to floating point type ty of lower size than k’s.

        k.fpext(ty)

        Extend floating point constant k to floating point type ty of higher size than k’s.

        k.uitofp(ty)

        Convert an unsigned integer constant k to floating point constant of type ty.

        k.sitofp(ty)

        Convert a signed integer constant k to floating point constant of type ty.

        k.fptoui(ty)

        Convert a floating point constant k to an unsigned integer constant of type ty.

        k.fptosi(ty)

        Convert a floating point constant k to a signed integer constant of type ty.

        k.ptrtoint(ty)

        Convert a pointer constant k to an integer constant of type ty.

        k.inttoptr(ty)

        Convert an integer constant k to a pointer constant of type ty.

        k.bitcast(ty)

        Convert k to a (equal-width) constant of type ty.

        k.select(cond,k2,k3)

        Replace value with k2 if the 1-bit integer constant cond is 1, else with k3.

        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.shuffle_vector(k2,mask)

        Shuffle vector constant k based on vector constants k2 and mask.

        -

        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.

        --++ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        - Value - - Meaning -
        ValueMeaning
        - IPRED_EQ - - Equality -
        - IPRED_NE - - Inequality -
        - IPRED_UGT - - Unsigned greater than -
        - IPRED_UGE - - Unsigned greater than or equal -
        - IPRED_ULT - - Unsigned less than -
        - IPRED_ULE - - Unsigned less than or equal -
        - IPRED_SGT - - Signed greater than -
        - IPRED_SGE - - Signed greater than or equal -
        - IPRED_SLT - - Signed less than -
        - IPRED_SLE - - Signed less than or equal -

        IPRED_EQ

        Equality

        IPRED_NE

        Inequality

        IPRED_UGT

        Unsigned greater than

        IPRED_UGE

        Unsigned greater than or equal

        IPRED_ULT

        Unsigned less than

        IPRED_ULE

        Unsigned less than or equal

        IPRED_SGT

        Signed greater than

        IPRED_SGE

        Signed greater than or equal

        IPRED_SLT

        Signed less than

        IPRED_SLE

        Signed less than or equal

        -

        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.

        --++ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        - Value - - Meaning -
        ValueMeaning
        - RPRED_FALSE - - Always false -
        - RPRED_OEQ - - True if ordered and equal -
        - RPRED_OGT - - True if ordered and greater than -
        - RPRED_OGE - - True if ordered and greater than or equal -
        - RPRED_OLT - - True if ordered and less than -
        - RPRED_OLE - - True if ordered and less than or equal -
        - RPRED_ONE - - True if ordered and operands are unequal -
        - RPRED_ORD - - True if ordered (no NaNs) -
        - RPRED_UNO - - True if unordered: isnan(X) | isnan(Y) -
        - RPRED_UEQ - - True if unordered or equal -
        - RPRED_UGT - - True if unordered or greater than -
        - RPRED_UGE - - True if unordered, greater than or equal -
        - RPRED_ULT - - True if unordered, or less than -
        - RPRED_ULE - - True if unordered, less than or equal -
        - RPRED_UNE - - True if unordered or not equal -
        - RPRED_TRUE - - Always true -

        RPRED_FALSE

        Always false

        RPRED_OEQ

        True if ordered and equal

        RPRED_OGT

        True if ordered and greater than

        RPRED_OGE

        True if ordered and greater than or equal

        RPRED_OLT

        True if ordered and less than

        RPRED_OLE

        True if ordered and less than or equal

        RPRED_ONE

        True if ordered and operands are unequal

        RPRED_ORD

        True if ordered (no NaNs)

        RPRED_UNO

        True if unordered: isnan(X) | isnan(Y)

        RPRED_UEQ

        True if unordered or equal

        RPRED_UGT

        True if unordered or greater than

        RPRED_UGE

        True if unordered, greater than or equal

        RPRED_ULT

        True if unordered, or less than

        RPRED_ULE

        True if unordered, less than or equal

        RPRED_UNE

        True if unordered or not equal

        `RPRED_TRUE `

        Always true

        llvm.core.Constant
        -
        Base Class
          +
          Base Class
          • llvm.core.Value

          -
          Static Constructors

          See table of constructors above for full list.

          -
          Methods

          See table of operations above for full list. There are no other +

          Static Constructors

          See table of constructors above for full list.

          +
          Methods

          See table of operations above for full list. There are no other methods.

        Global Value (llvm.core)

        -

        The class llvm.core.GlobalValue represents module-scope aliases, variables +

        The class llvm.core.GlobalValue represents module-scope aliases, variables and functions. Global variables are represented by the sub-class llvm.core.GlobalVariable and functions by llvm.core.Function.

        -

        Global values have the read-write properties linkage, section, +

        Global values have the read-write properties linkage, section, visibility and alignment. Use one of the following constants (from llvm.core) as values for linkage (see LLVM documentaion for details on each):

        --++ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        - Value - - Equivalent LLVM Assembly Keyword -
        ValueEquivalent LLVM Assembly Keyword
        - LINKAGE_LINKONCE - - linkonce -
        - LINKAGE_WEAK - - weak -
        - LINKAGE_APPENDING - - appending -
        - LINKAGE_INTERNAL - - internal -
        - LINKAGE_DLLIMPORT - - dllimport -
        - LINKAGE_DLLEXPORT - - dllexport -
        - LINKAGE_EXTERNAL - - externally visible -
        - LINKAGE_EXTERNAL_WEAK - - extern_weak -
        - LINKAGE_GHOST - - Stand-in functions -

        LINKAGE_EXTERNAL

        externally_visible

        LINKAGE_AVAILABLE_EXTERNALLY

        available_externally

        LINKAGE_LINKONCE_ANY

        linkonce

        LINKAGE_LINKONCE_ODR

        linkonce_odr

        LINKAGE_WEAK_ANY

        weak

        LINKAGE_WEAK_ODR

        weak_odr

        LINKAGE_APPENDING

        appending

        LINKAGE_INTERNAL

        internal

        LINKAGE_PRIVATE

        private

        LINKAGE_LINKER_PRIVATE

        linker_private

        LINKAGE_DLLIMPORT

        dllimport

        LINKAGE_DLLEXPORT

        dllexport

        LINKAGE_EXTERNAL_WEAK

        extern_weak

        LINKAGE_COMMON

        common

        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 to one of thse constants (from llvm.core, see also LLVM docs):

        --++ - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + +
        - Value - - Equivalent LLVM Assembly Keyword -
        ValueEquivalent LLVM Assembly Keyword
        - VISIBILITY_DEFAULT - - default -
        - VISIBILITY_HIDDEN - - hidden -
        - VISIBILITY_PROTECTED - - protected -

        VISIBILITY_DEFAULT

        default

        VISIBILITY_HIDDEN

        hidden

        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 global is a declaration or not. The module to which the global belongs to can be retrieved using the module property (read-only).

        llvm.core.GlobalValue
        -
        Base Class
          +
          Base Class
          • llvm.core.Constant

          -
          Properties
          -
          +
          Properties
          +
          linkage
          @@ -2701,7 +2099,7 @@ to can be retrieved using the module property (read-only).

          (LINKAGE_*).

          -
          +
          section
          @@ -2710,7 +2108,7 @@ to can be retrieved using the module property (read-only).

          global is placed into.

          -
          +
          visibility
          @@ -2719,7 +2117,7 @@ to can be retrieved using the module property (read-only).

        (VISIBILITY_*).

        -
        +
        alignment
        @@ -2727,7 +2125,7 @@ to can be retrieved using the module property (read-only).

        A power-of-2 integer indicating the boundary to align to.

        -
        +
        is_declaration [read-only]
        @@ -2735,7 +2133,7 @@ to can be retrieved using the module property (read-only).

        True if the global is a declaration, False otherwise.

        -
        +
        module [read-only]
        @@ -2746,14 +2144,14 @@ to can be retrieved using the module property (read-only).

        Global Variable (llvm.core)

        -

        Global variables (llvm.core.GlobalVariable) are subclasses of +

        Global variables (llvm.core.GlobalVariable) are subclasses of llvm.core.GlobalValue and represent module-level variables. These can have optional initializers and can be marked as constants. Global variables can be created either by using the add_global_variable method of the Module class (see above), or by using the static method GlobalVariable.new.

        -
        @@ -2761,14 +2159,13 @@ http://www.gnu.org/software/src-highlite --> gv1 = module_obj.add_global_variable(Type.int(), "gv1") # or equivalently, using a static constructor method -gv2 = GlobalVariable.new(module_obj, Type.int(), "gv2") -
        -

        Existing global variables of a module can be accessed by name using +gv2 = GlobalVariable.new(module_obj, Type.int(), "gv2")

        +

        Existing global variables of a module can be accessed by name using module_obj.get_global_variable_named(name) or GlobalVariable.get. All existing global variables can be enumerated via iterating over the property module_obj.global_variables.

        -
        @@ -2781,15 +2178,14 @@ gv2 = GlobalVariable# list all global variables in a module for gv in module_obj.global_variables: - print gv.name, "of type", gv.type -
        -

        The initializer for a global variable can be set by assigning to the + print gv.name, "of type", gv.type

        +

        The initializer for a global variable can be set by assigning to the initializer property of the object. The is_global_constant property can be used to indicate that the variable is a global constant.

        -

        Global variables can be delete using the delete method. Do not use the +

        Global variables can be delete using the delete method. Do not use the object after calling delete on it.

        -
        @@ -2799,20 +2195,19 @@ gv.initializer # delete the global gv.delete() # DO NOT dereference `gv' beyond this point! -gv = None -
        +gv = None
        llvm.core.GlobalVariable
        -
        Base Class
          +
          Base Class
          • llvm.core.GlobalValue

          -
          Static Constructors
          -
          +
          Static Constructors
          +
          new(module_obj, ty, name)
          @@ -2821,7 +2216,7 @@ gv = None module_obj and return a GlobalVariable object that represents it.

          -
          +
          get(module_obj, name)
          @@ -2832,8 +2227,8 @@ gv = None

          -
          Properties
          -
          +
          Properties
          +
          initializer
          @@ -2842,7 +2237,7 @@ gv = None derived). Gets the initializer constant, or None if none exists.

          -
          +
          global_constant
          @@ -2851,20 +2246,20 @@ gv = None

          -
          Methods
          -
          +
          Methods
          +
          delete()

          - Deletes the global variable from it's module. Do not hold any + Deletes the global variable from it’s module. Do not hold any references to this object after calling delete on it.

          Function (llvm.core)

          -

          Functions are represented by llvm.core.Function objects. They are +

          Functions are represented by llvm.core.Function objects. They are contained within modules, and can be created either with the method module_obj.add_function or the static constructor Function.new. References to functions already present in a module can be retrieved via @@ -2872,7 +2267,7 @@ References to functions already present in a module can be retrieved via Function.get. All functions in a module can be enumerated by iterating over module_obj.functions.

          -
          @@ -2894,16 +2289,15 @@ f4 = Function.< # list all function names in a module for f in module_obj.functions: - print f.name -
          -

          References to intrinsic functions can be got via the static constructor + print f.name

          +

          References to intrinsic functions can be got via the static constructor intrinsic. This returns a Function object, calling which is equivalent to invoking the intrinsic. The intrinsic method has to be called with a module object, an instrinic ID (which is a numeric constant) and a list of the types of arguments (which LLVM uses to resolve overloaded intrinsic functions).

          -
          @@ -2911,9 +2305,8 @@ http://www.gnu.org/software/src-highlite --> bswap = Function.intrinsic(mod, INTR_BSWAP, [Type.int()]) # call it -builder.call(bswap, [value]) -
          -

          Here, the constant INTR_BSWAP, available from llvm.core, represents +builder.call(bswap, [value])

          +

          Here, the constant INTR_BSWAP, available from llvm.core, represents the LLVM intrinsic llvm.bswap. The [Type.int()] selects the version of llvm.bswap that has a single 32-bit @@ -2921,289 +2314,172 @@ integer argument. The list of intrinsic IDs defined as integer constants in llvm.core. These are:

          ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          - INTR_ANNOTATION - - INTR_ATOMIC_CMP_SWAP - - INTR_ATOMIC_LOAD_ADD -
          - INTR_ATOMIC_LOAD_AND - - INTR_ATOMIC_LOAD_MAX - - INTR_ATOMIC_LOAD_MIN -
          - INTR_ATOMIC_LOAD_NAND - - INTR_ATOMIC_LOAD_OR - - INTR_ATOMIC_LOAD_SUB -
          - INTR_ATOMIC_LOAD_UMAX - - INTR_ATOMIC_LOAD_UMIN - - INTR_ATOMIC_LOAD_XOR -
          - INTR_ATOMIC_SWAP - - INTR_BSWAP - - INTR_COS -
          - INTR_CTLZ - - INTR_CTPOP - - INTR_CTTZ -
          - INTR_DBG_DECLARE - - INTR_DBG_FUNC_START - - INTR_DBG_REGION_END -
          - INTR_DBG_REGION_START - - INTR_DBG_STOPPOINT - - INTR_EH_DWARF_CFA -
          - INTR_EH_EXCEPTION - - INTR_EH_RETURN_I32 - - INTR_EH_RETURN_I64 -
          - INTR_EH_SELECTOR_I32 - - INTR_EH_SELECTOR_I64 - - INTR_EH_TYPEID_FOR_I32 -
          - INTR_EH_TYPEID_FOR_I64 - - INTR_EH_UNWIND_INIT - - INTR_EXP -
          - INTR_EXP2 - - INTR_FLT_ROUNDS - - INTR_FRAMEADDRESS -
          - INTR_GCREAD - - INTR_GCROOT - - INTR_GCWRITE -
          - INTR_INIT_TRAMPOLINE - - INTR_LOG - - INTR_LOG10 -
          - INTR_LOG2 - - INTR_LONGJMP - - INTR_MEMCPY_I32 -
          - INTR_MEMCPY_I64 - - INTR_MEMMOVE_I32 - - INTR_MEMMOVE_I64 -
          - INTR_MEMORY_BARRIER - - INTR_MEMSET_I32 - - INTR_MEMSET_I64 -
          - INTR_PART_SELECT - - INTR_PART_SET - - INTR_PCMARKER -
          - INTR_POW - - INTR_POWI - - INTR_PREFETCH -
          - INTR_READCYCLECOUNTER - - INTR_RETURNADDRESS - - INTR_SETJMP -
          - INTR_SIGLONGJMP - - INTR_SIGSETJMP - - INTR_SIN -
          - INTR_SQRT - - INTR_STACKRESTORE - - INTR_STACKSAVE -
          - INTR_TRAP - - INTR_VACOPY - - INTR_VAEND -
          - INTR_VAR_ANNOTATION - - INTR_VASTART - -

          INTR_ALPHA_UMULH

          INTR_ANNOTATION

          INTR_ATOMIC_CMP_SWAP

          INTR_ATOMIC_LOAD_ADD

          INTR_ATOMIC_LOAD_AND

          INTR_ATOMIC_LOAD_MAX

          INTR_ATOMIC_LOAD_MIN

          INTR_ATOMIC_LOAD_NAND

          INTR_ATOMIC_LOAD_OR

          INTR_ATOMIC_LOAD_SUB

          INTR_ATOMIC_LOAD_UMAX

          INTR_ATOMIC_LOAD_UMIN

          INTR_ATOMIC_LOAD_XOR

          INTR_ATOMIC_SWAP

          INTR_BSWAP

          INTR_CONVERTFF

          INTR_CONVERTFSI

          INTR_CONVERTFUI

          INTR_CONVERTSIF

          INTR_CONVERTSS

          INTR_CONVERTSU

          INTR_CONVERTUIF

          INTR_CONVERTUS

          INTR_CONVERTUU

          INTR_COS

          INTR_CTLZ

          INTR_CTPOP

          INTR_CTTZ

          INTR_DBG_DECLARE

          INTR_DBG_FUNC_START

          INTR_DBG_REGION_END

          INTR_DBG_REGION_START

          INTR_DBG_STOPPOINT

          INTR_EH_DWARF_CFA

          INTR_EH_EXCEPTION

          INTR_EH_RETURN_I32

          INTR_EH_RETURN_I64

          INTR_EH_SELECTOR_I32

          INTR_EH_SELECTOR_I64

          INTR_EH_SJLJ_LONGJMP

          INTR_EH_SJLJ_LSDA

          INTR_EH_SJLJ_SETJMP

          INTR_EH_TYPEID_FOR_I32

          INTR_EH_TYPEID_FOR_I64

          INTR_EH_UNWIND_INIT

          INTR_EXP

          INTR_EXP2

          INTR_FLT_ROUNDS

          INTR_FRAMEADDRESS

          INTR_GCREAD

          INTR_GCROOT

          INTR_GCWRITE

          INTR_INIT_TRAMPOLINE

          INTR_LOG

          INTR_LOG10

          INTR_LOG2

          INTR_LONGJMP

          INTR_MEMCPY

          INTR_MEMMOVE

          INTR_MEMORY_BARRIER

          INTR_MEMSET

          INTR_PCMARKER

          INTR_POW

          INTR_POWI

          INTR_PREFETCH

          INTR_PTR_ANNOTATION

          INTR_READCYCLECOUNTER

          INTR_RETURNADDRESS

          INTR_SADD_WITH_OVERFLOW

          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 -target's CPU instructions) available, but are omitted here for brevity. +

          There are also target-specific intrinsics (which correspond to that +target’s CPU instructions) available, but are omitted here for brevity. Full list can be seen from -core.py. +_intrinsic_ids.py. See the LLVM Language Reference for more information on the intrinsics, and the test directory in the source distribution for more examples. The intrinsic ID can be retrieved from a function object with the read-only property intrinsic_id.

          -

          The function's calling convention can be set using the +

          The function’s calling convention can be set using the calling_convention property. The following (integer) constants defined in llvm.core can be used as values:

          @@ -3266,16 +2542,16 @@ cellspacing="0" cellpadding="4">
          -

          See the LLVM docs for +

          See the LLVM docs for more information on each. Backend-specific numbered conventions can be -directly set as numbers.

          -

          An arbitrary string identifying which garbage collector to use can be +directly passed as integers.

          +

          An arbitrary string identifying which garbage collector to use can be set or got with the property collector.

          -

          The value objects corresponding to the arguments of a function can be +

          The value objects corresponding to the arguments of a function can be got using the read-only property args. These can be iterated over, and also be indexed via integers. An example:

          -
          @@ -3284,9 +2560,8 @@ http://www.gnu.org/software/src-highlite --> print arg.name, "of type", arg.type # change the name of the first argument -fn.args[0].name = "objptr" -
          -

          Basic blocks (see later) are contained within functions. When newly +fn.args[0].name = "objptr"

          +

          Basic blocks (see later) are contained within functions. When newly created, a function has no basic blocks. They have to be added explicitly, using the append_basic_block method, which adds a new, empty basic block as the last one in the function. The first basic block @@ -3297,7 +2572,7 @@ can be got via basic_block_count method. Note that get_entry_basic_block is slightly faster than basic_blocks[0] and so is basic_block_count, over len(f.basic_blocks).

          -
          @@ -3314,19 +2589,19 @@ b2 = fn. # get number of basic blocks n = fn.basic_block_count -n = len(fn.basic_blocks) # slower than previous method -
          -

          Functions can be deleted using the method delete. This deletes them +n = len(fn.basic_blocks) # slower than previous method

          +

          Functions can be deleted using the method delete. This deletes them from their containing module. All references to the function object 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.

          +

          TODO function attributes

          Argument (llvm.core)

          -

          The args property of llvm.core.Function objects yields +

          The args property of llvm.core.Function objects yields llvm.core.Argument objects. This allows for setting attributes for functions arguments. Argument objects cannot be constructed from user code, the only way to get a reference to these are via functions.

          -

          The method add_attribute and remove_attribute can be used to add or +

          The method add_attribute and remove_attribute can be used to add or remove the following attributes:

          -

          The corresponding +

          The corresponding LLVM docs provide more information.

          -

          The alignment of any parameter can also be set via set_argument(a) +

          The alignment of any parameter can also be set via set_argument(a) where a is a power of 2.

          Basic Block (llvm.core)

          -

          TODO

          +

          TODO

          Builder (llvm.core)

          -

          TODO

          +

          TODO

          Instructions (llvm.core)

          -

          TODO

          +

          TODO

          Module Provider (llvm.core)

          -

          TODO

          +

          TODO

          Target Data (llvm.ee)

          -

          TODO

          +

          TODO

          Execution Engine (llvm.ee)

          -

          TODO. For now, see test/example-jit.py.

          +

          TODO. For now, see test/example-jit.py.

          Pass Managers and Passes (llvm.passes)

          -

          TODO. For now, see test/passes.py.

          +

          TODO. For now, see test/passes.py.

          About the llvm-py Project

          -

          llvm-py lives at +

          llvm-py lives at http://mdevan.nfshost.com/llvm-py/. The code (subversion repository) and the issue tracker are hosted on the Google code hosting service, at @@ -3467,20 +2742,22 @@ It is distributed under the new BSD license, the full license text is in the file named LICENSE available in the source distribution.

          -

          The entire llvm-py website is generated from marked up text files +

          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 using the tool AsciiDoc. These text files and the (pre-)generated HTML pages are available in the source distribution.

          -

          llvm-py is an ongoing, live project. Your contributions in any form +

          llvm-py is an ongoing, live project. Your contributions in any form are most welcome. You can checkout the latest SVN HEAD from here.

          -

          Mahadevan R wrote llvm-py and works on it in his spare time. He can be +

          Mahadevan R wrote llvm-py and works on it in his spare time. He can be reached at mdevan.foobar@gmail.com.