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:
parent
6d57b0e5bc
commit
95dd7669ca
14 changed files with 238 additions and 106 deletions
10
llvm/core.py
10
llvm/core.py
|
|
@ -1483,7 +1483,10 @@ class GlobalVariable(GlobalValue):
|
|||
|
||||
@staticmethod
|
||||
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):
|
||||
GlobalValue.__init__(self, ptr, module)
|
||||
|
|
@ -1539,7 +1542,10 @@ class Function(GlobalValue):
|
|||
|
||||
@staticmethod
|
||||
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
|
||||
def intrinsic(module, id, types):
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ monospacedwords=(?u)\\?\basciidoc\(1\) (?u)\\?\ba2x\(1\)
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset={encoding}" />
|
||||
<meta name="generator" content="AsciiDoc {asciidoc-version}" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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}}-quirks.css" type="text/css" />
|
||||
<link rel="stylesheet" href="style/layout.css" type="text/css" />
|
||||
|
|
@ -69,7 +69,7 @@ endif::toc[]
|
|||
</td>
|
||||
<td>
|
||||
ifdef::toc[]
|
||||
<div id="toc" style="float: right">
|
||||
<div id="toc" style="float: right; display: none">
|
||||
<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>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -274,3 +274,7 @@ div.toclevel4 {
|
|||
margin-left: 6em;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
div.listingblock {
|
||||
line-height: 1.2em;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,6 @@
|
|||
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
|
||||
you can setup and use it. A working knowledge of Python and a basic idea
|
||||
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].
|
||||
|
||||
.Platforms
|
||||
Currently, llvm-py has been built and tested only on Linux/x86. However,
|
||||
it should be trivial to build it on other unices. Windows is not
|
||||
supported, for a variety of reasons.
|
||||
Currently, llvm-py has been built and tested only on Linux (i386, amd64)
|
||||
and OpenBSD (i386, amd64). However, it should be trivial to build it on
|
||||
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
|
||||
|
|
@ -70,16 +63,31 @@ been tried only with gcc/g\+\+ though.
|
|||
Tip: If LLVM 2.3 does not install cleanly, try installing ``ocamldoc''
|
||||
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
|
||||
~~~~~~~~~~~
|
||||
|
||||
Inorder to build llvm-py, it's build script needs to know from where to
|
||||
invoke the llvm helper program, +llvm-config+. If you've installed 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 +llvm-config+
|
||||
is not in your +PATH+, you'll need to pass the full path of
|
||||
+llvm-config+ to the build script.
|
||||
Inorder to build llvm-py, it's build script needs to know from where it
|
||||
can invoke the llvm helper program, +llvm-config+. If you've installed
|
||||
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
|
||||
+llvm-config+ is not in your +PATH+, you'll need to pass the full path
|
||||
of +llvm-config+ to the build script.
|
||||
|
||||
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
|
||||
|
|
@ -482,34 +490,41 @@ attributes of the `Module` class is:
|
|||
=======================================================================
|
||||
.Static Constructors
|
||||
`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.
|
||||
|
||||
.Properties
|
||||
`data_layout`::
|
||||
a string representing the ABI of the platform
|
||||
A string representing the ABI of the platform.
|
||||
`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]::
|
||||
TODO
|
||||
An iterable that yields `GlobalVariable` objects, that represent
|
||||
the global variables of the module.
|
||||
`functions` [read-only]::
|
||||
TODO
|
||||
An iterable that yields `Function` objects, that represent functions
|
||||
in the module.
|
||||
|
||||
.Methods
|
||||
`add_type_name`::
|
||||
TODO
|
||||
`delete_type_name`::
|
||||
TODO
|
||||
`add_global_variable`::
|
||||
TODO
|
||||
`get_global_variable_named`::
|
||||
TODO
|
||||
`add_function`::
|
||||
TODO
|
||||
`get_function_named`::
|
||||
TODO
|
||||
`verify`::
|
||||
Verifies the correctness of the module. Raises `LLVMException` on
|
||||
`add_type_name(name, ty)`::
|
||||
Add an alias (typedef) for the type `ty` with the name `name`.
|
||||
`delete_type_name(name)`::
|
||||
Delete an alias with the name `name`.
|
||||
`add_global_variable(ty, name)`::
|
||||
Add a global variable of the type `ty` with the name `name`.
|
||||
Returns a `GlobalVariable` object.
|
||||
`get_global_variable_named(name)`::
|
||||
Get a `GlobalVariable` object corresponding to the global
|
||||
variable with the name `name`. Raises `LLVMException` if such a
|
||||
variable does not exist.
|
||||
`add_function(ty, name)`::
|
||||
Add a function named `name` with the function type `ty`. `ty` must
|
||||
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.
|
||||
|
||||
.Special Methods
|
||||
|
|
@ -615,8 +630,9 @@ The class-level documentation follows:
|
|||
Creates an array type, holding `count` elements, each of type `elty`
|
||||
(which should be a `Type`).
|
||||
`pointer(pty, addrspc=0)`::
|
||||
Create a pointer to type `pty` (which should be a `Type). (TODO
|
||||
addrspc).
|
||||
Create a pointer to type `pty` (which should be a `Type). `addrspc`
|
||||
is an integer that represents the address space of the pointer (see
|
||||
LLVM docs / ask on llvm-dev for more info).
|
||||
`void()`::
|
||||
Creates a void type. Used for function return types.
|
||||
`label()`::
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.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-text">
|
||||
Web pages © 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>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.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-text">
|
||||
Web pages © 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>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.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:
|
||||
|
||||
* Intrinsics added.
|
||||
* JIT Tutorials ported (Sebastian Binet).
|
||||
* JIT Tutorials ported (Sebastien Binet).
|
||||
* GenericValue added. Used by ExecutionEngine.run().
|
||||
* Build cleanly on OpenBSD, x86-64/amd64 (Laurence Tratt).
|
||||
* Updated documentation.
|
||||
|
|
@ -158,7 +158,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 21-Jul-2008.
|
||||
Last updated 31-Jul-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.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-text">
|
||||
Web pages © 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>
|
||||
|
|
|
|||
36
www/web/examples/JITTutorial1.html
Normal file
36
www/web/examples/JITTutorial1.html
Normal 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>
|
||||
55
www/web/examples/JITTutorial2.html
Normal file
55
www/web/examples/JITTutorial2.html
Normal 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>
|
||||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.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-text">
|
||||
Web pages © 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>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.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-text">
|
||||
Web pages © 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>
|
||||
|
|
|
|||
|
|
@ -274,3 +274,7 @@ div.toclevel4 {
|
|||
margin-left: 6em;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
div.listingblock {
|
||||
line-height: 1.2em;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="generator" content="AsciiDoc 8.2.2" />
|
||||
<meta name="description" content="Text based document generation" />
|
||||
<meta name="keywords" content="text to HTML, text to DocBook, text to XML, AsciiDoc" />
|
||||
<meta name="description" content="Python bindings for LLVM" />
|
||||
<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-quirks.css" type="text/css" />
|
||||
<link rel="stylesheet" href="style/layout.css" type="text/css" />
|
||||
|
|
@ -33,7 +33,7 @@ window.onload = function(){generateToc(2)}
|
|||
<div>»<a href="about.html">About</a></div>
|
||||
</td>
|
||||
<td>
|
||||
<div id="toc" style="float: right">
|
||||
<div id="toc" style="float: right; display: none">
|
||||
<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>
|
||||
</div>
|
||||
|
|
@ -43,17 +43,6 @@ window.onload = function(){generateToc(2)}
|
|||
</div>
|
||||
<div id="preamble">
|
||||
<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
|
||||
you can setup and use it. A working knowledge of Python and a basic idea
|
||||
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
|
||||
information is available <a href="license.html">here</a>.</p>
|
||||
<div class="title">Platforms</div>
|
||||
<p>Currently, llvm-py has been built and tested only on Linux/x86. However,
|
||||
it should be trivial to build it on other unices. Windows is not
|
||||
supported, for a variety of reasons.</p>
|
||||
<p>Currently, llvm-py has been built and tested only on Linux (i386, amd64)
|
||||
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>
|
||||
|
|
@ -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>
|
||||
<p>Tip: If LLVM 2.3 does not install cleanly, try installing “ocamldoc”
|
||||
first.</p>
|
||||
<h3>LLVM and <tt>—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>—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>
|
||||
<p>Inorder to build llvm-py, it's build script needs to know from where to
|
||||
invoke the llvm helper program, <tt>llvm-config</tt>. If you've installed LLVM,
|
||||
then this will be available in your <tt>PATH</tt>, and nothing further needs to
|
||||
be done. If you've built LLVM yourself, or for any reason <tt>llvm-config</tt>
|
||||
is not in your <tt>PATH</tt>, you'll need to pass the full path of
|
||||
<tt>llvm-config</tt> to the build script.</p>
|
||||
<p>Inorder to build llvm-py, it's build script needs to know from where it
|
||||
can invoke the llvm helper program, <tt>llvm-config</tt>. If you've installed
|
||||
LLVM, then this will be available in your <tt>PATH</tt>, and nothing further
|
||||
needs to be done. If you've built LLVM yourself, or for any reason
|
||||
<tt>llvm-config</tt> is not in your <tt>PATH</tt>, you'll need to pass the full path
|
||||
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>
|
||||
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>
|
||||
|
|
@ -785,7 +786,7 @@ attributes of the <tt>Module</tt> class is:</p>
|
|||
</dt>
|
||||
<dd>
|
||||
<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.
|
||||
</p>
|
||||
</dd>
|
||||
|
|
@ -796,7 +797,7 @@ attributes of the <tt>Module</tt> class is:</p>
|
|||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
a string representing the ABI of the platform
|
||||
A string representing the ABI of the platform.
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
|
|
@ -804,7 +805,7 @@ attributes of the <tt>Module</tt> class is:</p>
|
|||
</dt>
|
||||
<dd>
|
||||
<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>
|
||||
</dd>
|
||||
<dt>
|
||||
|
|
@ -812,7 +813,8 @@ attributes of the <tt>Module</tt> class is:</p>
|
|||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
An iterable that yields <tt>GlobalVariable</tt> objects, that represent
|
||||
the global variables of the module.
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
|
|
@ -820,65 +822,71 @@ attributes of the <tt>Module</tt> class is:</p>
|
|||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
An iterable that yields <tt>Function</tt> objects, that represent functions
|
||||
in the module.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="title">Methods</div><dl>
|
||||
<dt>
|
||||
<tt>add_type_name</tt>
|
||||
<tt>add_type_name(name, ty)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
Add an alias (typedef) for the type <tt>ty</tt> with the name <tt>name</tt>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>delete_type_name</tt>
|
||||
<tt>delete_type_name(name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
Delete an alias with the name <tt>name</tt>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>add_global_variable</tt>
|
||||
<tt>add_global_variable(ty, name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<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>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>get_global_variable_named</tt>
|
||||
<tt>get_global_variable_named(name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<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>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>add_function</tt>
|
||||
<tt>add_function(ty, name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<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>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>get_function_named</tt>
|
||||
<tt>get_function_named(name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<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>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>verify</tt>
|
||||
<tt>verify()</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Verifies the correctness of the module. Raises <tt>LLVMException</tt> on
|
||||
Verify the correctness of the module. Raises <tt>LLVMException</tt> on
|
||||
errors.
|
||||
</p>
|
||||
</dd>
|
||||
|
|
@ -1228,8 +1236,9 @@ cellspacing="0" cellpadding="4">
|
|||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Create a pointer to type <tt>pty</tt> (which should be a `Type). (TODO
|
||||
addrspc).
|
||||
Create a pointer to type <tt>pty</tt> (which should be a <tt>Type). `addrspc</tt>
|
||||
is an integer that represents the address space of the pointer (see
|
||||
LLVM docs / ask on llvm-dev for more info).
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
|
|
@ -2425,6 +2434,8 @@ m.add_type_name("struct.node", th.type)
|
|||
# show what we created
|
||||
print m</tt></pre>
|
||||
</div></div>
|
||||
<div class="listingblock">
|
||||
<div class="content"></div></div>
|
||||
<p>which gives the output:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
|
|
@ -2633,7 +2644,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 21-Jul-2008.
|
||||
Last updated 31-Jul-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue