From 4bd7c3193964b6fe337737ef4e98fbd7e5502b64 Mon Sep 17 00:00:00 2001 From: Maggie Mari Date: Wed, 15 Aug 2012 18:44:55 -0500 Subject: [PATCH] Minor formatting changes to docs. --- .../doc/kaleidoscope/PythonLangImpl3.rst | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/docs/source/doc/kaleidoscope/PythonLangImpl3.rst b/docs/source/doc/kaleidoscope/PythonLangImpl3.rst index 73edef6..fb2685e 100644 --- a/docs/source/doc/kaleidoscope/PythonLangImpl3.rst +++ b/docs/source/doc/kaleidoscope/PythonLangImpl3.rst @@ -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 `_ (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 `_. 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 `_ :). - Now we get to the point where ``g_llvm_builder`` is set up. The first - line creates a new `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 `_. 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 `_ :). - +.. code-block:: python + # Finish off the function. try: return_value = self.body.CodeGen()