Added web pages, and some ee/passes stuff. *Broken*.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@3 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-06-03 17:24:46 +00:00
commit 6ee3298bd2
46 changed files with 1120 additions and 8 deletions

67
www/src/examples.txt Normal file
View file

@ -0,0 +1,67 @@
Examples
========
Here's an example:
[python]
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/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 temp1
temp1 = builder.add(func.args[0], func.args[1], "temp1")
# sub `1' from that
one = Constant.real( ty_double, 1.0 )
temp2 = builder.sub(temp1, one, "temp2")
# convert to integer
temp3 = builder.fptoui(temp2, ty_int, "temp3")
# return it
builder.ret(temp3)
# dump the module to see the bc
module.dump()
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
}
-----------------------------------------------------------------------