diff --git a/www/web/about.html b/www/web/about.html new file mode 100644 index 0000000..6531aa7 --- /dev/null +++ b/www/web/about.html @@ -0,0 +1,68 @@ + + + + + + + + + + +About - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+
+ + + +
+Note + +
llvm-py Mission Statement
+

Provide a simple, consistent and well-documented suite of APIs that +exposes just enough of LLVM to write a compiler/VM in Python.

+
+
+

llvm-py is developed by Mahadevan R, in his spare time, without being +paid for it. He can be reached at mdevan.foobar .at. gmail.com, on the +llvm-dev mailing list and irc.oftc.net#llvm (mdevan).

+

These web pages were generated using the nifty tool +asciidoc.

+
+
+ +
+
+ + diff --git a/www/web/contribute.html b/www/web/contribute.html new file mode 100644 index 0000000..a48e96b --- /dev/null +++ b/www/web/contribute.html @@ -0,0 +1,63 @@ + + + + + + + + + + +Contribute - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+

llvm-py is just hatching. It needs your patches and suggestions to +grow up. Please contribute! All patches are welcome.

+

The llvm-py code is hosted on a google code project by the same name, +here. It provides the SVN repository +and a bug tracker. The +latest code can be checked out from SVN like so:

+
+
+
$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py
+
+

You can browse the source online at: +http://code.google.com/p/llvm-py/source/browse.

+
+
+ +
+
+ + diff --git a/www/web/download.html b/www/web/download.html new file mode 100644 index 0000000..5dfd216 --- /dev/null +++ b/www/web/download.html @@ -0,0 +1,260 @@ + + + + + + + + + + +Download and Setup - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+

The latest release is 0.2, released xx-Jun-2008 (full Changelog +below).

+

Download it here:

+
+ +++++ + + + + + + + + + + + + + + + + + + + + + +
+ Release + + Date + + Package + + Mirror +
+ 0.2 + + xx-Jun-2008 + + llvm-py-0.2.tar.bz2 + + llvm-py-0.2.tar.bz2 +
+ 0.1 + + 20-May-2008 + + llvm-py-0.1.tar.bz2 + + llvm-py-0.1.tar.bz2 +
+
+
+
+

Bleeding Edge

+
+

The latest code can be checked out from SVN thusly:

+
+
+
$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py
+
+

Happy hacking, and please send in your patches.

+
+

Setting Up

+
+

Follow these steps to get llvm-py up and running:

+
    +
  • +

    +Uninstall any previous version of llvm-py. +

    +
  • +
  • +

    +Get and build LLVM. +

    +
  • +
  • +

    +Optionally, install it. +

    +
  • +
  • +

    +Get the latest release (see above) of llvm-py and untar it: +

    +
  • +
+
+
+
$ wget http://link/llvm-py-0.2.tar.bz2
+$ tar jxvf llvm-py-0.2.tar.bz2
+
+
    +
  • +

    +If you've installed LLVM, setup llvm-py like this: +

    +
  • +
+
+
+
$ cd llvm-py-0.2
+$ sudo python setup.py install
+
+
    +
  • +

    +If you haven't installed LLVM, locate the executable llvm-config + under your LLVM build directory (should be something like + /home/mdevan/llvm/Release/bin/llvm-config) and pass this to setup.py: +

    +
  • +
+
+
+
$ cd llvm-py-0.2
+$ sudo python setup.py install --llvm-config=/path/to/llvm-config
+
+

That's it!

+
Notes:
    +
  • +

    +setup.py is a standard Python distutils script. See the Python + documentation regarding + Installing Python Modules and + Distributing Python Modules for + more information on such scripts. +

    +
  • +
  • +

    +To build the debug version, build with the -g flag and the debug + version of llvm-config: +

    +
    +
    +
    $ python setup.py build -g --llvm-config=/path/to/Debug/bin/llvm-config
    +$ sudo python setup.py install
    +
    +
  • +
  • +

    +Debug binaries are huge! (65 MB+) +

    +
  • +
  • +

    +If --llvm-config is not specified, setup.py looks for + llvm-config in the PATH, which will succeed if LLVM is installed. +

    +
  • +
+
+

Uninstall

+
+

To get rid of llvm-py completely, if you wish to do so:

+
+
+
# rm -rf /usr/lib/python2.5/site-packages/llvm
+# rm -f /usr/lib/python2.5/site-packages/llvm_py-0.1.egg-info
+
+
    +
  • +

    +You need to be root to do this. +

    +
  • +
  • +

    +Paths are for debian-based systems, in other distros it might be different. +

    +
  • +
  • +

    +Note that there is a version number in the egg file name. +

    +
  • +
+
+

Changelog

+
+
+
+
0.1, 10-May-2008:
+
+  * Initial release.
+
+
+0.2, ongoing:
+
+  * Independent package, need not be unpacked into llvm/bindings
+  * Modules can be dumped to a string
+  * Modules can be verified
+  * Module.global_variables, Module.functions, Function.args,
+        Function.basic_blocks and BasicBlock.instructions are
+        now proper iterators (generators in fact) than plain lists
+
+  * MemoryBuffer is done
+  * TypeHandle is done
+  * Unit tester added (but doesn't do much for now)
+
+
+
+ +
+
+ + diff --git a/www/web/examples.html b/www/web/examples.html new file mode 100644 index 0000000..bc40125 --- /dev/null +++ b/www/web/examples.html @@ -0,0 +1,114 @@ + + + + + + + + + + +Examples - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+

Here's an example:

+
+
+
#!/usr/bin/env python
+
+from llvm.core import *
+
+## create a module
+module = Module.new("my_module")
+
+## create a function type taking two doubles and returning a (32-bit) integer
+ty_double = Type.double()
+ty_int    = Type.int()
+ty_func   = Type.function( ty_int, [ ty_double, ty_double ] )
+
+## create a function of this type
+func      = Function.new( module, ty_func, "foobar" )
+
+# name function args
+func.args[0].name = "arg1"
+func.args[1].name = "arg2"
+
+## implement the function
+
+# add a basic block
+entry = func.append_basic_block("entry")
+
+# create an llvm::IRBuilder
+builder = Builder.new()
+builder.position_at_end(entry)
+
+# add two args into tmp1
+tmp1 = builder.add(func.args[0], func.args[1], "tmp1")
+
+# sub `1' from that
+one = Constant.real( ty_double, 1.0 )
+tmp2 = builder.sub(tmp1, one, "tmp2")
+
+# convert to integer
+tmp3 = builder.fptoui(tmp2, ty_int, "tmp3")
+
+# return it
+builder.ret(tmp3)
+
+# dump the module to see the llvm "assembly" code
+print module
+
+

which gives this output:

+
+
+
; ModuleID = 'my_module'
+
+define i32 @foobar(double %arg1, double %arg2) {
+entry:
+        %temp1 = add double %arg1, %arg2                ; <double> [#uses=1]
+        %temp2 = sub double %temp1, 1.000000e+00                ; <double> [#uses=1]
+        %temp3 = fptoui double %temp2 to i32            ; <i32> [#uses=1]
+        ret i32 %temp3
+}
+
+
+
+ +
+
+ + diff --git a/www/web/images/icons/callouts/1.png b/www/web/images/icons/callouts/1.png new file mode 100644 index 0000000..7d47343 Binary files /dev/null and b/www/web/images/icons/callouts/1.png differ diff --git a/www/web/images/icons/callouts/10.png b/www/web/images/icons/callouts/10.png new file mode 100644 index 0000000..997bbc8 Binary files /dev/null and b/www/web/images/icons/callouts/10.png differ diff --git a/www/web/images/icons/callouts/11.png b/www/web/images/icons/callouts/11.png new file mode 100644 index 0000000..ce47dac Binary files /dev/null and b/www/web/images/icons/callouts/11.png differ diff --git a/www/web/images/icons/callouts/12.png b/www/web/images/icons/callouts/12.png new file mode 100644 index 0000000..31daf4e Binary files /dev/null and b/www/web/images/icons/callouts/12.png differ diff --git a/www/web/images/icons/callouts/13.png b/www/web/images/icons/callouts/13.png new file mode 100644 index 0000000..14021a8 Binary files /dev/null and b/www/web/images/icons/callouts/13.png differ diff --git a/www/web/images/icons/callouts/14.png b/www/web/images/icons/callouts/14.png new file mode 100644 index 0000000..64014b7 Binary files /dev/null and b/www/web/images/icons/callouts/14.png differ diff --git a/www/web/images/icons/callouts/15.png b/www/web/images/icons/callouts/15.png new file mode 100644 index 0000000..0d65765 Binary files /dev/null and b/www/web/images/icons/callouts/15.png differ diff --git a/www/web/images/icons/callouts/2.png b/www/web/images/icons/callouts/2.png new file mode 100644 index 0000000..5d09341 Binary files /dev/null and b/www/web/images/icons/callouts/2.png differ diff --git a/www/web/images/icons/callouts/3.png b/www/web/images/icons/callouts/3.png new file mode 100644 index 0000000..ef7b700 Binary files /dev/null and b/www/web/images/icons/callouts/3.png differ diff --git a/www/web/images/icons/callouts/4.png b/www/web/images/icons/callouts/4.png new file mode 100644 index 0000000..adb8364 Binary files /dev/null and b/www/web/images/icons/callouts/4.png differ diff --git a/www/web/images/icons/callouts/5.png b/www/web/images/icons/callouts/5.png new file mode 100644 index 0000000..4d7eb46 Binary files /dev/null and b/www/web/images/icons/callouts/5.png differ diff --git a/www/web/images/icons/callouts/6.png b/www/web/images/icons/callouts/6.png new file mode 100644 index 0000000..0ba694a Binary files /dev/null and b/www/web/images/icons/callouts/6.png differ diff --git a/www/web/images/icons/callouts/7.png b/www/web/images/icons/callouts/7.png new file mode 100644 index 0000000..472e96f Binary files /dev/null and b/www/web/images/icons/callouts/7.png differ diff --git a/www/web/images/icons/callouts/8.png b/www/web/images/icons/callouts/8.png new file mode 100644 index 0000000..5e60973 Binary files /dev/null and b/www/web/images/icons/callouts/8.png differ diff --git a/www/web/images/icons/callouts/9.png b/www/web/images/icons/callouts/9.png new file mode 100644 index 0000000..a0676d2 Binary files /dev/null and b/www/web/images/icons/callouts/9.png differ diff --git a/www/web/images/icons/caution.png b/www/web/images/icons/caution.png new file mode 100644 index 0000000..cb9d5ea Binary files /dev/null and b/www/web/images/icons/caution.png differ diff --git a/www/web/images/icons/example.png b/www/web/images/icons/example.png new file mode 100644 index 0000000..bba1c00 Binary files /dev/null and b/www/web/images/icons/example.png differ diff --git a/www/web/images/icons/home.png b/www/web/images/icons/home.png new file mode 100644 index 0000000..37a5231 Binary files /dev/null and b/www/web/images/icons/home.png differ diff --git a/www/web/images/icons/important.png b/www/web/images/icons/important.png new file mode 100644 index 0000000..1096c23 Binary files /dev/null and b/www/web/images/icons/important.png differ diff --git a/www/web/images/icons/next.png b/www/web/images/icons/next.png new file mode 100644 index 0000000..64e126b Binary files /dev/null and b/www/web/images/icons/next.png differ diff --git a/www/web/images/icons/note.png b/www/web/images/icons/note.png new file mode 100644 index 0000000..841820f Binary files /dev/null and b/www/web/images/icons/note.png differ diff --git a/www/web/images/icons/prev.png b/www/web/images/icons/prev.png new file mode 100644 index 0000000..3e8f12f Binary files /dev/null and b/www/web/images/icons/prev.png differ diff --git a/www/web/images/icons/tip.png b/www/web/images/icons/tip.png new file mode 100644 index 0000000..a3a029d Binary files /dev/null and b/www/web/images/icons/tip.png differ diff --git a/www/web/images/icons/up.png b/www/web/images/icons/up.png new file mode 100644 index 0000000..2db1ce6 Binary files /dev/null and b/www/web/images/icons/up.png differ diff --git a/www/web/images/icons/warning.png b/www/web/images/icons/warning.png new file mode 100644 index 0000000..0b0c419 Binary files /dev/null and b/www/web/images/icons/warning.png differ diff --git a/www/web/index.html b/www/web/index.html new file mode 100644 index 0000000..6caa47f --- /dev/null +++ b/www/web/index.html @@ -0,0 +1,75 @@ + + + + + + + + + + +llvm-py: Python Bindings for LLVM - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+

llvm-py provides Python bindings for +LLVM. It currently provides APIs to build the in-memory IR +(intermediate representation) and to dump it. Execution engine and related APIs +should appear soon.

+

llvm-py is a set of Python-based and C-based Python modules. It makes use of +llvm-c, the C binding for LLVM. It is based on the latest SVN version of LLVM +(and will not work on 2.2). It has been tested only with Python 2.5, although +it should be usable with 2.4 also. I've built and tested it only on Linux/i386 +machines.

+

Download links, setup help and changelog are on the +download page.

+
+
+

News

+
+
+
+20-May-2008 +
+
+

+ 0.1 released. +

+
+
+
+ +
+
+ + diff --git a/www/web/license.html b/www/web/license.html new file mode 100644 index 0000000..6974210 --- /dev/null +++ b/www/web/license.html @@ -0,0 +1,87 @@ + + + + + + + + + + +License - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+

llvm-py is distributed under the +new BSD license. +This is similar to LLVM's license. You should be able to use llvm-py +where-ever and how-ever you're able to use LLVM itself.

+

The license text is present in the +LICENSE +file in the distribution, and is reproduced here:

+
+
+
Copyright (c) 2008, Mahadevan R All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+  * Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+  * Neither the name of the Mahadevan R, llvm-py nor the names of its
+    contributors may be used to endorse or promote products derived from this
+    software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+ +
+
+ + diff --git a/www/web/style/layout.css b/www/web/style/layout.css new file mode 100644 index 0000000..8dc51ae --- /dev/null +++ b/www/web/style/layout.css @@ -0,0 +1,67 @@ + +body { + background-color: white; + margin: 1%; +} + +h1 { + margin-top: 0.5em; +} + +#layout-banner { + background-color: #73a0c5; + color: white; + font-family: sans-serif; + text-align: left; + padding: 0.8em 20px; +} + +#layout-title { + font-family: monospace; + font-size: 3.5em; + font-weight: bold; + letter-spacing: 0.2em; + margin: 0; +} + +#layout-description { + font-size: 1.2em; + letter-spacing: 0.1em; +} + +#layout-menu { + background-color: #f4f4f4; + border-right: 3px solid #eeeeee; + padding-top: 0.8em; + padding-left: 20px; + padding-right: 0.8em; + font-size: 1.1em; + font-family: sans-serif; + font-weight: bold; +} +#layout-menu a { + line-height: 2em; + margin-left: 0.5em; +} +#layout-menu a:link, #layout-menu a:visited, #layout-menu a:hover { + color: #527bbd; + text-decoration: none; +} +#layout-menu a:hover { + color: navy; + text-decoration: none; +} +#layout-menu #page-source { + border-top: 2px solid silver; + margin-top: 0.2em; +} + +#layout-content { + margin-left: 1.0em; + max-width: 600px; +} + +@media print { + #layout-banner { display: none; } + #layout-menu { display: none; } +} diff --git a/www/web/style/xhtml11-manpage.css b/www/web/style/xhtml11-manpage.css new file mode 100644 index 0000000..3ea378a --- /dev/null +++ b/www/web/style/xhtml11-manpage.css @@ -0,0 +1,18 @@ +/* Overrides for manpage documents */ +h1 { + padding-top: 0.5em; + padding-bottom: 0.5em; + border-top: 2px solid silver; + border-bottom: 2px solid silver; +} +h2 { + border-style: none; +} +div.sectionbody { + margin-left: 5%; +} + +@media print { + div#toc { display: none; } +} + diff --git a/www/web/style/xhtml11-quirks.css b/www/web/style/xhtml11-quirks.css new file mode 100644 index 0000000..dbb7775 --- /dev/null +++ b/www/web/style/xhtml11-quirks.css @@ -0,0 +1,40 @@ +/* Workarounds for IE6's broken and incomplete CSS2. */ + +div.sidebar-content { + background: #ffffee; + border: 1px solid silver; + padding: 0.5em; +} +div.sidebar-title, div.image-title { + color: #527bbd; + font-family: sans-serif; + font-weight: bold; + margin-top: 0.0em; + margin-bottom: 0.5em; +} + +div.listingblock div.content { + border: 1px solid silver; + background: #f4f4f4; + padding: 0.5em; +} + +div.quoteblock-content { + padding-left: 2.0em; +} + +div.exampleblock-content { + border-left: 2px solid silver; + padding-left: 0.5em; +} + +/* IE6 sets dynamically generated links as visited. */ +div#toc a:visited { color: blue; } + +/* Because IE6 child selector is broken. */ +div.olist2 ol { + list-style-type: lower-alpha; +} +div.olist2 div.olist ol { + list-style-type: decimal; +} diff --git a/www/web/style/xhtml11.css b/www/web/style/xhtml11.css new file mode 100644 index 0000000..fd931dd --- /dev/null +++ b/www/web/style/xhtml11.css @@ -0,0 +1,276 @@ +/* Debug borders */ +p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { +/* + border: 1px solid red; +*/ +} + +body { + margin: 1em 5% 1em 5%; +} + +a { + color: blue; + text-decoration: underline; +} +a:visited { + color: fuchsia; +} + +em { + font-style: italic; + color: navy; +} + +strong { + font-weight: bold; + color: #083194; +} + +tt { + color: navy; +} + +h1, h2, h3, h4, h5, h6 { + color: #527bbd; + font-family: sans-serif; + margin-top: 1.2em; + margin-bottom: 0.5em; + line-height: 1.3; +} + +h1, h2, h3 { + border-bottom: 2px solid silver; +} +h2 { + padding-top: 0.5em; +} +h3 { + float: left; +} +h3 + * { + clear: left; +} + +div.sectionbody { + font-family: serif; + margin-left: 0; +} + +hr { + border: 1px solid silver; +} + +p { + margin-top: 0.5em; + margin-bottom: 0.5em; +} + +ul, ol, li > p { + margin-top: 0; +} + +pre { + padding: 0; + margin: 0; +} + +span#author { + color: #527bbd; + font-family: sans-serif; + font-weight: bold; + font-size: 1.1em; +} +span#email { +} +span#revision { + font-family: sans-serif; +} + +div#footer { + font-family: sans-serif; + font-size: small; + border-top: 2px solid silver; + padding-top: 0.5em; + margin-top: 4.0em; +} +div#footer-text { + float: left; + padding-bottom: 0.5em; +} +div#footer-badges { + float: right; + padding-bottom: 0.5em; +} + +div#preamble, +div.tableblock, div.imageblock, div.exampleblock, div.verseblock, +div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, +div.admonitionblock { + margin-right: 10%; + margin-top: 1.5em; + margin-bottom: 1.5em; +} +div.admonitionblock { + margin-top: 2.5em; + margin-bottom: 2.5em; +} + +div.content { /* Block element content. */ + padding: 0; +} + +/* Block element titles. */ +div.title, caption.title { + color: #527bbd; + font-family: sans-serif; + font-weight: bold; + text-align: left; + margin-top: 1.0em; + margin-bottom: 0.5em; +} +div.title + * { + margin-top: 0; +} + +td div.title:first-child { + margin-top: 0.0em; +} +div.content div.title:first-child { + margin-top: 0.0em; +} +div.content + div.title { + margin-top: 0.0em; +} + +div.sidebarblock > div.content { + background: #ffffee; + border: 1px solid silver; + padding: 0.5em; +} + +div.listingblock { + margin-right: 0%; +} +div.listingblock > div.content { + border: 1px solid silver; + background: #f4f4f4; + padding: 0.5em; +} + +div.quoteblock > div.content { + padding-left: 2.0em; +} + +div.attribution { + text-align: right; +} +div.verseblock + div.attribution { + text-align: left; +} + +div.admonitionblock .icon { + vertical-align: top; + font-size: 1.1em; + font-weight: bold; + text-decoration: underline; + color: #527bbd; + padding-right: 0.5em; +} +div.admonitionblock td.content { + padding-left: 0.5em; + border-left: 2px solid silver; +} + +div.exampleblock > div.content { + border-left: 2px solid silver; + padding: 0.5em; +} + +div.verseblock div.content { + white-space: pre; +} + +div.imageblock div.content { padding-left: 0; } +div.imageblock img { border: 1px solid silver; } +span.image img { border-style: none; } + +dl { + margin-top: 0.8em; + margin-bottom: 0.8em; +} +dt { + margin-top: 0.5em; + margin-bottom: 0; + font-style: normal; +} +dd > *:first-child { + margin-top: 0.1em; +} + +ul, ol { + list-style-position: outside; +} +div.olist > ol { + list-style-type: decimal; +} +div.olist2 > ol { + list-style-type: lower-alpha; +} + +div.tableblock > table { + border: 3px solid #527bbd; +} +thead { + font-family: sans-serif; + font-weight: bold; +} +tfoot { + font-weight: bold; +} + +div.hlist { + margin-top: 0.8em; + margin-bottom: 0.8em; +} +div.hlist td { + padding-bottom: 15px; +} +td.hlist1 { + vertical-align: top; + font-style: normal; + padding-right: 0.8em; +} +td.hlist2 { + vertical-align: top; +} + +@media print { + div#footer-badges { display: none; } +} + +div#toctitle { + color: #527bbd; + font-family: sans-serif; + font-size: 1.1em; + font-weight: bold; + margin-top: 1.0em; + margin-bottom: 0.1em; +} + +div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { + margin-top: 0; + margin-bottom: 0; +} +div.toclevel2 { + margin-left: 2em; + font-size: 0.9em; +} +div.toclevel3 { + margin-left: 4em; + font-size: 0.9em; +} +div.toclevel4 { + margin-left: 6em; + font-size: 0.9em; +} diff --git a/www/web/userguide.html b/www/web/userguide.html new file mode 100644 index 0000000..e05587e --- /dev/null +++ b/www/web/userguide.html @@ -0,0 +1,357 @@ + + + + + + + + + + +llvm-py User Guide - llvm-py + + +
+
llvm-py
+
Python Bindings for LLVM
+
+ + + + + +
+
»Home
+
»Examples
+
»Download
+
»User Guide
+
»Contribute
+
»License
+
»About
+ +
»LLVM
+
+
+ +
+
+

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.

+
+
+

Introduction

+
+

LLVM (Low-Level Virtual Machine) provides enough +infrastructure to use it as the backend for your compiled, or +JIT-compiled language. It provides extensive optimization support, and +static and dynamic (JIT) backends for many platforms. See the website at +http://www.llvm.org/ to discover more.

+

Python bindings for LLVM provides a gentler learning curve for working +with the LLVM APIs. It should also prove easier to create working +prototypes and experimental languages using this medium.

+
License
+

Both LLVM and llvm-py are distributed under (different) permissive +open source licenses. llvm-py uses the +new BSD license. More +information is available 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.

+
Versions
+

As of now, llvm-py requires the latest SVN version of LLVM. It will +not work with version 2.2 of LLVM. However, 2.3 should be release soon, +and llvm-py should work with stock 2.3 LLVM.

+

llvm-py has been built and tested with Python 2.5. It should work with +Python 2.4, with minimal changes, if any.

+
+

Installation

+
+

llvm-py is distributed as a source tarball. You'll need to build and +install it before it can be used. At least the following will be +required for this:

+
    +
  • +

    +compilers, both gcc and g++ +

    +
  • +
  • +

    +Python itself +

    +
  • +
  • +

    +Python development files (headers and libraries) +

    +
  • +
  • +

    +LLVM, either installed or built +

    +
  • +
+

On debian-based systems, the first three can be installed with the +command `sudo apt-get install gcc g++ python python-dev'. Note that +ubuntu repository has an old version of llvm (1.8) which will not work +with llvm-py.

+

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.

+

Steps

+

The commands illustrated below assume that the LLVM source is available +under /home/mdevan/llvm. If you've a previous version of llvm-py +installed, you must remove it first, as described +below.

+

If you have llvm-config in your path, you can build and install +llvm-py this way:

+
+
+
$ tar jxvf llvm-py-0.2.tar.bz2
+$ cd llvm-py-0.2
+$ sudo python setup.py install
+
+

If you need to tell the build script where llvm-config is, do it this +way:

+
+
+
$ tar jxvf llvm-py-0.2.tar.bz2
+$ cd llvm-py-0.2
+$ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config
+
+

To build a debug version of llvm-py, that links against the debug +libraries of LLVM, use this:

+
+
+
$ tar jxvf llvm-py-0.2.tar.bz2
+$ cd llvm-py-0.2
+$ python setup.py build -g --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config
+$ sudo python setup.py install -g --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config
+
+

Be warned that debug binaries will be huge (65MB+) !

+

Uninstall

+

To get rid of llvm-py completely, if you wish to do so:

+
+
+
# rm -rf /usr/lib/python2.5/site-packages/llvm
+# rm -f /usr/lib/python2.5/site-packages/llvm_py-0.1.egg-info
+
+
    +
  • +

    +You need to be root to do this. +

    +
  • +
  • +

    +Paths are for debian-based systems, in other distros it might be different. +

    +
  • +
  • +

    +Note that there are version numbers (both Python's and llvm-py's) + which you might need to change to suit your system. +

    +
  • +
+
+

The Concepts

+
+

This section explains a few concepts related to LLVM.

+

Intermediate Representation

+

The intermediate representation, or IR for short, is an in-memory data +structure that represents executable code. The IR data structures allow +for creation of types, constants, functions, function arguments, +instructions, global variables and so on. For example, to create a +function sum that takes two integers and returns their sum, we need to +follow these steps:

+
    +
  • +

    +create an integer type ti of required bitwidth +

    +
  • +
  • +

    +create a function type tf which takes two ti -s and returns + another ti +

    +
  • +
  • +

    +create a function of type tf named sum +

    +
  • +
  • +

    +add a basic block to the function +

    +
  • +
  • +

    +using a helper object called an instruction builder, add two + instructions into the basic block: +

    +
      +
    1. +

      +an instruction to add the two arguments and store the result into + a temporary variable +

      +
    2. +
    3. +

      +a return instruction to return the value of the temporary variable +

      +
    4. +
    +
  • +
+

(A basic block is a block of instructions.)

+

LLVM has it's own instruction set; the instructions used above (add +and ret) are from this set. The LLVM instructions are at a higher +level than the usual assembly language; for example there are +instructions related to variable argument handling, exception handling, +and garbage collection. These allow high-level languages to be +represented cleanly in the IR.

+

The full set of instructions are:

+

TODO

+

SSA Form and PHI Nodes

+

All LLVM instructions are represented in the Static Single Assignment +(SSA) form. Essentially, this means that any variable can be assigned to +only once. Such a representation facilitates better optimization, among +other benefits.

+

A consequence of single assignment are PHI (Φ) nodes. These +are required when a variable can be assigned a different value based on +the path of control flow. For example, the value of b at the end of +execution of the snippet below:

+
+
+
a = 1;
+if (v < 10)
+  a = 2;
+b = a;
+
+

cannot be determined statically. The value of 2 cannot be assigned to +the original a, since a can be assigned to only once. There are +two a 's in there, and the last assignment has to choose between which +version to pick. This is accomplished by adding a PHI node:

+
+
+
a1 = 1;
+if (v < 10)
+  a2 = 2;
+b = PHI(a1, a2);
+
+

The PHI node selects a1 or a2, depending on where the control +reached the PHI node. The argument a1 of the PHI node is associated +with the block "a1 = 1;" and a2 with the block "a2 = 2;".

+

PHI nodes have to be explicitly created in the LLVM IR. The LLVM +instruction set therefore has an instruction called phi.

+

LLVM Assembly Language

+

The LLVM IR can be represented offline in two formats +- a textual, human-readable form, similar to assembly language, called + the LLVM assembly language (files with .ll extension) (XXX ?) +- a binary form, called the LLVM bitcode (files with .bc extension) +All three formats (the in-memory IR, the LLVM assembly language and the +LLVM bitcode) represent the same information. Each format can be +converted into the other two formats (using LLVM APIs).

+

The LLVM demo page lets you type in C or C++ +code, converts it into LLVM IR and outputs the IR as LLVM assembly +language code.

+

Here's a function in C, that calculates the sum of the first n +fibonacci numbers:

+
+
+
int fibsum(int n)
+{
+}
+
+

And here's the corresponding LLVM assembly listing, as provided by the +demo page:

+
+
+
+
+

Note the … TODO …

+

The LLVM Language Reference +defines the LLVM assembly language including the entire instruction set.

+

Modules

+

Modules, in the LLVM IR, are similar to a single C language source +file (.c file). A module contains:

+
    +
  • +

    +functions (declarations and definitions) +

    +
  • +
  • +

    +global variables and constants +

    +
  • +
  • +

    +global type aliases (typedef-s) +

    +
  • +
+

Modules are top-level containers; all executable code representation is +contained within modules.

+

Optimization and Passes

+

LLVM provides quite a few optimization algorithms that work on the IR. +These algorithms are organized as passes. Each pass does something +specific, like combining redundant instructions. Passes need not always +optimize the IR, it can also do other operations like inserting +instrumentation code, or analysing the IR (the result of which can be +used by passes that do optimizations) or even printing call graphs.

+

This LLVM documentation page +describes all the available passes, and what they do.

+

LLVM does not automatically choose to run any passes, anytime. Passes +have to be explicitly selected and run on each module. This gives you +the flexibility to choose transformations and optimizations that are +most suitable for the code in the module.

+

There is a LLVM binary called opt, +which lets you run passes on 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. (Although llvm-py does not allow you to +write your own passes, it does allow you to navigate the entire IR at +any stage, and perform any transforms on it as you like.)

+

Passes are run using a pass manager. For our purposes, there are two

+

Execution Engine

+

TODO

+

BitCode

+

TODO

+

llvm-gcc

+

TODO

+
+

The llvm-py Package

+
+

modules overview: llvm, llvm.core, llvm.ee, llvm.passes

+

importing modules

+

core:

+

types

+

constants

+

values

+
+ +
+
+ +