brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 05feee1 Raw
87 lines · plain
1=======================================2LLVM's Optional Rich Disassembly Output3=======================================4 5.. contents::6   :local:7 8Introduction9============10 11LLVM's default disassembly output is raw text. To allow consumers more ability12to introspect the instructions' textual representation or to reformat for a more13user friendly display there is an optional rich disassembly output.14 15This optional output is sufficient to reference into individual portions of the16instruction text. This is intended for clients like disassemblers, list file17generators, and pretty-printers, which need more than the raw instructions and18the ability to print them.19 20To provide this functionality the assembly text is marked up with annotations.21The markup is simple enough in syntax to be robust even in the case of version22mismatches between consumers and producers. That is, the syntax generally does23not carry semantics beyond "this text has an annotation," so consumers can24simply ignore annotations they do not understand or do not care about.25 26After calling ``LLVMCreateDisasm()`` to create a disassembler context the27optional output is enable with this call:28 29.. code-block:: c30 31    LLVMSetDisasmOptions(DC, LLVMDisassembler_Option_UseMarkup);32 33Then subsequent calls to ``LLVMDisasmInstruction()`` will return output strings34with the marked up annotations.35 36Instruction Annotations37=======================38 39.. _contextual markups:40 41Contextual markups42------------------43 44Annotated assembly display will supply contextual markup to help clients more45efficiently implement things like pretty printers. Most markup will be target46independent, so clients can effectively provide good display without any target47specific knowledge.48 49Annotated assembly goes through the normal instruction printer, but optionally50includes contextual tags on portions of the instruction string. An annotation51is any '<' '>' delimited section of text(1).52 53.. code-block:: bat54 55    annotation: '<' tag-name tag-modifier-list ':' annotated-text '>'56    tag-name: identifier57    tag-modifier-list: comma delimited identifier list58 59The tag-name is an identifier which gives the type of the annotation. For the60first pass, this will be very simple, with memory references, registers, and61immediates having the tag names "mem", "reg", and "imm", respectively.62 63The tag-modifier-list is typically additional target-specific context, such as64register class.65 66Clients should accept and ignore any tag-names or tag-modifiers they do not67understand, allowing the annotations to grow in richness without breaking older68clients.69 70For example, a possible annotation of an ARM load of a stack-relative location71might be annotated as:72 73.. code-block:: text74 75   ldr <reg gpr:r0>, <mem regoffset:[<reg gpr:sp>, <imm:#4>]>76 77 781: 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.79 80C API Details81-------------82 83The intended consumers of this information use the C API, therefore the new C84API function for the disassembler will be added to provide an option to produce85disassembled instructions with annotations, ``LLVMSetDisasmOptions()`` and the86``LLVMDisassembler_Option_UseMarkup`` option (see above).87