Minor formatting changes to docs.

This commit is contained in:
Maggie Mari 2012-08-15 18:44:55 -05:00
commit 4bd7c31939

View file

@ -34,8 +34,7 @@ First we define code generation methods in each AST node class:
.. code-block:: python .. code-block:: python
# Expression class for numeric literals like # Expression class for numeric literals like "1.0".
"1.0".
class NumberExpressionNode(ExpressionNode): class NumberExpressionNode(ExpressionNode):
def __init__(self, value): def __init__(self, value):
@ -57,6 +56,8 @@ First we define code generation methods in each AST node class:
The ``CodeGen`` method says to emit IR for that AST node along with all The ``CodeGen`` method says to emit IR for that AST node along with all
the things it depends on, and they all return an LLVM Value object. the things it depends on, and they all return an LLVM Value object.
"Value" is the class used to represent a "`Static Single Assignment "Value" is the class used to represent a "`Static Single Assignment
@ -87,6 +88,8 @@ during code generation:
``g_llvm_module`` is the LLVM construct that contains all of the ``g_llvm_module`` is the LLVM construct that contains all of the
functions and global variables in a chunk of code. In many ways, it is functions and global variables in a chunk of code. In many ways, it is
the top-level structure that the LLVM IR uses to contain code. the top-level structure that the LLVM IR uses to contain code.
@ -127,6 +130,8 @@ First we'll do numeric literals:
In llvmpy, floating point numeric constants are represented with the In llvmpy, floating point numeric constants are represented with the
``llvm.core.ConstantFP`` class. To create one, we can use the static ``llvm.core.ConstantFP`` class. To create one, we can use the static
``real()`` method in the ``llvm.core.Constant`` class. This code ``real()`` method in the ``llvm.core.Constant`` class. This code
@ -305,8 +310,8 @@ the function call code above.
.. code-block:: python .. code-block:: python
# If the name conflicted, there was already # If the name conflicted, there was already something with the same name.
something with the same name. # If it has a body, don't allow redefinition or reextern. # If it has a body, don't allow redefinition or reextern.
if function.name != self.name: if function.name != self.name:
function.delete() function.delete()
function = g_llvm_module.get_function_named(self.name) function = g_llvm_module.get_function_named(self.name)
@ -407,17 +412,23 @@ LLVM Function object that is ready to go for us.
block = function.append_basic_block('entry') block = function.append_basic_block('entry')
global g_llvm_builder g_llvm_builder = Builder.new(block) global g_llvm_builder g_llvm_builder = Builder.new(block)
Now we get to the point where ``g_llvm_builder`` is set up. The first
line creates a new `basic
block <http://en.wikipedia.org/wiki/Basic_block>`_ (named "entry"),
which is inserted into the function. The second line declares that the
global ``g_llvm_builder`` object is to be changed. The last line creates Now we get to the point where ``g_llvm_builder`` is set up. The first
a new builder that is set up to insert new instructions into the basic line creates a new `basic
block we just created. Basic blocks in LLVM are an important part of block <http://en.wikipedia.org/wiki/Basic_block>`_ (named "entry"),
functions that define the `Control Flow which is inserted into the function. The second line declares that the
Graph <http://en.wikipedia.org/wiki/Control_flow_graph>`_. Since we global ``g_llvm_builder`` object is to be changed. The last line creates
don't have any control flow, our functions will only contain one block a new builder that is set up to insert new instructions into the basic
at this point. We'll fix this in `Chapter 5 <PythonLangImpl5.html>`_ :). block we just created. Basic blocks in LLVM are an important part of
functions that define the `Control Flow
Graph <http://en.wikipedia.org/wiki/Control_flow_graph>`_. Since we
don't have any control flow, our functions will only contain one block
at this point. We'll fix this in `Chapter 5 <PythonLangImpl5.html>`_ :).
.. code-block:: python
# Finish off the function. # Finish off the function.
try: try: