Execution engine and passes work. Documentation and tests updated.
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@4 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
6ee3298bd2
commit
2255a7e5dd
15 changed files with 559 additions and 396 deletions
|
|
@ -5,49 +5,7 @@ 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()
|
||||
include::../../test/example.py[]
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
which gives this output:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue