Execution engine and passes work. Documentation and tests updated.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@4 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-06-07 13:44:25 +00:00
commit 2255a7e5dd
15 changed files with 559 additions and 396 deletions

View file

@ -4,12 +4,13 @@ About
[NOTE]
._llvm-py_ Mission Statement
=======================================================================
Provide a simple, consistent and well-documented suite of APIs
that exposes just enough of LLVM to write a compiler/interpreter/VM
in Python.
Provide a simple, consistent and well-documented suite of APIs that
exposes just enough of LLVM to write a compiler/VM in Python.
=======================================================================
_llvm-py_ is developed by Mahadevan R, in his spare time, without being
paid for it. He can be reached at _mdevan.foobar .at. gmail.com_, on the
llvm-dev mailing list and irc.oftc.net#llvm (mdevan).
These web pages were generated using the nifty tool
http://www.methods.co.nz/asciidoc/[asciidoc].

View file

@ -6,9 +6,8 @@ grow up. Please contribute! All patches are welcome.
The _llvm-py_ code is hosted on a google code project by the same name,
http://code.google.com/p/llvm-py/[here]. It provides the SVN repository
and a http://code.google.com/p/llvm-py/issues/list[bug tracker].
The latest code can be checked out from SVN like so:
and a http://code.google.com/p/llvm-py/issues/list[bug tracker]. The
latest code can be checked out from SVN like so:
----
$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py

View file

@ -1,7 +1,7 @@
Download and Setup
==================
The latest release is 0.2, released xx-Jun-2008 (full link:changelog[Changelog]
The latest release is 0.2, released xx-Jun-2008 (full link:#changelog[Changelog]
below).
Download it here:
@ -10,8 +10,8 @@ Download it here:
````~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Release,Date,Package,Mirror
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.2,xx-xxx-2008,http://link1/[llvm-py-0.2.tar.bz2],http://link1/[llvm-py-0.2.tar.bz2]
0.1,xx-xxx-2008,http://link1/[llvm-py-0.1.tar.bz2],http://link1/[llvm-py-0.1.tar.bz2]
0.2,xx-May-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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -32,6 +32,7 @@ Setting Up
Follow these steps to get _llvm-py_ up and running:
* link:#uninstall[Uninstall] any previous version of _llvm-py_.
* Get and build LLVM.
* Optionally, install it.
* Get the latest release (see above) of _llvm-py_ and untar it:
@ -54,11 +55,28 @@ $ sudo python setup.py install --llvm-config=/path/to/llvm-config
That's it!
NOTE: _setup.py_ is a standard Python distutils script. See the Python
documentation regarding http://docs.python.org/inst/inst.html[Installing
Python Modules] and http://docs.python.org/dist/dist.html[Distributing
Python Modules] for more information on such scripts.
.Notes:
- _setup.py_ is a standard Python distutils script. See the Python
documentation regarding
http://docs.python.org/inst/inst.html[Installing Python Modules] and
http://docs.python.org/dist/dist.html[Distributing Python Modules] for
more information on such scripts.
- To build the debug version, build with the +-g+ flag and the debug
version of llvm-config:
+
----
$ python setup.py build -g --llvm-config=/path/to/Debug/bin/llvm-config
$ sudo python setup.py install
----
- Debug binaries are _huge_! (65 MB+)
- If +++--llvm-config+++ is not specified, +setup.py+ looks for
+llvm-config+ in the +PATH+, which will succeed if LLVM is installed.
[[uninstall]]
Uninstall
---------
@ -69,8 +87,9 @@ To get rid of llvm-py completely, if you wish to do so:
# rm -f /usr/lib/python2.5/site-packages/llvm_py-0.1.egg-info
----
You'll need to be root to do this. Paths are for debian-based systems,
in other distros it might be different.
- You need to be root to do this.
- Paths are for debian-based systems, in other distros it might be different.
- Note that there is a version number in the egg file name.
[[changelog]]
@ -78,5 +97,5 @@ Changelog
----------
----
include::changelog[]
include::../../CHANGELOG[]
----

View file

@ -5,49 +5,7 @@ Here's an example:
[python]
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env python
from llvm.core import *
## create a module
module = Module.new("my_module")
## create a function type taking two doubles and returning a (32-bit) integer
ty_double = Type.double()
ty_int = Type.int()
ty_func = Type.function( ty_int, [ ty_double, ty_double ] )
## create a function of this type
func = Function.new( module, ty_func, "foobar" )
# name function args
func.args[0].name = "arg1"
func.args[1].name = "arg2"
## implement the function
# add a basic block
entry = func.append_basic_block("entry")
# create an llvm::IRBuilder
builder = Builder.new()
builder.position_at_end(entry)
# add two args into temp1
temp1 = builder.add(func.args[0], func.args[1], "temp1")
# sub `1' from that
one = Constant.real( ty_double, 1.0 )
temp2 = builder.sub(temp1, one, "temp2")
# convert to integer
temp3 = builder.fptoui(temp2, ty_int, "temp3")
# return it
builder.ret(temp3)
# dump the module to see the bc
module.dump()
include::../../test/example.py[]
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
which gives this output: