<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>LLVM’s Optional Rich Disassembly Output — LLVM 8 documentation</title> <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/language_data.js"></script> <link rel="index" title="Index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="next" title="System Library" href="SystemLibrary.html" /> <link rel="prev" title="The LLVM gold plugin" href="GoldPlugin.html" /> <style type="text/css"> table.right { float: right; margin-left: 20px; } table.right td { border: 1px solid #ccc; } </style> </head><body> <div class="logo"> <a href="index.html"> <img src="_static/logo.png" alt="LLVM Logo" width="250" height="88"/></a> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="SystemLibrary.html" title="System Library" accesskey="N">next</a> |</li> <li class="right" > <a href="GoldPlugin.html" title="The LLVM gold plugin" accesskey="P">previous</a> |</li> <li><a href="http://llvm.org/">LLVM Home</a> | </li> <li><a href="index.html">Documentation</a>»</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="body" role="main"> <div class="section" id="llvm-s-optional-rich-disassembly-output"> <h1>LLVM’s Optional Rich Disassembly Output<a class="headerlink" href="#llvm-s-optional-rich-disassembly-output" title="Permalink to this headline">¶</a></h1> <div class="contents local topic" id="contents"> <ul class="simple"> <li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li> <li><a class="reference internal" href="#instruction-annotations" id="id3">Instruction Annotations</a><ul> <li><a class="reference internal" href="#contextual-markups" id="id4">Contextual markups</a></li> <li><a class="reference internal" href="#c-api-details" id="id5">C API Details</a></li> </ul> </li> </ul> </div> <div class="section" id="introduction"> <h2><a class="toc-backref" href="#id2">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2> <p>LLVM’s default disassembly output is raw text. To allow consumers more ability to introspect the instructions’ textual representation or to reformat for a more user friendly display there is an optional rich disassembly output.</p> <p>This optional output is sufficient to reference into individual portions of the instruction text. This is intended for clients like disassemblers, list file generators, and pretty-printers, which need more than the raw instructions and the ability to print them.</p> <p>To provide this functionality the assembly text is marked up with annotations. The markup is simple enough in syntax to be robust even in the case of version mismatches between consumers and producers. That is, the syntax generally does not carry semantics beyond “this text has an annotation,” so consumers can simply ignore annotations they do not understand or do not care about.</p> <p>After calling <code class="docutils literal notranslate"><span class="pre">LLVMCreateDisasm()</span></code> to create a disassembler context the optional output is enable with this call:</p> <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">LLVMSetDisasmOptions</span><span class="p">(</span><span class="n">DC</span><span class="p">,</span> <span class="n">LLVMDisassembler_Option_UseMarkup</span><span class="p">);</span> </pre></div> </div> <p>Then subsequent calls to <code class="docutils literal notranslate"><span class="pre">LLVMDisasmInstruction()</span></code> will return output strings with the marked up annotations.</p> </div> <div class="section" id="instruction-annotations"> <h2><a class="toc-backref" href="#id3">Instruction Annotations</a><a class="headerlink" href="#instruction-annotations" title="Permalink to this headline">¶</a></h2> <div class="section" id="contextual-markups"> <span id="id1"></span><h3><a class="toc-backref" href="#id4">Contextual markups</a><a class="headerlink" href="#contextual-markups" title="Permalink to this headline">¶</a></h3> <p>Annoated assembly display will supply contextual markup to help clients more efficiently implement things like pretty printers. Most markup will be target independent, so clients can effectively provide good display without any target specific knowledge.</p> <p>Annotated assembly goes through the normal instruction printer, but optionally includes contextual tags on portions of the instruction string. An annotation is any ‘<’ ‘>’ delimited section of text(1).</p> <div class="highlight-bat notranslate"><div class="highlight"><pre><span></span>annotation: '<span class="p"><</span>' tag-name tag-modifier-list ':' annotated-text '<span class="p">></span>' tag-name: identifier tag-modifier-list: comma delimited identifier list </pre></div> </div> <p>The tag-name is an identifier which gives the type of the annotation. For the first pass, this will be very simple, with memory references, registers, and immediates having the tag names “mem”, “reg”, and “imm”, respectively.</p> <p>The tag-modifier-list is typically additional target-specific context, such as register class.</p> <p>Clients should accept and ignore any tag-names or tag-modifiers they do not understand, allowing the annotations to grow in richness without breaking older clients.</p> <p>For example, a possible annotation of an ARM load of a stack-relative location might be annotated as:</p> <div class="highlight-text notranslate"><div class="highlight"><pre><span></span>ldr <reg gpr:r0>, <mem regoffset:[<reg gpr:sp>, <imm:#4>]> </pre></div> </div> <p>1: For assembly dialects in which ‘<’ and/or ‘>’ are legal tokens, a literal token is escaped by following immediately with a repeat of the character. For example, a literal ‘<’ character is output as ‘<<’ in an annotated assembly string.</p> </div> <div class="section" id="c-api-details"> <h3><a class="toc-backref" href="#id5">C API Details</a><a class="headerlink" href="#c-api-details" title="Permalink to this headline">¶</a></h3> <p>The intended consumers of this information use the C API, therefore the new C API function for the disassembler will be added to provide an option to produce disassembled instructions with annotations, <code class="docutils literal notranslate"><span class="pre">LLVMSetDisasmOptions()</span></code> and the <code class="docutils literal notranslate"><span class="pre">LLVMDisassembler_Option_UseMarkup</span></code> option (see above).</p> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="SystemLibrary.html" title="System Library" >next</a> |</li> <li class="right" > <a href="GoldPlugin.html" title="The LLVM gold plugin" >previous</a> |</li> <li><a href="http://llvm.org/">LLVM Home</a> | </li> <li><a href="index.html">Documentation</a>»</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2003-2020, LLVM Project. Last updated on 2020-09-07. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.4. </div> </body> </html>