Patch for OpenBSD, x86_64 support (Laurence Tratt)
Added JIT tutorial ports (Sebastien Binet) Updated documentation git-svn-id: http://llvm-py.googlecode.com/svn/trunk@23 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
fe03572bba
commit
df4365921d
20 changed files with 501 additions and 74 deletions
|
|
@ -2,8 +2,8 @@
|
|||
A Simple Function
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Let's create a module containing a single function, corresponding to the
|
||||
`C` function:
|
||||
Let's create a (LLVM) module containing a single function, corresponding
|
||||
to the `C` function:
|
||||
|
||||
[C]
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -23,7 +23,7 @@ source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|||
from llvm import *
|
||||
from llvm.core import *
|
||||
|
||||
# Create a module.
|
||||
# Create an (empty) module.
|
||||
my_module = Module.new('my_module')
|
||||
|
||||
# All the types involved here are "int"s. This type is represented
|
||||
|
|
@ -128,5 +128,3 @@ And here's the output:
|
|||
returned 142
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
That was easy, right?!
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,35 @@
|
|||
Examples and LLVM Tutorials
|
||||
===========================
|
||||
|
||||
Examples
|
||||
========
|
||||
--------
|
||||
|
||||
include::example.inc[]
|
||||
|
||||
LLVM Tutorials
|
||||
--------------
|
||||
|
||||
The http://www.llvm.org/docs/tutorial/[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!)
|
||||
|
||||
1. A First Function
|
||||
http://www.llvm.org/docs/tutorial/JITTutorial1.html[LLVM]
|
||||
link:examples/JITTutorial1.py[llvm-py]
|
||||
2. A More Complicated Function
|
||||
http://www.llvm.org/docs/tutorial/JITTutorial2.html[LLVM]
|
||||
link:examples/JITTutorial2.py[llvm-py]
|
||||
|
||||
|
||||
.Kaleidoscope: Implementing a Language with LLVM
|
||||
1. Tutorial Introduction and the Lexer (TODO)
|
||||
2. Implementing a Parser and AST (TODO)
|
||||
3. Implementing Code Generation to LLVM IR (TODO)
|
||||
4. Adding JIT and Optimizer Support (TODO)
|
||||
5. Extending the language: control flow (TODO)
|
||||
6. Extending the language: user-defined operators (TODO)
|
||||
7. Extending the language: mutable variables / SSA construction (TODO)
|
||||
8. Conclusion and other useful LLVM tidbits (TODO)
|
||||
|
|
|
|||
1
www/src/examples/JITTutorial1.py
Symbolic link
1
www/src/examples/JITTutorial1.py
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../test/JITTutorial1.py
|
||||
1
www/src/examples/JITTutorial2.py
Symbolic link
1
www/src/examples/JITTutorial2.py
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../test/JITTutorial2.py
|
||||
|
|
@ -3,15 +3,20 @@ llvm-py: Python Bindings for LLVM
|
|||
|
||||
llvm-py provides http://www.python.org/[Python] bindings for
|
||||
http://llvm.org/[LLVM]. It's goal is to expose enough of LLVM APIs to
|
||||
implement a compiler backend or a VM in pure Python. Currently, llvm-py is
|
||||
available for LLVM 2.3 and Python 2.5, on Linux/x86. It is expected to
|
||||
be usable on various unices, as well as with Python 2.4, with minimal
|
||||
changes, if any.
|
||||
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 (or shout at the author) 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 builds on Linux, OpenBSD on i386 and x86-64/amd64.
|
||||
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.
|
||||
|
||||
News
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ llvm-py User Guide
|
|||
=======================================================================
|
||||
This document is updated frequently (last updated on {localdate}).
|
||||
Check back often.
|
||||
|
||||
You might wish to look over the link:#examples[examples] first.
|
||||
=======================================================================
|
||||
|
||||
|
||||
|
|
@ -1038,7 +1036,54 @@ methods.
|
|||
TypeHandle (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
TODO
|
||||
TypeHandle objects are used to create recursive types, like this linked
|
||||
list node structure in C:
|
||||
|
||||
[C]
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
struct node
|
||||
{
|
||||
int data;
|
||||
struct node *next;
|
||||
};
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This can be realized in llvm-py like this:
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
include::../../test/typehandle.py[]
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
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
|
||||
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
|
||||
http://code.google.com/p/llvm-py/source/browse/trunk/test/typehandle.py[test/typehandle.py]
|
||||
in the source distribution.
|
||||
|
||||
.llvm.core.TypeHandle
|
||||
[caption=""]
|
||||
=======================================================================
|
||||
.Static Constructors
|
||||
`new(abstract_ty)`::
|
||||
create a new `TypeHandle` instance, which holds a reference to the
|
||||
given abstract type `abstract_ty`. Typically, the abstract type used
|
||||
is `Type.opaque()`.
|
||||
|
||||
.Properties
|
||||
`type`::
|
||||
returns the contained type. Typically the `refine` method is called
|
||||
on the returned type.
|
||||
=======================================================================
|
||||
|
||||
|
||||
Instructions (llvm.core)
|
||||
|
|
@ -1095,17 +1140,17 @@ About the llvm-py Project
|
|||
|
||||
llvm-py lives at
|
||||
http://mdevan.nfshost.com/llvm-py/[http://mdevan.nfshost.com/llvm-py/].
|
||||
The code (subversion repository) and the issue tracker are hosted on google
|
||||
code, at
|
||||
The code (subversion repository) and the issue tracker are hosted on the
|
||||
Google code hosting service, at
|
||||
http://code.google.com/p/llvm-py/[http://code.google.com/p/llvm-py/].
|
||||
llvm-py is distributed under the new BSD license, the full license
|
||||
text is in the file named
|
||||
It is distributed under the new BSD license, the full license text is in
|
||||
the file named
|
||||
http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE[LICENSE]
|
||||
available in the source distribution.
|
||||
|
||||
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 generated HTML pages are available in the source
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue