<spanid="lib-terminator-module"></span><h1>Lib.Terminator module<aclass="headerlink"href="#module-Lib.Terminator"title="Permalink to this heading"></a></h1>
<p>MIF08, CAP, CFG library - Terminators.</p>
<p>Each <aclass="reference internal"href="Lib.CFG.html#Lib.CFG.Block"title="Lib.CFG.Block"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">block</span></code></a> of a <aclass="reference internal"href="Lib.CFG.html#Lib.CFG.CFG"title="Lib.CFG.CFG"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">CFG</span></code></a>
ends with a branching instruction called a terminator.
There are three kinds of terminators:</p>
<ulclass="simple">
<li><p><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.AbsoluteJump"title="Lib.Statement.AbsoluteJump"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Lib.Statement.AbsoluteJump</span></code></a> is a non-conditional jump
to another block of the CFG</p></li>
<li><p><aclass="reference internal"href="#Lib.Terminator.BranchingTerminator"title="Lib.Terminator.BranchingTerminator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">BranchingTerminator</span></code></a> is a conditional branching
instruction with two successor blocks.
Unlike the class <aclass="reference internal"href="Lib.Statement.html#Lib.Statement.ConditionalJump"title="Lib.Statement.ConditionalJump"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">ConditionalJump</span></code></a>
that was used in <aclass="reference internal"href="Lib.LinearCode.html#Lib.LinearCode.LinearCode"title="Lib.LinearCode.LinearCode"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">LinearCode</span></code></a>,
both successor labels have to be specified.</p></li>
<li><p><aclass="reference internal"href="#Lib.Terminator.Return"title="Lib.Terminator.Return"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Return</span></code></a> marks the end of the function</p></li>
</ul>
<p>During the construction of the CFG, <aclass="reference internal"href="#Lib.Terminator.jump2terminator"title="Lib.Terminator.jump2terminator"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">jump2terminator()</span></code></a> builds
a terminator for each extracted chunk of instructions.</p>
<emclass="property"><spanclass="pre">class</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Lib.Terminator.</span></span><spanclass="sig-name descname"><spanclass="pre">Return</span></span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">printIns</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">stream</span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.printIns"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.printIns"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">targets</span></span><spanclass="sig-paren">(</span><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.Label"title="Lib.Statement.Label"><spanclass="pre">Label</span></a><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.targets"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.targets"title="Permalink to this definition"></a></dt>
<dd><p>Return the labels targetted by the Return terminator.</p>
<spanclass="sig-name descname"><spanclass="pre">args</span></span><spanclass="sig-paren">(</span><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.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.args"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.args"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">rename</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">renamer</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Renamer"title="Lib.Operands.Renamer"><spanclass="pre">Renamer</span></a></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.rename"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.rename"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">substitute</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">subst</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">Dict</span><spanclass="p"><spanclass="pre">[</span></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">]</span></span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.substitute"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.substitute"title="Permalink to this definition"></a></dt>
<dd><p>Return a new instruction, cloned from this one, replacing operands
<spanclass="sig-name descname"><spanclass="pre">with_args</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">new_args</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">List</span><spanclass="p"><spanclass="pre">[</span></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">]</span></span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.with_args"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.with_args"title="Permalink to this definition"></a></dt>
<dd><p>Return a new instruction, cloned from this one, where operands have
<spanclass="sig-name descname"><spanclass="pre">is_read_only</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">bool</span></span></span><aclass="reference internal"href="../_modules/Lib/Terminator.html#Return.is_read_only"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.Return.is_read_only"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">cond</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Condition"title="Lib.Operands.Condition"><spanclass="pre">Condition</span></a></em><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.cond"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">label_then</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Label"title="Lib.Statement.Label"><spanclass="pre">Label</span></a></em><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.label_then"title="Permalink to this definition"></a></dt>
<dd><p>The destination label if the condition is true</p>
<spanclass="sig-name descname"><spanclass="pre">label_else</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Label"title="Lib.Statement.Label"><spanclass="pre">Label</span></a></em><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.label_else"title="Permalink to this definition"></a></dt>
<dd><p>The destination label if the condition is false</p>
<spanclass="sig-name descname"><spanclass="pre">op1</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a></em><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.op1"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">op2</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a></em><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.op2"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">args</span></span><spanclass="sig-paren">(</span><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.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../_modules/Lib/Terminator.html#BranchingTerminator.args"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.args"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">targets</span></span><spanclass="sig-paren">(</span><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.Label"title="Lib.Statement.Label"><spanclass="pre">Label</span></a><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../_modules/Lib/Terminator.html#BranchingTerminator.targets"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.targets"title="Permalink to this definition"></a></dt>
<dd><p>Return the labels targetted by the Branching terminator.</p>
<spanclass="sig-name descname"><spanclass="pre">rename</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">renamer</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Renamer"title="Lib.Operands.Renamer"><spanclass="pre">Renamer</span></a></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#BranchingTerminator.rename"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.rename"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">substitute</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">subst</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">Dict</span><spanclass="p"><spanclass="pre">[</span></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">]</span></span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#BranchingTerminator.substitute"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.substitute"title="Permalink to this definition"></a></dt>
<dd><p>Return a new instruction, cloned from this one, replacing operands
<spanclass="sig-name descname"><spanclass="pre">with_args</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">new_args</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">List</span><spanclass="p"><spanclass="pre">[</span></span><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.Operand"title="Lib.Operands.Operand"><spanclass="pre">Operand</span></a><spanclass="p"><spanclass="pre">]</span></span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/Terminator.html#BranchingTerminator.with_args"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.Terminator.BranchingTerminator.with_args"title="Permalink to this definition"></a></dt>
<dd><p>Return a new instruction, cloned from this one, where operands have
<spanclass="sig-prename descclassname"><spanclass="pre">Lib.Terminator.</span></span><spanclass="sig-name descname"><spanclass="pre">Terminator</span></span><emclass="property"><spanclass="w"></span><spanclass="p"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="pre">Lib.Terminator.Return</span><spanclass="pre">|</span><spanclass="pre">Lib.Statement.AbsoluteJump</span><spanclass="pre">|</span><spanclass="pre">Lib.Terminator.BranchingTerminator</span></em><aclass="headerlink"href="#Lib.Terminator.Terminator"title="Permalink to this definition"></a></dt>