Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: native_client_sdk/doc_generated/reference/pnacl-bitcode-manual.html

Issue 266713003: Initial draft of PNaCl bitcode files document. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 {{+bindTo:partials.standard_nacl_article}}
2
3 <section id="pnacl-bitcode-file-reference-manual">
4 <h1 id="pnacl-bitcode-file-reference-manual">PNaCl Bitcode File Reference Manual </h1>
5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap">
7 <li><a class="reference internal" href="#introduction" id="id19">Introduction</a ></li>
8 <li><a class="reference internal" href="#high-level-basics" id="id20">High Level Basics</a></li>
9 <li><a class="reference internal" href="#pnacl-blocks" id="id21">PNaCl Blocks</a ></li>
10 <li><a class="reference internal" href="#pnacl-records" id="id22">PNaCl Records< /a></li>
11 <li><a class="reference internal" href="#conventions-for-describing-records" id= "id23">Conventions for describing records</a></li>
12 <li><p class="first"><a class="reference internal" href="#parse-state" id="id24" >Parse State</a></p>
13 <ul class="small-gap">
14 <li><a class="reference internal" href="#typing" id="id25">Typing</a></li>
15 <li><a class="reference internal" href="#id-counters" id="id26">ID Counters</a>< /li>
16 <li><a class="reference internal" href="#size-variables" id="id27">Size Variable s</a></li>
17 <li><a class="reference internal" href="#other-variables" id="id28">Other Variab les</a></li>
18 </ul>
19 </li>
20 <li><p class="first"><a class="reference internal" href="#special-records" id="i d29">Special records</a></p>
21 <ul class="small-gap">
22 <li><a class="reference internal" href="#header-record" id="id30">Header Record< /a></li>
23 <li><a class="reference internal" href="#enter-block-record" id="id31">Enter Blo ck Record</a></li>
24 <li><a class="reference internal" href="#exit-block-record" id="id32">Exit Block Record</a></li>
25 </ul>
26 </li>
27 <li><p class="first"><a class="reference internal" href="#types-block" id="id33" >Types Block</a></p>
28 <ul class="small-gap">
29 <li><a class="reference internal" href="#count-record" id="id34">Count Record</a ></li>
30 <li><a class="reference internal" href="#void-type" id="id35">Void Type</a></li>
31 <li><a class="reference internal" href="#integer-types" id="id36">Integer Types< /a></li>
32 <li><a class="reference internal" href="#bit-floating-type" id="id37">32-Bit Flo ating Type</a></li>
33 <li><a class="reference internal" href="#id1" id="id38">64-bit Floating Type</a> </li>
34 <li><a class="reference internal" href="#vector-types" id="id39">Vector Types</a ></li>
35 <li><a class="reference internal" href="#function-types" id="id40">Function Type s</a></li>
36 </ul>
37 </li>
38 <li><p class="first"><a class="reference internal" href="#globals-block" id="id4 1">Globals block</a></p>
39 <ul class="small-gap">
40 <li><a class="reference internal" href="#id2" id="id42">Count Record</a></li>
41 <li><a class="reference internal" href="#global-variable-addressses" id="id43">G lobal Variable Addressses</a></li>
42 <li><a class="reference internal" href="#glboal-constant-addresses" id="id44">Gl boal Constant Addresses</a></li>
43 <li><a class="reference internal" href="#zerofill-initializer" id="id45">Zerofil l Initializer</a></li>
44 <li><a class="reference internal" href="#data-initializer" id="id46">Data Initia lizer</a></li>
45 <li><a class="reference internal" href="#relocation-initializer" id="id47">Reloc ation Initializer</a></li>
46 <li><a class="reference internal" href="#subfield-relocation-initializer" id="id 48">Subfield Relocation Initializer</a></li>
47 <li><a class="reference internal" href="#compound-initializer" id="id49">Compoun d Initializer</a></li>
48 </ul>
49 </li>
50 <li><a class="reference internal" href="#valuesymtab-block" id="id50">Valuesymta b Block</a></li>
51 <li><p class="first"><a class="reference internal" href="#module-block" id="id51 ">Module Block</a></p>
52 <ul class="small-gap">
53 <li><a class="reference internal" href="#version" id="id52">Version</a></li>
54 <li><p class="first"><a class="reference internal" href="#function-address" id=" id53">Function Address</a></p>
55 <ul class="small-gap">
56 <li><a class="reference internal" href="#updates" id="id54">Updates</a></li>
57 </ul>
58 </li>
59 </ul>
60 </li>
61 <li><a class="reference internal" href="#constants-blocks" id="id55">Constants B locks</a></li>
62 <li><p class="first"><a class="reference internal" href="#function-blocks" id="i d56">Function Blocks</a></p>
63 <ul class="small-gap">
64 <li><a class="reference internal" href="#function-enter" id="id57">Function ente r</a></li>
65 <li><p class="first"><a class="reference internal" href="#id3" id="id58">Count R ecord</a></p>
66 <ul class="small-gap">
67 <li><a class="reference internal" href="#id4" id="id59">Updates</a></li>
68 </ul>
69 </li>
70 <li><p class="first"><a class="reference internal" href="#terminator-instruction s" id="id60">Terminator Instructions</a></p>
71 <ul class="small-gap">
72 <li><a class="reference internal" href="#return-void-instruction" id="id61">Retu rn Void Instruction</a></li>
73 <li><a class="reference internal" href="#return-value-instruction" id="id62">Ret urn Value Instruction</a></li>
74 <li><a class="reference internal" href="#unconditional-branch-instruction" id="i d63">Unconditional Branch Instruction</a></li>
75 <li><a class="reference internal" href="#conditional-branch-instruction" id="id6 4">Conditional Branch Instruction</a></li>
76 <li><a class="reference internal" href="#unreachable" id="id65">Unreachable</a>< /li>
77 <li><a class="reference internal" href="#switch-instruction" id="id66">Switch In struction</a></li>
78 </ul>
79 </li>
80 <li><p class="first"><a class="reference internal" href="#binary-inststructions" id="id67">Binary Inststructions</a></p>
81 <ul class="small-gap">
82 <li><a class="reference internal" href="#add-instruction" id="id68">Add Instruct ion</a></li>
83 <li><a class="reference internal" href="#subtract-instruction" id="id69">Subtrac t Instruction</a></li>
84 <li><a class="reference internal" href="#multiply-instruction" id="id70">Multipl y Instruction</a></li>
85 <li><a class="reference internal" href="#divide-instruction" id="id71">Divide In struction</a></li>
86 <li><a class="reference internal" href="#remainder-instruction" id="id72">Remain der Instruction</a></li>
87 <li><a class="reference internal" href="#shift-left-instruction" id="id73">Shift left Instruction</a></li>
88 <li><a class="reference internal" href="#logical-shift-right-instructions" id="i d74">Logical Shift right Instructions</a></li>
89 <li><a class="reference internal" href="#arithmetic-shift-right-instructions" id ="id75">Arithmetic Shift right Instructions</a></li>
90 <li><a class="reference internal" href="#and-instruction" id="id76">And Instruct ion</a></li>
91 <li><a class="reference internal" href="#or-instruction" id="id77">Or Instructio n</a></li>
92 <li><a class="reference internal" href="#xor-instruction" id="id78">Xor Instruct ion</a></li>
93 </ul>
94 </li>
95 <li><p class="first"><a class="reference internal" href="#memory-creation-and-ac cess-instructions" id="id79">Memory creation and access Instructions</a></p>
96 <ul class="small-gap">
97 <li><a class="reference internal" href="#stack-frame-memory-allocation-instructi on" id="id80">Stack frame memory allocation Instruction</a></li>
98 <li><a class="reference internal" href="#load-instruction" id="id81">Load Instru ction</a></li>
99 <li><a class="reference internal" href="#store-instruction" id="id82">Store Inst ruction</a></li>
100 </ul>
101 </li>
102 <li><p class="first"><a class="reference internal" href="#conversion-instruction s" id="id83">Conversion Instructions</a></p>
103 <ul class="small-gap">
104 <li><a class="reference internal" href="#truncating-instructions" id="id84">Trun cating Instructions</a></li>
105 <li><a class="reference internal" href="#extending-instructions" id="id85">Exten ding Instructions</a></li>
106 </ul>
107 </li>
108 <li><a class="reference internal" href="#comparison-instructions" id="id86">Comp arison Instructions</a></li>
109 <li><p class="first"><a class="reference internal" href="#other-instructions" id ="id87">Other Instructions</a></p>
110 <ul class="small-gap">
111 <li><a class="reference internal" href="#phi-instruction" id="id88">Phi Instruct ion</a></li>
112 <li><a class="reference internal" href="#forward-type-declarations" id="id89">Fo rward type declarations</a></li>
113 <li><a class="reference internal" href="#select-instruction" id="id90">Select In struction</a></li>
114 <li><a class="reference internal" href="#call-instructions" id="id91">Call Instr uctions</a></li>
115 </ul>
116 </li>
117 <li><a class="reference internal" href="#intrinsic-functions" id="id92">Intrinsi c Functions</a></li>
118 <li><p class="first"><a class="reference internal" href="#support-functions" id= "id93">Support Functions</a></p>
119 <ul class="small-gap">
120 <li><a class="reference internal" href="#absoluteindex" id="id94">AbsoluteIndex< /a></li>
121 <li><a class="reference internal" href="#relativeindex" id="id95">RelativeIndex< /a></li>
122 </ul>
123 </li>
124 <li><p class="first"><a class="reference internal" href="#abbreviations" id="id9 6">Abbreviations</a></p>
125 <ul class="small-gap">
126 <li><a class="reference internal" href="#id18" id="id97">Introduction</a></li>
127 <li><a class="reference internal" href="#bitstream-format" id="id98">Bitstream F ormat</a></li>
128 </ul>
129 </li>
130 <li><a class="reference internal" href="#reference-implementation" id="id99">Ref erence Implementation</a></li>
131 </ul>
132 </li>
133 </ul>
134
135 </div><section id="introduction">
136 <h2 id="introduction">Introduction</h2>
137 <p>This document is a reference manual for the contents of PNaCl bitcode
138 files. It is presented using assembly language <em>PNaClAsm</em>. PNaClAsm
139 uses a <em>static single assignment</em> (SSA) model, based a representation
140 that requires generated results to have a single (assignment)
141 source. PNaClAsm is the textual version of the bitcode file.</p>
142 <p>PNaClAsm focusses on the semantic content of the file, not the
143 bit-encoding of that content. However, it does provide annotations
144 that allows one to specify how the PNaCl bitcode writer converts the
145 semantic content of a PNaClAsm program, into a specific bit sequence.</p>
146 <p>Below PNaClAsm is the high-level form of the data stored in PNaCl
147 bitcode files. Each construct in PNaClAsm defines a corresponding
148 <em>PNaCl record</em> [ref]. A PNaCl bitcode file is simply a sequence of
149 PNaCl records. The goal of PNaClAsm is to make records easier to read,
150 and not to define a high-level user programming language.</p>
151 <p>PNaCl records are an abstract encoding of structured data, similar
152 to XML. Like XML, PNaCl records have a notion of tags (i.e. the first
153 element in a record, called a <em>code</em>), and nested structures. The
154 nested structures are defined by corresponding <em>enter</em> and <em>exit</em>
155 block records.</p>
156 <p>These block records must be used like parentheses to define the block
157 structure that is imposed on top of records. Each exit record must be
158 preceded by a corresponding enter record. Blocks can be nested by
159 nesting enter/exit records appropriately.</p>
160 <p>The <em>PNaCl bitcode wrtier</em> takes the sequence of records, defined by a
161 PNaClAsm program, and coverts each record into a (variable) sequence
162 of bits. The output of each bit sequence is appended together. The
163 resulting generated sequence of bits is the contents of the PNaCl
164 bitcode file.</p>
165 <p>For every kind of record, there are default methods for converting
166 records into bit sequences. These methods correspond to a notion of
167 <em>abbreviations</em> [ref]. Each abbreviation defines a specific bit
168 sequence conversion to be applied. The default conversion methods are
169 simply predefined abbreviations.</p>
170 <p>The default abbreviations can be overriddeen with user-specified
171 abbrreviations. All user-specified abbreviations are included in the
172 generated bitcode file. Each abbreviation defines how records are
173 converted to bit sequences. The <em>PNaCl bitcode writer</em> uses these
174 abbreviations to convert the corresponding record sequence into a
175 corresponding bit sequence. As a result, all records have an
176 abbreviation (user or default) associated with them.</p>
177 <p>The <em>PNaCl bitcode reader</em> then uses these abbreviations to convert
178 the bit sequences back into the corresponding records.</p>
179 <p>Conceptually, abbreviations are used to define how to pack the
180 contents of records into bit sequenes. The main reason for defining
181 abbreviations is to save space. The default abbreviations are
182 simplistic and are intended to handle all possible records. The
183 default abbreviations do not really worry about being efficient, in
184 terms of the number of bits generated.</p>
185 <p>By separating the concepts of PNaCl records and abbreviations, the
186 notion of data compression is cleanly seperated from semantic
187 content. This allows different use cases to decide how much effort
188 should be spent on compressing records.</p>
189 <p>For a JIT translator, little (if any) compression should be
190 applied. In fact, the API to the JIT may just be the records
191 themselves. The goal of a JIT is to perform the final translation to
192 machine code as quickly as possible. On the other hand, when
193 delivering accross the web, one may want to compress the sequence of
194 bits considerably, to reduce costs in delivering web pages.</p>
195 </section><section id="high-level-basics">
196 <h2 id="high-level-basics">High Level Basics</h2>
197 <p>A program is defined as a sequence of top-level Blocks. Blocks
198 can be nested within other blocks. Each <em>block</em> defines a sequence of
199 records.</p>
200 <p>Most of the records, within a block, also define a unique values.
201 Each unique value is given a corresponding unique identifier
202 (i.e. <em>ID</em>). In PNaClAms. each kind of block defines it own kind of
203 identifiers. The names of these identifiers are defined by
204 concatinating a prefix character (&#8216;&#64;&#8217; or &#8216;%&#8217;), the k ind of block (a
205 single character), and a suffix index. The suffix index is defined by
206 the positional location of the defined value within the records of the
207 corresponding block. The indices are all zero based, meaning that the
208 first defined value (within a block) is defined using index 0.</p>
209 <p>Identifiers are categorized into two types, <em>local</em> and
210 <em>global</em>. Local identifiers are identifiers that are associated with
211 the implementation of a single function. All other identifiers are
212 global. This split is intentional. Global identifiers are used by
213 multiple functions, and therefore must be unique accross all function
214 implementations. Local identifiers only apply to a single function,
215 and can be reused between functions. The <em>PNaCl translator</em> uses this
216 separation to parallelize the compilation of functions.</p>
217 <p>Global identifiers use the prefix character <em>&#8216;&#64;&#8217;</em> whil e local
218 identifiers use the prefix character <em>&#8216;%&#8217;</em>.</p>
219 <p>Note: There is one exception to this separation of local and global
220 identifiers. Abbreviations can be defined locally and globally. An
221 abbreviation is local if it only applies to the block it appears
222 in. If it is global, the abberviation can apply to multiple block
223 instances.</p>
224 <p>Note that by using positional location to define identifiers (within a
225 block), the values defined in PNaCl bitcode files need not be
226 explicitly included in the bitcode file. Rather, they are inferred by
227 the (ordered) position of the record in the block. This is also
228 intentional. It is used to reduce the amount of data that must be
229 (explicitly) passed to the PNaCl translator.</p>
230 <p>In general, most of the records and blocks are assumed to be
231 topologically sorted, putting value definitions before thier uses.
232 This implies that records do not need to encode data if it can use the
233 corresponding information from it&#8217;s uses.</p>
234 <p>The most common use of this is that many instructions use the type of
235 their operands to determine the type of the instruction. Again, this
236 is intentional. It allows less information to be stored with the
237 instruction.</p>
238 <p>However, For function blocks (which define instructions), no
239 topological sort exists. Loop carried value dependencies simply do not
240 allow topologically sorting. To deal with this, function blocks have a
241 notion of a forward (instruction value) declarations. These
242 decalrations must appear before any of the uses of that value, if the
243 (instruction) value is defined later in the function, than its first
244 use.</p>
245 </section><section id="pnacl-blocks">
246 <h2 id="pnacl-blocks">PNaCl Blocks</h2>
247 <p>Blocks are used to organize records in the bitcode file. The
248 kinds of blocks defined in PNaClAsm are:</p>
249 <dl class="docutils">
250 <dt>Types block</dt>
251 <dd>Defines the set of types used by the program. All types used in the
252 program must be defined in this block.</dd>
253 <dt>Globals block</dt>
254 <dd>Defines the set of global addresses of global variables and
255 constants, used by the program. It also defines how each global
256 (associated with the global address) is initialized.</dd>
257 <dt>Valuesymtab block</dt>
258 <dd>Defines textual names for global and function addresses.</dd>
259 <dt>Function block</dt>
260 <dd>Each function (implemented) in a program has it&#8217;s own block that
261 defines the implementation of the corresponding function.</dd>
262 <dt>Constants Block</dt>
263 <dd>Each implemented function, that uses constants in its
264 instructions, defines a constant block. Constants blocks appear
265 within corresponding function block.</dd>
266 <dt>Modue block</dt>
267 <dd>A top-level block defining the program. This block defines global
268 information used by the program, followed by function blocks
269 defining the implementation of functions within the program.</dd>
270 <dt>Abbreviations block</dt>
271 <dd>Defines abbreviations that are used to compress PNaCl records. This
272 block is segmented into multiple sections, one section for each kind
273 of block. This block is optional and need not be defined.</dd>
274 </dl>
275 <p>A PNaCl program consists of a header record, an optional abbreviations
276 block, and a module block.</p>
277 <p>Each block, within a bitcode file, defines values. These values are
278 associated with IDs. Each type of block defines different kinds of
279 IDs.</p>
280 <p>The <em>types block</em> [ref] defines types used by the program. Each record
281 in the types block defines a separate type. Valid types include
282 various sizes of integer and floating types. They also define higher
283 level constructs such as vectors and function signatures. For each
284 definition, a type ID is defined. A type ID is of the form <em>&#64;tN</em>,
285 where <em>N</em> corresponds to the (relative) position of the corresponding
286 defining record in the types block.</p>
287 <p>The types block must appear within the module block,
288 and must appear before any block that uses a typed value. Many
289 PNaClAsm constructs allows one to use explicit type names, rather than
290 type IDs. However, they are internally converted to the corresponding
291 type ID in the types block. Hence, the requirement that the types
292 block must appear early in the module block.</p>
293 <p>The <em>module block</em> [ref] contains all other blocks (except for the
294 abbreviations block, which can either appear within the module block,
295 or immediately before the module block). The only values defined in a
296 module block are function addresses. All remaining definitions appear
297 within blocks of the module block.</p>
298 <p>Function addresses are global IDs of the form <em>&#64;fN</em>, where <em>N</ em>
299 corresponds to the position of the corresponding function address
300 record in the module block. Function addresses must appear after the
301 types block.</p>
302 <p>The <em>globals block</em> [ref] defines global addresses for global variable s
303 and constants, used in the program. This block not only defines the
304 addresses, but the size of the corresponding memory associated with
305 these addresses, and how the memory should be initialized.</p>
306 <p>The globals block must appear in the module block, and after all
307 function address records. Global addresses (defined by the globals
308 block) are of the form <em>&#64;gN</em>, where <em>N</em> is the (relative) posi tion of
309 the corresponding defining records.</p>
310 <p>The <em>valuesymtab block</em> [ref] does not define any values. Rather, its
311 only goal is to associate text names with previously defined global
312 addresses (i.e. function, constant, and variable). Each association
313 is defined by a record in the Valuesymtab block. Currently, only
314 <em>intrinsic</em> [ref] function addresses need a name. All other entries in
315 this block are considered as a hint for debugging. The PNaCl
316 translator may (or may not) pass these names to the running
317 executable, allowing the (runtime) debugger to associate names with
318 addresses.</p>
319 <p>Each <em>function block</em> [ref] defines the implementation of a single
320 function. Each function block defines the control-flow graph of the
321 function, which consists of basic blocks and instructions. If
322 constants are used within instructions, they are defined in a
323 <em>constants block</em>, nested within the corresponding function block.</p>
324 <p>All function blocks are associated with a corresponding function
325 address. This association is (again) positional rather than
326 explicit. That is, the Nth function block in a module block
327 corresponds to the Nth defining function address record in the
328 module block.</p>
329 <p>Hence, within a function block, there is no explicit reference to the
330 function address the block defines. For readability, PNaClAsm uses the
331 corresponding function heading, associated with the corresponding
332 function address record, even though that data does not appear in the
333 corresponding records.</p>
334 <p>Unlike other blocks, a function block defines multiple kinds of
335 values: parameter, basic block, and instruction. Parameter IDs (in
336 PNaClAsm) are identified using local IDs of the form <em>%pN</em>. Basic
337 block IDs are identified using local IDs of the form
338 <em>%bN</em>. Instructions that generate values are identified using local
339 IDs of the form <em>%vN</em>.</p>
340 <p>Hence, <em>%pN</em> denotes the Nth parameter of the function. <em>%bN</em> d enotes
341 the <em>Nth</em> basic block within the function. <em>%vN</em> denotes the value
342 generated by the <em>Nth</em> instruction that generates a value. Note: <em>%vN< /em>
343 does not necessarily refer to the <em>Nth</em> instruction in the function
344 block, because not all instructions generate values.</p>
345 <p>Within a function block, basic blocks are not explicitly defined in
346 the PNaCl records of a function block. Rather, the first record of the
347 block identifies how many basic blocks appear in the control flow
348 graph of the function. This record is then followed by a sequence of
349 records, each record defining a single instruction. Special
350 <em>terminating</em> [ref] (i.e. branch) instructions are used to determine
351 block boundaries.</p>
352 <p>Each <em>constants block</em> [ref] defines constants that are used by the
353 enclosing function block. The purpose of the constant block is to
354 merge all uses of a constant (within a function) into a single
355 defining ID. Constant IDs are of the form <em>%cN</em>, where <em>N</em>
356 corresponds to the (relative) position of constant defined in the
357 corresponding constants block. The constants block must appear before
358 any instruction.</p>
359 <p>The <em>abbreviations block</em> [ref] is optional. If it is included, it is
360 divided into sections. Each section is a sequence of records. Each
361 record in the sequence defines a user-defined abbreviation. Each
362 section defines abbreviations that can be applied to all (succeeding)
363 blocks of a particular kind. These abbreviations ares denoted by the
364 (global) ID of the form <em>&#64;aN</em>.</p>
365 </section><section id="pnacl-records">
366 <h2 id="pnacl-records">PNaCl Records</h2>
367 <p>A PNaCl record is a non-empty sequence of unsigned, 64-bit,
368 integers. A record is identified by the record <em>code</em>, which is the
369 first element in the sequence. Record codes are unique within a
370 specific kind of block, but are not necessarily unique accross
371 different kinds of blocks. The record code acts as the variant
372 descriminator (i.e. tag) within a block, to identify what type of
373 record it is.</p>
374 <p>Record codes are typically small numbers. In an ideal world, they
375 would be a consecutive sequence of integers, starting at
376 zero. However, the reality is that PNaCl records evolved over time
377 (and actually started as LLVM records[ref]). For backwards
378 compatability, old numbers have not been reused, leaving gaps in the
379 actual record code values used.</p>
380 <p>The exception of using small numbers for record codes, are four
381 special kinds of records. What makes these four kinds of records
382 special is that they either apply in multiple blocks, or don&#8217;t occur
383 in any block. To make these cases clear, and to leave room for lots of
384 future growth in PNaClAsm, these special records have record codes
385 close to value 2**16. Note: Well-formed PNaCl bitcode files do not
386 have record codes &gt;= 2**16.</p>
387 <p>A PNaCl record is denoted as follows:</p>
388 <pre class="prettyprint">
389 &lt;v1, v2, ... , vN&gt;
390 </pre>
391 <p>The value <em>v1</em> is the record code. The remaining values, <em>v2</em> t hrough
392 <em>vN</em>, are parameters that fill in additional information needed by the
393 construct it represents. All records must hava record code. Hence,
394 empty PNaCl records are not allowed.</p>
395 <p>While most records (for a given record code) are of the same length,
396 it is not true of all record codes. Some record codes, such as the
397 records for the call instruction, can have arbitrary length.</p>
398 <p>In PNaClAsm, if the record is converted to a bit sequence using the
399 default abbreviation, no additional notation is used. Otherwise, the
400 record is prefixed with the the abbreviation ID <em>I</em> to use (wrt the
401 block it appears in) as follows:</p>
402 <pre class="prettyprint">
403 I: &lt;v1, v2, ... , vN&gt;
404 </pre>
405 <p>The PNaCl bitcode writer, which converts records to bit sequences,
406 does this by writing out the abbreviation index used to encode the
407 record, followed by the contents of the PNaCl record. The details of
408 this are left to section on abbreviations[ref]. However, at the PNaCL
409 record level, one important aspect of this appears in block enter
410 records. These records must define how many bits are required to hold
411 abbreviation indices associated with records of that block.</p>
412 <p>There are 4 predefined (default) abbreviation indices, used as the
413 default abbreviations for PNaCl records. A block may (in addition),
414 define a list of block specific, user-defined, abbreviations (of
415 length <em>U&amp;). The number of bits *B</em> specified for an enter
416 record must be sufficiently large such that</p>
417 <pre class="prettyprint">
418 2**B &gt;= U + 4
419 </pre>
420 <p>In addition, the upper limit for B is 32.</p>
421 <p>Like much of PNaClAsm, PNaClAsm requires that you specify sizes
422 (associated with a block) up front so that the PNaCl bitcode
423 reader/writer can determine how to encode abbreviation indices. Hence,
424 within an enter block record, you must specify how bits will be used
425 to hold abbreviation indexes.</p>
426 </section><section id="conventions-for-describing-records">
427 <h2 id="conventions-for-describing-records">Conventions for describing records</ h2>
428 <p>The PNaClAsm assembler can be viewed as a parser of PNaCl records. The
429 Each PNaCl record is described by a corresponding PNaClAsm
430 construct. These constructs are described using syntax rules, and
431 semantics on how they are converted to records. The parser also has
432 state, that is updated after the instruction is parsed. These state
433 updates are part of the sementics of the corresponding record
434 construct.</p>
435 <p>For each PNaCl construct, we define multiple subsections. The <strong>Syntax< /strong>
436 subsection defines a syntax rule for the construct. The <strong>Record</strong>
437 subsection defines the corresponding record associated with the syntax
438 rule. The <strong>Semantics</strong> subsection describes the semantics
439 associated with the record, in terms of data within the parse state
440 and the corresponding syntax.</p>
441 <p>The <strong>Constraints</strong> subsection (if present) defines any constrai nts
442 associated with the construct. The <strong>Updates</strong> subsection (if prese nt)
443 defines how the parse state is updated when the construct is parsed.
444 The <strong>Examples</strong> subsection gives one (or more) examples of using t he
445 corresponding PNaClAsm construct.</p>
446 <p>Some semantics subsections use functions to compute values. The
447 meaning of functions can be found in <em>Support Functions</em> [ref].</p>
448 <p>Within a syntax rule, there may specifications about abbreviations.
449 These abbreviation specifications, if allowed, are at the end of the
450 construct, and enclosed in <em>&lt;</em> and <em>&gt;</em> bracket. These abbrev iation
451 specifications are optional in the syntax, and can be omitted. If they
452 are used, the abbreviation brackets are part of the actual syntax of
453 the construct. To make it clear that abbreviation specifications are
454 optional, syntax rules separate abbreviation specifications using
455 plenty of whitespace.</p>
456 <p>Abbreviation specifications consist of user-defined abbreviations,
457 abbreviation identifiers, and the number of bits required to repressent
458 abbreviations in a block. These notations appear, as appropriate, in
459 the corresponding syntax rules.</p>
460 <p>The most common abbreviation syntax is the corresponding abbreviation
461 identifier to use to read/write the corresponding record. In such
462 cases, if the specified abbreviation identifier is omitted, the
463 corresponding default abbreviation will be used by the PNaCl
464 reader/writer.</p>
465 <p>Also, within PNaClAsm, all alphabetic characters are lower case unless
466 they appear within a literal value. Hence, if we mix lower and upper
467 case letters within a name appearing in a syntax rule, the lower case
468 letters are literal while the upper case sequence of letters denote
469 (rule specific) values. If an upper case sequence of letters is
470 followed by digits, the corresponding embedded name includes both the
471 upper case letters and the digits. The valid values for each of these
472 names will be defined in the corresponding semantics subsection.</p>
473 <p>For example, consider the following syntax rule:</p>
474 <pre class="prettyprint">
475 %vN = add T O1, O2; &lt;A&gt;
476 </pre>
477 <p>This rule defines a PNaClAsm add instruction. This construct defines
478 an instruction that adds to two values (<em>O1</em> and <em>O2</em>) to generate
479 instruction value <em>%vN</em>. The types of the arguments, and the result,
480 are all of type <em>T</em>. Since abbreviation ID <em>A</em> is present, the
481 record is encoded using that abbreviation.</p>
482 <p>To be concrete, the syntactic rule above defines the structure of the
483 following PNaClAsm examples.</p>
484 <pre class="prettyprint">
485 %v10 = add i32 %v1, %v2; &lt;&#64;a5&gt;
486 %v11 = add i32 %v10, %v3;
487 </pre>
488 <p>In addition to specifying the syntax, each syntax rule also specifies
489 the contents of the corresponding record in the corresponding record
490 subsection. In simple cases, the elements of the corresponding record
491 are predefined (literal) constants. Otherwise the record element is a
492 name that is defined by the other subsections associated with the
493 construct.</p>
494 </section><section id="parse-state">
495 <h2 id="parse-state">Parse State</h2>
496 <p>This section describes the parse state of the PNaClAsm assembler. It
497 is used to define contextual data that is carried between records. The
498 following subsections describes each element of the parse state.</p>
499 <section id="typing">
500 <h3 id="typing">Typing</h3>
501 <p>Associated with most identifiers is a type. This type defines what
502 type the corresponding value has. It is defined by the (initially
503 empty) map</p>
504 <pre class="prettyprint">
505 TypeOf: ID -&gt; Type
506 </pre>
507 <p>For each type in the <em>types block</em> [ref], a corresponding inverse map< /p>
508 <pre class="prettyprint">
509 TypeID: Type -&gt; ID
510 </pre>
511 <p>is maintained to convert syntactic types to the corresponding type ID.
512 Note: This document assumes that map <em>TypeID</em> is automatically
513 maintained during updates to map <em>TypeOf</em> (when given a type
514 ID). Hence, <em>updates</em> subsections will not contain assignments to this
515 map.</p>
516 <p>Associated with each function identifier is it&#8217;s type signature. This
517 is different than the type of the function identifer, since function
518 identifiers are pointers (and always implemented as a 32-bit integer).</p>
519 <p>Function type signatures are maintained using:</p>
520 <pre class="prettyprint">
521 TypeOfFcn: ID -&gt; Type
522 </pre>
523 <p>In addition, if a function address is defining, there is a corresponding
524 implementation associated with the function address. To capture this association ,
525 we use the set:</p>
526 <pre class="prettyprint">
527 DefiningFcnIDs: set(ID)
528 </pre>
529 </section><section id="id-counters">
530 <h3 id="id-counters">ID Counters</h3>
531 <p>Each block defines one (or more) kinds of values. Value indices are
532 generated sequentially, starting at zero. To capture this, the
533 following counters are defined:</p>
534 <dl class="docutils">
535 <dt>NumTypes</dt>
536 <dd>The number of types defined so far (in the types block)</dd>
537 <dt>NumFuncAddresses</dt>
538 <dd>The number of function addresses defined so far (in the module
539 block).</dd>
540 <dt>NumDefinedFcnAddresses</dt>
541 <dd>The number of defining function addresses defined so far (in the
542 module block).</dd>
543 <dt>NumFuncImpls</dt>
544 <dd>The number of implemented functions defined so far (in the module block).</d d>
545 <dt>NumGlobalAddresses</dt>
546 <dd>The number of global variable/constant addresses defined so far (in
547 the globals block).</dd>
548 <dt>NumParams</dt>
549 <dd>The number of parameters defined for a function.</dd>
550 <dt>NumFcnConsts</dt>
551 <dd>The number of constants defined in a fucntion.</dd>
552 <dt>NumBasicBlocks</dt>
553 <dd>The number of basic blocks defined so far (within a function block).</dd>
554 <dt>NumValuedInsts</dt>
555 <dd>The number of instructions, generating values, defined so far
556 (within a function block).</dd>
557 </dl>
558 </section><section id="size-variables">
559 <h3 id="size-variables">Size Variables</h3>
560 <p>A number of blocks define expected sizes of constructs. These sizes are recor ded
561 in the following size variables:</p>
562 <dl class="docutils">
563 <dt>ExpectedBasicBlocks</dt>
564 <dd>The expected number of basic blocks within a function
565 implementation.</dd>
566 <dt>ExpectTypes</dt>
567 <dd>The expected number of types defined in the Types Block.</dd>
568 <dt>ExpectedGlobals</dt>
569 <dd>The expected number of global variable/constant addresses in the
570 globals block.</dd>
571 <dt>ExpectedInitializers</dt>
572 <dd>The expected number of initializers for a global variable/constant
573 address in the globals block.</dd>
574 </dl>
575 </section><section id="other-variables">
576 <h3 id="other-variables">Other Variables</h3>
577 <dl class="docutils">
578 <dt>EnclosingFcnID</dt>
579 <dd>The function ID of the function block being processed.</dd>
580 </dl>
581 </section></section><section id="special-records">
582 <h2 id="special-records">Special records</h2>
583 <p>There are four special PNaCl records, each having their own record
584 code. These special records are:</p>
585 <dl class="docutils">
586 <dt>Header</dt>
587 <dd>The header record is the first record of a PNaCl bitcode file, and
588 identifies the file&#8217;s magic number, as well as the bitcode version it
589 uses. The record defines the sequence of bytes that make up the
590 header and uniquely identifies the file as a PNaCl bitcode file.</dd>
591 <dt>Enter</dt>
592 <dd>An enter record defines the beginning of a block. Since blocks
593 can be nested, it can appear inside other blocks, as well as at the
594 top level.</dd>
595 <dt>Exit</dt>
596 <dd>An exit record defines the end of a block. Hence, it must appear in
597 every block, to end the block.</dd>
598 <dt>Addreviation</dt>
599 <dd>An abbreviation record defines a user-defined abbreviation to be
600 applied to records within blocks. Abbreviation records appearing in
601 the abbreviations block define global abbreviations. All other
602 abbreviations are local to the block they appear in, and can only be
603 used in that block.</dd>
604 </dl>
605 <p>All special records can&#8217;t have user-defined abbreviations associated
606 with them. The default abbreviation is always used.</p>
607 <p>The following subsections define valid special records, other than abbreviati on
608 records. Abbreviation records are described in the Abbreviations[ref] section.</ p>
609 <section id="header-record">
610 <h3 id="header-record">Header Record</h3>
611 <p>The header record must be the first record in the file. It is the only
612 record in the bitcode file that doesn&#8217;t have a corresponding construct
613 in PNaClAsm. Rather, the PNaClAsm assembler always automatically
614 inserts this record as the first record of the PNaCl bitcode file.</p>
615 <p><strong>Syntax</strong></p>
616 <p>There is no syntax for header records in PNaClAsm. They are
617 automatically inserted by the PNaCl bitcode writer.</p>
618 <p><strong>Record</strong></p>
619 <pre class="prettyprint">
620 &lt;66532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0&gt;
621 </pre>
622 <p><strong>Semantics</strong></p>
623 <p>The header record defines the initial sequence of bytes that must
624 appear at the beginning of all (PNaCl bitcode version 2) files. That
625 sequence is the list of bytes inside the record (excluding the record
626 code). As such, it uniquely identifies PNaCl bitcode files.</p>
627 <p><strong>Examples</strong></p>
628 <p>There are no examples for the header record, since it is not part of
629 PNaClAsm.</p>
630 </section><section id="enter-block-record">
631 <h3 id="enter-block-record">Enter Block Record</h3>
632 <p>Block records can be top-level, as well as nested in other
633 blocks. Blocks must begin with an <em>enter</em> record, and end with
634 an <em>exit</em> record.</p>
635 <p><strong>Syntax</strong></p>
636 <pre class="prettyprint">
637 N { &lt;B&gt;
638 </pre>
639 <p><strong>Record</strong></p>
640 <pre class="prettyprint">
641 &lt;655335, BlockID, B&gt;
642 </pre>
643 <p><strong>Semantics</strong></p>
644 <p>Enter block records define the beginning of a block. <em>B</em>, if present,
645 is the number of bits needed to represent all possible abbreviation
646 indices used within the block. If omitted, B=2 is always assumed.</p>
647 <p>The <em>BlockID</em> value is dependent on the name <em>N</em>. Valid names a nd
648 corresponding <em>BlockID</em> values are defined as follows:</p>
649 <table border="1" class="docutils">
650 <colgroup>
651 </colgroup>
652 <thead valign="bottom">
653 <tr class="row-odd"><th class="head">Name</th>
654 <th class="head">BlockID</th>
655 </tr>
656 </thead>
657 <tbody valign="top">
658 <tr class="row-even"><td>abbreviations</td>
659 <td>0</td>
660 </tr>
661 <tr class="row-odd"><td>constants</td>
662 <td>11</td>
663 </tr>
664 <tr class="row-even"><td>function</td>
665 <td>12</td>
666 </tr>
667 <tr class="row-odd"><td>globals</td>
668 <td>19</td>
669 </tr>
670 <tr class="row-even"><td>module</td>
671 <td>8</td>
672 </tr>
673 <tr class="row-odd"><td>types</td>
674 <td>17</td>
675 </tr>
676 <tr class="row-even"><td>valuesymtab</td>
677 <td>14</td>
678 </tr>
679 </tbody>
680 </table>
681 <p>Note: For readability, PNaClAsm allows a more readable form of a
682 function block enter record. See <em>function blocks</em> [ref] for more
683 details.</p>
684 <p><strong>Examples</strong></p>
685 <pre class="prettyprint">
686 module {
687 types {
688 count: 0;
689 }
690 globals {
691 count: 0;
692 }
693 }
694 </pre>
695 <p>This example defines a module, types, and globals block. Both the type
696 and the modules block appears within the module block.</p>
697 <p>The corresponding records are:</p>
698 <pre class="prettyprint">
699 &lt;655335, 8, 2&gt;
700 &lt;655335, 17, 2&gt;
701 &lt;1, 0&gt;
702 &lt;655334&gt;
703 &lt;655335, 19, 2&gt;
704 &lt;5, 0&gt;
705 &lt;655334&gt;
706 &lt;655334&gt;
707 </pre>
708 </section><section id="exit-block-record">
709 <h3 id="exit-block-record">Exit Block Record</h3>
710 <p>Block records can be top-level, as well as nested, records. Blocks must begin
711 with an <em>enter</em> record, and end with an <em>exit</em> record.</p>
712 <p><strong>Syntax</strong></p>
713 <pre class="prettyprint">
714 }
715 </pre>
716 <p><strong>Record</strong></p>
717 <pre class="prettyprint">
718 &lt;65536&gt;
719 </pre>
720 <p><strong>Semantics</strong></p>
721 <p>All exit records are identical, no matter what block they are ending. An
722 exit record defines the end of the block.</p>
723 <p><strong>Examples</strong></p>
724 <pre class="prettyprint">
725 module {
726 types {
727 count: 0;
728 }
729 globals {
730 count: 0;
731 }
732 }
733 </pre>
734 <p>This example defines a module, types, and globals block. Both the type
735 and the modules block appears within the module block.</p>
736 <p>The corresponding records are:</p>
737 <pre class="prettyprint">
738 &lt;655335, 8, 2&gt;
739 &lt;655335, 17, 2&gt;
740 &lt;1, 0&gt;
741 &lt;655334&gt;
742 &lt;655335, 19, 2&gt;
743 &lt;5, 0&gt;
744 &lt;655334&gt;
745 &lt;655334&gt;
746 </pre>
747 </section></section><section id="types-block">
748 <h2 id="types-block">Types Block</h2>
749 <p>The types block defines all types used in a program. It must appear in
750 the module block, before any function address records, the globals
751 block, the valuesymtab block, and any function blocks.</p>
752 <p>Each record in the types block defines a type used by the program.
753 Types can be broken into the following groups:</p>
754 <dl class="docutils">
755 <dt>Primitive types</dt>
756 <dd>Defines the set of base types for values. This includes various
757 sizes of integral and floating types, as well as vector types.</dd>
758 <dt>Void type</dt>
759 <dd>A primitive type that doesn&#8217;t represent any value and has no size.</dd >
760 <dt>Function types</dt>
761 <dd>The type signatures of functions.</dd>
762 <dt>Vector type</dt>
763 <dd>Defines vectors of primitive types.</dd>
764 </dl>
765 <p>In addition, any type that is not defined using another type is a
766 primitive type. All other types (i.e. function and vector)are
767 composite types.</p>
768 <p>Types must be defined in a topological order, causing primitive types
769 to apear before the composite types that use them. There are no
770 additional restrictions on the order that types can be defined in a
771 types block.</p>
772 <p>The following subsections introduces each valid PNaClAsm type, and the
773 corresponding PNaClAsm construct that defines the type. Types not
774 defined in the types block, can&#8217;t be used in a PNaCl program.</p>
775 <p>The first record of a types block must be a <em>count</em> record, defining
776 how many types are defined by the types block. All remaining records
777 defines a type. The following subsections define valid records within
778 a types block. The order of type records is important. The position of
779 these defining records implicitly define the type ID that will be used
780 to denote that type, within other PNaCl records of the bitcode file.</p>
781 <p>To make this more concrete, consider the following example types
782 block:</p>
783 <pre class="prettyprint">
784 types {
785 count: 4;
786 &#64;t0 = void;
787 &#64;t1 = i32;
788 &#64;t2 = float;
789 &#64;t3 = void (i32, float);
790 }
791 </pre>
792 <p>This example defines a types block that defines four type IDs:</p>
793 <ol class="arabic simple" start="0">
794 <li>The void type.</li>
795 <li>A 32-bit integer type.</li>
796 <li>A 32-bit floating type.</li>
797 <li>A function, taking 32-bit integer and float arguments, and returns void.</li >
798 </ol>
799 <p>Note that the order defines the corresponding ID that will be used for
800 that type, is based on the position of the type within the types
801 record. Hence, the assignment to ID &#64;tN can never appear before the
802 assignment to ID &#64;tN-1. Further, if type ID &#64;tN is assigned, it must
803 appear immediatedly after the assignment to ID &#64;tN-1.</p>
804 <section id="count-record">
805 <h3 id="count-record">Count Record</h3>
806 <p>The <em>count record</em> defines how many types are defined in the
807 types block. Following the types count record are records that define
808 types used by the PNaCl program.</p>
809 <p><strong>Syntax</strong></p>
810 <pre class="prettyprint">
811 count: N; &lt;I&gt;
812 </pre>
813 <p><strong>Record</strong></p>
814 <blockquote>
815 <div>I: &lt;1, N&gt;</div></blockquote>
816 <p><strong>Semantics</strong></p>
817 <p>This construct defines the number of types used by the PNaCl program.
818 <em>N</em> is the number of types defined in the types block. It is an error
819 to define more (or less) types than value <em>N</em>, within the enclosing
820 types block. <em>I</em> is the (optional) abbreviation associated with the
821 record.</p>
822 <p><strong>Updates</strong></p>
823 <pre class="prettyprint">
824 ExpectedTypes = N;
825 </pre>
826 <p><strong>Examples</strong></p>
827 <pre class="prettyprint">
828 types {
829 count: 2;
830 &#64;t0 = float;
831 &#64;t1 = i32;
832 }
833 </pre>
834 <p>This example defines that the only types used by the PNaCl program are
835 are 32 bit integer and floating type.</p>
836 <p>The corresponding PNaCl Records are:</p>
837 <pre class="prettyprint">
838 &lt;655335, 17, 2&gt;
839 &lt;1, 2&gt;
840 &lt;3&gt;
841 &lt;7, 32&gt;
842 &lt;655334&gt;
843 </pre>
844 </section><section id="void-type">
845 <h3 id="void-type">Void Type</h3>
846 <p>The <em>void</em> type record defines the void type, which corrresponds to
847 the type that doesn&#8217;t define any value, and has no size.</p>
848 <p><strong>Syntax</strong></p>
849 <pre class="prettyprint">
850 &#64;tN = void; &lt;I&gt;
851 </pre>
852 <p><strong>Record</strong></p>
853 <pre class="prettyprint">
854 I: &lt;2&gt;
855 </pre>
856 <p><strong>Semantics</strong></p>
857 <p>The void type record defines the type that has no values and has no
858 size. <em>I</em> is the (optional) abbreviation associated with the record.</p>
859 <p><strong>Constraints</strong></p>
860 <pre class="prettyprint">
861 N == NumTypes
862 NumTypes &lt; ExpectedTypes
863 </pre>
864 <p><strong>Updates</strong></p>
865 <pre class="prettyprint">
866 ++NumTypes;
867 TypeOf(&#64;tN) = void;
868 </pre>
869 <p><strong>Examples</strong></p>
870 <pre class="prettyprint">
871 &#64;t0 = void;
872 </pre>
873 <p>defines the record</p>
874 <pre class="prettyprint">
875 &lt;2&gt;
876 </pre>
877 </section><section id="integer-types">
878 <h3 id="integer-types">Integer Types</h3>
879 <p>PNaClAsm allows integral types for various bit sizes. Valid bit sizes
880 are 1, 8, 16, 32, and 64. Integers can be signed or unsigned, but the
881 signed component of in integer is not specified by the type. Rather,
882 individual instructions determine whether the value is assumed to be
883 signed or unsigned.</p>
884 <p>It should be noted that in PNaClAsm, all pointers are implemented as
885 32-bit (unsigned) integers. There isn&#8217;t a separate type for
886 pointers. The only way to tell that a 32-bit integer is a pointer, is
887 when it is used in an instruction that requires a pointer (such as
888 load and store instructions).</p>
889 <p><strong>Syntax</strong></p>
890 <pre class="prettyprint">
891 &#64;tN = iB; &lt;I&gt;
892 </pre>
893 <p><strong>Record</strong></p>
894 <blockquote>
895 <div>I: &lt;7, B&gt;</div></blockquote>
896 <p><strong>Semantics</strong></p>
897 <p>An integer type record defines an integral type. <em>B</em> defines the
898 number of bits of the integral type. <em>I</em> is the (optional)
899 abbreviation associated with the record.</p>
900 <p><strong>Constraints</strong></p>
901 <pre class="prettyprint">
902 N == NumTypes
903 NumTypes &lt; ExpectedTypes
904 B in {1, 8, 16, 32, 64}
905 </pre>
906 <p><strong>Updates</strong></p>
907 <pre class="prettyprint">
908 ++NumTypes;
909 TypeOf(&#64;tN) = iB;
910 </pre>
911 <p><strong>Examples</strong></p>
912 <pre class="prettyprint">
913 &#64;t1 = i32;
914 &#64;t2 = i1;
915 &#64;t3 = i64;
916 </pre>
917 <p>defines the records</p>
918 <pre class="prettyprint">
919 &lt;7, 32&gt;
920 &lt;7, 1&gt;
921 &lt;7, 64&gt;
922 </pre>
923 </section><section id="bit-floating-type">
924 <h3 id="bit-floating-type">32-Bit Floating Type</h3>
925 <p>PNaClAsm allows computation on 32-bit floating values. A floating type
926 record defines the 32-bit floating type.</p>
927 <p><strong>Syntax</strong></p>
928 <pre class="prettyprint">
929 &#64;tN = float; &lt;I&gt;
930 </pre>
931 <p><strong>Record</strong></p>
932 <pre class="prettyprint">
933 I: &lt;3&gt;
934 </pre>
935 <p><strong>Semantics</strong></p>
936 <p>A floating type record defines the 32-bit floating type. <em>I</em> is the
937 (optional) abbreviation associated with the record.</p>
938 <p><strong>Constraints</strong></p>
939 <pre class="prettyprint">
940 N == NumTypes
941 NumTypes &lt; ExpectedTypes
942 </pre>
943 <p><strong>Updates</strong></p>
944 <pre class="prettyprint">
945 ++NumTypes;
946 TypeOf(&#64;tN) = float;
947 </pre>
948 <p><strong>Examples</strong></p>
949 <pre class="prettyprint">
950 &#64;t5 = float;
951 </pre>
952 <p>defines the record</p>
953 <pre class="prettyprint">
954 &lt;3&gt;
955 </pre>
956 </section><section id="id1">
957 <h3 id="id1">64-bit Floating Type</h3>
958 <p>PNaClAsm allows computation on 64-bit floating values. A double type
959 record defines the 64-bit floating type.</p>
960 <p><strong>Syntax</strong></p>
961 <pre class="prettyprint">
962 &#64;tN = double; &lt;I&gt;
963 </pre>
964 <p><strong>Record</strong></p>
965 <pre class="prettyprint">
966 I: &lt;4&gt;
967 </pre>
968 <p><strong>Semantics</strong></p>
969 <p>A double type record defines the 64-bit floating type. <em>I</em> is the
970 (optional) abbreviation associated with the record.</p>
971 <p><strong>Constraints</strong></p>
972 <pre class="prettyprint">
973 N == NumTypes
974 NumTypes &lt; ExpectedTypes
975 </pre>
976 <p><strong>Updates</strong></p>
977 <pre class="prettyprint">
978 ++NumTypes;
979 TypeOf(&#64;tN) = double;
980 </pre>
981 <p><strong>Examples</strong></p>
982 <pre class="prettyprint">
983 &#64;t3 = double;
984 </pre>
985 <p>defines the record</p>
986 <pre class="prettyprint">
987 &lt;4&gt;
988 </pre>
989 </section><section id="vector-types">
990 <h3 id="vector-types">Vector Types</h3>
991 <p>TBD.</p>
992 </section><section id="function-types">
993 <h3 id="function-types">Function Types</h3>
994 <p>TBD.</p>
995 </section></section><section id="globals-block">
996 <h2 id="globals-block">Globals block</h2>
997 <p>The globals block defines global addresses of variables and constants,
998 used by the PNaCl program. It also defines the memory associated with
999 the global addresses, and how to initialize each global
1000 variable/constant. It must appear in the module block. It must appear
1001 after the types block, as well as after all function address
1002 records. But, it must also appear before the valuesymtab block, and
1003 any function blocks.</p>
1004 <p>The globals block begins with a count record, defining how many global
1005 addresses are defined by the PNaCl program. It is then followed by a
1006 sequence of records that defines how each global addresss is
1007 initialized.</p>
1008 <p>The standard sequence, for defining global addresses, begins with a
1009 global address record. It is then followed by a sequence of records
1010 defining how the global address is initialized. If the initializer is
1011 simple, a single record is used. Otherwise, the initializer is
1012 preceded with a compound record, specifying a number <em>N</em>, followed by
1013 sequence of <em>N</em> simple initializer records.</p>
1014 <p>The size of the memory referenced by each global address is defined by
1015 its initalizer records. All simple initializer records define a
1016 sequence of bytes. A compound initializer defines a sequence of bytes
1017 by concatenating corresponding sequence of bytes for each of its
1018 simple initializer records.</p>
1019 <p>For notational convenience, PNaClAsm begins a compound record with a
1020 &#8220;{&#8221;, and inserts a &#8220;}&#8221; after the last initializer record associated
1021 compound record. This latter &#8220;}&#8221; does not correspond to any record. It
1022 is implicitly assumed by the size specified in the compound record,
1023 and is added only to improve readability.</p>
1024 <p>For example, consider the following:</p>
1025 <pre class="prettyprint">
1026 globals {
1027 count: 2;
1028 const &#64;g0, align 1,
1029 zerofill 8;
1030 var &#64;g1, align 4,
1031 initializers 2 {
1032 {1, 2, 3, 4},
1033 zerofill 2;
1034 }
1035 }
1036 </pre>
1037 <p>In this example, the globals block contains 9 records. All lines,
1038 inside the block delimiters of this example (except the second to
1039 last) defines a record. The first record defines the number of global
1040 addresses defined by the program, i.e. 2. The second defines that
1041 second global addresses will be defined.</p>
1042 <p>The third record defines the global constant address <em>&#64;g0</em>, and it &#8217;s
1043 corresponding memory layout alignment. The forth record defines to
1044 initialize the constant with 8 bytes, all with the value zero. This
1045 size of <em>&#64;g0</em> is 8 bytes.</p>
1046 <p>The fifth record defines the global variable address <em>&#64;g1</em>, and it &#8217;s
1047 corresponding memory layout alignment. The sixth record defines that
1048 the initial value of <em>&#64;g1</em> is defined by the sequence of bytes define d
1049 by the following 2 initializer records. The seventh record defines that
1050 the first 4 bytes of <em>&#64;g1</em> are initialized with bytes 1, 2, 3, 4. The
1051 eighth record initializes bytes 5 and 6 to zero. The size of <em>&#64;g2</em> is
1052 therefore 6 bytes.</p>
1053 <p>The nine record is the exit block record.</p>
1054 <p>In other words, the corresponding records are:</p>
1055 <pre class="prettyprint">
1056 &lt;655335, 19, 2&gt;
1057 &lt;5, 2&gt;
1058 &lt;0, 1, 1&gt;
1059 &lt;2, 8&gt;
1060 &lt;0, 4, 0&gt;
1061 &lt;1, 2&gt;
1062 &lt;3, 1, 2, 3, 4&gt;
1063 &lt;2, 2&gt;
1064 &lt;655334&gt;
1065 </pre>
1066 <section id="id2">
1067 <h3 id="id2">Count Record</h3>
1068 <p>The count record defines the number of global addresses used by the
1069 PNaCl program.</p>
1070 <p><strong>Syntax</strong></p>
1071 <pre class="prettyprint">
1072 count: N; &lt;I&gt;
1073 </pre>
1074 <p><strong>Record</strong></p>
1075 <pre class="prettyprint">
1076 I: &lt;5, N&gt;
1077 </pre>
1078 <p><strong>Semantics</strong></p>
1079 <p>This record must appear first in the globals block. The count record
1080 defines the number of global addresses used by the program. <em>I</em> is the
1081 (optional) abbreviation associated with the record.</p>
1082 <p><strong>Updates</strong></p>
1083 <pre class="prettyprint">
1084 ExpectedGlobals = N;
1085 ExpectedInitializers = 0;
1086 </pre>
1087 </section><section id="global-variable-addressses">
1088 <h3 id="global-variable-addressses">Global Variable Addressses</h3>
1089 <p>A global variable address record defines a global address to global
1090 data. The global variable address record must be immediatedly
1091 followed by initializer record(s) that define how the corresponding
1092 global variable is initialized.</p>
1093 <p><strong>Syntax</strong></p>
1094 <pre class="prettyprint">
1095 var &#64;gN, align A, &lt;I&gt;
1096 </pre>
1097 <p><strong>Record</strong></p>
1098 <pre class="prettyprint">
1099 I: &lt;0, A, 0&gt;
1100 </pre>
1101 <p><strong>Semantics</strong></p>
1102 <p>A global varaible address record defines a global address for a global
1103 variable. <em>A</em> is the alignment to for the global variable. <em>I</em> i s
1104 the (optional) abbreviation associated with the record.</p>
1105 <p>It is assumed that the memory, referenced by the global variable
1106 address, can be both read and written to.</p>
1107 <p>??? Valid values for A. Section defining notion of memory alignments ???</p>
1108 <p><strong>Constraints</strong></p>
1109 <pre class="prettyprint">
1110 N == NumGlobalAddresses
1111 NumGlobalAddresses &lt; ExpectedGlobals
1112 ExpectedInitializers == 0
1113 </pre>
1114 <p><strong>Updates</strong></p>
1115 <pre class="prettyprint">
1116 ++NumGlobalAddresses;
1117 ExpectedInitializers = 1;
1118 TypeOf(&#64;gN) = i32;
1119 </pre>
1120 <p><strong>Examples</strong></p>
1121 <pre class="prettyprint">
1122 var &#64;g0, align 1,
1123 zerofill 8;
1124 var &#64;g1, align 1,
1125 {1, 2, 3, 4}
1126 </pre>
1127 <p>This example defines two global variable addresses, <em>&#64;g0</em> and
1128 <em>&#64;g1</em>. Both use memory alignment of 1. <em>&#64;g0</em> is an 8 byte variable
1129 initialized to zero. <em>&#64;g1</em> is a 4 byte variable, initialized by the
1130 sequence of bytes 1, 2, 3, and 4.</p>
1131 <p>The corresponding records defined by the example above are:</p>
1132 <pre class="prettyprint">
1133 &lt;0, 1, 0&gt;
1134 &lt;2, 8&gt;
1135 &lt;0, 1, 0&gt;
1136 &lt;3, 1, 2, 3, 4&gt;
1137 </pre>
1138 </section><section id="glboal-constant-addresses">
1139 <h3 id="glboal-constant-addresses">Glboal Constant Addresses</h3>
1140 <p>A global constant address record defines an address corresponding to a
1141 global constant that can&#8217;t be modified by the program. The global
1142 constant address record must be immediatedly followed by initializer
1143 record(s) that define how the corresponding global constant is
1144 initialized.</p>
1145 <p><strong>Syntax</strong></p>
1146 <pre class="prettyprint">
1147 const &#64;gN, align A, &lt;I&gt;
1148 </pre>
1149 <p><strong>Record</strong></p>
1150 <pre class="prettyprint">
1151 I: &lt;0, A, 1&gt;
1152 </pre>
1153 <p><strong>Semantics</strong></p>
1154 <p>A global constant address record defines a global address for a global
1155 constant. <em>A</em> is the memory alignment for the global constant. <em>I</em > is
1156 the (optional) abbreviation associated with the record.</p>
1157 <p>It is assumed that the memory, referenced by the global constant
1158 address, is only read, and can&#8217;t be written to.</p>
1159 <p>??? Valid values for A. Section defining notion of memory alignments ???</p>
1160 <p><strong>Constraints</strong></p>
1161 <pre class="prettyprint">
1162 N == NumGlobalAddresses
1163 NumGlobalAddresses &lt; ExpectedGlobals
1164 ExpectedInitializers = 0
1165 </pre>
1166 <p><strong>Updates</strong></p>
1167 <pre class="prettyprint">
1168 ++NumGlobalAddresses;
1169 ExpectedInitializers = 1;
1170 TypeOf(&#64;gN) = i32;
1171 </pre>
1172 <p><strong>Examples</strong></p>
1173 <pre class="prettyprint">
1174 const &#64;g0, align 1,
1175 zerofill 8;
1176 var &#64;g1, align 1,
1177 {1, 2}
1178 </pre>
1179 <p>This example defines two global constants, with global addresses <em>&#64;g0< /em>
1180 and <em>&#64;g1</em>. Both use memory alignment of 1. <em>&#64;g0</em> is an 8 b yte constant
1181 initialized to zero. <em>&#64;g1</em> is a 2 byte variable, initialized by the
1182 sequence of bytes 1 and 2.</p>
1183 <p>The corresponding PNaCl bitcode records are:</p>
1184 <pre class="prettyprint">
1185 &lt;0, 1, 1&gt;
1186 &lt;2, 8&gt;
1187 &lt;0, 1, 1&gt;
1188 &lt;3, 1, 2&gt;
1189 </pre>
1190 </section><section id="zerofill-initializer">
1191 <h3 id="zerofill-initializer">Zerofill Initializer</h3>
1192 <p>The zerofill initializer record intializes a sequence of bytes,
1193 associated with a global address, with zeros.</p>
1194 <p><strong>Syntax</strong></p>
1195 <pre class="prettyprint">
1196 zerofill N; &lt;I&gt;
1197 </pre>
1198 <p><strong>Record</strong></p>
1199 <pre class="prettyprint">
1200 I: &lt;2, N&gt;
1201 </pre>
1202 <p><strong>Semantics</strong></p>
1203 <p>A zerofill initializer record intializes a sequence of bytes,
1204 associated with a global address, with zeros. <em>I</em> is the (optional)
1205 abbreviation of the associated record.</p>
1206 <p><strong>Constraints</strong></p>
1207 <pre class="prettyprint">
1208 ExpectedInitializers &gt; 0;
1209 </pre>
1210 <p><strong>Updates</strong></p>
1211 <pre class="prettyprint">
1212 --ExpectedInitializers;
1213 </pre>
1214 <p><strong>Examples</strong></p>
1215 <pre class="prettyprint">
1216 const &#64;g0, align 1,
1217 zerofill 8;
1218 var &#64;g1, align 1,
1219 zerofill 4;
1220 </pre>
1221 <p>This example defines two global constants, with global addresses <em>&#64;g0< /em>
1222 and <em>&#64;g1</em>. The global memory associated with address <em>&#64;g0</em >, is an
1223 eight byte value, initialized to zero. The global memory associated
1224 with address <em>&#64;g1</em>, is a 4 byte value, initialized to zero.</p>
1225 <p>The corresponding PNaCl records are:</p>
1226 <pre class="prettyprint">
1227 &lt;0, 1, 1&gt;
1228 &lt;2, 8&gt;
1229 &lt;0, 1, 1&gt;
1230 &lt;2, 4&gt;
1231 </pre>
1232 </section><section id="data-initializer">
1233 <h3 id="data-initializer">Data Initializer</h3>
1234 <p>Data records define a sequence of bytes, defining the contents of the
1235 corresponding memory. The bytes defined by a data record corresponds
1236 the the corresponding bytes the memory will be initialized with.</p>
1237 <p><strong>Syntax</strong></p>
1238 <pre class="prettyprint">
1239 { B1 , .... , BN } &lt;I&gt;
1240 </pre>
1241 <p><strong>Record</strong></p>
1242 <pre class="prettyprint">
1243 I: &lt;3, B1, ..., BN&gt;
1244 </pre>
1245 <p><strong>Semantics</strong></p>
1246 <p>A data record defines a sequence of bytes <em>B1</em> throught <em>BN</em>, t hat
1247 intialize <em>N</em> bytes of memory. <em>I</em> is the (optional) abbreviation
1248 associated with the record.</p>
1249 <p><strong>Constraints</strong></p>
1250 <pre class="prettyprint">
1251 ExpectedInitializers &gt; 0
1252 </pre>
1253 <p><strong>Updates</strong></p>
1254 <pre class="prettyprint">
1255 --ExpectedInitializers;
1256 </pre>
1257 <p><strong>Examples</strong></p>
1258 <pre class="prettyprint">
1259 const &#64;g0, align 1,
1260 {1, 2, 97, 36, 44, 88, 44}
1261 const &#64;g1, align 1
1262 initializers 3 {
1263 {4, 5, 6, 7}
1264 reloc &#64;f1;
1265 {99, 66, 22, 12}
1266 }
1267 </pre>
1268 <p>The corresponding PNaCl records are:</p>
1269 <pre class="prettyprint">
1270 &lt;0, 1, 1&gt;
1271 &lt;3, 1, 2, 97, 36, 44, 88, 44&gt;
1272 &lt;0, 1, 1&gt;
1273 &lt;1, 3&gt;
1274 &lt;3, 4, 5, 6, 7&gt;
1275 &lt;4, 1&gt;
1276 &lt;3, 99, 66, 22, 12&gt;
1277 </pre>
1278 </section><section id="relocation-initializer">
1279 <h3 id="relocation-initializer">Relocation Initializer</h3>
1280 <p>A relocation initializer record allows one to fill the initial value
1281 with the value of another global address (i.e. either function,
1282 variable, or constant). Since addresses are pointers, and in PNaClAsm
1283 all pointers are of integral type i32, a relocation initializer record
1284 defines 4 bytes of memory.</p>
1285 <p><strong>Syntax</strong></p>
1286 <pre class="prettyprint">
1287 reloc A; &lt;I&gt;
1288 </pre>
1289 <p><strong>Record</strong></p>
1290 <pre class="prettyprint">
1291 I: &lt;4, N&gt;
1292 </pre>
1293 <p><strong>Semantics</strong></p>
1294 <p>A relocation initializer record defines a 4-byte value containing the
1295 specified global address <em>A</em>. <em>N</em> is the absolute index associated
1296 with address <em>A</em>. <em>I</em> is the (optional) abbreviation associated wi th
1297 the record.</p>
1298 <p><strong>Constraints</strong></p>
1299 <pre class="prettyprint">
1300 N == AbsoluteIndex(A);
1301 ExpectedInitializers &gt; 0
1302 </pre>
1303 <p><strong>Updates</strong></p>
1304 <pre class="prettyprint">
1305 --ExpectedInitializers;
1306 </pre>
1307 <p><strong>Examples</strong></p>
1308 <pre class="prettyprint">
1309 var &#64;g0, align 1,
1310 initializers 3 {
1311 reloc &#64;f1;
1312 reloc &#64;g0;
1313 reloc &#64;g10;
1314 }
1315 </pre>
1316 <p>This example defines global address <em>&#64;g0</em>. It defines 12 bytes of
1317 memory, and is initialized with three addresses <em>&#64;f1</em>, <em>&#64;g0</e m>, and
1318 <em>&#64;g10</em>. Note that all globals can be used in a relocation
1319 initialization record, even if it isn&#8217;t defined yet.</p>
1320 <p>Assuming</p>
1321 <pre class="prettyprint">
1322 100 = AbsoluteIndex(&#64;g0))
1323 </pre>
1324 <p>The corresponding PNaCl bitcode records are:</p>
1325 <pre class="prettyprint">
1326 &lt;0, 1, 0&gt;
1327 &lt;1, 3&gt;
1328 &lt;4, 1&gt;
1329 &lt;4, 100&gt;
1330 &lt;4, 110&gt;
1331 </pre>
1332 </section><section id="subfield-relocation-initializer">
1333 <h3 id="subfield-relocation-initializer">Subfield Relocation Initializer</h3>
1334 <p>A subfield relocation initializer record allows one to fill the
1335 initial value with the value of another (non-function) global address
1336 (i.e. either variable or constant), plus a constant. This constant
1337 must refer to an offset within the memory associated with the global
1338 address. Since addresses are pointers, and in PNaClAsm all pointers
1339 are of integral type i32, a relocation initializer record defines 4
1340 bytes of memory.</p>
1341 <p><strong>Syntax</strong></p>
1342 <pre class="prettyprint">
1343 reloc A + V; &lt;I&gt;
1344 </pre>
1345 <p><strong>Record</strong></p>
1346 <pre class="prettyprint">
1347 I: &lt;4, N, V&gt;
1348 </pre>
1349 <p><strong>Semantics</strong></p>
1350 <p>A relocation initializer record defines a 4-byte value containing the
1351 specified global (non-funciton) address <em>A</em>, modified by the (unsigned
1352 integer) offset <em>V</em>. <em>N</em> is the absolute indexassociated with <em> A</em>. The
1353 size of <em>V</em> must refer to a byte in the memory associated with address
1354 <em>A</em>. <em>I</em> is the (optional) abbreviation associated with the record .</p>
1355 <p><strong>Constraints</strong></p>
1356 <pre class="prettyprint">
1357 N == AbsoluteIndex(A)
1358 V &gt;= 0
1359 ExpectedInitializers &gt; 0
1360 </pre>
1361 <p><strong>Updates</strong></p>
1362 <pre class="prettyprint">
1363 --ExpectedInitializers;
1364 </pre>
1365 <p><strong>Examples</strong></p>
1366 <pre class="prettyprint">
1367 var &#64;g0, align 1,
1368 initializers 3 {
1369 reloc &#64;f1;
1370 reloc &#64;g0 + 4;
1371 reloc &#64;g10 + 32;
1372 }
1373 </pre>
1374 <p>This example defines global address <em>&#64;g0</em>, and is initialized with
1375 three pointers, addresses <em>&#64;f1</em>, <em>&#64;g0+4</em>, and <em>&#64;g10 +32</em>. Note that all
1376 global addresses can be used in a relocation initialization record,
1377 even if it isn&#8217;t defined yet. Validity of the reference can be
1378 verified, since a global address <em>&#64;g10</em> must be smaller than the valu e
1379 specified in the globals count record.</p>
1380 <p>Assuming</p>
1381 <pre class="prettyprint">
1382 100 = AbsoluteIndex(&#64;g0))
1383 </pre>
1384 <p>The corresponding PNaCl bitcode records are:</p>
1385 <pre class="prettyprint">
1386 &lt;0, 1, 0&gt;
1387 &lt;1, 3&gt;
1388 &lt;4, 1&gt;
1389 &lt;4, 100, 4&gt;
1390 &lt;4, 110, 32&gt;
1391 </pre>
1392 </section><section id="compound-initializer">
1393 <h3 id="compound-initializer">Compound Initializer</h3>
1394 <p>The compound initializer record must immediately follow a global variable/con stant
1395 address record. It defines how many (non-compound) initializer records are used to
1396 define the initializer. The size of the corresponding memory is the sum of the b ytes
1397 needed for each of the succeeding initializers.</p>
1398 <p><strong>Syntax</strong></p>
1399 <pre class="prettyprint">
1400 initializers N { &lt;I&gt;
1401 ...
1402 }
1403 </pre>
1404 <p><strong>Record</strong></p>
1405 <pre class="prettyprint">
1406 I: &lt;1, N&gt;
1407 </pre>
1408 <p><strong>Semantics</strong></p>
1409 <p>Defines that the next <em>N</em> initializers should be associated with the
1410 global address of the previous record. <em>I</em> is the (optional)
1411 abbreviation index associated with the record.</p>
1412 <p><strong>Constraints</strong></p>
1413 <pre class="prettyprint">
1414 ExpectedInitializers == 1
1415 </pre>
1416 <p><strong>Updates</strong></p>
1417 <pre class="prettyprint">
1418 ExpectedInitializers = N;
1419 </pre>
1420 <p><strong>Examples</strong></p>
1421 <pre class="prettyprint">
1422 const &#64;g1, align 1
1423 initializers 3 {
1424 {4, 5, 6, 7}
1425 reloc &#64;f1;
1426 {99, 66, 22, 12}
1427 }
1428 </pre>
1429 <p>The corresponding PNaCl records are:</p>
1430 <pre class="prettyprint">
1431 &lt;0, 1, 1&gt;
1432 &lt;1, 3&gt;
1433 &lt;3, 4, 5, 6, 7&gt;
1434 &lt;4, 1&gt;
1435 &lt;3, 99, 66, 22, 12&gt;
1436 </pre>
1437 </section></section><section id="valuesymtab-block">
1438 <h2 id="valuesymtab-block">Valuesymtab Block</h2>
1439 <p>TBD.</p>
1440 </section><section id="module-block">
1441 <h2 id="module-block">Module Block</h2>
1442 <p>The module block, like all blocks, are enclosed in a pair of
1443 enter/exit records, using block ID 8. A well-formed module block
1444 consists The following records (in order):</p>
1445 <dl class="docutils">
1446 <dt>A version record</dt>
1447 <dd>The version record communicates the version of the PNaCl bitcode
1448 reader/writer to use. Note that this is different than the PNaCl
1449 bitcode (ABI) verion. The PNaCl bitcode (ABI) version defines what
1450 is expected in records, and is defined in the header record of the
1451 bitcode file. The version record defines the version of the PNaC
1452 bitcode reader/writer to use to convert records into bit
1453 sequences.</dd>
1454 <dt>Optional local abbreviations</dt>
1455 <dd>Defines a list of local abbreviations to use for records within
1456 the module block.</dd>
1457 <dt>An optional abbreviations block</dt>
1458 <dd>The abbreviations block defines user-defined, global abbreviations
1459 that are used to convert PNaCl records to bit sequences in blocks
1460 following the abbreviations block.</dd>
1461 <dt>A types block</dt>
1462 <dd>The types block defines the set of all types used in the program.</dd>
1463 <dt>A non-empty sequence of function address records</dt>
1464 <dd>Each record defines a function address used by the
1465 program. Function addresses must either be external, or defined
1466 internally by the program. If they are defined by the program,
1467 there must be a function block (appearing later in the module)
1468 that defines the sequence of instructions for each defined
1469 function.</dd>
1470 <dt>A globals block defining the global variables.</dt>
1471 <dd>This block defines the set of global variable (addresses) used by
1472 the program. In addition to the addresses, each global variable
1473 also defines how the corresponding global variable is initialized.</dd>
1474 <dt>An optional value symbol table block.</dt>
1475 <dd>This block, if defined, provides textual names for function and
1476 global variable addresses (previously defined in the module). Note
1477 that only names for instrinsic functions must be provided. Any
1478 additional names are hints that may (or may not) be used by the
1479 PNaCl translator, and be available for debugging when executed.</dd>
1480 <dt>A sequence of function blocks.</dt>
1481 <dd>Each function block defines the corresponding control flow graph
1482 for each defined function. The order of function blocks is used to
1483 associate them with function addresses. The order of the defined
1484 function blocks must follow the same order as the corresponding
1485 function addresses defined in the module block.</dd>
1486 </dl>
1487 <p>Descriptions of the abbreviations[ref], types[ref], global
1488 variables[ref], value symbol table[ref], and function[ref] blocks are
1489 not provided here. See the appropriate reference for more details. The
1490 following subsections describe each of the records that can appear in
1491 a module block.</p>
1492 <section id="version">
1493 <h3 id="version">Version</h3>
1494 <p>The version record defines the implementation of the PNaCl
1495 reader/writer that converts PNaCl records to bit sequences. Note that
1496 this is different than the PNaCl version of the bitcode file (encoded
1497 in the header record of the bitcode file). The PNaCl version defines
1498 the valid forms of PNaCl records. The version record is specific to
1499 the PNaCl version, and may have different values for different PNaCl
1500 versions.</p>
1501 <p>Note that currently, only PNaCl version 2, and version record value 1
1502 is defined. Larger version record values are reserved for future
1503 changes.</p>
1504 <p><strong>Syntax</strong></p>
1505 <pre class="prettyprint">
1506 version N; &lt;I&gt;
1507 </pre>
1508 <p><strong>Record</strong></p>
1509 <pre class="prettyprint">
1510 I: &lt;1, N&gt;
1511 </pre>
1512 <p><strong>Semantics</strong></p>
1513 <p>The version record defines which PNaCl reader/writer rules should be
1514 followed. <em>N</em> is the version number. Currently <em>N</em> must be 1. Futu re
1515 versions of PNaCl may define other values. <em>I</em> is the (optional)
1516 abbreviation index associated with the record.</p>
1517 <p><em>Examples</em></p>
1518 <pre class="prettyprint">
1519 version 1;
1520 </pre>
1521 <p>The corresponding record is:</p>
1522 <pre class="prettyprint">
1523 &lt;1, 1&gt;
1524 </pre>
1525 </section><section id="function-address">
1526 <h3 id="function-address">Function Address</h3>
1527 <p>A function address record defines a function address. Defining
1528 function addresses also imply a corresponding
1529 implementation. Implementations of function addresses are defined by a
1530 corresponding function block. The association of defining function
1531 address with the corresponding function block is based on position.
1532 The <em>Nth</em> defining function address record, in the module block, has
1533 its implementation in the <em>Nth</em> function block of that module block.</p>
1534 <p><strong>Syntax</strong></p>
1535 <pre class="prettyprint">
1536 PN LN T0 &#64;fN ( T1 , ... , TM ); &lt;I&gt;
1537 </pre>
1538 <p><strong>Record</strong></p>
1539 <p><strong>Semnatics</strong></p>
1540 <p>Defines the function address <em>&#64;fN</em>. <em>PN</em> is the name that s pecifies
1541 the prototype value <em>P</em> associated with the function. A function
1542 address is defining only if <em>P==0</em>. Otherwise, it is only declared.
1543 The type of the function is defined by function type <em>&#64;tT. *L</em>
1544 is the linkage specification corresponding to name <em>LN</em>. <em>C</em> is th e
1545 calling convention used by the function.</p>
1546 <p>Type <em>&#64;tT</em> (associated with the corresponding syntax rules) is
1547 defined as:</p>
1548 <pre class="prettyprint">
1549 &#64;tT = TypeOf(T0 ( T1 , ... , TN ))
1550 </pre>
1551 <p>Valid prototype names <em>PN</em>, and corresponding <em>P</em> values, are:< /p>
1552 <table border="1" class="docutils">
1553 <colgroup>
1554 </colgroup>
1555 <thead valign="bottom">
1556 <tr class="row-odd"><th class="head">P</th>
1557 <th class="head">PN</th>
1558 </tr>
1559 </thead>
1560 <tbody valign="top">
1561 <tr class="row-even"><td>1</td>
1562 <td>declare</td>
1563 </tr>
1564 <tr class="row-odd"><td>0</td>
1565 <td>define</td>
1566 </tr>
1567 </tbody>
1568 </table>
1569 <p>Valid linkage names <em>LN</em>, and corresponding <em>L</em> values, are:</p >
1570 <table border="1" class="docutils">
1571 <colgroup>
1572 </colgroup>
1573 <thead valign="bottom">
1574 <tr class="row-odd"><th class="head">L</th>
1575 <th class="head">LN</th>
1576 </tr>
1577 </thead>
1578 <tbody valign="top">
1579 <tr class="row-even"><td>3</td>
1580 <td>internal</td>
1581 </tr>
1582 <tr class="row-odd"><td>0</td>
1583 <td>external</td>
1584 </tr>
1585 </tbody>
1586 </table>
1587 <p>Currently, only one calling convention <em>C</em> is supported:</p>
1588 <table border="1" class="docutils">
1589 <colgroup>
1590 </colgroup>
1591 <thead valign="bottom">
1592 <tr class="row-odd"><th class="head">C</th>
1593 <th class="head">Calling Convention</th>
1594 </tr>
1595 </thead>
1596 <tbody valign="top">
1597 <tr class="row-even"><td>0</td>
1598 <td>C calling convention</td>
1599 </tr>
1600 </tbody>
1601 </table>
1602 <p><strong>Constraint</strong></p>
1603 <pre class="prettyprint">
1604 N == NumFuncAddresses
1605 </pre>
1606 <section id="updates">
1607 <h4 id="updates">Updates</h4>
1608 <pre class="prettyprint">
1609 ++NumFuncAddresses;
1610 TypeOf(&#64;fN) = TypeOf(TypeID(i32));
1611 TypeOfFcn(&#64;fN) = TypeOf(&#64;tT);
1612
1613 if PN == 0:
1614 DefiningFcnIDs += &#64;FN;
1615 ++NumDefinedFunctionAddresses;
1616 </pre>
1617 <p><strong>Examples</strong></p>
1618 <pre class="prettyprint">
1619 module {
1620 ...
1621 types {
1622 &#64;t0 = void;
1623 &#64;t1 = i32;
1624 &#64;t3 = float;
1625 &#64;t4 = void (i32, float);
1626 &#64;t5 = i32 ();
1627 }
1628 ...
1629 declare external void &#64;f0(i32, float);
1630 define internal i32 &#64;f1();
1631 </pre>
1632 <p>This defines function addresses <em>&#64;f0</em> and <em>&#64;f1</em>. Functi on address
1633 <em>&#64;f0</em> is defined externally while <em>&#64;f2</em> has an implementat ion (defined
1634 by a corresponding function block). The type signature of <em>&#64;f0</em> is
1635 defined by type <em>&#64;t4</em> while the type signature of <em>&#64;f1</em> is <em>&#64;t5</em>.</p>
1636 <p>The corresopnding records for these two function addresses are:</p>
1637 <pre class="prettyprint">
1638 &lt;8, 4, 0, 1, 0&gt;
1639 &lt;8, 5, 0, 0, 1&gt;
1640 </pre>
1641 </section></section></section><section id="constants-blocks">
1642 <h2 id="constants-blocks">Constants Blocks</h2>
1643 <p>TBD.</p>
1644 </section><section id="function-blocks">
1645 <h2 id="function-blocks">Function Blocks</h2>
1646 <p>A function block defines the implementation of a function address. The
1647 function address it defines is based on the position of the
1648 corresponding defining function address. The Nth defining function
1649 address always corresponds to the corresponding Nth function block in
1650 the module block.</p>
1651 <p>A function definition contains a list of basic block, forming the CFG
1652 (control flow graph). Each basic block contains a list of
1653 instructions, and ends with a <em>terminator</em> [ref] (branch) instruction.</p >
1654 <p>The first basic block in a function is special in two ways: it is
1655 immediately executed on entrance to the function, and it is not
1656 allowed to have predecessor basic blocks (i.e. there can&#8217;t be any
1657 branches to the entry block of a function). Because the entry block
1658 has no predecessors, it also can&#8217;t have any <em>PHI nodes</em> [ref].</p>
1659 <p>The parameters are implied by the type of the corresponding function
1660 address. One parameter is defined for each argument of the function
1661 type signature.</p>
1662 <p>The number of basic blocks are defined by the count record. Each
1663 termimintor instruction ends the current basic block, and the next
1664 instruction begins a new basic blocks. Basic blocks are numbered by
1665 the order they appear (starting with index 0). Basic block IDs have
1666 the form <em>%bN</em>, where <em>N</em> corresponds to the position of the basic
1667 block within the function block.</p>
1668 <p>Each instruction, within a function block, corresponds to a
1669 corresponding PNaCl record. The layout of a function block is the
1670 (basic block) count record, followed by a sequence of instruction
1671 records.</p>
1672 <p>For readability, PNaClAsm introduces block IDs. These block IDs do not
1673 correspond to PNaCl records, since basic block boundaries are defined
1674 implicitly, after terminator instructions. They appear only for
1675 readability.</p>
1676 <p>Most operands of instructions are encoded using a relative index
1677 value, rather than abolute. The is done because most instruction
1678 operands refer to values defined earlier in the (same) basic block.
1679 As a result, the relative distance (back) from the next defining
1680 instruction value index (for the function block) is frequently a small
1681 number. Small numbers tend to require less bits when they are
1682 converted to bit sequences. This distance is used in the corresponding
1683 records to denote the operand values.</p>
1684 <p>The following subsections define records that can appear in a function
1685 block.</p>
1686 <section id="function-enter">
1687 <h3 id="function-enter">Function enter</h3>
1688 <p>PNaClAsm defines a function enter block construct. The corresponding
1689 record is simply an enter block record, with BlockID value 12. All
1690 context about the defining address is implicit by the position of the
1691 function block, and the corresponding defining function address. To
1692 improve readability, PNaClAsm includes the function signature into the
1693 syntax rule.</p>
1694 <p><strong>Syntax</strong></p>
1695 <pre class="prettyprint">
1696 function TR &#64;fN ( T0 %p0, ... , TM %pM) { &lt;B&gt;
1697 </pre>
1698 <p><strong>Record</strong></p>
1699 <blockquote>
1700 <div>&lt;655335, 12, B&gt;</div></blockquote>
1701 <p><strong>Semantics</strong></p>
1702 <p><em>B</em> is the number of bits reserved for abbreviations in the block. See
1703 enter block records[ref] for more details.</p>
1704 <p>The value of <em>N</em> corresponds the the positional index of the
1705 corresponding defining function address this block is associated
1706 with. <em>M</em> is the number of defined paramaters (plus one)
1707 in the function heading.</p>
1708 <p><strong>Constraints</strong></p>
1709 <pre class="prettyprint">
1710 N == NumFcnImpls
1711 &#64;fN in DefiningFcnIDs
1712 TypeOfFcn(&#64;fN) == TypeOf(TypeID(TR (T0, ... , TM)))
1713 </pre>
1714 <p><strong>Updates</strong></p>
1715 <pre class="prettyprint">
1716 ++NumFcnImpls;
1717 EnclosingFcnID = &#64;fN;
1718 NumBasicBlocks = 0;
1719 ExpectedBlocks = 0;
1720 NumParams = M;
1721 for I in [0..M]:
1722 TypeOf(%pI) = TypeOf(TypeID(TI));
1723 </pre>
1724 <p><strong>Examples</strong></p>
1725 <pre class="prettyprint">
1726 types {
1727 ...
1728 &#64;t10 = void (i32, float);
1729 ...
1730 }
1731 ...
1732 define internal void &#64;f12(i32, float);
1733 ...
1734 function void &#64;f12(i32 %p0, float %p1) {
1735 ...
1736 }
1737 </pre>
1738 <p>defines the enter block record:</p>
1739 <pre class="prettyprint">
1740 &lt;655335, 12, 2&gt;
1741 </pre>
1742 </section><section id="id3">
1743 <h3 id="id3">Count Record</h3>
1744 <p>The count record, within a function block, defines the number of basic
1745 blocks used to define the function implementation.</p>
1746 <p><strong>Syntax</strong></p>
1747 <pre class="prettyprint">
1748 blocks: N; &lt;I&gt;
1749 %b0:
1750 </pre>
1751 <p><strong>Record</strong></p>
1752 <pre class="prettyprint">
1753 I: &lt;1, N&gt;
1754 </pre>
1755 <p><strong>Semantics</strong></p>
1756 <p>The count record defines the number of basic blocks <em>N</em>, defined by
1757 the implemented function. <em>I</em> is the (optional) abbreviation
1758 associated with the record.</p>
1759 <p><strong>Constraints</strong></p>
1760 <pre class="prettyprint">
1761 ExpectedBasicBlocks == 0
1762 NumBasicBlocks == 0
1763 </pre>
1764 <section id="id4">
1765 <h4 id="id4">Updates</h4>
1766 <pre class="prettyprint">
1767 ExpectedBlocks = N;
1768 </pre>
1769 <p><strong>Examples</strong></p>
1770 <pre class="prettyprint">
1771 blocks: 5
1772 </pre>
1773 <p>The corresponding PNaCl bitcode record is:</p>
1774 <pre class="prettyprint">
1775 &lt;1, 5&gt;
1776 </pre>
1777 </section></section><section id="terminator-instructions">
1778 <h3 id="terminator-instructions">Terminator Instructions</h3>
1779 <p>Terminator instructions are instructions that appear in a function
1780 block, and define the end of the current basic block. A terminator
1781 instuction indicates which block should be executed after the current
1782 block is finished. The function block is well formed only if the number
1783 of terminator instructions, in the function block, corresponds to the
1784 value defined by the corresponding count block.</p>
1785 <section id="return-void-instruction">
1786 <h4 id="return-void-instruction">Return Void Instruction</h4>
1787 <p>The return void instruction is used to return control from a function
1788 back to the caller, without returning any value.</p>
1789 <p><strong>Syntax</strong></p>
1790 <pre class="prettyprint">
1791 ret; &lt;I&gt;
1792 %bB:
1793 </pre>
1794 <p><strong>Record</strong></p>
1795 <pre class="prettyprint">
1796 I: &lt;10&gt;
1797 </pre>
1798 <p><strong>Semantics</strong></p>
1799 <p>The return instruction returns control to the calling function.</p>
1800 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em>
1801 only appears if <em>B + 1 &lt; ExpectedBasicBlocks</em>. That is, the label is
1802 omitted only if this terminator instruction is the last instruction in
1803 the function block. <em>I</em> is the (optional) abbreviation index
1804 associated with the record.</p>
1805 <p><strong>Constraints</strong></p>
1806 <pre class="prettyprint">
1807 B == NumBasicBlocks
1808 NumBasicBlocks &lt; ExpectedBasicBLocks
1809 ReturnType(TypeOf(EnclosingFcnID)) == void
1810 </pre>
1811 <p><strong>Updates</strong></p>
1812 <pre class="prettyprint">
1813 ++NumBasicBlocks;
1814 </pre>
1815 <p><strong>Examples</strong></p>
1816 <p>The following shows the implementation of a function that simply returns.</p>
1817 <pre class="prettyprint">
1818 function void &#64;f5() {
1819 ret;
1820 }
1821 </pre>
1822 <p>The corresponding PNaCl records are:</p>
1823 <pre class="prettyprint">
1824 &lt;655335, 12, 2&gt;
1825 &lt;10&gt;
1826 &lt;655334&gt;
1827 </pre>
1828 </section><section id="return-value-instruction">
1829 <h4 id="return-value-instruction">Return Value Instruction</h4>
1830 <p>The return value instruction is used to return control from a
1831 function back to the caller, including a value. The value must
1832 correspond to the return type of the enclosing function.</p>
1833 <p><strong>Syntax</strong></p>
1834 <pre class="prettyprint">
1835 ret T V; &lt;I&gt;
1836 %bB:
1837 </pre>
1838 <p><strong>Record</strong></p>
1839 <pre class="prettyprint">
1840 I: &lt;10, R&gt;
1841 </pre>
1842 <p><strong>Semantics</strong></p>
1843 <p>The return instruction returns control to the calling function,
1844 returning the provided value.</p>
1845 <p><em>V</em> is the value to return. <em>R</em> is the corresponding relative i ndex
1846 defining the value to return. Type <em>T</em> must be of the type returned
1847 by the function. It must also be the type associated with value <em>V</em>.
1848 <em>I</em> is the (optional) abbreviation index associated with the record.</p>
1849 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB :</em>
1850 only appears if <em>B + 1 &lt; ExpectedBasicBlocks</em>. That is, the label is
1851 omitted only if this terminator instruction is the last instruction in
1852 the function block.</p>
1853 <p><strong>Constraints</strong></p>
1854 <pre class="prettyprint">
1855 R = RelativeIndex(V)
1856 B == NumBasicBlocks
1857 NumBasicBlocks &lt; ExpectedBasicBlocks
1858 T == TypeOf(V) == ReturnType(TypeOf(EnclosingFcnID))
1859 </pre>
1860 <p><strong>Updates</strong></p>
1861 <pre class="prettyprint">
1862 ++NumBasicBlocks;
1863 </pre>
1864 <p><strong>Examples</strong></p>
1865 <p>The following shows a return statement that returns the value
1866 generated by the previous instruction:</p>
1867 <pre class="prettyprint">
1868 %v10 = add i32 %v1, &#64;v2;
1869 ret i32 &#64;v10;
1870 </pre>
1871 <p>The corresponding PNaCl records are:</p>
1872 <pre class="prettyprint">
1873 &lt;2, 9, 8, 0&gt;
1874 &lt;10, 1&gt;
1875 </pre>
1876 </section><section id="unconditional-branch-instruction">
1877 <h4 id="unconditional-branch-instruction">Unconditional Branch Instruction</h4>
1878 <p>The unconditional branch instruction is used to cause control flow to
1879 transfer to a different basic block of the function.</p>
1880 <section id="syntax">
1881 <h5 id="syntax">Syntax</h5>
1882 <pre class="prettyprint">
1883 br %bN; &lt;I&gt;
1884 %bB:
1885 </pre>
1886 </section><section id="record">
1887 <h5 id="record">Record</h5>
1888 <pre class="prettyprint">
1889 I: &lt;11, N&gt;
1890 </pre>
1891 </section><section id="semantics">
1892 <h5 id="semantics">Semantics</h5>
1893 <p>The unconditional branch instruction causes control flow to transfer
1894 to basic block <em>N</em>. <em>I</em> is the (optional) abbreviation index
1895 associated with the record.</p>
1896 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em>
1897 only appears if <em>B + 1 &lt; ExpectedBasicBlocks</em>. That is, the label is
1898 omitted only if this terminator instruction is the last instruction in
1899 the function block.</p>
1900 </section><section id="constraints">
1901 <h5 id="constraints">Constraints</h5>
1902 <pre class="prettyprint">
1903 0 &lt; N
1904 N &lt; ExpectedBasicBlocks
1905 B == NumBasicBlocks
1906 NumBasicBlocks &lt; ExpectedBasicBlocks
1907 </pre>
1908 </section><section id="id5">
1909 <h5 id="id5">Updates</h5>
1910 <pre class="prettyprint">
1911 ++NumBasicBlocks;
1912 </pre>
1913 </section><section id="examples">
1914 <h5 id="examples">Examples</h5>
1915 <pre class="prettyprint">
1916 br %b2;
1917 </pre>
1918 <p>This branch instruction branches to the 3rd basic block of the function. It
1919 defines the following PNaCL record:</p>
1920 <pre class="prettyprint">
1921 &lt;11, 2&gt;
1922 </pre>
1923 </section></section><section id="conditional-branch-instruction">
1924 <h4 id="conditional-branch-instruction">Conditional Branch Instruction</h4>
1925 <p>The conditional branch instruction is used to cause control flow to
1926 transfer to a different basic block of the function, based on a
1927 boolean test condition.</p>
1928 <section id="id6">
1929 <h5 id="id6">Syntax</h5>
1930 <pre class="prettyprint">
1931 br i1 C, %bB1, %bB2; &lt;I&gt;
1932 %bB:
1933 </pre>
1934 </section><section id="id7">
1935 <h5 id="id7">Record</h5>
1936 <pre class="prettyprint">
1937 I: &lt;11, B1, B2, V&gt;
1938 </pre>
1939 </section><section id="id8">
1940 <h5 id="id8">Semantics</h5>
1941 <p>Upon execution of a conditional branch instruction, the <em>i1</em> (boolean)
1942 argument <em>C</em> is evaluated. If the value is <em>true</em>, control flows t o
1943 basic block <em>B1</em>. Otherwise control flows to basic block
1944 <em>B2</em>. Condition value V is the relative index of condition C. <em>I</em> is
1945 the (optional) abbreviation index associated with the record.</p>
1946 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em>
1947 only appears if <em>B + 1 &lt; ExpectedBasicBlocks</em>. That is, the label is
1948 omitted only if this terminator instruction is the last instruction in
1949 the function block.</p>
1950 </section><section id="id9">
1951 <h5 id="id9">Constraints</h5>
1952 <pre class="prettyprint">
1953 V == RelativeIndex(C)
1954 0 &lt; B1
1955 B1 &lt; ExpectedBasicBlocks
1956 0 &lt; B2
1957 B2 &lt; ExpectedBasicBlocks
1958 B == NumBasicBlocks and
1959 NumBasicBlocks &lt; ExpectedBasicBlocks
1960 TypeOf(C) == i1
1961 </pre>
1962 </section><section id="id10">
1963 <h5 id="id10">Updates</h5>
1964 <pre class="prettyprint">
1965 ++NumBasicBlocks;
1966 </pre>
1967 </section><section id="id11">
1968 <h5 id="id11">Examples</h5>
1969 <pre class="prettyprint">
1970 %b2:
1971 %v10 = cmp eq i32 %v8, %v9;
1972 br i1 %v10, %b3, %b4;
1973 %b3:
1974 ret i32 1;
1975 %b4:
1976 ret i32 0;
1977 </pre>
1978 <p>The record generated for the conditional branch instruction is:</p>
1979 <pre class="prettyprint">
1980 &lt;11, 3, 4, 1&gt;
1981 </pre>
1982 </section></section><section id="unreachable">
1983 <h4 id="unreachable">Unreachable</h4>
1984 <p>The unreachable instruction has no defined semantics. The instruction
1985 is used to inform the <em>PNaCl translator</em> that control can&#8217;t reach t his
1986 instruction. The most common use of this is when one calls a
1987 no-return function.</p>
1988 <section id="id12">
1989 <h5 id="id12">Syntax</h5>
1990 <pre class="prettyprint">
1991 unreachable; &lt;I&gt;
1992 %bB:
1993 </pre>
1994 </section><section id="id13">
1995 <h5 id="id13">Record</h5>
1996 <pre class="prettyprint">
1997 I: &lt;15&gt;
1998 </pre>
1999 </section><section id="id14">
2000 <h5 id="id14">Semantics</h5>
2001 <p>Directive to the <em>PNaCl translator</em> that this instruction is unreachab le.</p>
2002 <p><em>I</em> is the (optional) abbreviation index associated with the record.</ p>
2003 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em>
2004 only appears if <em>B + 1 &lt; ExpectedBasicBlocks</em>. That is, the label is
2005 omitted only if this terminator instruction is the last instruction in
2006 the function block.</p>
2007 </section><section id="id15">
2008 <h5 id="id15">Constraints</h5>
2009 <pre class="prettyprint">
2010 B == NumBasicBlocks and
2011 NumBasicBlocks &lt; ExpectedBasicBlocks
2012 </pre>
2013 </section><section id="id16">
2014 <h5 id="id16">Updates</h5>
2015 <pre class="prettyprint">
2016 ++NumBasicBlocks;
2017 </pre>
2018 </section><section id="id17">
2019 <h5 id="id17">Examples</h5>
2020 <p>TBD.</p>
2021 </section></section><section id="switch-instruction">
2022 <h4 id="switch-instruction">Switch Instruction</h4>
2023 <p>TBD.</p>
2024 </section></section><section id="binary-inststructions">
2025 <h3 id="binary-inststructions">Binary Inststructions</h3>
2026 <p>Binary instructions are used to do most of the computation in a
2027 program. They require two operands of the same type, execute an
2028 operation on them, and produce a value. The value may represent
2029 multiple values if the type is a vector type. The result value always
2030 has the same type as its operands.</p>
2031 <p>Most integer binary operations can be applied to signed and unsigned
2032 integers. In the few cases where the sign can make a difference,
2033 there are two separate binary operations, one for each case. For
2034 floating binary operations, the binary operation has the same name as
2035 the corresponding signed integer operation. One can tell whether the
2036 operation is integral or floating, by the type associated with the
2037 binary operation.</p>
2038 <section id="add-instruction">
2039 <h4 id="add-instruction">Add Instruction</h4>
2040 <p>The add instruction returns the sum of its two operands. Both
2041 arguments, and the result, must be an integer, floating, or vector
2042 type.</p>
2043 <p><strong>Syntax</strong></p>
2044 <pre class="prettyprint">
2045 %vN = add T V1, V2; &lt;I&gt;
2046 </pre>
2047 <p><strong>Record</strong></p>
2048 <blockquote>
2049 <div>I: &lt;2, A1, A2, 0&gt;</div></blockquote>
2050 <p><strong>Semantics</strong></p>
2051 <p>The add instruction returns the sum of its two operands. Arguments
2052 <em>V1</em> and <em>V2</em>, and the result <em>%vN</em>, must be of type <em>T< /em>. <em>T</em> must be
2053 an integral, floating, or vector type. <em>N</em> is defined by the record
2054 position, defining the corresponding value generated by the
2055 instruction. <em>I</em> is the (optiona) abbreviation associated with the
2056 corresponding record.</p>
2057 <p><strong>Constraints</strong></p>
2058 <pre class="prettyprint">
2059 A1 == RelativeIndex(V1)
2060 A2 == RelativeIndex(V2)
2061 TypeOf(V1) == TypeOf(V2)
2062 N == NumValuedInsts
2063 NumBasicBlocks &lt; ExpectedBasicBlocks
2064 </pre>
2065 <p><strong>Updates</strong></p>
2066 <pre class="prettyprint">
2067 ++NumValuedInsts;
2068 TypeOf(%vN) = T
2069 </pre>
2070 <p><strong>Examples</strong></p>
2071 <p>TBD.</p>
2072 </section><section id="subtract-instruction">
2073 <h4 id="subtract-instruction">Subtract Instruction</h4>
2074 <p>sub</p>
2075 <p>TBD.</p>
2076 </section><section id="multiply-instruction">
2077 <h4 id="multiply-instruction">Multiply Instruction</h4>
2078 <p>mul</p>
2079 <p>TBD.</p>
2080 </section><section id="divide-instruction">
2081 <h4 id="divide-instruction">Divide Instruction</h4>
2082 <p>div
2083 sdiv</p>
2084 <p>TBD.</p>
2085 </section><section id="remainder-instruction">
2086 <h4 id="remainder-instruction">Remainder Instruction</h4>
2087 <p>div
2088 sdiv</p>
2089 <p>TBD.</p>
2090 </section><section id="shift-left-instruction">
2091 <h4 id="shift-left-instruction">Shift left Instruction</h4>
2092 <p>shl</p>
2093 <p>TBD.</p>
2094 </section><section id="logical-shift-right-instructions">
2095 <h4 id="logical-shift-right-instructions">Logical Shift right Instructions</h4>
2096 <p>ashr</p>
2097 <p>TBD.</p>
2098 </section><section id="arithmetic-shift-right-instructions">
2099 <h4 id="arithmetic-shift-right-instructions">Arithmetic Shift right Instructions </h4>
2100 <p>ashr</p>
2101 <p>TBD.</p>
2102 </section><section id="and-instruction">
2103 <h4 id="and-instruction">And Instruction</h4>
2104 <p>TBD.</p>
2105 </section><section id="or-instruction">
2106 <h4 id="or-instruction">Or Instruction</h4>
2107 <p>TBD.</p>
2108 </section><section id="xor-instruction">
2109 <h4 id="xor-instruction">Xor Instruction</h4>
2110 <p>TBD.</p>
2111 </section></section><section id="memory-creation-and-access-instructions">
2112 <h3 id="memory-creation-and-access-instructions">Memory creation and access Inst ructions</h3>
2113 <p>TBD.</p>
2114 <section id="stack-frame-memory-allocation-instruction">
2115 <h4 id="stack-frame-memory-allocation-instruction">Stack frame memory allocation Instruction</h4>
2116 <p>alloca</p>
2117 <p>TBD.</p>
2118 </section><section id="load-instruction">
2119 <h4 id="load-instruction">Load Instruction</h4>
2120 <p>load</p>
2121 <p>TBD.</p>
2122 <p>??? Vector</p>
2123 </section><section id="store-instruction">
2124 <h4 id="store-instruction">Store Instruction</h4>
2125 <p>store</p>
2126 <p>??? Vector.</p>
2127 </section></section><section id="conversion-instructions">
2128 <h3 id="conversion-instructions">Conversion Instructions</h3>
2129 <p>TBD.</p>
2130 <section id="truncating-instructions">
2131 <h4 id="truncating-instructions">Truncating Instructions</h4>
2132 <p>trunc
2133 fptrunc</p>
2134 <p>TBD.</p>
2135 </section><section id="extending-instructions">
2136 <h4 id="extending-instructions">Extending Instructions</h4>
2137 <ul class="small-gap">
2138 <li>Extending</li>
2139 <li>Type Conversion</li>
2140 </ul>
2141 <p>TBD.</p>
2142 </section></section><section id="comparison-instructions">
2143 <h3 id="comparison-instructions">Comparison Instructions</h3>
2144 <p>cmp</p>
2145 <p>TBD.</p>
2146 </section><section id="other-instructions">
2147 <h3 id="other-instructions">Other Instructions</h3>
2148 <p>TBD.</p>
2149 <section id="phi-instruction">
2150 <h4 id="phi-instruction">Phi Instruction</h4>
2151 <p>TBD.</p>
2152 </section><section id="forward-type-declarations">
2153 <h4 id="forward-type-declarations">Forward type declarations</h4>
2154 <p>TBD.</p>
2155 </section><section id="select-instruction">
2156 <h4 id="select-instruction">Select Instruction</h4>
2157 <p>TBD.</p>
2158 </section><section id="call-instructions">
2159 <h4 id="call-instructions">Call Instructions</h4>
2160 <p>TBD.</p>
2161 </section></section><section id="intrinsic-functions">
2162 <h3 id="intrinsic-functions">Intrinsic Functions</h3>
2163 <p>TBD.</p>
2164 </section><section id="support-functions">
2165 <h3 id="support-functions">Support Functions</h3>
2166 <p>Defines functions used to convert syntactic representation to corresponding
2167 records.</p>
2168 <section id="absoluteindex">
2169 <h4 id="absoluteindex">AbsoluteIndex</h4>
2170 <p>Bitcode ID&#8217;s of the forms <em>&#64;fN</em>, <em>&#64;gN</em>, <em>%pN</ em>, <em>%cN</em>, and <em>%vN</em>, are
2171 combined into a single index space. This can be done because of the
2172 ordering imposed by PNaClAsm. All function address bitcode IDs must be
2173 defined before any of the other forms of bitcode IDs. All global
2174 address bitcode IDs must be defined before any local bitcode
2175 IDs. Within a function block, the parameter bitcode IDs must be
2176 defined before constant IDs, and constant IDs must be defined before
2177 instruction value IDs.</p>
2178 <p>Hence, within a function block, it is safe to refer to all of these
2179 bitcode IDs using a single <em>absolute</em> index. The abolute index for
2180 each kind of bitcode ID is computed as follows:</p>
2181 <table border="1" class="docutils">
2182 <colgroup>
2183 </colgroup>
2184 <thead valign="bottom">
2185 <tr class="row-odd"><th class="head">Bitcode ID</th>
2186 <th class="head">AbsoluteIndex</th>
2187 </tr>
2188 </thead>
2189 <tbody valign="top">
2190 <tr class="row-even"><td>&#64;fN</td>
2191 <td>N</td>
2192 </tr>
2193 <tr class="row-odd"><td>&#64;gN</td>
2194 <td>N + NumDefinedFcnAddresses</td>
2195 </tr>
2196 <tr class="row-even"><td>&#64;pN</td>
2197 <td>N + NumDefinedFcnAddresses + NumGlobalAddresses</td>
2198 </tr>
2199 <tr class="row-odd"><td>&#64;cN</td>
2200 <td>N + NumDefinedFcnAddresses + NumGlobalAddresses + NumParams</td>
2201 </tr>
2202 <tr class="row-even"><td>&#64;vN</td>
2203 <td>N + NumDefinedFcnAddresses + NumGlobalAddresses + NumParams + NumFcnConsts</ td>
2204 </tr>
2205 </tbody>
2206 </table>
2207 </section><section id="relativeindex">
2208 <h4 id="relativeindex">RelativeIndex</h4>
2209 <p>Relative indices are used to refer to values within instructions of a
2210 function. The relative index of an ID is always defined in terms of
2211 the index associated with the next value generating instruction. It is
2212 defined as follows:
2213 .. naclcode:</p>
2214 <pre class="prettyprint">
2215 RelativeIndex(J) = AbsoluteIndex(NumValuedInsts) - AbsoluteIndex(J)
2216 </pre>
2217 </section></section><section id="abbreviations">
2218 <h3 id="abbreviations">Abbreviations</h3>
2219 <p>TBD.</p>
2220 <section id="id18">
2221 <h4 id="id18">Introduction</h4>
2222 <p>TBD.</p>
2223 <ul class="small-gap">
2224 <li>Blocks</li>
2225 <li>Data Records</li>
2226 <li>Abbreviations</li>
2227 <li>Abbreviation Ids.</li>
2228 </ul>
2229 </section><section id="bitstream-format">
2230 <h4 id="bitstream-format">Bitstream Format</h4>
2231 <p>TBD.</p>
2232 <ul class="small-gap">
2233 <li>Header</li>
2234 <li>Block Structue</li>
2235 <li>Primitives</li>
2236 <li>Abbreviations</li>
2237 <li>BlockInfoBlock</li>
2238 </ul>
2239 </section></section><section id="reference-implementation">
2240 <h3 id="reference-implementation">Reference Implementation</h3>
2241 <p>TBD.</p>
2242 </section></section></section>
2243
2244 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698