mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-01 04:59:05 +00:00
542 lines
57 KiB
HTML
542 lines
57 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<!-- This file is generated by Nim. -->
|
|
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>cnif</title>
|
|
|
|
<!-- Google fonts -->
|
|
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
|
|
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
|
|
|
|
<!-- Favicon -->
|
|
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
|
|
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
|
|
|
|
<!-- CSS -->
|
|
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
|
|
|
|
<!-- JS -->
|
|
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
|
|
</head>
|
|
<body>
|
|
<div class="document" id="documentId">
|
|
<input type="checkbox" id="nav-toggle" hidden>
|
|
<label for="nav-toggle" id="nav-burger">☰</label>
|
|
<label for="nav-toggle" id="nav-overlay"></label>
|
|
<div class="container">
|
|
<h1 class="title">cnif</h1>
|
|
<div class="row">
|
|
<div class="three columns">
|
|
<div class="theme-select-wrapper">
|
|
<label for="theme-select">Theme: </label>
|
|
<select id="theme-select" onchange="setTheme(this.value)">
|
|
<option value="auto">🌗 Match OS</option>
|
|
<option value="dark">🌑 Dark</option>
|
|
<option value="light">🌕 Light</option>
|
|
</select>
|
|
</div>
|
|
<div id="global-links">
|
|
<ul class="simple">
|
|
<li><a id="indexLink" href="theindex.html">Index</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="searchInputDiv">
|
|
Search: <input type="search" id="searchInput" oninput="search()"/>
|
|
</div>
|
|
<div>
|
|
Group by:
|
|
<select onchange="groupBy(this.value)">
|
|
<option value="section">Section</option>
|
|
<option value="type">Type</option>
|
|
</select>
|
|
</div>
|
|
<ul class="simple simple-toc" id="toc-list">
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#CnifHeads" title="CnifHeads = object
|
|
valid*: bool ## file parsed, carries the meta head and has
|
|
## the current format version
|
|
initRequired*: bool
|
|
datInitRequired*: bool
|
|
semmedNif*: string ## the semmed NIF this TU was generated from
|
|
moduleBase*: string ## the module's mangled base name
|
|
cdefs*: seq[tuple[cname, nifname: string]] ## the proc definitions
|
|
cdata*: seq[tuple[cname, nifname: string]] ## the data definitions
|
|
crefs*: seq[string] ## C names referenced but not defined here
|
|
cdeps*: seq[string] ## module suffixes whose routine bodies this
|
|
## TU embeds (impl-cookie gated on reuse)">CnifHeads</a></li>
|
|
<li><a class="reference" href="#CnifLiveness" title="CnifLiveness = object
|
|
defs*: int ## proc definitions emitted across all modules
|
|
liveDefs*: int ## of those, reachable from the roots
|
|
live*: HashSet[string] ## live C names
|
|
broken*: bool">CnifLiveness</a></li>
|
|
<li><a class="reference" href="#MergeDecision" title="MergeDecision = object
|
|
live*: HashSet[string] ## globally reachable C names (dead cdefs
|
|
## are dropped from every module)
|
|
owners*: Table[string, string] ## for each `'u'`-flagged (unique,
|
|
## externally-linked) definition, the single
|
|
## artifact base name allowed to embed its
|
|
## body; every other module prototypes it
|
|
broken*: bool ## an artifact was missing or unparsable —
|
|
## the caller should fall back / regenerate
|
|
defs*, liveDefs*: int">MergeDecision</a></li>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#CnifDefEnd" title="CnifDefEnd = '\x05'">CnifDefEnd</a></li>
|
|
<li><a class="reference" href="#CnifDefSep" title="CnifDefSep = '\x1F'">CnifDefSep</a></li>
|
|
<li><a class="reference" href="#CnifDefStart" title="CnifDefStart = '\x04'">CnifDefStart</a></li>
|
|
<li><a class="reference" href="#CnifSymEnd" title="CnifSymEnd = '\x03'">CnifSymEnd</a></li>
|
|
<li><a class="reference" href="#CnifSymStart" title="CnifSymStart = '\x02'">CnifSymStart</a></li>
|
|
<li><a class="reference" href="#CnifVersion" title="CnifVersion = "4"">CnifVersion</a></li>
|
|
<li><a class="reference" href="#MergeDecisionFile" title="MergeDecisionFile = "ic.backend.merge.nif"">MergeDecisionFile</a></li>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<ul class="simple nested-toc-section">cnifDefDirective
|
|
<li><a class="reference" href="#cnifDefDirective%2Cstring%2Cstring%2Cstring" title="cnifDefDirective(name, flags, nifName: string): string">cnifDefDirective(name, flags, nifName: string): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">cnifEndDefs
|
|
<li><a class="reference" href="#cnifEndDefs" title="cnifEndDefs(): string">cnifEndDefs(): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">computeLiveFromCArtifacts
|
|
<li><a class="reference" href="#computeLiveFromCArtifacts%2CopenArray%5Bstring%5D" title="computeLiveFromCArtifacts(files: openArray[string]): CnifLiveness">computeLiveFromCArtifacts(files: openArray[string]): CnifLiveness</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">computeMergeDecision
|
|
<li><a class="reference" href="#computeMergeDecision%2CopenArray%5Bstring%5D" title="computeMergeDecision(files: openArray[string]): MergeDecision">computeMergeDecision(files: openArray[string]): MergeDecision</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">hasCnifMarks
|
|
<li><a class="reference" href="#hasCnifMarks%2Cstring" title="hasCnifMarks(s: string): bool">hasCnifMarks(s: string): bool</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">markCName
|
|
<li><a class="reference" href="#markCName%2Cstring" title="markCName(name: string): string">markCName(name: string): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">readCnifHeads
|
|
<li><a class="reference" href="#readCnifHeads%2Cstring" title="readCnifHeads(f: string): CnifHeads">readCnifHeads(f: string): CnifHeads</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">readMergeDecision
|
|
<li><a class="reference" href="#readMergeDecision%2Cstring" title="readMergeDecision(f: string): MergeDecision">readMergeDecision(f: string): MergeDecision</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">renderCFromArtifact
|
|
<li><a class="reference" href="#renderCFromArtifact%2Cstring%2CMergeDecision%2Cstring%2Cint" title="renderCFromArtifact(artifact: string; d: MergeDecision; ownerId: string;
|
|
dropped: var int): string">renderCFromArtifact(artifact: string; d: MergeDecision; ownerId: string;
|
|
dropped: var int): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">renderMarkedC
|
|
<li><a class="reference" href="#renderMarkedC%2Cstring%2CHashSet%5Bstring%5D%2Cint" title="renderMarkedC(code: string; live: HashSet[string]; dropped: var int): string">renderMarkedC(code: string; live: HashSet[string]; dropped: var int): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">stripCnifMarks
|
|
<li><a class="reference" href="#stripCnifMarks%2Cstring" title="stripCnifMarks(s: string): string">stripCnifMarks(s: string): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">writeCnifArtifact
|
|
<li><a class="reference" href="#writeCnifArtifact%2Cstring%2Cstring%2CopenArray%5Btuple%5Bstring%2Cstring%5D%5D%2Cstring%2Cstring%2CopenArray%5Bstring%5D" title="writeCnifArtifact(code: string; outfile: string; initRequired = false;
|
|
datInitRequired = false;
|
|
dataDefs: openArray[tuple[cname, nifname: string]] = [];
|
|
semmedNif = ""; moduleBase = "";
|
|
implDeps: openArray[string] = [])">writeCnifArtifact(code: string; outfile: string; initRequired = false;
|
|
datInitRequired = false;
|
|
dataDefs: openArray[tuple[cname, nifname: string]] = [];
|
|
semmedNif = ""; moduleBase = "";
|
|
implDeps: openArray[string] = [])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">writeMergeDecision
|
|
<li><a class="reference" href="#writeMergeDecision%2Cstring%2CMergeDecision" title="writeMergeDecision(outfile: string; d: MergeDecision)">writeMergeDecision(outfile: string; d: MergeDecision)</a></li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
<div class="nine columns" id="content">
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L1" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
<div id="tocRoot"></div>
|
|
|
|
<p class="module-desc"><p>The "cnif" artifact: the C code generator's output as a NIF file.</p>
|
|
<p>This is deliberately <em>not</em> NIFC: the C text is kept verbatim (Nim's C-level machinery — exception handling in particular — is more refined than what NIFC models today; the gap can be closed incrementally later). The only structure the artifact adds is the part dead code elimination and generic-instance merging need:</p>
|
|
<ul class="simple"><li>raw C text as string literals</li>
|
|
<li>every <em>global</em> entity's C name as a <tt class="docutils literal"><span class="pre"><span class="Identifier">Symbol</span></span></tt> token</li>
|
|
<li>every emitted proc definition as a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdef</span> <span class="Identifier">SymbolDef</span> <span class="Identifier">flags</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> group</li>
|
|
</ul>
|
|
<p>The C generator marks names with control characters at the single place a global's C name is minted (<tt class="docutils literal"><span class="pre"><span class="Identifier">fillBackendName</span></span></tt>) and emits a definition directive at the single place finished procs are appended; the marks then ride through all of the snippet composition untouched. This module turns the final marked module text into the <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt> artifact and strips the marks for the actual <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span></span></tt> output. Rendering C from the artifact is a plain token walk: string literals verbatim, symbols by name — which is also where a later merge step redirects losing generic instances.</p>
|
|
<p>Marker scheme (cannot collide: C string literals escape control chars, and <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="DecNumber">1</span></span></tt>/<tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="DecNumber">31</span></span></tt>/<tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="DecNumber">23</span></span></tt> of cgen's postprocess directives are distinct): 2 name 3 a global's C name 4 name 31 flags 31 nif 5 start of the definition of <tt class="docutils literal"><span class="pre"><span class="Identifier">name</span></span></tt>; <tt class="docutils literal"><span class="pre"><span class="Identifier">nif</span></span></tt> is the defining symbol's NIF name (empty for backend-minted symbols) so a later run can re-demand the definition 4 5 end of the definitions section</p>
|
|
</p>
|
|
<div class="section" id="7">
|
|
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
|
<dl class="item">
|
|
<div id="CnifHeads">
|
|
<dt><pre><a href="#CnifHeads"><span class="Identifier">CnifHeads</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
|
<span class="Identifier">valid</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span> <span class="Comment">## file parsed, carries the meta head and has</span>
|
|
<span class="Comment">## the current format version</span>
|
|
<span class="Identifier">initRequired</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span>
|
|
<span class="Identifier">datInitRequired</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span>
|
|
<span class="Identifier">semmedNif</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## the semmed NIF this TU was generated from</span>
|
|
<span class="Identifier">moduleBase</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## the module's mangled base name</span>
|
|
<span class="Identifier">cdefs</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">cname</span><span class="Other">,</span> <span class="Identifier">nifname</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">]</span><span class="Other">]</span> <span class="Comment">## the proc definitions</span>
|
|
<span class="Identifier">cdata</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">cname</span><span class="Other">,</span> <span class="Identifier">nifname</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">]</span><span class="Other">]</span> <span class="Comment">## the data definitions</span>
|
|
<span class="Identifier">crefs</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> <span class="Comment">## C names referenced but not defined here</span>
|
|
<span class="Identifier">cdeps</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> <span class="Comment">## module suffixes whose routine bodies this</span>
|
|
<span class="Comment">## TU embeds (impl-cookie gated on reuse)</span></pre></dt>
|
|
<dd>
|
|
|
|
The cheap-to-parse part of an artifact that a later run needs in order to reuse the TU without regenerating it.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L255" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L255" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="CnifLiveness">
|
|
<dt><pre><a href="#CnifLiveness"><span class="Identifier">CnifLiveness</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
|
<span class="Identifier">defs</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span> <span class="Comment">## proc definitions emitted across all modules</span>
|
|
<span class="Identifier">liveDefs</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span> <span class="Comment">## of those, reachable from the roots</span>
|
|
<span class="Identifier">live</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">HashSet</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> <span class="Comment">## live C names</span>
|
|
<span class="Identifier">broken</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L362" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L362" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="MergeDecision">
|
|
<dt><pre><a href="#MergeDecision"><span class="Identifier">MergeDecision</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
|
<span class="Identifier">live</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">HashSet</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> <span class="Comment">## globally reachable C names (dead cdefs</span>
|
|
<span class="Comment">## are dropped from every module)</span>
|
|
<span class="Identifier">owners</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">Table</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Identifier">string</span><span class="Other">]</span> <span class="Comment">## for each `'u'`-flagged (unique,</span>
|
|
<span class="Comment">## externally-linked) definition, the single</span>
|
|
<span class="Comment">## artifact base name allowed to embed its</span>
|
|
<span class="Comment">## body; every other module prototypes it</span>
|
|
<span class="Identifier">broken</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span> <span class="Comment">## an artifact was missing or unparsable —</span>
|
|
<span class="Comment">## the caller should fall back / regenerate</span>
|
|
<span class="Identifier">defs</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">liveDefs</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span></pre></dt>
|
|
<dd>
|
|
|
|
What the per-module backend's <tt class="docutils literal"><span class="pre"><span class="Identifier">merge</span></span></tt> stage computes from every module's <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt> and what its <tt class="docutils literal"><span class="pre"><span class="Identifier">emit</span></span></tt> stage consumes to render the final <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span></span></tt> of one module.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L468" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L468" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="10">
|
|
<h1><a class="toc-backref" href="#10">Consts</a></h1>
|
|
<dl class="item">
|
|
<div id="CnifDefEnd">
|
|
<dt><pre><a href="#CnifDefEnd"><span class="Identifier">CnifDefEnd</span></a> <span class="Other">=</span> <span class="CharLit">'\x05'</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L48" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L48" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="CnifDefSep">
|
|
<dt><pre><a href="#CnifDefSep"><span class="Identifier">CnifDefSep</span></a> <span class="Other">=</span> <span class="CharLit">'\x1F'</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L47" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L47" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="CnifDefStart">
|
|
<dt><pre><a href="#CnifDefStart"><span class="Identifier">CnifDefStart</span></a> <span class="Other">=</span> <span class="CharLit">'\x04'</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L46" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L46" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="CnifSymEnd">
|
|
<dt><pre><a href="#CnifSymEnd"><span class="Identifier">CnifSymEnd</span></a> <span class="Other">=</span> <span class="CharLit">'\x03'</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L45" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L45" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="CnifSymStart">
|
|
<dt><pre><a href="#CnifSymStart"><span class="Identifier">CnifSymStart</span></a> <span class="Other">=</span> <span class="CharLit">'\x02'</span></pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L44" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L44" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="CnifVersion">
|
|
<dt><pre><a href="#CnifVersion"><span class="Identifier">CnifVersion</span></a> <span class="Other">=</span> <span class="StringLit">"4"</span></pre></dt>
|
|
<dd>
|
|
|
|
Artifact format version, stored in the meta head. Artifacts written by an older compiler lack the NIF names and the cref group the def-retention check needs (v2), the cdeps group the fine-grained reuse gate needs (v3), or the type NIF names and cnif-marked extern RTTI references the typeinfo flavor of the def-retention check needs (v4); <tt class="docutils literal"><span class="pre"><span class="Identifier">readCnifHeads</span></span></tt> reports them as invalid so their TUs simply regenerate once.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L76" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L76" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="MergeDecisionFile">
|
|
<dt><pre><a href="#MergeDecisionFile"><span class="Identifier">MergeDecisionFile</span></a> <span class="Other">=</span> <span class="StringLit">"ic.backend.merge.nif"</span></pre></dt>
|
|
<dd>
|
|
|
|
Fixed name of the merge stage's output in the nimcache, read by <tt class="docutils literal"><span class="pre"><span class="Identifier">emit</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L587" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L587" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="12">
|
|
<h1><a class="toc-backref" href="#12">Procs</a></h1>
|
|
<dl class="item">
|
|
<div id="cnifDefDirective-procs-all">
|
|
<div id="cnifDefDirective,string,string,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#cnifDefDirective%2Cstring%2Cstring%2Cstring"><span class="Identifier">cnifDefDirective</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">,</span> <span class="Identifier">flags</span><span class="Other">,</span> <span class="Identifier">nifName</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L85" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L85" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="cnifEndDefs-procs-all">
|
|
<div id="cnifEndDefs">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#cnifEndDefs"><span class="Identifier">cnifEndDefs</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L88" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L88" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="computeLiveFromCArtifacts-procs-all">
|
|
<div id="computeLiveFromCArtifacts,openArray[string]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#computeLiveFromCArtifacts%2CopenArray%5Bstring%5D"><span class="Identifier">computeLiveFromCArtifacts</span></a><span class="Other">(</span><span class="Identifier">files</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="#CnifLiveness"><span class="Identifier">CnifLiveness</span></a> {.
|
|
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>dce1-style mark&sweep over the C-shaped artifacts: a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdef</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> group is a definition (flags 'x'/'c'/'m' — exportc, compilerproc, method/dispatcher — make it a root), names at the top level (data, globals, init code) are roots, names inside a group are its uses. Because the artifact is <em>fully lowered</em> output, no conservative modelling is needed: every call the C code contains is a token here.</p>
|
|
<p>NB: mangled C names contain no dots, so NIF's text reader classifies them as <tt class="docutils literal"><span class="pre"><span class="Identifier">Ident</span></span></tt> rather than <tt class="docutils literal"><span class="pre"><span class="Identifier">Symbol</span></span></tt>; the dialect therefore treats Ident tokens as name uses. Inside a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdef</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> the flags ident is the one immediately following the SymbolDef; everything after is a use.</p>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L368" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L368" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="computeMergeDecision-procs-all">
|
|
<div id="computeMergeDecision,openArray[string]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#computeMergeDecision%2CopenArray%5Bstring%5D"><span class="Identifier">computeMergeDecision</span></a><span class="Other">(</span><span class="Identifier">files</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="#MergeDecision"><span class="Identifier">MergeDecision</span></a> {.
|
|
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>One pass over every <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt>: the same mark&sweep as <tt class="docutils literal"><span class="pre"><span class="Identifier">computeLiveFromCArtifacts</span></span></tt> plus, per definition, owner assignment.</p>
|
|
<p>Each <tt class="docutils literal"><span class="pre"><span class="Identifier">cg</span></span></tt> process emits the body of every definition it demands (emit-everywhere), so the same externally-linked definition appears in several artifacts. A <tt class="docutils literal"><span class="pre"><span class="CharLit">'u'</span></span></tt> flag on the <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdef</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> marks those that need exactly one owner, assigned here across processes: the owner is the lexicographically smallest artifact that emits it — a pure function of the claimant set, hence stable across rebuilds. Definitions without <tt class="docutils literal"><span class="pre"><span class="CharLit">'u'</span></span></tt> (inline procs, dispatchers) are <tt class="docutils literal"><span class="pre"><span class="Keyword">static</span></span></tt>/main-only and emitted into every using TU, so they get no owner entry and are never deduplicated.</p>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L482" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L482" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="hasCnifMarks-procs-all">
|
|
<div id="hasCnifMarks,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#hasCnifMarks%2Cstring"><span class="Identifier">hasCnifMarks</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L53" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L53" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="markCName-procs-all">
|
|
<div id="markCName,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#markCName%2Cstring"><span class="Identifier">markCName</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L50" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L50" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="readCnifHeads-procs-all">
|
|
<div id="readCnifHeads,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#readCnifHeads%2Cstring"><span class="Identifier">readCnifHeads</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="#CnifHeads"><span class="Identifier">CnifHeads</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Reads <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">meta</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdata</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cref</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> and the <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdef</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> head names from an artifact. Artifacts written by an older compiler (no meta head or a different format version) report <tt class="docutils literal"><span class="pre"><span class="Identifier">valid</span><span class="Operator">=</span><span class="Identifier">false</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L270" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L270" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="readMergeDecision-procs-all">
|
|
<div id="readMergeDecision,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#readMergeDecision%2Cstring"><span class="Identifier">readMergeDecision</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="#MergeDecision"><span class="Identifier">MergeDecision</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Reads back a <tt class="docutils literal"><span class="pre"><span class="Identifier">writeMergeDecision</span></span></tt> file; <tt class="docutils literal"><span class="pre"><span class="Identifier">broken</span><span class="Operator">=</span><span class="Identifier">true</span></span></tt> if absent/unparsable.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L611" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L611" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="renderCFromArtifact-procs-all">
|
|
<div id="renderCFromArtifact,string,MergeDecision,string,int">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#renderCFromArtifact%2Cstring%2CMergeDecision%2Cstring%2Cint"><span class="Identifier">renderCFromArtifact</span></a><span class="Other">(</span><span class="Identifier">artifact</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">d</span><span class="Other">:</span> <a href="#MergeDecision"><span class="Identifier">MergeDecision</span></a><span class="Other">;</span> <span class="Identifier">ownerId</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span>
|
|
<span class="Identifier">dropped</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
The per-module backend's <tt class="docutils literal"><span class="pre"><span class="Identifier">emit</span></span></tt> stage: render one module's final <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span></span></tt> from its <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt> and the merge decision. String literals are emitted verbatim, symbols by name; a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdef</span> <span class="Operator">...</span><span class="Punctuation">)</span></span></tt> body is dropped when the name is dead, or when it is a <tt class="docutils literal"><span class="pre"><span class="CharLit">'u'</span></span></tt> unique definition this module does not own. The body's prototype lives in the surrounding raw text (cgen emits a forward declaration for every <em>used</em> proc, independent of where the body lands), so a dropped body still leaves a valid declaration — no synthesis needed. The head groups (meta/cdata/cref/cdeps) carry no C text.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L657" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L657" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="renderMarkedC-procs-all">
|
|
<div id="renderMarkedC,string,HashSet[string],int">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#renderMarkedC%2Cstring%2CHashSet%5Bstring%5D%2Cint"><span class="Identifier">renderMarkedC</span></a><span class="Other">(</span><span class="Identifier">code</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">live</span><span class="Other">:</span> <span class="Identifier">HashSet</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">dropped</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.
|
|
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Renders the final C text from the marked module text: symbol marks are removed (keeping the names — a later merge step substitutes them here), and definitions whose name is not in <tt class="docutils literal"><span class="pre"><span class="Identifier">live</span></span></tt> are dropped entirely. Each definition is self-delimiting (genProcAux emits an end directive right after the proc's text), so text written by other emitters is never part of a definition's span and survives unconditionally.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L218" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L218" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="stripCnifMarks-procs-all">
|
|
<div id="stripCnifMarks,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#stripCnifMarks%2Cstring"><span class="Identifier">stripCnifMarks</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Removes the symbol marks (keeping the names) and the definition directives (entirely) so the result is plain C.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L58" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L58" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="writeCnifArtifact-procs-all">
|
|
<div id="writeCnifArtifact,string,string,openArray[tuple[string,string]],string,string,openArray[string]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#writeCnifArtifact%2Cstring%2Cstring%2CopenArray%5Btuple%5Bstring%2Cstring%5D%5D%2Cstring%2Cstring%2CopenArray%5Bstring%5D"><span class="Identifier">writeCnifArtifact</span></a><span class="Other">(</span><span class="Identifier">code</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">outfile</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">initRequired</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">;</span>
|
|
<span class="Identifier">datInitRequired</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">;</span>
|
|
<span class="Identifier">dataDefs</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">cname</span><span class="Other">,</span> <span class="Identifier">nifname</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">]</span><span class="Other">]</span> <span class="Other">=</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">;</span>
|
|
<span class="Identifier">semmedNif</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">;</span> <span class="Identifier">moduleBase</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">;</span>
|
|
<span class="Identifier">implDeps</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> <span class="Other">=</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Splits the marked module text into the <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">c</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt> artifact. The artifact starts with a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">meta</span> <span class="Operator"><</span><span class="Identifier">flags</span><span class="Operator">></span> <span class="StringLit">"semmedNif"</span> <span class="StringLit">"moduleBase"</span> <span class="StringLit">"version"</span><span class="Punctuation">)</span></span></tt> head — whether the module has an init/datInit proc ('i'/'d'), which semmed NIF it was generated from and the module's mangled base name (what <tt class="docutils literal"><span class="pre"><span class="Identifier">registerModuleToMain</span></span></tt> and the reuse decision need when the TU is reused in a later run, possibly without the module ever being loaded again) — a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdata</span> <span class="Punctuation">(</span><span class="Identifier">SymbolDef</span> <span class="Identifier">StrLit</span><span class="Punctuation">)</span><span class="Operator">*</span><span class="Punctuation">)</span></span></tt> group naming the data definitions (consts, globals, RTTI) the TU embeds together with their NIF names, a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cref</span> <span class="Identifier">Ident</span><span class="Operator">*</span><span class="Punctuation">)</span></span></tt> group naming every C name the TU references but does not define itself (what the def-retention check consults when some <em>other</em> TU regenerates), and a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">cdeps</span> <span class="Identifier">Ident</span><span class="Operator">*</span><span class="Punctuation">)</span></span></tt> group naming the modules whose routine <em>bodies</em> this TU embeds (redirected defs, shared instances, hooks): the fine-grained reuse gate checks their <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">impl</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt> cookies on top of the direct imports' <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">iface</span><span class="Operator">.</span><span class="Identifier">nif</span></span></tt> cookies.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L91" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L91" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="writeMergeDecision-procs-all">
|
|
<div id="writeMergeDecision,string,MergeDecision">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#writeMergeDecision%2Cstring%2CMergeDecision"><span class="Identifier">writeMergeDecision</span></a><span class="Other">(</span><span class="Identifier">outfile</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">d</span><span class="Other">:</span> <a href="#MergeDecision"><span class="Identifier">MergeDecision</span></a><span class="Other">)</span> {.
|
|
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Serializes the merge decision: <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">merge</span> <span class="Punctuation">(</span><span class="Identifier">live</span> <span class="Identifier">Symbol</span><span class="Operator">*</span><span class="Punctuation">)</span> <span class="Punctuation">(</span><span class="Identifier">owners</span> <span class="Punctuation">(</span><span class="Identifier">own</span> <span class="Identifier">Symbol</span> <span class="Identifier">StrLit</span><span class="Punctuation">)</span><span class="Operator">*</span><span class="Punctuation">)</span><span class="Punctuation">)</span></span></tt>. C names are mangled (no dots) so they serialize as symbols; owner artifact base names go in string literals.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/compiler/cnif.nim#L590" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/compiler/cnif.nim#L590" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="twelve-columns footer">
|
|
<span class="nim-sprite"></span>
|
|
<br>
|
|
<small style="color: var(--hint);">Made with Nim. Generated: 2026-07-31 03:44:09 UTC</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
|
|
|
|
</body>
|
|
</html>
|