<spanid="lib-allocator-module"></span><h1>Lib.Allocator module<aclass="headerlink"href="#module-Lib.Allocator"title="Permalink to this heading"></a></h1>
<p>This file defines the base class <aclass="reference internal"href="#Lib.Allocator.Allocator"title="Lib.Allocator.Allocator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Allocator</span></code></a>
and the naïve implementation <aclass="reference internal"href="#Lib.Allocator.NaiveAllocator"title="Lib.Allocator.NaiveAllocator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">NaiveAllocator</span></code></a>.</p>
<emclass="property"><spanclass="pre">class</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Lib.Allocator.</span></span><spanclass="sig-name descname"><spanclass="pre">Allocator</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">fdata</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.FunctionData.html#Lib.FunctionData.FunctionData"title="Lib.FunctionData.FunctionData"><spanclass="pre">FunctionData</span></a></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Allocator.html#Allocator"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.Allocator"title="Permalink to this definition"></a></dt>
with a mapping from temporaries to where they should actually be stored
(in registers or in memory).</p></li>
<li><p>Then, <aclass="reference internal"href="#Lib.Allocator.Allocator.replace"title="Lib.Allocator.Allocator.replace"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">replace()</span></code></a> is called for each instruction in order to
replace the temporary operands with the previously assigned locations
(and possibly add some instructions before or after).
Concretely, it returns a list of instructions that should replace the original
instruction. The actual iteration over all the instructions is handled transparently
by <aclass="reference internal"href="Lib.LinearCode.html#Lib.LinearCode.LinearCode.iter_statements"title="Lib.LinearCode.LinearCode.iter_statements"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">Lib.LinearCode.LinearCode.iter_statements()</span></code></a>.</p></li>
<spanclass="sig-name descname"><spanclass="pre">prepare</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">None</span></span></span><aclass="reference internal"href="../_modules/Lib/Allocator.html#Allocator.prepare"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.Allocator.prepare"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">replace</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">old_instr</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Instruction"title="Lib.Statement.Instruction"><spanclass="pre">Instruction</span></a></span></em><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">List</span><spanclass="p"><spanclass="pre">[</span></span><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Instruction"title="Lib.Statement.Instruction"><spanclass="pre">Instruction</span></a><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../_modules/Lib/Allocator.html#Allocator.replace"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.Allocator.replace"title="Permalink to this definition"></a></dt>
<dd><p>Transform an instruction with temporaries into a list of instructions.</p>
<spanclass="sig-name descname"><spanclass="pre">rewriteCode</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">listcode</span></span></em><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">None</span></span></span><aclass="reference internal"href="../_modules/Lib/Allocator.html#Allocator.rewriteCode"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.Allocator.rewriteCode"title="Permalink to this definition"></a></dt>
<dd><p>Modify the code to replace temporaries with
<emclass="property"><spanclass="pre">class</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Lib.Allocator.</span></span><spanclass="sig-name descname"><spanclass="pre">NaiveAllocator</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">fdata</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.FunctionData.html#Lib.FunctionData.FunctionData"title="Lib.FunctionData.FunctionData"><spanclass="pre">FunctionData</span></a></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Allocator.html#NaiveAllocator"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.NaiveAllocator"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">replace</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">old_instr</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Instruction"title="Lib.Statement.Instruction"><spanclass="pre">Instruction</span></a></span></em><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">List</span><spanclass="p"><spanclass="pre">[</span></span><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Instruction"title="Lib.Statement.Instruction"><spanclass="pre">Instruction</span></a><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../_modules/Lib/Allocator.html#NaiveAllocator.replace"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.NaiveAllocator.replace"title="Permalink to this definition"></a></dt>
<dd><p>Replace Temporary operands with the corresponding allocated Register.</p>
<spanclass="sig-name descname"><spanclass="pre">prepare</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">None</span></span></span><aclass="reference internal"href="../_modules/Lib/Allocator.html#NaiveAllocator.prepare"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Allocator.NaiveAllocator.prepare"title="Permalink to this definition"></a></dt>