<spanid="lib-linearcode-module"></span><h1>Lib.LinearCode module<aclass="headerlink"href="#module-Lib.LinearCode"title="Permalink to this heading"></a></h1>
<emclass="property"><spanclass="pre">class</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Lib.LinearCode.</span></span><spanclass="sig-name descname"><spanclass="pre">LinearCode</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">name</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">str</span></span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/Lib/LinearCode.html#LinearCode"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode"title="Permalink to this definition"></a></dt>
<p>Representation of a RiscV program as a list of instructions.</p>
<p><aclass="reference internal"href="#Lib.LinearCode.LinearCode.add_instruction"title="Lib.LinearCode.LinearCode.add_instruction"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">add_instruction()</span></code></a> is repeatedly called in the codegen visitor
to build a complete list of RiscV instructions for the source program.</p>
<p>The <aclass="reference internal"href="#Lib.LinearCode.LinearCode.fdata"title="Lib.LinearCode.LinearCode.fdata"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">fdata</span></code></a> member variable contains some meta-information
on the program, for instance to allocate a new temporary.
See <aclass="reference internal"href="Lib.FunctionData.html#Lib.FunctionData.FunctionData"title="Lib.FunctionData.FunctionData"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Lib.FunctionData.FunctionData</span></code></a>.</p>
<spanclass="sig-name descname"><spanclass="pre">fdata</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="Lib.FunctionData.html#Lib.FunctionData.FunctionData"title="Lib.FunctionData.FunctionData"><spanclass="pre">FunctionData</span></a></em><aclass="headerlink"href="#Lib.LinearCode.LinearCode.fdata"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">iter_statements</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">f</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/LinearCode.html#LinearCode.iter_statements"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode.iter_statements"title="Permalink to this definition"></a></dt>
<dd><p>Iterate over instructions.
For each real instruction i (not label or comment), replace it
<spanclass="sig-name descname"><spanclass="pre">add_label</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">s</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.Statement.html#Lib.Statement.Label"title="Lib.Statement.Label"><spanclass="pre">Label</span></a></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/LinearCode.html#LinearCode.add_label"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode.add_label"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">add_comment</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">s</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">str</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/LinearCode.html#LinearCode.add_comment"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode.add_comment"title="Permalink to this definition"></a></dt>
<spanclass="sig-name descname"><spanclass="pre">add_instruction_PRINTLN_INT</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">reg</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><aclass="reference internal"href="Lib.Operands.html#Lib.Operands.DataLocation"title="Lib.Operands.DataLocation"><spanclass="pre">DataLocation</span></a></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/LinearCode.html#LinearCode.add_instruction_PRINTLN_INT"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode.add_instruction_PRINTLN_INT"title="Permalink to this definition"></a></dt>
<dd><p>Print integer value, with newline. (see Expand)</p>
<spanclass="sig-name descname"><spanclass="pre">print_code</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">output</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">comment</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</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/LinearCode.html#LinearCode.print_code"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode.print_code"title="Permalink to this definition"></a></dt>
<dd><p>Outputs the RiscV program as text to a file at the given path.</p>
<spanclass="sig-name descname"><spanclass="pre">print_dot</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">filename</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">str</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">DF</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">view</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">False</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/LinearCode.html#LinearCode.print_dot"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#Lib.LinearCode.LinearCode.print_dot"title="Permalink to this definition"></a></dt>
<dd><p>Outputs the RiscV program as graph to a file at the given path.</p>