$ svn checkout http://llvm-py.googlecode.com/svn/trunk/ llvm-py+
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 @@ + + +
+ + + + + + + +|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+About+
+
+
+
+
+
+
+
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. + |
+
|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+Contribute+
+
+
+
+
+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. + |
+
|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+Download and Setup+
+
+
+
+The latest release is 0.2, released xx-Jun-2008 (full Changelog +below). +Download it here: +
+
+
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: +
+
+
+ $ wget http://link/llvm-py-0.2.tar.bz2 +$ tar jxvf llvm-py-0.2.tar.bz2+
+
+
+ $ cd llvm-py-0.2 +$ sudo python setup.py install+
+
+
+ $ cd llvm-py-0.2 +$ sudo python setup.py install --llvm-config=/path/to/llvm-config+ That's it! +Notes:
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+
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) ++ |
+
|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+Examples+
+
+
+
+
+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
+}
+ |
+
|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+llvm-py: Python Bindings for 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+
+
+
+
|
+
|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+License+
+
+
+
+
+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.+ |
+
|
+ »Home
+
+
+
+
+
+
+
+ »LLVM
+ |
+
+
+
+
+
+llvm-py User Guide+
+
+
+
+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: +
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+
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: +
(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: +
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 + |
+