Added test/example for passes. Updated documentation.
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@36 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
c10b1b58c3
commit
8eb5532b3a
13 changed files with 335 additions and 175 deletions
|
|
@ -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.
|
||||
|
|
|
|||
78
test/passes.py
Normal file
78
test/passes.py
Normal file
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@
|
|||
</div>
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<p>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).</p>
|
||||
<p>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).</p>
|
||||
<p>Many thanks to the guys over at LLVM for all the nifty software.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 31-Jul-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -33,98 +33,65 @@
|
|||
</div>
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<p>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:</p>
|
||||
<div class="tableblock">
|
||||
<table rules="none"
|
||||
frame="hsides"
|
||||
cellspacing="0" cellpadding="4">
|
||||
<col width="600" />
|
||||
<col width="200" />
|
||||
<tbody valign="top">
|
||||
<tr>
|
||||
<td align="left">
|
||||
Google code hosting
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://code.google.com/p/llvm-py/">http://code.google.com/p/llvm-py/</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Browse SVN
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://code.google.com/p/llvm-py/source/browse/">http://code.google.com/p/llvm-py/source/browse</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Issues tracker
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://code.google.com/p/llvm-py/issues/list">http://code.google.com/p/llvm-py/issues/list</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>You can make a difference, just by:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
getting llvm-py to work on an as-yet-untested platform
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
adding support for more LLVM features into llvm-py
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
sending in patches for bugs you come across
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
improving the test scripts and documentation
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
spreading the word
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>Useful links:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
Google code hosting: <a href="http://code.google.com/p/llvm-py/">http://code.google.com/p/llvm-py/</a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Browse SVN: <a href="http://code.google.com/p/llvm-py/source/browse/">http://code.google.com/p/llvm-py/source/browse</a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Issues tracker: <a href="http://code.google.com/p/llvm-py/issues/list">http://code.google.com/p/llvm-py/issues/list</a>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>SVN HEAD can be checked out like so:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py</tt></pre>
|
||||
<pre><tt>$ svn co http://llvm-py.googlecode.com/svn/trunk/ llvm-py</tt></pre>
|
||||
</div></div>
|
||||
<p>Mahadevan R (mdevan.foobar@gmail.com) is available to answer your
|
||||
queries.</p>
|
||||
<p>Usual caveats apply: cutting edge, may be broken (but usually not),
|
||||
update and merge before sending patches etc.</p>
|
||||
</div>
|
||||
</div>
|
||||
<h2>Current Next Steps</h2>
|
||||
<div class="sectionbody">
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
Wrap GenericValue, function call args for execution engine.
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
done.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Add APIs to read/write <tt>.bc</tt> and <tt>.ll</tt> files.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Wrap <tt>lto</tt>.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Add examples.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Update documentation.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Improve tests.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 31-Jul-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
</div>
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<p>The latest release is 0.2.1, released 18-Jun-2008 (<a href="#changelog">Changelog</a>
|
||||
<p>The latest release is 0.3, released 8-Sep-2008 (<a href="#changelog">Changelog</a>
|
||||
below).</p>
|
||||
<p>Download it here:</p>
|
||||
<div class="tableblock">
|
||||
|
|
@ -61,6 +61,20 @@ cellspacing="0" cellpadding="4">
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr>
|
||||
<td align="left">
|
||||
0.3
|
||||
</td>
|
||||
<td align="left">
|
||||
8-Sep-2008
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://llvm-py.googlecode.com/files/llvm-py-0.3.tar.bz2">llvm-py-0.3.tar.bz2</a>
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="llvm-py-0.3.tar.bz2">llvm-py-0.3.tar.bz2</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
0.2.1
|
||||
|
|
@ -119,8 +133,12 @@ package.</p>
|
|||
<div class="sectionbody">
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>0.3, in progress:
|
||||
<pre><tt>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.</p>
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 31-Jul-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ Conclusion and other useful LLVM tidbits (TODO)
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 31-Jul-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -40,19 +40,28 @@ 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.</p>
|
||||
<p>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.</p>
|
||||
away, though. Be sure to send in a patch if you miss any specific LLVM
|
||||
API.</p>
|
||||
<p><em>Availability</em>: 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.</p>
|
||||
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.</p>
|
||||
<p><em>LLVM 2.4</em>: Read <a href="userguide.html#llvm24">this</a> if you're using LLVM
|
||||
2.4!</p>
|
||||
</div>
|
||||
</div>
|
||||
<h2>News</h2>
|
||||
<div class="sectionbody">
|
||||
<dl>
|
||||
<dt>
|
||||
8-Sep-2008
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
0.3 released. Passes, intrinsics, bitcode, assembly!
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
18-Jun-2008
|
||||
</dt>
|
||||
<dd>
|
||||
|
|
@ -81,7 +90,7 @@ minimal changes, if any.</p>
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 31-Jul-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 31-Jul-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ and OpenBSD (i386, amd64). However, it should be trivial to build it on
|
|||
other unices. Windows is not supported, for a variety of reasons.</p>
|
||||
<div class="title">Versions</div>
|
||||
<p>llvm-py requires verion 2.3 of LLVM. It will not work with previous
|
||||
versions.</p>
|
||||
versions. If you're using LLVM 2.4, see <a href="#llvm24">below</a>.</p>
|
||||
<p>llvm-py has been built and tested with Python 2.5. It should work with
|
||||
Python 2.4, with minimal changes, if any.</p>
|
||||
</div>
|
||||
|
|
@ -140,32 +140,67 @@ installed, it is recommended to remove it first, as described
|
|||
llvm-py this way:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>$ tar jxvf llvm-py-0.2.tar.bz2
|
||||
$ cd llvm-py-0.2
|
||||
<pre><tt>$ tar jxvf llvm-py-0.3.tar.bz2
|
||||
$ cd llvm-py-0.3
|
||||
$ sudo python setup.py install</tt></pre>
|
||||
</div></div>
|
||||
<p>If you need to tell the build script where <tt>llvm-config</tt> is, do it this
|
||||
way:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>$ tar jxvf llvm-py-0.2.tar.bz2
|
||||
$ cd llvm-py-0.2
|
||||
<pre><tt>$ 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</tt></pre>
|
||||
</div></div>
|
||||
<p>To build a debug version of llvm-py, that links against the debug
|
||||
libraries of LLVM, use this:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>$ tar jxvf llvm-py-0.2.tar.bz2
|
||||
$ cd llvm-py-0.2
|
||||
<pre><tt>$ 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</tt></pre>
|
||||
</div></div>
|
||||
<p>Be warned that debug binaries will be huge (100MB+) !</p>
|
||||
<p>Be warned that debug binaries will be huge (100MB+) ! They are required
|
||||
only if you need to debug into LLVM also.</p>
|
||||
<p><tt>setup.py</tt> is a standard Python distutils script. See the Python
|
||||
documentation regarding <a href="http://docs.python.org/inst/inst.html">Installing
|
||||
Python Modules</a> and <a href="http://docs.python.org/dist/dist.html">Distributing
|
||||
Python Modules</a> for more information on such scripts.</p>
|
||||
<h3><a id="llvm24"></a>LLVM 2.4</h3>
|
||||
<p>LLVM 2.4 is currently in progress. There are incompatible API changes
|
||||
from LLVM 2.3. The latest release of llvm-py will <em>not</em> compile against
|
||||
it.</p>
|
||||
<p>The llvm-py SVN has a branch called
|
||||
<a href="http://code.google.com/p/llvm-py/source/browse/#svn/branches/llvm2.4">llvm2.4</a>,
|
||||
which attempts to track the changes happening in LLVM 2.4. There are
|
||||
however, some caveats:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>
|
||||
There are no releases from this branch.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>llvm-py can be checked out from this branch like this:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>$ svn co http://llvm-py.googlecode.com/svn/branches/llvm2.4 llvm-py-2.4</tt></pre>
|
||||
</div></div>
|
||||
<p>The rest of the steps (build, install) remain the same as before.</p>
|
||||
<h3><a id="uninstall"></a>Uninstall</h3>
|
||||
<p>To get rid of llvm-py completely, if you wish to do so:</p>
|
||||
<div class="listingblock">
|
||||
|
|
@ -791,6 +826,21 @@ http://www.gnu.org/software/src-highlite -->
|
|||
bcfile <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">file</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"test.bc"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"w"</span><span style="color: #990000">)</span>
|
||||
my<span style="color: #009900">_</span>module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">to_bitcode</span></span><span style="color: #990000">(</span>bcfile<span style="color: #990000">)</span>
|
||||
</tt></pre></div></div>
|
||||
<p>Modules can also be constructed from LLVM assembly files (<tt>.ll</tt> files).
|
||||
The static method <tt>from_assembly</tt> can be used for this. Similar to the
|
||||
<tt>from_bitcode</tt> method, this one also takes a file-like object as
|
||||
argument:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content"><!-- Generator: GNU source-highlight 2.4
|
||||
by Lorenzo Bettini
|
||||
http://www.lorenzobettini.it
|
||||
http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># create a module from an assembly file</span></span>
|
||||
llfile <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">file</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"test.ll"</span><span style="color: #990000">)</span>
|
||||
my<span style="color: #009900">_</span>module <span style="color: #990000">=</span> <span style="color: #009900">Module</span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">from_assembly</span></span><span style="color: #990000">(</span>llfile<span style="color: #990000">)</span>
|
||||
</tt></pre></div></div>
|
||||
<p>Modules can be converted into their assembly representation by
|
||||
stringifying them (see below).</p>
|
||||
<div class="exampleblock">
|
||||
<div class="title">llvm.core.Module</div>
|
||||
<div class="exampleblock-content">
|
||||
|
|
@ -813,6 +863,15 @@ my<span style="color: #009900">_</span>module<span style="color: #990000">.</spa
|
|||
represented by the file-like object <tt>fileobj</tt>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>from_assembly(fileobj)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Create a new <tt>Module</tt> instance by parsing the LLVM assembly file
|
||||
represented by the file-like object <tt>fileobj</tt>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="title">Properties</div><dl>
|
||||
<dt>
|
||||
|
|
@ -3401,40 +3460,24 @@ cellspacing="0" cellpadding="4">
|
|||
</table>
|
||||
</div>
|
||||
<p>The corresponding
|
||||
<a href="file:///home/mdevan/llvm-2.3/docs/LangRef.html#paramattrs">LLVM docs</a>
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#paramattrs">LLVM docs</a>
|
||||
provide more information.</p>
|
||||
<p>The alignment of any parameter can also be set via <tt>set_argument(a)</tt>
|
||||
where <tt>a</tt> is a power of 2.</p>
|
||||
<h3>Basic Block (llvm.core)</h3>
|
||||
<p>The class <tt>llvm.core.BasicBlock</tt> represents a basic block of
|
||||
instructions. Basic blocks are logically contained within functions, and
|
||||
can be constructed only via <tt>Function</tt> objects. Use the
|
||||
<tt>Function.append_basic_block()</tt> method for this:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content"><!-- Generator: GNU source-highlight 2.4
|
||||
by Lorenzo Bettini
|
||||
http://www.lorenzobettini.it
|
||||
http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># create a function</span></span>
|
||||
func <span style="color: #990000">=</span> module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_function</span></span><span style="color: #990000">(</span>functy<span style="color: #990000">,</span> <span style="color: #FF0000">"fn"</span><span style="color: #990000">)</span>
|
||||
<span style="font-style: italic"><span style="color: #9A1900"># add a basic block, named 'entry', to the function</span></span>
|
||||
bblk <span style="color: #990000">=</span> func<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append_basic_block</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"entry"</span><span style="color: #990000">)</span>
|
||||
</tt></pre></div></div>
|
||||
<p>The list of all</p>
|
||||
<p>TODO</p>
|
||||
<h3>Builder (llvm.core)</h3>
|
||||
<p>TODO</p>
|
||||
<h3>Instructions (llvm.core)</h3>
|
||||
<p>The class <tt>llvm.core.Instruction</tt> represents an LLVM IR instruction.
|
||||
Instruction objects can be created only via a builder.</p>
|
||||
<p>TODO</p>
|
||||
<h3>Module Provider (llvm.core)</h3>
|
||||
<p>TODO</p>
|
||||
<h3>Target Data (llvm.ee)</h3>
|
||||
<p>TODO</p>
|
||||
<h3>Execution Engine (llvm.ee)</h3>
|
||||
<p>TODO</p>
|
||||
<p>TODO. For now, see <tt>test/example-jit.py</tt>.</p>
|
||||
<h3>Pass Managers and Passes (llvm.passes)</h3>
|
||||
<p>TODO</p>
|
||||
<p>TODO. For now, see <tt>test/passes.py</tt>.</p>
|
||||
</div>
|
||||
<h2>About the llvm-py Project</h2>
|
||||
<div class="sectionbody">
|
||||
|
|
@ -3460,7 +3503,7 @@ reached at <em>mdevan.foobar@gmail.com</em>.</p>
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 15-Aug-2008.
|
||||
Last updated 08-Sep-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue