Symbol_002dtable.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the BFD library.
  4. Copyright (C) 1991-2017 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3 or
  7. any later version published by the Free Software Foundation; with the
  8. Invariant Sections being "GNU General Public License" and "Funding
  9. Free Software", the Front-Cover texts being (a) (see below), and with
  10. the Back-Cover Texts being (b) (see below). A copy of the license is
  11. included in the section entitled "GNU Free Documentation License".
  12. (a) The FSF's Front-Cover Text is:
  13. A GNU Manual
  14. (b) The FSF's Back-Cover Text is:
  15. You have freedom to copy and modify this GNU Manual, like GNU
  16. software. Copies published by the Free Software Foundation raise
  17. funds for GNU development. -->
  18. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  19. <head>
  20. <title>Untitled Document: Symbol-table</title>
  21. <meta name="description" content="Untitled Document: Symbol-table">
  22. <meta name="keywords" content="Untitled Document: Symbol-table">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  27. <link href="index.html#Top" rel="start" title="Top">
  28. <link href="BFD-Index.html#BFD-Index" rel="index" title="BFD Index">
  29. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  30. <link href="mmo.html#mmo" rel="up" title="mmo">
  31. <link href="mmo-section-mapping.html#mmo-section-mapping" rel="next" title="mmo section mapping">
  32. <link href="File-layout.html#File-layout" rel="prev" title="File layout">
  33. <style type="text/css">
  34. <!--
  35. a.summary-letter {text-decoration: none}
  36. blockquote.smallquotation {font-size: smaller}
  37. div.display {margin-left: 3.2em}
  38. div.example {margin-left: 3.2em}
  39. div.indentedblock {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  44. div.smalllisp {margin-left: 3.2em}
  45. kbd {font-style:oblique}
  46. pre.display {font-family: inherit}
  47. pre.format {font-family: inherit}
  48. pre.menu-comment {font-family: serif}
  49. pre.menu-preformatted {font-family: serif}
  50. pre.smalldisplay {font-family: inherit; font-size: smaller}
  51. pre.smallexample {font-size: smaller}
  52. pre.smallformat {font-family: inherit; font-size: smaller}
  53. pre.smalllisp {font-size: smaller}
  54. span.nocodebreak {white-space:nowrap}
  55. span.nolinebreak {white-space:nowrap}
  56. span.roman {font-family:serif; font-weight:normal}
  57. span.sansserif {font-family:sans-serif; font-weight:normal}
  58. ul.no-bullet {list-style: none}
  59. -->
  60. </style>
  61. </head>
  62. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  63. <a name="Symbol_002dtable"></a>
  64. <div class="header">
  65. <p>
  66. Next: <a href="mmo-section-mapping.html#mmo-section-mapping" accesskey="n" rel="next">mmo section mapping</a>, Previous: <a href="File-layout.html#File-layout" accesskey="p" rel="prev">File layout</a>, Up: <a href="mmo.html#mmo" accesskey="u" rel="up">mmo</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  67. </div>
  68. <hr>
  69. <a name="Symbol-table-format"></a>
  70. <h4 class="subsection">3.5.2 Symbol table format</h4>
  71. <p>From mmixal.w (or really, the generated mmixal.tex) in the
  72. MMIXware package which also contains the <code>mmix</code> simulator:
  73. &ldquo;Symbols are stored and retrieved by means of a &lsquo;<samp>ternary
  74. search trie</samp>&rsquo;, following ideas of Bentley and Sedgewick. (See
  75. ACM&ndash;SIAM Symp. on Discrete Algorithms &lsquo;<samp>8</samp>&rsquo; (1997), 360&ndash;369;
  76. R.Sedgewick, &lsquo;<samp>Algorithms in C</samp>&rsquo; (Reading, Mass.
  77. Addison&ndash;Wesley, 1998), &lsquo;<samp>15.4</samp>&rsquo;.) Each trie node stores a
  78. character, and there are branches to subtries for the cases where
  79. a given character is less than, equal to, or greater than the
  80. character in the trie. There also is a pointer to a symbol table
  81. entry if a symbol ends at the current node.&rdquo;
  82. </p>
  83. <p>So it&rsquo;s a tree encoded as a stream of bytes. The stream of bytes
  84. acts on a single virtual global symbol, adding and removing
  85. characters and signalling complete symbol points. Here, we read
  86. the stream and create symbols at the completion points.
  87. </p>
  88. <p>First, there&rsquo;s a control byte <code>m</code>. If any of the listed bits
  89. in <code>m</code> is nonzero, we execute what stands at the right, in
  90. the listed order:
  91. </p>
  92. <div class="example">
  93. <pre class="example"> (MMO3_LEFT)
  94. 0x40 - Traverse left trie.
  95. (Read a new command byte and recurse.)
  96. (MMO3_SYMBITS)
  97. 0x2f - Read the next byte as a character and store it in the
  98. current character position; increment character position.
  99. Test the bits of <code>m</code>:
  100. (MMO3_WCHAR)
  101. 0x80 - The character is 16-bit (so read another byte,
  102. merge into current character.
  103. (MMO3_TYPEBITS)
  104. 0xf - We have a complete symbol; parse the type, value
  105. and serial number and do what should be done
  106. with a symbol. The type and length information
  107. is in j = (m &amp; 0xf).
  108. (MMO3_REGQUAL_BITS)
  109. j == 0xf: A register variable. The following
  110. byte tells which register.
  111. j &lt;= 8: An absolute symbol. Read j bytes as the
  112. big-endian number the symbol equals.
  113. A j = 2 with two zero bytes denotes an
  114. unknown symbol.
  115. j &gt; 8: As with j &lt;= 8, but add (0x20 &lt;&lt; 56)
  116. to the value in the following j - 8
  117. bytes.
  118. Then comes the serial number, as a variant of
  119. uleb128, but better named ubeb128:
  120. Read bytes and shift the previous value left 7
  121. (multiply by 128). Add in the new byte, repeat
  122. until a byte has bit 7 set. The serial number
  123. is the computed value minus 128.
  124. (MMO3_MIDDLE)
  125. 0x20 - Traverse middle trie. (Read a new command byte
  126. and recurse.) Decrement character position.
  127. (MMO3_RIGHT)
  128. 0x10 - Traverse right trie. (Read a new command byte and
  129. recurse.)
  130. </pre></div>
  131. <p>Let&rsquo;s look again at the <code>lop_stab</code> for the trivial file
  132. (see <a href="File-layout.html#File-layout">File layout</a>).
  133. </p>
  134. <div class="example">
  135. <pre class="example"> 0x980b0000 - lop_stab for &quot;:Main&quot; = 0, serial 1.
  136. 0x203a4040
  137. 0x10404020
  138. 0x4d206120
  139. 0x69016e00
  140. 0x81000000
  141. </pre></div>
  142. <p>This forms the trivial trie (note that the path between &ldquo;:&rdquo; and
  143. &ldquo;M&rdquo; is redundant):
  144. </p>
  145. <div class="example">
  146. <pre class="example"> 203a &quot;:&quot;
  147. 40 /
  148. 40 /
  149. 10 \
  150. 40 /
  151. 40 /
  152. 204d &quot;M&quot;
  153. 2061 &quot;a&quot;
  154. 2069 &quot;i&quot;
  155. 016e &quot;n&quot; is the last character in a full symbol, and
  156. with a value represented in one byte.
  157. 00 The value is 0.
  158. 81 The serial number is 1.
  159. </pre></div>
  160. <hr>
  161. <div class="header">
  162. <p>
  163. Next: <a href="mmo-section-mapping.html#mmo-section-mapping" accesskey="n" rel="next">mmo section mapping</a>, Previous: <a href="File-layout.html#File-layout" accesskey="p" rel="prev">File layout</a>, Up: <a href="mmo.html#mmo" accesskey="u" rel="up">mmo</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  164. </div>
  165. </body>
  166. </html>