module.get_X_named() methods throws if object of given name is not found.

updated docs.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@27 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-07-31 16:22:22 +00:00
commit 95dd7669ca
14 changed files with 238 additions and 106 deletions

View file

@ -1483,7 +1483,10 @@ class GlobalVariable(GlobalValue):
@staticmethod @staticmethod
def get(module, name): def get(module, name):
return GlobalVariable(_core.LLVMGetNamedGlobal(module.ptr, name), module) ptr = _core.LLVMGetNamedGlobal(module.ptr, name)
if not ptr:
raise llvm.LLVMException, ("no global named `%s`" % name)
return GlobalVariable(ptr, name)
def __init__(self, ptr, module): def __init__(self, ptr, module):
GlobalValue.__init__(self, ptr, module) GlobalValue.__init__(self, ptr, module)
@ -1539,7 +1542,10 @@ class Function(GlobalValue):
@staticmethod @staticmethod
def get(module, name): def get(module, name):
return Function(_core.LLVMGetNamedFunction(module.ptr, name), module) ptr = _core.LLVMGetNamedFunction(module.ptr, name)
if not ptr:
raise llvm.LLVMException, ("no function named `%s`" % name)
return Function(ptr, module)
@staticmethod @staticmethod
def intrinsic(module, id, types): def intrinsic(module, id, types):

View file

@ -36,8 +36,8 @@ monospacedwords=(?u)\\?\basciidoc\(1\) (?u)\\?\ba2x\(1\)
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset={encoding}" /> <meta http-equiv="Content-Type" content="text/html; charset={encoding}" />
<meta name="generator" content="AsciiDoc {asciidoc-version}" /> <meta name="generator" content="AsciiDoc {asciidoc-version}" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/{theme={backend}}.css" type="text/css" /> <link rel="stylesheet" href="style/{theme={backend}}.css" type="text/css" />
<link rel="stylesheet" href="style/{theme={backend}}-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/{theme={backend}}-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -69,7 +69,7 @@ endif::toc[]
</td> </td>
<td> <td>
ifdef::toc[] ifdef::toc[]
<div id="toc" style="float: right"> <div id="toc" style="float: right; display: none">
<div id="toctitle">Table of Contents</div> <div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript> <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div> </div>

View file

@ -274,3 +274,7 @@ div.toclevel4 {
margin-left: 6em; margin-left: 6em;
font-size: 0.9em; font-size: 0.9em;
} }
div.listingblock {
line-height: 1.2em;
}

View file

@ -1,13 +1,6 @@
llvm-py User Guide llvm-py User Guide
=================== ===================
[NOTE]
=======================================================================
This document is updated frequently (last updated on {localdate}).
Check back often.
=======================================================================
llvm-py provides Python bindings for LLVM. This document explains how llvm-py 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.
@ -33,9 +26,9 @@ http://opensource.org/licenses/bsd-license.php[new BSD license]. More
information is available link:license.html[here]. information is available link:license.html[here].
.Platforms .Platforms
Currently, llvm-py has been built and tested only on Linux/x86. However, Currently, llvm-py has been built and tested only on Linux (i386, amd64)
it should be trivial to build it on other unices. Windows is not and OpenBSD (i386, amd64). However, it should be trivial to build it on
supported, for a variety of reasons. other unices. Windows is not supported, for a variety of reasons.
.Versions .Versions
llvm-py requires verion 2.3 of LLVM. It will not work with previous llvm-py requires verion 2.3 of LLVM. It will not work with previous
@ -70,16 +63,31 @@ been tried only with gcc/g\+\+ though.
Tip: If LLVM 2.3 does not install cleanly, try installing ``ocamldoc'' Tip: If LLVM 2.3 does not install cleanly, try installing ``ocamldoc''
first. first.
LLVM and `--enable-pic`
~~~~~~~~~~~~~~~~~~~~~~~
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
shared object (_core.so) which links to these static libraries and
object files. It is therefore required that the LLVM libraries and
object files be built with the `-fPIC` option (generate position
independent code). Be sure to use the `--enable-pic` option while
configuring LLVM (default is no PIC), like this:
----
~/llvm-2.3$ ./configure --enable-pic --enable-optimized
----
llvm-config llvm-config
~~~~~~~~~~~ ~~~~~~~~~~~
Inorder to build llvm-py, it's build script needs to know from where to Inorder to build llvm-py, it's build script needs to know from where it
invoke the llvm helper program, +llvm-config+. If you've installed LLVM, can invoke the llvm helper program, +llvm-config+. If you've installed
then this will be available in your +PATH+, and nothing further needs to LLVM, then this will be available in your +PATH+, and nothing further
be done. If you've built LLVM yourself, or for any reason +llvm-config+ needs to be done. If you've built LLVM yourself, or for any reason
is not in your +PATH+, you'll need to pass the full path of +llvm-config+ is not in your +PATH+, you'll need to pass the full path
+llvm-config+ to the build script. 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 llvm-py. 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
@ -482,34 +490,41 @@ attributes of the `Module` class is:
======================================================================= =======================================================================
.Static Constructors .Static Constructors
`new(module_id)`:: `new(module_id)`::
create a new `Module` instance with given `module_id`. The `module_id` Create a new `Module` instance with given `module_id`. The `module_id`
should be a string. should be a string.
.Properties .Properties
`data_layout`:: `data_layout`::
a string representing the ABI of the platform A string representing the ABI of the platform.
`target`:: `target`::
a string like `i386-pc-linux-gnu` or `i386-pc-solaris2.8` A string like `i386-pc-linux-gnu` or `i386-pc-solaris2.8`.
`global_variables` [read-only]:: `global_variables` [read-only]::
TODO An iterable that yields `GlobalVariable` objects, that represent
the global variables of the module.
`functions` [read-only]:: `functions` [read-only]::
TODO An iterable that yields `Function` objects, that represent functions
in the module.
.Methods .Methods
`add_type_name`:: `add_type_name(name, ty)`::
TODO Add an alias (typedef) for the type `ty` with the name `name`.
`delete_type_name`:: `delete_type_name(name)`::
TODO Delete an alias with the name `name`.
`add_global_variable`:: `add_global_variable(ty, name)`::
TODO Add a global variable of the type `ty` with the name `name`.
`get_global_variable_named`:: Returns a `GlobalVariable` object.
TODO `get_global_variable_named(name)`::
`add_function`:: Get a `GlobalVariable` object corresponding to the global
TODO variable with the name `name`. Raises `LLVMException` if such a
`get_function_named`:: variable does not exist.
TODO `add_function(ty, name)`::
`verify`:: Add a function named `name` with the function type `ty`. `ty` must
Verifies the correctness of the module. Raises `LLVMException` on of an object of type `FunctionType`.
`get_function_named(name)`::
Get a `Function` object corresponding to the function with the name
`name`. Raises `LLVMException` if such a function does not exist.
`verify()`::
Verify the correctness of the module. Raises `LLVMException` on
errors. errors.
.Special Methods .Special Methods
@ -615,8 +630,9 @@ The class-level documentation follows:
Creates an array type, holding `count` elements, each of type `elty` Creates an array type, holding `count` elements, each of type `elty`
(which should be a `Type`). (which should be a `Type`).
`pointer(pty, addrspc=0)`:: `pointer(pty, addrspc=0)`::
Create a pointer to type `pty` (which should be a `Type). (TODO Create a pointer to type `pty` (which should be a `Type). `addrspc`
addrspc). is an integer that represents the address space of the pointer (see
LLVM docs / ask on llvm-dev for more info).
`void()`:: `void()`::
Creates a void type. Used for function return types. Creates a void type. Used for function return types.
`label()`:: `label()`::

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -42,7 +42,7 @@ llvm-dev mailing list and irc.oftc.net#llvm (mdevan).</p>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 21-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -124,7 +124,7 @@ Improve tests.
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 21-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -122,7 +122,7 @@ package.</p>
<pre><tt>0.3, in progress: <pre><tt>0.3, in progress:
* Intrinsics added. * Intrinsics added.
* JIT Tutorials ported (Sebastian Binet). * JIT Tutorials ported (Sebastien Binet).
* GenericValue added. Used by ExecutionEngine.run(). * GenericValue added. Used by ExecutionEngine.run().
* Build cleanly on OpenBSD, x86-64/amd64 (Laurence Tratt). * Build cleanly on OpenBSD, x86-64/amd64 (Laurence Tratt).
* Updated documentation. * Updated documentation.
@ -158,7 +158,7 @@ package.</p>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 21-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -228,7 +228,7 @@ Conclusion and other useful LLVM tidbits (TODO)
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 22-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>

View file

@ -0,0 +1,36 @@
<!-- Generator: GNU source-highlight 2.4
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900">#!/usr/bin/env python</font></i>
<b><font color="#000080">from</font></b> llvm<font color="#990000">.</font>core <b><font color="#000080">import</font></b> <font color="#990000">*</font>
<i><font color="#9A1900"># create a module</font></i>
module <font color="#990000">=</font> <font color="#009900">Module</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font><font color="#FF0000">"tut1"</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a function type taking 3 32-bit integers, return a 32-bit integer</font></i>
ty<font color="#009900">_</font>int <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">int </font></b><font color="#990000">(</font><font color="#993399">32</font><font color="#990000">)</font>
func<font color="#009900">_</font>type <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">function </font></b><font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,</font> <font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,)*</font><font color="#993399">3</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a function of that type</font></i>
mul<font color="#009900">_</font>add <font color="#990000">=</font> <font color="#009900">Function</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>module<font color="#990000">,</font> func<font color="#009900">_</font>type<font color="#990000">,</font> <font color="#FF0000">"mul_add"</font><font color="#990000">)</font>
mul<font color="#009900">_</font>add<font color="#990000">.</font>calling<font color="#009900">_</font>convention <font color="#990000">=</font> <font color="#009900">CC_C</font>
x <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">];</font> x<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"x"</font>
y <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">1</font><font color="#990000">];</font> y<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"y"</font>
z <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">];</font> z<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"z"</font>
<i><font color="#9A1900"># implement the function</font></i>
<i><font color="#9A1900"># new block</font></i>
blk <font color="#990000">=</font> mul<font color="#009900">_</font>add<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"entry"</font><font color="#990000">)</font>
<i><font color="#9A1900"># IR builder</font></i>
bldr <font color="#990000">=</font> <font color="#009900">Builder</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>blk<font color="#990000">)</font>
tmp<font color="#009900">_</font><font color="#993399">1</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">mul </font></b><font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp_1"</font><font color="#990000">)</font>
tmp<font color="#009900">_</font><font color="#993399">2</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">add </font></b><font color="#990000">(</font>tmp<font color="#009900">_</font><font color="#993399">1</font><font color="#990000">,</font> z<font color="#990000">,</font> <font color="#FF0000">"tmp_2"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret </font></b><font color="#990000">(</font>tmp<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font>
<b><font color="#0000FF">print</font></b> module
</tt></pre>

View file

@ -0,0 +1,55 @@
<!-- Generator: GNU source-highlight 2.4
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900">#!/usr/bin/env python</font></i>
<b><font color="#000080">from</font></b> llvm<font color="#990000">.</font>core <b><font color="#000080">import</font></b> <font color="#990000">*</font>
<i><font color="#9A1900"># create a module</font></i>
module <font color="#990000">=</font> <font color="#009900">Module</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font><font color="#FF0000">"tut2"</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a function type taking 2 integers, return a 32-bit integer</font></i>
ty<font color="#009900">_</font>int <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">int </font></b><font color="#990000">(</font><font color="#993399">32</font><font color="#990000">)</font>
func<font color="#009900">_</font>type <font color="#990000">=</font> <font color="#009900">Type</font><font color="#990000">.</font><b><font color="#000000">function </font></b><font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,</font> <font color="#990000">(</font>ty<font color="#009900">_</font>int<font color="#990000">,</font> ty<font color="#009900">_</font>int<font color="#990000">))</font>
<i><font color="#9A1900"># create a function of that type</font></i>
gcd <font color="#990000">=</font> <font color="#009900">Function</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>module<font color="#990000">,</font> func<font color="#009900">_</font>type<font color="#990000">,</font> <font color="#FF0000">"gcd"</font><font color="#990000">)</font>
<i><font color="#9A1900"># name function args</font></i>
x <font color="#990000">=</font> gcd<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">];</font> x<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"x"</font>
y <font color="#990000">=</font> gcd<font color="#990000">.</font>args<font color="#990000">[</font><font color="#993399">1</font><font color="#990000">];</font> y<font color="#990000">.</font>name <font color="#990000">=</font> <font color="#FF0000">"y"</font>
<i><font color="#9A1900"># implement the function</font></i>
<i><font color="#9A1900"># blocks...</font></i>
entry <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"entry"</font><font color="#990000">)</font>
ret <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"return"</font><font color="#990000">)</font>
cond<font color="#009900">_</font>false <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"cond_false"</font><font color="#990000">)</font>
cond<font color="#009900">_</font>true <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"cond_true"</font><font color="#990000">)</font>
cond<font color="#009900">_</font>false<font color="#009900">_</font><font color="#993399">2</font> <font color="#990000">=</font> gcd<font color="#990000">.</font><b><font color="#000000">append_basic_block </font></b><font color="#990000">(</font><font color="#FF0000">"cond_false_2"</font><font color="#990000">)</font>
<i><font color="#9A1900"># create a llvm::IRBuilder</font></i>
bldr <font color="#990000">=</font> <font color="#009900">Builder</font><font color="#990000">.</font><b><font color="#000000">new </font></b><font color="#990000">(</font>entry<font color="#990000">)</font>
x<font color="#009900">_</font>eq<font color="#009900">_</font>y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">icmp </font></b><font color="#990000">(</font><font color="#009900">IPRED_EQ</font><font color="#990000">,</font> x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">cbranch </font></b><font color="#990000">(</font>x<font color="#009900">_</font>eq<font color="#009900">_</font>y<font color="#990000">,</font> ret<font color="#990000">,</font> cond<font color="#009900">_</font>false<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>ret<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret</font></b><font color="#990000">(</font>x<font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>cond<font color="#009900">_</font>false<font color="#990000">)</font>
x<font color="#009900">_</font>lt<font color="#009900">_</font>y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">icmp </font></b><font color="#990000">(</font><font color="#009900">IPRED_ULT</font><font color="#990000">,</font> x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">cbranch </font></b><font color="#990000">(</font>x<font color="#009900">_</font>lt<font color="#009900">_</font>y<font color="#990000">,</font> cond<font color="#009900">_</font>true<font color="#990000">,</font> cond<font color="#009900">_</font>false<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>cond<font color="#009900">_</font>true<font color="#990000">)</font>
y<font color="#009900">_</font>sub<font color="#009900">_</font>x <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">sub </font></b><font color="#990000">(</font>y<font color="#990000">,</font> x<font color="#990000">,</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
recur<font color="#009900">_</font><font color="#993399">1</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">call </font></b><font color="#990000">(</font>gcd<font color="#990000">,</font> <font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#009900">_</font>sub<font color="#009900">_</font>x<font color="#990000">,),</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret </font></b><font color="#990000">(</font>recur<font color="#009900">_</font><font color="#993399">1</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">position_at_end </font></b><font color="#990000">(</font>cond<font color="#009900">_</font>false<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font>
x<font color="#009900">_</font>sub<font color="#009900">_</font>y <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">sub </font></b><font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">,</font> <font color="#FF0000">"x_sub_y"</font><font color="#990000">)</font>
recur<font color="#009900">_</font><font color="#993399">2</font> <font color="#990000">=</font> bldr<font color="#990000">.</font><b><font color="#000000">call </font></b><font color="#990000">(</font>gcd<font color="#990000">,</font> <font color="#990000">(</font>x<font color="#009900">_</font>sub<font color="#009900">_</font>y<font color="#990000">,</font> y<font color="#990000">,),</font> <font color="#FF0000">"tmp"</font><font color="#990000">)</font>
bldr<font color="#990000">.</font><b><font color="#000000">ret </font></b><font color="#990000">(</font>recur<font color="#009900">_</font><font color="#993399">2</font><font color="#990000">)</font>
<b><font color="#0000FF">print</font></b> module
</tt></pre>

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -81,7 +81,7 @@ minimal changes, if any.</p>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 21-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -74,7 +74,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 21-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>

View file

@ -274,3 +274,7 @@ div.toclevel4 {
margin-left: 6em; margin-left: 6em;
font-size: 0.9em; font-size: 0.9em;
} }
div.listingblock {
line-height: 1.2em;
}

View file

@ -3,8 +3,8 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.2" /> <meta name="generator" content="AsciiDoc 8.2.2" />
<meta name="description" content="Text based document generation" /> <meta name="description" content="Python bindings for LLVM" />
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" /> <meta name="keywords" content="llvm python compiler backend bindings" />
<link rel="stylesheet" href="style/xhtml11.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11.css" type="text/css" />
<link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" /> <link rel="stylesheet" href="style/xhtml11-quirks.css" type="text/css" />
<link rel="stylesheet" href="style/layout.css" type="text/css" /> <link rel="stylesheet" href="style/layout.css" type="text/css" />
@ -33,7 +33,7 @@ window.onload = function(){generateToc(2)}
<div>&#187;<a href="about.html">About</a></div> <div>&#187;<a href="about.html">About</a></div>
</td> </td>
<td> <td>
<div id="toc" style="float: right"> <div id="toc" style="float: right; display: none">
<div id="toctitle">Table of Contents</div> <div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript> <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div> </div>
@ -43,17 +43,6 @@ window.onload = function(){generateToc(2)}
</div> </div>
<div id="preamble"> <div id="preamble">
<div class="sectionbody"> <div class="sectionbody">
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">
<p>This document is updated frequently (last updated on 21-Jul-2008).
Check back often.</p>
</td>
</tr></table>
</div>
<p>llvm-py provides Python bindings for LLVM. This document explains how <p>llvm-py 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.</p> of LLVM is assumed.</p>
@ -75,9 +64,9 @@ open source licenses. llvm-py uses the
<a href="http://opensource.org/licenses/bsd-license.php">new BSD license</a>. More <a href="http://opensource.org/licenses/bsd-license.php">new BSD license</a>. More
information is available <a href="license.html">here</a>.</p> information is available <a href="license.html">here</a>.</p>
<div class="title">Platforms</div> <div class="title">Platforms</div>
<p>Currently, llvm-py has been built and tested only on Linux/x86. However, <p>Currently, llvm-py has been built and tested only on Linux (i386, amd64)
it should be trivial to build it on other unices. Windows is not and OpenBSD (i386, amd64). However, it should be trivial to build it on
supported, for a variety of reasons.</p> other unices. Windows is not supported, for a variety of reasons.</p>
<div class="title">Versions</div> <div class="title">Versions</div>
<p>llvm-py requires verion 2.3 of LLVM. It will not work with previous <p>llvm-py requires verion 2.3 of LLVM. It will not work with previous
versions.</p> versions.</p>
@ -120,13 +109,25 @@ llvm-g++ or any other); llvm-py can be built with any compiler. It has
been tried only with gcc/g++ though.</p> been tried only with gcc/g++ though.</p>
<p>Tip: If LLVM 2.3 does not install cleanly, try installing &#8220;ocamldoc&#8221; <p>Tip: If LLVM 2.3 does not install cleanly, try installing &#8220;ocamldoc&#8221;
first.</p> first.</p>
<h3>LLVM and <tt>&#8212;enable-pic</tt></h3>
<p>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
shared object (_core.so) which links to these static libraries and
object files. It is therefore required that the LLVM libraries and
object files be built with the <tt>-fPIC</tt> option (generate position
independent code). Be sure to use the <tt>&#8212;enable-pic</tt> option while
configuring LLVM (default is no PIC), like this:</p>
<div class="listingblock">
<div class="content">
<pre><tt>~/llvm-2.3$ ./configure --enable-pic --enable-optimized</tt></pre>
</div></div>
<h3>llvm-config</h3> <h3>llvm-config</h3>
<p>Inorder to build llvm-py, it's build script needs to know from where to <p>Inorder to build llvm-py, it's build script needs to know from where it
invoke the llvm helper program, <tt>llvm-config</tt>. If you've installed LLVM, can invoke the llvm helper program, <tt>llvm-config</tt>. If you've installed
then this will be available in your <tt>PATH</tt>, and nothing further needs to LLVM, then this will be available in your <tt>PATH</tt>, and nothing further
be done. If you've built LLVM yourself, or for any reason <tt>llvm-config</tt> needs to be done. If you've built LLVM yourself, or for any reason
is not in your <tt>PATH</tt>, you'll need to pass the full path of <tt>llvm-config</tt> is not in your <tt>PATH</tt>, you'll need to pass the full path
<tt>llvm-config</tt> to the build script.</p> of <tt>llvm-config</tt> to the build script.</p>
<p>You'll need to be <em>root</em> to install llvm-py. Remember that your <tt>PATH</tt> <p>You'll need to be <em>root</em> to install llvm-py. Remember that your <tt>PATH</tt>
is different from that of <em>root</em>, so even if <tt>llvm-config</tt> is in your is different from that of <em>root</em>, so even if <tt>llvm-config</tt> is in your
<tt>PATH</tt>, it may not be available when you do <tt>sudo</tt>.</p> <tt>PATH</tt>, it may not be available when you do <tt>sudo</tt>.</p>
@ -785,7 +786,7 @@ attributes of the <tt>Module</tt> class is:</p>
</dt> </dt>
<dd> <dd>
<p> <p>
create a new <tt>Module</tt> instance with given <tt>module_id</tt>. The <tt>module_id</tt> Create a new <tt>Module</tt> instance with given <tt>module_id</tt>. The <tt>module_id</tt>
should be a string. should be a string.
</p> </p>
</dd> </dd>
@ -796,7 +797,7 @@ attributes of the <tt>Module</tt> class is:</p>
</dt> </dt>
<dd> <dd>
<p> <p>
a string representing the ABI of the platform A string representing the ABI of the platform.
</p> </p>
</dd> </dd>
<dt> <dt>
@ -804,7 +805,7 @@ attributes of the <tt>Module</tt> class is:</p>
</dt> </dt>
<dd> <dd>
<p> <p>
a string like <tt>i386-pc-linux-gnu</tt> or <tt>i386-pc-solaris2.8</tt> A string like <tt>i386-pc-linux-gnu</tt> or <tt>i386-pc-solaris2.8</tt>.
</p> </p>
</dd> </dd>
<dt> <dt>
@ -812,7 +813,8 @@ attributes of the <tt>Module</tt> class is:</p>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO An iterable that yields <tt>GlobalVariable</tt> objects, that represent
the global variables of the module.
</p> </p>
</dd> </dd>
<dt> <dt>
@ -820,65 +822,71 @@ attributes of the <tt>Module</tt> class is:</p>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO An iterable that yields <tt>Function</tt> objects, that represent functions
in the module.
</p> </p>
</dd> </dd>
</dl> </dl>
<div class="title">Methods</div><dl> <div class="title">Methods</div><dl>
<dt> <dt>
<tt>add_type_name</tt> <tt>add_type_name(name, ty)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO Add an alias (typedef) for the type <tt>ty</tt> with the name <tt>name</tt>.
</p> </p>
</dd> </dd>
<dt> <dt>
<tt>delete_type_name</tt> <tt>delete_type_name(name)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO Delete an alias with the name <tt>name</tt>.
</p> </p>
</dd> </dd>
<dt> <dt>
<tt>add_global_variable</tt> <tt>add_global_variable(ty, name)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO Add a global variable of the type <tt>ty</tt> with the name <tt>name</tt>.
Returns a <tt>GlobalVariable</tt> object.
</p> </p>
</dd> </dd>
<dt> <dt>
<tt>get_global_variable_named</tt> <tt>get_global_variable_named(name)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO Get a <tt>GlobalVariable</tt> object corresponding to the global
variable with the name <tt>name</tt>. Raises <tt>LLVMException</tt> if such a
variable does not exist.
</p> </p>
</dd> </dd>
<dt> <dt>
<tt>add_function</tt> <tt>add_function(ty, name)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO Add a function named <tt>name</tt> with the function type <tt>ty</tt>. <tt>ty</tt> must
of an object of type <tt>FunctionType</tt>.
</p> </p>
</dd> </dd>
<dt> <dt>
<tt>get_function_named</tt> <tt>get_function_named(name)</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
TODO Get a <tt>Function</tt> object corresponding to the function with the name
<tt>name</tt>. Raises <tt>LLVMException</tt> if such a function does not exist.
</p> </p>
</dd> </dd>
<dt> <dt>
<tt>verify</tt> <tt>verify()</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
Verifies the correctness of the module. Raises <tt>LLVMException</tt> on Verify the correctness of the module. Raises <tt>LLVMException</tt> on
errors. errors.
</p> </p>
</dd> </dd>
@ -1228,8 +1236,9 @@ cellspacing="0" cellpadding="4">
</dt> </dt>
<dd> <dd>
<p> <p>
Create a pointer to type <tt>pty</tt> (which should be a `Type). (TODO Create a pointer to type <tt>pty</tt> (which should be a <tt>Type). `addrspc</tt>
addrspc). is an integer that represents the address space of the pointer (see
LLVM docs / ask on llvm-dev for more info).
</p> </p>
</dd> </dd>
<dt> <dt>
@ -2425,6 +2434,8 @@ m.add_type_name("struct.node", th.type)
# show what we created # show what we created
print m</tt></pre> print m</tt></pre>
</div></div> </div></div>
<div class="listingblock">
<div class="content"></div></div>
<p>which gives the output:</p> <p>which gives the output:</p>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
@ -2633,7 +2644,7 @@ reached at <em>mdevan.foobar@gmail.com</em>.</p>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>. Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 21-Jul-2008. Last updated 31-Jul-2008.
</div> </div>
</div> </div>
</div> </div>