Patch for OpenBSD, x86_64 support (Laurence Tratt)

Added JIT tutorial ports (Sebastien Binet)
Updated documentation

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@23 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-07-05 06:33:51 +00:00
commit df4365921d
20 changed files with 501 additions and 74 deletions

31
test/JITTutorial1.py Normal file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
from llvm.core import *
# create a module
module = Module.new ("tut1")
# create a function type taking 3 32-bit integers, return a 32-bit integer
ty_int = Type.int (32)
func_type = Type.function (ty_int, (ty_int,)*3)
# create a function of that type
mul_add = Function.new (module, func_type, "mul_add")
mul_add.calling_convention = CC_C
x = mul_add.args[0]; x.name = "x"
y = mul_add.args[1]; y.name = "y"
z = mul_add.args[2]; z.name = "z"
# implement the function
# new block
blk = mul_add.append_basic_block ("entry")
# IR builder
bldr = Builder.new (blk)
tmp_1 = bldr.mul (x, y, "tmp_1")
tmp_2 = bldr.add (tmp_1, z, "tmp_2")
bldr.ret (tmp_2)
print module

50
test/JITTutorial2.py Normal file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env python
from llvm.core import *
# create a module
module = Module.new ("tut2")
# create a function type taking 2 integers, return a 32-bit integer
ty_int = Type.int (32)
func_type = Type.function (ty_int, (ty_int, ty_int))
# create a function of that type
gcd = Function.new (module, func_type, "gcd")
# name function args
x = gcd.args[0]; x.name = "x"
y = gcd.args[1]; y.name = "y"
# implement the function
# blocks...
entry = gcd.append_basic_block ("entry")
ret = gcd.append_basic_block ("return")
cond_false = gcd.append_basic_block ("cond_false")
cond_true = gcd.append_basic_block ("cond_true")
cond_false_2 = gcd.append_basic_block ("cond_false_2")
# create a llvm::IRBuilder
bldr = Builder.new (entry)
x_eq_y = bldr.icmp (IPRED_EQ, x, y, "tmp")
bldr.cbranch (x_eq_y, ret, cond_false)
bldr.position_at_end (ret)
bldr.ret(x)
bldr.position_at_end (cond_false)
x_lt_y = bldr.icmp (IPRED_ULT, x, y, "tmp")
bldr.cbranch (x_lt_y, cond_true, cond_false_2)
bldr.position_at_end (cond_true)
y_sub_x = bldr.sub (y, x, "tmp")
recur_1 = bldr.call (gcd, (x, y_sub_x,), "tmp")
bldr.ret (recur_1)
bldr.position_at_end (cond_false_2)
x_sub_y = bldr.sub (x, y, "x_sub_y")
recur_2 = bldr.call (gcd, (x_sub_y, y,), "tmp")
bldr.ret (recur_2)
print module

19
test/typehandle.py Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
from llvm.core import *
# create a type handle object
th = TypeHandle.new(Type.opaque())
# create the struct with an opaque* instead of self*
ts = Type.struct([ Type.int(), Type.pointer(th.type) ])
# unify the types
th.type.refine(ts)
# create a module, and add a "typedef"
m = Module.new('mod1')
m.add_type_name("struct.node", th.type)
# show what we created
print m