$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py+
$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py
diff --git a/CHANGELOG b/CHANGELOG index 709c516..1f816e9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ -0.3, in progress: +0.3, 8-Sep-2008: + * Passes added. + * Assembly support: create modules from .ll files. * Various bug fixes. * Bitcode support: convert modules to bitcode and vice versa. * Intrinsics added. diff --git a/test/passes.py b/test/passes.py new file mode 100644 index 0000000..4184d5e --- /dev/null +++ b/test/passes.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +from llvm.core import * +from llvm.passes import * +from llvm.ee import * + +# A helper class. +class strstream(object): + def __init__(self, s): + self.s = s + def read(self): + return self.s + +# Create a module. +asm = """ + +define i32 @test() nounwind { + ret i32 42 +} + +define i32 @test1() nounwind { +entry: + %tmp = alloca i32 + store i32 42, i32* %tmp, align 4 + %tmp1 = load i32* %tmp, align 4 + %tmp2 = call i32 @test() + %tmp3 = load i32* %tmp, align 4 + %tmp4 = load i32* %tmp, align 4 + ret i32 %tmp1 +} + +define i32 @test2() nounwind { +entry: + %tmp = call i32 @test() + ret i32 %tmp +} +""" +m = Module.from_assembly(strstream(asm)) +mp = ModuleProvider.new(m) +print "-"*72 +print m + +# Let's run a module-level inlining pass. First, create a pass manager. +pm = PassManager.new() + +# Add the target data as the first "pass". This is mandatory. +pm.add( TargetData.new('') ) + +# Add the inlining pass. +pm.add( PASS_FUNCTION_INLINING ) + +# Run it! +pm.run(m) + +# Done with the pass manager. +del pm + +# Print the result. Note the change in @test2. +print "-"*72 +print m + + +# Let's run a DCE pass on the the function 'test1' now. First create a +# function pass manager. +fpm = FunctionPassManager.new(mp) + +# Add the target data as first "pass". This is mandatory. +fpm.add( TargetData.new('') ) + +# Add a DCE pass +fpm.add( PASS_AGGRESSIVE_DCE ) + +# Run the pass on the function 'test1' +fpm.run( m.get_function_named('test1') ) + +# Print the result. Note the change in @test1. +print "-"*72 +print m diff --git a/www/src/contribute.txt b/www/src/contribute.txt index a96ba84..7116850 100644 --- a/www/src/contribute.txt +++ b/www/src/contribute.txt @@ -1,23 +1,27 @@ Contribute ========== -llvm-py is just hatching. It needs your patches and suggestions to -grow up. Please contribute! All patches are welcome. Here are some links -to start hacking away: +You can make a difference, just by: -`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Google code hosting, http://code.google.com/p/llvm-py/[http://code.google.com/p/llvm-py/] -Browse SVN, http://code.google.com/p/llvm-py/source/browse/[http://code.google.com/p/llvm-py/source/browse] -Issues tracker, http://code.google.com/p/llvm-py/issues/list[http://code.google.com/p/llvm-py/issues/list] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- getting llvm-py to work on an as-yet-untested platform +- adding support for more LLVM features into llvm-py +- sending in patches for bugs you come across +- improving the test scripts and documentation +- spreading the word + + +Useful links: + +- Google code hosting: http://code.google.com/p/llvm-py/[http://code.google.com/p/llvm-py/] +- Browse SVN: http://code.google.com/p/llvm-py/source/browse/[http://code.google.com/p/llvm-py/source/browse] +- Issues tracker: http://code.google.com/p/llvm-py/issues/list[http://code.google.com/p/llvm-py/issues/list] SVN HEAD can be checked out like so: ---- -$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py +$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py ---- -Mahadevan R (mdevan.foobar@gmail.com) is available to answer your -queries. - +Usual caveats apply: cutting edge, may be broken (but usually not), +update and merge before sending patches etc. diff --git a/www/src/download.txt b/www/src/download.txt index 35302cb..e4ea610 100644 --- a/www/src/download.txt +++ b/www/src/download.txt @@ -1,7 +1,7 @@ Download ======== -The latest release is 0.2.1, released 18-Jun-2008 (link:#changelog[Changelog] +The latest release is 0.3, released 8-Sep-2008 (link:#changelog[Changelog] below). Download it here: @@ -10,6 +10,7 @@ Download it here: ````~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Release,Date,Package,Mirror ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +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] diff --git a/www/src/index.txt b/www/src/index.txt index 0bff2b3..384a571 100644 --- a/www/src/index.txt +++ b/www/src/index.txt @@ -9,18 +9,24 @@ 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 (or shout at the author) if you -miss any specific LLVM API. +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.3 -and Python 2.5. It has been built and tested on Linux/i386, and has been -reported to work with OpenBSD. It is expected to be usable on -various unices, as well as with Python 2.4 and LLVM 2.3+svn, with -minimal changes, if any. +and Python 2.5. It has been built and tested on Linux (x86, amd64) and +is reported to work with OpenBSD. It is expected to be usable on +various unices, as well as with Python 2.4. + +_LLVM 2.4_: Read link:userguide.html#llvm24[this] if you're using LLVM +2.4! + News ---- +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. diff --git a/www/src/userguide.txt b/www/src/userguide.txt index df701d9..ec9feea 100644 --- a/www/src/userguide.txt +++ b/www/src/userguide.txt @@ -32,7 +32,7 @@ other unices. Windows is not supported, for a variety of reasons. .Versions llvm-py requires verion 2.3 of LLVM. It will not work with previous -versions. +versions. If you're using LLVM 2.4, see link:#llvm24[below]. llvm-py has been built and tested with Python 2.5. It should work with Python 2.4, with minimal changes, if any. @@ -106,8 +106,8 @@ If you have +llvm-config+ in your path, you can build and install llvm-py this way: ----------------------------------------------------------------------- -$ tar jxvf llvm-py-0.2.tar.bz2 -$ cd llvm-py-0.2 +$ tar jxvf llvm-py-0.3.tar.bz2 +$ cd llvm-py-0.3 $ sudo python setup.py install ----------------------------------------------------------------------- @@ -115,8 +115,8 @@ If you need to tell the build script where +llvm-config+ is, do it this way: ----------------------------------------------------------------------- -$ tar jxvf llvm-py-0.2.tar.bz2 -$ cd llvm-py-0.2 +$ tar jxvf llvm-py-0.3.tar.bz2 +$ cd llvm-py-0.3 $ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config ----------------------------------------------------------------------- @@ -124,8 +124,8 @@ To build a debug version of llvm-py, that links against the debug libraries of LLVM, use this: ----------------------------------------------------------------------- -$ tar jxvf llvm-py-0.2.tar.bz2 -$ cd llvm-py-0.2 +$ tar jxvf llvm-py-0.3.tar.bz2 +$ cd llvm-py-0.3 $ 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 ----------------------------------------------------------------------- @@ -139,6 +139,35 @@ Python Modules] and http://docs.python.org/dist/dist.html[Distributing Python Modules] for more information on such scripts. +[[llvm24]] +LLVM 2.4 +~~~~~~~~ + +LLVM 2.4 is currently in progress. There are incompatible API changes +from LLVM 2.3. The latest release of llvm-py will _not_ compile against +it. + +The llvm-py SVN has a branch called +http://code.google.com/p/llvm-py/source/browse/#svn/branches/llvm2.4[llvm2.4], +which attempts to track the changes happening in LLVM 2.4. There are +however, some caveats: + +- There are no releases from this branch. +- When LLVM 2.4 is released, then these changes will be merged to main. + From then on llvm-py will support LLVM 2.4 and no longer LLVM 2.3. +- This branch is not religiously kept up-to-date with the changes + happening in LLVM SVN. Therefore, it may not work for you, but might + still be worth a try. + +llvm-py can be checked out from this branch like this: + +----------------------------------------------------------------------- +$ svn co http://llvm-py.googlecode.com/svn/branches/llvm2.4 llvm-py-2.4 +----------------------------------------------------------------------- + +The rest of the steps (build, install) remain the same as before. + + [[uninstall]] Uninstall ~~~~~~~~~ @@ -486,6 +515,22 @@ bcfile = file("test.bc", "w") my_module.to_bitcode(bcfile) source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +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: + +[python] +source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# create a module from an assembly file +llfile = file("test.ll") +my_module = Module.from_assembly(llfile) +source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Modules can be converted into their assembly representation by +stringifying them (see below). + + .llvm.core.Module [caption=""] ======================================================================= @@ -496,6 +541,9 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `from_bitcode(fileobj)`:: Create a new `Module` instance by deserializing the bitcode file represented by the file-like object `fileobj`. +`from_assembly(fileobj)`:: + Create a new `Module` instance by parsing the LLVM assembly file + represented by the file-like object `fileobj`. .Properties `data_layout`:: @@ -1467,7 +1515,7 @@ Value, Equivalent LLVM Assembly Keyword ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The corresponding -file:///home/mdevan/llvm-2.3/docs/LangRef.html#paramattrs[LLVM docs] +http://www.llvm.org/docs/LangRef.html#paramattrs[LLVM docs] provide more information. The alignment of any parameter can also be set via `set_argument(a)` @@ -1476,20 +1524,7 @@ where `a` is a power of 2. Basic Block (llvm.core) ~~~~~~~~~~~~~~~~~~~~~~~ -The class `llvm.core.BasicBlock` represents a basic block of -instructions. Basic blocks are logically contained within functions, and -can be constructed only via `Function` objects. Use the -`Function.append_basic_block()` method for this: - -[python] -source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# create a function -func = module.add_function(functy, "fn") -# add a basic block, named 'entry', to the function -bblk = func.append_basic_block("entry") -source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The list of all +TODO Builder (llvm.core) @@ -1501,9 +1536,6 @@ TODO Instructions (llvm.core) ~~~~~~~~~~~~~~~~~~~~~~~~ -The class `llvm.core.Instruction` represents an LLVM IR instruction. -Instruction objects can be created only via a builder. - TODO @@ -1522,13 +1554,13 @@ TODO Execution Engine (llvm.ee) ~~~~~~~~~~~~~~~~~~~~~~~~~~ -TODO +TODO. For now, see `test/example-jit.py`. Pass Managers and Passes (llvm.passes) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -TODO +TODO. For now, see `test/passes.py`. About the llvm-py Project diff --git a/www/web/about.html b/www/web/about.html index 28df233..b408ec1 100644 --- a/www/web/about.html +++ b/www/web/about.html @@ -33,16 +33,16 @@
llvm-py is developed by Mahadevan R, in his spare time, without being -paid for it. 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 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 just hatching. It needs your patches and suggestions to -grow up. Please contribute! All patches are welcome. Here are some links -to start hacking away:
-| - Google code hosting - | -- http://code.google.com/p/llvm-py/ - | -
| - Browse SVN - | -- http://code.google.com/p/llvm-py/source/browse - | -
| - Issues tracker - | -- http://code.google.com/p/llvm-py/issues/list - | -
You can make a difference, just by:
++getting llvm-py to work on an as-yet-untested platform +
++adding support for more LLVM features into llvm-py +
++sending in patches for bugs you come across +
++improving the test scripts and documentation +
++spreading the word +
+Useful links:
++Google code hosting: http://code.google.com/p/llvm-py/ +
++Browse SVN: http://code.google.com/p/llvm-py/source/browse +
++Issues tracker: http://code.google.com/p/llvm-py/issues/list +
+SVN HEAD can be checked out like so:
$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py+
$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py
Mahadevan R (mdevan.foobar@gmail.com) is available to answer your -queries.
+Usual caveats apply: cutting edge, may be broken (but usually not), +update and merge before sending patches etc.
-Wrap GenericValue, function call args for execution engine. -
--done. -
--Add APIs to read/write .bc and .ll files. -
--Wrap lto. -
--Add examples. -
--Update documentation. -
--Improve tests. -
-The latest release is 0.2.1, released 18-Jun-2008 (Changelog +
The latest release is 0.3, released 8-Sep-2008 (Changelog below).
Download it here:
0.3, in progress: +0.3, 8-Sep-2008: + * Passes added. + * Assembly support: create modules from .ll files. + * Various bug fixes. + * Bitcode support: convert modules to bitcode and vice versa. * Intrinsics added. * JIT Tutorials ported (Sebastien Binet). * GenericValue added. Used by ExecutionEngine.run(). @@ -158,7 +176,7 @@ package.
llvm-py is just hatching. It should be stable enough to start hacking -away, though. Be sure to send in a patch (or shout at the author) if you -miss any specific LLVM API.
+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.3 -and Python 2.5. It has been built and tested on Linux/i386, and has been -reported to work with OpenBSD. It is expected to be usable on -various unices, as well as with Python 2.4 and LLVM 2.3+svn, with -minimal changes, if any.
+and Python 2.5. It has been built and tested on Linux (x86, amd64) and +is reported to work with OpenBSD. It is expected to be usable on +various unices, as well as with Python 2.4. +LLVM 2.4: Read this if you're using LLVM +2.4!
+ 0.3 released. Passes, intrinsics, bitcode, assembly! +
+llvm-py requires verion 2.3 of LLVM. It will not work with previous -versions.
+versions. If you're using LLVM 2.4, see below.llvm-py has been built and tested with Python 2.5. It should work with Python 2.4, with minimal changes, if any.
@@ -140,32 +140,67 @@ installed, it is recommended to remove it first, as described llvm-py this way:$ tar jxvf llvm-py-0.2.tar.bz2 -$ cd llvm-py-0.2 +$ tar jxvf llvm-py-0.3.tar.bz2 +$ cd llvm-py-0.3 $ sudo python setup.py install
If you need to tell the build script where llvm-config is, do it this way:
$ tar jxvf llvm-py-0.2.tar.bz2 -$ cd llvm-py-0.2 +$ tar jxvf llvm-py-0.3.tar.bz2 +$ cd llvm-py-0.3 $ 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 libraries of LLVM, use this:
$ tar jxvf llvm-py-0.2.tar.bz2 -$ cd llvm-py-0.2 +$ tar jxvf llvm-py-0.3.tar.bz2 +$ cd llvm-py-0.3 $ 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+) !
+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 documentation regarding Installing Python Modules and Distributing Python Modules for more information on such scripts.
+LLVM 2.4 is currently in progress. There are incompatible API changes +from LLVM 2.3. The latest release of llvm-py will not compile against +it.
+The llvm-py SVN has a branch called +llvm2.4, +which attempts to track the changes happening in LLVM 2.4. There are +however, some caveats:
++There are no releases from this branch. +
++When LLVM 2.4 is released, then these changes will be merged to main. + From then on llvm-py will support LLVM 2.4 and no longer LLVM 2.3. +
++This branch is not religiously kept up-to-date with the changes + happening in LLVM SVN. Therefore, it may not work for you, but might + still be worth a try. +
+llvm-py can be checked out from this branch like this:
+$ svn co http://llvm-py.googlecode.com/svn/branches/llvm2.4 llvm-py-2.4+
The rest of the steps (build, install) remain the same as before.
To get rid of llvm-py completely, if you wish to do so:
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 +stringifying them (see below).
+ Create a new Module instance by parsing the LLVM assembly file + represented by the file-like object fileobj. +
+The corresponding -LLVM docs +LLVM docs provide more information.
The alignment of any parameter can also be set via set_argument(a) where a is a power of 2.
The class llvm.core.BasicBlock represents a basic block of -instructions. Basic blocks are logically contained within functions, and -can be constructed only via Function objects. Use the -Function.append_basic_block() method for this:
-# create a function -func = module.add_function(functy, "fn") -# add a basic block, named 'entry', to the function -bblk = func.append_basic_block("entry") -
The list of all
+TODO
TODO
The class llvm.core.Instruction represents an LLVM IR instruction. -Instruction objects can be created only via a builder.
TODO
TODO
TODO
TODO
+TODO. For now, see test/example-jit.py.
TODO
+TODO. For now, see test/passes.py.