From 6d57b0e5bcf050eaef0e80303494383d939f8609 Mon Sep 17 00:00:00 2001 From: "mdevan.foobar" Date: Tue, 22 Jul 2008 08:50:40 +0000 Subject: [PATCH] Revamped makeweb.py script; docs regenerated. git-svn-id: http://llvm-py.googlecode.com/svn/trunk@26 8d1e9007-1d4e-0410-b67e-1979fd6579aa --- CHANGELOG | 2 + www/makeweb.py | 159 ++++++++++++++++++++----------- www/src/examples.txt | 4 +- www/web/about.html | 2 +- www/web/contribute.html | 2 +- www/web/download.html | 4 +- www/web/examples.html | 52 +++++----- www/web/examples/JITTutorial1.py | 31 ------ www/web/examples/JITTutorial2.py | 50 ---------- www/web/index.html | 2 +- www/web/license.html | 2 +- www/web/userguide.html | 112 +++++++++++----------- 12 files changed, 198 insertions(+), 224 deletions(-) delete mode 100644 www/web/examples/JITTutorial1.py delete mode 100644 www/web/examples/JITTutorial2.py diff --git a/CHANGELOG b/CHANGELOG index 3d11116..4a1a9af 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ 0.3, in progress: + * Intrinsics added. + * JIT Tutorials ported (Sebastien Binet). * GenericValue added. Used by ExecutionEngine.run(). * Build cleanly on OpenBSD, x86-64/amd64 (Laurence Tratt). * Updated documentation. diff --git a/www/makeweb.py b/www/makeweb.py index f17df8a..3e217a7 100755 --- a/www/makeweb.py +++ b/www/makeweb.py @@ -1,21 +1,45 @@ #!/usr/bin/env python +# Usage: run "python makeweb.py src web" to update files +# under 'web'. See "python makeweb.py --help" for more options. + import os, sys, shutil from stat import * -from string import Template from optparse import OptionParser -# files in src dir that should not be copied to web dir -SKIP_FILES = [ 'layout.conf', '.svn', 'instrset.inc', 'example.inc' ] -# asciidoc command line -ASCIIDOC = 'asciidoc --unsafe --conf-file=${srcdir}/layout.conf -a icons -o ${outfile} ${infile}' +# how to process files that match various filename patterns +FILE_ACTION_TBL = [ -# specialized ASCIIDOC for certain files -# - this is a hack trying to look generic -ASCIIDOC_PERFILE = { - 'userguide.txt': ASCIIDOC.replace('-a icons', '-a icons -a toc') -} + # selector_func(infilepath) -> True|False + # output_filepath_func(outfilepath) -> outfilepath + # cmd_line_func(opts, infilepath, outfilepath) -> cmdline|None + + ( lambda f: f.endswith('.py'), + lambda o: o.replace('.py', '.html'), + lambda opts, i, o: "source-highlight --input='%s' --output='%s'" \ + % (i, o) ), + + ( lambda f: f.endswith('userguide.txt'), + lambda o: o.replace('.txt', '.html'), + lambda opts, i, o: "asciidoc --unsafe --conf-file='%s/layout.conf' -a icons -a toc -o '%s' '%s'" \ + % (opts.srcdir, o, i) ), + + ( lambda f: f.endswith('.txt'), + lambda o: o.replace('.txt', '.html'), + lambda opts, i, o: "asciidoc --unsafe --conf-file='%s/layout.conf' -a icons -o '%s' '%s'" \ + % (opts.srcdir, o, i) ), + + ( lambda f: f.endswith('layout.conf') or f.endswith('.svn') or f.endswith('.inc'), + lambda o: o, + lambda opts, i, o: None ) +] + + +# list of directories to skip +DIR_SKIP_TBL = [ + '.svn' +] def _is_older(inp, outp): @@ -31,61 +55,84 @@ def _rmtree_warn(fn, path, excinfo): print "** WARNING **: error while doing %s on %s" % (fn, path) -def asciidoc(opts, srcdir, inp, outp): - if _is_older(inp, outp) or opts.force: +def _can_skip(opts, infile, outfile): + return not _is_older(infile, outfile) and not opts.force + + +def process_file(opts, infile, outfile): + + for matchfn, outfilefn, cmdfn in FILE_ACTION_TBL: + if matchfn(infile): + outfile_actual = outfilefn(outfile) + cmd = cmdfn(opts, infile, outfile_actual) + if _can_skip(opts, infile, outfile_actual): + if opts.verbose >= 2: + print "up to date %s -> %s" % (infile, outfile_actual) + return + if cmd: + # do cmd + if opts.verbose: + print "process %s -> %s" % (infile, outfile_actual) + if opts.verbose >= 3: + print "command is [%s]" % cmd + if not opts.dryrun: + os.system(cmd) + # else if cmd is None, do nothing + return + + # nothing matched, default action is to copy + if not _can_skip(opts, infile, outfile): if opts.verbose: - print "asciidoc %s -> %s" % (inp, outp) - asciidoc = ASCIIDOC_PERFILE.get(os.path.split(inp)[-1], ASCIIDOC) - cmd = Template(asciidoc).substitute(srcdir=srcdir, infile=inp, outfile=outp) - if opts.verbose >= 3: - print "asciidoc command is [%s]" % cmd + print "copying %s -> %s" % (infile, outfile) if not opts.dryrun: - os.system(cmd) - else: - if opts.verbose >= 2: - print "up to date %s -> %s" % (inp, outp) - - -def copy(opts, inp, outp): - if os.path.isdir(inp): - if os.path.exists(outp) and not os.path.isdir(outp): - print "** ERROR **: cannot copy directory ('%s') to file ('%s')" % (inp, outp) - sys.exit(1) - if not os.path.exists(outp): - if opts.verbose: - print "creating %s" % (outp) - if not opts.dryrun: - os.mkdir(outp) - for file in os.listdir(inp): - if file not in SKIP_FILES: - copy(opts, os.path.join(inp, file), os.path.join(outp, file)) - else: - if _is_older(inp, outp) or opts.force: - if opts.verbose: - print "copying %s -> %s" % (inp, outp) - if not opts.dryrun: - shutil.copy(inp, outp) - else: - if opts.verbose >= 2: - print "up to date %s -> %s" % (inp, outp) + shutil.copy(infile, outfile) def make(opts, indir, outdir): - # make output dir if it does not exist - if not os.path.exists(outdir): + + # does outdir exists? + odexists = os.path.exists(outdir) + + # if it exists, it must be a dir! + if odexists and not os.path.isdir(outdir): + print "** WARNING **: output dir '%s' exists but is " \ + "not a dir, skipping" % outdir + return + + # make outdir if not existing + if not odexists: if opts.verbose: print "creating %s" % outdir if not opts.dryrun: os.mkdir(outdir) - # process all files/dirs under input directory + + # process indir/* -> outdir/* for elem in os.listdir(indir): inp = os.path.join(indir, elem) - if elem.endswith('.txt'): - outp = os.path.join(outdir, elem[:-4] + '.html') - asciidoc(opts, indir, inp, outp) - elif elem not in SKIP_FILES: - outp = os.path.join(outdir, elem) - copy(opts, inp, outp) + outp = os.path.join(outdir, elem) + + # process files + if os.path.isfile(inp): + if os.path.exists(outp) and not os.path.isfile(outp): + print "** WARNING **: output '%s' corresponding to " \ + "input '%s' is not a file, skipping" % (outp, inp) + else: + process_file(opts, inp, outp) + + # process directories + elif os.path.isdir(inp): + # if dir is in skip list, silently ignore + if elem in DIR_SKIP_TBL: + if opts.verbose >= 3: + print "skipping %s" % inp + continue + # just recurse + make(opts, inp, outp) + + # neither a file nor a dir + else: + print "** WARNING **: input '%s' is neither file nor " \ + "dir, skipping" % inp def get_opts(): @@ -116,6 +163,10 @@ def get_opts(): if opts.verbose == None: opts.verbose = 0 + # add srcdir and destdir also to opts + opts.srcdir = srcdir + opts.destdir = destdir + return (opts, srcdir, destdir) diff --git a/www/src/examples.txt b/www/src/examples.txt index 6f8831f..4064ec1 100644 --- a/www/src/examples.txt +++ b/www/src/examples.txt @@ -18,10 +18,10 @@ the corresponding Python code using llvm-py: 1. A First Function http://www.llvm.org/docs/tutorial/JITTutorial1.html[LLVM] - link:examples/JITTutorial1.py[llvm-py] + link:examples/JITTutorial1.html[llvm-py] 2. A More Complicated Function http://www.llvm.org/docs/tutorial/JITTutorial2.html[LLVM] - link:examples/JITTutorial2.py[llvm-py] + link:examples/JITTutorial2.html[llvm-py] .Kaleidoscope: Implementing a Language with LLVM diff --git a/www/web/about.html b/www/web/about.html index 9ce2a0e..b523b8a 100644 --- a/www/web/about.html +++ b/www/web/about.html @@ -42,7 +42,7 @@ llvm-dev mailing list and irc.oftc.net#llvm (mdevan).

diff --git a/www/web/contribute.html b/www/web/contribute.html index f9866b1..c8c0bb3 100644 --- a/www/web/contribute.html +++ b/www/web/contribute.html @@ -124,7 +124,7 @@ Improve tests. diff --git a/www/web/download.html b/www/web/download.html index 857c666..0c29274 100644 --- a/www/web/download.html +++ b/www/web/download.html @@ -121,6 +121,8 @@ package.

0.3, in progress:
 
+  * Intrinsics added.
+  * JIT Tutorials ported (Sebastian Binet).
   * GenericValue added. Used by ExecutionEngine.run().
   * Build cleanly on OpenBSD, x86-64/amd64 (Laurence Tratt).
   * Updated documentation.
@@ -156,7 +158,7 @@ package.

diff --git a/www/web/examples.html b/www/web/examples.html index dd731f3..f0257fb 100644 --- a/www/web/examples.html +++ b/www/web/examples.html @@ -41,7 +41,7 @@ to the C function:

by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
int sum(int a, int b)
+
int sum(int a, int b)
 {
     return a + b;
 }
@@ -59,20 +59,20 @@ http://www.gnu.org/software/src-highlite -->
 from llvm.core import *
 
 # Create an (empty) module.
-my_module = Module.new('my_module')
+my_module = Module.new('my_module')
 
 # All the types involved here are "int"s. This type is represented
 # by an object of the llvm.core.Type class:
-ty_int = Type.int()   # by default 32 bits
+ty_int = Type.int()   # by default 32 bits
 
 # We need to represent the class of functions that accept two integers
 # and return an integer. This is represented by an object of the
 # function type (llvm.core.FunctionType):
-ty_func = Type.function(ty_int, [ty_int, ty_int])
+ty_func = Type.function(ty_int, [ty_int, ty_int])
 
 # Now we need a function named 'sum' of this type. Functions are not
 # free-standing (in llvm-py); it needs to be contained in a module.
-f_sum = my_module.add_function(ty_func, "sum")
+f_sum = my_module.add_function(ty_func, "sum")
 
 # Let's name the function arguments as 'a' and 'b'.
 f_sum.args[0].name = "a"
@@ -81,17 +81,17 @@ f_sum.ar
 # Our function needs a "basic block" -- a set of instructions that
 # end with a terminator (like return, branch etc.). By convention
 # the first block is called "entry".
-bb = f_sum.append_basic_block("entry")
+bb = f_sum.append_basic_block("entry")
 
 # Let's add instructions into the block. For this, we need an
 # instruction builder:
-builder = Builder.new(bb)
+builder = Builder.new(bb)
 
 # OK, now for the instructions themselves. We'll create an add
 # instruction that returns the sum as a value, which we'll use
 # a ret instruction to return.
-tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
-builder.ret(tmp)
+tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
+builder.ret(tmp)
 
 # We've completed the definition now! Let's see the LLVM assembly
 # language representation of what we've created:
@@ -123,35 +123,35 @@ http://www.gnu.org/software/src-highlite -->
 from llvm.ee import *          # new import: ee = Execution Engine
 
 # Create a module, as in the previous example.
-my_module = Module.new('my_module')
-ty_int = Type.int()   # by default 32 bits
-ty_func = Type.function(ty_int, [ty_int, ty_int])
-f_sum = my_module.add_function(ty_func, "sum")
+my_module = Module.new('my_module')
+ty_int = Type.int()   # by default 32 bits
+ty_func = Type.function(ty_int, [ty_int, ty_int])
+f_sum = my_module.add_function(ty_func, "sum")
 f_sum.args[0].name = "a"
 f_sum.args[1].name = "b"
-bb = f_sum.append_basic_block("entry")
-builder = Builder.new(bb)
-tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
-builder.ret(tmp)
+bb = f_sum.append_basic_block("entry")
+builder = Builder.new(bb)
+tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
+builder.ret(tmp)
 
 # Create a module provider object first. Modules can come from
 # in-memory IRs like what we created now, or from bitcode (.bc)
 # files. The module provider abstracts this detail.
-mp = ModuleProvider.new(my_module)
+mp = ModuleProvider.new(my_module)
 
 # Create an execution engine object. This will create a JIT compiler
 # on platforms that support it, or an interpreter otherwise.
-ee = ExecutionEngine.new(mp)
+ee = ExecutionEngine.new(mp)
 
 # The arguments needs to be passed as "GenericValue" objects.
-arg1 = GenericValue.int(ty_int, 100)
-arg2 = GenericValue.int(ty_int, 42)
+arg1 = GenericValue.int(ty_int, 100)
+arg2 = GenericValue.int(ty_int, 42)
 
 # Now let's compile and run!
-retval = ee.run_function(f_sum, [arg1, arg2])
+retval = ee.run_function(f_sum, [arg1, arg2])
 
 # The return value is also GenericValue. Let's print it.
-print "returned", retval.as_int()
+print "returned", retval.as_int()
 

And here's the output:

@@ -171,14 +171,14 @@ the corresponding Python code using llvm-py:

A First Function LLVM - llvm-py + llvm-py

  • A More Complicated Function LLVM - llvm-py + llvm-py

  • @@ -228,7 +228,7 @@ Conclusion and other useful LLVM tidbits (TODO)
    diff --git a/www/web/examples/JITTutorial1.py b/www/web/examples/JITTutorial1.py deleted file mode 100644 index 294380d..0000000 --- a/www/web/examples/JITTutorial1.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 diff --git a/www/web/examples/JITTutorial2.py b/www/web/examples/JITTutorial2.py deleted file mode 100644 index ea1df8e..0000000 --- a/www/web/examples/JITTutorial2.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/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 diff --git a/www/web/index.html b/www/web/index.html index d801d50..df1defb 100644 --- a/www/web/index.html +++ b/www/web/index.html @@ -81,7 +81,7 @@ minimal changes, if any.

    diff --git a/www/web/license.html b/www/web/license.html index 64bb49a..b33edbd 100644 --- a/www/web/license.html +++ b/www/web/license.html @@ -74,7 +74,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    diff --git a/www/web/userguide.html b/www/web/userguide.html index bf8a955..881cba2 100644 --- a/www/web/userguide.html +++ b/www/web/userguide.html @@ -49,7 +49,7 @@ window.onload = function(){generateToc(2)} Note -

    This document is updated frequently (last updated on 05-Jul-2008). +

    This document is updated frequently (last updated on 21-Jul-2008). Check back often.

    @@ -301,12 +301,12 @@ by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite -->
    /* compute sum of 1..n */
    -unsigned sum(unsigned n)
    +unsigned sum(unsigned n)
     {
       if (n == 0)
         return 0;
       else
    -    return n + sum(n-1);
    +    return n + sum(n-1);
     }
     

    The corresponding LLVM assembly:

    @@ -758,7 +758,7 @@ http://www.gnu.org/software/src-highlite --> from llvm.core import * # create a module -my_module = Module.new('my_module') +my_module = Module.new('my_module')

    The constructor of the Module class should not be used to instantiate a Module object. This is a common feature for all llvm-py classes.

    @@ -1292,8 +1292,8 @@ http://www.gnu.org/software/src-highlite --> by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
    assert Type.int().kind == TYPE_INTEGER
    -assert Type.void().kind == TYPE_VOID
    +
    assert Type.int().kind == TYPE_INTEGER
    +assert Type.void().kind == TYPE_VOID
     
    @@ -1392,11 +1392,11 @@ http://www.gnu.org/software/src-highlite --> by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
    func_type = Type.function( Type.int(), [ Type.int(), Type.int() ] )
    +
    func_type = Type.function( Type.int(), [ Type.int(), Type.int() ] )
     for arg in func_type.args:
         assert arg.kind == TYPE_INTEGER
    -    assert arg == Type.int()
    -assert func_type.arg_count == len(func_type.args)
    +    assert arg == Type.int()
    +assert func_type.arg_count == len(func_type.args)
     
    @@ -1442,11 +1442,11 @@ http://www.gnu.org/software/src-highlite --> by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
    struct_type = Type.struct( [ Type.int(), Type.int() ] )
    +
    struct_type = Type.struct( [ Type.int(), Type.int() ] )
     for elem in struct_type.elements:
         assert elem.kind == TYPE_INTEGER
    -    assert elem == Type.int()
    -assert struct_type.element_count == len(struct_type.elements)
    +    assert elem == Type.int()
    +assert struct_type.element_count == len(struct_type.elements)
     
    @@ -1555,35 +1555,35 @@ http://www.gnu.org/software/src-highlite -->
    #!/usr/bin/env python
     
     # integers
    -int_ty      = Type.int()
    -bool_ty     = Type.int(1)
    -int_64bit   = Type.int(64)
    +int_ty      = Type.int()
    +bool_ty     = Type.int(1)
    +int_64bit   = Type.int(64)
     
     # floats
    -sprec_real  = Type.float()
    -dprec_real  = Type.double()
    +sprec_real  = Type.float()
    +dprec_real  = Type.double()
     
     # arrays and vectors
    -intar_ty    = Type.array( int_ty, 10 )     # "typedef int intar_ty[10];"
    -twodim      = Type.array( intar_ty , 10 )  # "typedef int twodim[10][10];"
    -vec         = Type.array( int_ty, 10 )
    +intar_ty    = Type.array( int_ty, 10 )     # "typedef int intar_ty[10];"
    +twodim      = Type.array( intar_ty , 10 )  # "typedef int twodim[10][10];"
    +vec         = Type.array( int_ty, 10 )
     
     # structures
    -s1_ty       = Type.struct( [ int_ty, sprec_real ] )
    +s1_ty       = Type.struct( [ int_ty, sprec_real ] )
         # "struct s1_ty { int v1; float v2; };"
     
     # pointers
    -intptr_ty   = Type.pointer(int_ty)         # "typedef int *intptr_ty;"
    +intptr_ty   = Type.pointer(int_ty)         # "typedef int *intptr_ty;"
     
     # functions
    -f1 = Type.function( int_ty, [ int_ty ] )
    +f1 = Type.function( int_ty, [ int_ty ] )
         # functions that take 1 int_ty and return 1 int_ty
     
    -f2 = Type.function( Type.void(), [ int_ty ] )
    +f2 = Type.function( Type.void(), [ int_ty ] )
         # functions that take 1 int_ty and return nothing
     
    -fnargs = [ Type.pointer( Type.int(8) ) ]
    -printf = Type.function( Type.int(), fnargs, True )
    +fnargs = [ Type.pointer( Type.int(8) ) ]
    +printf = Type.function( Type.int(), fnargs, True )
         # variadic function
     

    Values (llvm.core)

    @@ -1673,15 +1673,15 @@ http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite -->
    #!/usr/bin/env python
     
    -ti = Type.int()                         # a 32-bit int type
    +ti = Type.int()                         # a 32-bit int type
     
    -k1 = Constant.int(ti, 42)               # "int k1 = 42;"
    -k2 = k1.add( Constant.int( ti, 10 ) )   # "int k2 = k1 + 10;"
    +k1 = Constant.int(ti, 42)               # "int k1 = 42;"
    +k2 = k1.add( Constant.int( ti, 10 ) )   # "int k2 = k1 + 10;"
     
    -tr = Type.float()
    +tr = Type.float()
     
    -r1 = Constant.real(tr, "3.141592")      # create from a string
    -r2 = Constant.real(tr, 1.61803399)      # create from a Python float
    +r1 = Constant.real(tr, "3.141592")      # create from a string
    +r2 = Constant.real(tr, 1.61803399)      # create from a Python float
     

    The following constructors (static methods) can be used to create constants:

    @@ -2491,7 +2491,7 @@ to the C function:

    by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
    int sum(int a, int b)
    +
    int sum(int a, int b)
     {
         return a + b;
     }
    @@ -2509,20 +2509,20 @@ http://www.gnu.org/software/src-highlite -->
     from llvm.core import *
     
     # Create an (empty) module.
    -my_module = Module.new('my_module')
    +my_module = Module.new('my_module')
     
     # All the types involved here are "int"s. This type is represented
     # by an object of the llvm.core.Type class:
    -ty_int = Type.int()   # by default 32 bits
    +ty_int = Type.int()   # by default 32 bits
     
     # We need to represent the class of functions that accept two integers
     # and return an integer. This is represented by an object of the
     # function type (llvm.core.FunctionType):
    -ty_func = Type.function(ty_int, [ty_int, ty_int])
    +ty_func = Type.function(ty_int, [ty_int, ty_int])
     
     # Now we need a function named 'sum' of this type. Functions are not
     # free-standing (in llvm-py); it needs to be contained in a module.
    -f_sum = my_module.add_function(ty_func, "sum")
    +f_sum = my_module.add_function(ty_func, "sum")
     
     # Let's name the function arguments as 'a' and 'b'.
     f_sum.args[0].name = "a"
    @@ -2531,17 +2531,17 @@ f_sum.ar
     # Our function needs a "basic block" -- a set of instructions that
     # end with a terminator (like return, branch etc.). By convention
     # the first block is called "entry".
    -bb = f_sum.append_basic_block("entry")
    +bb = f_sum.append_basic_block("entry")
     
     # Let's add instructions into the block. For this, we need an
     # instruction builder:
    -builder = Builder.new(bb)
    +builder = Builder.new(bb)
     
     # OK, now for the instructions themselves. We'll create an add
     # instruction that returns the sum as a value, which we'll use
     # a ret instruction to return.
    -tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
    -builder.ret(tmp)
    +tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
    +builder.ret(tmp)
     
     # We've completed the definition now! Let's see the LLVM assembly
     # language representation of what we've created:
    @@ -2573,35 +2573,35 @@ http://www.gnu.org/software/src-highlite -->
     from llvm.ee import *          # new import: ee = Execution Engine
     
     # Create a module, as in the previous example.
    -my_module = Module.new('my_module')
    -ty_int = Type.int()   # by default 32 bits
    -ty_func = Type.function(ty_int, [ty_int, ty_int])
    -f_sum = my_module.add_function(ty_func, "sum")
    +my_module = Module.new('my_module')
    +ty_int = Type.int()   # by default 32 bits
    +ty_func = Type.function(ty_int, [ty_int, ty_int])
    +f_sum = my_module.add_function(ty_func, "sum")
     f_sum.args[0].name = "a"
     f_sum.args[1].name = "b"
    -bb = f_sum.append_basic_block("entry")
    -builder = Builder.new(bb)
    -tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
    -builder.ret(tmp)
    +bb = f_sum.append_basic_block("entry")
    +builder = Builder.new(bb)
    +tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
    +builder.ret(tmp)
     
     # Create a module provider object first. Modules can come from
     # in-memory IRs like what we created now, or from bitcode (.bc)
     # files. The module provider abstracts this detail.
    -mp = ModuleProvider.new(my_module)
    +mp = ModuleProvider.new(my_module)
     
     # Create an execution engine object. This will create a JIT compiler
     # on platforms that support it, or an interpreter otherwise.
    -ee = ExecutionEngine.new(mp)
    +ee = ExecutionEngine.new(mp)
     
     # The arguments needs to be passed as "GenericValue" objects.
    -arg1 = GenericValue.int(ty_int, 100)
    -arg2 = GenericValue.int(ty_int, 42)
    +arg1 = GenericValue.int(ty_int, 100)
    +arg2 = GenericValue.int(ty_int, 42)
     
     # Now let's compile and run!
    -retval = ee.run_function(f_sum, [arg1, arg2])
    +retval = ee.run_function(f_sum, [arg1, arg2])
     
     # The return value is also GenericValue. Let's print it.
    -print "returned", retval.as_int()
    +print "returned", retval.as_int()
     

    And here's the output:

    @@ -2633,7 +2633,7 @@ reached at mdevan.foobar@gmail.com.