Update llvm-py to llvmpy and fix more docs

This commit is contained in:
Travis E. Oliphant 2012-08-09 01:16:36 -05:00
commit 75ca0289b5
11 changed files with 49 additions and 56 deletions

View file

@ -23,7 +23,7 @@ Here's how it looks like:
{% highlight python %} #!/usr/bin/env python {% highlight python %} #!/usr/bin/env python
Import the llvm-py modules. Import the llvmpy modules.
=========================== ===========================
from llvm import \* from llvm.core import \* from llvm import \* from llvm.core import \*
@ -55,7 +55,7 @@ ty\_func = Type.function(ty\_int, [ty\_int, ty\_int])
Now we need a function named 'sum' of this type. Functions are not 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. free-standing (in llvmpy); 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")
@ -118,7 +118,7 @@ Let's compile this function in-memory and run it.
{% highlight python %} #!/usr/bin/env python {% highlight python %} #!/usr/bin/env python
Import the llvm-py modules. Import the llvmpy modules.
=========================== ===========================
from llvm import \* from llvm.core import \* from llvm.ee import \* # from llvm import \* from llvm.core import \* from llvm.ee import \* #
@ -183,7 +183,7 @@ Kaleidoscope ## {#kaleidoscope}
Implementing a Language with LLVM Implementing a Language with LLVM
The LLVM `Kaleidoscope <http://www.llvm.org/docs/tutorial/>`_ tutorial The LLVM `Kaleidoscope <http://www.llvm.org/docs/tutorial/>`_ tutorial
has been ported to llvm-py by Max Shawabkeh. has been ported to llvmpy by Max Shawabkeh.
1. `Tutorial Introduction and the 1. `Tutorial Introduction and the
Lexer <kaleidoscope/PythonLangImpl1.html>`_ Lexer <kaleidoscope/PythonLangImpl1.html>`_

View file

@ -72,11 +72,11 @@ constants in ``llvm.core``. These are:
There are also target-specific intrinsics (which correspond to that There are also target-specific intrinsics (which correspond to that
target's CPU instructions) available, but are omitted here for brevity. target's CPU instructions) available, but are omitted here for brevity.
Full list can be seen from Full list can be seen from
[*intrinsic\_ids.py](https://github.com/numba/llvm-py/blob/master/llvm/*\ intrinsic\_ids.py). [*intrinsic\_ids.py](https://github.com/numba/llvmpy/blob/master/llvm/*\ intrinsic\_ids.py).
See the `LLVM Language See the `LLVM Language
Reference <http://www.llvm.org/docs/LangRef.html>`_ for more information Reference <http://www.llvm.org/docs/LangRef.html>`_ for more information
on the intrinsics, and the on the intrinsics, and the
`test <https://github.com/numba/llvm-py/blob/master/test/intrinsic.py>`_ `test <https://github.com/numba/llvmpy/blob/master/test/intrinsic.py>`_
directory in the source distribution for more examples. The intrinsic ID directory in the source distribution for more examples. The intrinsic ID
can be retrieved from a function object with the read-only property can be retrieved from a function object with the read-only property
``intrinsic_id``. ``intrinsic_id``.
@ -84,7 +84,7 @@ can be retrieved from a function object with the read-only property
**Auto-generation of Intrinsic IDs** **Auto-generation of Intrinsic IDs**
A script (tool/intrgen.py in source tree) generates the intrinsic A script (tool/intrgen.py in source tree) generates the intrinsic
IDs automatically. This is necessary when compiling llvm-py with a IDs automatically. This is necessary when compiling llvmpy with a
different version of LLVM. different version of LLVM.
Calling Convention # {#callconv} Calling Convention # {#callconv}

View file

@ -29,12 +29,12 @@ will teach you a little bit about how LLVM does things, as well as
demonstrate how easy it is to use. It's much more work to build a lexer demonstrate how easy it is to use. It's much more work to build a lexer
and parser than it is to generate LLVM IR code. :) and parser than it is to generate LLVM IR code. :)
**Please note**: the code in this chapter and later requires llvm-py 0.6 **Please note**: the code in this chapter and later requires llvmpy 0.6
and LLVM 2.7. Earlier versions will most likely not work with it. Also and LLVM 2.7. Earlier versions will most likely not work with it. Also
note that you need to use a version of this tutorial that matches your note that you need to use a version of this tutorial that matches your
llvm-py release: If you are using an official llvm-py release, use the llvmpy release: If you are using an official llvm-py release, use the
version of the documentation on the `llvm-py examples version of the documentation on the `llvmpy examples
page <http://www.mdevan.org/llvm-py/examples.html>`_ page <http://www.mdevan.org/llvmpy/examples.html>`_
-------------- --------------
@ -128,7 +128,7 @@ First we'll do numeric literals:
{% highlight python %} def CodeGen(self): return {% highlight python %} def CodeGen(self): return
Constant.real(Type.double(), self.value) {% endhighlight %} Constant.real(Type.double(), self.value) {% endhighlight %}
In llvm-py, floating point numeric constants are represented with the In llvmpy, floating point numeric constants are represented with the
``llvm.core.ConstantFP`` class. To create one, we can use the static ``llvm.core.ConstantFP`` class. To create one, we can use the static
``real()`` method in the ``llvm.core.Constant`` class. This code ``real()`` method in the ``llvm.core.Constant`` class. This code
basically just creates and returns a ``ConstantFP``. Note that in the basically just creates and returns a ``ConstantFP``. Note that in the
@ -514,7 +514,7 @@ Full Code Listing # {#code}
=========================== ===========================
Here is the complete code listing for our running example, enhanced with Here is the complete code listing for our running example, enhanced with
the LLVM code generator. Because this uses the llvm-py libraries, you the LLVM code generator. Because this uses the llvmpy libraries, you
need to `download <../download.html>`_ and need to `download <../download.html>`_ and
`install <../userguide.html#install>`_ them. `install <../userguide.html#install>`_ them.

View file

@ -329,7 +329,7 @@ Now we can load this library into the Python process using
to produce simple output to the console: to produce simple output to the console:
{% highlight python %} >>> import llvm.core >>> {% highlight python %} >>> import llvm.core >>>
llvm.core.load\_library\_permanently('/home/max/llvm-py-tutorial/putchard.so') llvm.core.load\_library\_permanently('/home/max/llvmpy-tutorial/putchard.so')
>>> import kaleidoscope >>> kaleidoscope.main() ready> extern >>> import kaleidoscope >>> kaleidoscope.main() ready> extern
putchard(x) Read an extern: declare double @putchard(double) putchard(x) Read an extern: declare double @putchard(double)

View file

@ -27,7 +27,7 @@ using ``operands`` property from the
The name of the instruction (like ``add``, ``mul`` etc) can be got via The name of the instruction (like ``add``, ``mul`` etc) can be got via
the ``opcode_name`` property. The ``basic_block`` property gives the the ``opcode_name`` property. The ``basic_block`` property gives the
basic block to which the instruction belongs to. Note that llvm-py does basic block to which the instruction belongs to. Note that llvmpy does
not allow free-standing instruction objects (i.e., all instructions are not allow free-standing instruction objects (i.e., all instructions are
created contained within a basic block). created contained within a basic block).

View file

@ -18,11 +18,11 @@ create a module
my\_module = Module.new('my\_module') {% endhighlight %} my\_module = Module.new('my\_module') {% endhighlight %}
The constructor of the Module class should *not* be used to instantiate 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. a Module object. This is a common feature for all llvmpy classes.
**Convention** **Convention**
*All* llvm-py objects are instantiated using static methods of *All* llvmpy objects are instantiated using static methods of
corresponding classes. Constructors *should not* be used. corresponding classes. Constructors *should not* be used.
The argument ``my_module`` is a module identifier (a plain string). The argument ``my_module`` is a module identifier (a plain string).
@ -225,7 +225,7 @@ compares the resultant strings.
**Convention** **Convention**
*All* llvm-py objects (where it makes sense), when stringified, *All* llvmpy objects (where it makes sense), when stringified,
return the LLVM assembly representation. ``print module_obj`` for return the LLVM assembly representation. ``print module_obj`` for
example, prints the LLVM assembly form of the entire module. example, prints the LLVM assembly form of the entire module.

View file

@ -163,7 +163,7 @@ There is an LLVM binary called
`opt <http://www.llvm.org/cmds/opt.html>`_, which lets you run passes on `opt <http://www.llvm.org/cmds/opt.html>`_, which lets you run passes on
bitcode files from the command line. You can write your own passes (in 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+. 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 (Although llvmpy does not allow you to write your own passes, it does
allow you to navigate the entire IR at any stage, and perform any allow you to navigate the entire IR at any stage, and perform any
transforms on it as you like.) transforms on it as you like.)
@ -211,4 +211,4 @@ multiple modules.
-------------- --------------
**Next** -- `llvm-py Package <./llvm-py_package.html>`_ **Next** -- `llvmpy Package <./llvm-py_package.html>`_

View file

@ -1,10 +1,10 @@
+------------------------------+ +------------------------------+
| layout: page | | layout: page |
+------------------------------+ +------------------------------+
| title: The llvm-py Package | | title: The llvmpy Package |
+------------------------------+ +------------------------------+
The llvm-py is a Python package, consisting of 6 modules, that wrap over The llvmpy is a Python package, consisting of 6 modules, that wrap over
enough LLVM APIs to allow the implementation of your own compiler/VM enough LLVM APIs to allow the implementation of your own compiler/VM
backend in pure Python. If you're come this far, you probably know why backend in pure Python. If you're come this far, you probably know why
this is a good idea. this is a good idea.
@ -80,7 +80,7 @@ A note on the importing of these modules
Pythonically, modules are imported with the statement Pythonically, modules are imported with the statement
``import llvm.core``. However, you might find it more convenient to ``import llvm.core``. However, you might find it more convenient to
import llvm-py modules thus: import llvmpy modules thus:
{% highlight python %} from llvm import \* from llvm.core import \* from {% highlight python %} from llvm import \* from llvm.core import \* from
llvm.ee import \* from llvm.passes import \* {% endhighlight %} llvm.ee import \* from llvm.passes import \* {% endhighlight %}
@ -90,7 +90,7 @@ This avoids quite some typing. Both conventions work, however.
**Tip** **Tip**
Python-style documentation strings (``__doc__``) are present in Python-style documentation strings (``__doc__``) are present in
llvm-py. You can use the ``help()`` of the interactive Python llvmpy. You can use the ``help()`` of the interactive Python
interpreter or the ``object?`` of interpreter or the ``object?`` of
`IPython <http://ipython.scipy.org/moin/>`_ to get online help. `IPython <http://ipython.scipy.org/moin/>`_ to get online help.
(Note: not complete yet!) (Note: not complete yet!)

View file

@ -6,7 +6,7 @@
Types are what you think they are. A instance of Types are what you think they are. A instance of
`llvm.core.Type <llvm.core.Type.html>`_, or one of its derived classes, `llvm.core.Type <llvm.core.Type.html>`_, or one of its derived classes,
represent a type. llvm-py does not use as many classes to represent represent a type. llvmpy does not use as many classes to represent
types as does LLVM itself. Some types are represented using types as does LLVM itself. Some types are represented using
`llvm.core.Type <llvm.core.Type.html>`_ itself and the rest are `llvm.core.Type <llvm.core.Type.html>`_ itself and the rest are
represented using derived classes of represented using derived classes of

View file

@ -1,10 +1,8 @@
+---------------------+ ************
| layout: page | User Guide
+---------------------+ ************
| title: User Guide |
+---------------------+
llvm-py provides Python bindings for LLVM. This document explains how llvmpy provides Python bindings for LLVM. This document explains how
you can setup and use it. A working knowledge of Python and a basic idea you can setup and use it. A working knowledge of Python and a basic idea
of LLVM is assumed. of LLVM is assumed.
@ -26,31 +24,31 @@ Together with `clang <http://clang.llvm.org/>`_ or
means to quickly instrument C and C++ sources. For e.g., llvm-gcc can be 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 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, then be loaded and manipulated (adding profiling code to every function,
say) using a llvm-py based Python script. say) using a llvmpy based Python script.
License License
------- -------
Both LLVM and llvm-py are distributed under (different) permissive open Both LLVM and llvmpy are distributed under (different) permissive open
source licenses. llvm-py uses the `new BSD source licenses. llvmpy uses the `new BSD
license <http://opensource.org/licenses/bsd-license.php>`_. More license <http://opensource.org/licenses/bsd-license.php>`_. More
information is available information is available
`here <https://github.com/numba/llvm-py/blob/master/LICENSE>`_. `here <https://github.com/numba/llvmpy/blob/master/LICENSE>`_.
Platforms Platforms
--------- ---------
llvm-py has been built/tested/reported to work on various GNU/Linux llvmpy has been built/tested/reported to work on various GNU/Linux
flavours, BSD, Mac OS X; on i386 and amd64 architectures. Windows is not flavours, BSD, Mac OS X; on i386 and amd64 architectures. Windows is not
supported, for a variety of reasons. supported, for a variety of reasons.
Versions Versions
-------- --------
llvm-py 0.8.2 requires version 3.1 of LLVM. It may not work with llvmpy 0.8.2 requires version 3.1 of LLVM. It may not work with
previous versions. previous versions.
llvm-py has been built and tested with Python 2.7. It should work with llvmpy has been built and tested with Python 2.7. It should work with
earlier versions. It has not been tried with Python 3.x (patches earlier versions. It has not been tried with Python 3.x (patches
welcome). welcome).
@ -59,7 +57,7 @@ welcome).
Installation Installation
============ ============
The Git repo of llvm-py is at https://github.com/numba/llvm-py.git. The Git repo of llvmpy is at https://github.com/numba/llvmpy.git.
You'll need to build and install it before it can be used. At least the You'll need to build and install it before it can be used. At least the
following will be required for this: following will be required for this:
@ -73,14 +71,14 @@ command ``sudo apt-get install gcc g++ python python-dev``. Ensure that
your distro's repository has the appropriate version of LLVM! your distro's repository has the appropriate version of LLVM!
It does not matter which compiler LLVM itself was built with (``g++``, 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 ``llvm-g++`` or any other); llvmpy can be built with any compiler. It
has been tried only with gcc/g++ though. has been tried only with gcc/g++ though.
LLVM and ``--enable-pic`` LLVM and ``--enable-pic``
------------------------- -------------------------
The result of an LLVM build is a set of static libraries and object 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 files. The llvmpy contains an extension package that is built into a
shared object (\_core.so) which links to these static libraries and shared object (\_core.so) which links to these static libraries and
object files. It is therefore required that the LLVM libraries and object files. It is therefore required that the LLVM libraries and
object files be built with the ``-fPIC`` option (generate position object files be built with the ``-fPIC`` option (generate position
@ -93,14 +91,14 @@ configuring LLVM (default is no PIC), like this:
llvm-config llvm-config
----------- -----------
In order to build llvm-py, it's build script needs to know from where it In order to build llvmpy, it's build script needs to know from where it
can invoke the llvm helper program, ``llvm-config``. If you've installed can invoke the llvm helper program, ``llvm-config``. If you've installed
LLVM, then this will be available in your ``PATH``, and nothing further 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 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 ``llvm-config`` is not in your ``PATH``, you'll need to pass the full
path of ``llvm-config`` to the build script. 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 llvmpy. Remember that your ``PATH``
is different from that of 'root', so even if ``llvm-config`` is in your is different from that of 'root', so even if ``llvm-config`` is in your
``PATH``, it may not be available when you do ``sudo``. ``PATH``, it may not be available when you do ``sudo``.
@ -110,10 +108,10 @@ Steps
Get 3.1 version of LLVM, build it. Make sure '--enable-pic' is passed to Get 3.1 version of LLVM, build it. Make sure '--enable-pic' is passed to
LLVM's 'configure'. LLVM's 'configure'.
Get llvm-py and install it: Get llvmpy and install it:
{% highlight bash %} $ git clone git@github.com:numba/llvm-py.git $ cd {% highlight bash %} $ git clone git@github.com:numba/llvmpy.git $ cd
llvm-py $ python setup.py install {% endhighlight %} llvmpy $ python setup.py install {% endhighlight %}
If you need to tell the build script where ``llvm-config`` is, do it If you need to tell the build script where ``llvm-config`` is, do it
this way: this way:
@ -122,7 +120,7 @@ this way:
--llvm-config=/home/mdevan/llvm/Release/bin/llvm-config {% endhighlight --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config {% endhighlight
%} %}
To build a debug version of llvm-py, that links against the debug To build a debug version of llvmpy, that links against the debug
libraries of LLVM, use this: libraries of LLVM, use this:
{% highlight bash %} $ python setup.py build -g {% highlight bash %} $ python setup.py build -g
@ -144,7 +142,7 @@ information on such scripts.
Uninstall # {#uninstall} Uninstall # {#uninstall}
======================== ========================
If you'd installed llvm-py with the ``--user`` option, then llvm-py If you'd installed llvmpy with the ``--user`` option, then llvmpy
would be present under ``~/.local/lib/python2.7/site-packages``. would be present under ``~/.local/lib/python2.7/site-packages``.
Otherwise, it might be under ``/usr/lib/python2.7/site-packages`` or Otherwise, it might be under ``/usr/lib/python2.7/site-packages`` or
``/usr/local/lib/python2.7/site-packages``. The directory would vary ``/usr/local/lib/python2.7/site-packages``. The directory would vary

View file

@ -3,21 +3,16 @@
You can adapt this file completely to your liking, but it should at least You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive. contain the root `toctree` directive.
Documenation for llvmpy Documentation for llvmpy
================= =================
Contents: Contents:
.. toctree:: .. toctree::
:maxdepth: 2 :titlesonly:
doc/userguide.rst doc/userguide.rst
doc/llvmpy_package.rst doc/examples.rst
doc/llvm_concepts.rst
doc/types.rst
doc/examples/JITTutorial1.rst
doc/examples/JITTutorial2.rst
doc/kaleidoscope/PythonLangImpl1.rst
Indices and tables Indices and tables