Minor formatting changes to docs.
This commit is contained in:
parent
57d78fb42e
commit
4bd7c31939
1 changed files with 27 additions and 16 deletions
|
|
@ -34,8 +34,7 @@ First we define code generation methods in each AST node class:
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
# Expression class for numeric literals like
|
||||
"1.0".
|
||||
# Expression class for numeric literals like "1.0".
|
||||
class NumberExpressionNode(ExpressionNode):
|
||||
|
||||
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 things it depends on, and they all return an LLVM Value object.
|
||||
"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
|
||||
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.
|
||||
|
|
@ -127,6 +130,8 @@ First we'll do numeric literals:
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
In llvmpy, floating point numeric constants are represented with the
|
||||
``llvm.core.ConstantFP`` class. To create one, we can use the static
|
||||
``real()`` method in the ``llvm.core.Constant`` class. This code
|
||||
|
|
@ -305,8 +310,8 @@ the function call code above.
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
# If the name conflicted, there was already
|
||||
something with the same name. # If it has a body, don't allow redefinition or reextern.
|
||||
# If the name conflicted, there was already something with the same name.
|
||||
# If it has a body, don't allow redefinition or reextern.
|
||||
if function.name != self.name:
|
||||
function.delete()
|
||||
function = g_llvm_module.get_function_named(self.name)
|
||||
|
|
@ -406,19 +411,25 @@ LLVM Function object that is ready to go for us.
|
|||
# Create a new basic block to start insertion into.
|
||||
block = function.append_basic_block('entry')
|
||||
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
|
||||
a new builder that is set up to insert new instructions into the basic
|
||||
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>`_ :).
|
||||
|
||||
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
|
||||
a new builder that is set up to insert new instructions into the basic
|
||||
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.
|
||||
try:
|
||||
return_value = self.body.CodeGen()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue