Merge branch 'docs-fixes' of github.com:pfalcon/llvmpy into _pr57
This commit is contained in:
commit
cada51e297
26 changed files with 163 additions and 18 deletions
|
|
@ -11,12 +11,22 @@
|
||||||
# All configuration values have a default; values that are commented out
|
# All configuration values have a default; values that are commented out
|
||||||
# serve to show the default.
|
# serve to show the default.
|
||||||
|
|
||||||
import sys, os
|
import sys, os, glob
|
||||||
|
|
||||||
# If extensions (or modules to document with autodoc) are in another directory,
|
# If extensions (or modules to document with autodoc) are in another directory,
|
||||||
# add these directories to sys.path here. If the directory is relative to the
|
# add these directories to sys.path here. If the directory is relative to the
|
||||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||||
#sys.path.insert(0, os.path.abspath('.'))
|
#sys.path.insert(0, os.path.abspath('../..'))
|
||||||
|
|
||||||
|
# Support sphinx.ext.autodoc to extract docstrings from modules without installing
|
||||||
|
# complete package.
|
||||||
|
# The python modules depend on _core, so we must build entire package first though.
|
||||||
|
built_lib = glob.glob('../../build/lib.*/')
|
||||||
|
if not built_lib:
|
||||||
|
print "WARNING: To build complete documentation you must build package first"
|
||||||
|
else:
|
||||||
|
# lib dir has platform suffix
|
||||||
|
sys.path.insert(0, os.path.abspath(built_lib[0]))
|
||||||
|
|
||||||
# -- General configuration -----------------------------------------------------
|
# -- General configuration -----------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
A More Complicated Function
|
A More Complicated Function
|
||||||
====================
|
===========================
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ Written by `Chris Lattner <mailto:sabre@nondot.org>`_ and `Max
|
||||||
Shawabkeh <http://max99x.com>`_
|
Shawabkeh <http://max99x.com>`_
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
=========
|
============
|
||||||
|
|
||||||
Welcome to the "Implementing a language with LLVM" tutorial. This
|
Welcome to the "Implementing a language with LLVM" tutorial. This
|
||||||
tutorial runs through the implementation of a simple language, showing
|
tutorial runs through the implementation of a simple language, showing
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ variables is a useful thing regardless of whether you will be mutating
|
||||||
them. Here's a motivating example that shows how we could use these:
|
them. Here's a motivating example that shows how we could use these:
|
||||||
|
|
||||||
|
|
||||||
.. code-block::
|
.. code-block:: none
|
||||||
|
|
||||||
# Define ':' for sequencing: as a low-precedence operator that ignores operands
|
# Define ':' for sequencing: as a low-precedence operator that ignores operands
|
||||||
# and just returns the RHS.
|
# and just returns the RHS.
|
||||||
|
|
@ -352,7 +352,7 @@ function that ensures that the allocas are created in the entry block of
|
||||||
the function:
|
the function:
|
||||||
|
|
||||||
|
|
||||||
.. code-block::
|
.. code-block:: python
|
||||||
|
|
||||||
# Creates an alloca instruction in the entry block of the function. This is used
|
# Creates an alloca instruction in the entry block of the function. This is used
|
||||||
# for mutable variables.
|
# for mutable variables.
|
||||||
|
|
@ -475,7 +475,7 @@ It is interesting to see what the code looks like before and after the
|
||||||
mem2reg optimization runs. For example, this is the before/after code
|
mem2reg optimization runs. For example, this is the before/after code
|
||||||
for our recursive fib function. Before the optimization:
|
for our recursive fib function. Before the optimization:
|
||||||
|
|
||||||
.. code-block::
|
.. code-block:: llvm
|
||||||
|
|
||||||
define double @fib(double %x) {
|
define double @fib(double %x) {
|
||||||
entry:
|
entry:
|
||||||
|
|
@ -515,7 +515,7 @@ still just make the PHI.
|
||||||
|
|
||||||
Here is the code after the mem2reg pass runs:
|
Here is the code after the mem2reg pass runs:
|
||||||
|
|
||||||
.. code-block::
|
.. code-block:: llvm
|
||||||
|
|
||||||
define double @fib(double %x) {
|
define double @fib(double %x) {
|
||||||
entry:
|
entry:
|
||||||
|
|
@ -651,7 +651,7 @@ Now that we have an assignment operator, we can mutate loop variables
|
||||||
and arguments. For example, we can now run code like this:
|
and arguments. For example, we can now run code like this:
|
||||||
|
|
||||||
|
|
||||||
.. code-block::
|
.. code-block:: none
|
||||||
|
|
||||||
# Function to print a double.
|
# Function to print a double.
|
||||||
extern printd(x)
|
extern printd(x)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
*************************************************
|
***************************************************
|
||||||
Chapter 8: Conclusion and other useful LLVM tidbits
|
Chapter 8: Conclusion and other useful LLVM tidbits
|
||||||
*************************************************
|
***************************************************
|
||||||
|
|
||||||
Written by Chris Lattner
|
Written by Chris Lattner
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ generating LLVM IR. These are some of the more subtle things that may not be obv
|
||||||
but are very useful if you want to take advantage of LLVM's capabilities.
|
but are very useful if you want to take advantage of LLVM's capabilities.
|
||||||
|
|
||||||
Properties of the LLVM IR
|
Properties of the LLVM IR
|
||||||
========================
|
=========================
|
||||||
|
|
||||||
We have a couple common questions about code in the LLVM IR form - let's
|
We have a couple common questions about code in the LLVM IR form - let's
|
||||||
just get these out of the way right now, shall we?
|
just get these out of the way right now, shall we?
|
||||||
|
|
@ -164,7 +164,7 @@ This can make sense for specialized domains such as an in-kernel language.
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Safety Guarantees
|
Safety Guarantees
|
||||||
----------------
|
-----------------
|
||||||
|
|
||||||
Many of the languages above are also "safe" languages: it is
|
Many of the languages above are also "safe" languages: it is
|
||||||
impossible for a program written in Java to corrupt its address space and
|
impossible for a program written in Java to corrupt its address space and
|
||||||
|
|
@ -236,7 +236,7 @@ you desire in your front-end, on the language-specific AST.
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Tips and Tricks
|
Tips and Tricks
|
||||||
==============
|
===============
|
||||||
|
|
||||||
There is a variety of useful tips and tricks that you come to
|
There is a variety of useful tips and tricks that you come to
|
||||||
know after working on/with LLVM that aren't obvious at first glance.
|
know after working on/with LLVM that aren't obvious at first glance.
|
||||||
|
|
|
||||||
|
|
@ -56,3 +56,10 @@ Add an attribute ``attr`` to the argument, from the set listed above.
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Remove the attribute ``attr`` of the argument.
|
Remove the attribute ``attr`` of the argument.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Argument
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -28,3 +28,10 @@ A ``Type`` object representing the type of the element of the array.
|
||||||
[read-only]
|
[read-only]
|
||||||
|
|
||||||
The number of elements in the array.
|
The number of elements in the array.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.ArrayType
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -42,3 +42,10 @@ The parent function of this basicblock.
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
A list of instructions in this basicblock.
|
A list of instructions in this basicblock.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.BasicBlock
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -409,3 +409,10 @@ positioned.
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
Deprecated. Same as ``basic_block``
|
Deprecated. Same as ``basic_block``
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Builder
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@
|
||||||
| title: Constant (llvm.core) |
|
| title: Constant (llvm.core) |
|
||||||
+-------------------------------+
|
+-------------------------------+
|
||||||
|
|
||||||
|
llvm.core.Constant
|
||||||
|
==================
|
||||||
|
|
||||||
``Constant``-s represents constants that appear within the code. The
|
``Constant``-s represents constants that appear within the code. The
|
||||||
values of such objects are known at creation time. Constants can be
|
values of such objects are known at creation time. Constants can be
|
||||||
created from Python constants. A constant expression is also a constant
|
created from Python constants. A constant expression is also a constant
|
||||||
|
|
@ -351,3 +354,9 @@ some examples:
|
||||||
|
|
||||||
assert isinstance(k1, ConstantInt) assert isinstance(k2, ConstantArray)
|
assert isinstance(k1, ConstantInt) assert isinstance(k2, ConstantArray)
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Constant
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -149,3 +149,10 @@ function bodies.
|
||||||
|
|
||||||
Verifies the function. See `LLVM
|
Verifies the function. See `LLVM
|
||||||
docs <http://llvm.org/docs/Passes.html#verify>`_.
|
docs <http://llvm.org/docs/Passes.html#verify>`_.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Function
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -46,3 +46,10 @@ the function. Used like this:
|
||||||
Type.int(), Type.int() ] ) for arg in func_type.args: assert arg.kind
|
Type.int(), Type.int() ] ) for arg in func_type.args: assert arg.kind
|
||||||
== TYPE_INTEGER assert arg == Type.int() assert func_type.arg_count
|
== TYPE_INTEGER assert arg == Type.int() assert func_type.arg_count
|
||||||
== len(func_type.args)
|
== len(func_type.args)
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.FunctionType
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -95,3 +95,9 @@ A power-of-2 integer indicating the boundary to align to.
|
||||||
|
|
||||||
The module object to which this global belongs to.
|
The module object to which this global belongs to.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.GlobalValue
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@
|
||||||
| title: GlobalVariable (llvm.core) |
|
| title: GlobalVariable (llvm.core) |
|
||||||
+-------------------------------------+
|
+-------------------------------------+
|
||||||
|
|
||||||
|
llvm.core.GlobalVariable
|
||||||
|
========================
|
||||||
|
|
||||||
Global variables (``llvm.core.GlobalVariable``) are subclasses of
|
Global variables (``llvm.core.GlobalVariable``) are subclasses of
|
||||||
`llvm.core.GlobalValue <llvm.core.GlobalValue.html>`_ and represent
|
`llvm.core.GlobalValue <llvm.core.GlobalValue.html>`_ and represent
|
||||||
module-level variables. These can have optional initializers and can be
|
module-level variables. These can have optional initializers and can be
|
||||||
|
|
@ -37,3 +40,10 @@ class, or by using the static method ``GlobalVariable.new``.
|
||||||
# list all global variables in a module
|
# list all global variables in a module
|
||||||
for gv in module_obj.global_variables: print gv.name, "of type",
|
for gv in module_obj.global_variables: print gv.name, "of type",
|
||||||
gv.type
|
gv.type
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.GlobalVariable
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -240,3 +240,10 @@ Properties
|
||||||
|
|
||||||
The predicate of the compare instruction, one of the ``ICMP_*`` or
|
The predicate of the compare instruction, one of the ``ICMP_*`` or
|
||||||
``FCMP_*`` constants.
|
``FCMP_*`` constants.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Instruction
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -21,3 +21,10 @@ Properties
|
||||||
[read-only]
|
[read-only]
|
||||||
|
|
||||||
The width of the integer type, in number of bits.
|
The width of the integer type, in number of bits.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.IntegerType
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,26 @@
|
||||||
| title: Module (llvm.core) |
|
| title: Module (llvm.core) |
|
||||||
+-----------------------------+
|
+-----------------------------+
|
||||||
|
|
||||||
|
llvm.core.Module
|
||||||
|
================
|
||||||
|
|
||||||
Modules are top-level container objects. You need to create a module
|
Modules are top-level container objects. You need to create a module
|
||||||
object first, before you can add global variables, aliases or functions.
|
object first, before you can add global variables, aliases or functions.
|
||||||
Modules are created using the static method ``Module.new``:
|
Modules are created using the static method ``Module.new``:
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from llvm import \* from llvm.core import \*
|
from llvm import *
|
||||||
|
from llvm.core import *
|
||||||
|
|
||||||
# create a module
|
# create a module
|
||||||
my_module = Module.new('my_module')
|
my_module = Module.new('my_module')
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Module
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,10 @@ The address space of the pointer.
|
||||||
|
|
||||||
A `Type <llvm.core.Type.html>`_ object representing the type of the
|
A `Type <llvm.core.Type.html>`_ object representing the type of the
|
||||||
value pointed to.
|
value pointed to.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.PointerType
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
llvm.core.StructType
|
||||||
|
====================
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.StructType
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
@ -126,3 +126,10 @@ Example:
|
||||||
|
|
||||||
assert Type.int().kind == TYPE_INTEGER assert
|
assert Type.int().kind == TYPE_INTEGER assert
|
||||||
Type.void().kind == TYPE_VOID
|
Type.void().kind == TYPE_VOID
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Type
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -37,3 +37,10 @@ The list of operands (values, of type
|
||||||
|
|
||||||
The number of operands that this value referes to. Same as
|
The number of operands that this value referes to. Same as
|
||||||
``len(uses.operands)`` but faster if you just want the count.
|
``len(uses.operands)`` but faster if you just want the count.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.User
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -63,3 +63,10 @@ representation.
|
||||||
``Value`` objects can be compared for equality. Internally, this
|
``Value`` objects can be compared for equality. Internally, this
|
||||||
converts both arguments into their LLVM assembly representations and
|
converts both arguments into their LLVM assembly representations and
|
||||||
compares the resultant strings.
|
compares the resultant strings.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.Value
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,10 @@ element of the vector.
|
||||||
[read-only]
|
[read-only]
|
||||||
|
|
||||||
The number of elements in the vector.
|
The number of elements in the vector.
|
||||||
|
|
||||||
|
|
||||||
|
Automatically Generated Documentation
|
||||||
|
-------------------------------------
|
||||||
|
.. autoclass:: llvm.core.VectorType
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
llvm_cbuilder
|
llvm_cbuilder
|
||||||
=========
|
=============
|
||||||
|
|
||||||
llvm_cbuilder is a set of Python-contexts you can use to write C-like
|
llvm_cbuilder is a set of Python-contexts you can use to write C-like
|
||||||
constructs in Python which generates llvmpy code directly.
|
constructs in Python which generates llvmpy code directly.
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ follow these steps:
|
||||||
- add a *basic block* to the function
|
- add a *basic block* to the function
|
||||||
- using a helper object called an *instruction builder*, add two
|
- using a helper object called an *instruction builder*, add two
|
||||||
instructions into the basic block:
|
instructions into the basic block:
|
||||||
|
|
||||||
- an instruction to add the two
|
- an instruction to add the two
|
||||||
arguments and store the result into a temporary variable
|
arguments and store the result into a temporary variable
|
||||||
- a return
|
- a return
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
contain the root `toctree` directive.
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
Documentation for llvmpy
|
Documentation for llvmpy
|
||||||
=================
|
========================
|
||||||
|
|
||||||
Contents:
|
Contents:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue