This commit is contained in:
augustin64 2024-11-04 14:35:52 +01:00
commit 73f3dbeeb0
31 changed files with 178 additions and 168 deletions

View File

@ -17,8 +17,9 @@ class PhiNode(Statement):
"""
A φ node is a renaming in the CFG, of the form temp_x = φ(temp_0, ..., temp_n).
The field var contains the variable temp_x.
The field srcs relies for each precedent block in the CFG, identified with its label,
the variable temp_i of the φ node.
The field srcs links each corresponding predecessor in the CFG
---identified by its label---, to the variable temp_i of the φ
node.
"""
var: DataLocation
srcs: Dict[Label, Operand]

View File

@ -87,3 +87,10 @@ _Academic first semester 2024-2025_
- :book: Course: Thursday 25/10/2024, 10h15-12h15. Amphi B (Gabriel Radanne)
* SSA Optims [slides in english](course/cap_cours06b_ssa_optim.pdf).
# Week 8:
- :hammer: Lab 5b (1/2): Monday 04/11/2023, 13h30-15h30. Room E001 (Samuel Humeau & Emma Nardino)
* Smart Register Allocation [TP05b](TP05/tp5b.pdf).
* Code in [MiniC/TP04/](MiniC/TP05/).

BIN
TP05/tp5b.pdf Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 486d1ff73ffb3f41d31651516deff8a8
config: 33a23b4514891ef44049bf19634072fc
tags: 645f666f9bcd5a90fca523b33c5a78b7

View File

@ -92,7 +92,7 @@
<div class="viewcode-block" id="Allocator"><a class="viewcode-back" href="../../api/Lib.Allocator.html#Lib.Allocator.Allocator">[docs]</a><span class="k">class</span> <span class="nc">Allocator</span><span class="p">():</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;General base class for Naive, AllInMem and Smart Allocators.</span>
<span class="sd">&quot;&quot;&quot;General base class for Naive, AllInMem and Smart Allocators.</span>
<span class="sd"> Replace all temporaries in the code with actual data locations.</span>
<span class="sd"> Allocation is done in two steps:</span>
@ -118,23 +118,23 @@
<span class="k">pass</span></div>
<div class="viewcode-block" id="Allocator.replace"><a class="viewcode-back" href="../../api/Lib.Allocator.html#Lib.Allocator.Allocator.replace">[docs]</a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">old_instr</span><span class="p">:</span> <span class="n">Instruction</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Instruction</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Transform an instruction with temporaries into a list of instructions.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Transform an instruction with temporaries into a list of instructions.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="n">old_instr</span><span class="p">]</span></div>
<div class="viewcode-block" id="Allocator.rewriteCode"><a class="viewcode-back" href="../../api/Lib.Allocator.html#Lib.Allocator.Allocator.rewriteCode">[docs]</a> <span class="k">def</span> <span class="nf">rewriteCode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">listcode</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Modify the code to replace temporaries with</span>
<span class="sd">&quot;&quot;&quot;Modify the code to replace temporaries with</span>
<span class="sd"> registers or memory locations.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">listcode</span><span class="o">.</span><span class="n">iter_statements</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">replace</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="NaiveAllocator"><a class="viewcode-back" href="../../api/Lib.Allocator.html#Lib.Allocator.NaiveAllocator">[docs]</a><span class="k">class</span> <span class="nc">NaiveAllocator</span><span class="p">(</span><span class="n">Allocator</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Naive Allocator: try to assign a register to each temporary,</span>
<span class="sd">&quot;&quot;&quot;Naive Allocator: try to assign a register to each temporary,</span>
<span class="sd"> fails if there are more temporaries than registers.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<div class="viewcode-block" id="NaiveAllocator.replace"><a class="viewcode-back" href="../../api/Lib.Allocator.html#Lib.Allocator.NaiveAllocator.replace">[docs]</a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">old_instr</span><span class="p">:</span> <span class="n">Instruction</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Instruction</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Replace Temporary operands with the corresponding allocated Register.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Replace Temporary operands with the corresponding allocated Register.&quot;&quot;&quot;</span>
<span class="n">new_args</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">old_instr</span><span class="o">.</span><span class="n">args</span><span class="p">():</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">Temporary</span><span class="p">):</span>
@ -145,7 +145,7 @@
<span class="k">return</span> <span class="p">[</span><span class="n">new_instr</span><span class="p">]</span></div>
<div class="viewcode-block" id="NaiveAllocator.prepare"><a class="viewcode-back" href="../../api/Lib.Allocator.html#Lib.Allocator.NaiveAllocator.prepare">[docs]</a> <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Allocate all temporaries to registers.</span>
<span class="sd">&quot;&quot;&quot;Allocate all temporaries to registers.</span>
<span class="sd"> Fail if there are too many temporaries.&quot;&quot;&quot;</span>
<span class="n">regs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">GP_REGS</span><span class="p">)</span> <span class="c1"># Get a writable copy</span>
<span class="n">temp_allocation</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Temporary</span><span class="p">,</span> <span class="n">DataLocation</span><span class="p">]</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>

View File

@ -102,7 +102,7 @@
<div class="viewcode-block" id="Block"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block">[docs]</a><span class="k">class</span> <span class="nc">Block</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A basic block of a :py:class:`CFG` is made of three main parts:</span>
<span class="sd"> - a start :py:class:`label &lt;Lib.Statement.Label&gt;` that uniquely identifies the block in the CFG</span>
@ -138,7 +138,7 @@
<span class="k">return</span> <span class="n">s</span>
<div class="viewcode-block" id="Block.to_dot"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.to_dot">[docs]</a> <span class="k">def</span> <span class="nf">to_dot</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span> <span class="c1"># pragma: no cover</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Outputs all statements of the block as a string.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Outputs all statements of the block as a string.&quot;&quot;&quot;</span>
<span class="c1"># dot is weird: lines ending with \l instead of \n are left-aligned.</span>
<span class="n">NEWLINE</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\\</span><span class="s1">l &#39;</span>
<span class="n">instr</span> <span class="o">=</span> <span class="p">[]</span>
@ -153,11 +153,11 @@
<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_label</span><span class="p">)</span>
<div class="viewcode-block" id="Block.get_body"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_body">[docs]</a> <span class="k">def</span> <span class="nf">get_body</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">BlockInstr</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the statements in the body of the block (no phi-node nor the terminator).&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the statements in the body of the block (no phi-node nor the terminator).&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_instructions</span></div>
<div class="viewcode-block" id="Block.get_all_statements"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_all_statements">[docs]</a> <span class="k">def</span> <span class="nf">get_all_statements</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Statement</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return all statements of the block</span>
<span class="sd"> (including phi-nodes and the terminator, but not the label of the block).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -166,7 +166,7 @@
<span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">get_terminator</span><span class="p">()])</span></div>
<div class="viewcode-block" id="Block.get_body_and_terminator"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_body_and_terminator">[docs]</a> <span class="k">def</span> <span class="nf">get_body_and_terminator</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Statement</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return all statements of the block, except phi-nodes</span>
<span class="sd"> (and the label of the block).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -174,39 +174,39 @@
<span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">get_terminator</span><span class="p">()])</span></div>
<div class="viewcode-block" id="Block.get_label"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_label">[docs]</a> <span class="k">def</span> <span class="nf">get_label</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Label</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the label of the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the label of the block.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_label</span></div>
<div class="viewcode-block" id="Block.get_in"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_in">[docs]</a> <span class="k">def</span> <span class="nf">get_in</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="s1">&#39;Block&#39;</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the list of blocks with an edge to the considered block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the list of blocks with an edge to the considered block.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_in</span></div>
<div class="viewcode-block" id="Block.get_terminator"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_terminator">[docs]</a> <span class="k">def</span> <span class="nf">get_terminator</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Terminator</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the terminator of the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the terminator of the block.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_terminator</span></div>
<div class="viewcode-block" id="Block.set_terminator"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.set_terminator">[docs]</a> <span class="k">def</span> <span class="nf">set_terminator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">term</span><span class="p">:</span> <span class="n">Terminator</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Set the terminator of the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Set the terminator of the block.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_terminator</span> <span class="o">=</span> <span class="n">term</span></div>
<div class="viewcode-block" id="Block.get_phis"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.get_phis">[docs]</a> <span class="k">def</span> <span class="nf">get_phis</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Statement</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the list of all φ instructions of the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the list of all φ instructions of the block.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_phis</span></div>
<div class="viewcode-block" id="Block.add_phi"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.add_phi">[docs]</a> <span class="k">def</span> <span class="nf">add_phi</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">phi</span><span class="p">:</span> <span class="n">Statement</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a φ instruction to the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add a φ instruction to the block.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_phis</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span></div>
<div class="viewcode-block" id="Block.set_phis"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.set_phis">[docs]</a> <span class="k">def</span> <span class="nf">set_phis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">phis</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Statement</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Replace the φ instructions in the block by the given list `phis`.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Replace the φ instructions in the block by the given list `phis`.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_phis</span> <span class="o">=</span> <span class="n">phis</span></div>
<div class="viewcode-block" id="Block.remove_all_phis"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.remove_all_phis">[docs]</a> <span class="k">def</span> <span class="nf">remove_all_phis</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Remove all φ instructions in the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Remove all φ instructions in the block.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_phis</span> <span class="o">=</span> <span class="p">[]</span></div>
<div class="viewcode-block" id="Block.iter_statements"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.iter_statements">[docs]</a> <span class="k">def</span> <span class="nf">iter_statements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd"> For each real instruction i (not label or comment), replace it</span>
<span class="sd"> with the list of instructions given by f(i).</span>
@ -225,12 +225,12 @@
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_terminator</span><span class="p">(),</span> <span class="n">end_statements</span><span class="p">))</span></div>
<div class="viewcode-block" id="Block.add_instruction"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.Block.add_instruction">[docs]</a> <span class="k">def</span> <span class="nf">add_instruction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instr</span><span class="p">:</span> <span class="n">BlockInstr</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add an instruction to the body of the block.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add an instruction to the body of the block.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_instructions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">instr</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="CFG"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG">[docs]</a><span class="k">class</span> <span class="nc">CFG</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A complete control-flow graph representing a function.</span>
<span class="sd"> This class is mainly made of a list of basic :py:class:`Block`,</span>
<span class="sd"> a label indicating the :py:meth:`entry point of the function &lt;get_start&gt;`,</span>
@ -254,7 +254,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_end</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fdata</span><span class="o">.</span><span class="n">fresh_label</span><span class="p">(</span><span class="s2">&quot;end&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_init_blks</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a block for division by 0.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add a block for division by 0.&quot;&quot;&quot;</span>
<span class="c1"># Label for the address of the error message</span>
<span class="c1"># This address is added by print_code</span>
<span class="n">label_div_by_zero_msg</span> <span class="o">=</span> <span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fdata</span><span class="o">.</span><span class="n">_label_div_by_zero</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;_msg&quot;</span><span class="p">)</span>
@ -267,53 +267,53 @@
<span class="bp">self</span><span class="o">.</span><span class="n">add_block</span><span class="p">(</span><span class="n">blk</span><span class="p">)</span>
<div class="viewcode-block" id="CFG.get_start"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.get_start">[docs]</a> <span class="k">def</span> <span class="nf">get_start</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Label</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the entry label of the CFG.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the entry label of the CFG.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_start</span></div>
<div class="viewcode-block" id="CFG.set_start"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.set_start">[docs]</a> <span class="k">def</span> <span class="nf">set_start</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="n">Label</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Set the entry label of the CFG.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Set the entry label of the CFG.&quot;&quot;&quot;</span>
<span class="k">assert</span> <span class="p">(</span><span class="n">start</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_blocks</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_start</span> <span class="o">=</span> <span class="n">start</span></div>
<div class="viewcode-block" id="CFG.get_end"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.get_end">[docs]</a> <span class="k">def</span> <span class="nf">get_end</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Label</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the exit label of the CFG.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the exit label of the CFG.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_end</span></div>
<div class="viewcode-block" id="CFG.add_block"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.add_block">[docs]</a> <span class="k">def</span> <span class="nf">add_block</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">blk</span><span class="p">:</span> <span class="n">Block</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a new block to the CFG.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add a new block to the CFG.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_blocks</span><span class="p">[</span><span class="n">blk</span><span class="o">.</span><span class="n">_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">blk</span></div>
<div class="viewcode-block" id="CFG.get_block"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.get_block">[docs]</a> <span class="k">def</span> <span class="nf">get_block</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="n">Label</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Block</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the block with label `name`.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the block with label `name`.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_blocks</span><span class="p">[</span><span class="n">name</span><span class="p">]</span></div>
<div class="viewcode-block" id="CFG.get_blocks"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.get_blocks">[docs]</a> <span class="k">def</span> <span class="nf">get_blocks</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Block</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return all the blocks.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return all the blocks.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="n">b</span> <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_blocks</span><span class="o">.</span><span class="n">values</span><span class="p">()]</span></div>
<div class="viewcode-block" id="CFG.get_entries"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.get_entries">[docs]</a> <span class="k">def</span> <span class="nf">get_entries</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Block</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return all the blocks with no predecessors.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return all the blocks with no predecessors.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="n">b</span> <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_blocks</span><span class="o">.</span><span class="n">values</span><span class="p">()</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">b</span><span class="o">.</span><span class="n">get_in</span><span class="p">()]</span></div>
<div class="viewcode-block" id="CFG.add_edge"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.add_edge">[docs]</a> <span class="k">def</span> <span class="nf">add_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">src</span><span class="p">:</span> <span class="n">Block</span><span class="p">,</span> <span class="n">dest</span><span class="p">:</span> <span class="n">Block</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add the edge src -&gt; dest in the control flow graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add the edge src -&gt; dest in the control flow graph.&quot;&quot;&quot;</span>
<span class="n">dest</span><span class="o">.</span><span class="n">get_in</span><span class="p">()</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">src</span><span class="p">)</span></div>
<span class="c1"># assert (dest.get_label() in src.get_terminator().targets())</span>
<div class="viewcode-block" id="CFG.remove_edge"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.remove_edge">[docs]</a> <span class="k">def</span> <span class="nf">remove_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">src</span><span class="p">:</span> <span class="n">Block</span><span class="p">,</span> <span class="n">dest</span><span class="p">:</span> <span class="n">Block</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Remove the edge src -&gt; dest in the control flow graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Remove the edge src -&gt; dest in the control flow graph.&quot;&quot;&quot;</span>
<span class="n">dest</span><span class="o">.</span><span class="n">get_in</span><span class="p">()</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">src</span><span class="p">)</span></div>
<span class="c1"># assert (dest.get_label() not in src.get_terminator().targets())</span>
<div class="viewcode-block" id="CFG.out_blocks"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.out_blocks">[docs]</a> <span class="k">def</span> <span class="nf">out_blocks</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">block</span><span class="p">:</span> <span class="n">Block</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Block</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the list of blocks in the CFG targeted by</span>
<span class="sd"> the Terminator of Block block.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">get_block</span><span class="p">(</span><span class="n">dest</span><span class="p">)</span> <span class="k">for</span> <span class="n">dest</span> <span class="ow">in</span> <span class="n">block</span><span class="o">.</span><span class="n">get_terminator</span><span class="p">()</span><span class="o">.</span><span class="n">targets</span><span class="p">()]</span></div>
<div class="viewcode-block" id="CFG.gather_defs"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.gather_defs">[docs]</a> <span class="k">def</span> <span class="nf">gather_defs</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a dictionary associating variables to all the blocks</span>
<span class="sd"> containing one of their definitions.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -328,12 +328,12 @@
<span class="k">return</span> <span class="n">defs</span></div>
<div class="viewcode-block" id="CFG.iter_statements"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.iter_statements">[docs]</a> <span class="k">def</span> <span class="nf">iter_statements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Apply f to all instructions in all the blocks.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Apply f to all instructions in all the blocks.&quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_blocks</span><span class="p">():</span>
<span class="n">b</span><span class="o">.</span><span class="n">iter_statements</span><span class="p">(</span><span class="n">f</span><span class="p">)</span></div>
<div class="viewcode-block" id="CFG.linearize_naive"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.linearize_naive">[docs]</a> <span class="k">def</span> <span class="nf">linearize_naive</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Iterator</span><span class="p">[</span><span class="n">Statement</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Linearize the given control flow graph as a list of instructions.</span>
<span class="sd"> Naive procedure that adds jumps everywhere.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -353,13 +353,13 @@
<div class="viewcode-block" id="CFG.print_code"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.print_code">[docs]</a> <span class="k">def</span> <span class="nf">print_code</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span> <span class="n">linearize</span><span class="o">=</span><span class="p">(</span><span class="k">lambda</span> <span class="n">cfg</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">cfg</span><span class="o">.</span><span class="n">linearize_naive</span><span class="p">())),</span>
<span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Print the linearization of the CFG.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Print the linearization of the CFG.&quot;&quot;&quot;</span>
<span class="n">statements</span> <span class="o">=</span> <span class="n">linearize</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="n">_print_code</span><span class="p">(</span><span class="n">statements</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">fdata</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span> <span class="n">init_label</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_start</span><span class="p">,</span>
<span class="n">fin_label</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_end</span><span class="p">,</span> <span class="n">fin_div0</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">)</span></div>
<div class="viewcode-block" id="CFG.print_dot"><a class="viewcode-back" href="../../api/Lib.CFG.html#Lib.CFG.CFG.print_dot">[docs]</a> <span class="k">def</span> <span class="nf">print_dot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">DF</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">view</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span> <span class="c1"># pragma: no cover</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Print the CFG as a graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Print the CFG as a graph.&quot;&quot;&quot;</span>
<span class="n">graph</span> <span class="o">=</span> <span class="n">Digraph</span><span class="p">()</span>
<span class="c1"># nodes</span>
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">blk</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_blocks</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>

View File

@ -92,7 +92,7 @@
<div class="viewcode-block" id="computeDom"><a class="viewcode-back" href="../../api/Lib.Dominators.html#Lib.Dominators.computeDom">[docs]</a><span class="k">def</span> <span class="nf">computeDom</span><span class="p">(</span><span class="n">cfg</span><span class="p">:</span> <span class="n">CFG</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> `computeDom(cfg)` computes the table associating blocks to their</span>
<span class="sd"> dominators in `cfg`.</span>
<span class="sd"> It works by solving the equation system.</span>
@ -123,7 +123,7 @@
<div class="viewcode-block" id="printDT"><a class="viewcode-back" href="../../api/Lib.Dominators.html#Lib.Dominators.printDT">[docs]</a><span class="k">def</span> <span class="nf">printDT</span><span class="p">(</span><span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">graph</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span> <span class="c1"># pragma: no cover</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Display a graphical rendering of the given domination tree.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Display a graphical rendering of the given domination tree.&quot;&quot;&quot;</span>
<span class="n">dot</span> <span class="o">=</span> <span class="n">Digraph</span><span class="p">()</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">graph</span><span class="p">:</span>
<span class="n">dot</span><span class="o">.</span><span class="n">node</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">get_label</span><span class="p">()))</span>
@ -135,7 +135,7 @@
<div class="viewcode-block" id="computeDT"><a class="viewcode-back" href="../../api/Lib.Dominators.html#Lib.Dominators.computeDT">[docs]</a><span class="k">def</span> <span class="nf">computeDT</span><span class="p">(</span><span class="n">cfg</span><span class="p">:</span> <span class="n">CFG</span><span class="p">,</span> <span class="n">dominators</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]],</span>
<span class="n">dom_graphs</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">basename</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> `computeDT(cfg, dominators)` computes the domination tree of `cfg`</span>
<span class="sd"> using the previously computed `dominators`.</span>
<span class="sd"> It returns `DT`, a dictionary which associates a block with its children</span>
@ -174,7 +174,7 @@
<span class="n">DT</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]],</span>
<span class="n">b</span><span class="p">:</span> <span class="n">Block</span><span class="p">,</span>
<span class="n">DF</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> `_computeDF_at_block(...)` computes the dominance frontier at the given block,</span>
<span class="sd"> by updating `DF`.</span>
@ -192,7 +192,7 @@
<div class="viewcode-block" id="computeDF"><a class="viewcode-back" href="../../api/Lib.Dominators.html#Lib.Dominators.computeDF">[docs]</a><span class="k">def</span> <span class="nf">computeDF</span><span class="p">(</span><span class="n">cfg</span><span class="p">:</span> <span class="n">CFG</span><span class="p">,</span> <span class="n">dominators</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]],</span>
<span class="n">DT</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]],</span> <span class="n">dom_graphs</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">basename</span><span class="p">:</span> <span class="nb">str</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Block</span><span class="p">,</span> <span class="n">Set</span><span class="p">[</span><span class="n">Block</span><span class="p">]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> `computeDF(...)` computes the dominance frontier of a CFG.</span>
<span class="sd"> It returns `DF` which associates a block to its frontier.</span>

View File

@ -94,7 +94,7 @@
<div class="viewcode-block" id="FunctionData"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData">[docs]</a><span class="k">class</span> <span class="nc">FunctionData</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stores some metadata on a RiscV function:</span>
<span class="sd"> name of the function, label names, temporary variables</span>
<span class="sd"> (using :py:class:`Lib.Operands.TemporaryPool`),</span>
@ -119,18 +119,18 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_label_div_by_zero</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fresh_label</span><span class="p">(</span><span class="s2">&quot;div_by_zero&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="FunctionData.get_name"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.get_name">[docs]</a> <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the name of the function.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the name of the function.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span></div>
<div class="viewcode-block" id="FunctionData.fresh_tmp"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.fresh_tmp">[docs]</a> <span class="k">def</span> <span class="nf">fresh_tmp</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Temporary</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new fresh Temporary,</span>
<span class="sd"> which is added to the pool.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pool</span><span class="o">.</span><span class="n">fresh_tmp</span><span class="p">()</span></div>
<div class="viewcode-block" id="FunctionData.fresh_offset"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.fresh_offset">[docs]</a> <span class="k">def</span> <span class="nf">fresh_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Offset</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new offset in the memory stack.</span>
<span class="sd"> Offsets are decreasing relative to FP.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -144,20 +144,20 @@
<span class="k">return</span> <span class="n">Offset</span><span class="p">(</span><span class="n">FP</span><span class="p">,</span> <span class="o">-</span><span class="mi">8</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dec</span><span class="p">)</span></div>
<div class="viewcode-block" id="FunctionData.get_offset"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.get_offset">[docs]</a> <span class="k">def</span> <span class="nf">get_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the current offset in the memory stack.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dec</span></div>
<span class="k">def</span> <span class="nf">_fresh_label_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new unique label name based on the given string.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span>
<div class="viewcode-block" id="FunctionData.fresh_label"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.fresh_label">[docs]</a> <span class="k">def</span> <span class="nf">fresh_label</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Label</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new label, with a unique name based on the given string.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fresh_label_name</span><span class="p">(</span><span class="n">name</span><span class="p">))</span></div>
@ -171,7 +171,7 @@
<span class="k">def</span> <span class="nf">_iter_statements</span><span class="p">(</span>
<span class="n">listIns</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span><span class="p">],</span> <span class="n">f</span><span class="p">:</span> <span class="n">Callable</span><span class="p">[[</span><span class="n">_T</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span><span class="p">]])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span> <span class="o">|</span> <span class="n">Comment</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd"> For each real instruction i (not label or comment), replace it</span>
<span class="sd"> with the list of instructions given by f(i).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -191,7 +191,7 @@
<span class="k">def</span> <span class="nf">_print_code</span><span class="p">(</span><span class="n">listIns</span><span class="p">:</span> <span class="n">List</span><span class="p">,</span> <span class="n">fdata</span><span class="p">:</span> <span class="n">FunctionData</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span>
<span class="n">init_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fin_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fin_div0</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Please use print_code from LinearCode or CFG, not directly this one.</span>
<span class="sd"> Print the instructions from listIns, forming fdata, on output.</span>
@ -214,9 +214,9 @@
<span class="c1"># We use t0 because it is caller-saved</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> .text</span>
<span class="s2"> .globl </span><span class="si">{0}</span>
<span class="s2"> .globl </span><span class="si">{0}</span><span class="s2"></span>
<span class="si">{0}</span><span class="s2">:</span>
<span class="s2"> li t0, </span><span class="si">{1}</span>
<span class="s2"> li t0, </span><span class="si">{1}</span><span class="s2"></span>
<span class="s2"> sub sp, sp, t0</span>
<span class="s2"> sd ra, 0(sp)</span>
<span class="s2"> sd fp, 8(sp)</span>
@ -226,7 +226,7 @@
<span class="k">if</span> <span class="n">init_label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># Add a jump to init_label before the generated code.</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> j </span><span class="si">{0}</span>
<span class="s2"> j </span><span class="si">{0}</span><span class="s2"></span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">init_label</span><span class="p">))</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">##Generated Code</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="c1"># Generated code</span>
@ -243,7 +243,7 @@
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> ld ra, 0(sp)</span>
<span class="s2"> ld fp, 8(sp)</span>
<span class="s2"> li t0, </span><span class="si">{0}</span>
<span class="s2"> li t0, </span><span class="si">{0}</span><span class="s2"></span>
<span class="s2"> add sp, sp, t0</span>
<span class="s2"> ret</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cardoffset</span><span class="p">))</span>

View File

@ -87,7 +87,7 @@
<div class="viewcode-block" id="GraphError"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GraphError">[docs]</a><span class="k">class</span> <span class="nc">GraphError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Exception raised for self loops.</span>
<span class="sd">&quot;&quot;&quot;Exception raised for self loops.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">message</span><span class="p">:</span> <span class="nb">str</span>
@ -97,7 +97,7 @@
<div class="viewcode-block" id="GeneralGraph"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph">[docs]</a><span class="k">class</span> <span class="nc">GeneralGraph</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> General class regrouping similarities</span>
<span class="sd"> between directed and non oriented graphs.</span>
<span class="sd"> The only differences between the two are:</span>
@ -113,7 +113,7 @@
<span class="n">graph_dict</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Set</span><span class="p">]</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">graph_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Initializes a graph object.</span>
<span class="sd"> If no dictionary or None is given,</span>
<span class="sd"> an empty dictionary will be used.</span>
@ -123,11 +123,11 @@
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span> <span class="o">=</span> <span class="n">graph_dict</span>
<div class="viewcode-block" id="GeneralGraph.vertices"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.vertices">[docs]</a> <span class="k">def</span> <span class="nf">vertices</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the vertices of a graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the vertices of a graph.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span></div>
<div class="viewcode-block" id="GeneralGraph.add_vertex"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.add_vertex">[docs]</a> <span class="k">def</span> <span class="nf">add_vertex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vertex</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> If the vertex &quot;vertex&quot; is not in</span>
<span class="sd"> self.graph_dict, a key &quot;vertex&quot; with an empty</span>
<span class="sd"> list as a value is added to the dictionary.</span>
@ -137,7 +137,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">vertex</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span></div>
<div class="viewcode-block" id="GeneralGraph.edges"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.edges">[docs]</a> <span class="k">def</span> <span class="nf">edges</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Set</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the edges of the graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the edges of the graph.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[]</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@ -150,7 +150,7 @@
<span class="k">return</span> <span class="n">res</span>
<div class="viewcode-block" id="GeneralGraph.dfs_traversal"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.dfs_traversal">[docs]</a> <span class="k">def</span> <span class="nf">dfs_traversal</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">root</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compute a depth first search of the graph,</span>
<span class="sd"> from the vertex root.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -165,11 +165,11 @@
<span class="k">return</span> <span class="n">seen</span></div>
<div class="viewcode-block" id="GeneralGraph.is_reachable_from"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.is_reachable_from">[docs]</a> <span class="k">def</span> <span class="nf">is_reachable_from</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v1</span><span class="p">:</span> <span class="n">Any</span><span class="p">,</span> <span class="n">v2</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;True if there is a path from v1 to v2.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;True if there is a path from v1 to v2.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">v2</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dfs_traversal</span><span class="p">(</span><span class="n">v1</span><span class="p">)</span></div>
<div class="viewcode-block" id="GeneralGraph.connected_components"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.connected_components">[docs]</a> <span class="k">def</span> <span class="nf">connected_components</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Any</span><span class="p">]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compute the list of all connected components of the graph,</span>
<span class="sd"> each component being a list of vetices.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -183,7 +183,7 @@
<span class="k">return</span> <span class="n">components</span></div>
<div class="viewcode-block" id="GeneralGraph.bfs_traversal"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.GeneralGraph.bfs_traversal">[docs]</a> <span class="k">def</span> <span class="nf">bfs_traversal</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">root</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compute a breadth first search of the graph,</span>
<span class="sd"> from the vertex root.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -199,10 +199,10 @@
<div class="viewcode-block" id="Graph"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph">[docs]</a><span class="k">class</span> <span class="nc">Graph</span><span class="p">(</span><span class="n">GeneralGraph</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Class for non oriented graphs.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Class for non oriented graphs.&quot;&quot;&quot;</span>
<div class="viewcode-block" id="Graph.edges"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.edges">[docs]</a> <span class="k">def</span> <span class="nf">edges</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Set</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A static method generating the set of edges</span>
<span class="sd"> (they appear twice in the dictionnary).</span>
<span class="sd"> Return a list of sets.</span>
@ -215,7 +215,7 @@
<span class="k">return</span> <span class="n">edges</span></div>
<div class="viewcode-block" id="Graph.add_edge"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.add_edge">[docs]</a> <span class="k">def</span> <span class="nf">add_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">edge</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Any</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Add an edge in the graph.</span>
<span class="sd"> edge should be a pair and not (c,c)</span>
<span class="sd"> (we call g.add_edge((v1,v2)))</span>
@ -234,7 +234,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">vertex2</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">vertex1</span><span class="p">}</span></div>
<div class="viewcode-block" id="Graph.print_dot"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.print_dot">[docs]</a> <span class="k">def</span> <span class="nf">print_dot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">colors</span><span class="o">=</span><span class="p">{})</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Print the graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Print the graph.&quot;&quot;&quot;</span>
<span class="n">color_names</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="s1">&#39;blue&#39;</span><span class="p">,</span> <span class="s1">&#39;green&#39;</span><span class="p">,</span> <span class="s1">&#39;yellow&#39;</span><span class="p">,</span> <span class="s1">&#39;cyan&#39;</span><span class="p">,</span> <span class="s1">&#39;magenta&#39;</span><span class="p">]</span> <span class="o">+</span> \
<span class="p">[</span><span class="sa">f</span><span class="s2">&quot;grey</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">10</span><span class="p">)]</span>
<span class="n">color_shapes</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;ellipse&#39;</span><span class="p">,</span> <span class="s1">&#39;box&#39;</span><span class="p">,</span> <span class="s1">&#39;diamond&#39;</span><span class="p">,</span> <span class="s1">&#39;trapezium&#39;</span><span class="p">,</span> <span class="s1">&#39;egg&#39;</span><span class="p">,</span>
@ -261,20 +261,20 @@
<span class="n">dot</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">view</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># print in pdf</span></div>
<div class="viewcode-block" id="Graph.delete_vertex"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.delete_vertex">[docs]</a> <span class="k">def</span> <span class="nf">delete_vertex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vertex</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Delete a vertex and all the adjacent edges.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Delete a vertex and all the adjacent edges.&quot;&quot;&quot;</span>
<span class="n">gdict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span>
<span class="k">for</span> <span class="n">neighbour</span> <span class="ow">in</span> <span class="n">gdict</span><span class="p">[</span><span class="n">vertex</span><span class="p">]:</span>
<span class="n">gdict</span><span class="p">[</span><span class="n">neighbour</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">vertex</span><span class="p">)</span>
<span class="k">del</span> <span class="n">gdict</span><span class="p">[</span><span class="n">vertex</span><span class="p">]</span></div>
<div class="viewcode-block" id="Graph.delete_edge"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.delete_edge">[docs]</a> <span class="k">def</span> <span class="nf">delete_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">edge</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Any</span><span class="p">]):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Delete an edge.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Delete an edge.&quot;&quot;&quot;</span>
<span class="p">(</span><span class="n">v1</span><span class="p">,</span> <span class="n">v2</span><span class="p">)</span> <span class="o">=</span> <span class="n">edge</span>
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">v1</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">v2</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">v1</span><span class="p">)</span></div>
<div class="viewcode-block" id="Graph.color"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.color">[docs]</a> <span class="k">def</span> <span class="nf">color</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="nb">int</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Color the graph with an unlimited number of colors.</span>
<span class="sd"> Return a dict vertex -&gt; color, where color is an integer (0, 1, ...).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -283,7 +283,7 @@
<span class="c1"># see algo of the course</span>
<div class="viewcode-block" id="Graph.color_with_k_colors"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.Graph.color_with_k_colors">[docs]</a> <span class="k">def</span> <span class="nf">color_with_k_colors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">K</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">avoidingnodes</span><span class="o">=</span><span class="p">())</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">List</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Color with &lt;= K colors (if K is unspecified, use unlimited colors).</span>
<span class="sd"> Return 3 values:</span>
@ -336,18 +336,18 @@
<div class="viewcode-block" id="DiGraph"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph">[docs]</a><span class="k">class</span> <span class="nc">DiGraph</span><span class="p">(</span><span class="n">GeneralGraph</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Class for directed graphs.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Class for directed graphs.&quot;&quot;&quot;</span>
<div class="viewcode-block" id="DiGraph.pred"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.pred">[docs]</a> <span class="k">def</span> <span class="nf">pred</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Set</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return all predecessors of the vertex `v` in the graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return all predecessors of the vertex `v` in the graph.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span><span class="n">src</span> <span class="k">for</span> <span class="n">src</span><span class="p">,</span> <span class="n">dests</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">dests</span><span class="p">}</span></div>
<div class="viewcode-block" id="DiGraph.neighbourhoods"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.neighbourhoods">[docs]</a> <span class="k">def</span> <span class="nf">neighbourhoods</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Set</span><span class="p">]]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return all neighbourhoods in the graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return all neighbourhoods in the graph.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="o">.</span><span class="n">items</span><span class="p">())</span></div>
<div class="viewcode-block" id="DiGraph.edges"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.edges">[docs]</a> <span class="k">def</span> <span class="nf">edges</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Set</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; A static method generating the set of edges&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot; A static method generating the set of edges&quot;&quot;&quot;</span>
<span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">vertex</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">:</span>
<span class="k">for</span> <span class="n">neighbour</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">vertex</span><span class="p">]:</span>
@ -355,7 +355,7 @@
<span class="k">return</span> <span class="n">edges</span></div>
<div class="viewcode-block" id="DiGraph.add_edge"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.add_edge">[docs]</a> <span class="k">def</span> <span class="nf">add_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">edge</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Any</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Add an edge in the graph.</span>
<span class="sd"> edge should be a pair and not (c,c)</span>
<span class="sd"> (we call g.add_edge((v1,v2)))</span>
@ -369,7 +369,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">vertex2</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span></div>
<div class="viewcode-block" id="DiGraph.print_dot"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.print_dot">[docs]</a> <span class="k">def</span> <span class="nf">print_dot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Print the graph.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Print the graph.&quot;&quot;&quot;</span>
<span class="n">dot</span> <span class="o">=</span> <span class="n">Digraph</span><span class="p">(</span><span class="n">comment</span><span class="o">=</span><span class="s1">&#39;Conflict Graph&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">:</span>
<span class="n">shape</span> <span class="o">=</span> <span class="kc">None</span>
@ -381,14 +381,14 @@
<span class="n">dot</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">view</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># print in pdf</span></div>
<div class="viewcode-block" id="DiGraph.delete_vertex"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.delete_vertex">[docs]</a> <span class="k">def</span> <span class="nf">delete_vertex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vertex</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Delete a vertex and all the adjacent edges.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Delete a vertex and all the adjacent edges.&quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">node</span><span class="p">,</span> <span class="n">neighbours</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">vertex</span> <span class="ow">in</span> <span class="n">neighbours</span><span class="p">:</span>
<span class="n">neighbours</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">vertex</span><span class="p">)</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">vertex</span><span class="p">]</span></div>
<div class="viewcode-block" id="DiGraph.delete_edge"><a class="viewcode-back" href="../../api/Lib.Graphes.html#Lib.Graphes.DiGraph.delete_edge">[docs]</a> <span class="k">def</span> <span class="nf">delete_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">edge</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">Any</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Delete an edge.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Delete an edge.&quot;&quot;&quot;</span>
<span class="p">(</span><span class="n">v1</span><span class="p">,</span> <span class="n">v2</span><span class="p">)</span> <span class="o">=</span> <span class="n">edge</span>
<span class="bp">self</span><span class="o">.</span><span class="n">graph_dict</span><span class="p">[</span><span class="n">v1</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span></div></div>
</pre></div>

View File

@ -97,7 +97,7 @@
<div class="viewcode-block" id="LinearCode"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode">[docs]</a><span class="k">class</span> <span class="nc">LinearCode</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Representation of a RiscV program as a list of instructions.</span>
<span class="sd"> :py:meth:`add_instruction` is repeatedly called in the codegen visitor</span>
@ -111,7 +111,7 @@
<span class="sd"> the RiscV program to a file.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The :py:attr:`fdata` member variable contains some meta-information</span>
<span class="sd"> on the program, for instance to allocate a new temporary.</span>
<span class="sd"> See :py:class:`Lib.FunctionData.FunctionData`.</span>
@ -125,7 +125,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">fdata</span> <span class="o">=</span> <span class="n">FunctionData</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<div class="viewcode-block" id="LinearCode.add_instruction"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.add_instruction">[docs]</a> <span class="k">def</span> <span class="nf">add_instruction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">:</span> <span class="n">CodeStatement</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Utility function to add an instruction in the program.</span>
<span class="sd"> See also :py:mod:`Lib.RiscV` to generate relevant instructions.</span>
@ -133,7 +133,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_listIns</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span></div>
<div class="viewcode-block" id="LinearCode.iter_statements"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.iter_statements">[docs]</a> <span class="k">def</span> <span class="nf">iter_statements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd"> For each real instruction i (not label or comment), replace it</span>
<span class="sd"> with the list of instructions given by f(i).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -144,20 +144,20 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_listIns</span> <span class="o">=</span> <span class="n">new_list_ins</span></div>
<div class="viewcode-block" id="LinearCode.get_instructions"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.get_instructions">[docs]</a> <span class="k">def</span> <span class="nf">get_instructions</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">CodeStatement</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the list of instructions of the program.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the list of instructions of the program.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listIns</span></div>
<span class="c1"># each instruction has its own &quot;add in list&quot; version</span>
<div class="viewcode-block" id="LinearCode.add_label"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.add_label">[docs]</a> <span class="k">def</span> <span class="nf">add_label</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">:</span> <span class="n">Label</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a label in the program.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add a label in the program.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_instruction</span><span class="p">(</span><span class="n">s</span><span class="p">)</span></div>
<div class="viewcode-block" id="LinearCode.add_comment"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.add_comment">[docs]</a> <span class="k">def</span> <span class="nf">add_comment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a comment in the program.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add a comment in the program.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_instruction</span><span class="p">(</span><span class="n">Comment</span><span class="p">(</span><span class="n">s</span><span class="p">))</span></div>
<div class="viewcode-block" id="LinearCode.add_instruction_PRINTLN_INT"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.add_instruction_PRINTLN_INT">[docs]</a> <span class="k">def</span> <span class="nf">add_instruction_PRINTLN_INT</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reg</span><span class="p">:</span> <span class="n">DataLocation</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Print integer value, with newline. (see Expand)&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Print integer value, with newline. (see Expand)&quot;&quot;&quot;</span>
<span class="c1"># A print instruction generates the temp it prints.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_instruction</span><span class="p">(</span><span class="n">mv</span><span class="p">(</span><span class="n">A0</span><span class="p">,</span> <span class="n">reg</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_instruction</span><span class="p">(</span><span class="n">call</span><span class="p">(</span><span class="n">Function</span><span class="p">(</span><span class="s1">&#39;println_int&#39;</span><span class="p">)))</span></div>
@ -166,12 +166,12 @@
<span class="k">return</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listIns</span><span class="p">))</span>
<div class="viewcode-block" id="LinearCode.print_code"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.print_code">[docs]</a> <span class="k">def</span> <span class="nf">print_code</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Outputs the RiscV program as text to a file at the given path.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Outputs the RiscV program as text to a file at the given path.&quot;&quot;&quot;</span>
<span class="n">_print_code</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_listIns</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">fdata</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span> <span class="n">init_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">fin_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fin_div0</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">)</span></div>
<div class="viewcode-block" id="LinearCode.print_dot"><a class="viewcode-back" href="../../api/Lib.LinearCode.html#Lib.LinearCode.LinearCode.print_dot">[docs]</a> <span class="k">def</span> <span class="nf">print_dot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">DF</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">view</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span> <span class="c1"># pragma: no cover</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Outputs the RiscV program as graph to a file at the given path.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Outputs the RiscV program as graph to a file at the given path.&quot;&quot;&quot;</span>
<span class="c1"># import graphviz here so that students who don&#39;t have it can still work on lab4</span>
<span class="kn">from</span> <span class="nn">graphviz</span> <span class="kn">import</span> <span class="n">Digraph</span>
<span class="n">graph</span> <span class="o">=</span> <span class="n">Digraph</span><span class="p">()</span>

View File

@ -118,7 +118,7 @@
<div class="viewcode-block" id="Condition"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Condition">[docs]</a><span class="k">class</span> <span class="nc">Condition</span><span class="p">(</span><span class="n">Operand</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Condition, i.e. comparison operand for a CondJump.</span>
<span class="sd">&quot;&quot;&quot;Condition, i.e. comparison operand for a CondJump.</span>
<span class="sd"> Example usage :</span>
@ -144,7 +144,7 @@
<span class="k">raise</span> <span class="n">MiniCInternalError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Unsupported comparison operator </span><span class="si">{</span><span class="n">optype</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="Condition.negate"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Condition.negate">[docs]</a> <span class="k">def</span> <span class="nf">negate</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="s1">&#39;Condition&#39;</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the opposite condition.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the opposite condition.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Condition</span><span class="p">(</span><span class="n">opnot_dict</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_op</span><span class="p">])</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@ -152,7 +152,7 @@
<div class="viewcode-block" id="Function"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Function">[docs]</a><span class="k">class</span> <span class="nc">Function</span><span class="p">(</span><span class="n">Operand</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Operand for build-in function call.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Operand for build-in function call.&quot;&quot;&quot;</span>
<span class="n">_name</span><span class="p">:</span> <span class="nb">str</span>
@ -164,7 +164,7 @@
<div class="viewcode-block" id="DataLocation"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.DataLocation">[docs]</a><span class="k">class</span> <span class="nc">DataLocation</span><span class="p">(</span><span class="n">Operand</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; A Data Location is either a register, a temporary</span>
<span class="sd">&quot;&quot;&quot; A Data Location is either a register, a temporary</span>
<span class="sd"> or a place in memory (offset).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -181,7 +181,7 @@
<div class="viewcode-block" id="Register"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Register">[docs]</a><span class="k">class</span> <span class="nc">Register</span><span class="p">(</span><span class="n">DataLocation</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; A (physical) register.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot; A (physical) register.&quot;&quot;&quot;</span>
<span class="n">_number</span><span class="p">:</span> <span class="nb">int</span>
@ -234,7 +234,7 @@
<div class="viewcode-block" id="Offset"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Offset">[docs]</a><span class="k">class</span> <span class="nc">Offset</span><span class="p">(</span><span class="n">DataLocation</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; Offset = address in memory computed with base + offset.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot; Offset = address in memory computed with base + offset.&quot;&quot;&quot;</span>
<span class="n">_basereg</span><span class="p">:</span> <span class="n">Register</span>
<span class="n">_offset</span><span class="p">:</span> <span class="nb">int</span>
@ -247,12 +247,12 @@
<span class="k">return</span> <span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">(</span><span class="si">{}</span><span class="s2">)&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_offset</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_basereg</span><span class="p">))</span>
<div class="viewcode-block" id="Offset.get_offset"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Offset.get_offset">[docs]</a> <span class="k">def</span> <span class="nf">get_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the value of the offset.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the value of the offset.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_offset</span></div></div>
<div class="viewcode-block" id="Immediate"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Immediate">[docs]</a><span class="k">class</span> <span class="nc">Immediate</span><span class="p">(</span><span class="n">DataLocation</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Immediate operand (integer).&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Immediate operand (integer).&quot;&quot;&quot;</span>
<span class="n">_val</span><span class="p">:</span> <span class="nb">int</span>
@ -264,7 +264,7 @@
<div class="viewcode-block" id="Temporary"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Temporary">[docs]</a><span class="k">class</span> <span class="nc">Temporary</span><span class="p">(</span><span class="n">DataLocation</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Temporary, a location that has not been allocated yet.</span>
<span class="sd">&quot;&quot;&quot;Temporary, a location that has not been allocated yet.</span>
<span class="sd"> It will later be mapped to a physical register (Register) or to a memory location (Offset).</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -279,12 +279,12 @@
<span class="k">return</span> <span class="p">(</span><span class="s2">&quot;temp_</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_number</span><span class="p">)))</span>
<div class="viewcode-block" id="Temporary.get_alloced_loc"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Temporary.get_alloced_loc">[docs]</a> <span class="k">def</span> <span class="nf">get_alloced_loc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataLocation</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the DataLocation allocated to this Temporary.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the DataLocation allocated to this Temporary.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pool</span><span class="o">.</span><span class="n">get_alloced_loc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="TemporaryPool"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.TemporaryPool">[docs]</a><span class="k">class</span> <span class="nc">TemporaryPool</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Manage a pool of temporaries.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Manage a pool of temporaries.&quot;&quot;&quot;</span>
<span class="n">_all_temps</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Temporary</span><span class="p">]</span>
<span class="n">_current_num</span><span class="p">:</span> <span class="nb">int</span>
@ -296,20 +296,20 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_allocation</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
<div class="viewcode-block" id="TemporaryPool.get_all_temps"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.TemporaryPool.get_all_temps">[docs]</a> <span class="k">def</span> <span class="nf">get_all_temps</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Temporary</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return all the temporaries of the pool.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return all the temporaries of the pool.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_all_temps</span></div>
<div class="viewcode-block" id="TemporaryPool.get_alloced_loc"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.TemporaryPool.get_alloced_loc">[docs]</a> <span class="k">def</span> <span class="nf">get_alloced_loc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">:</span> <span class="n">Temporary</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataLocation</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Get the actual DataLocation allocated for the temporary t.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Get the actual DataLocation allocated for the temporary t.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_allocation</span><span class="p">[</span><span class="n">t</span><span class="p">]</span></div>
<div class="viewcode-block" id="TemporaryPool.add_tmp"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.TemporaryPool.add_tmp">[docs]</a> <span class="k">def</span> <span class="nf">add_tmp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">:</span> <span class="n">Temporary</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a temporary to the pool.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Add a temporary to the pool.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_all_temps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_allocation</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="n">t</span> <span class="c1"># While no allocation, return the temporary itself</span></div>
<div class="viewcode-block" id="TemporaryPool.set_temp_allocation"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.TemporaryPool.set_temp_allocation">[docs]</a> <span class="k">def</span> <span class="nf">set_temp_allocation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">allocation</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Temporary</span><span class="p">,</span> <span class="n">DataLocation</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Give a mapping from temporaries to actual registers.</span>
<span class="sd">&quot;&quot;&quot;Give a mapping from temporaries to actual registers.</span>
<span class="sd"> The argument allocation must be a dict from Temporary to</span>
<span class="sd"> DataLocation other than Temporary (typically Register or Offset).</span>
<span class="sd"> Typing enforces that keys are Temporary and values are Datalocation.</span>
@ -322,7 +322,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_allocation</span> <span class="o">=</span> <span class="n">allocation</span></div>
<div class="viewcode-block" id="TemporaryPool.fresh_tmp"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.TemporaryPool.fresh_tmp">[docs]</a> <span class="k">def</span> <span class="nf">fresh_tmp</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Temporary</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Give a new fresh Temporary and add it to the pool.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Give a new fresh Temporary and add it to the pool.&quot;&quot;&quot;</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">Temporary</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_current_num</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_current_num</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_tmp</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
@ -330,7 +330,7 @@
<div class="viewcode-block" id="Renamer"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Renamer">[docs]</a><span class="k">class</span> <span class="nc">Renamer</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Manage a renaming of temporaries.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Manage a renaming of temporaries.&quot;&quot;&quot;</span>
<span class="n">_pool</span><span class="p">:</span> <span class="n">TemporaryPool</span>
<span class="n">_env</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Temporary</span><span class="p">,</span> <span class="n">Temporary</span><span class="p">]</span>
@ -340,21 +340,21 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_env</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
<div class="viewcode-block" id="Renamer.fresh"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Renamer.fresh">[docs]</a> <span class="k">def</span> <span class="nf">fresh</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">:</span> <span class="n">Temporary</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Temporary</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Give a fresh rename for a Temporary.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Give a fresh rename for a Temporary.&quot;&quot;&quot;</span>
<span class="n">new_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pool</span><span class="o">.</span><span class="n">fresh_tmp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_env</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="n">new_t</span>
<span class="k">return</span> <span class="n">new_t</span></div>
<div class="viewcode-block" id="Renamer.replace"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Renamer.replace">[docs]</a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">:</span> <span class="n">Temporary</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Temporary</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Give the rename for a Temporary (which is itself if it is not renamed).&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Give the rename for a Temporary (which is itself if it is not renamed).&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_env</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span></div>
<div class="viewcode-block" id="Renamer.defined"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Renamer.defined">[docs]</a> <span class="k">def</span> <span class="nf">defined</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">:</span> <span class="n">Temporary</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;True if the Temporary is renamed.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;True if the Temporary is renamed.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_env</span></div>
<div class="viewcode-block" id="Renamer.copy"><a class="viewcode-back" href="../../api/Lib.Operands.html#Lib.Operands.Renamer.copy">[docs]</a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Give a copy of the Renamer.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Give a copy of the Renamer.&quot;&quot;&quot;</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">Renamer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pool</span><span class="p">)</span>
<span class="n">r</span><span class="o">.</span><span class="n">_env</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_env</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">return</span> <span class="n">r</span></div></div>

View File

@ -95,36 +95,37 @@
<div class="viewcode-block" id="PhiNode"><a class="viewcode-back" href="../../api/Lib.PhiNode.html#Lib.PhiNode.PhiNode">[docs]</a><span class="nd">@dataclass</span>
<span class="k">class</span> <span class="nc">PhiNode</span><span class="p">(</span><span class="n">Statement</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A φ node is a renaming in the CFG, of the form temp_x = φ(temp_0, ..., temp_n).</span>
<span class="sd"> The field var contains the variable temp_x.</span>
<span class="sd"> The field srcs relies for each precedent block in the CFG, identified with its label,</span>
<span class="sd"> the variable temp_i of the φ node.</span>
<span class="sd"> The field srcs links each corresponding predecessor in the CFG</span>
<span class="sd"> ---identified by its label---, to the variable temp_i of the φ</span>
<span class="sd"> node.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">var</span><span class="p">:</span> <span class="n">DataLocation</span>
<span class="n">srcs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Label</span><span class="p">,</span> <span class="n">Operand</span><span class="p">]</span>
<div class="viewcode-block" id="PhiNode.defined"><a class="viewcode-back" href="../../api/Lib.PhiNode.html#Lib.PhiNode.PhiNode.defined">[docs]</a> <span class="k">def</span> <span class="nf">defined</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the variable defined by the φ node.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the variable defined by the φ node.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">]</span></div>
<div class="viewcode-block" id="PhiNode.get_srcs"><a class="viewcode-back" href="../../api/Lib.PhiNode.html#Lib.PhiNode.PhiNode.get_srcs">[docs]</a> <span class="k">def</span> <span class="nf">get_srcs</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Label</span><span class="p">,</span> <span class="n">Operand</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the dictionnary associating for each previous block the corresponding variable.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">srcs</span></div>
<div class="viewcode-block" id="PhiNode.used"><a class="viewcode-back" href="../../api/Lib.PhiNode.html#Lib.PhiNode.PhiNode.used">[docs]</a> <span class="k">def</span> <span class="nf">used</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the variables used by the statement.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the variables used by the statement.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">srcs</span><span class="o">.</span><span class="n">values</span><span class="p">())</span></div>
<div class="viewcode-block" id="PhiNode.rename"><a class="viewcode-back" href="../../api/Lib.PhiNode.html#Lib.PhiNode.PhiNode.rename">[docs]</a> <span class="k">def</span> <span class="nf">rename</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">renamer</span><span class="p">:</span> <span class="n">Renamer</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Rename the variable defined by the φ node with a fresh name.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Rename the variable defined by the φ node with a fresh name.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="n">Temporary</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">var</span> <span class="o">=</span> <span class="n">renamer</span><span class="o">.</span><span class="n">fresh</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">)</span></div>
<div class="viewcode-block" id="PhiNode.rename_from"><a class="viewcode-back" href="../../api/Lib.PhiNode.html#Lib.PhiNode.PhiNode.rename_from">[docs]</a> <span class="k">def</span> <span class="nf">rename_from</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">renamer</span><span class="p">:</span> <span class="n">Renamer</span><span class="p">,</span> <span class="n">label</span><span class="p">:</span> <span class="n">Label</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Rename the variable associated to the block identified by `label`.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Rename the variable associated to the block identified by `label`.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">label</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">srcs</span><span class="p">:</span>
<span class="n">t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">srcs</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">Temporary</span><span class="p">):</span>

View File

@ -90,17 +90,17 @@
<div class="viewcode-block" id="call"><a class="viewcode-back" href="../../api/Lib.RiscV.html#Lib.RiscV.call">[docs]</a><span class="k">def</span> <span class="nf">call</span><span class="p">(</span><span class="n">function</span><span class="p">:</span> <span class="n">Function</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Instru3A</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Function call.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Function call.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Instru3A</span><span class="p">(</span><span class="s1">&#39;call&#39;</span><span class="p">,</span> <span class="n">function</span><span class="p">)</span></div>
<div class="viewcode-block" id="jump"><a class="viewcode-back" href="../../api/Lib.RiscV.html#Lib.RiscV.jump">[docs]</a><span class="k">def</span> <span class="nf">jump</span><span class="p">(</span><span class="n">label</span><span class="p">:</span> <span class="n">Label</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">AbsoluteJump</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Unconditional jump to label.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Unconditional jump to label.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">AbsoluteJump</span><span class="p">(</span><span class="n">label</span><span class="p">)</span></div>
<div class="viewcode-block" id="conditional_jump"><a class="viewcode-back" href="../../api/Lib.RiscV.html#Lib.RiscV.conditional_jump">[docs]</a><span class="k">def</span> <span class="nf">conditional_jump</span><span class="p">(</span><span class="n">label</span><span class="p">:</span> <span class="n">Label</span><span class="p">,</span> <span class="n">op1</span><span class="p">:</span> <span class="n">Operand</span><span class="p">,</span> <span class="n">cond</span><span class="p">:</span> <span class="n">Condition</span><span class="p">,</span> <span class="n">op2</span><span class="p">:</span> <span class="n">Operand</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a conditional jump to the code.</span>
<span class="sd">&quot;&quot;&quot;Add a conditional jump to the code.</span>
<span class="sd"> This is a wrapper around bge, bgt, beq, ... c is a Condition, like</span>
<span class="sd"> Condition(&#39;bgt&#39;), Condition(MiniCParser.EQ), ...</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -141,12 +141,12 @@
<div class="viewcode-block" id="land"><a class="viewcode-back" href="../../api/Lib.RiscV.html#Lib.RiscV.land">[docs]</a><span class="k">def</span> <span class="nf">land</span><span class="p">(</span><span class="n">dr</span><span class="p">:</span> <span class="n">Operand</span><span class="p">,</span> <span class="n">sr1</span><span class="p">:</span> <span class="n">Operand</span><span class="p">,</span> <span class="n">sr2orimm7</span><span class="p">:</span> <span class="n">Operand</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Instru3A</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;And instruction (cannot be called `and` due to Python and).&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;And instruction (cannot be called `and` due to Python and).&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Instru3A</span><span class="p">(</span><span class="s2">&quot;and&quot;</span><span class="p">,</span> <span class="n">dr</span><span class="p">,</span> <span class="n">sr1</span><span class="p">,</span> <span class="n">sr2orimm7</span><span class="p">)</span></div>
<div class="viewcode-block" id="lor"><a class="viewcode-back" href="../../api/Lib.RiscV.html#Lib.RiscV.lor">[docs]</a><span class="k">def</span> <span class="nf">lor</span><span class="p">(</span><span class="n">dr</span><span class="p">:</span> <span class="n">Operand</span><span class="p">,</span> <span class="n">sr1</span><span class="p">:</span> <span class="n">Operand</span><span class="p">,</span> <span class="n">sr2orimm7</span><span class="p">:</span> <span class="n">Operand</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Instru3A</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Or instruction (cannot be called `or` due to Python or).&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Or instruction (cannot be called `or` due to Python or).&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Instru3A</span><span class="p">(</span><span class="s2">&quot;or&quot;</span><span class="p">,</span> <span class="n">dr</span><span class="p">,</span> <span class="n">sr1</span><span class="p">,</span> <span class="n">sr2orimm7</span><span class="p">)</span></div>

View File

@ -95,7 +95,7 @@
<div class="viewcode-block" id="regset_to_string"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.regset_to_string">[docs]</a><span class="k">def</span> <span class="nf">regset_to_string</span><span class="p">(</span><span class="n">registerset</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Utility function: pretty-prints a set of locations.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Utility function: pretty-prints a set of locations.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s2">&quot;{&quot;</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">registerset</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;}&quot;</span></div>
@ -105,32 +105,32 @@
<div class="viewcode-block" id="Statement"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Statement">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">unsafe_hash</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Statement</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;A Statement, which is an instruction, a comment or a label.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;A Statement, which is an instruction, a comment or a label.&quot;&quot;&quot;</span>
<div class="viewcode-block" id="Statement.defined"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Statement.defined">[docs]</a> <span class="k">def</span> <span class="nf">defined</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Operands defined (written) in this instruction&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Operands defined (written) in this instruction&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[]</span></div>
<div class="viewcode-block" id="Statement.used"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Statement.used">[docs]</a> <span class="k">def</span> <span class="nf">used</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Operands used (read) in this instruction&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Operands used (read) in this instruction&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[]</span></div>
<div class="viewcode-block" id="Statement.substitute"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Statement.substitute">[docs]</a> <span class="k">def</span> <span class="nf">substitute</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">TStatement</span><span class="p">,</span> <span class="n">subst</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Operand</span><span class="p">,</span> <span class="n">Operand</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">TStatement</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return a new instruction, cloned from this one, replacing operands</span>
<span class="sd">&quot;&quot;&quot;Return a new instruction, cloned from this one, replacing operands</span>
<span class="sd"> that appear as key in subst by their value.&quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
<span class="s2">&quot;substitute: Operands </span><span class="si">{}</span><span class="s2"> are not present in instruction </span><span class="si">{}</span><span class="s2">&quot;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">subst</span><span class="p">,</span> <span class="bp">self</span><span class="p">))</span></div>
<div class="viewcode-block" id="Statement.with_args"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Statement.with_args">[docs]</a> <span class="k">def</span> <span class="nf">with_args</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">TStatement</span><span class="p">,</span> <span class="n">new_args</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">TStatement</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return a new instruction, cloned from this one, where operands have</span>
<span class="sd">&quot;&quot;&quot;Return a new instruction, cloned from this one, where operands have</span>
<span class="sd"> been replaced by new_args.&quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
<span class="s2">&quot;substitute: Operands </span><span class="si">{}</span><span class="s2"> are not present in instruction </span><span class="si">{}</span><span class="s2">&quot;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">new_args</span><span class="p">,</span> <span class="bp">self</span><span class="p">))</span></div>
<div class="viewcode-block" id="Statement.printIns"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Statement.printIns">[docs]</a> <span class="k">def</span> <span class="nf">printIns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stream</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Print the statement on the given output.</span>
<span class="sd"> Should never be called on the base class.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -139,7 +139,7 @@
<div class="viewcode-block" id="Comment"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Comment">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">unsafe_hash</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Comment</span><span class="p">(</span><span class="n">Statement</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;A comment.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;A comment.&quot;&quot;&quot;</span>
<span class="n">comment</span><span class="p">:</span> <span class="nb">str</span>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c1"># use only for print_dot !</span>
@ -151,7 +151,7 @@
<div class="viewcode-block" id="Label"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Label">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">unsafe_hash</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Label</span><span class="p">(</span><span class="n">Statement</span><span class="p">,</span> <span class="n">Operand</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;A label is both a Statement and an Operand.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;A label is both a Statement and an Operand.&quot;&quot;&quot;</span>
<span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@ -170,7 +170,7 @@
<span class="n">_read_only</span><span class="p">:</span> <span class="nb">bool</span>
<div class="viewcode-block" id="Instruction.is_read_only"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Instruction.is_read_only">[docs]</a> <span class="k">def</span> <span class="nf">is_read_only</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> True if the instruction only reads from its operands.</span>
<span class="sd"> Otherwise, the first operand is considered as the destination</span>
@ -182,7 +182,7 @@
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>
<div class="viewcode-block" id="Instruction.args"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Instruction.args">[docs]</a> <span class="k">def</span> <span class="nf">args</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;List of operands the instruction takes&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;List of operands the instruction takes&quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>
<div class="viewcode-block" id="Instruction.defined"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Instruction.defined">[docs]</a> <span class="k">def</span> <span class="nf">defined</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@ -214,7 +214,7 @@
<span class="k">return</span> <span class="nb">hash</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">ins</span><span class="p">,</span> <span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">()))</span>
<div class="viewcode-block" id="Instruction.printIns"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.Instruction.printIns">[docs]</a> <span class="k">def</span> <span class="nf">printIns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stream</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Print the instruction on the given output.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Print the instruction on the given output.&quot;&quot;&quot;</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="n">file</span><span class="o">=</span><span class="n">stream</span><span class="p">)</span></div></div>
@ -273,7 +273,7 @@
<div class="viewcode-block" id="AbsoluteJump"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.AbsoluteJump">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">init</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">AbsoluteJump</span><span class="p">(</span><span class="n">Instruction</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; An Absolute Jump is a specific kind of instruction&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot; An Absolute Jump is a specific kind of instruction&quot;&quot;&quot;</span>
<span class="n">ins</span> <span class="o">=</span> <span class="s2">&quot;j&quot;</span>
<span class="n">label</span><span class="p">:</span> <span class="n">Label</span>
<span class="n">_read_only</span> <span class="o">=</span> <span class="kc">True</span>
@ -305,13 +305,13 @@
<span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="nb">super</span><span class="p">)</span>
<div class="viewcode-block" id="AbsoluteJump.targets"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.AbsoluteJump.targets">[docs]</a> <span class="k">def</span> <span class="nf">targets</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Label</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the labels targetted by the AbsoluteJump.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the labels targetted by the AbsoluteJump.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">]</span></div></div>
<div class="viewcode-block" id="ConditionalJump"><a class="viewcode-back" href="../../api/Lib.Statement.html#Lib.Statement.ConditionalJump">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">init</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">ConditionalJump</span><span class="p">(</span><span class="n">Instruction</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; A Conditional Jump is a specific kind of instruction&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot; A Conditional Jump is a specific kind of instruction&quot;&quot;&quot;</span>
<span class="n">cond</span><span class="p">:</span> <span class="n">Condition</span>
<span class="n">label</span><span class="p">:</span> <span class="n">Label</span>
<span class="n">op1</span><span class="p">:</span> <span class="n">Operand</span>

View File

@ -108,7 +108,7 @@
<div class="viewcode-block" id="Return"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.Return">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">unsafe_hash</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Return</span><span class="p">(</span><span class="n">Statement</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;A terminator that marks the end of the function.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;A terminator that marks the end of the function.&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">(</span><span class="s2">&quot;return&quot;</span><span class="p">)</span>
@ -117,7 +117,7 @@
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;return&quot;</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">stream</span><span class="p">)</span></div>
<div class="viewcode-block" id="Return.targets"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.Return.targets">[docs]</a> <span class="k">def</span> <span class="nf">targets</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Label</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the labels targetted by the Return terminator.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the labels targetted by the Return terminator.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[]</span></div>
<div class="viewcode-block" id="Return.args"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.Return.args">[docs]</a> <span class="k">def</span> <span class="nf">args</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Operand</span><span class="p">]:</span>
@ -146,7 +146,7 @@
<div class="viewcode-block" id="BranchingTerminator"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.BranchingTerminator">[docs]</a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">init</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">BranchingTerminator</span><span class="p">(</span><span class="n">Instruction</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;A terminating statement with a condition.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;A terminating statement with a condition.&quot;&quot;&quot;</span>
<span class="c1">#: The condition of the branch</span>
<span class="n">cond</span><span class="p">:</span> <span class="n">Condition</span>
@ -173,7 +173,7 @@
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">op1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">op2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_then</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_else</span><span class="p">]</span></div>
<div class="viewcode-block" id="BranchingTerminator.targets"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.BranchingTerminator.targets">[docs]</a> <span class="k">def</span> <span class="nf">targets</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Label</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the labels targetted by the Branching terminator.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;Return the labels targetted by the Branching terminator.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">label_then</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_else</span><span class="p">]</span></div>
<div class="viewcode-block" id="BranchingTerminator.rename"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.BranchingTerminator.rename">[docs]</a> <span class="k">def</span> <span class="nf">rename</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">renamer</span><span class="p">:</span> <span class="n">Renamer</span><span class="p">):</span>
@ -213,7 +213,7 @@
<div class="viewcode-block" id="jump2terminator"><a class="viewcode-back" href="../../api/Lib.Terminator.html#Lib.Terminator.jump2terminator">[docs]</a><span class="k">def</span> <span class="nf">jump2terminator</span><span class="p">(</span><span class="n">j</span><span class="p">:</span> <span class="n">ConditionalJump</span> <span class="o">|</span> <span class="n">AbsoluteJump</span> <span class="o">|</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">next_label</span><span class="p">:</span> <span class="n">Label</span> <span class="o">|</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Terminator</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Construct the Terminator associated to the potential jump j</span>
<span class="sd"> to the potential label next_label.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -227,7 +227,7 @@
<span class="k">return</span> <span class="n">BranchingTerminator</span><span class="p">(</span><span class="n">j</span><span class="o">.</span><span class="n">cond</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">op1</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">op2</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">label</span><span class="p">,</span> <span class="n">label_else</span><span class="p">)</span>
<span class="k">case</span> <span class="n">AbsoluteJump</span><span class="p">():</span>
<span class="k">return</span> <span class="n">AbsoluteJump</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="n">j</span><span class="o">.</span><span class="n">label</span><span class="p">)</span>
<span class="k">case</span><span class="w"> </span><span class="k">_</span><span class="p">:</span>
<span class="k">case</span> <span class="k">_</span><span class="p">:</span>
<span class="k">if</span> <span class="n">next_label</span><span class="p">:</span>
<span class="k">return</span> <span class="n">AbsoluteJump</span><span class="p">(</span><span class="n">next_label</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Allocator module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.CFG module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Dominators module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Errors module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.FunctionData module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Graphes module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.LinearCode module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Operands module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.PhiNode module &mdash; MiniC documentation</title>
@ -105,8 +105,9 @@ b._phis for a <a class="reference internal" href="Lib.CFG.html#Lib.CFG.Block" ti
<dd><p>Bases: <a class="reference internal" href="Lib.Statement.html#Lib.Statement.Statement" title="Lib.Statement.Statement"><code class="xref py py-class docutils literal notranslate"><span class="pre">Statement</span></code></a></p>
<p>A φ node is a renaming in the CFG, of the form temp_x = φ(temp_0, …, temp_n).
The field var contains the variable temp_x.
The field srcs relies for each precedent block in the CFG, identified with its label,
the variable temp_i of the φ node.</p>
The field srcs links each corresponding predecessor in the CFG
—identified by its label—, to the variable temp_i of the φ
node.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="Lib.PhiNode.PhiNode.var">
<span class="sig-name descname"><span class="pre">var</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference internal" href="Lib.Operands.html#Lib.Operands.DataLocation" title="Lib.Operands.DataLocation"><span class="pre">DataLocation</span></a></em><a class="headerlink" href="#Lib.PhiNode.PhiNode.var" title="Permalink to this definition"></a></dt>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.RiscV module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Statement module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.Terminator module &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib package &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MiniC &mdash; MiniC documentation</title>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Welcome to MiniCs documentation! &mdash; MiniC documentation</title>

File diff suppressed because one or more lines are too long